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 #70 from blopa/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
blopa committed Nov 30, 2017
2 parents d884192 + 7176580 commit 227df7b
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 74 deletions.
14 changes: 8 additions & 6 deletions Magento1_deprecated/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 `<tooltip>` to configuration descriptions

## License
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php
// this is the helper class of the module
// it contains all the constans and most of the generic functions
// and some parts of the bussiness logic
class Werules_Chatbot_Helper_Data extends Mage_Core_Helper_Abstract
{
// ----- CONSTANTS ----------
Expand Down Expand Up @@ -130,6 +133,7 @@ class Werules_Chatbot_Helper_Data extends Mage_Core_Helper_Abstract
// return json_decode($result, true);
// }

// gets content from a given URL
public function getContent($url)
{
$ch = curl_init();
Expand All @@ -143,6 +147,7 @@ public function getContent($url)
return null;
}

// converts ogg files to mp3
public function convertOggToMp3($filePath, $fileName)
{
// install ffmpeg by typoing sudo apt-get install ffmpeg
Expand All @@ -160,7 +165,7 @@ public function convertOggToMp3($filePath, $fileName)
return $output;
}

// excerpt text
// excerpt a given text
public function excerpt($text, $size)
{
if (strlen($text) > $size)
Expand Down Expand Up @@ -250,7 +255,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 .'%'),
Expand Down Expand Up @@ -470,4 +475,4 @@ public function prepareFacebookOrderPayload($orderID) // TODO add link to produc

return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

// this class is used to replace Magento own class that contains a glitch
class Werules_Chatbot_Model_Adminhtml_Serialized extends Mage_Adminhtml_Model_System_Config_Backend_Serialized
{
protected function _afterLoad()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function _construct()
$this->_chatbotHelper = Mage::helper('werules_chatbot');
}

// handle messages sent from chats other than Facebook Messenger
public function foreignMessageFromSupport($chatId, $text)
{
// helpers
Expand Down Expand Up @@ -42,6 +43,7 @@ public function foreignMessageFromSupport($chatId, $text)
return false;
}

// start handling Facebook API request
public function facebookHandler()
{
// Instances the Facebook class
Expand All @@ -50,6 +52,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);
Expand All @@ -65,10 +71,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"))
Expand Down Expand Up @@ -116,6 +118,7 @@ public function facebookHandler()
return $facebook->respondSuccess();
}

// after handle, process text message
public function processText()
{
// configs
Expand Down Expand Up @@ -685,8 +688,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();

Expand Down Expand Up @@ -718,17 +721,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,
Expand All @@ -738,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(
Expand Down Expand Up @@ -844,17 +850,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,
Expand All @@ -864,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(
Expand Down Expand Up @@ -1041,7 +1050,7 @@ public function processText()
$productIDs = $category->getProductCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('visibility', 4)
->addAttributeToFilter('type_id', 'simple')
//->addAttributeToFilter('type_id', 'simple')
->getAllIds()
;
}
Expand Down Expand Up @@ -1278,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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function setWebhook($webhookUrl)
return $telegram->setWebhook($webhookUrl);
}

// start handling telegram API request
public function telegramHandler()
{
// Instances the Telegram class
Expand Down Expand Up @@ -157,6 +158,7 @@ public function telegramHandler()
return $telegram->respondSuccess();
}

// after handle, process the text message
public function processText()
{
// configs
Expand Down Expand Up @@ -801,8 +803,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();

Expand All @@ -826,7 +828,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);
Expand All @@ -835,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));
Expand Down Expand Up @@ -916,7 +919,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);
Expand All @@ -925,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));
Expand Down Expand Up @@ -1041,7 +1045,7 @@ public function processText()
$productIDs = $category->getProductCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('visibility', 4)
->addAttributeToFilter('type_id', 'simple')
//->addAttributeToFilter('type_id', 'simple')
->getAllIds();
}
else
Expand Down Expand Up @@ -1261,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));
Expand Down
Loading

0 comments on commit 227df7b

Please sign in to comment.