@tiledesk/tiledesk-tybot-connector 0.5.0 → 0.5.1-rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/ExtApi.js +4 -83
  3. package/ExtUtil.js +0 -1
  4. package/Logger.js +113 -0
  5. package/TdCache.js +5 -3
  6. package/TiledeskClientTest.js +5 -28
  7. package/TiledeskExpression.js +6 -47
  8. package/{models → engine}/IntentForm.js +30 -44
  9. package/{models → engine}/IntentsMachineFactory.js +5 -4
  10. package/{models → engine}/MongodbBotsDataSource.js +31 -55
  11. package/{models → engine}/MongodbIntentsMachine.js +6 -5
  12. package/{models → engine}/TiledeskChatbot.js +82 -259
  13. package/{models → engine}/TiledeskChatbotConst.js +9 -0
  14. package/{models → engine}/TiledeskIntentsMachine.js +5 -15
  15. package/{models → engine/mock}/MockBotsDataSource.js +2 -19
  16. package/{models → engine/mock}/MockTdCache.js +0 -9
  17. package/index.js +106 -380
  18. package/logs/app.log +11557 -277
  19. package/logs/app1.log +62258 -0
  20. package/logs/app2.log +46280 -0
  21. package/logs/app3.log +31686 -0
  22. package/logs/app4.log +46163 -0
  23. package/logs/app5.log +33173 -0
  24. package/models/faq.js +2 -5
  25. package/package.json +5 -2
  26. package/{TiledeskServices → services}/AIService.js +4 -3
  27. package/{models/faqKbService.js → services/FaqKbService.js} +1 -2
  28. package/{models/faqService.js → services/FaqService.js} +4 -3
  29. package/services/IntegrationService.js +43 -0
  30. package/services/TilebotService.js +47 -0
  31. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +68 -142
  32. package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +8 -14
  33. package/tiledeskChatbotPlugs/Filler.js +0 -1
  34. package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +12 -20
  35. package/tiledeskChatbotPlugs/MessagePipeline.js +5 -15
  36. package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +4 -13
  37. package/tiledeskChatbotPlugs/TiledeskRequestVariables.js +1 -1
  38. package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +21 -89
  39. package/tiledeskChatbotPlugs/directives/DEPRECATED_DirSetAttribute.js +1 -1
  40. package/tiledeskChatbotPlugs/directives/DirAddTags.js +23 -140
  41. package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +42 -128
  42. package/tiledeskChatbotPlugs/directives/DirAskGPT.js +37 -127
  43. package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +52 -145
  44. package/tiledeskChatbotPlugs/directives/DirAssign.js +12 -23
  45. package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +16 -12
  46. package/tiledeskChatbotPlugs/directives/DirAssistant.js +56 -198
  47. package/tiledeskChatbotPlugs/directives/DirBrevo.js +41 -101
  48. package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +9 -19
  49. package/tiledeskChatbotPlugs/directives/DirClearTranscript.js +1 -1
  50. package/tiledeskChatbotPlugs/directives/DirClose.js +4 -2
  51. package/tiledeskChatbotPlugs/directives/DirCode.js +16 -23
  52. package/tiledeskChatbotPlugs/directives/DirCondition.js +19 -25
  53. package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +9 -82
  54. package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +10 -22
  55. package/tiledeskChatbotPlugs/directives/DirCustomerio.js +34 -89
  56. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +17 -22
  57. package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +8 -8
  58. package/tiledeskChatbotPlugs/directives/DirDepartment.js +13 -12
  59. package/tiledeskChatbotPlugs/directives/DirDisableInputText.js +2 -6
  60. package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +4 -4
  61. package/tiledeskChatbotPlugs/directives/DirForm.js +17 -24
  62. package/tiledeskChatbotPlugs/directives/DirGptTask.js +49 -139
  63. package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +8 -53
  64. package/tiledeskChatbotPlugs/directives/DirHubspot.js +31 -91
  65. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +19 -26
  66. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +24 -78
  67. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +17 -68
  68. package/tiledeskChatbotPlugs/directives/DirIntent.js +12 -104
  69. package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +15 -14
  70. package/tiledeskChatbotPlugs/directives/DirLockIntent.js +7 -12
  71. package/tiledeskChatbotPlugs/directives/DirMake.js +21 -53
  72. package/tiledeskChatbotPlugs/directives/DirMessage.js +35 -28
  73. package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +8 -87
  74. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +6 -4
  75. package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +6 -4
  76. package/tiledeskChatbotPlugs/directives/DirQapla.js +26 -120
  77. package/tiledeskChatbotPlugs/directives/DirRandomReply.js +11 -19
  78. package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +4 -0
  79. package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +5 -2
  80. package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +12 -58
  81. package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +11 -57
  82. package/tiledeskChatbotPlugs/directives/DirReply.js +34 -37
  83. package/tiledeskChatbotPlugs/directives/DirReplyV2.js +30 -72
  84. package/tiledeskChatbotPlugs/directives/DirSendEmail.js +9 -10
  85. package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +15 -40
  86. package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +8 -5
  87. package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +25 -113
  88. package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +14 -13
  89. package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +3 -3
  90. package/tiledeskChatbotPlugs/directives/DirWait.js +5 -6
  91. package/tiledeskChatbotPlugs/directives/DirWebRequest.js +14 -49
  92. package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +22 -77
  93. package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +1 -1
  94. package/tiledeskChatbotPlugs/directives/DirWebResponse.js +23 -64
  95. package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +13 -42
  96. package/tiledeskChatbotPlugs/directives/Directives.js +1 -3
  97. package/utils/HttpUtils.js +128 -0
  98. package/{models → utils}/TiledeskChatbotUtil.js +140 -234
  99. package/utils/winston.js +42 -0
  100. package/TdCache copy.js +0 -242
  101. package/TiledeskServices/utils.js +0 -99
  102. /package/{models → engine/mock}/MockIntentsMachine.js +0 -0
