Chatbot_Integration - Version 0.0.9

Version Notes

Add option to send custom replies to predetermined messages.

Download this release

Release Info

Developer Pablo
Extension Chatbot_Integration
Version 0.0.9
Comparing to
See all releases


Code changes from version 0.0.5 to 0.0.9

app/code/community/Werules/Chatbot/Block/Commands.php CHANGED
@@ -1,44 +1,62 @@
1
  <?php
2
  class Werules_Chatbot_Block_Commands extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
3
  {
4
- protected $_itemRenderer;
 
5
 
6
  public function _prepareToRender()
7
  {
8
  $this->addColumn('command_id', array(
9
  'label' => Mage::helper('core')->__('Command'),
10
- 'renderer' => $this->_getRenderer()
 
 
 
 
11
  ));
12
  $this->addColumn('command_code', array(
13
  'label' => Mage::helper('core')->__('Command Code'),
14
- 'style' => 'width: 150px'
15
- ));
16
- $this->addColumn('command_alias_list', array(
17
- 'label' => Mage::helper('core')->__('Alias'),
18
- 'style' => 'width: 250px'
19
  ));
20
 
21
  $this->_addAfter = false;
22
  $this->_addButtonLabel = Mage::helper('core')->__('Add');
23
  }
24
 
25
- protected function _getRenderer()
26
  {
27
- if (!$this->_itemRenderer)
28
  {
29
- $this->_itemRenderer = $this->getLayout()->createBlock(
30
  'werules_chatbot/commandsSelect',
31
  '',
32
  array('is_render_to_js_template' => true)
33
- )->setExtraParams("style='width: auto;'");
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  }
35
- return $this->_itemRenderer;
36
  }
37
 
38
  protected function _prepareArrayRow(Varien_Object $row)
39
  {
40
  $row->setData(
41
- 'option_extra_attr_' . $this->_getRenderer()->calcOptionHash($row->getData('command_id')),
 
 
 
 
42
  'selected="selected"'
43
  );
44
  }
1
  <?php
2
  class Werules_Chatbot_Block_Commands extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
3
  {
4
+ protected $_itemRendererCommands;
5
+ protected $_itemRendererEnable;
6
 
7
  public function _prepareToRender()
8
  {
9
  $this->addColumn('command_id', array(
10
  'label' => Mage::helper('core')->__('Command'),
11
+ 'renderer' => $this->_getRendererCommands()
12
+ ));
13
+ $this->addColumn('enable_command', array(
14
+ 'label' => Mage::helper('core')->__('Enable Command'),
15
+ 'renderer' => $this->_getRendererEnable()
16
  ));
17
  $this->addColumn('command_code', array(
18
  'label' => Mage::helper('core')->__('Command Code'),
19
+ 'style' => 'width: 100%'
 
 
 
 
20
  ));
21
 
22
  $this->_addAfter = false;
23
  $this->_addButtonLabel = Mage::helper('core')->__('Add');
24
  }
25
 
26
+ protected function _getRendererCommands()
27
  {
28
+ if (!$this->_itemRendererCommands)
29
  {
30
+ $this->_itemRendererCommands = $this->getLayout()->createBlock(
31
  'werules_chatbot/commandsSelect',
32
  '',
33
  array('is_render_to_js_template' => true)
34
+ )->setExtraParams("style='width: 100%;'");
35
+ }
36
+ return $this->_itemRendererCommands;
37
+ }
38
+
39
+ protected function _getRendererEnable()
40
+ {
41
+ if (!$this->_itemRendererEnable)
42
+ {
43
+ $this->_itemRendererEnable = $this->getLayout()->createBlock(
44
+ 'werules_chatbot/enable',
45
+ '',
46
+ array('is_render_to_js_template' => true)
47
+ )->setExtraParams("style='width: 100%;'");
48
  }
49
+ return $this->_itemRendererEnable;
50
  }
51
 
52
  protected function _prepareArrayRow(Varien_Object $row)
53
  {
54
  $row->setData(
55
+ 'option_extra_attr_' . $this->_getRendererCommands()->calcOptionHash($row->getData('command_id')),
56
+ 'selected="selected"'
57
+ );
58
+ $row->setData(
59
+ 'option_extra_attr_' . $this->_getRendererEnable()->calcOptionHash($row->getData('enable_command')),
60
  'selected="selected"'
61
  );
62
  }
app/code/community/Werules/Chatbot/Block/Replies.php CHANGED
@@ -1,51 +1,98 @@
1
  <?php
2
  class Werules_Chatbot_Block_Replies extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
3
  {
4
- protected $_itemRenderer;
 
 
5
 
6
  public function _prepareToRender()
7
  {
8
- $this->addColumn('catch_phrase', array(
9
- 'label' => Mage::helper('core')->__('Phrase'),
10
  'style' => 'width: 250px'
11
  ));
12
- $this->addColumn('reply_phrase', array(
13
- 'label' => Mage::helper('core')->__('Reply'),
14
- 'style' => 'width: 250px'
 
 
 
 
 
 
 
 
15
  ));
16
  $this->addColumn('similarity', array(
17
  'label' => Mage::helper('core')->__('Similarity (%)'),
18
- 'style' => 'width: 50px',
19
  //'type' => 'number',
20
  //'maxlength' => '3',
21
  'class' => 'input-number validate-number validate-number-range number-range-1-100'
22
  ));
23
- $this->addColumn('match_case', array(
24
- 'label' => Mage::helper('core')->__('Match Case'),
25
- 'renderer' => $this->_getRenderer()
26
  ));
27
 
28
  $this->_addAfter = false;
29
  $this->_addButtonLabel = Mage::helper('core')->__('Add');
30
  }
31
 
32
- protected function _getRenderer()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  {
34
- if (!$this->_itemRenderer)
35
  {
36
- $this->_itemRenderer = $this->getLayout()->createBlock(
37
  'werules_chatbot/enable',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  '',
39
  array('is_render_to_js_template' => true)
40
  )->setExtraParams("style='width: auto;'");
41
  }
42
- return $this->_itemRenderer;
43
  }
44
 
45
  protected function _prepareArrayRow(Varien_Object $row)
46
  {
47
  $row->setData(
48
- 'option_extra_attr_' . $this->_getRenderer()->calcOptionHash($row->getData('match_case')),
 
 
 
 
 
 
 
 
49
  'selected="selected"'
50
  );
51
  }
1
  <?php
2
  class Werules_Chatbot_Block_Replies extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
3
  {
4
+ protected $_itemRendererEnableCase;
5
+ protected $_itemRendererEnableProcessing;
6
+ protected $_itemRendererReplyMode;
7
 
8
  public function _prepareToRender()
9
  {
10
+ $this->addColumn('match_sintax', array(
11
+ 'label' => Mage::helper('core')->__('Match Text or Regular Expression'),
12
  'style' => 'width: 250px'
13
  ));
14
+ $this->addColumn('match_case', array(
15
+ 'label' => Mage::helper('core')->__('Match Case'),
16
+ 'renderer' => $this->_getRendererEnableCase()
17
+ ));
18
+ $this->addColumn('stop_processing', array(
19
+ 'label' => Mage::helper('core')->__('Stop Processing'),
20
+ 'renderer' => $this->_getRendererEnableProcessing()
21
+ ));
22
+ $this->addColumn('reply_mode', array(
23
+ 'label' => Mage::helper('core')->__('Reply Mode'),
24
+ 'renderer' => $this->_getRendererReplyMode()
25
  ));
26
  $this->addColumn('similarity', array(
27
  'label' => Mage::helper('core')->__('Similarity (%)'),
28
+ 'style' => 'width: 100%',
29
  //'type' => 'number',
30
  //'maxlength' => '3',
31
  'class' => 'input-number validate-number validate-number-range number-range-1-100'
32
  ));
33
+ $this->addColumn('reply_phrase', array(
34
+ 'label' => Mage::helper('core')->__('Reply'),
35
+ 'style' => 'width: 250px'
36
  ));
37
 
38
  $this->_addAfter = false;
39
  $this->_addButtonLabel = Mage::helper('core')->__('Add');
40
  }
41
 
42
+ protected function _getRendererEnableCase()
43
+ {
44
+ if (!$this->_itemRendererEnableCase)
45
+ {
46
+ $this->_itemRendererEnableCase = $this->getLayout()->createBlock(
47
+ 'werules_chatbot/enable',
48
+ //'werules_chatbot/replyMode',
49
+ '',
50
+ array('is_render_to_js_template' => true)
51
+ )->setExtraParams("style='width: auto;'");
52
+ }
53
+ return $this->_itemRendererEnableCase;
54
+ }
55
+
56
+ protected function _getRendererEnableProcessing()
57
  {
58
+ if (!$this->_itemRendererEnableProcessing)
59
  {
60
+ $this->_itemRendererEnableProcessing = $this->getLayout()->createBlock(
61
  'werules_chatbot/enable',
62
+ //'werules_chatbot/replyMode',
63
+ '',
64
+ array('is_render_to_js_template' => true)
65
+ )->setExtraParams("style='width: 100%;'");
66
+ }
67
+ return $this->_itemRendererEnableProcessing;
68
+ }
69
+
70
+ protected function _getRendererReplyMode()
71
+ {
72
+ if (!$this->_itemRendererReplyMode)
73
+ {
74
+ $this->_itemRendererReplyMode = $this->getLayout()->createBlock(
75
+ //'werules_chatbot/enable',
76
+ 'werules_chatbot/replyMode',
77
  '',
78
  array('is_render_to_js_template' => true)
79
  )->setExtraParams("style='width: auto;'");
80
  }
81
+ return $this->_itemRendererReplyMode;
82
  }
83
 
84
  protected function _prepareArrayRow(Varien_Object $row)
85
  {
86
  $row->setData(
87
+ 'option_extra_attr_' . $this->_getRendererEnableCase()->calcOptionHash($row->getData('match_case')),
88
+ 'selected="selected"'
89
+ );
90
+ $row->setData(
91
+ 'option_extra_attr_' . $this->_getRendererEnableProcessing()->calcOptionHash($row->getData('stop_processing')),
92
+ 'selected="selected"'
93
+ );
94
+ $row->setData(
95
+ 'option_extra_attr_' . $this->_getRendererReplyMode()->calcOptionHash($row->getData('reply_mode')),
96
  'selected="selected"'
97
  );
98
  }
app/code/community/Werules/Chatbot/Block/ReplyMode.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Werules_Chatbot_Block_ReplyMode extends Mage_Core_Block_Html_Select
3
+ {
4
+ public function _toHtml()
5
+ {
6
+ $options = Mage::getSingleton('chatbot/replyMode')->toOptionArray();
7
+ if (!$this->getOptions())
8
+ {
9
+ foreach ($options as $option)
10
+ {
11
+ $this->addOption($option['value'], $option['label']);
12
+ }
13
+ }
14
+
15
+ return parent::_toHtml();
16
+ }
17
+
18
+ public function setInputName($value)
19
+ {
20
+ return $this->setName($value);
21
+ }
22
+ }
app/code/community/Werules/Chatbot/Model/Api/Facebook/Handler.php CHANGED
@@ -24,13 +24,13 @@
24
  }
25
 
26
  // mage helper
27
- $magehelper = Mage::helper('core');
28
 
29
  $apiKey = $chatdata->getApikey($chatdata->_apiType); // get facebook bot api
30
  if ($apiKey)
31
  {
32
  $facebook = new Messenger($apiKey);
33
- $message = $magehelper->__("Message from support") . ":\n" . $text;
34
  $facebook->sendMessage($chat_id, $message);
35
  return true;
36
  }
@@ -95,10 +95,10 @@
95
  if (!empty($originalText) && !empty($chatId) && $isEcho != "true")
96
  {
97
  // Instances facebook user details
98
- $user_data = $facebook->UserData($chatId);
99
  $username = null;
100
- if (!empty($user_data))
101
- $username = $user_data['first_name'];
102
 
103
  $text = strtolower($originalText);
104
 
@@ -123,49 +123,10 @@
123
  // send feedback to user
124
  $facebook->sendChatAction($chatId, "typing_on");
125
 
126
- // handle default replies
127
- if ($enableReplies == "1")
128
- {
129
- $defaultReplies = Mage::getStoreConfig('chatbot_enable/facebook_config/default_replies');
130
- if ($defaultReplies)
131
- {
132
- $replies = unserialize($defaultReplies);
133
- if (is_array($replies))
134
- {
135
- foreach($replies as $reply)
136
- {
137
- $match = $reply["catch_phrase"];
138
- $similarity = $reply["similarity"];
139
- if (is_numeric($similarity))
140
- {
141
- if (!($similarity >= 1 && $similarity <= 100))
142
- $similarity = 100;
143
- }
144
- else
145
- $similarity = 100;
146
-
147
- if ($reply["match_case"] == "0")
148
- {
149
- $match = strtolower($match);
150
- $text = strtolower($text);
151
- }
152
-
153
- similar_text($text, $match, $percent);
154
- if ($percent >= $similarity)
155
- {
156
- $facebook->sendMessage($chatId, $reply["reply_phrase"]);
157
- return $facebook->respondSuccess();
158
- break; // probably useless
159
- }
160
- }
161
- }
162
- }
163
- }
164
-
165
  // payload handler, may change the conversation state
166
  if ($chatdata->getFacebookConvState() == $chatdata->_listProductsState || $chatdata->getFacebookConvState() == $chatdata->_listOrdersState) // listing products
167
  {
168
- if ($chatdata->checkCommandWithValue($text, $listMoreCategories))
169
  {
170
  if ($chatdata->updateChatdata('facebook_conv_state', $chatdata->_listCategoriesState))
171
  {
@@ -175,7 +136,7 @@
175
  $showMore = (int)$arr[1];
176
  }
177
  }
178
- else if ($chatdata->checkCommandWithValue($text, $listMoreSearch))
179
  {
180
  if ($chatdata->updateChatdata('facebook_conv_state', $chatdata->_searchState))
181
  {
@@ -185,7 +146,7 @@
185
  $showMore = (int)$arr[1];
186
  }
187
  }
188
- else if ($chatdata->checkCommandWithValue($text, $listMoreOrders))
189
  {
190
  if ($chatdata->updateChatdata('facebook_conv_state', $chatdata->_listOrdersState))
191
  {
@@ -202,7 +163,7 @@
202
  $conversationState = $chatdata->getFacebookConvState();
203
 
204
  // mage helper
205
- $magehelper = Mage::helper('core');
206
 
207
  // handle admin stuff
208
  //$isAdmin = $chatdata->getIsAdmin();
@@ -224,14 +185,14 @@
224
  {
225
  // TODO IMPORTANT remember to switch off all other supports
226
  $customerData->updateChatdata('facebook_conv_state', $chatdata->_supportState);
227
- $facebook->sendMessage($customerChatId, $magehelper->__("You're now on support mode."));
228
  }
229
- $facebook->sendMessage($customerChatId, $magehelper->__("Message from support") . ":\n" . $text); // send message to customer TODO
230
- $facebook->sendMessage($chatId, $magehelper->__("Message sent."));
231
  }
232
  return $facebook->respondSuccess();
233
  }
234
- else if ($chatdata->checkCommandWithValue($text, $chatdata->_admSendMessage2AllCmd))
235
  {
236
  $message = trim($chatdata->getCommandValue($text, $chatdata->_admSendMessage2AllCmd));
237
  if (!empty($message))
@@ -243,45 +204,45 @@
243
  if ($fbChatId)
244
  $facebook->sendMessage($fbChatId, $message); // $magehelper->__("Message from support") . ":\n" .
245
  }
246
- $facebook->sendMessage($chatId, $magehelper->__("Message sent."));
247
  }
248
  else
249
- $facebook->sendMessage($chatId, $magehelper->__("Please use") . ' "' . $chatdata->_admSendMessage2AllCmd . " " . $magehelper->__("your message here.") . '"');
250
  }
251
  else if ($isPayload)
252
  {
253
- if ($chatdata->checkCommandWithValue($text, $chatdata->_admEndSupportCmd)) // finish customer support
254
  {
255
  $customerChatId = trim($chatdata->getCommandValue($text, $chatdata->_admEndSupportCmd)); // get customer chatId from payload
256
  $customerData = Mage::getModel('chatbot/chatdata')->load($customerChatId, 'facebook_chat_id'); // load chatdata model
257
  $customerData->updateChatdata('facebook_conv_state', $chatdata->_startState); // update conversation state
258
 
259
- $facebook->sendMessage($chatId, $magehelper->__("Done. The customer is no longer on support."));
260
- $facebook->sendMessage($customerChatId, $magehelper->__("Support ended."));
261
  }
262
- else if ($chatdata->checkCommandWithValue($text, $chatdata->_admBlockSupportCmd)) // block user from using support
263
  {
264
  $customerChatId = trim($chatdata->getCommandValue($text, $chatdata->_admBlockSupportCmd)); // get customer chatId from payload
265
  $customerData = Mage::getModel('chatbot/chatdata')->load($customerChatId, 'facebook_chat_id'); // load chatdata model
266
  if ($customerData->getEnableSupport() == "1")
267
  {
268
  $customerData->updateChatdata('enable_support', "0"); // disable support
269
- $facebook->sendMessage($chatId, $magehelper->__("Done. The customer is no longer able to enter support."));
270
  }
271
  else //if ($customerData->getEnableSupport() == "0")
272
  {
273
  $customerData->updateChatdata('enable_support', "1"); // enable support
274
- $facebook->sendMessage($chatId, $magehelper->__("Done. The customer is now able to enter support."));
275
  }
276
 
277
  }
278
- else if ($chatdata->checkCommandWithValue($text, $replyToCustomerMessage))
279
  {
280
  $customerChatId = trim($chatdata->getCommandValue($text, $replyToCustomerMessage)); // get customer chatId from payload
281
  $chatdata->updateChatdata('facebook_support_reply_chat_id', $customerChatId);
282
  $chatdata->updateChatdata('facebook_conv_state', $chatdata->_replyToSupportMessageState);
283
 
284
- $facebook->sendMessage($chatId, $magehelper->__("Ok, send me the message and I'll forward it to the customer."));
285
  }
286
  else if ($chatdata->checkCommand($text, $chatdata->_admSendMessage2AllCmd)) // TODO
287
  {
@@ -292,19 +253,117 @@
292
  }
293
  }
294
 
 
 
295
  if ($chatdata->getIsLogged() == "1") // check if customer is logged
296
  {
297
  if (Mage::getModel('customer/customer')->load((int)$chatdata->getCustomerId())->getId()) // if is a valid customer id
298
  {
299
  if ($chatdata->getEnableFacebook() != "1")
300
  {
301
- $facebook->sendMessage($chatId, $magehelper->__("To talk with me, please enable Facebook Messenger on your account chatbot settings."));
302
  $facebook->sendChatAction($chatId, "typing_off");
303
  return $facebook->respondSuccess();
304
  }
305
  }
306
  }
307
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308
  // user isnt registred HERE
309
  if (is_null($chatdata->getFacebookChatId())) // if user isn't registred
310
  {
@@ -326,8 +385,8 @@
326
  {
327
  $facebook->sendMessage($chatId, $chatdata->_errorMessage); // TODO
328
  }
329
- $facebook->sendChatAction($chatId, "typing_off");
330
- return $facebook->respondSuccess();
331
  }
332
 
333
  // init commands
@@ -347,14 +406,15 @@
347
  $chatdata->_helpCmd = $chatdata->getCommandString(13);
348
  $chatdata->_aboutCmd = $chatdata->getCommandString(14);
349
  $chatdata->_logoutCmd = $chatdata->getCommandString(15);
 
350
  if (!$chatdata->_cancelCmd['command']) $chatdata->_cancelCmd['command'] = "cancel"; // it must always have a cancel command
351
 
352
  // init messages
353
- $chatdata->_errorMessage = $magehelper->__("Something went wrong, please try again.");
354
- $chatdata->_cancelMessage = $magehelper->__("To cancel, send") . ' "' . $chatdata->_cancelCmd['command'] . '"';
355
- $chatdata->_canceledMessage = $magehelper->__("Ok, canceled.");
356
- $chatdata->_loginFirstMessage = $magehelper->__("Please login first.");
357
- array_push($chatdata->_positiveMessages, $magehelper->__("Ok"), $magehelper->__("Okay"), $magehelper->__("Cool"), $magehelper->__("Awesome"));
358
  // $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)]
359
 
360
  if ($enablePredict == "1" && !$isPayload) // prediction is enabled and itsn't payload
@@ -377,7 +437,8 @@
377
  $chatdata->_cancelCmd['command'],
378
  $chatdata->_helpCmd['command'],
379
  $chatdata->_aboutCmd['command'],
380
- $chatdata->_logoutCmd['command']
 
381
  );
382
 
383
  foreach ($cmdarray as $cmd)
@@ -400,7 +461,7 @@
400
  }
401
  else if ($conversationState == $chatdata->_supportState)
402
  {
403
- $message = $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("exiting support mode.");
404
  }
405
  else if ($conversationState == $chatdata->_searchState)
406
  {
@@ -430,19 +491,32 @@
430
  }
431
 
432
  // add2cart commands
433
- if ($chatdata->checkCommandWithValue($text, $chatdata->_add2CartCmd['command'])) // ignore alias
434
  {
435
  $errorFlag = false;
 
436
  $cmdvalue = $chatdata->getCommandValue($text, $chatdata->_add2CartCmd['command']);
437
  if ($cmdvalue) // TODO
438
  {
439
- $productName = Mage::getModel('catalog/product')->load($cmdvalue)->getName();
440
- if (empty($productName))
441
- $productName = $magehelper->__("this product");
442
- $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("adding %s to your cart.", $productName));
443
- $facebook->sendChatAction($chatId, "typing_on");
444
- if ($chatdata->addProd2Cart($cmdvalue))
445
- $facebook->sendMessage($chatId, $magehelper->__("Added. To checkout send") . ' "' . $chatdata->_checkoutCmd['command'] . '"');
 
 
 
 
 
 
 
 
 
 
 
 
446
  else
447
  $errorFlag = true;
448
  }
@@ -451,6 +525,9 @@
451
 
452
  if ($errorFlag)
453
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
 
 
 
454
  return $facebook->respondSuccess();
455
  }
456
 
@@ -458,8 +535,17 @@
458
  if ($chatdata->checkCommand($text, $chatdata->_helpCmd))
459
  {
460
  $message = Mage::getStoreConfig('chatbot_enable/facebook_config/facebook_help_msg'); // TODO
461
- if ($message) // TODO
 
462
  $facebook->sendMessage($chatId, $message);
 
 
 
 
 
 
 
 
463
  $facebook->sendChatAction($chatId, "typing_off");
464
  return $facebook->respondSuccess();
465
  }
@@ -468,75 +554,7 @@
468
  if ($chatdata->checkCommand($text, $chatdata->_aboutCmd))
469
  {
470
  $message = Mage::getStoreConfig('chatbot_enable/facebook_config/facebook_about_msg'); // TODO
471
- $cmdListing = Mage::getStoreConfig('chatbot_enable/facebook_config/enable_command_list');
472
- if ($cmdListing == 1)
473
- {
474
- $message .= "\n\n" . $magehelper->__("Command list") . ":\n";
475
- $replies = array(); // quick replies limit is 10 options
476
- // just getting the command string, not checking the command
477
- if ($chatdata->_listCategoriesCmd['command'])
478
- {
479
- array_push($replies, array('content_type' => 'text', 'title' => $chatdata->_listCategoriesCmd['command'], 'payload' => str_replace(' ', '_', $chatdata->_listCategoriesCmd['command'])));
480
- $message .= $chatdata->_listCategoriesCmd['command'] . " - " . $magehelper->__("List store categories.") . "\n";
481
- }
482
- if ($chatdata->_searchCmd['command'])
483
- {
484
- array_push($replies, array('content_type' => 'text', 'title' => $chatdata->_searchCmd['command'], 'payload' => str_replace(' ', '_', $chatdata->_searchCmd['command'])));
485
- $message .= $chatdata->_searchCmd['command'] . " - " . $magehelper->__("Search for products.") . "\n";
486
- }
487
- if ($chatdata->_loginCmd['command'])
488
- {
489
- array_push($replies, array('content_type' => 'text', 'title' => $chatdata->_loginCmd['command'], 'payload' => str_replace(' ', '_', $chatdata->_loginCmd['command'])));
490
- $message .= $chatdata->_loginCmd['command'] . " - " . $magehelper->__("Login into your account.") . "\n";
491
- }
492
- if ($chatdata->_logoutCmd['command'])
493
- {
494
- array_push($replies, array('content_type' => 'text', 'title' => $chatdata->_logoutCmd['command'], 'payload' => str_replace(' ', '_', $chatdata->_loginCmd['command'])));
495
- $message .= $chatdata->_logoutCmd['command'] . " - " . $magehelper->__("Logout from your account.") . "\n";
496
- }
497
- if ($chatdata->_listOrdersCmd['command'])
498
- {
499
- array_push($replies, array('content_type' => 'text', 'title' => $chatdata->_listOrdersCmd['command'], 'payload' => str_replace(' ', '_', $chatdata->_listOrdersCmd['command'])));
500
- $message .= $chatdata->_listOrdersCmd['command'] . " - " . $magehelper->__("List your personal orders.") . "\n";
501
- }
502
- //$message .= $chatdata->_reorderCmd['command'] . " - " . $magehelper->__("Reorder a order.") . "\n";
503
- //$message .= $chatdata->_add2CartCmd['command'] . " - " . $magehelper->__("Add product to cart.") . "\n";
504
- if ($chatdata->_checkoutCmd['command'])
505
- {
506
- array_push($replies, array('content_type' => 'text', 'title' => $chatdata->_checkoutCmd['command'], 'payload' => str_replace(' ', '_', $chatdata->_checkoutCmd['command'])));
507
- $message .= $chatdata->_checkoutCmd['command'] . " - " . $magehelper->__("Checkout your order.") . "\n";
508
- }
509
- if ($chatdata->_clearCartCmd['command'])
510
- {
511
- array_push($replies, array('content_type' => 'text', 'title' => $chatdata->_clearCartCmd['command'], 'payload' => str_replace(' ', '_', $chatdata->_clearCartCmd['command'])));
512
- $message .= $chatdata->_clearCartCmd['command'] . " - " . $magehelper->__("Clear your cart.") . "\n";
513
- }
514
- if ($chatdata->_trackOrderCmd['command'])
515
- {
516
- array_push($replies, array('content_type' => 'text', 'title' => $chatdata->_trackOrderCmd['command'], 'payload' => str_replace(' ', '_', $chatdata->_trackOrderCmd['command'])));
517
- $message .= $chatdata->_trackOrderCmd['command'] . " - " . $magehelper->__("Track your order status.") . "\n";
518
- }
519
- if ($chatdata->_supportCmd['command'])
520
- {
521
- array_push($replies, array('content_type' => 'text', 'title' => $chatdata->_supportCmd['command'], 'payload' => str_replace(' ', '_', $chatdata->_supportCmd['command'])));
522
- $message .= $chatdata->_supportCmd['command'] . " - " . $magehelper->__("Send message to support.") . "\n";
523
- }
524
- if ($chatdata->_sendEmailCmd['command'])
525
- {
526
- array_push($replies, array('content_type' => 'text', 'title' => $chatdata->_sendEmailCmd['command'], 'payload' => str_replace(' ', '_', $chatdata->_sendEmailCmd['command'])));
527
- $message .= $chatdata->_sendEmailCmd['command'] . " - " . $magehelper->__("Send email.") . "\n";
528
- }
529
- //$message .= $chatdata->_cancelCmd['command'] . " - " . $magehelper->__("Cancel.");
530
- if ($chatdata->_helpCmd['command'])
531
- {
532
- array_push($replies, array('content_type' => 'text', 'title' => $chatdata->_helpCmd['command'], 'payload' => str_replace(' ', '_', $chatdata->_helpCmd['command'])));
533
- $message .= $chatdata->_helpCmd['command'] . " - " . $magehelper->__("Get help.") . "\n";
534
- }
535
- //$message .= $chatdata->_aboutCmd['command'] . " - " . $magehelper->__("About.");
536
-
537
- $facebook->sendQuickReply($chatId, $message, $replies);
538
- }
539
- else
540
  $facebook->sendMessage($chatId, $message);
541
 
542
  $facebook->sendChatAction($chatId, "typing_off");
@@ -547,9 +565,9 @@
547
  if ($conversationState == $chatdata->_listCategoriesState) // TODO show only in stock products
548
  {
549
  if ($showMore == 0) // show only in the first time
550
- $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("please wait while I gather all products from %s for you.", $text));
551
  else
552
- $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("listing more."));
553
 
554
  $facebook->sendChatAction($chatId, "typing_on");
555
  $_category = Mage::getModel('catalog/category')->loadByAttribute('name', $text);
@@ -559,11 +577,12 @@
559
  if ($_category->getId()) // check if is a valid category
560
  {
561
  $noProductFlag = false;
562
- $productIDs = $_category->getProductCollection()
563
  ->addAttributeToSelect('*')
564
  ->addAttributeToFilter('visibility', 4)
565
- ->addAttributeToFilter('type_id', 'simple')
566
- ->getAllIds();
 
567
 
568
  $elements = array();
569
  if ($productIDs)
@@ -576,9 +595,9 @@
576
  if ($showMore == 0)
577
  {
578
  if ($total == 1)
579
- $facebook->sendMessage($chatId, $magehelper->__("Done. This category has only one product.", $total));
580
  else
581
- $facebook->sendMessage($chatId, $magehelper->__("Done. This category has %s products.", $total));
582
  }
583
 
584
  $placeholder = Mage::getSingleton("catalog/product_media_config")->getBaseMediaUrl() . DS . "placeholder" . DS . Mage::getStoreConfig("catalog/placeholder/thumbnail_placeholder");
@@ -587,27 +606,27 @@
587
  if ($i >= $showMore)
588
  {
589
  $product = Mage::getModel('catalog/product')->load($productID);
590
- $product_url = $product->getProductUrl();
591
- $product_image = $product->getImageUrl();
592
- if (empty($product_image))
593
- $product_image = $placeholder;
594
 
595
  $button = array(
596
  array(
597
  'type' => 'postback',
598
- 'title' => $magehelper->__("Add to cart"),
599
  'payload' => $chatdata->_add2CartCmd['command'] . $productID
600
  ),
601
  array(
602
  'type' => 'web_url',
603
- 'url' => $product_url,
604
- 'title' => $magehelper->__("Visit product's page")
605
  )
606
  );
607
  $element = array(
608
  'title' => $product->getName(),
609
- 'item_url' => $product_url,
610
- 'image_url' => $product_image,
611
  'subtitle' => $chatdata->excerpt($product->getShortDescription(), 60),
612
  'buttons' => $button
613
  );
@@ -619,7 +638,7 @@
619
  $button = array(
620
  array(
621
  'type' => 'postback',
622
- 'title' => $magehelper->__("Show more"),
623
  'payload' => $listMoreCategories . $text . "," . (string)($i + 1)
624
  )
625
  );
@@ -638,7 +657,7 @@
638
  }
639
  else if (($i + 1) == $total) // if it's the last one, back to _startState
640
  {
641
- $facebook->sendMessage($chatId, $magehelper->__("And that was the last one."));
642
  if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_startState))
643
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
644
  }
@@ -655,7 +674,7 @@
655
  $noProductFlag = true;
656
 
657
  if ($noProductFlag)
