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

Commit

Permalink
ignore posts without payload or text messages
Browse files Browse the repository at this point in the history
  • Loading branch information
blopa committed Dec 10, 2017
1 parent 30d366a commit 93c5e63
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
7 changes: 6 additions & 1 deletion Magento2/app/code/Werules/Chatbot/Block/Webhook/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected function messageHandler($messageObject)
else
return $this->_helper->getJsonErrorResponse();

return $this->_helper->getJsonSuccessResponse();
return $this->getJsonSuccessResponse();
}

public function getConfigValue($code)
Expand All @@ -139,6 +139,11 @@ protected function getJsonErrorResponse()
return $this->_helper->getJsonErrorResponse();
}

protected function getJsonSuccessResponse()
{
return $this->_helper->getJsonSuccessResponse();
}

protected function logPostData($data, $file = 'werules_chatbot.log')
{
$postLog = ($this->getConfigValue('werules_chatbot_general/general/enable_post_log') == $this->_define::ENABLED);
Expand Down
10 changes: 8 additions & 2 deletions Magento2/app/code/Werules/Chatbot/Block/Webhook/Messenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ protected function processRequest()
$this->logPostData($messengerInstance->getPostData(), 'werules_chatbot_messenger.log');

$messageObject = $this->createMessageObject($messengerInstance);
$result = $this->messageHandler($messageObject);
if (isset($messageObject->content))
$result = $this->messageHandler($messageObject);
else
$result = $this->getJsonSuccessResponse(); // return success to avoid receiving the same message again
}
// }
// else
Expand All @@ -107,11 +110,14 @@ protected function getMessengerInstance()
protected function createMessageObject($messenger)
{
$messageObject = new \stdClass();
$messageObject->senderId = $messenger->ChatID();
if ($messenger->Text())
$content = $messenger->Text();
else
$content = $messenger->getPostbackTitle();
if (!$content)
return $messageObject;

$messageObject->senderId = $messenger->ChatID();
$messageObject->content = $content;
$messageObject->status = $this->_define::PROCESSING;
$messageObject->direction = $this->_define::INCOMING;
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ Go to **System > General Settings > Chatbot Settings**
- Add Messages Queue Modes
- Add option to Clear Message Queue
- Add price to product list
- Add condition to only handle messages from Messenger
- Add new configuration tab
- Fix some bugs
- Add bugs to fix later
- **v1.0.2:**
- Add Messages Queue
- Add List More command
Expand Down Expand Up @@ -268,6 +272,7 @@ A: Thank you! You can help by codding more features, creating pull requests, or
- Add Command Listing on Help Command
- Add Enable Default Replies
- Add more options to filter clearing message queue
- Add handler for other posts from Messenger

## License
MIT License
Expand Down

0 comments on commit 93c5e63

Please sign in to comment.