@@ -34,6 +34,15 @@ class TiledeskChatbotConst {
34
34
  static REQ_CHATBOT_TOKEN = "chatbotToken";
35
35
  static REQ_CHATBOT_TOKEN_v2 = "chatbot_jwt_token";
36
36
  static API_BASE_URL = "api_base_url";
37
+ static REQ_LAST_USER_IMAGE_URL = 'lastUserImageURL';
38
+ static REQ_LAST_USER_IMAGE_NAME = 'lastUserImageName';
39
+ static REQ_LAST_USER_IMAGE_WIDTH = 'lastUserImageWidth';
40
+ static REQ_LAST_USER_IMAGE_HEIGHT = 'lastUserImageHeight';
41
+ static REQ_LAST_USER_IMAGE_TYPE = 'lastUserImageType';
42
+ static REQ_LAST_USER_DOCUMENT_URL = 'lastUserDocumentURL';
43
+ static REQ_LAST_USER_DOCUMENT_NAME = 'lastUserDocumentName';
44
+ static REQ_LAST_USER_DOCUMENT_TYPE = 'lastUserDocumentType';
45
+
37
46
  }
38
47
 
39
48
  module.exports = { TiledeskChatbotConst };
@@ -1,5 +1,6 @@
1
1
 
2
2
  let axios = require('axios');
3
+ const winston = require('../utils/winston');
3
4
 