658
- $facebook->sendMessage($chatId, $magehelper->__("Sorry, no products found in this category."));
659
  else
660
  $facebook->sendGenericTemplate($chatId, $elements);
661
  }
@@ -675,9 +694,9 @@
675
  else if ($conversationState == $chatdata->_searchState)
676
  {
677
  if ($showMore == 0) // show only in the first time
678
- $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("please wait while I search for '%s' for you.", $text));
679
  else
680
- $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("listing more."));
681
 
682
  $facebook->sendChatAction($chatId, "typing_on");
683
  $errorFlag = false;
@@ -698,9 +717,9 @@
698
  if ($showMore == 0)
699
  {
700
  if ($total == 1)
701
- $facebook->sendMessage($chatId, $magehelper->__("Done. I've found only one product for your criteria.", $total));
702
  else
703
- $facebook->sendMessage($chatId, $magehelper->__("Done. I've found %s products for your criteria.", $total));
704
  }
705
 
706
  $placeholder = Mage::getSingleton("catalog/product_media_config")->getBaseMediaUrl() . DS . "placeholder" . DS . Mage::getStoreConfig("catalog/placeholder/thumbnail_placeholder");
@@ -713,27 +732,27 @@
713
  if ($i >= $showMore)
714
  {
715
  $product = Mage::getModel('catalog/product')->load($productID);
716
- $product_url = $product->getProductUrl();
717
- $product_image = $product->getImageUrl();
718
- if (empty($product_image))
719
- $product_image = $placeholder;
720
 
721
  $button = array(
722
  array(
723
  'type' => 'postback',
724
- 'title' => $magehelper->__("Add to cart"),
725
  'payload' => $chatdata->_add2CartCmd['command'] . $productID
726
  ),
727
  array(
728
  'type' => 'web_url',
729
- 'url' => $product_url,
730
- 'title' => $magehelper->__("Visit product's page")
731
  )
732
  );
733
  $element = array(
734
  'title' => $product->getName(),
735
- 'item_url' => $product_url,
736
- 'image_url' => $product_image,
737
  'subtitle' => $chatdata->excerpt($product->getShortDescription(), 60),
738
  'buttons' => $button
739
  );
@@ -745,7 +764,7 @@
745
  $button = array(
746
  array(
747
  'type' => 'postback',
748
- 'title' => $magehelper->__("Show more"),
749
  'payload' => $listMoreSearch . $text . "," . (string)($i + 1)
750
  )
751
  );
@@ -764,7 +783,7 @@
764
  }
765
  else if (($i + 1) == $total) // if it's the last one, back to _startState
766
  {
767
- $facebook->sendMessage($chatId, $magehelper->__("And that was the last one."));
768
  if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_startState))
769
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
770
  }
@@ -782,7 +801,7 @@
782
  $noProductFlag = true;
783
 
784
  if ($noProductFlag)
785
- $facebook->sendMessage($chatId, $magehelper->__("Sorry, no products found for this criteria."));
786
  else if ($errorFlag)
787
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
788
  else if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_listProductsState))
@@ -807,25 +826,25 @@
807
  $buttons = array(
808
  array(
809
  'type' => 'postback',
810
- 'title' => $magehelper->__("End support"),
811
  'payload' => $chatdata->_admEndSupportCmd . $chatId
812
 
813
  ),
814
  array(
815
  'type' => 'postback',
816
- 'title' => $magehelper->__("Enable/Disable support"),
817
  'payload' => $chatdata->_admBlockSupportCmd . $chatId
818
 
819
  ),
820
  array(
821
  'type' => 'postback',
822
- 'title' => $magehelper->__("Reply this message"),
823
  'payload' => $replyToCustomerMessage . $chatId
824
 
825
  )
826
  );
827
 
828
- $message = $magehelper->__("From") . ": " . $username . "\n" . $magehelper->__("ID") . ": " . $chatId . "\n" . $text;
829
  $facebook->sendButtonTemplate($supportGroupId, $message, $buttons);
830
  $errorFlag = false;
831
  }
@@ -834,18 +853,18 @@
834
  if ($errorFlag)
835
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
836
  else
837
- $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("we have sent your message to support."));
838
  return $facebook->respondSuccess();
839
  }
840
  else if ($conversationState == $chatdata->_sendEmailState)
841
  {
842
- $facebook->sendMessage($chatId, $magehelper->__("Trying to send the email..."));
843
- if ($chatdata->sendEmail($text))
844
  {
845
- $facebook->sendMessage($chatId, $magehelper->__("Done."));
846
  }
847
  else
848
- $facebook->sendMessage($chatId, $magehelper->__("Sorry, I wasn't able to send an email this time. Please try again later."));
849
  if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_startState))
850
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
851
  return $facebook->respondSuccess();
@@ -855,14 +874,14 @@
855
  $errorFlag = false;
856
  if ($chatdata->getIsLogged() == "1")
857
  {
858
- $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("please wait while I check the status for order %s.", $text));
859
  $facebook->sendChatAction($chatId, "typing_on");
860
  $order = Mage::getModel('sales/order')->loadByIncrementId($text);
861
  if ($order->getId())
862
  {
863
  if ($order->getCustomerId() == $chatdata->getCustomerId()) // not a problem if customer dosen't exist
864
  {
865
- $facebook->sendMessage($chatId, $magehelper->__("Your order status is") . " " . $order->getStatus());
866
  }
867
  else
868
  $errorFlag = true;
@@ -875,14 +894,14 @@
875
  if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_startState))
876
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
877
  else if ($errorFlag)
878
- $facebook->sendMessage($chatId, $magehelper->__("Sorry, we couldn't find any order with this information."));
879
  return $facebook->respondSuccess();
880
  }
881
 
882
  //general commands
883
  if ($chatdata->checkCommand($text, $chatdata->_listCategoriesCmd))
884
  {
885
- $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("please wait while I gather all categories for you."));
886
  $facebook->sendChatAction($chatId, "typing_on");
887
 
888
  $categoryHelper = Mage::helper('catalog/category');
@@ -925,13 +944,13 @@
925
  }
926
  if (!empty($replies))
927
  {
928
- $message = $magehelper->__("Select a category") . ". " . $chatdata->_cancelMessage;
929
  $facebook->sendQuickReply($chatId, $message, $replies);
930
  }
931
  }
932
  else if ($i == 0)
933
  {
934
- $facebook->sendMessage($chatId, $magehelper->__("No categories available at the moment, please try again later."));
935
  if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_startState))
936
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
937
  }
@@ -944,7 +963,7 @@
944
  {
945
  $sessionId = null;
946
  $quoteId = null;
947
- $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("please wait while I prepare the checkout for you."));
948
  $facebook->sendChatAction($chatId, "typing_on");
949
  if ($chatdata->getIsLogged() == "1")
950
  {
@@ -982,17 +1001,17 @@
982
  array(
983
  'type' => 'web_url',
984
  'url' => $cartUrl,
985
- 'title' => $magehelper->__("Checkout")
986
  )
987
  );
988
  $emptyCart = false;
989
- $message = $magehelper->__("Products on cart") . ":\n";
990
  foreach ($cart->getQuote()->getItemsCollection() as $item) // TODO
991
  {
992
  $message .= $item->getQty() . "x " . $item->getProduct()->getName() . "\n" .
993
- $magehelper->__("Price") . ": " . Mage::helper('core')->currency($item->getProduct()->getPrice(), true, false) . "\n\n";
994
  }
995
- $message .= $magehelper->__("Total") . ": " . Mage::helper('core')->currency($ordersubtotal, true, false);
996
 
997
  if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_checkoutState))
998
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
@@ -1003,18 +1022,20 @@
1003
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
1004
  }
1005
  if ($emptyCart)
1006
- $facebook->sendMessage($chatId, $magehelper->__("Your cart is empty."));
1007
  return $facebook->respondSuccess();
1008
  }
1009
  else if ($chatdata->checkCommand($text, $chatdata->_clearCartCmd))
1010
  {
 
 
1011
  $errorFlag = false;
1012
  if ($chatdata->clearCart())
1013
  {
1014
  if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_clearCartState))
1015
  $errorFlag = true;
1016
  else
1017
- $facebook->sendMessage($chatId, $magehelper->__("Cart cleared."));
1018
  }
1019
  else
1020
  $errorFlag = true;
@@ -1027,35 +1048,41 @@
1027
  if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_searchState))
1028
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
1029
  else
1030
- $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("what do you want to search for?") . " " . $chatdata->_cancelMessage);
1031
  return $facebook->respondSuccess();
1032
  }
1033
  else if ($chatdata->checkCommand($text, $chatdata->_loginCmd))
1034
  {
1035
  if ($chatdata->getIsLogged() != "1") // customer not logged
1036
  {
1037
- $hashlink = Mage::getUrl('chatbot/settings/index/') . "hash" . DS . $chatdata->getHashKey();
 
1038
  $buttons = array(
1039
  array(
1040
  'type' => 'web_url',
1041
- 'url' => $hashlink,
1042
- 'title' => $magehelper->__("Login")
1043
  )
1044
  );
1045
  if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_loginState))
1046
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
1047
  else
1048
- $facebook->sendButtonTemplate($chatId, $magehelper->__("To login to your account, access the link below"), $buttons);
 
 
 
 
 
1049
  }
1050
  else
1051
- $facebook->sendMessage($chatId, $magehelper->__("You're already logged."));
1052
  return $facebook->respondSuccess();
1053
  }
1054
  else if ($chatdata->checkCommand($text, $chatdata->_logoutCmd)) // TODO
1055
  {
1056
  if ($chatdata->getIsLogged() == "1")
1057
  {
1058
- $facebook->sendMessage($chatId, $magehelper->__("Ok, logging out."));
1059
  $errorFlag = false;
1060
  try
1061
  {
@@ -1072,21 +1099,30 @@
1072
  if ($errorFlag)
1073
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
1074
  else
1075
- $facebook->sendMessage($chatId, $magehelper->__("Done."));
1076
  }
1077
  else
1078
- $facebook->sendMessage($chatId, $magehelper->__("You're not logged."));
1079
 
1080
  return $facebook->respondSuccess();
1081
  }
 
 
 
 
 
 
 
 
 
1082
  else if ($chatdata->checkCommand($text, $chatdata->_listOrdersCmd) || $moreOrders)
1083
  {
1084
  if ($chatdata->getIsLogged() == "1")
1085
  {
1086
  if ($showMore == 0) // show only in the first time
1087
- $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("please wait while I gather your orders for listing."));
1088
  else
1089
- $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("listing more."));
1090
 
1091
  $facebook->sendChatAction($chatId, "typing_on");
1092
  $ordersIDs = $chatdata->getOrdersIdsFromCustomer();
@@ -1100,9 +1136,9 @@
1100
  if ($showMore == 0)
1101
  {
1102
  if ($total == 1)
1103
- $facebook->sendMessage($chatId, $magehelper->__("Done. You've only one order.", $total));
1104
  else
1105
- $facebook->sendMessage($chatId, $magehelper->__("Done. I've found %s orders.", $total));
1106
  }
1107
 
1108
  foreach($ordersIDs as $orderID)
@@ -1113,7 +1149,7 @@
1113
  {
1114
  $button = array(
1115
  'type' => 'postback',
1116
- 'title' => $magehelper->__("Reorder"),
1117
  'payload' => $chatdata->_reorderCmd['command'] . $orderID
1118
  );
1119
  array_push($buttons, $button);
@@ -1124,7 +1160,7 @@
1124
  // TODO add option to list more orders
1125
  $button = array(
1126
  'type' => 'postback',
1127
- 'title' => $magehelper->__("Show more orders"),
1128
  'payload' => $listMoreOrders . (string)($i + 1)
1129
  );
1130
  array_push($buttons, $button);
@@ -1135,7 +1171,7 @@
1135
  }
1136
  else if (($i + 1) == $total) // if it's the last one, back to _startState
1137
  {
1138
- $facebook->sendMessage($chatId, $magehelper->__("And that was the last one."));
1139
  if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_startState))
1140
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
1141
  }
@@ -1155,7 +1191,7 @@
1155
  }
1156
  else
1157
  {
1158
- $facebook->sendMessage($chatId, $magehelper->__("This account has no orders."));
1159
  return $facebook->respondSuccess();
1160
  }
1161
  }
@@ -1163,11 +1199,11 @@
1163
  $facebook->sendMessage($chatId, $chatdata->_loginFirstMessage);
1164
  return $facebook->respondSuccess();
1165
  }
1166
- else if ($chatdata->checkCommandWithValue($text, $chatdata->_reorderCmd['command'])) // ignore alias
1167
  {
1168
  if ($chatdata->getIsLogged() == "1")
1169
  {
1170
- $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("please wait while I add the products from this order to your cart."));
1171
  $facebook->sendChatAction($chatId, "typing_on");
1172
  $errorFlag = false;
1173
  $cmdvalue = $chatdata->getCommandValue($text, $chatdata->_reorderCmd['command']);
@@ -1197,7 +1233,7 @@
1197
  else if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_reorderState))
1198
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
1199
  else // success!!
1200
- $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("to checkout send") . ' "' . $chatdata->_checkoutCmd['command'] . '"');
1201
  }
1202
  else
1203
  $facebook->sendMessage($chatId, $chatdata->_loginFirstMessage);
@@ -1213,10 +1249,10 @@
1213
  if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_trackOrderState))
1214
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
1215
  else
1216
- $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("send the order number."));
1217
  }
1218
  else
1219
- $facebook->sendMessage($chatId, $magehelper->__("Your account dosen't have any orders."));
1220
  }
1221
  else
1222
  $facebook->sendMessage($chatId, $chatdata->_loginFirstMessage);
@@ -1233,13 +1269,13 @@
1233
  if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_supportState))
1234
  $errorFlag = true;
1235
  else
1236
- $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("what do you need support for?") . " " . $chatdata->_cancelMessage);
1237
  }
1238
  else
1239
- $facebook->sendMessage($chatId, $magehelper->__("You're already on support in other chat application, please close it before opening a new one."));
1240
  }
1241
  else
1242
- $facebook->sendMessage($chatId, $magehelper->__("I'm sorry, you can't ask for support now. Please try again later."));
1243
 
1244
  if ($errorFlag)
1245
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
@@ -1251,8 +1287,8 @@
1251
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
1252
  else
1253
  {
1254
- $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("write the email content."));
1255
- $facebook->sendMessage($chatId, $magehelper->__("By doing this you agree that we may contact you directly via chat message.") . " " . $chatdata->_cancelMessage);
1256
  }
1257
  return $facebook->respondSuccess();
1258
  }
@@ -1273,15 +1309,26 @@
1273
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
1274
  else
1275
  $facebook->sendMessage($chatId,
1276
- $magehelper->__("Sorry, I didn't understand that.") . " " .
1277
- $magehelper->__("Please wait while our support check your message so you can talk to a real person.") . " " .
1278
  $chatdata->_cancelMessage
1279
  ); // TODO
1280
  return $facebook->respondSuccess();
1281
  }
1282
- //else if ($enable_witai == "1"){}
1283
- else
1284
- $facebook->sendMessage($chatId, $magehelper->__("Sorry, I didn't understand that.")); // TODO
 
 
 
 
 
 
 
 
 
 
 
1285
  }
1286
  }
1287
 
24
  }
25
 
26
  // mage helper
27
+ $mageHelper = Mage::helper('core');
28
 
29
  $apiKey = $chatdata->getApikey($chatdata->_apiType); // get facebook bot api
30
  if ($apiKey)
31
  {
32
  $facebook = new Messenger($apiKey);
33
+ $message = $mageHelper->__("Message from support") . ":\n" . $text;
34
  $facebook->sendMessage($chat_id, $message);
35
  return true;
36
  }
95
  if (!empty($originalText) && !empty($chatId) && $isEcho != "true")
96
  {
97
  // Instances facebook user details
98
+ $userData = $facebook->UserData($chatId);
99
  $username = null;
100
+ if (!empty($userData))
101
+ $username = $userData['first_name'];
102
 
103
  $text = strtolower($originalText);
104
 
123
  // send feedback to user
124
  $facebook->sendChatAction($chatId, "typing_on");
125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  // payload handler, may change the conversation state
127
  if ($chatdata->getFacebookConvState() == $chatdata->_listProductsState || $chatdata->getFacebookConvState() == $chatdata->_listOrdersState) // listing products
128
  {
129
+ if ($chatdata->startsWith($text, $listMoreCategories)) // old checkCommandWithValue
130
  {
131
  if ($chatdata->updateChatdata('facebook_conv_state', $chatdata->_listCategoriesState))
132
  {
136
  $showMore = (int)$arr[1];
137
  }
138
  }
139
+ else if ($chatdata->startsWith($text, $listMoreSearch)) // old checkCommandWithValue
140
  {
141
  if ($chatdata->updateChatdata('facebook_conv_state', $chatdata->_searchState))
142
  {
146
  $showMore = (int)$arr[1];
147
  }
148
  }
149
+ else if ($chatdata->startsWith($text, $listMoreOrders)) // old checkCommandWithValue
150
  {
151
  if ($chatdata->updateChatdata('facebook_conv_state', $chatdata->_listOrdersState))
152
  {
163
  $conversationState = $chatdata->getFacebookConvState();
164
 
165
  // mage helper
166
+ $mageHelper = Mage::helper('core');
167
 
168
  // handle admin stuff
169
  //$isAdmin = $chatdata->getIsAdmin();
185
  {
186
  // TODO IMPORTANT remember to switch off all other supports
187
  $customerData->updateChatdata('facebook_conv_state', $chatdata->_supportState);
188
+ $facebook->sendMessage($customerChatId, $mageHelper->__("You're now on support mode."));
189
  }
190
+ $facebook->sendMessage($customerChatId, $mageHelper->__("Message from support") . ":\n" . $text); // send message to customer TODO
191
+ $facebook->sendMessage($chatId, $mageHelper->__("Message sent."));
192
  }
193
  return $facebook->respondSuccess();
194
  }
195
+ else if ($chatdata->startsWith($text, $chatdata->_admSendMessage2AllCmd)) // old checkCommandWithValue
196
  {
197
  $message = trim($chatdata->getCommandValue($text, $chatdata->_admSendMessage2AllCmd));
198
  if (!empty($message))
204
  if ($fbChatId)
205
  $facebook->sendMessage($fbChatId, $message); // $magehelper->__("Message from support") . ":\n" .
206
  }
207
+ $facebook->sendMessage($chatId, $mageHelper->__("Message sent."));
208
  }
209
  else
210
+ $facebook->sendMessage($chatId, $mageHelper->__("Please use") . ' "' . $chatdata->_admSendMessage2AllCmd . " " . $mageHelper->__("your message here.") . '"');
211
  }
212
  else if ($isPayload)
213
  {
214
+ if ($chatdata->startsWith($text, $chatdata->_admEndSupportCmd)) // finish customer support // old checkCommandWithValue
215
  {
216
  $customerChatId = trim($chatdata->getCommandValue($text, $chatdata->_admEndSupportCmd)); // get customer chatId from payload
217
  $customerData = Mage::getModel('chatbot/chatdata')->load($customerChatId, 'facebook_chat_id'); // load chatdata model
218
  $customerData->updateChatdata('facebook_conv_state', $chatdata->_startState); // update conversation state
219
 
220
+ $facebook->sendMessage($chatId, $mageHelper->__("Done. The customer is no longer on support."));
221
+ $facebook->sendMessage($customerChatId, $mageHelper->__("Support ended."));
222
  }
223
+ else if ($chatdata->startsWith($text, $chatdata->_admBlockSupportCmd)) // block user from using support // old checkCommandWithValue
224
  {
225
  $customerChatId = trim($chatdata->getCommandValue($text, $chatdata->_admBlockSupportCmd)); // get customer chatId from payload
226
  $customerData = Mage::getModel('chatbot/chatdata')->load($customerChatId, 'facebook_chat_id'); // load chatdata model
227
  if ($customerData->getEnableSupport() == "1")
228
  {
229
  $customerData->updateChatdata('enable_support', "0"); // disable support
230
+ $facebook->sendMessage($chatId, $mageHelper->__("Done. The customer is no longer able to enter support."));
231
  }
232
  else //if ($customerData->getEnableSupport() == "0")
233
  {
234
  $customerData->updateChatdata('enable_support', "1"); // enable support
235
+ $facebook->sendMessage($chatId, $mageHelper->__("Done. The customer is now able to enter support."));
236
  }
237
 
238
  }
239
+ else if ($chatdata->startsWith($text, $replyToCustomerMessage)) // old checkCommandWithValue
240
  {
241
  $customerChatId = trim($chatdata->getCommandValue($text, $replyToCustomerMessage)); // get customer chatId from payload
242
  $chatdata->updateChatdata('facebook_support_reply_chat_id', $customerChatId);
243
  $chatdata->updateChatdata('facebook_conv_state', $chatdata->_replyToSupportMessageState);
244
 
245
+ $facebook->sendMessage($chatId, $mageHelper->__("Ok, send me the message and I'll forward it to the customer."));
246
  }
247
  else if ($chatdata->checkCommand($text, $chatdata->_admSendMessage2AllCmd)) // TODO
248
  {
253
  }
254
  }
255
 
256
+ // ALL CUSTOMER HANDLERS GOES AFTER HERE
257
+
258
  if ($chatdata->getIsLogged() == "1") // check if customer is logged
259
  {
260
  if (Mage::getModel('customer/customer')->load((int)$chatdata->getCustomerId())->getId()) // if is a valid customer id
261
  {
262
  if ($chatdata->getEnableFacebook() != "1")
263
  {
264
+ $facebook->sendMessage($chatId, $mageHelper->__("To talk with me, please enable Facebook Messenger on your account chatbot settings."));
265
  $facebook->sendChatAction($chatId, "typing_off");
266
  return $facebook->respondSuccess();
267
  }
268
  }
269
  }
270
 
271
+ $blockerStates = (
272
+ $conversationState == $chatdata->_listCategoriesState ||
273
+ $conversationState == $chatdata->_searchState ||
274
+ $conversationState == $chatdata->_supportState ||
275
+ $conversationState == $chatdata->_sendEmailState ||
276
+ $conversationState == $chatdata->_trackOrderState
277
+ );
278
+
279
+ // handle default replies
280
+ if ($enableReplies == "1" && !$blockerStates)
281
+ {
282
+ $defaultReplies = Mage::getStoreConfig('chatbot_enable/facebook_config/default_replies');
283
+ if ($defaultReplies)
284
+ {
285
+ $replies = unserialize($defaultReplies);
286
+ if (is_array($replies))
287
+ {
288
+ foreach($replies as $reply)
289
+ {
290
+ // MODES
291
+ // 0 =>'Similarity'
292
+ // 1 =>'Starts With'
293
+ // 2 =>'Ends With'
294
+ // 3 =>'Contains'
295
+ // 4 =>'Match Regular Expression'
296
+ // 5 =>'Equals to'
297
+
298
+ $matched = false;
299
+ $match = $reply["match_sintax"];
300
+ $mode = $reply["reply_mode"];
301
+
302
+ if ($reply["match_case"] == "0")
303
+ {
304
+ $match = strtolower($match);
305
+ $textToMatch = strtolower($text);
306
+ }
307
+ else
308
+ $textToMatch = $text;
309
+
310
+ if ($mode == "0") // Similarity
311
+ {
312
+ $similarity = $reply["similarity"];
313
+ if (is_numeric($similarity))
314
+ {
315
+ if (!($similarity >= 1 && $similarity <= 100))
316
+ $similarity = 100;
317
+ }
318
+ else
319
+ $similarity = 100;
320
+
321
+ similar_text($textToMatch, $match, $percent);
322
+ if ($percent >= $similarity)
323
+ $matched = true;
324
+ }
325
+ else if ($mode == "1") // Starts With
326
+ {
327
+ if ($chatdata->startsWith($textToMatch, $match))
328
+ $matched = true;
329
+ }
330
+ else if ($mode == "2") // Ends With
331
+ {
332
+ if ($chatdata->endsWith($textToMatch, $match))
333
+ $matched = true;
334
+ }
335
+ else if ($mode == "3") // Contains
336
+ {
337
+ if (strpos($textToMatch, $match) !== false)
338
+ $matched = true;
339
+ }
340
+ else if ($mode == "4") // Match Regular Expression
341
+ {
342
+ // if ($match[0] != "/")
343
+ // $match = "/" . $match;
344
+ // if ((substr($match, -1) != "/") && ($match[strlen($match) - 2] != "/"))
345
+ // $match .= "/";
346
+ if (preg_match($match, $textToMatch))
347
+ $matched = true;
348
+ }
349
+ else if ($mode == "5") // Equals to
350
+ {
351
+ if ($textToMatch == $match)
352
+ $matched = true;
353
+ }
354
+
355
+ if ($matched)
356
+ {
357
+ $facebook->sendMessage($chatId, $reply["reply_phrase"]);
358
+ if ($reply["stop_processing"] == "1")
359
+ return $facebook->respondSuccess();
360
+ break;
361
+ }
362
+ }
363
+ }
364
+ }
365
+ }
366
+
367
  // user isnt registred HERE
368
  if (is_null($chatdata->getFacebookChatId())) // if user isn't registred
369
  {
385
  {
386
  $facebook->sendMessage($chatId, $chatdata->_errorMessage); // TODO
387
  }
388
+ //$facebook->sendChatAction($chatId, "typing_off");
389
+ //return $facebook->respondSuccess(); // commented to keep processing the message
390
  }
391
 
392
  // init commands
406
  $chatdata->_helpCmd = $chatdata->getCommandString(13);
407
  $chatdata->_aboutCmd = $chatdata->getCommandString(14);
408
  $chatdata->_logoutCmd = $chatdata->getCommandString(15);
409
+ $chatdata->_registerCmd = $chatdata->getCommandString(16);
410
  if (!$chatdata->_cancelCmd['command']) $chatdata->_cancelCmd['command'] = "cancel"; // it must always have a cancel command
411
 
412
  // init messages
413
+ $chatdata->_errorMessage = $mageHelper->__("Something went wrong, please try again.");
414
+ $chatdata->_cancelMessage = $mageHelper->__("To cancel, send") . ' "' . $chatdata->_cancelCmd['command'] . '"';
415
+ $chatdata->_canceledMessage = $mageHelper->__("Ok, canceled.");
416
+ $chatdata->_loginFirstMessage = $mageHelper->__("Please login first.");
417
+ array_push($chatdata->_positiveMessages, $mageHelper->__("Ok"), $mageHelper->__("Okay"), $mageHelper->__("Cool"), $mageHelper->__("Awesome"));
418
  // $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)]
419
 
420
  if ($enablePredict == "1" && !$isPayload) // prediction is enabled and itsn't payload
437
  $chatdata->_cancelCmd['command'],
438
  $chatdata->_helpCmd['command'],
439
  $chatdata->_aboutCmd['command'],
440
+ $chatdata->_logoutCmd['command'],
441
+ $chatdata->_registerCmd['command']
442
  );
443
 
444
  foreach ($cmdarray as $cmd)
461
  }
462
  else if ($conversationState == $chatdata->_supportState)
463
  {
464
+ $message = $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("exiting support mode.");
465
  }
466
  else if ($conversationState == $chatdata->_searchState)
467
  {
491
  }
492
 
493
  // add2cart commands
494
+ if ($chatdata->startsWith($text, $chatdata->_add2CartCmd['command'])) // ignore alias // old checkCommandWithValue
495
  {
496
  $errorFlag = false;
497
+ $notInStock = false;
498
  $cmdvalue = $chatdata->getCommandValue($text, $chatdata->_add2CartCmd['command']);
499
  if ($cmdvalue) // TODO
500
  {
501
+ $product = Mage::getModel('catalog/product')->load($cmdvalue);
502
+ if ($product->getId())
503
+ {
504
+ $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getIsInStock();
505
+ if ($stock > 0)
506
+ {
507
+ $productName = $product->getName();
508
+ if (empty($productName))
509
+ $productName = $mageHelper->__("this product");
510
+ $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("adding %s to your cart.", $productName));
511
+ $facebook->sendChatAction($chatId, "typing_on");
512
+ if ($chatdata->addProd2Cart($cmdvalue))
513
+ $facebook->sendMessage($chatId, $mageHelper->__("Added. To checkout send") . ' "' . $chatdata->_checkoutCmd['command'] . '"');
514
+ else
515
+ $errorFlag = true;
516
+ }
517
+ else
518
+ $notInStock = true;
519
+ }
520
  else
521
  $errorFlag = true;
522
  }
525
 
526
  if ($errorFlag)
527
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
528
+ else if ($notInStock)
529
+ $facebook->sendMessage($chatId, $mageHelper->__("This product is not in stock."));
530
+
531
  return $facebook->respondSuccess();
532
  }
533
 
535
  if ($chatdata->checkCommand($text, $chatdata->_helpCmd))
536
  {
537
  $message = Mage::getStoreConfig('chatbot_enable/facebook_config/facebook_help_msg'); // TODO
538
+ if (!empty($message)) // TODO
539
+ {
540
  $facebook->sendMessage($chatId, $message);
541
+ $cmdListing = Mage::getStoreConfig('chatbot_enable/facebook_config/enable_help_command_list');
542
+ if ($cmdListing == "1")
543
+ {
544
+ $content = $chatdata->listFacebookCommandsMessage();
545
+ $facebook->sendQuickReply($chatId, $content[0], $content[1]);
546
+ }
547
+ }
548
+
549
  $facebook->sendChatAction($chatId, "typing_off");
550
  return $facebook->respondSuccess();
551
  }
554
  if ($chatdata->checkCommand($text, $chatdata->_aboutCmd))
555
  {
556
  $message = Mage::getStoreConfig('chatbot_enable/facebook_config/facebook_about_msg'); // TODO
557
+ if (!empty($message))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
558
  $facebook->sendMessage($chatId, $message);
559
 
560
  $facebook->sendChatAction($chatId, "typing_off");
565
  if ($conversationState == $chatdata->_listCategoriesState) // TODO show only in stock products
566
  {
567
  if ($showMore == 0) // show only in the first time
568
+ $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("please wait while I gather all products from %s for you.", $text));
569
  else
570
+ $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("listing more."));
571
 
572
  $facebook->sendChatAction($chatId, "typing_on");
573
  $_category = Mage::getModel('catalog/category')->loadByAttribute('name', $text);
577
  if ($_category->getId()) // check if is a valid category
