diff --git a/Magento2/app/code/Werules/Chatbot/Api/Data/ChatbotAPIInterface.php b/Magento2/app/code/Werules/Chatbot/Api/Data/ChatbotAPIInterface.php index 5b66509..e2538b2 100644 --- a/Magento2/app/code/Werules/Chatbot/Api/Data/ChatbotAPIInterface.php +++ b/Magento2/app/code/Werules/Chatbot/Api/Data/ChatbotAPIInterface.php @@ -24,18 +24,18 @@ interface ChatbotAPIInterface { - const CHATBOTUSER_ID = 'chatbotuser_id'; + const UPDATED_AT = 'updated_at'; + const CHAT_ID = 'chat_id'; const LAST_COMMAND_DETAILS = 'last_command_details'; - const FALLBACK_QTY = 'fallback_qty'; - const CHATBOTAPI_ID = 'chatbotapi_id'; const CREATED_AT = 'created_at'; - const LOGGED = 'logged'; - const CONVERSATION_STATE = 'conversation_state'; const HASH_KEY = 'hash_key'; + const CHATBOTAPI_ID = 'chatbotapi_id'; + const LOGGED = 'logged'; const CHATBOT_TYPE = 'chatbot_type'; - const UPDATED_AT = 'updated_at'; + const CONVERSATION_STATE = 'conversation_state'; + const CHATBOTUSER_ID = 'chatbotuser_id'; const ENABLED = 'enabled'; - const CHAT_ID = 'chat_id'; + const FALLBACK_QTY = 'fallback_qty'; /** diff --git a/Magento2/app/code/Werules/Chatbot/Api/Data/ChatbotUserInterface.php b/Magento2/app/code/Werules/Chatbot/Api/Data/ChatbotUserInterface.php index 74a82d9..f84709f 100644 --- a/Magento2/app/code/Werules/Chatbot/Api/Data/ChatbotUserInterface.php +++ b/Magento2/app/code/Werules/Chatbot/Api/Data/ChatbotUserInterface.php @@ -24,15 +24,15 @@ interface ChatbotUserInterface { - const CHATBOTUSER_ID = 'chatbotuser_id'; + const UPDATED_AT = 'updated_at'; const CUSTOMER_ID = 'customer_id'; - const CREATED_AT = 'created_at'; - const SESSION_ID = 'session_id'; - const ENABLE_SUPPORT = 'enable_support'; const QUOTE_ID = 'quote_id'; const ADMIN = 'admin'; - const UPDATED_AT = 'updated_at'; + const ENABLE_SUPPORT = 'enable_support'; + const CREATED_AT = 'created_at'; const ENABLE_PROMOTIONAL_MESSAGES = 'enable_promotional_messages'; + const SESSION_ID = 'session_id'; + const CHATBOTUSER_ID = 'chatbotuser_id'; /** diff --git a/Magento2/app/code/Werules/Chatbot/Api/Data/MessageInterface.php b/Magento2/app/code/Werules/Chatbot/Api/Data/MessageInterface.php index d9b874b..534afdd 100644 --- a/Magento2/app/code/Werules/Chatbot/Api/Data/MessageInterface.php +++ b/Magento2/app/code/Werules/Chatbot/Api/Data/MessageInterface.php @@ -24,19 +24,19 @@ interface MessageInterface { - const CONTENT = 'content'; + const DIRECTION = 'direction'; + const UPDATED_AT = 'updated_at'; + const CHAT_MESSAGE_ID = 'chat_message_id'; const CONTENT_TYPE = 'content_type'; - const SENT_AT = 'sent_at'; - const STATUS = 'status'; - const MESSAGE_ID = 'message_id'; const CREATED_AT = 'created_at'; - const SENDER_ID = 'sender_id'; - const DIRECTION = 'direction'; + const SENT_AT = 'sent_at'; const CHATBOT_TYPE = 'chatbot_type'; - const UPDATED_AT = 'updated_at'; + const MESSAGE_ID = 'message_id'; const MESSAGE_PAYLOAD = 'message_payload'; - const CHAT_MESSAGE_ID = 'chat_message_id'; + const SENDER_ID = 'sender_id'; + const CONTENT = 'content'; const CURRENT_COMMAND_DETAILS = 'current_command_details'; + const STATUS = 'status'; /** diff --git a/Magento2/app/code/Werules/Chatbot/Api/Data/PromotionalMessagesInterface.php b/Magento2/app/code/Werules/Chatbot/Api/Data/PromotionalMessagesInterface.php new file mode 100644 index 0000000..eaedfad --- /dev/null +++ b/Magento2/app/code/Werules/Chatbot/Api/Data/PromotionalMessagesInterface.php @@ -0,0 +1,98 @@ +. + */ + +namespace Werules\Chatbot\Api\Data; + +interface PromotionalMessagesInterface +{ + + const UPDATED_AT = 'updated_at'; + const CONTENT = 'content'; + const CREATED_AT = 'created_at'; + const STATUS = 'status'; + const PROMOTIONALMESSAGES_ID = 'promotionalmessages_id'; + + + /** + * Get promotionalmessages_id + * @return string|null + */ + public function getPromotionalmessagesId(); + + /** + * Set promotionalmessages_id + * @param string $promotionalmessages_id + * @return \Werules\Chatbot\Api\Data\PromotionalMessagesInterface + */ + public function setPromotionalmessagesId($promotionalmessagesId); + + /** + * Get content + * @return string|null + */ + public function getContent(); + + /** + * Set content + * @param string $content + * @return \Werules\Chatbot\Api\Data\PromotionalMessagesInterface + */ + public function setContent($content); + + /** + * Get created_at + * @return string|null + */ + public function getCreatedAt(); + + /** + * Set created_at + * @param string $created_at + * @return \Werules\Chatbot\Api\Data\PromotionalMessagesInterface + */ + public function setCreatedAt($created_at); + + /** + * Get updated_at + * @return string|null + */ + public function getUpdatedAt(); + + /** + * Set updated_at + * @param string $updated_at + * @return \Werules\Chatbot\Api\Data\PromotionalMessagesInterface + */ + public function setUpdatedAt($updated_at); + + /** + * Get status + * @return string|null + */ + public function getStatus(); + + /** + * Set status + * @param string $status + * @return \Werules\Chatbot\Api\Data\PromotionalMessagesInterface + */ + public function setStatus($status); +} diff --git a/Magento2/app/code/Werules/Chatbot/Api/Data/PromotionalMessagesSearchResultsInterface.php b/Magento2/app/code/Werules/Chatbot/Api/Data/PromotionalMessagesSearchResultsInterface.php new file mode 100644 index 0000000..edc85f2 --- /dev/null +++ b/Magento2/app/code/Werules/Chatbot/Api/Data/PromotionalMessagesSearchResultsInterface.php @@ -0,0 +1,40 @@ +. + */ + +namespace Werules\Chatbot\Api\Data; + +interface PromotionalMessagesSearchResultsInterface extends \Magento\Framework\Api\SearchResultsInterface +{ + + + /** + * Get PromotionalMessages list. + * @return \Werules\Chatbot\Api\Data\PromotionalMessagesInterface[] + */ + public function getItems(); + + /** + * Set content list. + * @param \Werules\Chatbot\Api\Data\PromotionalMessagesInterface[] $items + * @return $this + */ + public function setItems(array $items); +} diff --git a/Magento2/app/code/Werules/Chatbot/Api/PromotionalMessagesRepositoryInterface.php b/Magento2/app/code/Werules/Chatbot/Api/PromotionalMessagesRepositoryInterface.php new file mode 100644 index 0000000..047a22f --- /dev/null +++ b/Magento2/app/code/Werules/Chatbot/Api/PromotionalMessagesRepositoryInterface.php @@ -0,0 +1,76 @@ +. + */ + +namespace Werules\Chatbot\Api; + +use Magento\Framework\Api\SearchCriteriaInterface; + +interface PromotionalMessagesRepositoryInterface +{ + + + /** + * Save PromotionalMessages + * @param \Werules\Chatbot\Api\Data\PromotionalMessagesInterface $promotionalMessages + * @return \Werules\Chatbot\Api\Data\PromotionalMessagesInterface + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function save( + \Werules\Chatbot\Api\Data\PromotionalMessagesInterface $promotionalMessages + ); + + /** + * Retrieve PromotionalMessages + * @param string $promotionalmessagesId + * @return \Werules\Chatbot\Api\Data\PromotionalMessagesInterface + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function getById($promotionalmessagesId); + + /** + * Retrieve PromotionalMessages matching the specified criteria. + * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria + * @return \Werules\Chatbot\Api\Data\PromotionalMessagesSearchResultsInterface + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function getList( + \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria + ); + + /** + * Delete PromotionalMessages + * @param \Werules\Chatbot\Api\Data\PromotionalMessagesInterface $promotionalMessages + * @return bool true on success + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function delete( + \Werules\Chatbot\Api\Data\PromotionalMessagesInterface $promotionalMessages + ); + + /** + * Delete PromotionalMessages by ID + * @param string $promotionalmessagesId + * @return bool true on success + * @throws \Magento\Framework\Exception\NoSuchEntityException + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function deleteById($promotionalmessagesId); +} diff --git a/Magento2/app/code/Werules/Chatbot/Block/Adminhtml/PromotionalMessages/Edit/BackButton.php b/Magento2/app/code/Werules/Chatbot/Block/Adminhtml/PromotionalMessages/Edit/BackButton.php new file mode 100644 index 0000000..47a4547 --- /dev/null +++ b/Magento2/app/code/Werules/Chatbot/Block/Adminhtml/PromotionalMessages/Edit/BackButton.php @@ -0,0 +1,51 @@ +. + */ + +namespace Werules\Chatbot\Block\Adminhtml\PromotionalMessages\Edit; + +use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface; + +class BackButton extends GenericButton implements ButtonProviderInterface +{ + + /** + * @return array + */ + public function getButtonData() + { + return [ + 'label' => __('Back'), + 'on_click' => sprintf("location.href = '%s';", $this->getBackUrl()), + 'class' => 'back', + 'sort_order' => 10 + ]; + } + + /** + * Get URL for back (reset) button + * + * @return string + */ + public function getBackUrl() + { + return $this->getUrl('*/*/'); + } +} diff --git a/Magento2/app/code/Werules/Chatbot/Block/Adminhtml/PromotionalMessages/Edit/DeleteButton.php b/Magento2/app/code/Werules/Chatbot/Block/Adminhtml/PromotionalMessages/Edit/DeleteButton.php new file mode 100644 index 0000000..0516e5d --- /dev/null +++ b/Magento2/app/code/Werules/Chatbot/Block/Adminhtml/PromotionalMessages/Edit/DeleteButton.php @@ -0,0 +1,57 @@ +. + */ + +namespace Werules\Chatbot\Block\Adminhtml\PromotionalMessages\Edit; + +use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface; + +class DeleteButton extends GenericButton implements ButtonProviderInterface +{ + + /** + * @return array + */ + public function getButtonData() + { + $data = []; + if ($this->getModelId()) { + $data = [ + 'label' => __('Delete Promotionalmessages'), + 'class' => 'delete', + 'on_click' => 'deleteConfirm(\'' . __( + 'Are you sure you want to do this?' + ) . '\', \'' . $this->getDeleteUrl() . '\')', + 'sort_order' => 20, + ]; + } + return $data; + } + + /** + * Get URL for delete button + * + * @return string + */ + public function getDeleteUrl() + { + return $this->getUrl('*/*/delete', ['promotionalmessages_id' => $this->getModelId()]); + } +} diff --git a/Magento2/app/code/Werules/Chatbot/Block/Adminhtml/PromotionalMessages/Edit/GenericButton.php b/Magento2/app/code/Werules/Chatbot/Block/Adminhtml/PromotionalMessages/Edit/GenericButton.php new file mode 100644 index 0000000..0bd824d --- /dev/null +++ b/Magento2/app/code/Werules/Chatbot/Block/Adminhtml/PromotionalMessages/Edit/GenericButton.php @@ -0,0 +1,60 @@ +. + */ + +namespace Werules\Chatbot\Block\Adminhtml\PromotionalMessages\Edit; + +use Magento\Backend\Block\Widget\Context; + +abstract class GenericButton +{ + + protected $context; + + /** + * @param \Magento\Backend\Block\Widget\Context $context + */ + public function __construct(Context $context) + { + $this->context = $context; + } + + /** + * Return model ID + * + * @return int|null + */ + public function getModelId() + { + return $this->context->getRequest()->getParam('promotionalmessages_id'); + } + + /** + * Generate url by route and parameters + * + * @param string $route + * @param array $params + * @return string + */ + public function getUrl($route = '', $params = []) + { + return $this->context->getUrlBuilder()->getUrl($route, $params); + } +} diff --git a/Magento2/app/code/Werules/Chatbot/Block/Adminhtml/PromotionalMessages/Edit/SaveAndContinueButton.php b/Magento2/app/code/Werules/Chatbot/Block/Adminhtml/PromotionalMessages/Edit/SaveAndContinueButton.php new file mode 100644 index 0000000..cfc5ac2 --- /dev/null +++ b/Magento2/app/code/Werules/Chatbot/Block/Adminhtml/PromotionalMessages/Edit/SaveAndContinueButton.php @@ -0,0 +1,45 @@ +. + */ + +namespace Werules\Chatbot\Block\Adminhtml\PromotionalMessages\Edit; + +use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface; + +class SaveAndContinueButton extends GenericButton implements ButtonProviderInterface +{ + + /** + * @return array + */ + public function getButtonData() + { + return [ + 'label' => __('Save and Continue Edit'), + 'class' => 'save', + 'data_attribute' => [ + 'mage-init' => [ + 'button' => ['event' => 'saveAndContinueEdit'], + ], + ], + 'sort_order' => 80, + ]; + } +} diff --git a/Magento2/app/code/Werules/Chatbot/Block/Adminhtml/PromotionalMessages/Edit/SaveButton.php b/Magento2/app/code/Werules/Chatbot/Block/Adminhtml/PromotionalMessages/Edit/SaveButton.php new file mode 100644 index 0000000..c7fe296 --- /dev/null +++ b/Magento2/app/code/Werules/Chatbot/Block/Adminhtml/PromotionalMessages/Edit/SaveButton.php @@ -0,0 +1,44 @@ +. + */ + +namespace Werules\Chatbot\Block\Adminhtml\PromotionalMessages\Edit; + +use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface; + +class SaveButton extends GenericButton implements ButtonProviderInterface +{ + + /** + * @return array + */ + public function getButtonData() + { + return [ + 'label' => __('Save Promotionalmessages'), + 'class' => 'save primary', + 'data_attribute' => [ + 'mage-init' => ['button' => ['event' => 'save']], + 'form-role' => 'save', + ], + 'sort_order' => 90, + ]; + } +} diff --git a/Magento2/app/code/Werules/Chatbot/Block/Chatbox/Messenger.php b/Magento2/app/code/Werules/Chatbot/Block/Chatbox/Messenger.php new file mode 100644 index 0000000..ae0352a --- /dev/null +++ b/Magento2/app/code/Werules/Chatbot/Block/Chatbox/Messenger.php @@ -0,0 +1,121 @@ +. + */ + +namespace Werules\Chatbot\Block\Chatbox; + +class Messenger extends \Magento\Framework\View\Element\Template +{ + protected $_helper; + protected $_define; + protected $_chatbotAPI; + protected $_store; + + public function __construct( + \Magento\Framework\View\Element\Template\Context $context, + \Werules\Chatbot\Helper\Data $helperData, + \Magento\Store\Api\Data\StoreInterface $store, + \Werules\Chatbot\Model\ChatbotAPI $chatbotAPI, + array $data = array() + ) + { + $this->_chatbotAPI = $chatbotAPI; + $this->_helper = $helperData; + $this->_store = $store; + $this->_define = new \Werules\Chatbot\Helper\Define; + parent::__construct($context, $data); + } + + private function getMessengerInstance() + { + $api_token = $this->_helper->getConfigValue('werules_chatbot_messenger/general/api_key'); + $messenger = $this->_chatbotAPI->initMessengerAPI($api_token); + return $messenger; + } + + public function getFacebookPageId() + { + $pageId = $this->getConfigValue('werules_chatbot_messenger/general/page_id'); + if ($pageId) + return $pageId; + + $messengerInstance = $this->getMessengerInstance(); + $pageDetails = $messengerInstance->getPageDetails(); + if (isset($pageDetails['id'])) + { + $pageId = $pageDetails['id']; + $this->setConfigValue('werules_chatbot_messenger/general/page_id', $pageId); + return $pageId; + } + + return ''; + } + + public function getFacebookAppId() + { + $appId = $this->getConfigValue('werules_chatbot_messenger/general/app_id'); + return $appId; + } + + public function isDomainWhitelisted() + { + $enable = $this->getConfigValue('werules_chatbot_messenger/general/domain_whitelisted'); + if ($enable) + return true; + + $messengerInstance = $this->getMessengerInstance(); +// $url = parse_url($_SERVER['SERVER_NAME'], PHP_URL_HOST); + $url = $_SERVER['SERVER_NAME']; + $domain = array($url); + $result = $messengerInstance->addDomainsToWhitelist($domain); + if (!isset($result['error'])) + { + $this->setConfigValue('werules_chatbot_messenger/general/domain_whitelisted', $this->_define::WHITELABELED); + return true; + } + + return false; + } + + public function isChatboxEnabled() + { + $enable = $this->getConfigValue('werules_chatbot_messenger/general/enable_messenger_box'); + $isWhitelisted = $this->isDomainWhitelisted(); + if ($enable && $isWhitelisted) + return true; + + return false; + } + + private function getConfigValue($code) + { + return $this->_helper->getConfigValue($code); + } + + private function setConfigValue($field, $value) + { + $this->_helper->setConfigValue($field, $value); + } + + public function getLocaleCode() + { + return $this->_store->getLocaleCode(); + } +} diff --git a/Magento2/app/code/Werules/Chatbot/Controller/Adminhtml/PromotionalMessages.php b/Magento2/app/code/Werules/Chatbot/Controller/Adminhtml/PromotionalMessages.php new file mode 100644 index 0000000..83d3c48 --- /dev/null +++ b/Magento2/app/code/Werules/Chatbot/Controller/Adminhtml/PromotionalMessages.php @@ -0,0 +1,54 @@ +. + */ + +namespace Werules\Chatbot\Controller\Adminhtml; + +abstract class PromotionalMessages extends \Magento\Backend\App\Action +{ + + const ADMIN_RESOURCE = 'Werules_Chatbot::top_level'; + protected $_coreRegistry; + + /** + * @param \Magento\Backend\App\Action\Context $context + * @param \Magento\Framework\Registry $coreRegistry + */ + public function __construct( + \Magento\Backend\App\Action\Context $context, + \Magento\Framework\Registry $coreRegistry + ) { + $this->_coreRegistry = $coreRegistry; + parent::__construct($context); + } + + /** + * Init page + * + * @param \Magento\Backend\Model\View\Result\Page $resultPage + */ + public function initPage($resultPage) + { + $resultPage->setActiveMenu(self::ADMIN_RESOURCE) + ->addBreadcrumb(__('Werules'), __('Werules')) + ->addBreadcrumb(__('Promotionalmessages'), __('Promotionalmessages')); + return $resultPage; + } +} diff --git a/Magento2/app/code/Werules/Chatbot/Controller/Adminhtml/PromotionalMessages/Delete.php b/Magento2/app/code/Werules/Chatbot/Controller/Adminhtml/PromotionalMessages/Delete.php new file mode 100644 index 0000000..cdc9f6f --- /dev/null +++ b/Magento2/app/code/Werules/Chatbot/Controller/Adminhtml/PromotionalMessages/Delete.php @@ -0,0 +1,60 @@ +. + */ + +namespace Werules\Chatbot\Controller\Adminhtml\PromotionalMessages; + +class Delete extends \Werules\Chatbot\Controller\Adminhtml\PromotionalMessages +{ + + /** + * Delete action + * + * @return \Magento\Framework\Controller\ResultInterface + */ + public function execute() + { + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + // check if we know what should be deleted + $id = $this->getRequest()->getParam('promotionalmessages_id'); + if ($id) { + try { + // init model and delete + $model = $this->_objectManager->create('Werules\Chatbot\Model\PromotionalMessages'); + $model->load($id); + $model->delete(); + // display success message + $this->messageManager->addSuccessMessage(__('You deleted the Promotionalmessages.')); + // go to grid + return $resultRedirect->setPath('*/*/'); + } catch (\Exception $e) { + // display error message + $this->messageManager->addErrorMessage($e->getMessage()); + // go back to edit form + return $resultRedirect->setPath('*/*/edit', ['promotionalmessages_id' => $id]); + } + } + // display error message + $this->messageManager->addErrorMessage(__('We can\'t find a Promotionalmessages to delete.')); + // go to grid + return $resultRedirect->setPath('*/*/'); + } +} diff --git a/Magento2/app/code/Werules/Chatbot/Controller/Adminhtml/PromotionalMessages/Edit.php b/Magento2/app/code/Werules/Chatbot/Controller/Adminhtml/PromotionalMessages/Edit.php new file mode 100644 index 0000000..0c1b402 --- /dev/null +++ b/Magento2/app/code/Werules/Chatbot/Controller/Adminhtml/PromotionalMessages/Edit.php @@ -0,0 +1,77 @@ +. + */ + +namespace Werules\Chatbot\Controller\Adminhtml\PromotionalMessages; + +class Edit extends \Werules\Chatbot\Controller\Adminhtml\PromotionalMessages +{ + + protected $resultPageFactory; + + /** + * @param \Magento\Backend\App\Action\Context $context + * @param \Magento\Framework\Registry $coreRegistry + * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory + */ + public function __construct( + \Magento\Backend\App\Action\Context $context, + \Magento\Framework\Registry $coreRegistry, + \Magento\Framework\View\Result\PageFactory $resultPageFactory + ) { + $this->resultPageFactory = $resultPageFactory; + parent::__construct($context, $coreRegistry); + } + + /** + * Edit action + * + * @return \Magento\Framework\Controller\ResultInterface + */ + public function execute() + { + // 1. Get ID and create model + $id = $this->getRequest()->getParam('promotionalmessages_id'); + $model = $this->_objectManager->create('Werules\Chatbot\Model\PromotionalMessages'); + + // 2. Initial checking + if ($id) { + $model->load($id); + if (!$model->getId()) { + $this->messageManager->addErrorMessage(__('This Promotionalmessages no longer exists.')); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setPath('*/*/'); + } + } + $this->_coreRegistry->register('werules_chatbot_promotionalmessages', $model); + + // 5. Build edit form + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $this->initPage($resultPage)->addBreadcrumb( + $id ? __('Edit Promotionalmessages') : __('New Promotionalmessages'), + $id ? __('Edit Promotionalmessages') : __('New Promotionalmessages') + ); + $resultPage->getConfig()->getTitle()->prepend(__('Promotionalmessagess')); + $resultPage->getConfig()->getTitle()->prepend($model->getId() ? $model->getTitle() : __('New Promotionalmessages')); + return $resultPage; + } +} diff --git a/Magento2/app/code/Werules/Chatbot/Controller/Adminhtml/PromotionalMessages/Index.php b/Magento2/app/code/Werules/Chatbot/Controller/Adminhtml/PromotionalMessages/Index.php new file mode 100644 index 0000000..9a5151f --- /dev/null +++ b/Magento2/app/code/Werules/Chatbot/Controller/Adminhtml/PromotionalMessages/Index.php @@ -0,0 +1,54 @@ +. + */ + +namespace Werules\Chatbot\Controller\Adminhtml\PromotionalMessages; + +class Index extends \Magento\Backend\App\Action +{ + + protected $resultPageFactory; + + /** + * Constructor + * + * @param \Magento\Backend\App\Action\Context $context + * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory + */ + public function __construct( + \Magento\Backend\App\Action\Context $context, + \Magento\Framework\View\Result\PageFactory $resultPageFactory + ) { + $this->resultPageFactory = $resultPageFactory; + parent::__construct($context); + } + + /** + * Index action + * + * @return \Magento\Framework\Controller\ResultInterface + */ + public function execute() + { + $resultPage = $this->resultPageFactory->create(); + $resultPage->getConfig()->getTitle()->prepend(__("PromotionalMessages")); + return $resultPage; + } +} diff --git a/Magento2/app/code/Werules/Chatbot/Controller/Adminhtml/PromotionalMessages/InlineEdit.php b/Magento2/app/code/Werules/Chatbot/Controller/Adminhtml/PromotionalMessages/InlineEdit.php new file mode 100644 index 0000000..8da56f4 --- /dev/null +++ b/Magento2/app/code/Werules/Chatbot/Controller/Adminhtml/PromotionalMessages/InlineEdit.php @@ -0,0 +1,78 @@ +. + */ + +namespace Werules\Chatbot\Controller\Adminhtml\PromotionalMessages; + +class InlineEdit extends \Magento\Backend\App\Action +{ + + protected $jsonFactory; + + /** + * @param \Magento\Backend\App\Action\Context $context + * @param \Magento\Framework\Controller\Result\JsonFactory $jsonFactory + */ + public function __construct( + \Magento\Backend\App\Action\Context $context, + \Magento\Framework\Controller\Result\JsonFactory $jsonFactory + ) { + parent::__construct($context); + $this->jsonFactory = $jsonFactory; + } + + /** + * Inline edit action + * + * @return \Magento\Framework\Controller\ResultInterface + */ + public function execute() + { + /** @var \Magento\Framework\Controller\Result\Json $resultJson */ + $resultJson = $this->jsonFactory->create(); + $error = false; + $messages = []; + + if ($this->getRequest()->getParam('isAjax')) { + $postItems = $this->getRequest()->getParam('items', []); + if (!count($postItems)) { + $messages[] = __('Please correct the data sent.'); + $error = true; + } else { + foreach (array_keys($postItems) as $modelid) { + /** @var \Werules\Chatbot\Model\PromotionalMessages $model */ + $model = $this->_objectManager->create('Werules\Chatbot\Model\PromotionalMessages')->load($modelid); + try { + $model->setData(array_merge($model->getData(), $postItems[$modelid])); + $model->save(); + } catch (\Exception $e) { + $messages[] = "[Promotionalmessages ID: {$modelid}] {$e->getMessage()}"; + $error = true; + } + } + } + } + + return $resultJson->setData([ + 'messages' => $messages, + 'error' => $error + ]); + } +} diff --git a/Magento2/app/code/Werules/Chatbot/Controller/Adminhtml/PromotionalMessages/NewAction.php b/Magento2/app/code/Werules/Chatbot/Controller/Adminhtml/PromotionalMessages/NewAction.php new file mode 100644 index 0000000..d3837b0 --- /dev/null +++ b/Magento2/app/code/Werules/Chatbot/Controller/Adminhtml/PromotionalMessages/NewAction.php @@ -0,0 +1,54 @@ +. + */ + +namespace Werules\Chatbot\Controller\Adminhtml\PromotionalMessages; + +class NewAction extends \Werules\Chatbot\Controller\Adminhtml\PromotionalMessages +{ + + protected $resultForwardFactory; + + /** + * @param \Magento\Backend\App\Action\Context $context + * @param \Magento\Framework\Registry $coreRegistry + * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory + */ + public function __construct( + \Magento\Backend\App\Action\Context $context, + \Magento\Framework\Registry $coreRegistry, + \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory + ) { + $this->resultForwardFactory = $resultForwardFactory; + parent::__construct($context, $coreRegistry); + } + + /** + * New action + * + * @return \Magento\Framework\Controller\ResultInterface + */ + public function execute() + { + /** @var \Magento\Framework\Controller\Result\Forward $resultForward */ + $resultForward = $this->resultForwardFactory->create(); + return $resultForward->forward('edit'); + } +} diff --git a/Magento2/app/code/Werules/Chatbot/Controller/Adminhtml/PromotionalMessages/Save.php b/Magento2/app/code/Werules/Chatbot/Controller/Adminhtml/PromotionalMessages/Save.php new file mode 100644 index 0000000..ef8d80d --- /dev/null +++ b/Magento2/app/code/Werules/Chatbot/Controller/Adminhtml/PromotionalMessages/Save.php @@ -0,0 +1,98 @@ +. + */ + +namespace Werules\Chatbot\Controller\Adminhtml\PromotionalMessages; + +use Magento\Framework\Exception\LocalizedException; + +class Save extends \Magento\Backend\App\Action +{ + + protected $dataPersistor; + + /** + * @param \Magento\Backend\App\Action\Context $context + * @param \Magento\Framework\App\Request\DataPersistorInterface $dataPersistor + */ + public function __construct( + \Magento\Backend\App\Action\Context $context, + \Magento\Framework\App\Request\DataPersistorInterface $dataPersistor + ) { + $this->dataPersistor = $dataPersistor; + parent::__construct($context); + } + + /** + * Save action + * + * @return \Magento\Framework\Controller\ResultInterface + */ + public function execute() + { + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); +// $data = $this->getRequest()->getPostValue(); + $data = $this->getCompleteData($this->getRequest()->getPostValue()); + if ($data) { + $id = $this->getRequest()->getParam('promotionalmessages_id'); + + $model = $this->_objectManager->create('Werules\Chatbot\Model\PromotionalMessages')->load($id); + if (!$model->getId() && $id) { + $this->messageManager->addErrorMessage(__('This Promotionalmessages no longer exists.')); + return $resultRedirect->setPath('*/*/'); + } + $model->setData($data); + + try { + $model->save(); + $this->messageManager->addSuccessMessage(__('You saved the Promotionalmessages.')); + $this->dataPersistor->clear('werules_chatbot_promotionalmessages'); + + if ($this->getRequest()->getParam('back')) { + return $resultRedirect->setPath('*/*/edit', ['promotionalmessages_id' => $model->getId()]); + } + return $resultRedirect->setPath('*/*/'); + } catch (LocalizedException $e) { + $this->messageManager->addErrorMessage($e->getMessage()); + } catch (\Exception $e) { + $this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the Promotionalmessages.')); + } + + $this->dataPersistor->set('werules_chatbot_promotionalmessages', $data); + return $resultRedirect->setPath('*/*/edit', ['promotionalmessages_id' => $this->getRequest()->getParam('promotionalmessages_id')]); + } + return $resultRedirect->setPath('*/*/'); + } + + private function getCompleteData($data) + { + if (!$data) + return array(); + + $newData = $data; + $datetime = date('Y-m-d H:i:s'); + $newData['created_at'] = $datetime; + $newData['updated_at'] = $datetime; + $newData['status'] = 0; + + return $newData; + } +} diff --git a/Magento2/app/code/Werules/Chatbot/Cron/PromotionalMessages.php b/Magento2/app/code/Werules/Chatbot/Cron/PromotionalMessages.php new file mode 100644 index 0000000..465175d --- /dev/null +++ b/Magento2/app/code/Werules/Chatbot/Cron/PromotionalMessages.php @@ -0,0 +1,102 @@ +. + */ + +namespace Werules\Chatbot\Cron; + +class PromotionalMessages +{ + + protected $_logger; + protected $_messageModel; + protected $_promotionalMessagesModel; + protected $_helper; + protected $_define; + + /** + * Constructor + * + * @param \Psr\Log\LoggerInterface $logger + */ + public function __construct( + \Psr\Log\LoggerInterface $logger, + \Werules\Chatbot\Model\Message $message, + \Werules\Chatbot\Model\PromotionalMessages $promotionalMessages, + \Werules\Chatbot\Helper\Data $helperData, + \Werules\Chatbot\Helper\Define $define + ) + { + $this->_logger = $logger; + $this->_messageModel = $message; + $this->_promotionalMessagesModel = $promotionalMessages; + $this->_helper = $helperData; + $this->_define = $define; + } + + /** + * Execute the cron + * + * @return void + */ + public function execute() + { + $promotionalMessageCollection = $this->_promotionalMessagesModel->getCollection() + ->addFieldToFilter('status', array('eq' => $this->_define::NOT_SENT)); + + if (count($promotionalMessageCollection) > 0) + { + $uniqueMessageCollection = $this->_messageModel->getCollection()->distinct(true); + $uniqueMessageCollection->getSelect()->group('sender_id'); + foreach ($promotionalMessageCollection as $promotionalMessage) + { + $messageContent = $promotionalMessage->getContent(); + foreach ($uniqueMessageCollection as $message) + { + $chatbotUser = $this->_helper->getChatbotuserBySenderId($message->getSenderId()); + if ($chatbotUser->getEnablePromotionalMessages() == $this->_define::DISABLED) + { + $this->_helper->logger(__("Customer ID %1 choose to not receive promotional messages.", $chatbotUser->getCustomerId()), 'werules_chatbot_promotional_messages.log'); + continue; + } + + $content = array( + 'content_type' => $this->_define::CONTENT_TEXT, + 'content' => $messageContent, + 'current_command_details' => json_encode(array()), + ); + $outgoingMessage = $this->_helper->createOutgoingMessage($message, $content); + $result = $this->_helper->processOutgoingMessage($outgoingMessage); + + if ($result) + { + if ($promotionalMessage->getStatus() != $this->_define::SENT) + { + $promotionalMessage->setStatus($this->_define::SENT); + $promotionalMessage->setUpdatedAt(date('Y-m-d H:i:s')); + $promotionalMessage->save(); + } + } + else + $this->_helper->logger(__("Unable to send message to Chatbot Chat ID %1.", $message->getSenderId()), 'werules_chatbot_promotional_messages.log'); + } + } + } + } +} diff --git a/Magento2/app/code/Werules/Chatbot/Cron/Worker.php b/Magento2/app/code/Werules/Chatbot/Cron/QueueWorker.php similarity index 99% rename from Magento2/app/code/Werules/Chatbot/Cron/Worker.php rename to Magento2/app/code/Werules/Chatbot/Cron/QueueWorker.php index 59055a7..ac766e2 100644 --- a/Magento2/app/code/Werules/Chatbot/Cron/Worker.php +++ b/Magento2/app/code/Werules/Chatbot/Cron/QueueWorker.php @@ -21,12 +21,13 @@ namespace Werules\Chatbot\Cron; -class Worker +class QueueWorker { protected $_logger; protected $_messageModel; protected $_helper; + protected $_define; /** * Constructor diff --git a/Magento2/app/code/Werules/Chatbot/Helper/Data.php b/Magento2/app/code/Werules/Chatbot/Helper/Data.php index f1dfb53..eeafe6f 100644 --- a/Magento2/app/code/Werules/Chatbot/Helper/Data.php +++ b/Magento2/app/code/Werules/Chatbot/Helper/Data.php @@ -2110,7 +2110,7 @@ private function getChatbotAPIBySenderId($senderId) return $chatbotAPI; } - private function getChatbotuserBySenderId($senderId) + public function getChatbotuserBySenderId($senderId) { $chatbotAPI = $this->getChatbotAPIModelBySenderId($senderId); $chatbotUser = $this->_chatbotUserFactory->create(); diff --git a/Magento2/app/code/Werules/Chatbot/Helper/Define.php b/Magento2/app/code/Werules/Chatbot/Helper/Define.php index f605b8c..d5db115 100644 --- a/Magento2/app/code/Werules/Chatbot/Helper/Define.php +++ b/Magento2/app/code/Werules/Chatbot/Helper/Define.php @@ -33,6 +33,7 @@ class Define const OUTGOING = 1; const DISABLED = 0; const ENABLED = 1; + const WHITELABELED = 1; const NOT_LOGGED = 0; const NOT_ADMIN = 0; const ADMIN = 1; @@ -42,6 +43,8 @@ class Define const DEFAULT_MIN_CONFIDENCE = 0.7; const BREAK_LINE = '\n'; // chr(10) const QUEUE_PROCESSING_LIMIT = self::SECONDS_IN_MINUTE * 3; + const NOT_SENT = 0; + const SENT = 1; // commands const START_COMMAND_ID = 0; diff --git a/Magento2/app/code/Werules/Chatbot/Model/Api/Messenger.php b/Magento2/app/code/Werules/Chatbot/Model/Api/Messenger.php index c2c641e..d79318e 100644 --- a/Magento2/app/code/Werules/Chatbot/Model/Api/Messenger.php +++ b/Magento2/app/code/Werules/Chatbot/Model/Api/Messenger.php @@ -303,6 +303,28 @@ public function sendReceiptTemplate($chat_id, array $payload) { ); } +// $whitelist = array( +// 'www.github.com', +// 'www.facebook.com' +// ) + public function addDomainsToWhitelist(array $whitelist) { + return $this->endpoint("me/thread_settings", + array( + 'setting_type' => 'domain_whitelisting', + 'whitelisted_domains' => $whitelist, + 'domain_action_type' => 'add' + ) + ); + } + + public function getPageDetails() { + return $this->endpoint( + "me", + array(), + false + ); + } + /// Get the text of the current message public function Text() { if (isset($this->data["entry"][0]["messaging"][0]["message"]["text"])) diff --git a/Magento2/app/code/Werules/Chatbot/Model/PromotionalMessages.php b/Magento2/app/code/Werules/Chatbot/Model/PromotionalMessages.php new file mode 100644 index 0000000..9b4dc29 --- /dev/null +++ b/Magento2/app/code/Werules/Chatbot/Model/PromotionalMessages.php @@ -0,0 +1,131 @@ +. + */ + +namespace Werules\Chatbot\Model; + +use Werules\Chatbot\Api\Data\PromotionalMessagesInterface; + +class PromotionalMessages extends \Magento\Framework\Model\AbstractModel implements PromotionalMessagesInterface +{ + + /** + * @return void + */ + protected function _construct() + { + $this->_init('Werules\Chatbot\Model\ResourceModel\PromotionalMessages'); + } + + /** + * Get promotionalmessages_id + * @return string + */ + public function getPromotionalmessagesId() + { + return $this->getData(self::PROMOTIONALMESSAGES_ID); + } + + /** + * Set promotionalmessages_id + * @param string $promotionalmessagesId + * @return \Werules\Chatbot\Api\Data\PromotionalMessagesInterface + */ + public function setPromotionalmessagesId($promotionalmessagesId) + { + return $this->setData(self::PROMOTIONALMESSAGES_ID, $promotionalmessagesId); + } + + /** + * Get content + * @return string + */ + public function getContent() + { + return $this->getData(self::CONTENT); + } + + /** + * Set content + * @param string $content + * @return \Werules\Chatbot\Api\Data\PromotionalMessagesInterface + */ + public function setContent($content) + { + return $this->setData(self::CONTENT, $content); + } + + /** + * Get created_at + * @return string + */ + public function getCreatedAt() + { + return $this->getData(self::CREATED_AT); + } + + /** + * Set created_at + * @param string $created_at + * @return \Werules\Chatbot\Api\Data\PromotionalMessagesInterface + */ + public function setCreatedAt($created_at) + { + return $this->setData(self::CREATED_AT, $created_at); + } + + /** + * Get updated_at + * @return string + */ + public function getUpdatedAt() + { + return $this->getData(self::UPDATED_AT); + } + + /** + * Set updated_at + * @param string $updated_at + * @return \Werules\Chatbot\Api\Data\PromotionalMessagesInterface + */ + public function setUpdatedAt($updated_at) + { + return $this->setData(self::UPDATED_AT, $updated_at); + } + + /** + * Get status + * @return string + */ + public function getStatus() + { + return $this->getData(self::STATUS); + } + + /** + * Set status + * @param string $status + * @return \Werules\Chatbot\Api\Data\PromotionalMessagesInterface + */ + public function setStatus($status) + { + return $this->setData(self::STATUS, $status); + } +} diff --git a/Magento2/app/code/Werules/Chatbot/Model/PromotionalMessages/DataProvider.php b/Magento2/app/code/Werules/Chatbot/Model/PromotionalMessages/DataProvider.php new file mode 100644 index 0000000..e805408 --- /dev/null +++ b/Magento2/app/code/Werules/Chatbot/Model/PromotionalMessages/DataProvider.php @@ -0,0 +1,86 @@ +. + */ + +namespace Werules\Chatbot\Model\PromotionalMessages; + +use Werules\Chatbot\Model\ResourceModel\PromotionalMessages\CollectionFactory; +use Magento\Framework\App\Request\DataPersistorInterface; + +class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider +{ + + protected $collection; + + protected $dataPersistor; + + protected $loadedData; + + /** + * Constructor + * + * @param string $name + * @param string $primaryFieldName + * @param string $requestFieldName + * @param CollectionFactory $collectionFactory + * @param DataPersistorInterface $dataPersistor + * @param array $meta + * @param array $data + */ + public function __construct( + $name, + $primaryFieldName, + $requestFieldName, + CollectionFactory $collectionFactory, + DataPersistorInterface $dataPersistor, + array $meta = [], + array $data = [] + ) { + $this->collection = $collectionFactory->create(); + $this->dataPersistor = $dataPersistor; + parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data); + } + + /** + * Get data + * + * @return array + */ + public function getData() + { + if (isset($this->loadedData)) { + return $this->loadedData; + } + $items = $this->collection->getItems(); + foreach ($items as $model) { + $this->loadedData[$model->getId()] = $model->getData(); + } + $data = $this->dataPersistor->get('werules_chatbot_promotionalmessages'); + + if (!empty($data)) { + $model = $this->collection->getNewEmptyItem(); + $model->setData($data); + $this->loadedData[$model->getId()] = $model->getData(); + $this->dataPersistor->clear('werules_chatbot_promotionalmessages'); + } + + return $this->loadedData; + } +} diff --git a/Magento2/app/code/Werules/Chatbot/Model/PromotionalMessagesRepository.php b/Magento2/app/code/Werules/Chatbot/Model/PromotionalMessagesRepository.php new file mode 100644 index 0000000..92a5c2e --- /dev/null +++ b/Magento2/app/code/Werules/Chatbot/Model/PromotionalMessagesRepository.php @@ -0,0 +1,183 @@ +. + */ + +namespace Werules\Chatbot\Model; + +use Magento\Framework\Api\SortOrder; +use Magento\Framework\Exception\CouldNotSaveException; +use Werules\Chatbot\Model\ResourceModel\PromotionalMessages\CollectionFactory as PromotionalMessagesCollectionFactory; +use Magento\Store\Model\StoreManagerInterface; +use Magento\Framework\Exception\NoSuchEntityException; +use Werules\Chatbot\Model\ResourceModel\PromotionalMessages as ResourcePromotionalMessages; +use Magento\Framework\Reflection\DataObjectProcessor; +use Magento\Framework\Exception\CouldNotDeleteException; +use Werules\Chatbot\Api\Data\PromotionalMessagesInterfaceFactory; +use Werules\Chatbot\Api\PromotionalMessagesRepositoryInterface; +use Magento\Framework\Api\DataObjectHelper; +use Werules\Chatbot\Api\Data\PromotionalMessagesSearchResultsInterfaceFactory; + +class PromotionalMessagesRepository implements promotionalMessagesRepositoryInterface +{ + + protected $promotionalMessagesCollectionFactory; + + protected $dataPromotionalMessagesFactory; + + protected $dataObjectProcessor; + + private $storeManager; + + protected $dataObjectHelper; + + protected $searchResultsFactory; + + protected $resource; + + protected $promotionalMessagesFactory; + + + /** + * @param ResourcePromotionalMessages $resource + * @param PromotionalMessagesFactory $promotionalMessagesFactory + * @param PromotionalMessagesInterfaceFactory $dataPromotionalMessagesFactory + * @param PromotionalMessagesCollectionFactory $promotionalMessagesCollectionFactory + * @param PromotionalMessagesSearchResultsInterfaceFactory $searchResultsFactory + * @param DataObjectHelper $dataObjectHelper + * @param DataObjectProcessor $dataObjectProcessor + * @param StoreManagerInterface $storeManager + */ + public function __construct( + ResourcePromotionalMessages $resource, + PromotionalMessagesFactory $promotionalMessagesFactory, + PromotionalMessagesInterfaceFactory $dataPromotionalMessagesFactory, + PromotionalMessagesCollectionFactory $promotionalMessagesCollectionFactory, + PromotionalMessagesSearchResultsInterfaceFactory $searchResultsFactory, + DataObjectHelper $dataObjectHelper, + DataObjectProcessor $dataObjectProcessor, + StoreManagerInterface $storeManager + ) { + $this->resource = $resource; + $this->promotionalMessagesFactory = $promotionalMessagesFactory; + $this->promotionalMessagesCollectionFactory = $promotionalMessagesCollectionFactory; + $this->searchResultsFactory = $searchResultsFactory; + $this->dataObjectHelper = $dataObjectHelper; + $this->dataPromotionalMessagesFactory = $dataPromotionalMessagesFactory; + $this->dataObjectProcessor = $dataObjectProcessor; + $this->storeManager = $storeManager; + } + + /** + * {@inheritdoc} + */ + public function save( + \Werules\Chatbot\Api\Data\PromotionalMessagesInterface $promotionalMessages + ) { + /* if (empty($promotionalMessages->getStoreId())) { + $storeId = $this->storeManager->getStore()->getId(); + $promotionalMessages->setStoreId($storeId); + } */ + try { + $promotionalMessages->getResource()->save($promotionalMessages); + } catch (\Exception $exception) { + throw new CouldNotSaveException(__( + 'Could not save the promotionalMessages: %1', + $exception->getMessage() + )); + } + return $promotionalMessages; + } + + /** + * {@inheritdoc} + */ + public function getById($promotionalMessagesId) + { + $promotionalMessages = $this->promotionalMessagesFactory->create(); + $promotionalMessages->getResource()->load($promotionalMessages, $promotionalMessagesId); + if (!$promotionalMessages->getId()) { + throw new NoSuchEntityException(__('PromotionalMessages with id "%1" does not exist.', $promotionalMessagesId)); + } + return $promotionalMessages; + } + + /** + * {@inheritdoc} + */ + public function getList( + \Magento\Framework\Api\SearchCriteriaInterface $criteria + ) { + $collection = $this->promotionalMessagesCollectionFactory->create(); + foreach ($criteria->getFilterGroups() as $filterGroup) { + foreach ($filterGroup->getFilters() as $filter) { + if ($filter->getField() === 'store_id') { + $collection->addStoreFilter($filter->getValue(), false); + continue; + } + $condition = $filter->getConditionType() ?: 'eq'; + $collection->addFieldToFilter($filter->getField(), [$condition => $filter->getValue()]); + } + } + + $sortOrders = $criteria->getSortOrders(); + if ($sortOrders) { + /** @var SortOrder $sortOrder */ + foreach ($sortOrders as $sortOrder) { + $collection->addOrder( + $sortOrder->getField(), + ($sortOrder->getDirection() == SortOrder::SORT_ASC) ? 'ASC' : 'DESC' + ); + } + } + $collection->setCurPage($criteria->getCurrentPage()); + $collection->setPageSize($criteria->getPageSize()); + + $searchResults = $this->searchResultsFactory->create(); + $searchResults->setSearchCriteria($criteria); + $searchResults->setTotalCount($collection->getSize()); + $searchResults->setItems($collection->getItems()); + return $searchResults; + } + + /** + * {@inheritdoc} + */ + public function delete( + \Werules\Chatbot\Api\Data\PromotionalMessagesInterface $promotionalMessages + ) { + try { + $promotionalMessages->getResource()->delete($promotionalMessages); + } catch (\Exception $exception) { + throw new CouldNotDeleteException(__( + 'Could not delete the PromotionalMessages: %1', + $exception->getMessage() + )); + } + return true; + } + + /** + * {@inheritdoc} + */ + public function deleteById($promotionalMessagesId) + { + return $this->delete($this->getById($promotionalMessagesId)); + } +} diff --git a/Magento2/app/code/Werules/Chatbot/Model/ResourceModel/PromotionalMessages.php b/Magento2/app/code/Werules/Chatbot/Model/ResourceModel/PromotionalMessages.php new file mode 100644 index 0000000..bcfd9e7 --- /dev/null +++ b/Magento2/app/code/Werules/Chatbot/Model/ResourceModel/PromotionalMessages.php @@ -0,0 +1,36 @@ +. + */ + +namespace Werules\Chatbot\Model\ResourceModel; + +class PromotionalMessages extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb +{ + + /** + * Define resource model + * + * @return void + */ + protected function _construct() + { + $this->_init('werules_chatbot_promotionalmessages', 'promotionalmessages_id'); + } +} diff --git a/Magento2/app/code/Werules/Chatbot/Model/ResourceModel/PromotionalMessages/Collection.php b/Magento2/app/code/Werules/Chatbot/Model/ResourceModel/PromotionalMessages/Collection.php new file mode 100644 index 0000000..c1bacc2 --- /dev/null +++ b/Magento2/app/code/Werules/Chatbot/Model/ResourceModel/PromotionalMessages/Collection.php @@ -0,0 +1,39 @@ +. + */ + +namespace Werules\Chatbot\Model\ResourceModel\PromotionalMessages; + +class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection +{ + + /** + * Define resource model + * + * @return void + */ + protected function _construct() + { + $this->_init( + 'Werules\Chatbot\Model\PromotionalMessages', + 'Werules\Chatbot\Model\ResourceModel\PromotionalMessages' + ); + } +} diff --git a/Magento2/app/code/Werules/Chatbot/Setup/InstallSchema.php b/Magento2/app/code/Werules/Chatbot/Setup/InstallSchema.php index 725bf3a..d1c10db 100644 --- a/Magento2/app/code/Werules/Chatbot/Setup/InstallSchema.php +++ b/Magento2/app/code/Werules/Chatbot/Setup/InstallSchema.php @@ -405,6 +405,62 @@ public function install( // 'chatbotapi_id', // \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE // ); + + + $table_werules_chatbot_promotionalmessages = $setup->getConnection()->newTable($setup->getTable('werules_chatbot_promotionalmessages')); + + + $table_werules_chatbot_promotionalmessages->addColumn( + 'promotionalmessages_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + array('identity' => true,'nullable' => false,'primary' => true,'unsigned' => true,), + 'Entity ID' + ); + + + + $table_werules_chatbot_promotionalmessages->addColumn( + 'content', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 640, + ['nullable' => False], + 'Message Content' + ); + + + + $table_werules_chatbot_promotionalmessages->addColumn( + 'created_at', + \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME, + null, + [], + 'Created At' + ); + + + + $table_werules_chatbot_promotionalmessages->addColumn( + 'updated_at', + \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME, + null, + [], + 'Updated At' + ); + + + + $table_werules_chatbot_promotionalmessages->addColumn( + 'status', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['default' => 0,'nullable' => False], + 'Status' + ); + + + $setup->getConnection()->createTable($table_werules_chatbot_promotionalmessages); + $setup->getConnection()->createTable($table_werules_chatbot_chatbotapi); $setup->getConnection()->createTable($table_werules_chatbot_chatbotuser); diff --git a/Magento2/app/code/Werules/Chatbot/Setup/UpgradeData.php b/Magento2/app/code/Werules/Chatbot/Setup/UpgradeData.php index 0dd61e3..6e16c79 100644 --- a/Magento2/app/code/Werules/Chatbot/Setup/UpgradeData.php +++ b/Magento2/app/code/Werules/Chatbot/Setup/UpgradeData.php @@ -36,7 +36,7 @@ public function upgrade( ModuleContextInterface $context ) { $setup->startSetup(); - if (version_compare($context->getVersion(), "1.0.4", "<")) { + if (version_compare($context->getVersion(), "1.0.5", "<")) { //Your upgrade script } $setup->endSetup(); diff --git a/Magento2/app/code/Werules/Chatbot/Setup/UpgradeSchema.php b/Magento2/app/code/Werules/Chatbot/Setup/UpgradeSchema.php index 3381fca..bb83fe8 100644 --- a/Magento2/app/code/Werules/Chatbot/Setup/UpgradeSchema.php +++ b/Magento2/app/code/Werules/Chatbot/Setup/UpgradeSchema.php @@ -92,6 +92,55 @@ public function upgrade( ); } } +// $setup->endSetup(); + +// $setup->startSetup(); + if (version_compare($context->getVersion(), "1.0.5", "<")) { + $installer = $setup; + $installer->startSetup(); + + $table = $installer->getConnection() + ->newTable($installer->getTable('werules_chatbot_promotionalmessages')); + + $table->addColumn( + 'promotionalmessages_id', + \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, + null, + array('identity' => true,'nullable' => false,'primary' => true,'unsigned' => true,), + 'Entity ID' + ); + $table->addColumn( + 'content', + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 640, + ['nullable' => False], + 'Message Content' + ); + $table->addColumn( + 'created_at', + \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME, + null, + [], + 'Created At' + ); + $table->addColumn( + 'updated_at', + \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME, + null, + [], + 'Updated At' + ); + $table->addColumn( + 'status', + \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + ['default' => 0,'nullable' => False], + 'Status' + ); + + $installer->getConnection()->createTable($table); + $installer->endSetup(); + } $setup->endSetup(); } } diff --git a/Magento2/app/code/Werules/Chatbot/Ui/Component/Listing/Column/PromotionalMessagesActions.php b/Magento2/app/code/Werules/Chatbot/Ui/Component/Listing/Column/PromotionalMessagesActions.php new file mode 100644 index 0000000..a09a7f7 --- /dev/null +++ b/Magento2/app/code/Werules/Chatbot/Ui/Component/Listing/Column/PromotionalMessagesActions.php @@ -0,0 +1,91 @@ +. + */ + +namespace Werules\Chatbot\Ui\Component\Listing\Column; + +class PromotionalMessagesActions extends \Magento\Ui\Component\Listing\Columns\Column +{ + + const URL_PATH_EDIT = 'werules_chatbot/promotionalmessages/edit'; + const URL_PATH_DELETE = 'werules_chatbot/promotionalmessages/delete'; + const URL_PATH_DETAILS = 'werules_chatbot/promotionalmessages/details'; + protected $urlBuilder; + + /** + * @param \Magento\Framework\View\Element\UiComponent\ContextInterface $context + * @param \Magento\Framework\View\Element\UiComponentFactory $uiComponentFactory + * @param \Magento\Framework\UrlInterface $urlBuilder + * @param array $components + * @param array $data + */ + public function __construct( + \Magento\Framework\View\Element\UiComponent\ContextInterface $context, + \Magento\Framework\View\Element\UiComponentFactory $uiComponentFactory, + \Magento\Framework\UrlInterface $urlBuilder, + array $components = [], + array $data = [] + ) { + $this->urlBuilder = $urlBuilder; + parent::__construct($context, $uiComponentFactory, $components, $data); + } + + /** + * Prepare Data Source + * + * @param array $dataSource + * @return array + */ + public function prepareDataSource(array $dataSource) + { + if (isset($dataSource['data']['items'])) { + foreach ($dataSource['data']['items'] as & $item) { + if (isset($item['promotionalmessages_id'])) { + $item[$this->getData('name')] = [ + 'edit' => [ + 'href' => $this->urlBuilder->getUrl( + static::URL_PATH_EDIT, + [ + 'promotionalmessages_id' => $item['promotionalmessages_id'] + ] + ), + 'label' => __('Edit') + ], + 'delete' => [ + 'href' => $this->urlBuilder->getUrl( + static::URL_PATH_DELETE, + [ + 'promotionalmessages_id' => $item['promotionalmessages_id'] + ] + ), + 'label' => __('Delete'), + 'confirm' => [ + 'title' => __('Delete "${ $.$data.title }"'), + 'message' => __('Are you sure you wan\'t to delete a "${ $.$data.title }" record?') + ] + ] + ]; + } + } + } + + return $dataSource; + } +} diff --git a/Magento2/app/code/Werules/Chatbot/etc/acl.xml b/Magento2/app/code/Werules/Chatbot/etc/acl.xml index 1c7045a..c50f6b1 100644 --- a/Magento2/app/code/Werules/Chatbot/etc/acl.xml +++ b/Magento2/app/code/Werules/Chatbot/etc/acl.xml @@ -3,6 +3,13 @@ + + + + + + + @@ -21,12 +28,11 @@ - - - - - - + + + + + diff --git a/Magento2/app/code/Werules/Chatbot/etc/adminhtml/menu.xml b/Magento2/app/code/Werules/Chatbot/etc/adminhtml/menu.xml index c137056..603a063 100644 --- a/Magento2/app/code/Werules/Chatbot/etc/adminhtml/menu.xml +++ b/Magento2/app/code/Werules/Chatbot/etc/adminhtml/menu.xml @@ -2,8 +2,9 @@ - - - + + + + diff --git a/Magento2/app/code/Werules/Chatbot/etc/adminhtml/system.xml b/Magento2/app/code/Werules/Chatbot/etc/adminhtml/system.xml index 32be612..4e0ffad 100644 --- a/Magento2/app/code/Werules/Chatbot/etc/adminhtml/system.xml +++ b/Magento2/app/code/Werules/Chatbot/etc/adminhtml/system.xml @@ -1,7 +1,7 @@ - +
@@ -11,7 +11,7 @@ Magento Chatbot v1.0.4 +

Magento Chatbot v1.0.5

To use this module you'll have to use SSL in your store.

]]>
@@ -67,7 +67,7 @@ Magento Chatbot v1.0.4 +

Magento Chatbot v1.0.5

To use this module you'll have to use SSL in your store.

]]>
@@ -75,6 +75,11 @@ Enable Messenger bot. Magento\Config\Model\Config\Source\Enabledisable + + + Enable Hub Challenge verification. + Magento\Config\Model\Config\Source\Enabledisable + 0 @@ -82,20 +87,33 @@ Message to send when bot is disabled. Leave it empty to send no message. Please check the maximum size for messages on Messenger API, otherwise your message might not be sent. - + + + Your Facebook Application ID. + + Your page access token. - + - Facebook page username. + Facebook page username. If you don't know, leave it blank. - - - - - - + + + Facebook Page ID. If you don't know, leave it blank and we fill it for you. + + + + Is this domain whitelisted on Facebook? If not, don't worry, we'll whitelist it for you and update this setting. + Magento\Config\Model\Config\Source\Yesno + + + + Enable Messenger chat box. + Magento\Config\Model\Config\Source\Yesno + + @@ -103,7 +121,7 @@ - + @@ -111,22 +129,22 @@ - + - + - + First message the bot will send to your client. please check the maximum size for messages on Facebook API, otherwise your message might not be sent. you can use "{customername}" to send the customer name. - + @@ -135,7 +153,7 @@ Enable welcome message options. Magento\Config\Model\Config\Source\Yesno - + 1 @@ -145,27 +163,31 @@ Magento\Config\Model\Config\Backend\Serialized\ArraySerialized Werules\Chatbot\Block\Adminhtml\System\Config\Form\Field\WelcomeOptions - + + + Message will be sent when customer asks informations about the store. Please check the maximum size for messages on Facebook API, otherwise your message might not be sent. + + Message will be sent when customer asks for help. Please check the maximum size for messages on Facebook API, otherwise your message might not be sent. - + Enable command listing when customer ask for help. Magento\Config\Model\Config\Source\Yesno - + Code of the commands and it's alias. Alias must be split by comma. eg.: "support,chat,talk,sac". Magento\Config\Model\Config\Backend\Serialized\ArraySerialized Werules\Chatbot\Block\Adminhtml\System\Config\Form\Field\Commands - + Enable default replies. Magento\Config\Model\Config\Source\Yesno - + 1 @@ -174,12 +196,12 @@ Magento\Config\Model\Config\Backend\Serialized\ArraySerialized Werules\Chatbot\Block\Adminhtml\System\Config\Form\Field\DefaultReplies - + Enable Natural Language Processor replies. Magento\Config\Model\Config\Source\Yesno - + 1 @@ -187,7 +209,7 @@ validate-no-html-tags Natural Language Processor entity prefix is a prefix name to flag that the request is coming from Messenger. - + 1 @@ -196,11 +218,11 @@ Magento\Config\Model\Config\Backend\Serialized\ArraySerialized Werules\Chatbot\Block\Adminhtml\System\Config\Form\Field\NaturalLanguageProcessorReplies - + Message will be sent when the bot don't understand customer messages for the Nst time. - + @@ -209,15 +231,6 @@ input-number validate-number Number of fallbacks before sending the fallback message. - - - Enable Hub Challenge verification. - Magento\Config\Model\Config\Source\Enabledisable - - - - Message will be sent when customer asks informations about the store. Please check the maximum size for messages on Facebook API, otherwise your message might not be sent. -
@@ -227,7 +240,7 @@ Magento Chatbot v1.0.4 +

Magento Chatbot v1.0.5

To use this module you'll have to use SSL in your store.

You should only change settings here if you know what you're doing.

-