diff --git a/Magento1_deprecated/README.md b/Magento1_deprecated/README.md index 7112fea..9f7c0bf 100644 --- a/Magento1_deprecated/README.md +++ b/Magento1_deprecated/README.md @@ -1,5 +1,7 @@ # Magento Chatbot Module (Telegram, Messenger, Whatsapp, WeChat and Skype) +# IMPORTANT +### THIS VERSION IS DEPECRATED, YOU CAN FIND THE NEW MAGENTO1 VERSION [HERE](https://github.com/blopa/Magento-Chatbot/tree/master/Magento1) OR MAGENTO2 [HERE](https://github.com/blopa/Magento-Chatbot/tree/master/Magento2) **Chatbots!** They're all the rage: Telegram has them, Facebook wants them, and it seems like every computer coder wants to make them. But what are they? And why is every company suddenly hot on this new A.I. trend? @@ -7,7 +9,7 @@ > Chatbots are computer programs that you interact with via a chat interface. Using a chatbot is as simple as having a conversation with it. You can ask it questions or give it commands, and it'll respond to you and carry out your actions. Chatbots can be run in any number of chat apps, including Facebook Messenger, your phone's text messaging app, and most others. **Become part of the chatbots revolution.** -**Download the latest version [here](https://github.com/blopa/Magento-Chatbot/releases/latest). Or get it via Magento Connect https://www.magentocommerce.com/magento-connect/chatbot-integration.html** +**Download the latest version [here](https://github.com/blopa/Magento-Chatbot/releases/latest). ~~Or get it via Magento Connect https://www.magentocommerce.com/magento-connect/chatbot-integration.html~~** ## About This repository is the source code for the Magento Chatbot (Telegram, Messenger, Whatsapp, WeChat and Skype), with this module you can fully integrate your Magento store with the most popular chat apps in the market. This means that by simply installing this module and a few clicks you can have a new way to show and sell your products to your clients. diff --git a/Magento2/app/code/Werules/Chatbot/Block/Customer/Index.php b/Magento2/app/code/Werules/Chatbot/Block/Customer/Index.php index 8fa2a14..50227c3 100644 --- a/Magento2/app/code/Werules/Chatbot/Block/Customer/Index.php +++ b/Magento2/app/code/Werules/Chatbot/Block/Customer/Index.php @@ -35,7 +35,8 @@ public function __construct( \Werules\Chatbot\Model\ChatbotUserFactory $chatbotUser, \Werules\Chatbot\Model\ResourceModel\ChatbotAPI\CollectionFactory $chatbotAPI, // \Werules\Chatbot\Model\ChatbotUser $chatbotAPI, - \Magento\Customer\Model\Session $customerSession + \Magento\Customer\Model\Session $customerSession, + array $data = array() ) { $this->_customerSession = $customerSession; @@ -45,7 +46,7 @@ public function __construct( $this->_chatbotAPI = $chatbotAPI; $this->_define = new \Werules\Chatbot\Helper\Define; // $this->_isScopePrivate = true; - parent::__construct($context); + parent::__construct($context, $data); } public function _prepareLayout() diff --git a/Magento2/app/code/Werules/Chatbot/Block/Webhook/Index.php b/Magento2/app/code/Werules/Chatbot/Block/Webhook/Index.php index 6a3c300..bc57fa5 100644 --- a/Magento2/app/code/Werules/Chatbot/Block/Webhook/Index.php +++ b/Magento2/app/code/Werules/Chatbot/Block/Webhook/Index.php @@ -33,11 +33,13 @@ class Index extends \Magento\Framework\View\Element\Template public function __construct( \Magento\Framework\View\Element\Template\Context $context, +// \Magento\Framework\Registry $registry, \Magento\Framework\ObjectManagerInterface $objectManager, \Werules\Chatbot\Helper\Data $helperData, \Werules\Chatbot\Model\ChatbotAPI $chatbotAPI, \Magento\Framework\App\Request\Http $request, - \Werules\Chatbot\Model\MessageFactory $message + \Werules\Chatbot\Model\MessageFactory $message, + array $data = array() // \Werules\Chatbot\Cron\Worker $cronWorker ) { @@ -48,7 +50,7 @@ public function __construct( $this->_objectManager = $objectManager; $this->_define = new \Werules\Chatbot\Helper\Define; // $this->_cronWorker = $cronWorker; - parent::__construct($context); + parent::__construct($context, $data); } protected function createMessageObject($apiModel){} // TODO diff --git a/Magento2/app/code/Werules/Chatbot/Block/Webhook/Messenger.php b/Magento2/app/code/Werules/Chatbot/Block/Webhook/Messenger.php index 94b7cdd..2a6411e 100644 --- a/Magento2/app/code/Werules/Chatbot/Block/Webhook/Messenger.php +++ b/Magento2/app/code/Werules/Chatbot/Block/Webhook/Messenger.php @@ -27,14 +27,22 @@ class Messenger extends \Werules\Chatbot\Block\Webhook\Index // public function __construct( // \Magento\Framework\View\Element\Template\Context $context, +// \Magento\Framework\ObjectManagerInterface $objectManager, // \Werules\Chatbot\Helper\Data $helperData, // \Werules\Chatbot\Model\ChatbotAPI $chatbotAPI, -// \Werules\Chatbot\Model\Message $message, -// \Werules\Chatbot\Model\Api\Messenger $messenger +// \Magento\Framework\App\Request\Http $request, +// \Werules\Chatbot\Model\MessageFactory $message +//// \Werules\Chatbot\Cron\Worker $cronWorker // ) // { -// parent::__construct($context, $helperData, $chatbotAPI, $message); -// $this->_messenger = $messenger; +// $this->_helper = $helperData; +// $this->_chatbotAPI = $chatbotAPI; +// $this->_request = $request; +// $this->_messageModel = $message; +// $this->_objectManager = $objectManager; +// $this->_define = new \Werules\Chatbot\Helper\Define; +//// $this->_cronWorker = $cronWorker; +//// parent::__construct($context, $objectManager, $helperData, $chatbotAPI, $request, $message); // } public function getVerificationHub($hub_token) @@ -51,7 +59,7 @@ public function getVerificationHub($hub_token) protected function getMessengerPayload($messenger) { - $payload = $messenger->getPayload(); + $payload = $messenger->getPostbackPayload(); if (!$payload) $payload = $messenger->getQuickReplyPayload(); @@ -101,7 +109,11 @@ protected function createMessageObject($messenger) { $messageObject = new \stdClass(); $messageObject->senderId = $messenger->ChatID(); - $messageObject->content = $messenger->Text(); + if ($messenger->Text()) + $content = $messenger->Text(); + else + $content = $messenger->getPostbackTitle(); + $messageObject->content = $content; $messageObject->status = $this->_define::PROCESSING; $messageObject->direction = $this->_define::INCOMING; $messageObject->chatType = $this->_define::MESSENGER_INT; // TODO diff --git a/Magento2/app/code/Werules/Chatbot/Helper/Data.php b/Magento2/app/code/Werules/Chatbot/Helper/Data.php index cebac06..6bbbdcd 100644 --- a/Magento2/app/code/Werules/Chatbot/Helper/Data.php +++ b/Magento2/app/code/Werules/Chatbot/Helper/Data.php @@ -752,9 +752,7 @@ private function processPayloadCommands($message) $senderId = $message->getSenderId(); $chatbotAPI = $this->getChatbotAPIModelBySenderId($senderId); if ($chatbotAPI->getLogged() == $this->_define::LOGGED) - { $result = $this->processReorderCommand($payload->parameter, $senderId); - } else $result = $this->getNotLoggedMessage(); } diff --git a/Magento2/app/code/Werules/Chatbot/Model/Api/Messenger.php b/Magento2/app/code/Werules/Chatbot/Model/Api/Messenger.php index feb1b06..c2c641e 100644 --- a/Magento2/app/code/Werules/Chatbot/Model/Api/Messenger.php +++ b/Magento2/app/code/Werules/Chatbot/Model/Api/Messenger.php @@ -55,7 +55,7 @@ public function verifyWebhook($hub_token) { } } - return false; + return ''; } /// Do requests to Messenger Bot API @@ -308,7 +308,7 @@ public function Text() { if (isset($this->data["entry"][0]["messaging"][0]["message"]["text"])) return $this->data["entry"][0]["messaging"][0]["message"]["text"]; - return false; + return ''; } /// Get the userdata who sent the message @@ -318,30 +318,50 @@ public function UserData($chat_id) { /// Get the chat_id of the current message public function ChatID() { - return $this->data['entry'][0]['messaging'][0]['sender']['id']; + if (isset($this->data["entry"][0]['messaging'][0]['sender']['id'])) + return $this->data['entry'][0]['messaging'][0]['sender']['id']; + + return ''; } /// Get the recipient_id of the current message public function RecipientID() { - return $this->data['entry'][0]['messaging'][0]['recipient']['id']; + if (isset($this->data["entry"][0]['messaging'][0]['recipient']['id'])) + return $this->data['entry'][0]['messaging'][0]['recipient']['id']; + + return ''; } /// Get m.me ref type public function getReferralType() { - return $this->data["entry"][0]["messaging"][0]["referral"]["type"]; + if (isset($this->data["entry"][0]["messaging"][0]["referral"]["type"])) + return $this->data["entry"][0]["messaging"][0]["referral"]["type"]; + + return ''; } /// Get m.me ref data public function getReferralRef() { - return $this->data["entry"][0]["messaging"][0]["referral"]["ref"]; + if (isset($this->data["entry"][0]["messaging"][0]["referral"]["ref"])) + return $this->data["entry"][0]["messaging"][0]["referral"]["ref"]; + + return ''; } - /// Get payload - public function getPayload() { + /// Get postback payload + public function getPostbackPayload() { if (isset($this->data["entry"][0]["messaging"][0]["postback"]["payload"])) return $this->data["entry"][0]["messaging"][0]["postback"]["payload"]; - return false; + return ''; + } + + /// Get postback title + public function getPostbackTitle() { + if (isset($this->data["entry"][0]["messaging"][0]["postback"]["title"])) + return $this->data["entry"][0]["messaging"][0]["postback"]["title"]; + + return ''; } /// Get quickreply payload @@ -349,27 +369,39 @@ public function getQuickReplyPayload() { if (isset($this->data["entry"][0]["messaging"][0]["message"]["quick_reply"]["payload"])) return $this->data["entry"][0]["messaging"][0]["message"]["quick_reply"]["payload"]; - return false; + return ''; } /// Get message timestamp public function getMessageTimestamp() { - return $this->data["entry"][0]["time"]; + if (isset($this->data["entry"][0]["time"])) + return $this->data["entry"][0]["time"]; + + return ''; } /// Get the message_id of the current message public function MessageID() { - return $this->data["entry"][0]["messaging"][0]["message"]["mid"]; + if (isset($this->data["entry"][0]["messaging"][0]["message"]["mid"])) + return $this->data["entry"][0]["messaging"][0]["message"]["mid"]; + + return ''; } /// Get the is_echo of the current message public function getEcho() { - return $this->data["entry"][0]["messaging"][0]["message"]["is_echo"]; + if (isset($this->data["entry"][0]["messaging"][0]["message"]["is_echo"])) + return $this->data["entry"][0]["messaging"][0]["message"]["is_echo"]; + + return ''; } /// Get the app_id of the current message public function getAppId() { - return $this->data["entry"][0]["messaging"][0]["message"]["app_id"]; + if (isset($this->data["entry"][0]["messaging"][0]["message"]["app_id"])) + return $this->data["entry"][0]["messaging"][0]["message"]["app_id"]; + + return ''; } private function sendAPIRequest($url, array $content, $post = true, $response = true) { diff --git a/Magento2/app/code/Werules/Chatbot/Setup/UpgradeData.php b/Magento2/app/code/Werules/Chatbot/Setup/UpgradeData.php index 2db21c1..fcdfb68 100644 --- a/Magento2/app/code/Werules/Chatbot/Setup/UpgradeData.php +++ b/Magento2/app/code/Werules/Chatbot/Setup/UpgradeData.php @@ -36,7 +36,7 @@ public function upgrade( ModuleContextInterface $context ) { $setup->startSetup(); - if (version_compare($context->getVersion(), "1.0.0", "<")) { + if (version_compare($context->getVersion(), "1.0.1", "<")) { //Your upgrade script } $setup->endSetup(); diff --git a/Magento2/app/code/Werules/Chatbot/Setup/UpgradeSchema.php b/Magento2/app/code/Werules/Chatbot/Setup/UpgradeSchema.php index 75ceb28..1bd7c00 100644 --- a/Magento2/app/code/Werules/Chatbot/Setup/UpgradeSchema.php +++ b/Magento2/app/code/Werules/Chatbot/Setup/UpgradeSchema.php @@ -38,6 +38,26 @@ public function upgrade( $setup->startSetup(); if (version_compare($context->getVersion(), "1.0.0", "<")) { //Your upgrade script + // Get module table +// $tableName = $setup->getTable('table_name'); +// +// // Check if the table already exists +// if ($setup->getConnection()->isTableExists($tableName) == true) { +// // Declare data +// $columns = [ +// 'imagename' => [ +// 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, +// 'nullable' => false, +// 'comment' => 'image name', +// ], +// ]; +// +// $connection = $setup->getConnection(); +// foreach ($columns as $name => $definition) { +// $connection->addColumn($tableName, $name, $definition); +// } +// +// } } $setup->endSetup(); } diff --git a/Magento2/app/code/Werules/Chatbot/etc/adminhtml/system.xml b/Magento2/app/code/Werules/Chatbot/etc/adminhtml/system.xml index 9a15704..550b98d 100644 --- a/Magento2/app/code/Werules/Chatbot/etc/adminhtml/system.xml +++ b/Magento2/app/code/Werules/Chatbot/etc/adminhtml/system.xml @@ -11,7 +11,7 @@ Magento Chatbot v1.0.0 +

Magento Chatbot v1.0.1

To use this module you'll have to use SSL in your store.

]]>
@@ -61,7 +61,7 @@ Werules_Chatbot::config_werules_chatbot - Magento Chatbot v1.0.0

To use this module you'll have to use SSL in your store.

]]>
+ Magento Chatbot v1.0.1

To use this module you'll have to use SSL in your store.

]]>
Enable Messenger bot. diff --git a/Magento2/app/code/Werules/Chatbot/etc/module.xml b/Magento2/app/code/Werules/Chatbot/etc/module.xml index 27e8216..8b8152c 100644 --- a/Magento2/app/code/Werules/Chatbot/etc/module.xml +++ b/Magento2/app/code/Werules/Chatbot/etc/module.xml @@ -1,4 +1,4 @@ - + diff --git a/README.md b/README.md index 8ba5e9a..58e3717 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,9 @@ Go to **System > General Settings > Chatbot Settings** ## Release Notes ### Magento2 +- **v1.0.1:** + - Fix missing parameter on CLI installation + - Fix get on Messenger payload message - **v1.0.0:** - First working version - Messenger integration