578
  {
579
  $noProductFlag = false;
580
+ $productCollection = $_category->getProductCollection()
581
  ->addAttributeToSelect('*')
582
  ->addAttributeToFilter('visibility', 4)
583
+ ->addAttributeToFilter('type_id', 'simple');
584
+ Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($productCollection);
585
+ $productIDs = $productCollection->getAllIds();
586
 
587
  $elements = array();
588
  if ($productIDs)
595
  if ($showMore == 0)
596
  {
597
  if ($total == 1)
598
+ $facebook->sendMessage($chatId, $mageHelper->__("Done. This category has only one product."));
599
  else
600
+ $facebook->sendMessage($chatId, $mageHelper->__("Done. This category has %s products.", $total));
601
  }
602
 
603
  $placeholder = Mage::getSingleton("catalog/product_media_config")->getBaseMediaUrl() . DS . "placeholder" . DS . Mage::getStoreConfig("catalog/placeholder/thumbnail_placeholder");
606
  if ($i >= $showMore)
607
  {
608
  $product = Mage::getModel('catalog/product')->load($productID);
609
+ $productUrl = $product->getProductUrl();
610
+ $productImage = $product->getImageUrl();
611
+ if (empty($productImage))
612
+ $productImage = $placeholder;
613
 
614
  $button = array(
615
  array(
616
  'type' => 'postback',
617
+ 'title' => $mageHelper->__("Add to cart"),
618
  'payload' => $chatdata->_add2CartCmd['command'] . $productID
619
  ),
620
  array(
621
  'type' => 'web_url',
622
+ 'url' => $productUrl,
623
+ 'title' => $mageHelper->__("Visit product's page")
624
  )
625
  );
626
  $element = array(
627
  'title' => $product->getName(),
628
+ 'item_url' => $productUrl,
629
+ 'image_url' => $productImage,
630
  'subtitle' => $chatdata->excerpt($product->getShortDescription(), 60),
631
  'buttons' => $button
632
  );
638
  $button = array(
639
  array(
640
  'type' => 'postback',
641
+ 'title' => $mageHelper->__("Show more"),
642
  'payload' => $listMoreCategories . $text . "," . (string)($i + 1)
643
  )
644
  );
657
  }
658
  else if (($i + 1) == $total) // if it's the last one, back to _startState
659
  {
660
+ $facebook->sendMessage($chatId, $mageHelper->__("And that was the last one."));
661
  if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_startState))
662
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
663
  }
674
  $noProductFlag = true;
675
 
676
  if ($noProductFlag)
677
+ $facebook->sendMessage($chatId, $mageHelper->__("Sorry, no products found in this category."));
678
  else
679
  $facebook->sendGenericTemplate($chatId, $elements);
680
  }
694
  else if ($conversationState == $chatdata->_searchState)
695
  {
696
  if ($showMore == 0) // show only in the first time
697
+ $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("please wait while I search for '%s' for you.", $text));
698
  else
699
+ $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("listing more."));
700
 
701
  $facebook->sendChatAction($chatId, "typing_on");
702
  $errorFlag = false;
717
  if ($showMore == 0)
718
  {
719
  if ($total == 1)
720
+ $facebook->sendMessage($chatId, $mageHelper->__("Done. I've found only one product for your criteria."));
721
  else
722
+ $facebook->sendMessage($chatId, $mageHelper->__("Done. I've found %s products for your criteria.", $total));
723
  }
724
 
725
  $placeholder = Mage::getSingleton("catalog/product_media_config")->getBaseMediaUrl() . DS . "placeholder" . DS . Mage::getStoreConfig("catalog/placeholder/thumbnail_placeholder");
732
  if ($i >= $showMore)
733
  {
734
  $product = Mage::getModel('catalog/product')->load($productID);
735
+ $productUrl = $product->getProductUrl();
736
+ $productImage = $product->getImageUrl();
737
+ if (empty($productImage))
738
+ $productImage = $placeholder;
739
 
740
  $button = array(
741
  array(
742
  'type' => 'postback',
743
+ 'title' => $mageHelper->__("Add to cart"),
744
  'payload' => $chatdata->_add2CartCmd['command'] . $productID
745
  ),
746
  array(
747
  'type' => 'web_url',
748
+ 'url' => $productUrl,
749
+ 'title' => $mageHelper->__("Visit product's page")
750
  )
751
  );
752
  $element = array(
753
  'title' => $product->getName(),
754
+ 'item_url' => $productUrl,
755
+ 'image_url' => $productImage,
756
  'subtitle' => $chatdata->excerpt($product->getShortDescription(), 60),
757
  'buttons' => $button
758
  );
764
  $button = array(
765
  array(
766
  'type' => 'postback',
767
+ 'title' => $mageHelper->__("Show more"),
768
  'payload' => $listMoreSearch . $text . "," . (string)($i + 1)
769
  )
770
  );
783
  }
784
  else if (($i + 1) == $total) // if it's the last one, back to _startState
785
  {
786
+ $facebook->sendMessage($chatId, $mageHelper->__("And that was the last one."));
787
  if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_startState))
788
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
789
  }
801
  $noProductFlag = true;
802
 
803
  if ($noProductFlag)
804
+ $facebook->sendMessage($chatId, $mageHelper->__("Sorry, no products found for this criteria."));
805
  else if ($errorFlag)
806
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
807
  else if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_listProductsState))
826
  $buttons = array(
827
  array(
828
  'type' => 'postback',
829
+ 'title' => $mageHelper->__("End support"),
830
  'payload' => $chatdata->_admEndSupportCmd . $chatId
831
 
832
  ),
833
  array(
834
  'type' => 'postback',
835
+ 'title' => $mageHelper->__("Enable/Disable support"),
836
  'payload' => $chatdata->_admBlockSupportCmd . $chatId
837
 
838
  ),
839
  array(
840
  'type' => 'postback',
841
+ 'title' => $mageHelper->__("Reply this message"),
842
  'payload' => $replyToCustomerMessage . $chatId
843
 
844
  )
845
  );
846
 
847
+ $message = $mageHelper->__("From") . ": " . $username . "\n" . $mageHelper->__("ID") . ": " . $chatId . "\n" . $text;
848
  $facebook->sendButtonTemplate($supportGroupId, $message, $buttons);
849
  $errorFlag = false;
850
  }
853
  if ($errorFlag)
854
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
855
  else
856
+ $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("we have sent your message to support."));
857
  return $facebook->respondSuccess();
858
  }
859
  else if ($conversationState == $chatdata->_sendEmailState)
860
  {
861
+ $facebook->sendMessage($chatId, $mageHelper->__("Trying to send the email..."));
862
+ if ($chatdata->sendEmail($text, $username))
863
  {
864
+ $facebook->sendMessage($chatId, $mageHelper->__("Done."));
865
  }
866
  else
867
+ $facebook->sendMessage($chatId, $mageHelper->__("Sorry, I wasn't able to send an email this time. Please try again later."));
868
  if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_startState))
869
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
870
  return $facebook->respondSuccess();
874
  $errorFlag = false;
875
  if ($chatdata->getIsLogged() == "1")
876
  {
877
+ $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("please wait while I check the status for order %s.", $text));
878
  $facebook->sendChatAction($chatId, "typing_on");
879
  $order = Mage::getModel('sales/order')->loadByIncrementId($text);
880
  if ($order->getId())
881
  {
882
  if ($order->getCustomerId() == $chatdata->getCustomerId()) // not a problem if customer dosen't exist
883
  {
884
+ $facebook->sendMessage($chatId, $mageHelper->__("Your order status is") . " " . $order->getStatus());
885
  }
886
  else
887
  $errorFlag = true;
894
  if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_startState))
895
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
896
  else if ($errorFlag)
897
+ $facebook->sendMessage($chatId, $mageHelper->__("Sorry, we couldn't find any order with this information."));
898
  return $facebook->respondSuccess();
899
  }
900
 
901
  //general commands
902
  if ($chatdata->checkCommand($text, $chatdata->_listCategoriesCmd))
903
  {
904
+ $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("please wait while I gather all categories for you."));
905
  $facebook->sendChatAction($chatId, "typing_on");
906
 
907
  $categoryHelper = Mage::helper('catalog/category');
944
  }
945
  if (!empty($replies))
946
  {
947
+ $message = $mageHelper->__("Select a category") . ". " . $chatdata->_cancelMessage;
948
  $facebook->sendQuickReply($chatId, $message, $replies);
949
  }
950
  }
951
  else if ($i == 0)
952
  {
953
+ $facebook->sendMessage($chatId, $mageHelper->__("No categories available at the moment, please try again later."));
954
  if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_startState))
955
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
956
  }
963
  {
964
  $sessionId = null;
965
  $quoteId = null;
966
+ $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("please wait while I prepare the checkout for you."));
967
  $facebook->sendChatAction($chatId, "typing_on");
968
  if ($chatdata->getIsLogged() == "1")
969
  {
1001
  array(
1002
  'type' => 'web_url',
1003
  'url' => $cartUrl,
1004
+ 'title' => $mageHelper->__("Checkout")
1005
  )
1006
  );
1007
  $emptyCart = false;
1008
+ $message = $mageHelper->__("Products on cart") . ":\n";
1009
  foreach ($cart->getQuote()->getItemsCollection() as $item) // TODO
1010
  {
1011
  $message .= $item->getQty() . "x " . $item->getProduct()->getName() . "\n" .
1012
+ $mageHelper->__("Price") . ": " . Mage::helper('core')->currency($item->getProduct()->getPrice(), true, false) . "\n\n";
1013
  }
1014
+ $message .= $mageHelper->__("Total") . ": " . Mage::helper('core')->currency($ordersubtotal, true, false);
1015
 
1016
  if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_checkoutState))
1017
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
1022
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
1023
  }
1024
  if ($emptyCart)
1025
+ $facebook->sendMessage($chatId, $mageHelper->__("Your cart is empty."));
1026
  return $facebook->respondSuccess();
1027
  }
1028
  else if ($chatdata->checkCommand($text, $chatdata->_clearCartCmd))
1029
  {
1030
+ $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("please wait while I clear your cart."));
1031
+ $facebook->sendChatAction($chatId, "typing_on");
1032
  $errorFlag = false;
1033
  if ($chatdata->clearCart())
1034
  {
1035
  if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_clearCartState))
1036
  $errorFlag = true;
1037
  else
1038
+ $facebook->sendMessage($chatId, $mageHelper->__("Cart cleared."));
1039
  }
1040
  else
1041
  $errorFlag = true;
1048
  if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_searchState))
1049
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
1050
  else
1051
+ $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("what do you want to search for?") . " " . $chatdata->_cancelMessage);
1052
  return $facebook->respondSuccess();
1053
  }
1054
  else if ($chatdata->checkCommand($text, $chatdata->_loginCmd))
1055
  {
1056
  if ($chatdata->getIsLogged() != "1") // customer not logged
1057
  {
1058
+ $hashUrl = Mage::getUrl('chatbot/settings/index/'); // get base module URL
1059
+ $hashUrl = strtok($hashUrl, '?') . "hash" . DS . $chatdata->getHashKey(); // remove magento parameters
1060
  $buttons = array(
1061
  array(
1062
  'type' => 'web_url',
1063
+ 'url' => $hashUrl,
1064
+ 'title' => $mageHelper->__("Login")
1065
  )
1066
  );
1067
  if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_loginState))
1068
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
1069
  else
1070
+ {
1071
+ $facebook->sendButtonTemplate(
1072
+ $chatId, $mageHelper->__("To login to your account, access the link below") . ". " .
1073
+ $mageHelper->__("If you want to logout from your account, just send") . " " . $chatdata->_logoutCmd, $buttons
1074
+ );
1075
+ }
1076
  }
1077
  else
1078
+ $facebook->sendMessage($chatId, $mageHelper->__("You're already logged."));
1079
  return $facebook->respondSuccess();
1080
  }
1081
  else if ($chatdata->checkCommand($text, $chatdata->_logoutCmd)) // TODO
1082
  {
1083
  if ($chatdata->getIsLogged() == "1")
1084
  {
1085
+ $facebook->sendMessage($chatId, $mageHelper->__("Ok, logging out."));
1086
  $errorFlag = false;
1087
  try
1088
  {
1099
  if ($errorFlag)
1100
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
1101
  else
1102
+ $facebook->sendMessage($chatId, $mageHelper->__("Done."));
1103
  }
1104
  else
1105
+ $facebook->sendMessage($chatId, $mageHelper->__("You're not logged."));
1106
 
1107
  return $facebook->respondSuccess();
1108
  }
1109
+ else if ($chatdata->checkCommand($text, $chatdata->_registerCmd)) // TODO
1110
+ {
1111
+ $registerUrl = strtok(Mage::getUrl('customer/account/create'), '?');
1112
+ if (!empty($registerUrl))
1113
+ $facebook->sendMessage($chatId, $mageHelper->__("Access %s to register a new account on our shop.", $registerUrl));
1114
+ else
1115
+ $facebook->sendMessage($chatId, $chatdata->_errorMessage);
1116
+ return $facebook->respondSuccess();
1117
+ }
1118
  else if ($chatdata->checkCommand($text, $chatdata->_listOrdersCmd) || $moreOrders)
1119
  {
1120
  if ($chatdata->getIsLogged() == "1")
1121
  {
1122
  if ($showMore == 0) // show only in the first time
1123
+ $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("please wait while I gather your orders for listing."));
1124
  else
1125
+ $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("listing more."));
1126
 
1127
  $facebook->sendChatAction($chatId, "typing_on");
1128
  $ordersIDs = $chatdata->getOrdersIdsFromCustomer();
1136
  if ($showMore == 0)
1137
  {
1138
  if ($total == 1)
1139
+ $facebook->sendMessage($chatId, $mageHelper->__("Done. You've only one order."));
1140
  else
1141
+ $facebook->sendMessage($chatId, $mageHelper->__("Done. I've found %s orders.", $total));
1142
  }
1143
 
1144
  foreach($ordersIDs as $orderID)
1149
  {
1150
  $button = array(
1151
  'type' => 'postback',
1152
+ 'title' => $mageHelper->__("Reorder"),
1153
  'payload' => $chatdata->_reorderCmd['command'] . $orderID
1154
  );
1155
  array_push($buttons, $button);
1160
  // TODO add option to list more orders
1161
  $button = array(
1162
  'type' => 'postback',
1163
+ 'title' => $mageHelper->__("Show more orders"),
1164
  'payload' => $listMoreOrders . (string)($i + 1)
1165
  );
1166
  array_push($buttons, $button);
1171
  }
1172
  else if (($i + 1) == $total) // if it's the last one, back to _startState
1173
  {
1174
+ $facebook->sendMessage($chatId, $mageHelper->__("And that was the last one."));
1175
  if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_startState))
1176
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
1177
  }
1191
  }
1192
  else
1193
  {
1194
+ $facebook->sendMessage($chatId, $mageHelper->__("This account has no orders."));
1195
  return $facebook->respondSuccess();
1196
  }
1197
  }
1199
  $facebook->sendMessage($chatId, $chatdata->_loginFirstMessage);
1200
  return $facebook->respondSuccess();
1201
  }
1202
+ else if ($chatdata->startsWith($text, $chatdata->_reorderCmd['command'])) // ignore alias // old checkCommandWithValue
1203
  {
1204
  if ($chatdata->getIsLogged() == "1")
1205
  {
1206
+ $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("please wait while I add the products from this order to your cart."));
1207
  $facebook->sendChatAction($chatId, "typing_on");
1208
  $errorFlag = false;
1209
  $cmdvalue = $chatdata->getCommandValue($text, $chatdata->_reorderCmd['command']);
1233
  else if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_reorderState))
1234
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
1235
  else // success!!
1236
+ $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("to checkout send") . ' "' . $chatdata->_checkoutCmd['command'] . '"');
1237
  }
1238
  else
1239
  $facebook->sendMessage($chatId, $chatdata->_loginFirstMessage);
1249
  if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_trackOrderState))
1250
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
1251
  else
1252
+ $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("send the order number."));
1253
  }
1254
  else
1255
+ $facebook->sendMessage($chatId, $mageHelper->__("Your account dosen't have any orders."));
1256
  }
1257
  else
1258
  $facebook->sendMessage($chatId, $chatdata->_loginFirstMessage);
1269
  if (!$chatdata->updateChatdata('facebook_conv_state', $chatdata->_supportState))
1270
  $errorFlag = true;
1271
  else
1272
+ $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("what do you need support for?") . " " . $chatdata->_cancelMessage);
1273
  }
1274
  else
1275
+ $facebook->sendMessage($chatId, $mageHelper->__("You're already on support in other chat application, please close it before opening a new one."));
1276
  }
1277
  else
1278
+ $facebook->sendMessage($chatId, $mageHelper->__("I'm sorry, you can't ask for support now. Please try again later."));
1279
 
1280
  if ($errorFlag)
1281
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
1287
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
1288
  else
1289
  {
1290
+ $facebook->sendMessage($chatId, $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("write the email content."));
1291
+ $facebook->sendMessage($chatId, $mageHelper->__("By doing this you agree that we may contact you directly via chat message.") . " " . $chatdata->_cancelMessage);
1292
  }
1293
  return $facebook->respondSuccess();
1294
  }
1309
  $facebook->sendMessage($chatId, $chatdata->_errorMessage);
1310
  else
1311
  $facebook->sendMessage($chatId,
1312
+ $mageHelper->__("Sorry, I didn't understand that.") . " " .
1313
+ $mageHelper->__("Please wait while our support check your message so you can talk to a real person.") . " " .
1314
  $chatdata->_cancelMessage
1315
  ); // TODO
1316
  return $facebook->respondSuccess();
1317
  }
1318
+ else // process cases where the customer message wasn't understandable
1319
+ {
1320
+ //if ($enable_witai == "1"){}
1321
+
1322
+ $facebook->sendMessage($chatId, $mageHelper->__("Sorry, I didn't understand that.")); // TODO
1323
+
1324
+ $cmdListingOnError = Mage::getStoreConfig('chatbot_enable/facebook_config/enable_error_command_list');
1325
+ if ($cmdListingOnError == "1")
1326
+ {
1327
+ $message = $mageHelper->__("Please try one of the following commands.");
1328
+ $content = $chatdata->listFacebookCommandsMessage();
1329
+ $facebook->sendQuickReply($chatId, $message . $content[0], $content[1]);
1330
+ }
1331
+ }
1332
  }
1333
  }
1334
 
app/code/community/Werules/Chatbot/Model/Api/Telegram/Handler.php CHANGED
@@ -29,7 +29,7 @@
29
  {
30
  $telegram = new Telegram($apiKey);
31
 
32
- $magehelper = Mage::helper('core');
33
  $supportgroup = Mage::getStoreConfig('chatbot_enable/telegram_config/telegram_support_group');
34
  if (!empty($supportgroup))
35
  {
@@ -37,7 +37,10 @@
37
  if ($supportgroup[0] == "g") // remove the 'g' from groupd id, and add '-'
38
  $supportgroup = "-" . ltrim($supportgroup, "g");
39
 
40
- $message = $magehelper->__("Message via") . " " . $api_name . ":\n" . $magehelper->__("From") . ": " . $customerName . "\n" . $text;
 
 
 
41
  $result = $telegram->sendMessage(array('chat_id' => $supportgroup, 'text' => $message));
42
  $mid = $result['result']['message_id'];
43
  if (!empty($mid))
@@ -69,12 +72,92 @@
69
  $text = $telegram->Text();
70
  $chatId = $telegram->ChatID();
71
  $messageId = $telegram->MessageID();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
  // configs
74
  //$enable_witai = Mage::getStoreConfig('chatbot_enable/witai_config/enable_witai');
75
  $enabledBot = Mage::getStoreConfig('chatbot_enable/telegram_config/enable_bot');
76
  $enableReplies = Mage::getStoreConfig('chatbot_enable/telegram_config/enable_default_replies');
77
- $enableLog = Mage::getStoreConfig('chatbot_enable/general_config/enable_post_log');
78
  $enableEmptyCategoriesListing = Mage::getStoreConfig('chatbot_enable/general_config/list_empty_categories');
79
  $enableFinalMessage2Support = Mage::getStoreConfig('chatbot_enable/general_config/enable_support_final_message');
80
  $supportGroupId = Mage::getStoreConfig('chatbot_enable/telegram_config/telegram_support_group');
@@ -82,15 +165,16 @@
82
  $cat_id = null;
83
  $moreOrders = false;
84
  $listingLimit = 5;
 
85
  $listMoreCategories = "/lmc_";
86
  $listMoreSearch = "/lms_";
87
  $listMoreOrders = "/lmo_";
88
 
89
- if ($enableLog == "1") // log all posts
90
- Mage::log("Post Data:\n" . var_export($telegram->getData(), true) . "\n\n", null, 'chatbot_telegram.log');
91
-
92
  if (!is_null($text) && !is_null($chatId))
93
  {
 
 
 
94
  // Instances the model class
95
  $chatdata = Mage::getModel('chatbot/chatdata')->load($chatId, 'telegram_chat_id');
96
  $chatdata->_apiType = $chatdata->_tgBot;
@@ -112,49 +196,10 @@
112
  // send feedback to user
113
  $telegram->sendChatAction(array('chat_id' => $chatId, 'action' => 'typing'));
114
 
115
- // handle default replies
116
- if ($enableReplies == "1")
117
- {
118
- $defaultReplies = Mage::getStoreConfig('chatbot_enable/telegram_config/default_replies');
119
- if ($defaultReplies)
120
- {
121
- $replies = unserialize($defaultReplies);
122
- if (is_array($replies))
123
- {
124
- foreach($replies as $reply)
125
- {
126
- $match = $reply["catch_phrase"];
127
- $similarity = $reply["similarity"];
128
- if (is_numeric($similarity))
129
- {
130
- if (!($similarity >= 1 && $similarity <= 100))
131
- $similarity = 100;
132
- }
133
- else
134
- $similarity = 100;
135
-
136
- if ($reply["match_case"] == "0")
137
- {
138
- $match = strtolower($match);
139
- $text = strtolower($text);
140
- }
141
-
142
- similar_text($text, $match, $percent);
143
- if ($percent >= $similarity)
144
- {
145
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $reply["reply_phrase"]));
146
- return $telegram->respondSuccess();
147
- break; // probably useless
148
- }
149
- }
150
- }
151
- }
152
- }
153
-
154
  // show more handler, may change the conversation state
155
  if ($chatdata->getTelegramConvState() == $chatdata->_listProductsState || $chatdata->getTelegramConvState() == $chatdata->_listOrdersState) // listing products
156
  {
157
- if ($chatdata->checkCommandWithValue($text, $listMoreCategories))
158
  {
159
  if ($chatdata->updateChatdata('telegram_conv_state', $chatdata->_listCategoriesState))
160
  {
@@ -164,7 +209,7 @@
164
  $showMore = (int)$arr[1]; // get where listing stopped
165
  }
166
  }
167
- else if ($chatdata->checkCommandWithValue($text, $listMoreSearch))
168
  {
169
  if ($chatdata->updateChatdata('telegram_conv_state', $chatdata->_searchState))
170
  {
@@ -175,7 +220,7 @@
175
  $text = str_replace("_", " ", $value); // get search criteria
176
  }
177
  }
178
- else if ($chatdata->checkCommandWithValue($text, $listMoreOrders))
179
  {
180
  if ($chatdata->updateChatdata('telegram_conv_state', $chatdata->_listOrdersState))
181
  {
@@ -192,7 +237,7 @@
192
  $conversationState = $chatdata->getTelegramConvState();
193
 
194
  // mage helper
195
- $magehelper = Mage::helper('core');
196
 
197
  if ($supportGroupId[0] == "g") // remove the 'g' from groupd id, and add '-'
198
  $supportGroupId = "-" . ltrim($supportGroupId, "g");
@@ -228,28 +273,28 @@
228
  {
229
  // TODO IMPORTANT remember to switch off all other supports
230
  $customerData->updateChatdata('telegram_conv_state', $chatdata->_startState);
231
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Done. The customer is no longer on support.")));
232
- $telegram->sendMessage(array('chat_id' => $replyFromUserId, 'text' => $magehelper->__("Support ended."))); // TODO
233
  }
234
  else if ($text == $admBlockSupport) // block user from using support
235
  {
236
  $customerData->updateChatdata('enable_support', "0"); // disable support
237
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Done. The customer is no longer able to enter support."))); // TODO
238
  }
239
  else if ($text == $admEnableSupport) // block user from using support
240
  {
241
  $customerData->updateChatdata('enable_support', "1"); // enable support
242
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Done. The customer is now able to enter support."))); // TODO
243
  }
244
  else // if no command, then it's replying the user
245
  {
246
  if ($customerData->getTelegramConvState() != $chatdata->_supportState) // if user isn't on support, switch to support
247
  {
248
  $customerData->updateChatdata('telegram_conv_state', $chatdata->_supportState);
249
- $telegram->sendMessage(array('chat_id' => $replyFromUserId, 'text' => $magehelper->__("You're now on support mode.")));
250
  }
251
- $telegram->sendMessage(array('chat_id' => $replyFromUserId, 'text' => $magehelper->__("Message from support") . ":\n" . $text)); // send message to customer TODO
252
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Message sent."))); // send message to admin group TODO
253
  }
254
  }
255
  }
@@ -258,7 +303,7 @@
258
  {
259
  $admSend2All = "/" . $chatdata->_admSendMessage2AllCmd;
260
 
261
- if ($chatdata->checkCommandWithValue($text, $admSend2All))
262
  {
263
  $message = trim($chatdata->getCommandValue($text, $admSend2All));
264
  if (!empty($message))
@@ -270,34 +315,132 @@
270
  if ($tgChatId)
271
  $telegram->sendMessage(array('chat_id' => $tgChatId, 'text' => $message)); // $magehelper->__("Message from support") . ":\n" .
272
  }
273
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Message sent.")));
274
  }
275
  else
276
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Please use") . ' "' . $admSend2All . " " . $magehelper->__("your message here.") . '"'));
277
  }
278
  }
279
  return $telegram->respondSuccess();
280
  }
281
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("I don't work with groups."))); // TODO
282
  return $telegram->respondSuccess(); // ignore all group messages
283
  }
284
 
 
 
285
  if ($chatdata->getIsLogged() == "1") // check if customer is logged
286
  {
287
  if (Mage::getModel('customer/customer')->load((int)$chatdata->getCustomerId())->getId()) // if is a valid customer id
288
  {
289
  if ($chatdata->getEnableTelegram() != "1")
290
  {
291
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("To talk with me, please enable Telegram on your account chatbot settings.")));
292
  return $telegram->respondSuccess();
293
  }
294
  }
295
  }
296
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297
  // init start command
298
  $chatdata->_startCmd['command'] = "/start";
299
 
300
- if (is_null($chatdata->getTelegramChatId()) && !$chatdata->checkCommandWithValue($text, $chatdata->_startCmd['command'])) // if user isn't registred, and not using the start command
301
  {
302
  $message = Mage::getStoreConfig('chatbot_enable/telegram_config/telegram_welcome_msg'); // TODO
303
  if ($message) // TODO
@@ -333,15 +476,15 @@
333
  $chatdata->_helpCmd['command'] = $chatdata->validateTelegramCmd("/" . $chatdata->getCommandString(13)['command']);
334
  $chatdata->_aboutCmd['command'] = $chatdata->validateTelegramCmd("/" . $chatdata->getCommandString(14)['command']);
335
  $chatdata->_logoutCmd['command'] = $chatdata->validateTelegramCmd("/" . $chatdata->getCommandString(15)['command']);
336
-
337
  if (!$chatdata->_cancelCmd['command']) $chatdata->_cancelCmd['command'] = "/cancel"; // it must always have a cancel command
338
 
339
  // init messages
340
- $chatdata->_errorMessage = $magehelper->__("Something went wrong, please try again.");
341
- $chatdata->_cancelMessage = $magehelper->__("To cancel, send") . " " . $chatdata->_cancelCmd['command'];
342
- $chatdata->_canceledMessage = $magehelper->__("Ok, canceled.");
343
- $chatdata->_loginFirstMessage = $magehelper->__("Please login first.");
344
- array_push($chatdata->_positiveMessages, $magehelper->__("Ok"), $magehelper->__("Okay"), $magehelper->__("Cool"), $magehelper->__("Awesome"));
345
  // $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)]
346
 
347
  // TODO DEBUG COMMANDS
@@ -361,7 +504,7 @@
361
  // $telegram->sendMessage(array('chat_id' => $chat_id, 'text' => $conversationState));
362
 
363
  // start command
364
- if ($chatdata->checkCommandWithValue($text, $chatdata->_startCmd['command'])) // ignore alias
365
  //if ($text == $chatdata->_startCmd['command'])
366
  {
367
  $startdata = explode(" ", $text);
@@ -418,8 +561,15 @@
418
  if ($chatdata->checkCommand($text, $chatdata->_helpCmd))
419
  {
420
  $message = Mage::getStoreConfig('chatbot_enable/telegram_config/telegram_help_msg'); // TODO
421
- if ($message) // TODO
 
 
 
 
 
422
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $message));
 
 
423
  return $telegram->respondSuccess();
424
  }
425
 
@@ -427,28 +577,9 @@
427
  if ($chatdata->checkCommand($text, $chatdata->_aboutCmd))
428
  {
429
  $message = Mage::getStoreConfig('chatbot_enable/telegram_config/telegram_about_msg'); // TODO
430
- $cmdListing = Mage::getStoreConfig('chatbot_enable/telegram_config/enable_command_list');
431
- if ($cmdListing == 1)
432
- {
433
- $message .= "\n\n" . $magehelper->__("Command list") . ":\n";
434
- if ($chatdata->_listCategoriesCmd['command']) $message .= $chatdata->_listCategoriesCmd['command'] . " - " . $magehelper->__("List store categories.") . "\n";
435
- if ($chatdata->_searchCmd['command']) $message .= $chatdata->_searchCmd['command'] . " - " . $magehelper->__("Search for products.") . "\n";
436
- if ($chatdata->_loginCmd['command']) $message .= $chatdata->_loginCmd['command'] . " - " . $magehelper->__("Login into your account.") . "\n";
437
- if ($chatdata->_logoutCmd['command']) $message .= $chatdata->_logoutCmd['command'] . " - " . $magehelper->__("Logout from your account.") . "\n";
438
- if ($chatdata->_listOrdersCmd['command']) $message .= $chatdata->_listOrdersCmd['command'] . " - " . $magehelper->__("List your personal orders.") . "\n";
439
- //$message .= $chatdata->_reorderCmd['command'] . " - " . $magehelper->__("Reorder a order.") . "\n";
440
- //$message .= $chatdata->_add2CartCmd['command'] . " - " . $magehelper->__("Add product to cart.") . "\n";
441
- if ($chatdata->_checkoutCmd['command']) $message .= $chatdata->_checkoutCmd['command'] . " - " . $magehelper->__("Checkout your order.") . "\n";
442
- if ($chatdata->_clearCartCmd['command']) $message .= $chatdata->_clearCartCmd['command'] . " - " . $magehelper->__("Clear your cart.") . "\n";
443
- if ($chatdata->_trackOrderCmd['command']) $message .= $chatdata->_trackOrderCmd['command'] . " - " . $magehelper->__("Track your order status.") . "\n";
444
- if ($chatdata->_supportCmd['command']) $message .= $chatdata->_supportCmd['command'] . " - " . $magehelper->__("Send message to support.") . "\n";
445
- if ($chatdata->_sendEmailCmd['command']) $message .= $chatdata->_sendEmailCmd['command'] . " - " . $magehelper->__("Send email.") . "\n";
446
- //$message .= $chatdata->_cancelCmd['command'] . " - " . $magehelper->__("Cancel.");
447
- if ($chatdata->_helpCmd['command']) $message .= $chatdata->_helpCmd['command'] . " - " . $magehelper->__("Get help.") . "\n";
448
- //$message .= $chatdata->_aboutCmd['command'] . " - " . $magehelper->__("About.");
449
- }
450
 
451
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $message));
452
  return $telegram->respondSuccess();
453
  }
454
 
@@ -462,7 +593,7 @@
462
  }
463
  else if ($conversationState == $chatdata->_supportState)
464
  {
465
- $content = array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("exiting support mode."));
466
  //$telegram->sendMessage(array('chat_id' => $chat_id, 'text' => $magehelper->__("Done.")));
467
  }
468
  else if ($conversationState == $chatdata->_searchState)
@@ -492,19 +623,32 @@
492
  }
493
 
494
  // add2cart commands