4
5
  class TiledeskIntentsMachine {
5
6
 
@@ -21,9 +22,9 @@ class TiledeskIntentsMachine {
21
22
  */
22
23
  async decode(botId, text) {
23
24
  return new Promise( (resolve, reject) => {
24
- if (this.log) {console.log("NLP AI...");}
25
+ winston.verbose("(TiledeskIntentsMachine) NLP AI...");
25
26
  const url = `${this.API_ENDPOINT}/model/parse`;
26
- if (this.log) {console.log("AI URL", url);}
27
+ winston.verbose("(TiledeskIntentsMachine) AI URL " + url);
27
28
  const HTTPREQUEST = {
28
29
  url: url,
29
30
  headers: {
@@ -39,11 +40,10 @@ class TiledeskIntentsMachine {
39
40
  HTTPREQUEST,
40
41
  (err, resbody) => {
41
42
  if (err) {
42
- // console.error("An error occurred on /model/parse:", err)
43
43
  reject(err);
44
44
  }
45
45
  else {
46
- console.log("Tiledesk AI replied:", resbody)
46
+ winston.debug("(TiledeskIntentsMachine) Tiledesk AI replied: ", resbody)
47
47
  resolve(this.translateForTiledesk(resbody));
48
48
  }
49
49
  }, false
@@ -94,10 +94,6 @@ class TiledeskIntentsMachine {
94
94
  }
95
95
 
96
96
  myrequest(options, callback, log) {
97
- if (this.log) {
98
- console.log("API URL:", options.url);
99
- console.log("** Options:", JSON.stringify(options));
100
- }
101
97
  axios(
102
98
  {
103
99
  url: options.url,
@@ -107,11 +103,6 @@ class TiledeskIntentsMachine {
107
103
  headers: options.headers
108
104
  })
109
105
  .then((res) => {
110
- if (this.log) {
111
- console.log("Response for url:", options.url);
112
- console.log("Response headers:\n", JSON.stringify(res.headers));
113
- //console.log("******** Response for url:", res);
114
- }
115
106
  if (res && res.status == 200 && res.data) {
116
107
  if (callback) {
117
108
  callback(null, res.data);
@@ -123,8 +114,7 @@ class TiledeskIntentsMachine {
123
114
  }
124
115
  }
125
116
  })
126
- .catch( (error) => {
127
- console.error("(TiledeskIntentsMachine) Axios error: ", JSON.stringify(error));
117
+ .catch((error) => {
128
118
  if (callback) {
129
119
  callback(error, null, null);
130
120
  }
@@ -24,7 +24,6 @@ class MockBotsDataSource {
24
24
  }catch(err){
25
25
  reject(err);
26
26
  }
27
-
28
27
  })
29
28
  }
30
29
 
@@ -38,12 +37,8 @@ class MockBotsDataSource {
38
37
  * @returns an Array of matches
39
38
  */
40
39
  async getByExactMatch(botId, text) {
41
- // console.log("text is:", text);
42
- // console.log("this.data.bots[botId]:", this.data.bots[botId]);
43
40
  const intent_display_name = this.data.bots[botId].questions_intent[text];
44
- // console.log("intent_display_name:", intent_display_name);
45
41
  if (intent_display_name) {
46
- // console.log("intent by display name:", this.data.bots[botId].intents[intent_display_name]);
47
42
  return [this.data.bots[botId].intents[intent_display_name]];
48
43
  }
49
44
  return null;
@@ -55,26 +50,20 @@ class MockBotsDataSource {
55
50
  * @returns a single Intent
56
51
  */
57
52
  async getByIntentDisplayName(botId, intentName) {
58
- // console.log("this.data_", JSON.stringify(this.data.bots[botId]))
59
- // const intent = this.data.bots[botId].intents[intentName];
60
- // console.log("got intent:", intent);
61
53
  let intent;
62
54
  try {
63
55
  let key = intentName.trim();
64
- // console.log("key is:", key);
65
56
  if (key.startsWith("#")) {
66
57
  let intent_id = key.substring(key.indexOf("#") + 1);
67
58
  intent = this.data.bots[botId].intents_by_intent_id[intent_id];
68
59
  }
69
60
  else {
70
- // console.log("key is intent name:", key);
71
61
  let intent_id = key;
72
62
  intent = this.data.bots[botId].intents[intent_id];
73
- // console.log("Intent found", intent);
74
63
  }
75
64
  }
76
65
  catch(err) {
77
- console.error("Error is:", err);
66
+ winston.error("(MockBotsDataSource) Error getByIntentDisplayName: ", err);
78
67
  }
79
68
  return intent;
80
69
  }
@@ -82,23 +71,17 @@ class MockBotsDataSource {
82
71
  async getByIntentDisplayNameCache(botId, key, tdcache) {
83
72
  let faq = null;
84
73
  if (tdcache) {
85
- // console.log("mock cache. anyway in mock getting faq from datasource...");
86
74
  faq = await this.getByIntentDisplayName(botId, key);
87
- // console.log("faq found in datasource.:", JSON.stringify(faq));
88
75
  }
89
76
  else {
90
- // console.log("mock no chache. getting faq from datasource...");
91
77
  faq = await this.getByIntentDisplayName(botId, key);
92
- // console.log("faq found in datasource..:", JSON.stringify(faq));
93
78
  }
79
+
94
80
  // clones the faq to avoid modifying original object
95
- // console.log("faq is:", faq)
96
81
  let json_faq;
97
82
  if (faq !== null && faq !== undefined) {
98
83
  let string_faq = JSON.stringify(faq)
99
- // console.log("string faq is:", string_faq)
100
84
  json_faq = JSON.parse(string_faq);
101
- // console.log("json faq is:", json_faq)
102
85
  }
103
86
  return json_faq;
104
87
  }
@@ -15,11 +15,7 @@ class MockTdCache {
15
15
  }
16
16
 
17
17
  async incr(k) {
18
- // console.log("incr...", k)
19
- // return new Promise( (resolve, reject) => {
20
- // console.log("Promise incr...", k)
21
18
  let value = await this.get(k);
22
- // console.log("value.............", value)
23
19
  if (value == undefined || value == null) {
24
20
  value = 0;
25
21
  }
@@ -27,15 +23,10 @@ class MockTdCache {
27
23
  value = Number(value);
28
24
  }
29
25
  catch(error) {
30
- // console.error("Error on value = Number(value);", error);
31
26
  value = 0
32
27
  }
33
- // console.log("got", k, value)
34
28
  let v_incr = Number(value) + 1;
35
29
  this.db.set(k, "" + v_incr) // saves as string
36
- // resolve();
37
-
38
- // });
39
30
  }
40
31
 
41
32
  async get(k) {