Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
add select for whitelabel domain
Browse files Browse the repository at this point in the history
  • Loading branch information
blopa committed Dec 26, 2017
1 parent abc110e commit 966256d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
23 changes: 22 additions & 1 deletion Magento2/app/code/Werules/Chatbot/Block/Chatbox/Messenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,31 @@ public function getFacebookAppId()
return $appId;
}

public function isDomainWhitelabeled()
{
$enable = $this->getConfigValue('werules_chatbot_messenger/general/domain_whitelisted');
if ($enable)
return true;

$messengerInstance = $this->getMessengerInstance();
// $url = parse_url($_SERVER['SERVER_NAME'], PHP_URL_HOST);
$url = $_SERVER['SERVER_NAME'];
$domain = array($url);
$result = $messengerInstance->addDomainsToWhitelist($domain);
if (!isset($result['error']))
{
$this->setConfigValue('werules_chatbot_messenger/general/domain_whitelisted', $this->_define::WHITELABELED);
return true;
}

return false;
}

public function isChatboxEnabled()
{
$enable = $this->getConfigValue('werules_chatbot_messenger/general/enable_messenger_box');
if ($enable)
$isWhitelabeled = $this->isDomainWhitelabeled();
if ($enable && $isWhitelabeled)
return true;

return false;
Expand Down
1 change: 1 addition & 0 deletions Magento2/app/code/Werules/Chatbot/Helper/Define.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Define
const OUTGOING = 1;
const DISABLED = 0;
const ENABLED = 1;
const WHITELABELED = 1;
const NOT_LOGGED = 0;
const NOT_ADMIN = 0;
const ADMIN = 1;
Expand Down
14 changes: 14 additions & 0 deletions Magento2/app/code/Werules/Chatbot/Model/Api/Messenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,20 @@ public function sendReceiptTemplate($chat_id, array $payload) {
);
}

// $whitelist = array(
// 'www.github.com',
// 'www.facebook.com'
// )
public function addDomainsToWhitelist(array $whitelist) {
return $this->endpoint("me/thread_settings",
array(
'setting_type' => 'domain_whitelisting',
'whitelisted_domains' => $whitelist,
'domain_action_type' => 'add'
)
);
}

public function getPageDetails() {
return $this->endpoint(
"me",
Expand Down
5 changes: 5 additions & 0 deletions Magento2/app/code/Werules/Chatbot/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@
<label>Facebook Page ID</label>
<comment>Facebook Page ID. If you don't know, leave it blank and we fill it for you.</comment>
</field>
<field id="domain_whitelisted" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="8" translate="label comment tooltip" type="select">
<label>Whitelisted Domain?</label>
<comment>Is this domain whitelisted on Facebook? If not, don't worry, we'll whitelist it for you and update this setting.</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="enable_messenger_box" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="8" translate="label comment tooltip" type="select">
<label>Enable Messenger Chat Box</label>
<comment>Enable Messenger chat box.</comment>
Expand Down

0 comments on commit 966256d

Please sign in to comment.