495
- if ($chatdata->checkCommandWithValue($text, $chatdata->_add2CartCmd['command'])) // ignore alias
496
  {
497
  $errorFlag = false;
 
498
  $cmdvalue = $chatdata->getCommandValue($text, $chatdata->_add2CartCmd['command']);
499
  if ($cmdvalue) // TODO
500
  {
501
- $productName = Mage::getModel('catalog/product')->load($cmdvalue)->getName();
502
- if (empty($productName))
503
- $productName = $magehelper->__("this product");
504
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("adding %s to your cart.", $productName)));
505
- $telegram->sendChatAction(array('chat_id' => $chatId, 'action' => 'typing'));
506
- if ($chatdata->addProd2Cart($cmdvalue))
507
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Added. To checkout send") . " " . $chatdata->_checkoutCmd['command']));
 
 
 
 
 
 
 
 
 
 
 
 
508
  else
509
  $errorFlag = true;
510
  }
@@ -513,6 +657,9 @@
513
 
514
  if ($errorFlag)
515
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
 
 
 
516
  return $telegram->respondSuccess();
517
  }
518
 
@@ -524,13 +671,13 @@
524
  else
525
  $_category = Mage::getModel('catalog/category')->loadByAttribute('name', $text);
526
 
 
527
  if ($showMore == 0) // show only in the first time
528
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("please wait while I gather all products from %s for you.", $_category->getName())));
529
  else
530
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("listing more.")));
531
 
532
  $telegram->sendChatAction(array('chat_id' => $chatId, 'action' => 'typing'));
533
- $keyb = $telegram->buildKeyBoardHide(true); // hide keyboard built on listing categories
534
  $errorFlag = false;
535
  if ($_category) // check if variable isn't false/empty
536
  {
@@ -554,9 +701,9 @@
554
  if ($showMore == 0)
555
  {
556
  if ($total == 1)
557
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Done. This category has only one product.", $total)));
558
  else
559
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Done. This category has %s products.", $total)));
560
  }
561
 
562
  foreach ($productIDs as $productID)
@@ -568,14 +715,14 @@
568
  {
569
  $image = $chatdata->loadImageContent($productID);
570
  if ($image)
571
- $telegram->sendPhoto(array('chat_id' => $chatId, 'reply_markup' => $keyb, 'photo' => $image, 'caption' => $message));
572
  else
573
- $telegram->sendMessage(array('chat_id' => $chatId, 'reply_markup' => $keyb, 'text' => $message));
574
 
575
  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)
576
  {
577
  // TODO add option to list more products
578
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("To show more, send") . " " . $listMoreCategories . $_category->getId() . "_" . (string)($i + 1)));
579
  if ($chatdata->getTelegramConvState() != $chatdata->_listProductsState)
580
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_listProductsState))
581
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
@@ -583,7 +730,7 @@
583
  }
584
  else if (($i + 1) == $total) // if it's the last one, back to _startState
585
  {
586
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("And that was the last one.")));
587
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_startState))
588
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
589
  }
@@ -602,7 +749,7 @@
602
  $noProductFlag = true;
603
 
604
  if ($noProductFlag)
605
- $telegram->sendMessage(array('chat_id' => $chatId, 'reply_markup' => $keyb, 'text' => $magehelper->__("Sorry, no products found in this category.")));
606
  }
607
  else
608
  $errorFlag = true;
@@ -620,9 +767,10 @@
620
  else if ($conversationState == $chatdata->_searchState) // TODO
621
  {
622
  if ($showMore == 0) // show only in the first time
623
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("please wait while I search for '%s' for you.", $text)));
624
  else
625
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("listing more.")));
 
626
  $telegram->sendChatAction(array('chat_id' => $chatId, 'action' => 'typing'));
627
  $errorFlag = false;
628
  $noProductFlag = false;
@@ -642,9 +790,9 @@
642
  if ($showMore == 0)
643
  {
644
  if ($total == 1)
645
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Done. I've found only %s product for your criteria.", $total)));
646
  else
647
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Done. I've found %s products for your criteria.", $total)));
648
  }
649
 
650
  foreach ($productIDs as $productID)
@@ -663,7 +811,7 @@
663
  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)
664
  {
665
  // TODO add option to list more products
666
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("To show more, send") . " " . $listMoreSearch . str_replace(" ", "_", $text) . "_" . (string)($i + 1)));
667
  if ($chatdata->getTelegramConvState() != $chatdata->_listProductsState)
668
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_listProductsState))
669
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
@@ -671,7 +819,7 @@
671
  }
672
  else if (($i + 1) == $total) // if it's the last one, back to _startState
673
  {
674
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("And that was the last one.")));
675
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_startState))
676
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
677
  }
@@ -689,7 +837,7 @@
689
  $noProductFlag = true;
690
 
691
  if ($noProductFlag)
692
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Sorry, no products found for this criteria.")));
693
 
694
  if ($errorFlag)
695
  {
@@ -704,7 +852,7 @@
704
  if (!empty($supportGroupId))
705
  {
706
  $telegram->forwardMessage(array('chat_id' => $supportGroupId, 'from_chat_id' => $chatId, 'message_id' => $telegram->MessageID())); // Reply to this message to reply to the customer
707
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("we have sent your message to support.")));
708
  }
709
  else
710
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
@@ -712,13 +860,13 @@
712
  }
713
  else if ($conversationState == $chatdata->_sendEmailState)
714
  {
715
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Trying to send the email...")));
716
- if ($chatdata->sendEmail($text))
717
  {
718
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Done.")));
719
  }
720
  else
721
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Sorry, I wasn't able to send an email this time. Please try again later.")));
722
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_startState))
723
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
724
  return $telegram->respondSuccess();
@@ -728,14 +876,14 @@
728
  $errorFlag = false;
729
  if ($chatdata->getIsLogged() == "1")
730
  {
731
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("please wait while I check the status for order %s.", $text)));
732
  $telegram->sendChatAction(array('chat_id' => $chatId, 'action' => 'typing'));
733
  $order = Mage::getModel('sales/order')->loadByIncrementId($text);
734
  if ($order->getId())
735
  {
736
  if ($order->getCustomerId() == $chatdata->getCustomerId()) // not a problem if customer dosen't exist
737
  {
738
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Your order status is") . " " . $order->getStatus()));
739
  }
740
  else
741
  $errorFlag = true;
@@ -748,14 +896,14 @@
748
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_startState))
749
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
750
  else if ($errorFlag)
751
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Sorry, we couldn't find any order with this information.")));
752
  return $telegram->respondSuccess();
753
  }
754
 
755
  // general commands
756
  if ($chatdata->checkCommand($text, $chatdata->_listCategoriesCmd))
757
  {
758
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("please wait while I gather all categories for you.")));
759
  $telegram->sendChatAction(array('chat_id' => $chatId, 'action' => 'typing'));
760
 
761
  $categoryHelper = Mage::helper('catalog/category');
@@ -766,11 +914,13 @@
766
  else if ($categories)
767
  {
768
  $option = array();
769
- foreach ($categories as $_category) // TODO fix buttons max size
 
 
770
  {
771
  if ($enableEmptyCategoriesListing != "1") // unallow empty categories listing
772
  {
773
- $category = Mage::getModel('catalog/category')->load($_category->getId()); // reload category because EAV Entity
774
  $productIDs = $category->getProductCollection()
775
  ->addAttributeToSelect('*')
776
  ->addAttributeToFilter('visibility', 4)
@@ -781,18 +931,30 @@
781
  $productIDs = true;
782
  if (!empty($productIDs)) // category with no products
783
  {
784
- $cat_name = $_category->getName();
785
- array_push($option, $cat_name);
 
 
 
 
 
 
 
 
 
786
  $i++;
787
  }
788
  }
789
 
790
- $keyb = $telegram->buildKeyBoard(array($option));
791
- $telegram->sendMessage(array('chat_id' => $chatId, 'reply_markup' => $keyb, 'text' => $magehelper->__("Select a category") . ". " . $chatdata->_cancelMessage));
 
 
 
792
  }
793
  else if ($i == 0)
794
  {
795
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("No categories available at the moment, please try again later.")));
796
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_startState))
797
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
798
  }
@@ -805,7 +967,7 @@
805
  {
806
  $sessionId = null;
807
  $quoteId = null;
808
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("please wait while I prepare the checkout for you.")));
809
  $telegram->sendChatAction(array('chat_id' => $chatId, 'action' => 'typing'));
810
  if ($chatdata->getIsLogged() == "1")
811
  {
@@ -840,15 +1002,15 @@
840
  if ($ordersubtotal > 0)
841
  {
842
  $emptyCart = false;
843
- $message = $magehelper->__("Products on cart") . ":\n";
844
  foreach ($cart->getQuote()->getItemsCollection() as $item) // TODO
845
  {
846
  $message .= $item->getQty() . "x " . $item->getProduct()->getName() . "\n" .
847
- $magehelper->__("Price") . ": " . Mage::helper('core')->currency($item->getProduct()->getPrice(), true, false) . "\n\n";
848
  }
849
- $message .= $magehelper->__("Total") . ": " .
850
  Mage::helper('core')->currency($ordersubtotal, true, false) . "\n\n" .
851
- "[" . $magehelper->__("Checkout Here") . "](" . $cartUrl . ")";
852
 
853
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_checkoutState))
854
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
@@ -859,18 +1021,20 @@
859
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
860
  }
861
  if ($emptyCart)
862
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Your cart is empty.")));
863
  return $telegram->respondSuccess();
864
  }
865
  else if ($chatdata->checkCommand($text, $chatdata->_clearCartCmd))
866
  {
 
 
867
  $errorFlag = false;
868
  if ($chatdata->clearCart())
869
  {
870
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_clearCartState))
871
  $errorFlag = true;
872
  else
873
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Cart cleared.")));
874
  }
875
  else
876
  $errorFlag = true;
@@ -883,28 +1047,36 @@
883
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_searchState))
884
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
885
  else
886
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("what do you want to search for?") . " " . $chatdata->_cancelMessage));
887
  return $telegram->respondSuccess();
888
  }
889
  else if ($chatdata->checkCommand($text, $chatdata->_loginCmd)) // TODO
890
  {
891
  if ($chatdata->getIsLogged() != "1") // customer not logged
892
  {
893
- $hashlink = Mage::getUrl('chatbot/settings/index/') . "hash" . DS . $chatdata->getHashKey();
 
894
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_loginState))
895
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
896
  else
897
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("To login to your account, click this link") . ": " . $hashlink));
 
 
 
 
 
 
 
898
  }
899
  else
900
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("You're already logged.")));
901
  return $telegram->respondSuccess();
902
  }
903
  else if ($chatdata->checkCommand($text, $chatdata->_logoutCmd)) // TODO
904
  {
905
  if ($chatdata->getIsLogged() == "1")
906
  {
907
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Ok, logging out.")));
908
  $errorFlag = false;
909
  try
910
  {
@@ -921,21 +1093,30 @@
921
  if ($errorFlag)
922
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
923
  else
924
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Done.")));
925
  }
926
  else
927
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("You're not logged.")));
928
 
929
  return $telegram->respondSuccess();
930
  }
 
 
 
 
 
 
 
 
 
931
  else if ($chatdata->checkCommand($text, $chatdata->_listOrdersCmd) || $moreOrders) // TODO
932
  {
933
  if ($chatdata->getIsLogged() == "1")
934
  {
935
  if ($showMore == 0) // show only in the first time
936
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("please wait while I gather your orders for listing.")));
937
  else
938
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("listing more.")));
939
 
940
  $telegram->sendChatAction(array('chat_id' => $chatId, 'action' => 'typing'));
941
  $ordersIDs = $chatdata->getOrdersIdsFromCustomer();
@@ -948,9 +1129,9 @@
948
  if ($showMore == 0)
949
  {
950
  if ($total == 1)
951
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Done. You've only one order.", $total)));
952
  else
953
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Done. I've found %s orders.", $total)));
954
  }
955
 
956
  foreach($ordersIDs as $orderID)
@@ -964,7 +1145,7 @@
964
  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)
965
  {
966
  // TODO add option to list more orders
967
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("To show more, send") . " " . $listMoreOrders . (string)($i + 1)));
968
  if ($chatdata->getTelegramConvState() != $chatdata->_listOrdersState)
969
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_listOrdersState))
970
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
@@ -972,7 +1153,7 @@
972
  }
973
  else if (($i + 1) == $total) // if it's the last one, back to _startState
974
  {
975
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("And that was the last one.")));
976
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_startState))
977
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
978
  }
@@ -988,7 +1169,7 @@
988
  }
989
  else
990
  {
991
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("This account has no orders.")));
992
  return $telegram->respondSuccess();
993
  }
994
  }
@@ -996,11 +1177,11 @@
996
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_loginFirstMessage));
997
  return $telegram->respondSuccess();
998
  }
999
- else if ($chatdata->checkCommandWithValue($text, $chatdata->_reorderCmd['command'])) // ignore alias TODO
1000
  {
1001
  if ($chatdata->getIsLogged() == "1")
1002
  {
1003
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("please wait while I add the products from this order to your cart.")));
1004
  $telegram->sendChatAction(array('chat_id' => $chatId, 'action' => 'typing'));
1005
  $errorFlag = false;
1006
  $cmdvalue = $chatdata->getCommandValue($text, $chatdata->_reorderCmd['command']);
@@ -1030,7 +1211,7 @@
1030
  else if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_reorderState))
1031
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
1032
  else // success!!
1033
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("to checkout send") . " " . $chatdata->_checkoutCmd['command']));
1034
  }
1035
  else
1036
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_loginFirstMessage));
@@ -1046,10 +1227,10 @@
1046
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_trackOrderState))
1047
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
1048
  else
1049
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("send the order number.")));
1050
  }
1051
  else
1052
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Your account dosen't have any orders.")));
1053
  }
1054
  else
1055
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_loginFirstMessage));
@@ -1066,13 +1247,13 @@
1066
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_supportState))
1067
  $errorFlag = true;
1068
  else
1069
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("what do you need support for?") . " " . $chatdata->_cancelMessage));
1070
  }
1071
  else
1072
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("You're already on support in other chat application, please close it before opening a new one.")));
1073
  }
1074
  else
1075
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("I'm sorry, you can't ask for support now. Please try again later.")));
1076
 
1077
  if ($errorFlag)
1078
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
@@ -1084,8 +1265,8 @@
1084
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
1085
  else
1086
  {
1087
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $magehelper->__("write the email content.")));
1088
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("By doing this you agree that we may contact you directly via chat message.") . " " . $chatdata->_cancelMessage));
1089
  }
1090
  return $telegram->respondSuccess();
1091
  }
@@ -1099,8 +1280,8 @@
1099
  // $chatdata->updateChatdata('telegram_conv_state', $chatdata->_supportState);
1100
  $telegram->forwardMessage(array('chat_id' => $supportGroupId, 'from_chat_id' => $chatId, 'message_id' => $telegram->MessageID()));
1101
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' =>
1102
- $magehelper->__("Sorry, I didn't understand that.") . " " .
1103
- $magehelper->__("Please wait while our support check your message so you can talk to a real person.")// . " " .
1104
  //$chatdata->_cancelMessage
1105
  )); // TODO
1106
  }
@@ -1108,9 +1289,20 @@
1108
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
1109
  return $telegram->respondSuccess();
1110
  }
1111
- //else if ($enable_witai == "1"){}
1112
- else
1113
- $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $magehelper->__("Sorry, I didn't understand that."))); // TODO
 
 
 
 
 
 
 
 
 
 
 
1114
  }
1115
  }
1116
 
29
  {
30
  $telegram = new Telegram($apiKey);
31
 
32
+ $mageHelper = Mage::helper('core');
33
  $supportgroup = Mage::getStoreConfig('chatbot_enable/telegram_config/telegram_support_group');
34
  if (!empty($supportgroup))
35
  {
37
  if ($supportgroup[0] == "g") // remove the 'g' from groupd id, and add '-'
38
  $supportgroup = "-" . ltrim($supportgroup, "g");
39
 
40
+ if (!$customerName)
41
+ $customerName = $mageHelper->__("Not informed");
42
+
43
+ $message = $mageHelper->__("Message via") . " " . $api_name . ":\n" . $mageHelper->__("From") . ": " . $customerName . "\n" . $text;
44
  $result = $telegram->sendMessage(array('chat_id' => $supportgroup, 'text' => $message));
45
  $mid = $result['result']['message_id'];
46
  if (!empty($mid))
72
  $text = $telegram->Text();
73
  $chatId = $telegram->ChatID();
74
  $messageId = $telegram->MessageID();
75
+ $inlineQuery = $telegram->Inline_Query();
76
+
77
+ $enableLog = Mage::getStoreConfig('chatbot_enable/general_config/enable_post_log');
78
+ if ($enableLog == "1") // log all posts
79
+ Mage::log("Post Data:\n" . var_export($telegram->getData(), true) . "\n\n", null, 'chatbot_telegram.log');
80
+
81
+ if (!empty($inlineQuery))
82
+ {
83
+ $query = $inlineQuery['query'];
84
+ $queryId = $inlineQuery['id'];
85
+ $results = array();
86
+ $chatdataInline = Mage::getModel('chatbot/chatdata');
87
+ if (!empty($query))
88
+ {
89
+ $productIDs = $chatdataInline->getProductIdsBySearch($query);
90
+ $mageHelperInline = Mage::helper('core');
91
+ if (!empty($productIDs))
92
+ {
93
+ //$total = count($productIDs);
94
+ $i = 0;
95
+ foreach($productIDs as $productID)
96
+ {
97
+ $product = Mage::getModel('catalog/product')->load($productID);
98
+ if ($product->getId())
99
+ {
100
+ if ($product->getStockItem()->getIsInStock() > 0)
101
+ {
102
+ if ($i >= 5)
103
+ break;
104
+ $productUrl = $product->getProductUrl();
105
+ $productImage = $product->getImageUrl();
106
+ $productName = $product->getName();
107
+ $productDescription = $chatdataInline->excerpt($product->getShortDescription(), 60);
108
+ $placeholder = Mage::getSingleton("catalog/product_media_config")->getBaseMediaUrl() . DS . "placeholder" . DS . Mage::getStoreConfig("catalog/placeholder/thumbnail_placeholder");
109
+ if (empty($productImage))
110
+ $productImage = $placeholder;
111
+
112
+ $message = $productName . "\n" .
113
+ $mageHelperInline->__("Price") . ": " . Mage::helper('core')->currency($product->getPrice(), true, false) . "\n" .
114
+ $productDescription . "\n" .
115
+ $productUrl
116
+ ;
117
+
118
+ $result = array(
119
+ 'type' => 'article',
120
+ 'id' => $queryId . "/" . (string)$i,
121
+ 'title' => $productName,
122
+ 'description' => $productDescription,
123
+ 'thumb_url' => $productImage,
124
+ 'input_message_content' => array(
125
+ 'message_text' => $message,
126
+ 'parse_mode' => 'HTML'
127
+ )
128
+ );
129
+
130
+ array_push($results, $result);
131
+ $i++;
132
+ }
133
+ }
134
+ }
135
+
136
+ $telegram->answerInlineQuery(array('inline_query_id' => $queryId, 'results' => json_encode($results)));
137
+ }
138
+ else
139
+ {
140
+ $results = array(
141
+ array(
142
+ 'type' => 'article',
143
+ 'id' => $queryId . "/0",
144
+ 'title' => $mageHelperInline->__("Sorry, no products found for this criteria."),
145
+ 'input_message_content' => array(
146
+ 'message_text' => $mageHelperInline->__("Sorry, no products found for this criteria.")
147
+ )
148
+ )
149
+ );
150
+ $telegram->answerInlineQuery(array('inline_query_id' => $queryId, 'results' => json_encode($results)));
151
+ }
152
+ }
153
+
154
+ $telegram->respondSuccess();
155
+ }
156
 
157
  // configs
158
  //$enable_witai = Mage::getStoreConfig('chatbot_enable/witai_config/enable_witai');
159
  $enabledBot = Mage::getStoreConfig('chatbot_enable/telegram_config/enable_bot');
160
  $enableReplies = Mage::getStoreConfig('chatbot_enable/telegram_config/enable_default_replies');
 
161
  $enableEmptyCategoriesListing = Mage::getStoreConfig('chatbot_enable/general_config/list_empty_categories');
162
  $enableFinalMessage2Support = Mage::getStoreConfig('chatbot_enable/general_config/enable_support_final_message');
163
  $supportGroupId = Mage::getStoreConfig('chatbot_enable/telegram_config/telegram_support_group');
165
  $cat_id = null;
166
  $moreOrders = false;
167
  $listingLimit = 5;
168
+ $categoryLimit = 18;
169
  $listMoreCategories = "/lmc_";
170
  $listMoreSearch = "/lms_";
171
  $listMoreOrders = "/lmo_";
172
 
 
 
 
173
  if (!is_null($text) && !is_null($chatId))
174
  {
175
+ // Instances facebook user details
176
+ $username = $telegram->Username();
177
+
178
  // Instances the model class
179
  $chatdata = Mage::getModel('chatbot/chatdata')->load($chatId, 'telegram_chat_id');
180
  $chatdata->_apiType = $chatdata->_tgBot;
196
  // send feedback to user
197
  $telegram->sendChatAction(array('chat_id' => $chatId, 'action' => 'typing'));
198
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
  // show more handler, may change the conversation state
200
  if ($chatdata->getTelegramConvState() == $chatdata->_listProductsState || $chatdata->getTelegramConvState() == $chatdata->_listOrdersState) // listing products
201
  {
202
+ if ($chatdata->startsWith($text, $listMoreCategories)) // old checkCommandWithValue
203
  {
204
  if ($chatdata->updateChatdata('telegram_conv_state', $chatdata->_listCategoriesState))
205
  {
209
  $showMore = (int)$arr[1]; // get where listing stopped
210
  }
211
  }
212
+ else if ($chatdata->startsWith($text, $listMoreSearch)) // old checkCommandWithValue
213
  {
214
  if ($chatdata->updateChatdata('telegram_conv_state', $chatdata->_searchState))
215
  {
220
  $text = str_replace("_", " ", $value); // get search criteria
221
  }
222
  }
223
+ else if ($chatdata->startsWith($text, $listMoreOrders)) // old checkCommandWithValue
224
  {
225
  if ($chatdata->updateChatdata('telegram_conv_state', $chatdata->_listOrdersState))
226
  {
237
  $conversationState = $chatdata->getTelegramConvState();
238
 
239
  // mage helper
240
+ $mageHelper = Mage::helper('core');
241
 
242
  if ($supportGroupId[0] == "g") // remove the 'g' from groupd id, and add '-'
243
  $supportGroupId = "-" . ltrim($supportGroupId, "g");
273
  {
274
  // TODO IMPORTANT remember to switch off all other supports
275
  $customerData->updateChatdata('telegram_conv_state', $chatdata->_startState);
276
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Done. The customer is no longer on support.")));
277
+ $telegram->sendMessage(array('chat_id' => $replyFromUserId, 'text' => $mageHelper->__("Support ended."))); // TODO
278
  }
279
  else if ($text == $admBlockSupport) // block user from using support
280
  {
281
  $customerData->updateChatdata('enable_support', "0"); // disable support
282
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Done. The customer is no longer able to enter support."))); // TODO
283
  }
284
  else if ($text == $admEnableSupport) // block user from using support
285
  {
286
  $customerData->updateChatdata('enable_support', "1"); // enable support
287
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Done. The customer is now able to enter support."))); // TODO
288
  }
289
  else // if no command, then it's replying the user
290
  {
291
  if ($customerData->getTelegramConvState() != $chatdata->_supportState) // if user isn't on support, switch to support
292
  {
293
  $customerData->updateChatdata('telegram_conv_state', $chatdata->_supportState);
294
+ $telegram->sendMessage(array('chat_id' => $replyFromUserId, 'text' => $mageHelper->__("You're now on support mode.")));
295
  }
296
+ $telegram->sendMessage(array('chat_id' => $replyFromUserId, 'text' => $mageHelper->__("Message from support") . ":\n" . $text)); // send message to customer TODO
297
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Message sent."))); // send message to admin group TODO
298
  }
299
  }
300
  }
303
  {
304
  $admSend2All = "/" . $chatdata->_admSendMessage2AllCmd;
305
 
306
+ if ($chatdata->startsWith($text, $admSend2All)) // old checkCommandWithValue
307
  {
308
  $message = trim($chatdata->getCommandValue($text, $admSend2All));
309
  if (!empty($message))
315
  if ($tgChatId)
316
  $telegram->sendMessage(array('chat_id' => $tgChatId, 'text' => $message)); // $magehelper->__("Message from support") . ":\n" .
317
  }
318
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Message sent.")));
319
  }
320
  else
321
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Please use") . ' "' . $admSend2All . " " . $mageHelper->__("your message here.") . '"'));
322
  }
323
  }
324
  return $telegram->respondSuccess();
325
  }
326
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("I don't work with groups."))); // TODO
327
  return $telegram->respondSuccess(); // ignore all group messages
328
  }
329
 
330
+ // ALL CUSTOMER HANDLERS GOES AFTER HERE
331
+
332
  if ($chatdata->getIsLogged() == "1") // check if customer is logged
333
  {
334
  if (Mage::getModel('customer/customer')->load((int)$chatdata->getCustomerId())->getId()) // if is a valid customer id
335
  {
336
  if ($chatdata->getEnableTelegram() != "1")
337
  {
338
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("To talk with me, please enable Telegram on your account chatbot settings.")));
339
  return $telegram->respondSuccess();
340
  }
341
  }
342
  }
343
 
344
+ $blockerStates = (
345
+ $conversationState == $chatdata->_listCategoriesState ||
346
+ $conversationState == $chatdata->_searchState ||
347
+ $conversationState == $chatdata->_supportState ||
348
+ $conversationState == $chatdata->_sendEmailState ||
349
+ $conversationState == $chatdata->_trackOrderState
350
+ );
351
+
352
+ // handle default replies
353
+ if ($enableReplies == "1" && !$blockerStates)
354
+ {
355
+ $defaultReplies = Mage::getStoreConfig('chatbot_enable/telegram_config/default_replies');
356
+ if ($defaultReplies)
357
+ {
358
+ $replies = unserialize($defaultReplies);
359
+ if (is_array($replies))
360
+ {
361
+ foreach($replies as $reply)
362
+ {
363
+ // MODES
364
+ // 0 =>'Similarity'
365
+ // 1 =>'Starts With'
366
+ // 2 =>'Ends With'
367
+ // 3 =>'Contains'
368
+ // 4 =>'Match Regular Expression'
369
+ // 5 =>'Equals to'
370
+
371
+ $matched = false;
372
+ $match = $reply["match_sintax"];
373
+ $mode = $reply["reply_mode"];
374
+
375
+ if ($reply["match_case"] == "0")
376
+ {
377
+ $match = strtolower($match);
378
+ $textToMatch = strtolower($text);
379
+ }
380
+ else
381
+ $textToMatch = $text;
382
+
383
+ if ($mode == "0") // Similarity
384
+ {
385
+ $similarity = $reply["similarity"];
386
+ if (is_numeric($similarity))
387
+ {
388
+ if (!($similarity >= 1 && $similarity <= 100))
389
+ $similarity = 100;
390
+ }
391
+ else
392
+ $similarity = 100;
393
+
394
+ similar_text($textToMatch, $match, $percent);
395
+ if ($percent >= $similarity)
396
+ $matched = true;
397
+ }
398
+ else if ($mode == "1") // Starts With
399
+ {
400
+ if ($chatdata->startsWith($textToMatch, $match))
401
+ $matched = true;
402
+ }
403
+ else if ($mode == "2") // Ends With
404
+ {
405
+ if ($chatdata->endsWith($textToMatch, $match))
406
+ $matched = true;
407
+ }
408
+ else if ($mode == "3") // Contains
409
+ {
410
+ if (strpos($textToMatch, $match) !== false)
411
+ $matched = true;
412
+ }
413
+ else if ($mode == "4") // Match Regular Expression
414
+ {
415
+ // if ($match[0] != "/")
416
+ // $match = "/" . $match;
417
+ // if ((substr($match, -1) != "/") && ($match[strlen($match) - 2] != "/"))
418
+ // $match .= "/";
419
+ if (preg_match($match, $textToMatch))
420
+ $matched = true;
421
+ }
422
+ else if ($mode == "5") // Equals to
423
+ {
424
+ if ($textToMatch == $match)
425
+ $matched = true;
426
+ }
427
+
428
+ if ($matched)
429
+ {
430
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $reply["reply_phrase"]));
431
+ if ($reply["stop_processing"] == "1")
432
+ return $telegram->respondSuccess();
433
+ break;
434
+ }
435
+ }
436
+ }
437
+ }
438
+ }
439
+
440
  // init start command
441
  $chatdata->_startCmd['command'] = "/start";
442
 
443
+ if (is_null($chatdata->getTelegramChatId()) && !$chatdata->startsWith($text, $chatdata->_startCmd['command'])) // if user isn't registred, and not using the start command // old checkCommandWithValue
444
  {
445
  $message = Mage::getStoreConfig('chatbot_enable/telegram_config/telegram_welcome_msg'); // TODO
446
  if ($message) // TODO
476
  $chatdata->_helpCmd['command'] = $chatdata->validateTelegramCmd("/" . $chatdata->getCommandString(13)['command']);
477
  $chatdata->_aboutCmd['command'] = $chatdata->validateTelegramCmd("/" . $chatdata->getCommandString(14)['command']);
478
  $chatdata->_logoutCmd['command'] = $chatdata->validateTelegramCmd("/" . $chatdata->getCommandString(15)['command']);
479
+ $chatdata->_registerCmd['command'] = $chatdata->validateTelegramCmd("/" . $chatdata->getCommandString(16)['command']);
480
  if (!$chatdata->_cancelCmd['command']) $chatdata->_cancelCmd['command'] = "/cancel"; // it must always have a cancel command
481
 
482
  // init messages
483
+ $chatdata->_errorMessage = $mageHelper->__("Something went wrong, please try again.");
484
+ $chatdata->_cancelMessage = $mageHelper->__("To cancel, send") . " " . $chatdata->_cancelCmd['command'];
485
+ $chatdata->_canceledMessage = $mageHelper->__("Ok, canceled.");
486
+ $chatdata->_loginFirstMessage = $mageHelper->__("Please login first.");
487
+ array_push($chatdata->_positiveMessages, $mageHelper->__("Ok"), $mageHelper->__("Okay"), $mageHelper->__("Cool"), $mageHelper->__("Awesome"));
488
  // $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)]
489
 
490
  // TODO DEBUG COMMANDS
504
  // $telegram->sendMessage(array('chat_id' => $chat_id, 'text' => $conversationState));
505
 
506
  // start command
507
+ if ($chatdata->startsWith($text, $chatdata->_startCmd['command'])) // ignore alias // old checkCommandWithValue
508
  //if ($text == $chatdata->_startCmd['command'])
509
  {
510
  $startdata = explode(" ", $text);
561
  if ($chatdata->checkCommand($text, $chatdata->_helpCmd))
562
  {
563
  $message = Mage::getStoreConfig('chatbot_enable/telegram_config/telegram_help_msg'); // TODO
564
+ if (!empty($message)) // TODO
565
+ {
566
+ $cmdListing = Mage::getStoreConfig('chatbot_enable/telegram_config/enable_help_command_list');
567
+ if ($cmdListing == "1")
568
+ $message .= $chatdata->listTelegramCommandsMessage();
569
+
570
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $message));
571
+ }
572
+
573
  return $telegram->respondSuccess();
574
  }
