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

Commit

Permalink
Merge pull request #122 from blopa/hotfix/generation_problem
Browse files Browse the repository at this point in the history
Hotfix/generation problem
  • Loading branch information
blopa committed Dec 2, 2017
2 parents de5c0a2 + bfb9cd6 commit ffd1ccd
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 31 deletions.
4 changes: 3 additions & 1 deletion Magento1_deprecated/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# 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?

<img src="/screenshots/chat.gif?raw=true" width="550px">

> 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.
Expand Down
5 changes: 3 additions & 2 deletions Magento2/app/code/Werules/Chatbot/Block/Customer/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions Magento2/app/code/Werules/Chatbot/Block/Webhook/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
{
Expand All @@ -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
Expand Down
24 changes: 18 additions & 6 deletions Magento2/app/code/Werules/Chatbot/Block/Webhook/Messenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -51,7 +59,7 @@ public function getVerificationHub($hub_token)

protected function getMessengerPayload($messenger)
{
$payload = $messenger->getPayload();
$payload = $messenger->getPostbackPayload();
if (!$payload)
$payload = $messenger->getQuickReplyPayload();

Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions Magento2/app/code/Werules/Chatbot/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
60 changes: 46 additions & 14 deletions Magento2/app/code/Werules/Chatbot/Model/Api/Messenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function verifyWebhook($hub_token) {
}
}

return false;
return '';
}

/// Do requests to Messenger Bot API
Expand Down Expand Up @@ -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
Expand All @@ -318,58 +318,90 @@ 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
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) {
Expand Down
2 changes: 1 addition & 1 deletion Magento2/app/code/Werules/Chatbot/Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
20 changes: 20 additions & 0 deletions Magento2/app/code/Werules/Chatbot/Setup/UpgradeSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions Magento2/app/code/Werules/Chatbot/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<group id="general" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label comment tooltip">
<label>General Settings</label>
<comment><![CDATA[
<h3>Magento Chatbot v1.0.0</h3>
<h3>Magento Chatbot v1.0.1</h3>
<p><b>To use this module you'll have to use SSL in your store.</b></p>
]]></comment>
<field id="enable" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="1" translate="label comment tooltip" type="select">
Expand Down Expand Up @@ -61,7 +61,7 @@
<resource>Werules_Chatbot::config_werules_chatbot</resource>
<group id="general" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label comment tooltip">
<label>Messenger Settings</label>
<comment><![CDATA[<h3>Magento Chatbot v1.0.0</h3><p>To use this module you'll have to use SSL in your store.</p>]]></comment>
<comment><![CDATA[<h3>Magento Chatbot v1.0.1</h3><p>To use this module you'll have to use SSL in your store.</p>]]></comment>
<field id="enable" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="1" translate="label comment tooltip" type="select">
<label>Enable Messenger Bot</label>
<comment>Enable Messenger bot.</comment>
Expand Down
2 changes: 1 addition & 1 deletion Magento2/app/code/Werules/Chatbot/etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Werules_Chatbot" setup_version="1.0.0" schema_version="1.0.0"/>
<module name="Werules_Chatbot" setup_version="1.0.1" schema_version="1.0.0"/>
</config>
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ffd1ccd

Please sign in to comment.