From 4b18d0fb9f3e39d9c98f35a33fef24bc5e34000a Mon Sep 17 00:00:00 2001 From: blopa Date: Sat, 9 Sep 2017 15:58:12 -0300 Subject: [PATCH 01/11] change log order --- .../code/community/Werules/Chatbot/Model/Cron.php | 13 +++++++++++++ .../Werules/Chatbot/Model/Api/Facebook/Handler.php | 8 ++++---- .../code/community/Werules/Chatbot/etc/config.xml | 12 ++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 Magento1/app/code/community/Werules/Chatbot/Model/Cron.php diff --git a/Magento1/app/code/community/Werules/Chatbot/Model/Cron.php b/Magento1/app/code/community/Werules/Chatbot/Model/Cron.php new file mode 100644 index 0000000..1a530f6 --- /dev/null +++ b/Magento1/app/code/community/Werules/Chatbot/Model/Cron.php @@ -0,0 +1,13 @@ +postMessage('1253214391436892', "Isso eh um teste"); + } +} diff --git a/Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Api/Facebook/Handler.php b/Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Api/Facebook/Handler.php index d058c99..239e17c 100644 --- a/Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Api/Facebook/Handler.php +++ b/Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Api/Facebook/Handler.php @@ -50,6 +50,10 @@ public function facebookHandler() if (!isset($facebook)) // if no apiKey available, break process return json_encode(array("status" => "error")); + $enableLog = Mage::getStoreConfig('chatbot_enable/general_config/enable_post_log'); + if ($enableLog == "1") // log all posts + Mage::log("Post Data:\n" . var_export($facebook->RawData(), true) . "\n\n", null, 'chatbot_facebook.log'); + // hub challenge $hubToken = Mage::getStoreConfig('chatbot_enable/general_config/your_custom_key'); $verify = $facebook->verifyWebhook($hubToken); @@ -65,10 +69,6 @@ public function facebookHandler() // helper $mageHelper = Mage::helper('core'); - $enableLog = Mage::getStoreConfig('chatbot_enable/general_config/enable_post_log'); - if ($enableLog == "1") // log all posts - Mage::log("Post Data:\n" . var_export($facebook->RawData(), true) . "\n\n", null, 'chatbot_facebook.log'); - $appId = $facebook->getAppId(); $canDisableBot = Mage::getStoreConfig('chatbot_enable/facebook_config/option_disable_bot'); if (($isEcho == "true") && ($canDisableBot == "1")) diff --git a/Magento1_deprecated/app/code/community/Werules/Chatbot/etc/config.xml b/Magento1_deprecated/app/code/community/Werules/Chatbot/etc/config.xml index 97af24e..abdbdf5 100644 --- a/Magento1_deprecated/app/code/community/Werules/Chatbot/etc/config.xml +++ b/Magento1_deprecated/app/code/community/Werules/Chatbot/etc/config.xml @@ -5,6 +5,18 @@ 0.0.16 + + + + + */1 * * * * + + + chatbot/cron::crontask + + + + From a0d1ed3b9643fb4e7f1d5ef7f0be175c73027e13 Mon Sep 17 00:00:00 2001 From: blopa Date: Sat, 9 Sep 2017 18:19:42 -0300 Subject: [PATCH 02/11] sending message whenever a customer have a abandoned cart --- .../community/Werules/Chatbot/Model/Cron.php | 61 ++++++++++++++- .../community/Werules/Chatbot/etc/config.xml | 2 +- .../community/Werules/Chatbot/etc/system.xml | 75 +++++++++++++++---- 3 files changed, 120 insertions(+), 18 deletions(-) diff --git a/Magento1/app/code/community/Werules/Chatbot/Model/Cron.php b/Magento1/app/code/community/Werules/Chatbot/Model/Cron.php index 1a530f6..f8e1442 100644 --- a/Magento1/app/code/community/Werules/Chatbot/Model/Cron.php +++ b/Magento1/app/code/community/Werules/Chatbot/Model/Cron.php @@ -1,13 +1,68 @@ postMessage('1253214391436892', "Isso eh um teste"); + $chatbotCollection = Mage::getModel('chatbot/chatdata')->getCollection(); + foreach($chatbotCollection as $chatbot) + { + //$hasQuote = $chatbot->getSessionId() && $chatbot->getQuoteId(); // has class quote and session ids + $enabled = // if backend promotional messages are disabled or if the customer wants to receive promotional messages + (Mage::getStoreConfig('chatbot_enable/general_config/disable_promotional_messages') != "1") || + ($chatbot->getEnablePromotionalMessages() == "1"); + $customer = Mage::getModel('customer/customer')->load((int)$chatbot->getCustomerId()); + if (($customer->getId()) && ($enabled)) // if is a valid customer id + { + $fbChatId = $chatbot->getFacebookChatId(); + $tgChatId = $chatbot->getTelegramChatId(); + $customerId = $customer->getId(); + $lifetime = (int)Mage::getStoreConfig('chatbot_enable/general_config/abandoned_cart_days'); + //$lifetime = 7; + $quotes = Mage::getModel( 'sales/quote' )->getCollection(); + $quotes->addFieldToFilter('customer_id', $customerId) + //->addFieldToFilter('is_active', 1) + ->addFieldToFilter('updated_at', array('to' => date("Y-m-d", time() - ($lifetime * 86400)))) + ; + if (count($quotes) > 0) // TODO + { + $enableFb = Mage::getStoreConfig('chatbot_enable/facebook_config/enable_abandoned_cart'); + $enableTg = Mage::getStoreConfig('chatbot_enable/telegram_config/enable_abandoned_cart'); + + if ($enableFb == "1") // messenger + { + $message = Mage::getStoreConfig('chatbot_enable/facebook_config/abandoned_cart_msg'); + if ($message != "") + { + $apikey = Mage::getStoreConfig('chatbot_enable/facebook_config/facebook_api_key'); + $facebook = new MessengerBot($apikey); + $facebook->postMessage($fbChatId, $message); + } + } + if ($enableTg == "1") // telegram + { + $message = Mage::getStoreConfig('chatbot_enable/telegram_config/abandoned_cart_msg'); + if ($message != "") + { + $apikey = Mage::getStoreConfig('chatbot_enable/telegram_config/telegram_api_key'); + $facebook = new TelegramBot($apikey); + $facebook->postMessage($tgChatId, $message); + } + } + } +// foreach($quotes as $quote) +// { +// $orders = Mage::getModel('sales/order')->getCollection(); +// $orders->addFieldToFilter('quote_id', $quote->getId()); +// $items = Mage::getModel('sales/quote_item') +// ->getCollection() +// ->setQuote($quote); +// } + } + } } } diff --git a/Magento1_deprecated/app/code/community/Werules/Chatbot/etc/config.xml b/Magento1_deprecated/app/code/community/Werules/Chatbot/etc/config.xml index abdbdf5..7e18e69 100644 --- a/Magento1_deprecated/app/code/community/Werules/Chatbot/etc/config.xml +++ b/Magento1_deprecated/app/code/community/Werules/Chatbot/etc/config.xml @@ -9,7 +9,7 @@ - */1 * * * * + 0 0 * * * chatbot/cron::crontask diff --git a/Magento1_deprecated/app/code/community/Werules/Chatbot/etc/system.xml b/Magento1_deprecated/app/code/community/Werules/Chatbot/etc/system.xml index 93c9b24..83a8567 100644 --- a/Magento1_deprecated/app/code/community/Werules/Chatbot/etc/system.xml +++ b/Magento1_deprecated/app/code/community/Werules/Chatbot/etc/system.xml @@ -56,11 +56,20 @@ 1 Automatically Enable Support if Customer Types a Message That The Bot Dosen't Understand. + + + text + 3 + 1 + 1 + 1 + Quantity of Days to Consider a Cart Abandoned. + select chatbot/enable - 3 + 4 1 1 1 @@ -70,7 +79,7 @@ select chatbot/enable - 4 + 5 1 1 1 @@ -80,7 +89,7 @@ select chatbot/enable - 5 + 6 1 1 1 @@ -290,11 +299,30 @@ 1 Enable Command Listing When The Bot Don't Understand What The Customer Typed + + + select + chatbot/enable + 14 + 1 + 1 + 1 + Enable Abandoned Cart Message + + + + text + 15 + 1 + 1 + 1 + Abandoned Cart Message. + werules_chatbot/commands chatbot/adminhtml_serialized - 14 + 16 1 1 0 @@ -304,7 +332,7 @@ select chatbot/enable - 15 + 17 1 1 1 @@ -314,7 +342,7 @@ werules_chatbot/replies chatbot/adminhtml_serialized - 16 + 18 1 1 0 @@ -324,7 +352,7 @@ text - 17 + 19 1 1 1 @@ -333,7 +361,7 @@ text - 18 + 20 1 1 1 @@ -542,11 +570,30 @@ 1 Enable Command Listing When The Bot Don't Understand What The Customer Typed + + + select + chatbot/enable + 18 + 1 + 1 + 1 + Enable Abandoned Cart Message + + + + text + 19 + 1 + 1 + 1 + Abandoned Cart Message. + select chatbot/enable - 18 + 20 1 1 1 @@ -556,7 +603,7 @@ werules_chatbot/commands chatbot/adminhtml_serialized - 19 + 21 1 1 0 @@ -566,7 +613,7 @@ select chatbot/enable - 20 + 22 1 1 1 @@ -576,7 +623,7 @@ werules_chatbot/replies chatbot/adminhtml_serialized - 21 + 23 1 1 0 @@ -586,7 +633,7 @@ text - 22 + 24 1 1 1 @@ -595,7 +642,7 @@ text - 23 + 25 1 1 1 From c336896702345c9e029eb6e1f9c72ac66198bcee Mon Sep 17 00:00:00 2001 From: blopa Date: Sat, 9 Sep 2017 19:00:35 -0300 Subject: [PATCH 03/11] abandoned cart message --- .../app/code/community/Werules/Chatbot/etc/system.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Magento1_deprecated/app/code/community/Werules/Chatbot/etc/system.xml b/Magento1_deprecated/app/code/community/Werules/Chatbot/etc/system.xml index 83a8567..9b671ad 100644 --- a/Magento1_deprecated/app/code/community/Werules/Chatbot/etc/system.xml +++ b/Magento1_deprecated/app/code/community/Werules/Chatbot/etc/system.xml @@ -28,7 +28,6 @@ text - validate-alphanum 0 1 1 @@ -63,6 +62,7 @@ 1 1 1 + input-number validate-number Quantity of Days to Consider a Cart Abandoned. @@ -316,6 +316,9 @@ 1 1 1 + + 1 + Abandoned Cart Message. @@ -587,6 +590,9 @@ 1 1 1 + + 1 + Abandoned Cart Message. From 7c4221182b144396f7e0d7503f162f09db2fd59b Mon Sep 17 00:00:00 2001 From: blopa Date: Sat, 9 Sep 2017 19:02:53 -0300 Subject: [PATCH 04/11] change cronjob name --- .../app/code/community/Werules/Chatbot/etc/config.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Magento1_deprecated/app/code/community/Werules/Chatbot/etc/config.xml b/Magento1_deprecated/app/code/community/Werules/Chatbot/etc/config.xml index 7e18e69..4b7a1b8 100644 --- a/Magento1_deprecated/app/code/community/Werules/Chatbot/etc/config.xml +++ b/Magento1_deprecated/app/code/community/Werules/Chatbot/etc/config.xml @@ -7,14 +7,14 @@ - + 0 0 * * * chatbot/cron::crontask - + From 1526c13204a6fe5dd8ad0db69cd8ca731f2c3e6b Mon Sep 17 00:00:00 2001 From: blopa Date: Sat, 9 Sep 2017 19:07:07 -0300 Subject: [PATCH 05/11] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1319211..3b4c299 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ Go to **System > General Settings > Chatbot Settings** - Track order status - Reorder - Send email - - Custom fallback messages + - Custom fallback messages - Much more ### Magento1 #### Deprecated versions From 2f2e141c0abc843eae48a5cf181a0bb78bbe5cab Mon Sep 17 00:00:00 2001 From: blopa Date: Thu, 28 Sep 2017 22:37:51 -0300 Subject: [PATCH 06/11] remove simple products filter --- .../community/Werules/Chatbot/Helper/Data.php | 2 +- .../Chatbot/Model/Api/Facebook/Handler.php | 32 +++++++++++-------- .../Chatbot/Model/Api/Telegram/Handler.php | 12 ++++--- README.md | 4 +-- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/Magento1_deprecated/app/code/community/Werules/Chatbot/Helper/Data.php b/Magento1_deprecated/app/code/community/Werules/Chatbot/Helper/Data.php index f3f3fca..bf86ff1 100644 --- a/Magento1_deprecated/app/code/community/Werules/Chatbot/Helper/Data.php +++ b/Magento1_deprecated/app/code/community/Werules/Chatbot/Helper/Data.php @@ -250,7 +250,7 @@ public function getProductIdsBySearch($searchString) $productCollection = Mage::getResourceModel('catalog/product_collection') ->addAttributeToSelect('*') ->addAttributeToFilter('visibility', 4) - ->addAttributeToFilter('type_id', 'simple') + //->addAttributeToFilter('type_id', 'simple') ->addAttributeToFilter( array( array('attribute' => 'sku', 'like' => '%' . $searchString .'%'), diff --git a/Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Api/Facebook/Handler.php b/Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Api/Facebook/Handler.php index 239e17c..a55c415 100644 --- a/Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Api/Facebook/Handler.php +++ b/Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Api/Facebook/Handler.php @@ -685,8 +685,8 @@ public function processText() $noProductFlag = false; $productCollection = $_category->getProductCollection() ->addAttributeToSelect('*') - ->addAttributeToFilter('visibility', 4) - ->addAttributeToFilter('type_id', 'simple'); + ->addAttributeToFilter('visibility', 4); + //->addAttributeToFilter('type_id', 'simple'); Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($productCollection); $productIDs = $productCollection->getAllIds(); @@ -718,17 +718,20 @@ public function processText() $productImage = $placeholder; $button = array( - array( - 'type' => 'postback', - 'title' => $mageHelper->__("Add to cart"), - 'payload' => $chatbotHelper->_add2CartCmd['command'] . $productID - ), array( 'type' => 'web_url', 'url' => $productUrl, 'title' => $mageHelper->__("Visit product's page") ) ); + if ($product->getTypeId() == "simple") + array_push($button, + array( + 'type' => 'postback', + 'title' => $mageHelper->__("Add to cart"), + 'payload' => $chatbotHelper->_add2CartCmd['command'] . $productID + ) + ); $element = array( 'title' => $product->getName(), 'item_url' => $productUrl, @@ -844,17 +847,20 @@ public function processText() $productImage = $placeholder; $button = array( - array( - 'type' => 'postback', - 'title' => $mageHelper->__("Add to cart"), - 'payload' => $chatbotHelper->_add2CartCmd['command'] . $productID - ), array( 'type' => 'web_url', 'url' => $productUrl, 'title' => $mageHelper->__("Visit product's page") ) ); + if ($product->getTypeId() == "simple") + array_push($button, + array( + 'type' => 'postback', + 'title' => $mageHelper->__("Add to cart"), + 'payload' => $chatbotHelper->_add2CartCmd['command'] . $productID + ) + ); $element = array( 'title' => $product->getName(), 'item_url' => $productUrl, @@ -1041,7 +1047,7 @@ public function processText() $productIDs = $category->getProductCollection() ->addAttributeToSelect('*') ->addAttributeToFilter('visibility', 4) - ->addAttributeToFilter('type_id', 'simple') + //->addAttributeToFilter('type_id', 'simple') ->getAllIds() ; } diff --git a/Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Api/Telegram/Handler.php b/Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Api/Telegram/Handler.php index e0d2162..4cc34e3 100644 --- a/Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Api/Telegram/Handler.php +++ b/Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Api/Telegram/Handler.php @@ -801,8 +801,8 @@ public function processText() $noProductFlag = false; $productCollection = $_category->getProductCollection() ->addAttributeToSelect('*') - ->addAttributeToFilter('visibility', 4) - ->addAttributeToFilter('type_id', 'simple'); + ->addAttributeToFilter('visibility', 4); + //->addAttributeToFilter('type_id', 'simple'); Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($productCollection); $productIDs = $productCollection->getAllIds(); @@ -826,7 +826,8 @@ public function processText() $message = $chatbotHelper->prepareTelegramProdMessages($productID); if ($message) // TODO { - $message .= "\n" . $mageHelper->__("Add to cart") . ": " . $chatbotHelper->_add2CartCmd['command'] . $productID; + if (Mage::getModel('catalog/product')->load($productID)->getTypeId() == "simple") + $message .= "\n" . $mageHelper->__("Add to cart") . ": " . $chatbotHelper->_add2CartCmd['command'] . $productID; if ($i >= $showMore) { $productImage = $chatbotHelper->loadImageContent($productID); @@ -916,7 +917,8 @@ public function processText() $message = $chatbotHelper->prepareTelegramProdMessages($productID); if ($message) // TODO { - $message .= "\n" . $mageHelper->__("Add to cart") . ": " . $chatbotHelper->_add2CartCmd['command'] . $productID; + if (Mage::getModel('catalog/product')->load($productID)->getTypeId() == "simple") + $message .= "\n" . $mageHelper->__("Add to cart") . ": " . $chatbotHelper->_add2CartCmd['command'] . $productID; if ($i >= $showMore) { $productImage = $chatbotHelper->loadImageContent($productID); @@ -1041,7 +1043,7 @@ public function processText() $productIDs = $category->getProductCollection() ->addAttributeToSelect('*') ->addAttributeToFilter('visibility', 4) - ->addAttributeToFilter('type_id', 'simple') + //->addAttributeToFilter('type_id', 'simple') ->getAllIds(); } else diff --git a/README.md b/README.md index 3b4c299..442c762 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ A big thanks to [Eleirbag89](https://github.com/Eleirbag89/) who wrote [this](ht - List store categories - List products from category - Search for products -- Add product to cart +- Add product to cart (Currently not working with Configurable Products and products with custom options) - Clear cart - Login/Logout to your account - List orders @@ -50,8 +50,6 @@ A big thanks to [Eleirbag89](https://github.com/Eleirbag89/) who wrote [this](ht - Send email - Custom fallback messages -**Currently not working with Configurable Products and products with custom options** - ## Languages - English (US) From 94e3cfe7e3017cf88557827650da79c825dd8d83 Mon Sep 17 00:00:00 2001 From: blopa Date: Thu, 28 Sep 2017 23:17:17 -0300 Subject: [PATCH 07/11] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 442c762..fcfdf6c 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ Go to **System > General Settings > Chatbot Settings** - List orders - Track order status - Reorder - - Send email + - Send email - Custom fallback messages - Much more ### Magento1 From 97376f506184c3ad49467311e6746bf8cba6f258 Mon Sep 17 00:00:00 2001 From: blopa Date: Thu, 28 Sep 2017 23:19:23 -0300 Subject: [PATCH 08/11] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fcfdf6c..19c8149 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ Go to **System > General Settings > Chatbot Settings** - Custom fallback messages - Much more ### Magento1 -#### Deprecated versions +#### Deprecated versions - **v0.0.16:** - Code improvements - Fix flood of messages when disabling bot for human respond From 3fa3e17608341f7dfb9debf7287c39ddab2bc028 Mon Sep 17 00:00:00 2001 From: blopa Date: Sat, 30 Sep 2017 00:38:07 -0300 Subject: [PATCH 09/11] add comments for functions --- .../community/Werules/Chatbot/Model/Cron.php | 1 + .../community/Werules/Chatbot/Helper/Data.php | 9 +++++-- .../Chatbot/Model/Adminhtml/Serialized.php | 2 +- .../Chatbot/Model/Api/Facebook/Handler.php | 9 ++++--- .../Chatbot/Model/Api/Telegram/Handler.php | 8 ++++--- .../Werules/Chatbot/Model/Chatdata.php | 12 ++++++++++ .../controllers/SettingsController.php | 9 +++++-- .../js/werules/chatbot/chatbot.js | 24 +++++++------------ .../default/css/werules_chatbot/chatbot.css | 1 + 9 files changed, 48 insertions(+), 27 deletions(-) diff --git a/Magento1/app/code/community/Werules/Chatbot/Model/Cron.php b/Magento1/app/code/community/Werules/Chatbot/Model/Cron.php index f8e1442..51407e0 100644 --- a/Magento1/app/code/community/Werules/Chatbot/Model/Cron.php +++ b/Magento1/app/code/community/Werules/Chatbot/Model/Cron.php @@ -2,6 +2,7 @@ require_once("Api/Facebook/MessengerBot.php"); require_once("Api/Telegram/TelegramBot.php"); +// handle all cron tasks. class Werules_Chatbot_Model_Cron { public function crontask() diff --git a/Magento1_deprecated/app/code/community/Werules/Chatbot/Helper/Data.php b/Magento1_deprecated/app/code/community/Werules/Chatbot/Helper/Data.php index bf86ff1..ddb1160 100644 --- a/Magento1_deprecated/app/code/community/Werules/Chatbot/Helper/Data.php +++ b/Magento1_deprecated/app/code/community/Werules/Chatbot/Helper/Data.php @@ -1,4 +1,7 @@ $size) @@ -470,4 +475,4 @@ public function prepareFacebookOrderPayload($orderID) // TODO add link to produc return null; } -} \ No newline at end of file +} diff --git a/Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Adminhtml/Serialized.php b/Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Adminhtml/Serialized.php index d8a4a35..e0b9ad5 100644 --- a/Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Adminhtml/Serialized.php +++ b/Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Adminhtml/Serialized.php @@ -1,5 +1,5 @@ _chatbotHelper = Mage::helper('werules_chatbot'); } + // handle messages sent from chats other than Facebook Messenger public function foreignMessageFromSupport($chatId, $text) { // helpers @@ -42,6 +43,7 @@ public function foreignMessageFromSupport($chatId, $text) return false; } + // start handling Facebook API request public function facebookHandler() { // Instances the Facebook class @@ -116,6 +118,7 @@ public function facebookHandler() return $facebook->respondSuccess(); } + // after handle, process text message public function processText() { // configs @@ -741,7 +744,7 @@ public function processText() ); array_push($elements, $element); - if (($i + 1) != $total && $i >= ($showMore + $listingLimit)) // if isn't the 'last but one' and $i is bigger than listing limit + what was shown last time ($show_more) + if (($i + 1) != $total && $i >= ($showMore + $listingLimit)) // if isn't the 'last but one' and $i is bigger than listing limit + what was shown last time ($showMore) { // TODO add option to list more products $button = array( @@ -870,7 +873,7 @@ public function processText() ); array_push($elements, $element); - if (($i + 1) != $total && $i >= ($showMore + $listingLimit)) // if isn't the 'last but one' and $i is bigger than listing limit + what was shown last time ($show_more) + if (($i + 1) != $total && $i >= ($showMore + $listingLimit)) // if isn't the 'last but one' and $i is bigger than listing limit + what was shown last time ($showMore) { // TODO add option to list more products $button = array( @@ -1284,7 +1287,7 @@ public function processText() array_push($replies, $reply); if ($i >= $showMore) { - if (($i + 1) != $total && $i >= ($showMore + $listingLimit)) // if isn't the 'last but one' and $i is bigger than listing limit + what was shown last time ($show_more) + if (($i + 1) != $total && $i >= ($showMore + $listingLimit)) // if isn't the 'last but one' and $i is bigger than listing limit + what was shown last time ($showMore) { $reply = array( 'content_type' => 'text', diff --git a/Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Api/Telegram/Handler.php b/Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Api/Telegram/Handler.php index 4cc34e3..6fcc6e0 100644 --- a/Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Api/Telegram/Handler.php +++ b/Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Api/Telegram/Handler.php @@ -22,6 +22,7 @@ public function setWebhook($webhookUrl) return $telegram->setWebhook($webhookUrl); } + // start handling telegram API request public function telegramHandler() { // Instances the Telegram class @@ -157,6 +158,7 @@ public function telegramHandler() return $telegram->respondSuccess(); } + // after handle, process the text message public function processText() { // configs @@ -836,7 +838,7 @@ public function processText() else $telegram->postMessage($chatId, $message); - if (($i + 1) != $total && $i >= ($showMore + $listingLimit)) // if isn't the 'last but one' and $i is bigger than listing limit + what was shown last time ($show_more) + if (($i + 1) != $total && $i >= ($showMore + $listingLimit)) // if isn't the 'last but one' and $i is bigger than listing limit + what was shown last time ($showMore) { // TODO add option to list more products $telegram->postMessage($chatId, $mageHelper->__("To show more, send") . " " . $listMoreCategories . $_category->getId() . "_" . (string)($i + 1)); @@ -927,7 +929,7 @@ public function processText() else $telegram->postMessage($chatId, $message); - if (($i + 1) != $total && $i >= ($showMore + $listingLimit)) // if isn't the 'last but one' and $i is bigger than listing limit + what was shown last time ($show_more) + if (($i + 1) != $total && $i >= ($showMore + $listingLimit)) // if isn't the 'last but one' and $i is bigger than listing limit + what was shown last time ($showMore) { // TODO add option to list more products $telegram->postMessage($chatId, $mageHelper->__("To show more, send") . " " . $listMoreSearch . str_replace(" ", "_", $text) . "_" . (string)($i + 1)); @@ -1263,7 +1265,7 @@ public function processText() if ($i >= $showMore) { $telegram->postMessage($chatId, $message); - if (($i + 1) != $total && $i >= ($showMore + $listingLimit)) // if isn't the 'last but one' and $i is bigger than listing limit + what was shown last time ($show_more) + if (($i + 1) != $total && $i >= ($showMore + $listingLimit)) // if isn't the 'last but one' and $i is bigger than listing limit + what was shown last time ($showMore) { // TODO add option to list more orders $telegram->postMessage($chatId, $mageHelper->__("To show more, send") . " " . $listMoreOrders . (string)($i + 1)); diff --git a/Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Chatdata.php b/Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Chatdata.php index 9bef114..57fa0ae 100644 --- a/Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Chatdata.php +++ b/Magento1_deprecated/app/code/community/Werules/Chatbot/Model/Chatdata.php @@ -6,6 +6,7 @@ // require_once("Api/WeChat/Handler.php"); require_once("Api/witAI/witAI.php"); +// main class of the module class Werules_Chatbot_Model_Chatdata extends Mage_Core_Model_Abstract { //APIs @@ -25,6 +26,7 @@ public function _construct() } // GENERAL FUNCTIONS + // handle all requests public function requestHandler($action, $webhook) // handle request { // handle webhook configuration @@ -86,6 +88,7 @@ public function requestHandler($action, $webhook) // handle request return json_encode(array("status" => "error")); // TODO } + // respond success after handling the request protected function respondSuccess() { // $chatbotHelper = $this->_chatbotHelper; @@ -102,6 +105,8 @@ protected function respondSuccess() http_response_code(200); return json_encode(array("status" => "success")); } + + // function to send email using Zend framework protected function sendEmail($text, $username) { $storeName = Mage::app()->getStore()->getName(); @@ -164,6 +169,7 @@ protected function sendEmail($text, $username) } } + // add product to the cart. Currently only works with simple products protected function addProd2Cart($prodId) // TODO add expiration date for sessions { $stock = Mage::getModel('cataloginventory/stock_item') @@ -227,6 +233,7 @@ protected function addProd2Cart($prodId) // TODO add expiration date for session return true; } + // get command string from backend settings protected function getCommandString($cmdId) { $chatbotHelper = $this->_chatbotHelper; @@ -295,6 +302,7 @@ protected function getCommandString($cmdId) return array('command' => null, 'alias' => null); } + // clear cart protected function clearCart() { try @@ -327,6 +335,7 @@ protected function clearCart() return true; } + // update data from this class public function updateChatdata($dataType, $state) { try @@ -350,6 +359,7 @@ public function updateChatdata($dataType, $state) } // TELEGRAM FUNCTIONS + // handle all messages from other chats other than Telegram to Telegram public function foreignMessageToTelegramSupport($foreignChatId, $text, $apiName, $customerName) { //$chatdata = Mage::getModel('chatbot/chatdata'); @@ -405,6 +415,7 @@ public function foreignMessageToTelegramSupport($foreignChatId, $text, $apiName, return false; } + // function that list all Telegram enabled commands protected function listTelegramCommandsMessage() { $chatbotHelper = $this->_chatbotHelper; @@ -432,6 +443,7 @@ protected function listTelegramCommandsMessage() } // FACEBOOK FUNCTIONS + // function that list all Facebook enabled commands protected function listFacebookCommandsMessage() { $chatbotHelper = $this->_chatbotHelper; diff --git a/Magento1_deprecated/app/code/community/Werules/Chatbot/controllers/SettingsController.php b/Magento1_deprecated/app/code/community/Werules/Chatbot/controllers/SettingsController.php index d8f669b..a7834ef 100644 --- a/Magento1_deprecated/app/code/community/Werules/Chatbot/controllers/SettingsController.php +++ b/Magento1_deprecated/app/code/community/Werules/Chatbot/controllers/SettingsController.php @@ -2,7 +2,8 @@ // settings controller, used to save all data from customer configurations // and also "links" a chatbot to the customer in the function loginFromChatbot class Werules_Chatbot_SettingsController extends Mage_Core_Controller_Front_Action { - public function preDispatch() // function that makes the settings page only available when the user is logged in + // function that makes the settings page only available when the user is logged in + public function preDispatch() { parent::preDispatch(); $loginUrl = Mage::helper('customer')->getLoginUrl(); @@ -11,7 +12,9 @@ public function preDispatch() // function that makes the settings page only avai $this->setFlag('', self::FLAG_NO_DISPATCH, true); } } - public function indexAction() // main action, sets layout and page title + + // main action, sets layout and page title + public function indexAction() { $this->loadLayout(); // some code @@ -21,6 +24,7 @@ public function indexAction() // main action, sets layout and page title $this->renderLayout(); } + // save settings public function saveAction() { $mageHelper = Mage::helper('core'); @@ -63,6 +67,7 @@ public function saveAction() $this->_redirect('chatbot/settings/index'); // redirect customer to settings page } + // handle requests with hash private function requestHandler() { $hash = Mage::app()->getRequest()->getParam('hash'); diff --git a/Magento1_deprecated/js/werules/chatbot/chatbot.js b/Magento1_deprecated/js/werules/chatbot/chatbot.js index 14a972a..d78765f 100644 --- a/Magento1_deprecated/js/werules/chatbot/chatbot.js +++ b/Magento1_deprecated/js/werules/chatbot/chatbot.js @@ -1,20 +1,15 @@ +// display/hide match mode function werulesTogleMatchMode(element) { //debugger; var val = element.value; var name = element.name; - if (val == 0) - { - name = name.substr(0, name.lastIndexOf("[")) + "[similarity]"; - var target = document.getElementsByName(name); + name = name.substr(0, name.lastIndexOf("[")) + "[similarity]"; + var target = document.getElementsByName(name); + if (val === 0) target[0].disabled = false; - } else - { - name = name.substr(0, name.lastIndexOf("[")) + "[similarity]"; - var target = document.getElementsByName(name); target[0].disabled = true; - } } function werulesTogleEnable(element) @@ -36,21 +31,18 @@ function werulesTogleEnable(element) // } } +// display/hide reply mode function werulesTogleReplyMode(element) { //debugger; var val = element.value; var name = element.name; - if (val == 0) - { - name = name.substr(0, name.lastIndexOf("[")) + "[command_id]"; - var target = document.getElementsByName(name); + name = name.substr(0, name.lastIndexOf("[")) + "[command_id]"; + var target = document.getElementsByName(name); + if (val === 0) target[0].disabled = true; - } else { - name = name.substr(0, name.lastIndexOf("[")) + "[command_id]"; - var target = document.getElementsByName(name); //target[0].classList.remove("werules-disabled"); //target[0].style = ""; target[0].disabled = false; diff --git a/Magento1_deprecated/skin/adminhtml/base/default/css/werules_chatbot/chatbot.css b/Magento1_deprecated/skin/adminhtml/base/default/css/werules_chatbot/chatbot.css index 9a19413..2b3e611 100644 --- a/Magento1_deprecated/skin/adminhtml/base/default/css/werules_chatbot/chatbot.css +++ b/Magento1_deprecated/skin/adminhtml/base/default/css/werules_chatbot/chatbot.css @@ -1,3 +1,4 @@ +/*backend css*/ .werules-disabled-input{ pointer-events: none; background-color: #ebebe4; From 93604c8adbaac3b583cfbeba83f1f22affcd8b01 Mon Sep 17 00:00:00 2001 From: blopa Date: Tue, 3 Oct 2017 00:52:28 -0300 Subject: [PATCH 10/11] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 19c8149..c94174c 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ Go to **System > General Settings > Chatbot Settings** - Custom fallback messages - Much more ### Magento1 -#### Deprecated versions +#### Deprecated versions - **v0.0.16:** - Code improvements - Fix flood of messages when disabling bot for human respond From 7176580ac1aeab86cef8d16af1d5bd480899a177 Mon Sep 17 00:00:00 2001 From: blopa Date: Wed, 29 Nov 2017 23:49:13 -0200 Subject: [PATCH 11/11] add crontask file and update readme --- .../community/Werules/Chatbot/Model/Cron.php | 69 ------------------- Magento1_deprecated/README.md | 14 ++-- README.md | 6 +- 3 files changed, 11 insertions(+), 78 deletions(-) delete mode 100644 Magento1/app/code/community/Werules/Chatbot/Model/Cron.php diff --git a/Magento1/app/code/community/Werules/Chatbot/Model/Cron.php b/Magento1/app/code/community/Werules/Chatbot/Model/Cron.php deleted file mode 100644 index 51407e0..0000000 --- a/Magento1/app/code/community/Werules/Chatbot/Model/Cron.php +++ /dev/null @@ -1,69 +0,0 @@ -getCollection(); - foreach($chatbotCollection as $chatbot) - { - //$hasQuote = $chatbot->getSessionId() && $chatbot->getQuoteId(); // has class quote and session ids - $enabled = // if backend promotional messages are disabled or if the customer wants to receive promotional messages - (Mage::getStoreConfig('chatbot_enable/general_config/disable_promotional_messages') != "1") || - ($chatbot->getEnablePromotionalMessages() == "1"); - $customer = Mage::getModel('customer/customer')->load((int)$chatbot->getCustomerId()); - if (($customer->getId()) && ($enabled)) // if is a valid customer id - { - $fbChatId = $chatbot->getFacebookChatId(); - $tgChatId = $chatbot->getTelegramChatId(); - $customerId = $customer->getId(); - $lifetime = (int)Mage::getStoreConfig('chatbot_enable/general_config/abandoned_cart_days'); - //$lifetime = 7; - $quotes = Mage::getModel( 'sales/quote' )->getCollection(); - $quotes->addFieldToFilter('customer_id', $customerId) - //->addFieldToFilter('is_active', 1) - ->addFieldToFilter('updated_at', array('to' => date("Y-m-d", time() - ($lifetime * 86400)))) - ; - if (count($quotes) > 0) // TODO - { - $enableFb = Mage::getStoreConfig('chatbot_enable/facebook_config/enable_abandoned_cart'); - $enableTg = Mage::getStoreConfig('chatbot_enable/telegram_config/enable_abandoned_cart'); - - if ($enableFb == "1") // messenger - { - $message = Mage::getStoreConfig('chatbot_enable/facebook_config/abandoned_cart_msg'); - if ($message != "") - { - $apikey = Mage::getStoreConfig('chatbot_enable/facebook_config/facebook_api_key'); - $facebook = new MessengerBot($apikey); - $facebook->postMessage($fbChatId, $message); - } - } - if ($enableTg == "1") // telegram - { - $message = Mage::getStoreConfig('chatbot_enable/telegram_config/abandoned_cart_msg'); - if ($message != "") - { - $apikey = Mage::getStoreConfig('chatbot_enable/telegram_config/telegram_api_key'); - $facebook = new TelegramBot($apikey); - $facebook->postMessage($tgChatId, $message); - } - } - } -// foreach($quotes as $quote) -// { -// $orders = Mage::getModel('sales/order')->getCollection(); -// $orders->addFieldToFilter('quote_id', $quote->getId()); -// $items = Mage::getModel('sales/quote_item') -// ->getCollection() -// ->setQuote($quote); -// } - } - } - } -} diff --git a/Magento1_deprecated/README.md b/Magento1_deprecated/README.md index 6995f05..159f247 100644 --- a/Magento1_deprecated/README.md +++ b/Magento1_deprecated/README.md @@ -35,7 +35,7 @@ A big thanks to [Eleirbag89](https://github.com/Eleirbag89/) who wrote [this](ht - List store categories - List products from category - Search for products -- Add product to cart +- Add product to cart (Currently not working with Configurable Products and products with custom options) - Clear cart - Login/Logout to your account - List orders @@ -51,8 +51,6 @@ A big thanks to [Eleirbag89](https://github.com/Eleirbag89/) who wrote [this](ht - Set custom reply messages for predetermined text or regex - Custom fallback messages -**Currently not working with Configurable Products and products with custom options** - ## Languages - English (US) - Portuguese (BR) @@ -142,6 +140,10 @@ Conversation ![ScreenShot](https://raw.githubusercontent.com/blopa/Magento-Chatbot/master/screenshots/conversation.jpg) ## Release Notes +- **v0.0.17:** + - Add Abandoned Cart messages + - Enable all types of products to be listed + - Update module license for MIT license - **v0.0.16:** - Code improvements - Fix flood of messages when disabling bot for human respond @@ -252,6 +254,7 @@ A: Thank you! You can help by codding more features, creating pull requests, or - Microsoft Bot Framework / Skype - ??? - **Features:** + - Add message queueing - Documentation / Tutorials / Videos - Add a custom in-store message chat app - Save support history @@ -260,9 +263,8 @@ A: Thank you! You can help by codding more features, creating pull requests, or - Force a command for a customer - Integrate checkout to Facebook Payment API - Save messages on database before sending to make sure it will be sent eventually - - Add compatibility with configurable products - - Add compatibility with products with custom options - - Add "abandoned cart" messages + - Add "Add to cart" feature for configurable products and products with custom options + - Better approach for Abandoned Carts - Add `CDATA` and `` to configuration descriptions ## License diff --git a/README.md b/README.md index c94174c..8d785fb 100644 --- a/README.md +++ b/README.md @@ -107,11 +107,11 @@ Go to **System > General Settings > Chatbot Settings** - List orders - Track order status - Reorder - - Send email - - Custom fallback messages + - Send email + - Custom fallback messages - Much more ### Magento1 -#### Deprecated versions +#### Deprecated versions - **v0.0.16:** - Code improvements - Fix flood of messages when disabling bot for human respond