575
 
577
  if ($chatdata->checkCommand($text, $chatdata->_aboutCmd))
578
  {
579
  $message = Mage::getStoreConfig('chatbot_enable/telegram_config/telegram_about_msg'); // TODO
580
+ if (!empty($message))
581
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $message));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
582
 
 
583
  return $telegram->respondSuccess();
584
  }
585
 
593
  }
594
  else if ($conversationState == $chatdata->_supportState)
595
  {
596
+ $content = array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("exiting support mode."));
597
  //$telegram->sendMessage(array('chat_id' => $chat_id, 'text' => $magehelper->__("Done.")));
598
  }
599
  else if ($conversationState == $chatdata->_searchState)
623
  }
624
 
625
  // add2cart commands
626
+ if ($chatdata->startsWith($text, $chatdata->_add2CartCmd['command'])) // ignore alias // old checkCommandWithValue
627
  {
628
  $errorFlag = false;
629
+ $notInStock = false;
630
  $cmdvalue = $chatdata->getCommandValue($text, $chatdata->_add2CartCmd['command']);
631
  if ($cmdvalue) // TODO
632
  {
633
+ $product = Mage::getModel('catalog/product')->load($cmdvalue);
634
+ if ($product->getId())
635
+ {
636
+ $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getIsInStock();
637
+ if ($stock > 0)
638
+ {
639
+ $productName = $product->getName();
640
+ if (empty($productName))
641
+ $productName = $mageHelper->__("this product");
642
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("adding %s to your cart.", $productName)));
643
+ $telegram->sendChatAction(array('chat_id' => $chatId, 'action' => 'typing'));
644
+ if ($chatdata->addProd2Cart($cmdvalue))
645
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Added. To checkout send") . " " . $chatdata->_checkoutCmd['command']));
646
+ else
647
+ $errorFlag = true;
648
+ }
649
+ else
650
+ $notInStock = true;
651
+ }
652
  else
653
  $errorFlag = true;
654
  }
657
 
658
  if ($errorFlag)
659
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
660
+ else if ($notInStock)
661
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("This product is not in stock.")));
662
+
663
  return $telegram->respondSuccess();
664
  }
665
 
671
  else
672
  $_category = Mage::getModel('catalog/category')->loadByAttribute('name', $text);
673
 
674
+ $keyb = $telegram->buildKeyBoardHide(true); // hide keyboard built on listing categories
675
  if ($showMore == 0) // show only in the first time
676
+ $telegram->sendMessage(array('chat_id' => $chatId, 'reply_markup' => $keyb, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("please wait while I gather all products from %s for you.", $_category->getName())));
677
  else
678
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("listing more.")));
679
 
680
  $telegram->sendChatAction(array('chat_id' => $chatId, 'action' => 'typing'));
 
681
  $errorFlag = false;
682
  if ($_category) // check if variable isn't false/empty
683
  {
701
  if ($showMore == 0)
702
  {
703
  if ($total == 1)
704
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Done. This category has only one product.")));
705
  else
706
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Done. This category has %s products.", $total)));
707
  }
708
 
709
  foreach ($productIDs as $productID)
715
  {
716
  $image = $chatdata->loadImageContent($productID);
717
  if ($image)
718
+ $telegram->sendPhoto(array('chat_id' => $chatId, 'photo' => $image, 'caption' => $message));
719
  else
720
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $message));
721
 
722
  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)
723
  {
724
  // TODO add option to list more products
725
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("To show more, send") . " " . $listMoreCategories . $_category->getId() . "_" . (string)($i + 1)));
726
  if ($chatdata->getTelegramConvState() != $chatdata->_listProductsState)
727
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_listProductsState))
728
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
730
  }
731
  else if (($i + 1) == $total) // if it's the last one, back to _startState
732
  {
733
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("And that was the last one.")));
734
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_startState))
735
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
736
  }
749
  $noProductFlag = true;
750
 
751
  if ($noProductFlag)
752
+ $telegram->sendMessage(array('chat_id' => $chatId, 'reply_markup' => $keyb, 'text' => $mageHelper->__("Sorry, no products found in this category.")));
753
  }
754
  else
755
  $errorFlag = true;
767
  else if ($conversationState == $chatdata->_searchState) // TODO
768
  {
769
  if ($showMore == 0) // show only in the first time
770
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("please wait while I search for '%s' for you.", $text)));
771
  else
772
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("listing more.")));
773
+
774
  $telegram->sendChatAction(array('chat_id' => $chatId, 'action' => 'typing'));
775
  $errorFlag = false;
776
  $noProductFlag = false;
790
  if ($showMore == 0)
791
  {
792
  if ($total == 1)
793
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Done. I've found only one product for your criteria.")));
794
  else
795
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Done. I've found %s products for your criteria.", $total)));
796
  }
797
 
798
  foreach ($productIDs as $productID)
811
  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)
812
  {
813
  // TODO add option to list more products
814
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("To show more, send") . " " . $listMoreSearch . str_replace(" ", "_", $text) . "_" . (string)($i + 1)));
815
  if ($chatdata->getTelegramConvState() != $chatdata->_listProductsState)
816
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_listProductsState))
817
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
819
  }
820
  else if (($i + 1) == $total) // if it's the last one, back to _startState
821
  {
822
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("And that was the last one.")));
823
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_startState))
824
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
825
  }
837
  $noProductFlag = true;
838
 
839
  if ($noProductFlag)
840
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Sorry, no products found for this criteria.")));
841
 
842
  if ($errorFlag)
843
  {
852
  if (!empty($supportGroupId))
853
  {
854
  $telegram->forwardMessage(array('chat_id' => $supportGroupId, 'from_chat_id' => $chatId, 'message_id' => $telegram->MessageID())); // Reply to this message to reply to the customer
855
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("we have sent your message to support.")));
856
  }
857
  else
858
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
860
  }
861
  else if ($conversationState == $chatdata->_sendEmailState)
862
  {
863
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Trying to send the email...")));
864
+ if ($chatdata->sendEmail($text, $username))
865
  {
866
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Done.")));
867
  }
868
  else
869
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Sorry, I wasn't able to send an email this time. Please try again later.")));
870
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_startState))
871
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
872
  return $telegram->respondSuccess();
876
  $errorFlag = false;
877
  if ($chatdata->getIsLogged() == "1")
878
  {
879
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("please wait while I check the status for order %s.", $text)));
880
  $telegram->sendChatAction(array('chat_id' => $chatId, 'action' => 'typing'));
881
  $order = Mage::getModel('sales/order')->loadByIncrementId($text);
882
  if ($order->getId())
883
  {
884
  if ($order->getCustomerId() == $chatdata->getCustomerId()) // not a problem if customer dosen't exist
885
  {
886
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Your order status is") . " " . $order->getStatus()));
887
  }
888
  else
889
  $errorFlag = true;
896
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_startState))
897
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
898
  else if ($errorFlag)
899
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Sorry, we couldn't find any order with this information.")));
900
  return $telegram->respondSuccess();
901
  }
902
 
903
  // general commands
904
  if ($chatdata->checkCommand($text, $chatdata->_listCategoriesCmd))
905
  {
906
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("please wait while I gather all categories for you.")));
907
  $telegram->sendChatAction(array('chat_id' => $chatId, 'action' => 'typing'));
908
 
909
  $categoryHelper = Mage::helper('catalog/category');
914
  else if ($categories)
915
  {
916
  $option = array();
917
+ $arr = array();
918
+ $charCount = 0;
919
+ foreach ($categories as $category) // TODO fix buttons max size
920
  {
921
  if ($enableEmptyCategoriesListing != "1") // unallow empty categories listing
922
  {
923
+ $category = Mage::getModel('catalog/category')->load($category->getId()); // reload category because EAV Entity
924
  $productIDs = $category->getProductCollection()
925
  ->addAttributeToSelect('*')
926
  ->addAttributeToFilter('visibility', 4)
931
  $productIDs = true;
932
  if (!empty($productIDs)) // category with no products
933
  {
934
+ //$option = array( array("A", "B"), array("C", "D") );
935
+ $catName = $category->getName();
936
+ $charCount = $charCount + strlen($catName);
937
+ array_push($arr, $catName); // push category name into array arr
938
+ if ($charCount > $categoryLimit) // size limit for Telegram buttons
939
+ {
940
+ array_push($option, $arr); // when hits the limit, add array to options
941
+ $arr = array(); // clear array
942
+ $charCount = 0;
943
+ }
944
+
945
  $i++;
946
  }
947
  }
948
 
949
+ if (!empty($arr)) // if the loop ended, and there's still categories on arr
950
+ array_push($option, $arr);
951
+
952
+ $keyb = $telegram->buildKeyBoard($option);
953
+ $telegram->sendMessage(array('chat_id' => $chatId, 'reply_markup' => $keyb, 'resize_keyboard' => true, 'text' => $mageHelper->__("Select a category") . ". " . $chatdata->_cancelMessage));
954
  }
955
  else if ($i == 0)
956
  {
957
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("No categories available at the moment, please try again later.")));
958
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_startState))
959
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
960
  }
967
  {
968
  $sessionId = null;
969
  $quoteId = null;
970
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("please wait while I prepare the checkout for you.")));
971
  $telegram->sendChatAction(array('chat_id' => $chatId, 'action' => 'typing'));
972
  if ($chatdata->getIsLogged() == "1")
973
  {
1002
  if ($ordersubtotal > 0)
1003
  {
1004
  $emptyCart = false;
1005
+ $message = $mageHelper->__("Products on cart") . ":\n";
1006
  foreach ($cart->getQuote()->getItemsCollection() as $item) // TODO
1007
  {
1008
  $message .= $item->getQty() . "x " . $item->getProduct()->getName() . "\n" .
1009
+ $mageHelper->__("Price") . ": " . Mage::helper('core')->currency($item->getProduct()->getPrice(), true, false) . "\n\n";
1010
  }
1011
+ $message .= $mageHelper->__("Total") . ": " .
1012
  Mage::helper('core')->currency($ordersubtotal, true, false) . "\n\n" .
1013
+ "[" . $mageHelper->__("Checkout Here") . "](" . $cartUrl . ")";
1014
 
1015
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_checkoutState))
1016
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
1021
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
1022
  }
1023
  if ($emptyCart)
1024
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Your cart is empty.")));
1025
  return $telegram->respondSuccess();
1026
  }
1027
  else if ($chatdata->checkCommand($text, $chatdata->_clearCartCmd))
1028
  {
1029
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("please wait while I clear your cart.")));
1030
+ $telegram->sendChatAction(array('chat_id' => $chatId, 'action' => 'typing'));
1031
  $errorFlag = false;
1032
  if ($chatdata->clearCart())
1033
  {
1034
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_clearCartState))
1035
  $errorFlag = true;
1036
  else
1037
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Cart cleared.")));
1038
  }
1039
  else
1040
  $errorFlag = true;
1047
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_searchState))
1048
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
1049
  else
1050
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("what do you want to search for?") . " " . $chatdata->_cancelMessage));
1051
  return $telegram->respondSuccess();
1052
  }
1053
  else if ($chatdata->checkCommand($text, $chatdata->_loginCmd)) // TODO
1054
  {
1055
  if ($chatdata->getIsLogged() != "1") // customer not logged
1056
  {
1057
+ $hashUrl = Mage::getUrl('chatbot/settings/index/'); // get base module URL
1058
+ $hashUrl = strtok($hashUrl, '?') . "hash" . DS . $chatdata->getHashKey(); // remove magento parameters
1059
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_loginState))
1060
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
1061
  else
1062
+ {
1063
+ $telegram->sendMessage(array(
1064
+ 'chat_id' => $chatId, 'text' => $mageHelper->__("To login to your account, click this link") . ": " .
1065
+ $hashUrl . " . " .
1066
+ $mageHelper->__("If you want to logout from your account, just send") . " " .
1067
+ $chatdata->_logoutCmd
1068
+ ));
1069
+ }
1070
  }
1071
  else
1072
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("You're already logged.")));
1073
  return $telegram->respondSuccess();
1074
  }
1075
  else if ($chatdata->checkCommand($text, $chatdata->_logoutCmd)) // TODO
1076
  {
1077
  if ($chatdata->getIsLogged() == "1")
1078
  {
1079
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Ok, logging out.")));
1080
  $errorFlag = false;
1081
  try
1082
  {
1093
  if ($errorFlag)
1094
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
1095
  else
1096
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Done.")));
1097
  }
1098
  else
1099
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("You're not logged.")));
1100
 
1101
  return $telegram->respondSuccess();
1102
  }
1103
+ else if ($chatdata->checkCommand($text, $chatdata->_registerCmd)) // TODO
1104
+ {
1105
+ $registerUrl = strtok(Mage::getUrl('customer/account/create'), '?');
1106
+ if (!empty($registerUrl))
1107
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Access %s to register a new account on our shop.", $registerUrl)));
1108
+ else
1109
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
1110
+ return $telegram->respondSuccess();
1111
+ }
1112
  else if ($chatdata->checkCommand($text, $chatdata->_listOrdersCmd) || $moreOrders) // TODO
1113
  {
1114
  if ($chatdata->getIsLogged() == "1")
1115
  {
1116
  if ($showMore == 0) // show only in the first time
1117
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("please wait while I gather your orders for listing.")));
1118
  else
1119
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("listing more.")));
1120
 
1121
  $telegram->sendChatAction(array('chat_id' => $chatId, 'action' => 'typing'));
1122
  $ordersIDs = $chatdata->getOrdersIdsFromCustomer();
1129
  if ($showMore == 0)
1130
  {
1131
  if ($total == 1)
1132
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Done. You've only one order.")));
1133
  else
1134
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Done. I've found %s orders.", $total)));
1135
  }
1136
 
1137
  foreach($ordersIDs as $orderID)
1145
  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)
1146
  {
1147
  // TODO add option to list more orders
1148
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("To show more, send") . " " . $listMoreOrders . (string)($i + 1)));
1149
  if ($chatdata->getTelegramConvState() != $chatdata->_listOrdersState)
1150
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_listOrdersState))
1151
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
1153
  }
1154
  else if (($i + 1) == $total) // if it's the last one, back to _startState
1155
  {
1156
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("And that was the last one.")));
1157
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_startState))
1158
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
1159
  }
1169
  }
1170
  else
1171
  {
1172
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("This account has no orders.")));
1173
  return $telegram->respondSuccess();
1174
  }
1175
  }
1177
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_loginFirstMessage));
1178
  return $telegram->respondSuccess();
1179
  }
1180
+ else if ($chatdata->startsWith($text, $chatdata->_reorderCmd['command'])) // ignore alias TODO // old checkCommandWithValue
1181
  {
1182
  if ($chatdata->getIsLogged() == "1")
1183
  {
1184
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("please wait while I add the products from this order to your cart.")));
1185
  $telegram->sendChatAction(array('chat_id' => $chatId, 'action' => 'typing'));
1186
  $errorFlag = false;
1187
  $cmdvalue = $chatdata->getCommandValue($text, $chatdata->_reorderCmd['command']);
1211
  else if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_reorderState))
1212
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
1213
  else // success!!
1214
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("to checkout send") . " " . $chatdata->_checkoutCmd['command']));
1215
  }
1216
  else
1217
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_loginFirstMessage));
1227
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_trackOrderState))
1228
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
1229
  else
1230
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("send the order number.")));
1231
  }
1232
  else
1233
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Your account dosen't have any orders.")));
1234
  }
1235
  else
1236
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_loginFirstMessage));
1247
  if (!$chatdata->updateChatdata('telegram_conv_state', $chatdata->_supportState))
1248
  $errorFlag = true;
1249
  else
1250
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("what do you need support for?") . " " . $chatdata->_cancelMessage));
1251
  }
1252
  else
1253
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("You're already on support in other chat application, please close it before opening a new one.")));
1254
  }
1255
  else
1256
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("I'm sorry, you can't ask for support now. Please try again later.")));
1257
 
1258
  if ($errorFlag)
1259
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
1265
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
1266
  else
1267
  {
1268
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_positiveMessages[array_rand($chatdata->_positiveMessages)] . ", " . $mageHelper->__("write the email content.")));
1269
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("By doing this you agree that we may contact you directly via chat message.") . " " . $chatdata->_cancelMessage));
1270
  }
1271
  return $telegram->respondSuccess();
1272
  }
1280
  // $chatdata->updateChatdata('telegram_conv_state', $chatdata->_supportState);
1281
  $telegram->forwardMessage(array('chat_id' => $supportGroupId, 'from_chat_id' => $chatId, 'message_id' => $telegram->MessageID()));
1282
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' =>
1283
+ $mageHelper->__("Sorry, I didn't understand that.") . " " .
1284
+ $mageHelper->__("Please wait while our support check your message so you can talk to a real person.")// . " " .
1285
  //$chatdata->_cancelMessage
1286
  )); // TODO
1287
  }
1289
  $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $chatdata->_errorMessage));
1290
  return $telegram->respondSuccess();
1291
  }
1292
+ else // process cases where the customer message wasn't understandable
1293
+ {
1294
+ //else if ($enable_witai == "1"){}
1295
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $mageHelper->__("Sorry, I didn't understand that."))); // TODO
1296
+
1297
+ $cmdListingOnError = Mage::getStoreConfig('chatbot_enable/telegram_config/enable_error_command_list');
1298
+ if ($cmdListingOnError == "1")
1299
+ {
1300
+ $message = $mageHelper->__("Please try one of the following commands.");
1301
+ $message .= $chatdata->listTelegramCommandsMessage();
1302
+ $telegram->sendMessage(array('chat_id' => $chatId, 'text' => $message)); // TODO
1303
+ }
1304
+
1305
+ }
1306
  }
1307
  }
1308
 
