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 #121 from blopa/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
blopa authored Dec 4, 2017
2 parents ffd1ccd + 3ffcc2c commit e57ad34
Show file tree
Hide file tree
Showing 20 changed files with 579 additions and 242 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea
mage1.bat
mage2.bat
Magento2/TestCron.php
conf.php
packager.php
extension/
Expand Down
2 changes: 2 additions & 0 deletions Magento1_deprecated/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# 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">
Expand Down
22 changes: 18 additions & 4 deletions Magento2/app/code/Werules/Chatbot/Api/Data/ChatbotAPIInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface ChatbotAPIInterface
const CHATBOT_TYPE = 'chatbot_type';
const UPDATED_AT = 'updated_at';
const ENABLED = 'enabled';
const LAST_COMMAND_DETAILS = 'last_command_details';
const CHAT_ID = 'chat_id';


Expand All @@ -49,26 +50,26 @@ public function getChatbotapiId();
* @return \Werules\Chatbot\Api\Data\ChatbotAPIInterface
*/
public function setChatbotapiId($chatbotapiId);

/**
* Get hash_key
* @return string|null
*/
public function getHashKey();

/**
* Set hash_key
* @param string $hash_key
* @return \Werules\Chatbot\Api\Data\ChatbotAPIInterface
*/
public function setHashKey($hash_key);

/**
* Get logged
* @return string|null
*/
public function getLogged();

/**
* Set logged
* @param string $logged
Expand Down Expand Up @@ -179,4 +180,17 @@ public function getChatbotuserId();
* @return \Werules\Chatbot\Api\Data\ChatbotAPIInterface
*/
public function setChatbotuserId($chatbotuser_id);

/**
* Get last_command_details
* @return string|null
*/
public function getLastCommandDetails();

/**
* Set last_command_details
* @param string $last_command_details
* @return \Werules\Chatbot\Api\Data\ChatbotAPIInterface
*/
public function setLastCommandDetails($last_command_details);
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public function toArray()
13 => __("Help"),
14 => __("About"),
15 => __("Logout"),
16 => __("Register")
16 => __("Register"),
17 => __("List More")
);
}
}
2 changes: 1 addition & 1 deletion Magento2/app/code/Werules/Chatbot/Block/Webhook/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected function messageHandler($messageObject)
} catch (\Magento\Framework\Exception\LocalizedException $e) {
return $this->_helper->getJsonErrorResponse();
}
$this->_helper->processMessage($messageModel->getMessageId());
$result = $this->_helper->processMessage($messageModel->getMessageId());

return $this->_helper->getJsonSuccessResponse();
}
Expand Down
10 changes: 5 additions & 5 deletions Magento2/app/code/Werules/Chatbot/Controller/Webhook/Index.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?php
/**
* Magento Chatbot Integration
* Copyright (C) 2017
*
* Copyright (C) 2017
*
* This file is part of Werules/Chatbot.
*
*
* Werules/Chatbot is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
Expand Down
44 changes: 25 additions & 19 deletions Magento2/app/code/Werules/Chatbot/Cron/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,30 @@ public function execute()
// ->addFieldToFilter('status', array('eq' => '0'));
// }
// }
// $processingLimit = $this->_define::SECONDS_IN_HOUR;
// $messageCollection = $this->_messageModel->getCollection()
// ->addFieldToFilter('status', array('neq' => $this->_define::PROCESSED));
// foreach ($messageCollection as $message) {
// //$this->_logger->addInfo(var_export($m->getContent(), true));
// $datetime = date('Y-m-d H:i:s');
// if ($message->getStatus() == $this->_define::NOT_PROCESSED)
// {
// $message->setStatus($this->_define::PROCESSING); // processing
// $message->setUpdatedAt($datetime);
// $message->save();
// $this->_helper->processMessage($message->getMessageId());
// }
// else if (($message->getStatus() == $this->_define::PROCESSING) && ((strtotime($datetime) - strtotime($message->getUpdatedAt())) > $processingLimit))
// {
// $this->_helper->processMessage($message->getMessageId());
// }
// }
// $this->_logger->addInfo("Cronjob Worker is executed.");
$processingLimit = $this->_define::SECONDS_IN_MINUTE * 3;
$messageCollection = $this->_messageModel->getCollection()
->addFieldToFilter('status', array('neq' => $this->_define::PROCESSED))
;
foreach ($messageCollection as $message) {
$result = true;
$datetime = date('Y-m-d H:i:s');
if ($message->getStatus() == $this->_define::NOT_PROCESSED)
{
$message->updateMessageStatus($this->_define::PROCESSING);
$result = $this->_helper->processMessage($message->getMessageId());
}
else if (($message->getStatus() == $this->_define::PROCESSING) && ((strtotime($datetime) - strtotime($message->getUpdatedAt())) > $processingLimit))
{
// if a message is in 'processing' status for more than 3 minutes, try to reprocess it
// $message->updateMessageStatus($this->_define::PROCESSING); // already on 'processing' status
$result = $this->_helper->processMessage($message->getMessageId());
}

if (!$result)
$message->updateMessageStatus($this->_define::NOT_PROCESSED);
// else
// $this->_logger->addInfo('Result of MessageID ' . $message->getMessageId() . ':\n' . var_export($result, true));
}
// $this->_logger->addInfo("Chatbot Cronjob was executed.");
}
}
Loading

0 comments on commit e57ad34

Please sign in to comment.