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

Commit

Permalink
add option to enable/disable chatbox
Browse files Browse the repository at this point in the history
  • Loading branch information
blopa committed Dec 26, 2017
1 parent 4b2c907 commit abc110e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 27 deletions.
9 changes: 9 additions & 0 deletions Magento2/app/code/Werules/Chatbot/Block/Chatbox/Messenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ public function getFacebookAppId()
return $appId;
}

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

return false;
}

public function getConfigValue($code)
{
return $this->_helper->getConfigValue($code);
Expand Down
12 changes: 6 additions & 6 deletions Magento2/app/code/Werules/Chatbot/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@
</field>
<field id="page_id" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="7" translate="label comment tooltip" type="text">
<label>Facebook Page ID</label>
<comment>Facebook Page ID. If you don't know, leave it blank.</comment>
<comment>Facebook Page ID. If you don't know, leave it blank and we fill it for you.</comment>
</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>
<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 Facebook Messenger Box</label>-->
<!--<comment>Enable Facebook Messenger box</comment>-->
<!--<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>-->
<!--</field>-->
<!--<field id="messenger_box_width" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="9" translate="label comment tooltip" type="text">-->
<!--<depends>-->
<!--<field id="werules_chatbot_messenger/general/enable_messenger_box">1</field>-->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<script>
// Facebook SDK for JavaScript
window.fbAsyncInit = function() {
FB.init({
appId : <?php echo $this->getFacebookAppId() ?>,
autoLogAppEvents : true,
xfbml : true,
version : 'v2.11'
});
};
<?php if ($this->isChatboxEnabled()): ?>
<script>
// Facebook SDK for JavaScript
window.fbAsyncInit = function() {
FB.init({
appId : <?php echo $this->getFacebookAppId() ?>,
autoLogAppEvents : true,
xfbml : true,
version : 'v2.11'
});
};

(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<?php endif; ?>
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
<div class="fb-customerchat" page_id=<?php echo $this->getFacebookPageId(); ?> ref="OPTIONAL_WEBHOOK_PARAM">
</div>
<?php if ($this->isChatboxEnabled()): ?>
<div class="fb-customerchat" page_id=<?php echo $this->getFacebookPageId(); ?> ref="OPTIONAL_WEBHOOK_PARAM">
</div>
<?php endif; ?>
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<!-- }-->
<!-- }-->
<!--</style>-->
<?php //$fbChatUrl = "http://messenger.com"; ?>
<?php //$fbChatUrl = "http://web.telegram.org"; ?>
<!--<div id="werules-messenger-box">-->
<!-- <!-- code from https://gist.github.com/tomcritchlow/493774b09b02e31d1184d7cda926c659 -->-->
<!-- <a href="--><?php //echo $fbChatUrl; ?><!--" target="_blank" onclick="OpenChatInNewTab();">-->
Expand Down

0 comments on commit abc110e

Please sign in to comment.