app/code/community/Werules/Chatbot/Model/Api/Telegram/Telegram.php CHANGED
@@ -1245,7 +1245,7 @@ class Telegram {
1245
  * \return the String users's text
1246
  */
1247
  public function Text() {
1248
- return $this->data["message"] ["text"];
1249
  }
1250
 
1251
  /// Get the chat_id of the current message
1245
  * \return the String users's text
1246
  */
1247
  public function Text() {
1248
+ return $this->data["message"]["text"];
1249
  }
1250
 
1251
  /// Get the chat_id of the current message
app/code/community/Werules/Chatbot/Model/Chatdata.php CHANGED
@@ -36,7 +36,7 @@ class Werules_Chatbot_Model_Chatdata extends Mage_Core_Model_Abstract
36
  protected $_cmdList =
37
  "
38
  start,
39
- list_cat,
40
  search,
41
  login,
42
  list_orders,
@@ -50,7 +50,8 @@ class Werules_Chatbot_Model_Chatdata extends Mage_Core_Model_Abstract
50
  cancel,
51
  help,
52
  about,
53
- logout
 
54
  ";
55
  protected $_startCmd = array();
56
  protected $_listCategoriesCmd = array();
@@ -68,6 +69,7 @@ class Werules_Chatbot_Model_Chatdata extends Mage_Core_Model_Abstract
68
  protected $_helpCmd = array();
69
  protected $_aboutCmd = array();
70
  protected $_logoutCmd = array();
 
71
 
72
  // admin cmds
73
  // protected $adminCmdList =
@@ -110,19 +112,41 @@ class Werules_Chatbot_Model_Chatdata extends Mage_Core_Model_Abstract
110
  // handle webhook configuration
111
  if ($webhook && $apiKey && $action == $this->_tgBot) // set telegram webhook
112
  {
113
- try
114
- {
115
- $telegram = new Telegram($apiKey);
116
- $webhook_url = Mage::getUrl('chatbot/chatdata/', array('_forced_secure' => true)) . $this->_tgBot;
117
- $webhook_url = str_replace("http://", "https://", $webhook_url);
118
- $telegram->setWebhook($webhook_url);
 
 
119
  }
120
- catch (Exception $e)
121
- {
122
- return Mage::helper('core')->__("Something went wrong, please try again.");
123
  }
124
 
125
- return Mage::helper('core')->__("Webhook for Telegram configured.");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  } // start to handle conversation
127
  else if ($action == $this->_tgBot && $apiKey) // telegram api
128
  {
@@ -159,15 +183,18 @@ class Werules_Chatbot_Model_Chatdata extends Mage_Core_Model_Abstract
159
  return null;
160
  }
161
 
162
- protected function sendEmail($text)
163
  {
164
  $storeName = Mage::app()->getStore()->getName();
165
  $storeEmail = Mage::getStoreConfig('trans_email/ident_general/email');// TODO
166
- $magehelper = Mage::helper('core');
167
 
168
- $url = $magehelper->__("Not informed");
169
- $customerEmail = $magehelper->__("Not informed");
170
- $customerName = $magehelper->__("Not informed");
 
 
 
171
 
172
  $mail = new Zend_Mail('UTF-8');
173
 
@@ -191,14 +218,14 @@ class Werules_Chatbot_Model_Chatdata extends Mage_Core_Model_Abstract
191
  }
192
 
193
  $emailBody =
194
- $magehelper->__("Message from chatbot customer") . "<br><br>" .
195
- $magehelper->__("Customer name") . ": " .
196
  $customerName . "<br>" .
197
- $magehelper->__("Message") . ":<br>" .
198
  $text . "<br><br>" .
199
- $magehelper->__("Contacts") . ":<br>" .
200
- $magehelper->__("Chatbot") . ": " . $url . "<br>" .
201
- $magehelper->__("Email") . ": " . $customerEmail . "<br>";
202
 
203
  $mail->setBodyHtml($emailBody);
204
  $mail->setFrom($storeEmail, $storeName);
@@ -282,68 +309,67 @@ class Werules_Chatbot_Model_Chatdata extends Mage_Core_Model_Abstract
282
  protected function getCommandString($cmdId)
283
  {
284
  $rep = "";
 
285
  if ($this->_apiType == $this->_tgBot)
286
  {
287
  $rep = "_";
288
- $confpath = 'chatbot_enable/telegram_config/';
289
  }
290
  else if ($this->_apiType == $this->_fbBot)
291
  {
292
  $rep = " ";
293
- $confpath = 'chatbot_enable/facebook_config/';
294
  }
295
- // else if ($this->_apiType == $this->_wappBot)
296
- // $confpath = 'chatbot_enable/whatsapp_config/';
297
 
298
- $config = Mage::getStoreConfig($confpath . 'enabled_commands');
299
- $enabledCmds = explode(',', $config);
300
- if (is_array($enabledCmds))
301
  {
302
- if (in_array($cmdId, $enabledCmds))
 
 
 
303
  {
304
- $defaultCmds = explode(',', $this->_cmdList);
305
- if (is_array($defaultCmds))
306
  {
307
- $cmdCode = "";
308
- $alias = array();
309
- $config = Mage::getStoreConfig($confpath . 'commands_list');
310
- if ($config)
311
  {
312
- $commands = unserialize($config);
313
- if (is_array($commands))
314
  {
315
- foreach($commands as $cmd)
316
  {
317
- if ($cmd['command_id'] == $cmdId)
318
- {
319
- $cmdCode = $cmd['command_code'];
320
- $alias = array_map('strtolower', explode(',', $cmd['command_alias_list']));
321
- break;
322
- }
323
- }
324
- if (empty($cmdCode)) // if no command found, return the default
325
  $cmdCode = $defaultCmds[$cmdId];
 
 
 
 
 
 
326
  }
327
- else // if no command found, return the default
328
- $cmdCode = $defaultCmds[$cmdId];
329
  }
330
- else // if no command found, return the default
331
- $cmdCode = $defaultCmds[$cmdId];
332
-
333
- $cmdCode = preg_replace( // remove all non-alphanumerics
334
- $this->_unallowedCharacters,
335
- '',
336
- str_replace( // replace whitespace for underscore
337
- ' ',
338
- $rep,
339
- trim($cmdCode)
340
- )
341
- );
342
-
343
- return array('command' => strtolower($cmdCode), 'alias' => $alias);
344
  }
 
 
345
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
346
  }
 
347
  return array('command' => null, 'alias' => null);
348
  }
349
 
@@ -380,13 +406,22 @@ class Werules_Chatbot_Model_Chatdata extends Mage_Core_Model_Abstract
380
  return false;
381
  }
382
 
383
- protected function checkCommandWithValue($text, $cmd)
384
  {
385
- if ($cmd)
386
- return substr($text, 0, strlen($cmd)) == $cmd;
387
  return false;
388
  }
389
 
 
 
 
 
 
 
 
 
 
390
  protected function clearCart()
391
  {
392
  try
@@ -419,12 +454,12 @@ class Werules_Chatbot_Model_Chatdata extends Mage_Core_Model_Abstract
419
  return true;
420
  }
421
 
422
- public function updateChatdata($datatype, $state)
423
  {
424
  try
425
  {
426
  $data = array(
427
- $datatype => $state,
428
  "updated_at" => date('Y-m-d H:i:s')
429
  ); // data to be insert on database
430
  $this->addData($data);
@@ -466,23 +501,25 @@ class Werules_Chatbot_Model_Chatdata extends Mage_Core_Model_Abstract
466
  return false;
467
  }
468
 
469
- protected function getProductIdsBySearch($searchstring)
470
  {
471
  // Code to Search Product by $searchstring and get Product IDs
472
- $product_collection_ids = Mage::getResourceModel('catalog/product_collection')
473
  ->addAttributeToSelect('*')
474
  ->addAttributeToFilter('visibility', 4)
475
  ->addAttributeToFilter('type_id', 'simple')
476
  ->addAttributeToFilter(
477
  array(
478
- array('attribute' => 'sku', 'like' => '%' . $searchstring .'%'),
479
- array('attribute' => 'name', 'like' => '%' . $searchstring .'%')
480
  )
481
- )
482
- ->getAllIds();
 
 
483
 
484
- if (!empty($product_collection_ids))
485
- return $product_collection_ids;
486
 
487
  return false;
488
  }
@@ -510,6 +547,31 @@ class Werules_Chatbot_Model_Chatdata extends Mage_Core_Model_Abstract
510
  return $cmd;
511
  }
512
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
513
  protected function prepareTelegramOrderMessages($orderID) // TODO add link to product name
514
  {
515
  $order = Mage::getModel('sales/order')->load($orderID);
@@ -539,15 +601,101 @@ class Werules_Chatbot_Model_Chatdata extends Mage_Core_Model_Abstract
539
  {
540
  if ($product->getStockItem()->getIsInStock() > 0)
541
  {
 
542
  $message = $product->getName() . "\n" .
 
543
  $this->excerpt($product->getShortDescription(), 60) . "\n" .
544
- Mage::helper('core')->__("Add to cart") . ": " . $this->_add2CartCmd['command'] . $product->getId();
545
  return $message;
546
  }
547
  }
548
  return null;
549
  }
550
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
551
  protected function prepareFacebookProdMessages($productID) // TODO add link to product name
552
  {
553
  $product = Mage::getModel('catalog/product')->load($productID);
36
  protected $_cmdList =
37
  "
38
  start,
39
+ list_categories,
40
  search,
41
  login,
42
  list_orders,
50
  cancel,
51
  help,
52
  about,
53
+ logout,
54
+ register
55
  ";
56
  protected $_startCmd = array();
57
  protected $_listCategoriesCmd = array();
69
  protected $_helpCmd = array();
70
  protected $_aboutCmd = array();
71
  protected $_logoutCmd = array();
72
+ protected $_registerCmd = array();
73
 
74
  // admin cmds
75
  // protected $adminCmdList =
112
  // handle webhook configuration
113
  if ($webhook && $apiKey && $action == $this->_tgBot) // set telegram webhook
114
  {
115
+ $mageHelper = Mage::helper('core');
116
+ $telegram = new Telegram($apiKey);
117
+ $customKey = Mage::getStoreConfig('chatbot_enable/general_config/your_custom_key');
118
+ //$webhookUrl = str_replace("http://", "https://", Mage::getUrl('*/*/*', array('_use_rewrite' => true, '_forced_secure' => true)));
119
+ // replace http by https, and remove all url parameters with strok
120
+ $webhookUrl = str_replace("http://", "https://", strtok(Mage::getUrl('chatbot/chatdata/' . $this->_tgBot, array('_forced_secure' => true)), '?') . "key" . DS . $customKey . DS);
121
+ try {
122
+ $telegram->setWebhook($webhookUrl);
123
  }
124
+ catch (Exception $e) {
125
+ return $mageHelper->__("Something went wrong, please try again.");
 
126
  }
127
 
128
+ //return var_dump(array('url' => $webhookUrl));
129
+ $tgGetWebhook = "<a href='https://api.telegram.org/bot" . $apiKey . "/getWebhookInfo' target='_blank'>" . $mageHelper->__("here") . "</a>";
130
+ $tgSetWebhook = "<a href='https://api.telegram.org/bot" . $apiKey . "/setWebhook?url=" . $webhookUrl . "' target='_blank'>" . $mageHelper->__("here") . "</a>";
131
+ $message = $mageHelper->__("Webhook for Telegram configured.") .
132
+ $mageHelper->__("Webhook URL") . ": " .
133
+ $webhookUrl . "<br>" .
134
+ $mageHelper->__("Click %s to check that information on Telegram website. If a wrong URL is set, try reloading this page or click %s.", $tgGetWebhook, $tgSetWebhook)
135
+ ;
136
+ return $message;
137
+ }
138
+ else if ($webhook && $apiKey && $action == $this->_fbBot) // set facebook webhook
139
+ {
140
+ $mageHelper = Mage::helper('core');
141
+ $customKey = Mage::getStoreConfig('chatbot_enable/general_config/your_custom_key');
142
+ // replace http by https, and remove all url parameters with strok
143
+ $webhookUrl = str_replace("http://", "https://", strtok(Mage::getUrl('chatbot/chatdata/' . $this->_fbBot, array('_forced_secure' => true)), '?') . "key" . DS . $customKey . DS);
144
+
145
+ $message = $mageHelper->__("To configure Facebook webhook access") .
146
+ " https://developers.facebook.com/apps/(FACEBOOK_APP_ID)/webhooks/ " .
147
+ $mageHelper->__("and set the webhook URL as") . " " . $webhookUrl
148
+ ;
149
+ return $message;
150
  } // start to handle conversation
151
  else if ($action == $this->_tgBot && $apiKey) // telegram api
152
  {
183
  return null;
184
  }
185
 
186
+ protected function sendEmail($text, $username)
187
  {
188
  $storeName = Mage::app()->getStore()->getName();
189
  $storeEmail = Mage::getStoreConfig('trans_email/ident_general/email');// TODO
190
+ $mageHelper = Mage::helper('core');
191
 
192
+ $url = $mageHelper->__("Not informed");
193
+ $customerEmail = $mageHelper->__("Not informed");
194
+ if ($username)
195
+ $customerName = $username;
196
+ else
197
+ $customerName = $mageHelper->__("Not informed");
198
 
199
  $mail = new Zend_Mail('UTF-8');
200
 
218
  }
219
 
220
  $emailBody =
221
+ $mageHelper->__("Message from chatbot customer") . "<br><br>" .
222
+ $mageHelper->__("Customer name") . ": " .
223
  $customerName . "<br>" .
224
+ $mageHelper->__("Message") . ":<br>" .
225
  $text . "<br><br>" .
226
+ $mageHelper->__("Contacts") . ":<br>" .
227
+ $mageHelper->__("Chatbot") . ": " . $url . "<br>" .
228
+ $mageHelper->__("Email") . ": " . $customerEmail . "<br>";
229
 
230
  $mail->setBodyHtml($emailBody);
231
  $mail->setFrom($storeEmail, $storeName);
309
  protected function getCommandString($cmdId)
310
  {
311
  $rep = "";
312
+ $confPath = "";
313
  if ($this->_apiType == $this->_tgBot)
314
  {
315
  $rep = "_";
316
+ $confPath = 'chatbot_enable/telegram_config/';
317
  }
318
  else if ($this->_apiType == $this->_fbBot)
319
  {
320
  $rep = " ";
321
+ $confPath = 'chatbot_enable/facebook_config/';
322
  }
 
 
323
 
324
+ $defaultCmds = explode(',', $this->_cmdList);
325
+ if (is_array($defaultCmds)) // should never fail
 
326
  {
327
+ $cmdCode = "";
328
+ $alias = array();
329
+ $config = Mage::getStoreConfig($confPath . 'commands_list');
330
+ if (!empty($config))
331
  {
332
+ $commands = unserialize($config);
333
+ if (is_array($commands))
334
  {
335
+ foreach($commands as $cmd)
 
 
 
336
  {
337
+ if ($cmd['command_id'] == $cmdId && $cmd['enable_command'] == "1")
 
338
  {
339
+ if (empty($cmd['command_code']))
340
  {
 
 
 
 
 
 
 
 
341
  $cmdCode = $defaultCmds[$cmdId];
342
+ break;
343
+ }
344
+
345
+ $cmdCode = $cmd['command_code'];
346
+ $alias = array_map('strtolower', explode(',', $cmd['command_alias_list']));
347
+ break;
348
  }
 
 
349
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
  }
351
+ else // if no command found, return the default
352
+ $cmdCode = $defaultCmds[$cmdId];
353
  }
354
+ else // if no command found, return the default
355
+ $cmdCode = $defaultCmds[$cmdId];
356
+
357
+ if (empty($cmdCode)) // if no command enabled found, return null
358
+ return array('command' => null, 'alias' => null);
359
+
360
+ $cmdCode = preg_replace( // remove all non-alphanumerics
361
+ $this->_unallowedCharacters,
362
+ '',
363
+ str_replace( // replace whitespace for underscore
364
+ ' ',
365
+ $rep,
366
+ trim($cmdCode)
367
+ )
368
+ );
369
+
370
+ return array('command' => strtolower($cmdCode), 'alias' => $alias);
371
  }
372
+
373
  return array('command' => null, 'alias' => null);
374
  }
375
 
406
  return false;
407
  }
408
 
409
+ protected function startsWith($haystack, $needle)
410
  {
411
+ if ($needle)
412
+ return substr($haystack, 0, strlen($needle)) == $needle;
413
  return false;
414
  }
415
 
416
+ protected function endsWith($haystack, $needle)
417
+ {
418
+ $length = strlen($needle);
419
+ if ($length == 0)
420
+ return true;
421
+
422
+ return (substr($haystack, -$length) === $needle);
423
+ }
424
+
425
  protected function clearCart()
426
  {
427
  try
454
  return true;
455
  }
456
 
457
+ public function updateChatdata($dataType, $state)
458
  {
459
  try
460
  {
461
  $data = array(
462
+ $dataType => $state,
463
  "updated_at" => date('Y-m-d H:i:s')
464
  ); // data to be insert on database
465
  $this->addData($data);
501
  return false;
502
  }
503
 
504
+ protected function getProductIdsBySearch($searchString)
505
  {
506
  // Code to Search Product by $searchstring and get Product IDs
507
+ $productCollection = Mage::getResourceModel('catalog/product_collection')
508
  ->addAttributeToSelect('*')
509
  ->addAttributeToFilter('visibility', 4)
510
  ->addAttributeToFilter('type_id', 'simple')
511
  ->addAttributeToFilter(
512
  array(
513
+ array('attribute' => 'sku', 'like' => '%' . $searchString .'%'),
514
+ array('attribute' => 'name', 'like' => '%' . $searchString .'%')
515
  )
516
+ );
517
+ //->getAllIds();
518
+ Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($productCollection);
519
+ $productIDs = $productCollection->getAllIds();
520
 
521
+ if (!empty($productIDs))
522
+ return $productIDs;
523
 
524
  return false;
525
  }
547
  return $cmd;
548
  }
549
 
550
+ protected function listTelegramCommandsMessage()
551
+ {
552
+ $mageHelper = Mage::helper('core');
553
+
554
+ $message = "\n\n" . $mageHelper->__("Command list") . ":\n";
555
+ if ($this->_listCategoriesCmd['command']) $message .= $this->_listCategoriesCmd['command'] . " - " . $mageHelper->__("List store categories.") . "\n";
556
+ if ($this->_searchCmd['command']) $message .= $this->_searchCmd['command'] . " - " . $mageHelper->__("Search for products.") . "\n";
557
+ if ($this->_loginCmd['command']) $message .= $this->_loginCmd['command'] . " - " . $mageHelper->__("Login into your account.") . "\n";
558
+ if ($this->_logoutCmd['command']) $message .= $this->_logoutCmd['command'] . " - " . $mageHelper->__("Logout from your account.") . "\n";
559
+ if ($this->_registerCmd['command']) $message .= $this->_registerCmd['command'] . " - " . $mageHelper->__("Create a new account.") . "\n";
560
+ if ($this->_listOrdersCmd['command']) $message .= $this->_listOrdersCmd['command'] . " - " . $mageHelper->__("List your personal orders.") . "\n";
561
+ //$message .= $chatdata->_reorderCmd['command'] . " - " . $magehelper->__("Reorder a order.") . "\n";
562
+ //$message .= $chatdata->_add2CartCmd['command'] . " - " . $magehelper->__("Add product to cart.") . "\n";
563
+ if ($this->_checkoutCmd['command']) $message .= $this->_checkoutCmd['command'] . " - " . $mageHelper->__("Checkout your order.") . "\n";
564
+ if ($this->_clearCartCmd['command']) $message .= $this->_clearCartCmd['command'] . " - " . $mageHelper->__("Clear your cart.") . "\n";
565
+ if ($this->_trackOrderCmd['command']) $message .= $this->_trackOrderCmd['command'] . " - " . $mageHelper->__("Track your order status.") . "\n";
566
+ if ($this->_supportCmd['command']) $message .= $this->_supportCmd['command'] . " - " . $mageHelper->__("Send message to support.") . "\n";
567
+ if ($this->_sendEmailCmd['command']) $message .= $this->_sendEmailCmd['command'] . " - " . $mageHelper->__("Send email.") . "\n";
568
+ //$message .= $chatdata->_cancelCmd['command'] . " - " . $magehelper->__("Cancel.");
569
+ if ($this->_helpCmd['command']) $message .= $this->_helpCmd['command'] . " - " . $mageHelper->__("Get help.") . "\n";
570
+ if ($this->_aboutCmd['command']) $message .= $this->_aboutCmd['command'] . " - " . $mageHelper->__("About.") . "\n";
571
+
572
+ return $message;
573
+ }
574
+
575
  protected function prepareTelegramOrderMessages($orderID) // TODO add link to product name
576
  {
577
  $order = Mage::getModel('sales/order')->load($orderID);
601
  {
602
  if ($product->getStockItem()->getIsInStock() > 0)
603
  {
604
+ $mageHelper = Mage::helper('core');
605
  $message = $product->getName() . "\n" .
606
+ $mageHelper->__("Price") . ": " . Mage::helper('core')->currency($product->getPrice(), true, false) . "\n" .
607
  $this->excerpt($product->getShortDescription(), 60) . "\n" .
608
+ $mageHelper->__("Add to cart") . ": " . $this->_add2CartCmd['command'] . $product->getId();
609
  return $message;
610
  }
611
  }
612
  return null;
613
  }
614
 
615
+ // FACEBOOK FUNCTIONS
616
+ protected function listFacebookCommandsMessage()
617
+ {
618
+ $mageHelper = Mage::helper('core');
619
+
620
+ $message = "\n\n" . $mageHelper->__("Command list") . ":\n";
621
+ $replies = array(); // quick replies limit is 10 options
622
+ $content = array();
623
+ // some commands are commented because of the 10 limit from Facebook
624
+ // just getting the command string, not checking the command
625
+ if ($this->_listCategoriesCmd['command']) // 1
626
+ {
627
+ array_push($replies, array('content_type' => 'text', 'title' => $this->_listCategoriesCmd['command'], 'payload' => str_replace(' ', '_', $this->_listCategoriesCmd['command'])));
628
+ $message .= '"' . $this->_listCategoriesCmd['command'] . '"' . " - " . $mageHelper->__("List store categories.") . "\n";
629
+ }
630
+ if ($this->_searchCmd['command']) // 2
631
+ {
632
+ array_push($replies, array('content_type' => 'text', 'title' => $this->_searchCmd['command'], 'payload' => str_replace(' ', '_', $this->_searchCmd['command'])));
633
+ $message .= '"' . $this->_searchCmd['command'] . '"' . " - " . $mageHelper->__("Search for products.") . "\n";
634
+ }
635
+ if ($this->_loginCmd['command']) // 3
636
+ {
637
+ array_push($replies, array('content_type' => 'text', 'title' => $this->_loginCmd['command'], 'payload' => str_replace(' ', '_', $this->_loginCmd['command'])));
638
+ $message .= '"' . $this->_loginCmd['command'] . '"' . " - " . $mageHelper->__("Login into your account.") . "\n";
639
+ }
640
+ if ($this->_logoutCmd['command']) // 4
641
+ {
642
+ //array_push($replies, array('content_type' => 'text', 'title' => $chatdata->_logoutCmd['command'], 'payload' => str_replace(' ', '_', $chatdata->_loginCmd['command'])));
643
+ $message .= '"' . $this->_logoutCmd['command'] . '"' . " - " . $mageHelper->__("Logout from your account.") . "\n";
644
+ }
645
+ if ($this->_registerCmd['command']) // 5
646
+ {
647
+ array_push($replies, array('content_type' => 'text', 'title' => $this->_registerCmd['command'], 'payload' => str_replace(' ', '_', $this->_registerCmd['command'])));
648
+ $message .= '"' . $this->_registerCmd['command'] . '"' . " - " . $mageHelper->__("Create a new account.") . "\n";
649
+ }
650
+ if ($this->_listOrdersCmd['command']) // 6
651
+ {
652
+ array_push($replies, array('content_type' => 'text', 'title' => $this->_listOrdersCmd['command'], 'payload' => str_replace(' ', '_', $this->_listOrdersCmd['command'])));
653
+ $message .= '"' . $this->_listOrdersCmd['command'] . '"' . " - " . $mageHelper->__("List your personal orders.") . "\n";
654
+ }
655
+ //$message .= '"' . $chatdata->_reorderCmd['command'] . '"' . " - " . $magehelper->__("Reorder a order.") . "\n";
656
+ //$message .= '"' . $chatdata->_add2CartCmd['command'] . '"' . " - " . $magehelper->__("Add product to cart.") . "\n";
657
+ if ($this->_checkoutCmd['command']) // 7
658
+ {
659
+ //array_push($replies, array('content_type' => 'text', 'title' => $chatdata->_checkoutCmd['command'], 'payload' => str_replace(' ', '_', $chatdata->_checkoutCmd['command'])));
660
+ $message .= '"' . $this->_checkoutCmd['command'] . '"' . " - " . $mageHelper->__("Checkout your order.") . "\n";
661
+ }
662
+ if ($this->_clearCartCmd['command']) // 8
663
+ {
664
+ array_push($replies, array('content_type' => 'text', 'title' => $this->_clearCartCmd['command'], 'payload' => str_replace(' ', '_', $this->_clearCartCmd['command'])));
665
+ $message .= '"' . $this->_clearCartCmd['command'] . '"' . " - " . $mageHelper->__("Clear your cart.") . "\n";
666
+ }
667
+ if ($this->_trackOrderCmd['command']) // 9
668
+ {
669
+ array_push($replies, array('content_type' => 'text', 'title' => $this->_trackOrderCmd['command'], 'payload' => str_replace(' ', '_', $this->_trackOrderCmd['command'])));
670
+ $message .= '"' . $this->_trackOrderCmd['command'] . '"' . " - " . $mageHelper->__("Track your order status.") . "\n";
671
+ }
672
+ if ($this->_supportCmd['command']) // 10
673
+ {
674
+ array_push($replies, array('content_type' => 'text', 'title' => $this->_supportCmd['command'], 'payload' => str_replace(' ', '_', $this->_supportCmd['command'])));
675
+ $message .= '"' . $this->_supportCmd['command'] . '"' . " - " . $mageHelper->__("Send message to support.") . "\n";
676
+ }
677
+ if ($this->_sendEmailCmd['command']) // 11
678
+ {
679
+ array_push($replies, array('content_type' => 'text', 'title' => $this->_sendEmailCmd['command'], 'payload' => str_replace(' ', '_', $this->_sendEmailCmd['command'])));
680
+ $message .= '"' . $this->_sendEmailCmd['command'] . '"' . " - " . $mageHelper->__("Send email.") . "\n";
681
+ }
682
+ //$message .= '"' . $chatdata->_cancelCmd['command'] . '"' . " - " . $magehelper->__("Cancel.");
683
+ if ($this->_aboutCmd['command']) // 12
684
+ {
685
+ array_push($replies, array('content_type' => 'text', 'title' => $this->_aboutCmd['command'], 'payload' => str_replace(' ', '_', $this->_aboutCmd['command'])));
686
+ $message .= '"' . $this->_aboutCmd['command'] . '"' . " - " . $mageHelper->__("About.") . "\n";
687
+ }
688
+ if ($this->_helpCmd['command']) // 13
689
+ {
690
+ //array_push($replies, array('content_type' => 'text', 'title' => $this->_helpCmd['command'], 'payload' => str_replace(' ', '_', $this->_helpCmd['command'])));
691
+ $message .= '"' . $this->_helpCmd['command'] . '"' . " - " . $mageHelper->__("Get help.") . "\n";
692
+ }
693
+
694
+ array_push($content, $message); // $content[0] -> $message
695
+ array_push($content, $replies); // $content[1] -> $replies
696
+ return $content;
697
+ }
698
+
699
  protected function prepareFacebookProdMessages($productID) // TODO add link to product name
700
  {
701
  $product = Mage::getModel('catalog/product')->load($productID);
app/code/community/Werules/Chatbot/Model/Options.php CHANGED
@@ -24,7 +24,8 @@ class Werules_Chatbot_Model_Options
24
  array('value'=>12, 'label'=>'Cancel'),
25
  array('value'=>13, 'label'=>'Help'),
26
  array('value'=>14, 'label'=>'About'),
27
- array('value'=>15, 'label'=>'Logout')
 
28
  );
29
  }
30
  }
24
  array('value'=>12, 'label'=>'Cancel'),
25
  array('value'=>13, 'label'=>'Help'),
26
  array('value'=>14, 'label'=>'About'),
27
+ array('value'=>15, 'label'=>'Logout'),
28
+ array('value'=>16, 'label'=>'Register')
29
  );
30
  }
31
  }
app/code/community/Werules/Chatbot/Model/ReplyMode.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Werules_Chatbot_Model_ReplyMode
3
+ {
4
+ /**
5
+ * Provide available enable as a value/label array
6
+ *
7
+ * @return array
8
+ */
9
+ public function toOptionArray()
10
+ {
11
+ return array(
12
+ array('value'=>0, 'label'=>'Similarity'),
13
+ array('value'=>1, 'label'=>'Starts With'),
14
+ array('value'=>2, 'label'=>'Ends With'),
15
+ array('value'=>3, 'label'=>'Contains'),
16
+ array('value'=>4, 'label'=>'Match Regular Expression'),
17
+ array('value'=>5, 'label'=>'Equals to')
18
+ );
19
+ }
20
+ }
app/code/community/Werules/Chatbot/controllers/ChatdataController.php CHANGED
@@ -11,6 +11,10 @@ class Werules_Chatbot_ChatdataController extends Mage_Core_Controller_Front_Acti
11
  {
12
  $this->loadLayout();
13
  $this->getLayout()->getBlock('root')->setTemplate("werules_chatbot_view.phtml"); // use root block to output pure values without html tags
 
 
 
 
14
  $this->renderLayout();
15
  }
16
 
11
  {
12
  $this->loadLayout();
13
  $this->getLayout()->getBlock('root')->setTemplate("werules_chatbot_view.phtml"); // use root block to output pure values without html tags
14
+ //$this->getLayout()->getBlock('root')->setTemplate("werules_chatbot_view.phtml")->setTitle(Mage::helper('core')->__('Chatbot')); // use root block to output pure values without html tags
15
+ //$this->getLayout()->getBlock('head')->setTitle(Mage::helper('core')->__('Chatbot'));
16
+ //$this->getLayout()->getBlock('head')->setTitle($this->__('My Title')); // then this works
17
+ //$this->getLayout()->unsetBlock('head');
18
  $this->renderLayout();
19
  }
20
 
app/code/community/Werules/Chatbot/controllers/SettingsController.php CHANGED
@@ -21,7 +21,7 @@ class Werules_Chatbot_SettingsController extends Mage_Core_Controller_Front_Acti
21
 
22
  public function saveAction()
23
  {
24
- $magehelper = Mage::helper('core');
25
  $postData = $this->getRequest()->getPost(); // get all post data
26
  if ($postData)
27
  {
@@ -44,11 +44,11 @@ class Werules_Chatbot_SettingsController extends Mage_Core_Controller_Front_Acti
44
  $chatdata->addData($data);
45
  $chatdata->save();
46
 
47
- Mage::getSingleton('customer/session')->addSuccess($magehelper->__("Chatbot settings saved successfully.")); // throw success message to the html page
48
  }
49
  catch (Exception $e)
50
  {
51
- Mage::getSingleton('customer/session')->addError($magehelper->__("Something went wrong, please try again.")); // throw error message to the html page
52
  }
53
  }
54
  $this->_redirect('chatbot/settings/index'); // redirect customer to settings page
@@ -67,7 +67,7 @@ class Werules_Chatbot_SettingsController extends Mage_Core_Controller_Front_Acti
67
  $error = false;
68
  $logged = true;
69
  $data = array();
70
- $magehelper = Mage::helper('core');
71
  $chatdataHash = Mage::getModel('chatbot/chatdata')->load($hash, 'hash_key');
72
  if ($chatdataHash->getIsLogged() == "0")
73
  {
@@ -157,10 +157,10 @@ class Werules_Chatbot_SettingsController extends Mage_Core_Controller_Front_Acti
157
  }
158
  // messages
159
  if ($success)
160
- Mage::getSingleton('customer/session')->addSuccess($magehelper->__("Your account is now attached with our chatbot."));
161
  else if ($error)
162
- Mage::getSingleton('customer/session')->addError($magehelper->__("Something went wrong, please try again."));
163
  else if ($logged)
164
- Mage::getSingleton('customer/session')->addNotice($magehelper->__("You're already logged."));
165
  }
166
  }
21
 
22
  public function saveAction()
23
  {
24
+ $mageHelper = Mage::helper('core');
25
  $postData = $this->getRequest()->getPost(); // get all post data
26
  if ($postData)
27
  {
44
  $chatdata->addData($data);
45
  $chatdata->save();
46
 
47
+ Mage::getSingleton('customer/session')->addSuccess($mageHelper->__("Chatbot settings saved successfully.")); // throw success message to the html page
48
  }
49
  catch (Exception $e)
50
  {
51
+ Mage::getSingleton('customer/session')->addError($mageHelper->__("Something went wrong, please try again.")); // throw error message to the html page
52
  }
53
  }
54
  $this->_redirect('chatbot/settings/index'); // redirect customer to settings page
67
  $error = false;
68
  $logged = true;
69
  $data = array();
70
+ $mageHelper = Mage::helper('core');
71
  $chatdataHash = Mage::getModel('chatbot/chatdata')->load($hash, 'hash_key');
72
  if ($chatdataHash->getIsLogged() == "0")
73
  {
157
  }
158
  // messages
159
  if ($success)
160
+ Mage::getSingleton('customer/session')->addSuccess($mageHelper->__("Your account is now attached with our chatbot."));
161
  else if ($error)
162
+ Mage::getSingleton('customer/session')->addError($mageHelper->__("Something went wrong, please try again."));
163
  else if ($logged)
164
+ Mage::getSingleton('customer/session')->addNotice($mageHelper->__("You're already logged."));
165
  }
166
  }
app/code/community/Werules/Chatbot/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Werules_Chatbot>
5
- <version>0.0.5</version>
6
  </Werules_Chatbot>
7
  </modules>
8
  <frontend>
2
  <config>
3
  <modules>
4
  <Werules_Chatbot>
5
+ <version>0.0.9</version>
6
  </Werules_Chatbot>
7
  </modules>
8
  <frontend>
app/code/community/Werules/Chatbot/etc/system.xml CHANGED
@@ -33,7 +33,7 @@
33
  <show_in_default>1</show_in_default>
34
  <show_in_website>1</show_in_website>
35
  <show_in_store>1</show_in_store>
36
- <comment>This is Your Custom Secret Key Used to Activate/Deactivate The API Webhook For Telegram, And to Use as Your Challenge Hub For Facebook. Alphanumeric Only! Access http://YOUR_STORE_URL/chatbot/chatdata/API/telegram/YOUR_CUSTOM_KEY to Set Telegram Webhook.</comment>
37
  </your_custom_key>
38
  <master_support_group>
39
  <label>Master Support Group</label>
@@ -133,7 +133,7 @@
133
  <show_in_default>1</show_in_default>
134
  <show_in_website>1</show_in_website>
135
  <show_in_store>1</show_in_store>
136
- <comment>Message To Send When Bot Is Disabled. Leave It Empty To Send No Message.</comment>
137
  </disabled_message>
138
  <telegram_api_key>
139
  <label>Telegram Bot API Key</label>
@@ -160,7 +160,7 @@
160
  <show_in_default>1</show_in_default>
161
  <show_in_website>1</show_in_website>
162
  <show_in_store>1</show_in_store>
163
- <comment>First Message The Bot Will Send To Your Client.</comment>
164
  </telegram_welcome_msg>
165
  <telegram_help_msg>
166
  <label>Telegram Help Message</label>
@@ -169,7 +169,7 @@
169
  <show_in_default>1</show_in_default>
170
  <show_in_website>1</show_in_website>
171
  <show_in_store>1</show_in_store>
172
- <comment>Message Will be Sent When Customer Asks For Help.</comment>
173
  </telegram_help_msg>
174
  <telegram_about_msg>
175
  <label>Telegram About Message</label>
@@ -178,33 +178,33 @@
178
  <show_in_default>1</show_in_default>
179
  <show_in_website>1</show_in_website>
180
  <show_in_store>1</show_in_store>
181
- <comment>Message Will be Sent When Customer Asks For About.</comment>
182
  </telegram_about_msg>
183
- <enable_command_list>
184
- <label>Enable Command Listing</label>
185
  <frontend_type>select</frontend_type>
186
  <source_model>chatbot/enable</source_model>
187
  <sort_order>7</sort_order>
188
  <show_in_default>1</show_in_default>
189
  <show_in_website>1</show_in_website>
190
  <show_in_store>1</show_in_store>
191
- <comment>Enable Command Listing When Customer Ask For About</comment>
192
- </enable_command_list>
193
- <enabled_commands>
194
- <label>Enabled Commands</label>
195
- <frontend_type>multiselect</frontend_type>
196
- <source_model>chatbot/options</source_model>
197
  <sort_order>8</sort_order>
198
  <show_in_default>1</show_in_default>
199
  <show_in_website>1</show_in_website>
200
  <show_in_store>1</show_in_store>
201
- <comment>Enabled Commands</comment>
202
- </enabled_commands>
203
  <commands_list>
204
  <label>Commands List</label>
205
  <frontend_model>werules_chatbot/commands</frontend_model>
206
  <backend_model>chatbot/adminhtml_serialized</backend_model> <!-- TODO adminhtml/system_config_backend_serialized_array -->
207
- <sort_order>9</sort_order>
208
  <show_in_default>1</show_in_default>
209
  <show_in_website>1</show_in_website>
210
  <show_in_store>0</show_in_store>
@@ -214,7 +214,7 @@
214
  <label>Enable Default Replies</label>
215
  <frontend_type>select</frontend_type>
216
  <source_model>chatbot/enable</source_model>
217
- <sort_order>10</sort_order>
218
  <show_in_default>1</show_in_default>
219
  <show_in_website>1</show_in_website>
220
  <show_in_store>1</show_in_store>
@@ -224,11 +224,11 @@
224
  <label>Default Replies</label>
225
  <frontend_model>werules_chatbot/replies</frontend_model>
226
  <backend_model>chatbot/adminhtml_serialized</backend_model> <!-- TODO adminhtml/system_config_backend_serialized_array -->
227
- <sort_order>11</sort_order>
228
  <show_in_default>1</show_in_default>
229
  <show_in_website>1</show_in_website>
230
  <show_in_store>0</show_in_store>
231
- <comment>Default Replies.</comment>
232
  </default_replies>
233
  </fields>
234
  </telegram_config>
@@ -258,7 +258,7 @@
258
  <show_in_default>1</show_in_default>
259
  <show_in_website>1</show_in_website>
260
  <show_in_store>1</show_in_store>
261
- <comment>Message To Send When Bot Is Disabled. Leave It Empty To Send No Message.</comment>
262
  </disabled_message>
263
  <facebook_api_key>
264
  <label>Messenger Bot API Key</label>
@@ -285,7 +285,7 @@
285
  <show_in_default>1</show_in_default>
286
  <show_in_website>1</show_in_website>
287
  <show_in_store>1</show_in_store>
288
- <comment>First Message The Bot Will Send To Your Client.</comment>
289
  </facebook_welcome_msg>
290
  <facebook_help_msg>
291
  <label>Messenger Help Message</label>
@@ -294,7 +294,7 @@
294
  <show_in_default>1</show_in_default>
295
  <show_in_website>1</show_in_website>
296
  <show_in_store>1</show_in_store>
297
- <comment>Message Will be Sent When Customer Asks For Help.</comment>
298
  </facebook_help_msg>
299
  <facebook_about_msg>
300
  <label>Messenger About Message</label>
@@ -303,10 +303,10 @@
303
  <show_in_default>1</show_in_default>
304
  <show_in_website>1</show_in_website>
305
  <show_in_store>1</show_in_store>
306
- <comment>Message Will be Sent When Customer Asks For About.</comment>
307
  </facebook_about_msg>
308
- <enable_command_list>
309
- <label>Enable Command Listing</label>
310
  <frontend_type>select</frontend_type>
311
  <source_model>chatbot/enable</source_model>
312
  <sort_order>7</sort_order>
@@ -314,32 +314,32 @@
314
  <show_in_website>1</show_in_website>
315
  <show_in_store>1</show_in_store>
316
  <comment>Enable Command Listing When Customer Ask For About</comment>
317
- </enable_command_list>
318
- <enable_predict_commands>
319
- <label>Enable Command Prediction</label>
320
  <frontend_type>select</frontend_type>
321
  <source_model>chatbot/enable</source_model>
322
  <sort_order>8</sort_order>
323
  <show_in_default>1</show_in_default>
324
  <show_in_website>1</show_in_website>
325
  <show_in_store>1</show_in_store>
326
- <comment>Enable The Bot to Try to Predict What Command The Customer Wants by Looking into What He Wrote</comment>
327
- </enable_predict_commands>
328
- <enabled_commands>
329
- <label>Enabled Commands</label>
330
- <frontend_type>multiselect</frontend_type>
331
- <source_model>chatbot/options</source_model>
332
  <sort_order>9</sort_order>
333
  <show_in_default>1</show_in_default>
334
  <show_in_website>1</show_in_website>
335
  <show_in_store>1</show_in_store>
336
- <comment>Enabled Commands</comment>
337
- </enabled_commands>
338
  <commands_list>
339
  <label>Commands List</label>
340
  <frontend_model>werules_chatbot/commands</frontend_model>
341
  <backend_model>chatbot/adminhtml_serialized</backend_model> <!-- TODO adminhtml/system_config_backend_serialized_array -->
342
- <sort_order>10</sort_order>
343
  <show_in_default>1</show_in_default>
344
  <show_in_website>1</show_in_website>
345
  <show_in_store>0</show_in_store>
@@ -349,7 +349,7 @@
349
  <label>Enable Default Replies</label>
350
  <frontend_type>select</frontend_type>
351
  <source_model>chatbot/enable</source_model>
352
- <sort_order>11</sort_order>
353
  <show_in_default>1</show_in_default>
354
  <show_in_website>1</show_in_website>
355
  <show_in_store>1</show_in_store>
@@ -359,11 +359,11 @@
359
  <label>Default Replies</label>
360
  <frontend_model>werules_chatbot/replies</frontend_model>
361
  <backend_model>chatbot/adminhtml_serialized</backend_model> <!-- TODO adminhtml/system_config_backend_serialized_array -->
362
- <sort_order>12</sort_order>
363
  <show_in_default>1</show_in_default>
364
  <show_in_website>1</show_in_website>
365
  <show_in_store>0</show_in_store>
366
- <comment>Default Replies.</comment>
367
  </default_replies>
368
  </fields>
369
  </facebook_config>
33
  <show_in_default>1</show_in_default>
34
  <show_in_website>1</show_in_website>
35
  <show_in_store>1</show_in_store>
36
+ <comment>This is Your Custom Secret Key Used For The Webhook URL, to Activate/Deactivate The API Webhook For Telegram, And to Use as Your Challenge Hub For Facebook. Alphanumeric Only! Access http://(YOUR_STORE_URL)/chatbot/chatdata/(API)/webhook/(YOUR_CUSTOM_KEY) to Set The Webhook, change API to "telegram" or "facebook".</comment>
37
  </your_custom_key>
38
  <master_support_group>
39
  <label>Master Support Group</label>
133
  <show_in_default>1</show_in_default>
134
  <show_in_website>1</show_in_website>
135
  <show_in_store>1</show_in_store>
136
+ <comment>Message To Send When Bot Is Disabled. Leave It Empty To Send No Message. Please Check The Maximum Size For Messages On Telegram API, Otherwise Your Message Might Not Be Sent.</comment>
137
  </disabled_message>
138
  <telegram_api_key>
139
  <label>Telegram Bot API Key</label>
160
  <show_in_default>1</show_in_default>
161
  <show_in_website>1</show_in_website>
162
  <show_in_store>1</show_in_store>
163
+ <comment>First Message The Bot Will Send To Your Client. Please Check The Maximum Size For Messages On Telegram API, Otherwise Your Message Might Not Be Sent.</comment>
164
  </telegram_welcome_msg>
165
  <telegram_help_msg>
166
  <label>Telegram Help Message</label>
169
  <show_in_default>1</show_in_default>
170
  <show_in_website>1</show_in_website>
171
  <show_in_store>1</show_in_store>
172
+ <comment>Message Will be Sent When Customer Asks For Help. Please Check The Maximum Size For Messages On Telegram API, Otherwise Your Message Might Not Be Sent.</comment>
173
  </telegram_help_msg>
174
  <telegram_about_msg>
175
  <label>Telegram About Message</label>
178
  <show_in_default>1</show_in_default>
179
  <show_in_website>1</show_in_website>
180
  <show_in_store>1</show_in_store>
181
+ <comment>Message Will be Sent When Customer Asks For About. Please Check The Maximum Size For Messages On Telegram API, Otherwise Your Message Might Not Be Sent.</comment>
182
  </telegram_about_msg>
