diff --git a/Magento2/app/code/Werules/Chatbot/Block/Chatbox/Messenger.php b/Magento2/app/code/Werules/Chatbot/Block/Chatbox/Messenger.php index c036514..c82ecd1 100644 --- a/Magento2/app/code/Werules/Chatbot/Block/Chatbox/Messenger.php +++ b/Magento2/app/code/Werules/Chatbot/Block/Chatbox/Messenger.php @@ -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; diff --git a/Magento2/app/code/Werules/Chatbot/Helper/Define.php b/Magento2/app/code/Werules/Chatbot/Helper/Define.php index 028cec4..d5db115 100644 --- a/Magento2/app/code/Werules/Chatbot/Helper/Define.php +++ b/Magento2/app/code/Werules/Chatbot/Helper/Define.php @@ -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; diff --git a/Magento2/app/code/Werules/Chatbot/Model/Api/Messenger.php b/Magento2/app/code/Werules/Chatbot/Model/Api/Messenger.php index aca2d39..d79318e 100644 --- a/Magento2/app/code/Werules/Chatbot/Model/Api/Messenger.php +++ b/Magento2/app/code/Werules/Chatbot/Model/Api/Messenger.php @@ -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", diff --git a/Magento2/app/code/Werules/Chatbot/etc/adminhtml/system.xml b/Magento2/app/code/Werules/Chatbot/etc/adminhtml/system.xml index 0e56f44..d71ead4 100644 --- a/Magento2/app/code/Werules/Chatbot/etc/adminhtml/system.xml +++ b/Magento2/app/code/Werules/Chatbot/etc/adminhtml/system.xml @@ -103,6 +103,11 @@ Facebook Page ID. If you don't know, leave it blank and we fill it for you. + + + Is this domain whitelisted on Facebook? If not, don't worry, we'll whitelist it for you and update this setting. + Magento\Config\Model\Config\Source\Yesno + Enable Messenger chat box.