183
+ <enable_help_command_list>
184
+ <label>Enable Command Listing On Help</label>
185
  <frontend_type>select</frontend_type>
186
  <source_model>chatbot/enable</source_model>
187
  <sort_order>7</sort_order>
188
  <show_in_default>1</show_in_default>
189
  <show_in_website>1</show_in_website>
190
  <show_in_store>1</show_in_store>
191
+ <comment>Enable Command Listing When Customer Ask For Help</comment>
192
+ </enable_help_command_list>
193
+ <enable_error_command_list>
194
+ <label>Enable Command Listing On Error</label>
195
+ <frontend_type>select</frontend_type>
196
+ <source_model>chatbot/enable</source_model>
197
  <sort_order>8</sort_order>
198
  <show_in_default>1</show_in_default>
199
  <show_in_website>1</show_in_website>
200
  <show_in_store>1</show_in_store>
201
+ <comment>Enable Command Listing When The Bot Don't Understand What The Customer Typed</comment>
202
+ </enable_error_command_list>
203
  <commands_list>
204
  <label>Commands List</label>
205
  <frontend_model>werules_chatbot/commands</frontend_model>
206
  <backend_model>chatbot/adminhtml_serialized</backend_model> <!-- TODO adminhtml/system_config_backend_serialized_array -->
207
+ <sort_order>10</sort_order>
208
  <show_in_default>1</show_in_default>
209
  <show_in_website>1</show_in_website>
210
  <show_in_store>0</show_in_store>
214
  <label>Enable Default Replies</label>
215
  <frontend_type>select</frontend_type>
216
  <source_model>chatbot/enable</source_model>
217
+ <sort_order>11</sort_order>
218
  <show_in_default>1</show_in_default>
219
  <show_in_website>1</show_in_website>
220
  <show_in_store>1</show_in_store>
224
  <label>Default Replies</label>
225
  <frontend_model>werules_chatbot/replies</frontend_model>
226
  <backend_model>chatbot/adminhtml_serialized</backend_model> <!-- TODO adminhtml/system_config_backend_serialized_array -->
227
+ <sort_order>12</sort_order>
228
  <show_in_default>1</show_in_default>
229
  <show_in_website>1</show_in_website>
230
  <show_in_store>0</show_in_store>
231
+ <comment>Replies to be Send to The Customer Whenever Matches One of The Requirements.</comment>
232
  </default_replies>
233
  </fields>
234
  </telegram_config>
258
  <show_in_default>1</show_in_default>
259
  <show_in_website>1</show_in_website>
260
  <show_in_store>1</show_in_store>
261
+ <comment>Message To Send When Bot Is Disabled. Leave It Empty To Send No Message. Please Check The Maximum Size For Messages On Facebook API, Otherwise Your Message Might Not Be Sent.</comment>
262
  </disabled_message>
263
  <facebook_api_key>
264
  <label>Messenger Bot API Key</label>
285
  <show_in_default>1</show_in_default>
286
  <show_in_website>1</show_in_website>
287
  <show_in_store>1</show_in_store>
288
+ <comment>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.</comment>
289
  </facebook_welcome_msg>
290
  <facebook_help_msg>
291
  <label>Messenger Help Message</label>
294
  <show_in_default>1</show_in_default>
295
  <show_in_website>1</show_in_website>
296
  <show_in_store>1</show_in_store>
297
+ <comment>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.</comment>
298
  </facebook_help_msg>
299
  <facebook_about_msg>
300
  <label>Messenger About Message</label>
303
  <show_in_default>1</show_in_default>
304
  <show_in_website>1</show_in_website>
305
  <show_in_store>1</show_in_store>
306
+ <comment>Message Will be Sent When Customer Asks For About. Please Check The Maximum Size For Messages On Facebook API, Otherwise Your Message Might Not Be Sent.</comment>
307
  </facebook_about_msg>
308
+ <enable_help_command_list>
309
+ <label>Enable Command Listing On Help</label>
310
  <frontend_type>select</frontend_type>
311
  <source_model>chatbot/enable</source_model>
312
  <sort_order>7</sort_order>
314
  <show_in_website>1</show_in_website>
315
  <show_in_store>1</show_in_store>
316
  <comment>Enable Command Listing When Customer Ask For About</comment>
317
+ </enable_help_command_list>
318
+ <enable_error_command_list>
319
+ <label>Enable Command Listing On Error</label>
320
  <frontend_type>select</frontend_type>
321
  <source_model>chatbot/enable</source_model>
322
  <sort_order>8</sort_order>
323
  <show_in_default>1</show_in_default>
324
  <show_in_website>1</show_in_website>
325
  <show_in_store>1</show_in_store>
326
+ <comment>Enable Command Listing When The Bot Don't Understand What The Customer Typed</comment>
327
+ </enable_error_command_list>
328
+ <enable_predict_commands>
329
+ <label>Enable Command Prediction</label>
330
+ <frontend_type>select</frontend_type>
331
+ <source_model>chatbot/enable</source_model>
332
  <sort_order>9</sort_order>
333
  <show_in_default>1</show_in_default>
334
  <show_in_website>1</show_in_website>
335
  <show_in_store>1</show_in_store>
336
+ <comment>Enable The Bot to Try to Predict What Command The Customer Wants by Looking into What He Wrote</comment>
337
+ </enable_predict_commands>
338
  <commands_list>
339
  <label>Commands List</label>
340
  <frontend_model>werules_chatbot/commands</frontend_model>
341
  <backend_model>chatbot/adminhtml_serialized</backend_model> <!-- TODO adminhtml/system_config_backend_serialized_array -->
342
+ <sort_order>11</sort_order>
343
  <show_in_default>1</show_in_default>
344
  <show_in_website>1</show_in_website>
345
  <show_in_store>0</show_in_store>
349
  <label>Enable Default Replies</label>
350
  <frontend_type>select</frontend_type>
351
  <source_model>chatbot/enable</source_model>
352
+ <sort_order>12</sort_order>
353
  <show_in_default>1</show_in_default>
354
  <show_in_website>1</show_in_website>
355
  <show_in_store>1</show_in_store>
359
  <label>Default Replies</label>
360
  <frontend_model>werules_chatbot/replies</frontend_model>
361
  <backend_model>chatbot/adminhtml_serialized</backend_model> <!-- TODO adminhtml/system_config_backend_serialized_array -->
362
+ <sort_order>13</sort_order>
363
  <show_in_default>1</show_in_default>
364
  <show_in_website>1</show_in_website>
365
  <show_in_store>0</show_in_store>
366
+ <comment>Replies to be Send to The Customer Whenever Matches One of The Requirements.</comment>
367
  </default_replies>
368
  </fields>
369
  </facebook_config>
app/code/community/Werules/Chatbot/sql/chatbot_setup/{mysql4-install-0.0.5.php → mysql4-install-0.0.9.php} RENAMED
File without changes
app/design/frontend/base/default/layout/werules_chatbot.xml CHANGED
@@ -20,6 +20,9 @@
20
  <remove name="left" />
21
  <remove name="header" />
22
  <remove name="footer" />
 
 
 
23
  <reference name="content">
24
  <block type="core/template" name="chatbot_content" template="werules_chatbot_view.phtml"/>
25
  </reference>
@@ -30,6 +33,9 @@
30
  <remove name="left" />
31
  <remove name="header" />
32
  <remove name="footer" />
 
 
 
33
  <reference name="content">
34
  <block type="core/template" name="chatbot_content" template="werules_chatbot_view.phtml"/>
35
  </reference>
@@ -40,6 +46,9 @@
40
  <remove name="left" />
41
  <remove name="header" />
42
  <remove name="footer" />
 
 
 
43
  <reference name="content">
44
  <block type="core/template" name="chatbot_content" template="werules_chatbot_view.phtml"/>
45
  </reference>
20
  <remove name="left" />
21
  <remove name="header" />
22
  <remove name="footer" />
23
+ <remove name="customer_form_login" />
24
+ <remove name="customer_form_register" />
25
+ <remove name="customer_form_register_ajax" /> <!-- remove ajax register block from https://github.com/digitalpianism/ajaxlogin module -->
26
  <reference name="content">
27
  <block type="core/template" name="chatbot_content" template="werules_chatbot_view.phtml"/>
28
  </reference>
33
  <remove name="left" />
34
  <remove name="header" />
35
  <remove name="footer" />
36
+ <remove name="customer_form_login" />
37
+ <remove name="customer_form_register" />
38
+ <remove name="customer_form_register_ajax" /> <!-- remove ajax register block from https://github.com/digitalpianism/ajaxlogin module -->
39
  <reference name="content">
40
  <block type="core/template" name="chatbot_content" template="werules_chatbot_view.phtml"/>
41
  </reference>
46
  <remove name="left" />
47
  <remove name="header" />
48
  <remove name="footer" />
49
+ <remove name="customer_form_login" />
50
+ <remove name="customer_form_register" />
51
+ <remove name="customer_form_register_ajax" /> <!-- remove ajax register block from https://github.com/digitalpianism/ajaxlogin module -->
52
  <reference name="content">
53
  <block type="core/template" name="chatbot_content" template="werules_chatbot_view.phtml"/>
54
  </reference>
app/design/frontend/base/default/template/werules_chatbot_view.phtml CHANGED
@@ -1,9 +1,32 @@
1
  <?php
2
  $action = $this->getRequest()->getActionName();
3
- $webhook = Mage::app()->getRequest()->getParam('webhook');
4
- $custom_key = Mage::getStoreConfig('chatbot_enable/general_config/your_custom_key');
5
 
6
- if ($webhook != $custom_key)
7
- $webhook = null;
8
- echo Mage::getModel('chatbot/chatdata')->requestHandler($action, $webhook);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  ?>
1
  <?php
2
  $action = $this->getRequest()->getActionName();
 
 
3
 
4
+ if (!empty($action))
5
+ {
6
+ $webhook = Mage::app()->getRequest()->getParam('webhook');
7
+ $key = Mage::app()->getRequest()->getParam('key');
8
+ $customKey = Mage::getStoreConfig('chatbot_enable/general_config/your_custom_key');
9
+
10
+ if ($webhook == $customKey) // set webhook
11
+ echo Mage::getModel('chatbot/chatdata')->requestHandler($action, $webhook);
12
+ else if ($key == $customKey) // process request
13
+ echo Mage::getModel('chatbot/chatdata')->requestHandler($action, null);
14
+ else // error
15
+ {
16
+ $enableLog = Mage::getStoreConfig('chatbot_enable/general_config/enable_post_log');
17
+ if ($enableLog == "1")
18
+ {
19
+ //$visitorData = Mage::getSingleton('core/session')->getVisitorData();
20
+ $remoteAddr = Mage::helper('core/http')->getRemoteAddr(false);
21
+ Mage::log(
22
+ "Error trying to access webhook:\n" .
23
+ //"Visitor Data: \n" . var_export($visitorData, true) . "\n" .
24
+ "IP: " . $remoteAddr . "\n" .
25
+ "API: " . $action . "\n" .
26
+ "Key: " . (!empty($key) ? $key : $webhook) . "\n", null, 'chatbot_error.log');
27
+ }
28
+ }
29
+ }
30
+ else
31
+ echo json_encode(array("status" => "error"));
32
  ?>
app/locale/en_US/Werules_Chatbot.csv ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Order","Order"
2
+ "Price","Price"
3
+ "Total","Total"
4
+ "Zipcode","Zipcode"
5
+ "Reorder","Reorder"
6
+ "Add to cart","Add to cart"
7
+ "Message from support","Message from support"
8
+ "Message sent.","Message sent."
9
+ "I don't work with groups.","I don't work with groups."
10
+ "Something went wrong, please try again.","Something went wrong, please try again."
11
+ "Ok","Ok"
12
+ "Okay","Okay"
13
+ "Cool","Cool"
14
+ "Awesome","Awesome"
15
+ "Added. To checkout send","Added. To checkout send"
16
+ "Sorry, no products found in this category.","Sorry, no products found in this category."
17
+ "Sorry, no products found for this criteria.","Sorry, no products found for this criteria."
18
+ "we have sent your message to support.","we have sent your message to support."
19
+ "Select a category","Select a category"
20
+ "Products on cart","Products on cart"
21
+ "Checkout Here","Checkout Here"
22
+ "Your cart is empty.","Your cart is empty."
23
+ "Cart cleared.","Cart cleared."
24
+ "what do you want to search for?","what do you want to search for?"
25
+ "To login to your account, click this link","To login to your account, click this link"
26
+ "To login to your account, access the link below","To login to your account, access the link below"
27
+ "let me fetch that for you.","let me fetch that for you."
28
+ "Please login first.","Please login first."
29
+ "to checkout send","to checkout send"
30
+ "what do you need support for?","what do you need support for?"
31
+ "exiting support mode.","exiting support mode."
32
+ "Done.","Done."
33
+ "Sorry, I didn't understand that.","Sorry, I didn't understand that."
34
+ "Ok, canceled.","Ok, canceled."
35
+ "Your account is now attached with our chatbot.","Your account is now attached with our chatbot."
36
+ "Chatbot settings saved successfully.","Chatbot settings saved successfully."
37
+ "List store categories.","List store categories."
38
+ "Search for products.","Search for products."
39
+ "Login into your account.","Login into your account."
40
+ "Logout from your account.","Logout from your account."
41
+ "List your personal orders.","List your personal orders."
42
+ "Reorder a order.","Reorder a order."
43
+ "Add product to cart.","Add product to cart."
44
+ "Checkout your order.","Checkout your order."
45
+ "Clear your cart.","Clear your cart."
46
+ "Track your order status.","Track your order status."
47
+ "Send message to support.","Send message to support."
48
+ "Send email.","Send email."
49
+ "Cancel.","Cancel."
50
+ "Get help.","Get help."
51
+ "About.","About."
52
+ "Webhook for Telegram configured.","Webhook for Telegram configured."
53
+ "Command list","Command list"
54
+ "This account has no orders.","This account has no orders."
55
+ "write the email content.","write the email content."
56
+ "By doing this you agree that we may contact you directly via chat message.","By doing this you agree that we may contact you directly via chat message."
57
+ "Trying to send the email...","Trying to send the email..."
58
+ "Contact from chatbot","Contact from chatbot"
59
+ "Sorry, I wasn't able to send an email this time. Please try again later.","Sorry, I wasn't able to send an email this time. Please try again later."
60
+ "Not informed","Not informed"
61
+ "Message from chatbot customer","Message from chatbot customer"
62
+ "Customer name","Customer name"
63
+ "Message","Message"
64
+ "Contacts","Contacts"
65
+ "To cancel, send","To cancel, send"
66
+ "Chatbot","Chatbot"
67
+ "Email","Email"
68
+ "send the order number.","send the order number."
69
+ "Sorry, we couldn't find any order with this information.","Sorry, we couldn't find any order with this information."
70
+ "Your account dosen't have any orders.","Your account dosen't have any orders."
71
+ "To talk with me, please enable Telegram on your account chatbot settings.","To talk with me, please enable Telegram on your account chatbot settings."
72
+ "Start a bot conversation on Telegram","Start a bot conversation on Telegram"
73
+ "Start a bot conversation on Facebook Messenger","Start a bot conversation on Facebook Messenger"
74
+ "Here","Here"
75
+ "Enable Telegram?","Enable Telegram?"
76
+ "Enable Facebook?","Enable Facebook?"
77
+ "Enable Whatsapp?","Enable Whatsapp?"
78
+ "Enable Wechat?","Enable Wechat?"
79
+ "To talk with me, please enable Facebook Messenger on your account chatbot settings.","To talk with me, please enable Facebook Messenger on your account chatbot settings."
80
+ "Visit product's page","Visit product's page"
81
+ "Processing...","Processing..."
82
+ "Please wait while I check that for you.","Please wait while I check that for you."
83
+ "Login","Login"
84
+ "To login to your account, click the link below","To login to your account, click the link below"
85
+ "You're already logged.","You're already logged."
86
+ "You're not logged.","You're not logged."
87
+ "Message via","Message via"
88
+ "From","From"
89
+ "You're already on support in other chat application, please close it before opening a new one.","You're already on support in other chat application, please close it before opening a new one."
90
+ "Show more","Show more"
91
+ "Show more orders","Show more orders"
92
+ "To show more, send","To show more, send"
93
+ "No categories available at the moment, please try again later.","No categories available at the moment, please try again later."
94
+ "Done. This category has %s products.","Done. This category has %s products."
95
+ "Done. This category has only one product.","Done. This category has only one product."
96
+ "Done. I've found %s products for your criteria.","Done. I've found %s products for your criteria."
97
+ "Done. I've found only one product for your criteria.","Done. I've found only one product for your criteria."
98
+ "Done. You've only one order.","Done. You've only one order."
99
+ "Done. I've found %s orders.","Done. I've found %s orders."
100
+ "Please wait while our support check your message so you can talk to a real person.","Please wait while our support check your message so you can talk to a real person."
101
+ "Please use","Please use"
102
+ "your message here.","your message here."
103
+ "We're working on this feature.","We're working on this feature."
104
+ "Done. The customer is no longer on support.","Done. The customer is no longer on support."
105
+ "Support ended.","Support ended."
106
+ "You're now on support mode.","You're now on support mode."
107
+ "Ok, send me the message and I'll forward it to the customer.","Ok, send me the message and I'll forward it to the customer."
108
+ "Done. The customer is no longer able to enter support.","Done. The customer is no longer able to enter support."
109
+ "Done. The customer is now able to enter support.","Done. The customer is now able to enter support."
110
+ "I'm sorry, you can't ask for support now. Please try again later.","I'm sorry, you can't ask for support now. Please try again later."
111
+ "Block support","Block support"
112
+ "Enable support","Enable support"
113
+ "End support","End support"
114
+ "Reply this message","Reply this message"
115
+ "ID","ID"
116
+ "Enable/Disable support","Enable/Disable support"
117
+ "Ok, logging out.","Ok, logging out."
118
+ "please wait while I prepare the checkout for you.","please wait while I prepare the checkout for you."
119
+ "please wait while I gather your orders for listing.","please wait while I gather your orders for listing."
120
+ "please wait while I add the products from this order to your cart.","please wait while I add the products from this order to your cart."
121
+ "adding %s to your cart.","adding %s to your cart."
122
+ "please wait while I gather all categories for you.","please wait while I gather all categories for you."
123
+ "please wait while I search for '%s' for you.","please wait while I search for '%s' for you."
124
+ "please wait while I check the status for order %s.","please wait while I check the status for order %s."
125
+ "this product","this product"
126
+ "listing more.","listing more."
127
+ "please wait while I gather all products from %s for you.","please wait while I gather all products from %s for you."
128
+ "Phrase","Phrase"
129
+ "Reply","Reply"
130
+ "Similarity (%)","Similarity (%)"
131
+ "Add","Add"
132
+ "Command","Command"
133
+ "Command Code","Command Code"
134
+ "Alias","Alias"
135
+ "Match Case","Match Case"
136
+ "And that was the last one.","And that was the last one."
137
+ "please wait while I clear your cart.","please wait while I clear your cart."
138
+ "Webhook URL","Webhook URL"
139
+ "Click %s to check that information on Telegram website. If a wrong URL is set, try reloading this page or click %s.","Click %s to check that information on Telegram website. If a wrong URL is set, try reloading this page or click %s."
140
+ "here","here"
141
+ "To configure Facebook webhook access","To configure Facebook webhook access"
142
+ "and set the webhook URL as","and set the webhook URL as"
143
+ "Create a new account.","Create a new account."
144
+ "Access %s to register a new account on our shop.","Access %s to register a new account on our shop."
145
+ "This product is not in stock.","This product is not in stock."
146
+ "If you want to logout from your account, just send","If you want to logout from your account, just send"
147
+ "Please try one of the following commands.","Please try one of the following commands."
app/locale/pt_BR/Werules_Chatbot.csv CHANGED
@@ -23,6 +23,7 @@
23
  "Cart cleared.","Carrinho esvaziado"
24
  "what do you want to search for?","digite o que você quer procurar."
25
  "To login to your account, click this link","Para acessar sua conta, clique nesse link"
 
26
  "let me fetch that for you.","deixa eu buscar essa informação para você."
27
  "Please login first.","Por favor, faça o login primeiro."
28
  "to checkout send","para finalizar o pedido envie"
@@ -48,7 +49,7 @@
48
  "Cancel.","Cancelar."
49
  "Get help.","Ajuda."
50
  "About.","Sobre."
51
- "Webhook for Telegram configured..","Webhook para o Telegram configurado com sucesso."
52
  "Command list","Lista de comandos"
53
  "This account has no orders.","Nenhum pedido nessa conta."
54
  "write the email content.","escreva o conteudo do e-mail."
@@ -123,7 +124,7 @@
123
  "please wait while I check the status for order %s.","por favor aguarde enquanto verifico o status do pedido %s."
124
  "this product","esse produto"
125
  "listing more.","listando mais."
126
- "please wait while I gather all products from %s for you.","por favor aguarde euqnaot busco todos os produtos da categoria %s para você."
127
  "Phrase","Frase"
128
  "Reply","Resposta"
129
  "Similarity (%)","Similaridade (%)"
@@ -133,3 +134,14 @@
133
  "Alias","Aliás"
134
  "Match Case","Diferenciar Maiúsculas de Minúsculas"
135
  "And that was the last one.","E esse foi o último."
 
 
 
 
 
 
 
 
 
 
 
23
  "Cart cleared.","Carrinho esvaziado"
24
  "what do you want to search for?","digite o que você quer procurar."
25
  "To login to your account, click this link","Para acessar sua conta, clique nesse link"
26
+ "To login to your account, access the link below","Para acessar sua conta, clique no link abaixo"
27
  "let me fetch that for you.","deixa eu buscar essa informação para você."
28
  "Please login first.","Por favor, faça o login primeiro."
29
  "to checkout send","para finalizar o pedido envie"
49
  "Cancel.","Cancelar."
50
  "Get help.","Ajuda."
51
  "About.","Sobre."
52
+ "Webhook for Telegram configured.","Webhook para o Telegram configurado com sucesso."
53
  "Command list","Lista de comandos"
54
  "This account has no orders.","Nenhum pedido nessa conta."
55
  "write the email content.","escreva o conteudo do e-mail."
124
  "please wait while I check the status for order %s.","por favor aguarde enquanto verifico o status do pedido %s."
125
  "this product","esse produto"
126
  "listing more.","listando mais."
127
+ "please wait while I gather all products from %s for you.","por favor aguarde enquanto busco todos os produtos da categoria %s para você."
128
  "Phrase","Frase"
129
  "Reply","Resposta"
130
  "Similarity (%)","Similaridade (%)"
134
  "Alias","Aliás"
135
  "Match Case","Diferenciar Maiúsculas de Minúsculas"
136
  "And that was the last one.","E esse foi o último."
137
+ "please wait while I clear your cart.","por favor aguarde enquanto limpo o seu carrinho."
138
+ "Webhook URL","URL do Webhook"
139
+ "Click %s to check that information on Telegram website. If a wrong URL is set, try reloading this page or click %s.","Clique %s para verificar essa informação no site do Telegram. Se a URL estiver errada, tente recarregar essa página ou clique %s."
140
+ "here","aqui"
141
+ "To configure Facebook webhook access","Para configurar o webhook do Facebook acesse"
142
+ "and set the webhook URL as","e coloque a URL"
143
+ "Create a new account.","Criar uma nova conta."
144
+ "Access %s to register a new account on our shop.","Acesse %s para criar uma nova conta em nossa loja."
145
+ "This product is not in stock.","Não temos estoque para esse produto."
146
+ "If you want to logout from your account, just send","Se você quiser sair da sua conta, envie"
147
+ "Please try one of the following commands.","Por gentileza tente um dos comandos abaixo."
app/locale/zh_CN/Werules_Chatbot.csv ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Order","订单"
2
+ "Price","价格"
3
+ "Total","总数"
4
+ "Zipcode","区码"
5
+ "Reorder","再订购"
6
+ "Add to cart","加入购物车"
7
+ "Message from support","支援信息"
8
+ "Message sent.","已发出信息。"
9
+ "I don't work with groups.","我并不在群组中工作。"
10
+ "Something went wrong, please try again.","有些问题出现了,请再试一次。"
11
+ "Ok","Ok"
12
+ "Okay","Okay"
13
+ "Cool","酷"
14
+ "Awesome","正"
15
+ "Added. To checkout send","已加进了。结账请送出"
16
+ "Sorry, no products found in this category.","对不起,此类别暂时没有产品。"
17
+ "Sorry, no products found for this criteria.","对不起,按此要求暂时找不到产品。"
18
+ "we have sent your message to support.","我们已把你的信息转送给了支援团队。"
19
+ "Select a category","选择类别"
20
+ "Products on cart","购物车中的产品"
21
+ "Checkout Here","从此处结账"
22
+ "Your cart is empty.","你的购物车是空的。"
23
+ "Cart cleared.","已清空了购物车。"
24
+ "what do you want to search for?","请问你想找什麽呢?"
25
+ "To login to your account, click this link","按此连结登入阁下之账户"
26
+ "let me fetch that for you.","等我帮你找找。"
27
+ "Please login first.","请先登入。"
28
+ "to checkout send","结账请送出"
29
+ "what do you need support for?","你需要什麽协助呢?"
30
+ "exiting support mode.","正在离开支援模式。"
31
+ "Done.","已完成。"
32
+ "Sorry, I didn't understand that.","对不起,我不太明白。"
33
+ "Ok, canceled.","好的,已取消了。"
34
+ "Your account is now attached with our chatbot.","你的账户已跟聊天机器人接好了。"
35
+ "Chatbot settings saved successfully.","成功储存聊天机器人设定。"
36
+ "List store categories.","列出类别清单。"
37
+ "Search for products.","搜寻产品。"
38
+ "Login into your account.","登入你的账户。"
39
+ "Logout from your account.","登出你的账户。"
40
+ "List your personal orders.","列出你的个人订单。"
41
+ "Reorder a order.","再订购。"
42
+ "Add product to cart.","把产品加进购物车。"
43
+ "Checkout your order.","结账"
44
+ "Clear your cart.","清空你的购物车。"
45
+ "Track your order status.","追踪你的订单状态。"
46
+ "Send message to support.","发送信息给支援团队。"
47
+ "Send email.","发送电邮。"
48
+ "Cancel.","取消。"
49
+ "Get help.","寻求协助。"
50
+ "About.","关於。"
51
+ "Webhook for Telegram configured.","已设定好 Telegram 的 Webhook。"
52
+ "Command list","指令清单"
53
+ "This account has no orders.","此账户没有订单。"
54
+ "write the email content.","撰写电邮内容。"
55
+ "By doing this you agree that we may contact you directly via chat message."阁下同意接受我们直接跟你用聊天信息联络。"
56
+ "Trying to send the email...","正尝试发送电邮..."
57
+ "Contact from chatbot","聊天机器人的联络"
58
+ "Sorry, I wasn't able to send an email this time. Please try again later.","对不起,这次我未能发出电邮。请稍候再试。"
59
+ "Not informed","未有告知"
60
+ "Message from chatbot customer","来自聊天机器人客户的信息"
61
+ "Customer name","客户名称"
62
+ "Message","信息"
63
+ "Contacts","联络人"
64
+ "To cancel, send","要取消的话,请发出"
65
+ "Chatbot","聊天机器人"
66
+ "Email","电邮"
67
+ "send the order number.","发出订单编号。"
68
+ "Sorry, we couldn't find any order with this information.","对不起,我们未能就这资料找到任何订单。"
69
+ "Your account dosen't have any orders.","你的账户没有任何订单。"
70
+ "To talk with me, please enable Telegram on your account chatbot settings.","再跟我对话,请先开启 Telegram 内的 chatbot 设定。"
71
+ "Start a bot conversation on Telegram","在 Telegram 上开始机器人对话"
72
+ "Start a bot conversation on Facebook Messenger","在 Facebook Messenger 上开始机器人对话"
73
+ "Here","此处"
74
+ "Enable Telegram?","启用 Telegram?"
75
+ "Enable Facebook?","启用 Facebook?"
76
+ "Enable Whatsapp?","启用 WhatsApp?"
77
+ "Enable Wechat?","启用 WeChat?"
78
+ "To talk with me, please enable Facebook Messenger on your account chatbot settings.","再跟我对话,请先开启 Facebook Messenger 内的 chatbot 设定。"
79
+ "Visit product's page","浏览产品专页"
80
+ "Processing...","处理中..."
81
+ "Please wait while I check that for you.","请等等,我正常处理中。"
82
+ "Login","登入"
83
+ "To login to your account, click the link below","按此连结登入阁下之账户""
84
+ "You're already logged.","你已经登入。"
85
+ "You're not logged.","你还未登入。"
86
+ "Message via","信息来自"
87
+ "From","由"
88
+ "You're already on support in other chat application, please close it before opening a new one.","你已於另一个聊天软件内得到支援,请先关闭再开新档。"
89
+ "Show more","显示更多"
90
+ "Show more orders","显示更多订单"
91
+ "To show more, send","要显示更多,请发出"
92
+ "No categories available at the moment, please try again later.","现在没有任何类别,请稍候再试。"
93
+ "Done. This category has %s products.","已完成。此类别有 %s 件产品。"
94
+ "Done. This category has only one product.","已完成。此类别只有 1 件产品。"
95
+ "Done. I've found %s products for your criteria.","已完成。我按你的要求找到了 %s 件产品。"
96
+ "Done. I've found only one product for your criteria.","已完成。我按你的要求只找到了 1 件产品。"
97
+ "Done. You've only one order.","已完成。你只有一则订单。"
98
+ "Done. I've found %s orders.","已完成。我找到了 %s 则订单。"
99
+ "Please wait while our support check your message so you can talk to a real person.","请等候我们的支援团队查阅阁下的信息再安排跟真人对话。"
100
+ "Please use","请使用"
101
+ "your message here.","你在此的信息。"
102
+ "We're working on this feature.","我们正常落力完成这功能。"
103
+ "Done. The customer is no longer on support.","已完成。这客户已不再接受支援。"
104
+ "Support ended.","支援结束。"
105
+ "You're now on support mode.","已开启支援模式。"
106
+ "Ok, send me the message and I'll forward it to the customer.","好的,请发信息给我,我会再转发给客户。"
107
+ "Done. The customer is no longer able to enter support.","已完成。此客户无法再进入支援。"
108
+ "Done. The customer is now able to enter support.","已完成。此客户现在能够进入支援。"
109
+ "I'm sorry, you can't ask for support now. Please try again later.","对不起,你暂时无法得到支援。请稍候再试。"
110
+ "Block support","阻止支援"
111
+ "Enable support","启用支援"
112
+ "End support","结束支援"
113
+ "Reply this message","回覆信息"
114
+ "ID","ID"
115
+ "Enable/Disable support","启用/关闭支援"
116
+ "Ok, logging out.","好的,正在登出。"
117
+ "please wait while I prepare the checkout for you.","请等候我准备给你结账。"
118
+ "please wait while I gather your orders for listing.","请等候我列出你的订单。"
119
+ "please wait while I add the products from this order to your cart.","请等候我把这订单中的产品加进你的购物车。"
120
+ "adding %s to your cart.","正在添加 %s 进你的购物车。"
121
+ "please wait while I gather all categories for you.","请等候我给你显示所有类别。"
122
+ "please wait while I search for '%s' for you.","请等候我给你搜寻 %s"
123
+ "please wait while I check the status for order %s.","请等候我给你查询订单 %s 的状态。"
124
+ "this product","此产品"
125
+ "listing more.","列出更多。"
126
+ "please wait while I gather all products from %s for you.","请等候我给你从 %s 显示所有产品。"
127
+ "Phrase","词组"
128
+ "Reply","回覆"
129
+ "Similarity (%)","相似程度 (%)"
130
+ "Add","添加"
131
+ "Command","指令"
132
+ "Command Code","指令代码"
133
+ "Alias","别名"
134
+ "Match Case","符合大小写"
135
+ "And that was the last one.","这是最後一个。"
136
+ "please wait while I clear your cart.","请等候我清空你的购物车。"
137
+ "Webhook URL","Webhook URL 位址"
138
+ "Click %s to check that information on Telegram website. If a wrong URL is set, try reloading this page or click %s.","点选 %s 从 Telegram 网站查看资讯。如果连结错误,请尝试刷新这页或点按 %s。"
139
+ "here","此处"
140
+ "To configure Facebook webhook access","要设定接上 Facebook webhook"
141
+ "and set the webhook URL as","及设定 webhook URL 位址为"
142
+ "Create a new account.","建立新账户。"
143
+ "Access %s to register a new account on our shop.","经由 %s 在我们的商店登记新账户。"
144
+ "This product is not in stock.","此产品还未在存货。"
app/locale/zh_HK/Werules_Chatbot.csv ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Order","訂單"
2
+ "Price","價格"
3
+ "Total","總數"
4
+ "Zipcode","區碼"
5
+ "Reorder","再訂購"
6
+ "Add to cart","加入購物車"
7
+ "Message from support","支援信息"
8
+ "Message sent.","已發出信息。"
9
+ "I don't work with groups.","我並不在群組中工作。"
10
+ "Something went wrong, please try again.","有些問題出現了,請再試一次。"
11
+ "Ok","Ok"
12
+ "Okay","Okay"
13
+ "Cool","酷"
14
+ "Awesome","正"
15
+ "Added. To checkout send","已加進了。結賬請送出"
16
+ "Sorry, no products found in this category.","對不起,此類別暫時沒有產品。"
17
+ "Sorry, no products found for this criteria.","對不起,按此要求暫時找不到產品。"
18
+ "we have sent your message to support.","我們已把你的信息轉送給了支援團隊。"
19
+ "Select a category","選擇類別"
20
+ "Products on cart","購物車中的產品"
21
+ "Checkout Here","從此處結賬"
22
+ "Your cart is empty.","你的購物車是空的。"
23
+ "Cart cleared.","已清空了購物車。"
24
+ "what do you want to search for?","請問你想找什麼呢?"
25
+ "To login to your account, click this link","按此連結登入閣下之賬戶"
26
+ "let me fetch that for you.","等我幫你找找。"
27
+ "Please login first.","請先登入。"
28
+ "to checkout send","結賬請送出"
29
+ "what do you need support for?","你需要什麼協助呢?"
30
+ "exiting support mode.","正在離開支援模式。"
31
+ "Done.","已完成。"
32
+ "Sorry, I didn't understand that.","對不起,我不太明白。"
33
+ "Ok, canceled.","好的,已取消了。"
34
+ "Your account is now attached with our chatbot.","你的賬戶已跟聊天機器人接好了。"
35
+ "Chatbot settings saved successfully.","成功儲存聊天機器人設定。"
36
+ "List store categories.","列出類別清單。"
37
+ "Search for products.","搜尋產品。"
38
+ "Login into your account.","登入你的賬戶。"
39
+ "Logout from your account.","登出你的賬戶。"
40
+ "List your personal orders.","列出你的個人訂單。"
41
+ "Reorder a order.","再訂購。"
42
+ "Add product to cart.","把產品加進購物車。"
43
+ "Checkout your order.","結賬"
44
+ "Clear your cart.","清空你的購物車。"
45
+ "Track your order status.","追蹤你的訂單狀態。"
46
+ "Send message to support.","發送信息給支援團隊。"
47
+ "Send email.","發送電郵。"
48
+ "Cancel.","取消。"
49
+ "Get help.","尋求協助。"
50
+ "About.","關於。"
51
+ "Webhook for Telegram configured.","已設定好 Telegram 的 Webhook。"
52
+ "Command list","指令清單"
53
+ "This account has no orders.","此賬戶沒有訂單。"
54
+ "write the email content.","撰寫電郵內容。"
55
+ "By doing this you agree that we may contact you directly via chat message."閣下同意接受我們直接跟你用聊天信息聯絡。"
56
+ "Trying to send the email...","正嘗試發送電郵..."
57
+ "Contact from chatbot","聊天機器人的聯絡"
58
+ "Sorry, I wasn't able to send an email this time. Please try again later.","對不起,這次我未能發出電郵。請稍候再試。"
59
+ "Not informed","未有告知"
60
+ "Message from chatbot customer","來自聊天機器人客戶的信息"
61
+ "Customer name","客戶名稱"
62
+ "Message","信息"
63
+ "Contacts","聯絡人"
64
+ "To cancel, send","要取消的話,請發出"
65
+ "Chatbot","聊天機器人"
66
+ "Email","電郵"
67
+ "send the order number.","發出訂單編號。"
68
+ "Sorry, we couldn't find any order with this information.","對不起,我們未能就這資料找到任何訂單。"
69
+ "Your account dosen't have any orders.","你的賬戶沒有任何訂單。"
70
+ "To talk with me, please enable Telegram on your account chatbot settings.","再跟我對話,請先開啟 Telegram 內的 chatbot 設定。"
71
+ "Start a bot conversation on Telegram","在 Telegram 上開始機器人對話"
72
+ "Start a bot conversation on Facebook Messenger","在 Facebook Messenger 上開始機器人對話"
73
+ "Here","此處"
74
+ "Enable Telegram?","啟用 Telegram?"
75
+ "Enable Facebook?","啟用 Facebook?"
76
+ "Enable Whatsapp?","啟用 WhatsApp?"
77
+ "Enable Wechat?","啟用 WeChat?"
78
+ "To talk with me, please enable Facebook Messenger on your account chatbot settings.","再跟我對話,請先開啟 Facebook Messenger 內的 chatbot 設定。"
79
+ "Visit product's page","瀏覽產品專頁"
80
+ "Processing...","處理中..."
81
+ "Please wait while I check that for you.","請等等,我正常處理中。"
82
+ "Login","登入"
83
+ "To login to your account, click the link below","按此連結登入閣下之賬戶""
84
+ "You're already logged.","你已經登入。"
85
+ "You're not logged.","你還未登入。"
86
+ "Message via","信息來自"
87
+ "From","由"
88
+ "You're already on support in other chat application, please close it before opening a new one.","你已於另一個聊天軟件內得到支援,請先關閉再開新檔。"
89
+ "Show more","顯示更多"
90
+ "Show more orders","顯示更多訂單"
91
+ "To show more, send","要顯示更多,請發出"
92
+ "No categories available at the moment, please try again later.","現在沒有任何類別,請稍候再試。"
93
+ "Done. This category has %s products.","已完成。此類別有 %s 件產品。"
94
+ "Done. This category has only one product.","已完成。此類別只有 1 件產品。"
95
+ "Done. I've found %s products for your criteria.","已完成。我按你的要求找到了 %s 件產品。"
96
+ "Done. I've found only one product for your criteria.","已完成。我按你的要求只找到了 1 件產品。"
97
+ "Done. You've only one order.","已完成。你只有一則訂單。"
98
+ "Done. I've found %s orders.","已完成。我找到了 %s 則訂單。"
99
+ "Please wait while our support check your message so you can talk to a real person.","請等候我們的支援團隊查閱閣下的信息再安排跟真人對話。"
100
+ "Please use","請使用"
101
+ "your message here.","你在此的信息。"
102
+ "We're working on this feature.","我們正常落力完成這功能。"
103
+ "Done. The customer is no longer on support.","已完成。這客戶已不再接受支援。"
104
+ "Support ended.","支援結束。"
105
+ "You're now on support mode.","已開啟支援模式。"
106
+ "Ok, send me the message and I'll forward it to the customer.","好的,請發信息給我,我會再轉發給客戶。"
107
+ "Done. The customer is no longer able to enter support.","已完成。此客戶無法再進入支援。"
108
+ "Done. The customer is now able to enter support.","已完成。此客戶現在能夠進入支援。"
109
+ "I'm sorry, you can't ask for support now. Please try again later.","對不起,你暫時無法得到支援。請稍候再試。"
110
+ "Block support","阻止支援"
111
+ "Enable support","啟用支援"
112
+ "End support","結束支援"
113
+ "Reply this message","回覆信息"
114
+ "ID","ID"
115
+ "Enable/Disable support","啟用/關閉支援"
116
+ "Ok, logging out.","好的,正在登出。"
117
+ "please wait while I prepare the checkout for you.","請等候我準備給你結賬。"
118
+ "please wait while I gather your orders for listing.","請等候我列出你的訂單。"
119
+ "please wait while I add the products from this order to your cart.","請等候我把這訂單中的產品加進你的購物車。"
120
+ "adding %s to your cart.","正在添加 %s 進你的購物車。"
121
+ "please wait while I gather all categories for you.","請等候我給你顯示所有類別。"
122
+ "please wait while I search for '%s' for you.","請等候我給你搜尋 %s"
123
+ "please wait while I check the status for order %s.","請等候我給你查詢訂單 %s 的狀態。"
124
+ "this product","此產品"
125
+ "listing more.","列出更多。"
126
+ "please wait while I gather all products from %s for you.","請等候我給你從 %s 顯示所有產品。"
127
+ "Phrase","詞組"
128
+ "Reply","回覆"
129
+ "Similarity (%)","相似程度 (%)"
130
+ "Add","添加"
131
+ "Command","指令"
132
+ "Command Code","指令代碼"
133
+ "Alias","別名"
134
+ "Match Case","符合大小寫"
135
+ "And that was the last one.","這是最後一個。"
136
+ "please wait while I clear your cart.","請等候我清空你的購物車。"
137
+ "Webhook URL","Webhook URL 位址"
138
+ "Click %s to check that information on Telegram website. If a wrong URL is set, try reloading this page or click %s.","點選 %s 從 Telegram 網站查看資訊。如果連結錯誤,請嘗試刷新這頁或點按 %s。"
139
+ "here","此處"
140
+ "To configure Facebook webhook access","要設定接上 Facebook webhook"
141
+ "and set the webhook URL as","及設定 webhook URL 位址為"
142
+ "Create a new account.","建立新賬戶。"
143
+ "Access %s to register a new account on our shop.","經由 %s 在我們的商店登記新賬戶。"
144
+ "This product is not in stock.","此產品還未在存貨。"
app/locale/zh_TW/Werules_Chatbot.csv ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Order","訂單"
2
+ "Price","價格"
3
+ "Total","總數"
4
+ "Zipcode","區碼"
5
+ "Reorder","再訂購"
6
+ "Add to cart","加入購物車"
7
+ "Message from support","支援信息"
8
+ "Message sent.","已發出信息。"
9
+ "I don't work with groups.","我並不在群組中工作。"
10
+ "Something went wrong, please try again.","有些問題出現了,請再試一次。"
11
+ "Ok","Ok"
12
+ "Okay","Okay"
13
+ "Cool","酷"
14
+ "Awesome","正"
15
+ "Added. To checkout send","已加進了。結帳請送出"
16
+ "Sorry, no products found in this category.","對不起,此類別暫時沒有產品。"
17
+ "Sorry, no products found for this criteria.","對不起,按此要求暫時找不到產品。"
18
+ "we have sent your message to support.","我們已把你的信息轉送給了支援團隊。"
19
+ "Select a category","選擇類別"
20
+ "Products on cart","購物車中的產品"
21
+ "Checkout Here","從此處結帳"
22
+ "Your cart is empty.","你的購物車是空的。"
23
+ "Cart cleared.","已清空了購物車。"
24
+ "what do you want to search for?","請問你想找什麼呢?"
25
+ "To login to your account, click this link","按此連結登入閣下之帳戶"
26
+ "let me fetch that for you.","等我幫你找找。"
27
+ "Please login first.","請先登入。"
28
+ "to checkout send","結帳請送出"
29
+ "what do you need support for?","你需要什麼協助呢?"
30
+ "exiting support mode.","正在離開支援模式。"
31
+ "Done.","已完成。"
32
+ "Sorry, I didn't understand that.","對不起,我不太明白。"
33
+ "Ok, canceled.","好的,已取消了。"
34
+ "Your account is now attached with our chatbot.","你的帳戶已跟聊天機器人接好了。"
35
+ "Chatbot settings saved successfully.","成功儲存聊天機器人設定。"
36
+ "List store categories.","列出類別清單。"
37
+ "Search for products.","搜尋產品。"
38
+ "Login into your account.","登入你的帳戶。"
39
+ "Logout from your account.","登出你的帳戶。"
40
+ "List your personal orders.","列出你的個人訂單。"
41
+ "Reorder a order.","再訂購。"
42
+ "Add product to cart.","把產品加進購物車。"
43
+ "Checkout your order.","結帳"
44
+ "Clear your cart.","清空你的購物車。"
45
+ "Track your order status.","追蹤你的訂單狀態。"
46
+ "Send message to support.","發送信息給支援團隊。"
47
+ "Send email.","發送電郵。"
48
+ "Cancel.","取消。"
49
+ "Get help.","尋求協助。"
50
+ "About.","關於。"
51
+ "Webhook for Telegram configured.","已設定好 Telegram 的 Webhook。"
52
+ "Command list","指令清單"
53
+ "This account has no orders.","此帳戶沒有訂單。"
54
+ "write the email content.","撰寫電郵內容。"
55
+ "By doing this you agree that we may contact you directly via chat message."閣下同意接受我們直接跟你用聊天信息聯絡。"
56
+ "Trying to send the email...","正嘗試發送電郵..."
57
+ "Contact from chatbot","聊天機器人的聯絡"
58
+ "Sorry, I wasn't able to send an email this time. Please try again later.","對不起,這次我未能發出電郵。請稍候再試。"
59
+ "Not informed","未有告知"
60
+ "Message from chatbot customer","來自聊天機器人客戶的信息"
61
+ "Customer name","客戶名稱"
62
+ "Message","信息"
63
+ "Contacts","聯絡人"
64
+ "To cancel, send","要取消的話,請發出"
65
+ "Chatbot","聊天機器人"
66
+ "Email","電郵"
67
+ "send the order number.","發出訂單編號。"
68
+ "Sorry, we couldn't find any order with this information.","對不起,我們未能就這資料找到任何訂單。"
69
+ "Your account dosen't have any orders.","你的帳戶沒有任何訂單。"
70
+ "To talk with me, please enable Telegram on your account chatbot settings.","再跟我對話,請先開啟 Telegram 內的 chatbot 設定。"
71
+ "Start a bot conversation on Telegram","在 Telegram 上開始機器人對話"
72
+ "Start a bot conversation on Facebook Messenger","在 Facebook Messenger 上開始機器人對話"
73
+ "Here","此處"
74
+ "Enable Telegram?","啟用 Telegram?"
75
+ "Enable Facebook?","啟用 Facebook?"
76
+ "Enable Whatsapp?","啟用 WhatsApp?"
77
+ "Enable Wechat?","啟用 WeChat?"
78
+ "To talk with me, please enable Facebook Messenger on your account chatbot settings.","再跟我對話,請先開啟 Facebook Messenger 內的 chatbot 設定。"
79
+ "Visit product's page","瀏覽產品專頁"
80
+ "Processing...","處理中..."
81
+ "Please wait while I check that for you.","請等等,我正常處理中。"
82
+ "Login","登入"
83
+ "To login to your account, click the link below","按此連結登入閣下之帳戶""
84
+ "You're already logged.","你已經登入。"
85
+ "You're not logged.","你還未登入。"
86
+ "Message via","信息來自"
87
+ "From","由"
88
+ "You're already on support in other chat application, please close it before opening a new one.","你已於另一個聊天軟件內得到支援,請先關閉再開新檔。"
89
+ "Show more","顯示更多"
90
+ "Show more orders","顯示更多訂單"
91
+ "To show more, send","要顯示更多,請發出"
92
+ "No categories available at the moment, please try again later.","現在沒有任何類別,請稍候再試。"
93
+ "Done. This category has %s products.","已完成。此類別有 %s 件產品。"
94
+ "Done. This category has only one product.","已完成。此類別只有 1 件產品。"
95
+ "Done. I've found %s products for your criteria.","已完成。我按你的要求找到了 %s 件產品。"
96
+ "Done. I've found only one product for your criteria.","已完成。我按你的要求只找到了 1 件產品。"
97
+ "Done. You've only one order.","已完成。你只有一則訂單。"
98
+ "Done. I've found %s orders.","已完成。我找到了 %s 則訂單。"
99
+ "Please wait while our support check your message so you can talk to a real person.","請等候我們的支援團隊查閱閣下的信息再安排跟真人對話。"
100
+ "Please use","請使用"
101
+ "your message here.","你在此的信息。"
102
+ "We're working on this feature.","我們正常落力完成這功能。"
103
+ "Done. The customer is no longer on support.","已完成。這客戶已不再接受支援。"
104
+ "Support ended.","支援結束。"
105
+ "You're now on support mode.","已開啟支援模式。"
106
+ "Ok, send me the message and I'll forward it to the customer.","好的,請發信息給我,我會再轉發給客戶。"
107
+ "Done. The customer is no longer able to enter support.","已完成。此客戶無法再進入支援。"
108
+ "Done. The customer is now able to enter support.","已完成。此客戶現在能夠進入支援。"
109
+ "I'm sorry, you can't ask for support now. Please try again later.","對不起,你暫時無法得到支援。請稍候再試。"
110
+ "Block support","阻止支援"
111
+ "Enable support","啟用支援"
112
+ "End support","結束支援"
113
+ "Reply this message","回覆信息"
114
+ "ID","ID"
115
+ "Enable/Disable support","啟用/關閉支援"
116
+ "Ok, logging out.","好的,正在登出。"
117
+ "please wait while I prepare the checkout for you.","請等候我準備給你結帳。"
118
+ "please wait while I gather your orders for listing.","請等候我列出你的訂單。"
119
+ "please wait while I add the products from this order to your cart.","請等候我把這訂單中的產品加進你的購物車。"
120
+ "adding %s to your cart.","正在添加 %s 進你的購物車。"
121
+ "please wait while I gather all categories for you.","請等候我給你顯示所有類別。"
122
+ "please wait while I search for '%s' for you.","請等候我給你搜尋 %s"
123
+ "please wait while I check the status for order %s.","請等候我給你查詢訂單 %s 的狀態。"
124
+ "this product","此產品"
125
+ "listing more.","列出更多。"
126
+ "please wait while I gather all products from %s for you.","請等候我給你從 %s 顯示所有產品。"
127
+ "Phrase","詞組"
128
+ "Reply","回覆"
129
+ "Similarity (%)","相似程度 (%)"
130
+ "Add","添加"
131
+ "Command","指令"
132
+ "Command Code","指令代碼"
133
+ "Alias","別名"
134
+ "Match Case","符合大小寫"
135
+ "And that was the last one.","這是最後一個。"
136
+ "please wait while I clear your cart.","請等候我清空你的購物車。"
137
+ "Webhook URL","Webhook URL 位址"
138
+ "Click %s to check that information on Telegram website. If a wrong URL is set, try reloading this page or click %s.","點選 %s 從 Telegram 網站查看資訊。如果連結錯誤,請嘗試刷新這頁或點按 %s。"
139
+ "here","此處"
140
+ "To configure Facebook webhook access","要設定接上 Facebook webhook"
141
+ "and set the webhook URL as","及設定 webhook URL 位址為"
142
+ "Create a new account.","建立新帳戶。"
143
+ "Access %s to register a new account on our shop.","經由 %s 在我們的商店登記新帳戶。"
144
+ "This product is not in stock.","此產品還未在存貨。"
package.xml CHANGED
@@ -1,5 +1,7 @@
1
  <?xml version="1.0"?>
2
- <package><name>Chatbot_Integration</name><version>0.0.5</version><stability>stable</stability><license>OSL</license><channel>community</channel><extends></extends><summary>Chatbot Integration for Telegram and Facebook Messenger.</summary><description>Chatbot (Telegram and Facebook Messenger), with this module you can fully integrate your Magento store with the most popular chat apps in the market. This means that by simply installing this module and a few clicks you can have a new way to show and sell your products to your clients. Very easy to use! Try now, it's FREE.&lt;br&gt;&#xD;
 
 
3
  &lt;h1&gt;Features&lt;/h1&gt;&lt;br&gt;&#xD;
4
  - List store categories&lt;br&gt;&#xD;
5
  - List products from category&lt;br&gt;&#xD;
@@ -17,7 +19,7 @@
17
  - Force exit customer from support mode&lt;br&gt;&#xD;
18
  - Block a customer for using support mode&lt;br&gt;&#xD;
19
  - Use Telegram to receive and reply messages from Facebook&lt;br&gt;&#xD;
20
- - Set custom reply messages for predetermined phrases&lt;br&gt;&#xD;
21
  &lt;br&gt;&#xD;
22
  &lt;b&gt;Currently not working with Configurable Products and products with custom options&lt;/b&gt;&lt;br&gt;&#xD;
23
  &lt;br&gt;&#xD;
@@ -25,4 +27,4 @@
25
  1. Unpack the extension ZIP file in your Magento root directory&lt;br&gt;&#xD;
26
  2. Clear the Magento cache: **System &gt; Cache Management**&lt;br&gt;&#xD;
27
  3. Log out the Magento admin and log back in to clear the ACL list&lt;br&gt;&#xD;
28
- 4. Recompile if you are using the Magento Compiler&lt;br&gt;</description><notes>Add option to send custom replies to predetermined messages.</notes><authors><author><name>Pablo</name><user>pablomontenegro</user><email>blopa@werules.com</email></author></authors><date>2017-03-11</date><time>15:04:46</time><compatible></compatible><dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies><contents><target name="mage"><dir name="app"><dir name="code"><dir name="community"><dir name="Werules"><dir name="Chatbot"><dir name="Block"><file name="Commands.php" hash="553475eba0ca5190ae6361d7aaf3c5eb"/><file name="CommandsSelect.php" hash="21d792402bb6758700e08885fc0708b5"/><file name="Enable.php" hash="91137cacb5a60f061deefed4ca8e4f91"/><file name="Replies.php" hash="454254306837abff6f74859df10b8a9f"/></dir><dir name="controllers"><file name="ChatdataController.php" hash="096cabaec4414d91862298a588f5c11a"/><file name="IndexController.php" hash="eae277df370ef69ebd75f72691523154"/><file name="SettingsController.php" hash="d169d06da794fd11ff08b53de4027a54"/></dir><dir name="etc"><file name="config.xml" hash="92c9e97c48d4d7b99f10d9f2cf3d346c"/><file name="system.xml" hash="223c148d353fc56181fa73e01ff3b3fd"/></dir><dir name="Helper"><file name="Data.php" hash="288462ee4ca74138d88e758a602a6311"/></dir><dir name="Model"><file name="Chatdata.php" hash="ea9a741edf1d1ddf953f8339039f40d5"/><file name="Chats.php" hash="174b05d4ceb3e98936a9e87f82b23621"/><file name="Enable.php" hash="c8c53bf3b4237632bb74d7721a1159a4"/><file name="Options.php" hash="092f711eee89759f33d09dec4e90583d"/><dir name="Adminhtml"><file name="Serialized.php" hash="270219dca43a25113933afb8c819e8da"/></dir><dir name="Api"><dir name="Facebook"><file name="Handler.php" hash="e2de02bef6bfaefe093bc34e8cb22306"/><file name="Messenger.php" hash="35c4bbe5df4b43f432b56b54b968bdc7"/></dir><dir name="Telegram"><file name="Handler.php" hash="26bde01c63dbf81bbcd7dcea52698aaf"/><file name="Telegram.php" hash="572289b61adb8ed8a822cf6d142010fd"/></dir><dir name="witAI"><file name="witAI.php" hash="f751d285f9d93aa8558f6c50c6535327"/></dir></dir><dir name="Mysql4"><file name="Chatdata.php" hash="5b1926048637e2bf7833a8a35643c812"/><dir name="Chatdata"><file name="Collection.php" hash="89bf742cfd5eeaf3704259fd3aedbdce"/></dir></dir></dir><dir name="sql"><dir name="chatbot_setup"><file name="mysql4-install-0.0.5.php" hash="60f58885b022c7165dbd12be3aadee9f"/></dir></dir></dir></dir></dir></dir><dir name="design"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="werules_chatbot.xml" hash="135c293d383f8e700a634eb84aa808f7"/></dir><dir name="template"><file name="werules_chatbot_config.phtml" hash="6a855bcae6c7bb2b914573b3f3081329"/><file name="werules_chatbot_view.phtml" hash="49d9b523d7c69571839695227d29a620"/></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="Werules_Chatbot.xml" hash="2d37b23d0f8894ec6627cd4877286019"/></dir></dir><dir name="locale"><dir name="pt_BR"><file name="Werules_Chatbot.csv" hash="ea4de497a43b613792b3e9f4133f5f06"/></dir></dir></dir></target></contents></package>
1
  <?xml version="1.0"?>
2
+ <package><name>Chatbot_Integration</name><version>0.0.9</version><stability>stable</stability><license>OSL</license><channel>community</channel><extends></extends><summary>Chatbot Integration for Telegram and Facebook Messenger.</summary><description>Chatbot (Telegram and Facebook Messenger), with this module you can fully integrate your Magento store with the most popular chat apps in the market. This means that by simply installing this module and a few clicks you can have a new way to show and sell your products to your clients. Very easy to use! Try now, it's FREE.&lt;br&gt;&#xD;
3
+ Customers will be able to simply enter into a chat conversation with your bot, and ask him to do things like add products to cart, check order status, send emails to your store, and much much more. Check the features below.&lt;br&gt;&#xD;
4
+ &lt;img src="http://i.imgur.com/W3pudq0.gif"/&gt;&lt;br&gt;&#xD;
5
  &lt;h1&gt;Features&lt;/h1&gt;&lt;br&gt;&#xD;
6
  - List store categories&lt;br&gt;&#xD;
7
  - List products from category&lt;br&gt;&#xD;
19
  - Force exit customer from support mode&lt;br&gt;&#xD;
20
  - Block a customer for using support mode&lt;br&gt;&#xD;
21
  - Use Telegram to receive and reply messages from Facebook&lt;br&gt;&#xD;
22
+ - Set custom reply messages for predetermined text or regex&lt;br&gt;&#xD;
23
  &lt;br&gt;&#xD;
24
  &lt;b&gt;Currently not working with Configurable Products and products with custom options&lt;/b&gt;&lt;br&gt;&#xD;
25
  &lt;br&gt;&#xD;
27
  1. Unpack the extension ZIP file in your Magento root directory&lt;br&gt;&#xD;
28
  2. Clear the Magento cache: **System &gt; Cache Management**&lt;br&gt;&#xD;
29
  3. Log out the Magento admin and log back in to clear the ACL list&lt;br&gt;&#xD;
30
+ 4. Recompile if you are using the Magento Compiler&lt;br&gt;</description><notes>Add option to send custom replies to predetermined messages.</notes><authors><author><name>Pablo</name><user>pablomontenegro</user><email>blopa@werules.com</email></author></authors><date>2017-03-17</date><time>21:33:50</time><compatible></compatible><dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies><contents><target name="mage"><dir name="app"><dir name="code"><dir name="community"><dir name="Werules"><dir name="Chatbot"><dir name="Block"><file name="Commands.php" hash="ff76acbe888fe51f655b543dcedfefd9"/><file name="CommandsSelect.php" hash="21d792402bb6758700e08885fc0708b5"/><file name="Enable.php" hash="91137cacb5a60f061deefed4ca8e4f91"/><file name="Replies.php" hash="4d0d42024f3db1d404011c24fb1c8e8e"/><file name="ReplyMode.php" hash="627a852f4a4686ec7304528e512f3d4e"/></dir><dir name="controllers"><file name="ChatdataController.php" hash="e646f390c1e5d1b7c69c667913587085"/><file name="IndexController.php" hash="eae277df370ef69ebd75f72691523154"/><file name="SettingsController.php" hash="5c924a7091e535dff538becb6d4dc6fd"/></dir><dir name="etc"><file name="config.xml" hash="7bef96632623db6ec40c914a9f35032d"/><file name="system.xml" hash="5631b31eeff99dca781a4562bd23ee9c"/></dir><dir name="Helper"><file name="Data.php" hash="288462ee4ca74138d88e758a602a6311"/></dir><dir name="Model"><file name="Chatdata.php" hash="dbd39655a9c7bb383e38c1656a51d1c9"/><file name="Chats.php" hash="174b05d4ceb3e98936a9e87f82b23621"/><file name="Enable.php" hash="c8c53bf3b4237632bb74d7721a1159a4"/><file name="Options.php" hash="1a4b5c16044d342106d6f570782f06b0"/><file name="ReplyMode.php" hash="b183ff17102bdc0c2c8b63806487fe7d"/><dir name="Adminhtml"><file name="Serialized.php" hash="270219dca43a25113933afb8c819e8da"/></dir><dir name="Api"><dir name="Facebook"><file name="Handler.php" hash="bcd7fdf2c47dd5c206fe4c448a84f36b"/><file name="Messenger.php" hash="35c4bbe5df4b43f432b56b54b968bdc7"/></dir><dir name="Telegram"><file name="Handler.php" hash="bd3f0854806edaeb3535f9a7ca3f4357"/><file name="Telegram.php" hash="e45a3a7c734cbdfe620d1458a34a604f"/></dir><dir name="witAI"><file name="witAI.php" hash="f751d285f9d93aa8558f6c50c6535327"/></dir></dir><dir name="Mysql4"><file name="Chatdata.php" hash="5b1926048637e2bf7833a8a35643c812"/><dir name="Chatdata"><file name="Collection.php" hash="89bf742cfd5eeaf3704259fd3aedbdce"/></dir></dir></dir><dir name="sql"><dir name="chatbot_setup"><file name="mysql4-install-0.0.9.php" hash="60f58885b022c7165dbd12be3aadee9f"/></dir></dir></dir></dir></dir></dir><dir name="design"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="werules_chatbot.xml" hash="0e79cf08dfd69fe93226c26d2c0b3836"/></dir><dir name="template"><file name="werules_chatbot_config.phtml" hash="6a855bcae6c7bb2b914573b3f3081329"/><file name="werules_chatbot_view.phtml" hash="29a3e82118b1a9df5fc00f72c2a59882"/></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="Werules_Chatbot.xml" hash="2d37b23d0f8894ec6627cd4877286019"/></dir></dir><dir name="locale"><dir name="en_US"><file name="Werules_Chatbot.csv" hash="393a4ce32f2eda1e4c1c5c579be5641b"/></dir><dir name="pt_BR"><file name="Werules_Chatbot.csv" hash="90eef98c8e72ee1982abe5a6ee05979d"/></dir><dir name="zh_CN"><file name="Werules_Chatbot.csv" hash="d2f6f680907942c0f55ed7e6b1eabd6d"/></dir><dir name="zh_HK"><file name="Werules_Chatbot.csv" hash="731541b30881e92df2f0c27772e1509c"/></dir><dir name="zh_TW"><file name="Werules_Chatbot.csv" hash="484eff00afdb9caf7928078948233005"/></dir></dir></dir></target></contents></package>