@tiledesk/tiledesk-tybot-connector 2.0.12-rc5 → 2.0.12-rc6

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 (44) hide show
  1. package/ExtApi.js +1 -8
  2. package/ExtUtil.js +5 -6
  3. package/engine/IntentForm.js +0 -1
  4. package/engine/IntentsMachineFactory.js +4 -4
  5. package/engine/MongodbBotsDataSource.js +0 -1
  6. package/engine/MongodbIntentsMachine.js +0 -1
  7. package/engine/TiledeskChatbot.js +11 -16
  8. package/engine/TiledeskIntentsMachine.js +1 -2
  9. package/index.js +11 -23
  10. package/package.json +1 -1
  11. package/services/AIService.js +1 -1
  12. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +10 -10
  13. package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +1 -2
  14. package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +1 -3
  15. package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +1 -3
  16. package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +7 -9
  17. package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfNotOpenHours.js +3 -10
  18. package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfOpenHours.js +2 -9
  19. package/tiledeskChatbotPlugs/directives/DirAddKbContent.js +333 -0
  20. package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +0 -1
  21. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +1 -3
  22. package/tiledeskChatbotPlugs/directives/DirFlowLog.js +1 -1
  23. package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +36 -54
  24. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +0 -1
  25. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +1 -2
  26. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +0 -1
  27. package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +7 -9
  28. package/tiledeskChatbotPlugs/directives/DirIntent.js +0 -1
  29. package/tiledeskChatbotPlugs/directives/DirLockIntent.js +0 -1
  30. package/tiledeskChatbotPlugs/directives/DirMake.js +1 -15
  31. package/tiledeskChatbotPlugs/directives/DirMessage.js +0 -1
  32. package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +0 -1
  33. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +0 -1
  34. package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +0 -1
  35. package/tiledeskChatbotPlugs/directives/DirReply.js +1 -1
  36. package/tiledeskChatbotPlugs/directives/DirReplyV2.js +8 -10
  37. package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +0 -1
  38. package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +1 -3
  39. package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +0 -1
  40. package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +0 -1
  41. package/tiledeskChatbotPlugs/directives/DirWebRequest.js +0 -1
  42. package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +1 -15
  43. package/tiledeskChatbotPlugs/directives/Directives.js +1 -0
  44. package/utils/TiledeskChatbotUtil.js +14 -28
@@ -1,6 +1,7 @@
1
1
  const { TiledeskClient } = require('@tiledesk/tiledesk-client');
2
2
  const { DirIntent } = require('./DirIntent');
3
3
  const ms = require('minimist-string');
4
+ const winston = require('../../utils/winston');
4
5
 
5
6
  class DirIfOpenHours {
6
7
 
@@ -26,9 +27,6 @@ class DirIfOpenHours {
26
27
  let params;
27
28
  params = this.parseParams(directive.parameter);
28
29
  if (!params.trueIntent && !params.falseIntent) {
29
- if (this.log) {
30
- console.log("missing both params.trueIntent & params.falseIntent");
31
- }
32
30
  callback();
33
31
  return;
34
32
  }
@@ -60,14 +58,14 @@ class DirIfOpenHours {
60
58
  if (falseIntent && falseIntent.trim() === "") {
61
59
  falseIntent = null;
62
60
  }
63
- if (this.log) {console.log("condition action:", action);}
61
+ winston.verbose("(DirIfOpenHours) Action:", action);
64
62
  if (!trueIntent && !falseIntent) {
65
- if (this.log) {console.log("Invalid condition, no intents specified");}
66
- callback();
63
+ winston.error("(DirIfOpenHours) Error: missing both action.trueIntent & action.falseIntent");
64
+ callback();
67
65
  return;
68
66
  }
69
67
  this.tdClient.openNow((err, result) => {
70
- if (this.log) {console.log("openNow():", result);}
68
+ winston.error("(DirIfOpenHours) openNow():", result)
71
69
  if (err) {
72
70
  console.error("*** DirIfOpenHours Error:", err);
73
71
  callback();
@@ -75,7 +73,7 @@ class DirIfOpenHours {
75
73
  else if (result && result.isopen) {
76
74
  if (trueIntent) {
77
75
  let intentDirective = DirIntent.intentDirectiveFor(trueIntent);
78
- if (this.log) {console.log("DirIfOpenHours (openHours) => trueIntent");}
76
+ winston.debug("(DirIfOpenHours) (openHours) => trueIntent ");
79
77
  this.intentDir.execute(intentDirective, () => {
80
78
  callback(stopOnConditionMet);
81
79
  });
@@ -87,7 +85,7 @@ class DirIfOpenHours {
87
85
  }
88
86
  else if (falseIntent) {
89
87
  let intentDirective = DirIntent.intentDirectiveFor(falseIntent);
90
- if (this.log) {console.log("DirIfOpenHours (openHours) => falseIntent", falseIntent);}
88
+ winston.debug("(DirIfOpenHours) (openHours) => falseIntent ");
91
89
  this.intentDir.execute(intentDirective, () => {
92
90
  callback(stopOnConditionMet);
93
91
  });
@@ -16,7 +16,6 @@ class DirIntent {
16
16
  this.TILEBOT_ENDPOINT = context.TILEBOT_ENDPOINT;
17
17
  this.supportRequest = context.supportRequest;
18
18
  this.token = context.token;
19
- this.log = context.log;
20
19
  }
21
20
 
22
21
  execute(directive, callback) {
@@ -12,7 +12,6 @@ class DirLockIntent {
12
12
  throw new Error('tdcache (TdCache) object is mandatory.');
13
13
  }
14
14
  this.tdcache = this.context.tdcache;
15
- this.log = context.log;
16
15
  }
17
16
 
18
17
  async execute(directive, callback) {
@@ -204,21 +204,7 @@ class DirMake {
204
204
 
205
205
  })
206
206
  .catch((err) => {
207
- if (this.log) {
208
- // FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - START
209
- let cache = [];
210
- let error_log = JSON.stringify(err, function (key, value) { // try to use a separate function
211
- if (typeof value === 'object' && value != null) {
212
- if (cache.indexOf(value) !== -1) {
213
- return;
214
- }
215
- cache.push(value);
216
- }
217
- return value;
218
- });
219
- winston.error("(DirMake) An error occurred: ", error_log);
220
- // FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - END;
221
- }
207
+ // FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - END;
222
208
  if (callback) {
223
209
  let status = 1000;
224
210
  let cache = [];
@@ -16,7 +16,6 @@ class DirMessage {
16
16
  this.requestId = context.requestId;
17
17
  this.tdcache = this.context.tdcache;
18
18
  this.token = context.token;
19
- this.log = this.context.log;
20
19
  this.supportRequest = this.context.supportRequest
21
20
 
22
21
  this.tdClient = new TiledeskClient({ projectId: this.context.projectId, token: this.context.token, APIURL: this.API_ENDPOINT, APIKEY: "___", log: this.log });
@@ -15,7 +15,6 @@ class DirMessageToBot {
15
15
  this.TILEBOT_ENDPOINT = context.TILEBOT_ENDPOINT;
16
16
  this.supportRequest = context.supportRequest;
17
17
  this.token = context.token;
18
- this.log = context.log;
19
18
  }
20
19
 
21
20
  execute(directive, callback) {
@@ -1,4 +1,3 @@
1
- // const { TiledeskClient } = require('@tiledesk/tiledesk-client');
2
1
  const { Directives } = require('./Directives');
3
2
  const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
4
3
  const { TiledeskChatbotConst } = require('../../engine/TiledeskChatbotConst');
@@ -1,4 +1,3 @@
1
- // const { TiledeskClient } = require('@tiledesk/tiledesk-client');
2
1
  const { Directives } = require('./Directives');
3
2
  const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
4
3
  const { TiledeskChatbotConst } = require('../../engine/TiledeskChatbotConst');
@@ -84,7 +84,7 @@ class DirReply {
84
84
  let command = commands[i];
85
85
  if (command.type === 'message' && command.message && command.message.text) {
86
86
  command.message.text = filler.fill(command.message.text, requestAttributes);
87
- TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes, this.log);
87
+ TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes);
88
88
  winston.debug("DirReply command filled: " + command.message.text);
89
89
  }
90
90
  if (command.type === 'settings' && command.settings) {
@@ -21,6 +21,7 @@ class DirReplyV2 {
21
21
  this.requestId = context.requestId;
22
22
  this.token = context.token;
23
23
  this.tdcache = context.tdcache;
24
+ this.intentDir = new DirIntent(context);
24
25
  this.chatbot = context.chatbot;
25
26
  this.reply = context.reply;
26
27
  this.originalMessage = context.message;
@@ -59,11 +60,10 @@ class DirReplyV2 {
59
60
  const message = action;
60
61
 
61
62
  let current; // debug only
62
- if (this.log) {
63
- if (message.attributes.commands[1].message.text) {
64
- current = message.attributes.commands[1].message.text
65
- }
63
+ if (message.attributes.commands[1].message.text) {
64
+ current = message.attributes.commands[1].message.text
66
65
  }
66
+
67
67
  let must_stop = false;
68
68
  // fill
69
69
  let requestAttributes = null;
@@ -72,11 +72,9 @@ class DirReplyV2 {
72
72
  await TiledeskChatbot.allParametersStatic(
73
73
  this.tdcache, this.requestId
74
74
  );
75
- if (this.log) {
76
- for (const [key, value] of Object.entries(requestAttributes)) {
77
- const value_type = typeof value;
78
- }
79
- }
75
+ // for (const [key, value] of Object.entries(requestAttributes)) {
76
+ // const value_type = typeof value;
77
+ // }
80
78
 
81
79
  TiledeskChatbotUtil.replaceJSONButtons(message, requestAttributes);
82
80
 
@@ -195,7 +193,7 @@ class DirReplyV2 {
195
193
  let command = commands[i];
196
194
  if (command.type === 'message' && command.message && command.message.text) {
197
195
  command.message.text = filler.fill(command.message.text, requestAttributes);
198
- TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes, this.log);
196
+ TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes);
199
197
  }
200
198
  }
201
199
  }
@@ -77,7 +77,6 @@ class DirSetAttribute {
77
77
  throw new Error('context object is mandatory.');
78
78
  }
79
79
  this.context = context;
80
- this.log = context.log;
81
80
  }
82
81
 
83
82
  execute(directive, callback) {
@@ -205,9 +205,7 @@ class DirSetAttributeV2 {
205
205
  httpUtils.request(
206
206
  HTTPREQUEST, async (err, resbody) => {
207
207
  if (err) {
208
- if (this.log) {
209
- winston.error("(DirSetAttributeV2) persistOnTiledesk() error: ", err);
210
- }
208
+ winston.error("(DirSetAttributeV2) persistOnTiledesk() error: ", err);
211
209
  } else {
212
210
  winston.debug("(DirSetAttributeV2) Attributes saved: ", resbody);
213
211
  }
@@ -9,7 +9,6 @@ class DirSetConversationTags {
9
9
  throw new Error('context object is mandatory.');
10
10
  }
11
11
  this.context = context;
12
- this.log = context.log;
13
12
  this.requestId = context.requestId;
14
13
  this.API_ENDPOINT = context.API_ENDPOINT;
15
14
 
@@ -11,7 +11,6 @@ class DirUnlockIntent {
11
11
  throw new Error('tdcache (TdCache) object is mandatory.');
12
12
  }
13
13
  this.tdcache = context.tdcache;
14
- this.log = context.log;
15
14
  }
16
15
 
17
16
  async execute(directive, callback) {
@@ -13,7 +13,6 @@ class DirWebRequest {
13
13
  this.context = context;
14
14
  this.tdcache = context.tdcache;
15
15
  this.requestId = context.requestId;
16
- this.log = context.log;
17
16
  }
18
17
 
19
18
  execute(directive, callback) {
@@ -317,21 +317,7 @@ class DirWebRequestV2 {
317
317
  }
318
318
  })
319
319
  .catch((err) => {
320
- if (this.log) {
321
- // FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - START
322
- let cache = [];
323
- let error_log = JSON.stringify(err, function (key, value) { // try to use a separate function
324
- if (typeof value === 'object' && value != null) {
325
- if (cache.indexOf(value) !== -1) {
326
- return;
327
- }
328
- cache.push(value);
329
- }
330
- return value;
331
- });
332
- winston.error("(DirWebRequestv2) An error occurred: ", error_log);
333
- // FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - END
334
- }
320
+ // FIX THE STRINGIFY OF CIRCULAR STRUCTURE BUG - END
335
321
  if (callback) {
336
322
  let status = 1000;
337
323
  let cache = [];
@@ -60,6 +60,7 @@ class Directives {
60
60
  static ADD_TAGS = 'add_tags'
61
61
  static WEB_RESPONSE = "web_response";
62
62
  static FLOW_LOG = "flow_log";
63
+ static ADD_KB_CONTENT = "add_kb_content";
63
64
 
64
65
  // static WHEN_ONLINE_MOVE_TO_AGENT = "whenonlinemovetoagent"; // DEPRECATED?
65
66
  // static WHEN_OFFLINE_HOURS = "whenofflinehours"; // DEPRECATED // adds a message on top of the original message when offline hours opts: --replace
@@ -252,24 +252,24 @@ class TiledeskChatbotUtil {
252
252
  }
253
253
  }
254
254
 
255
- static fillCommandAttachments(command, variables, log) {
256
- if (log) { winston.debug("(TiledeskChatbotUtils) Filling command button: ", command) }
255
+ static fillCommandAttachments(command, variables) {
256
+ winston.debug("(TiledeskChatbotUtils) Filling command button: ", command)
257
257
  if (command.message && command.message.attributes && command.message.attributes.attachment && command.message.attributes.attachment.buttons && command.message.attributes.attachment.buttons.length > 0) {
258
258
  let buttons = command.message.attributes.attachment.buttons;
259
259
  const filler = new Filler();
260
260
  buttons.forEach(button => {
261
261
  if (button.link) {
262
262
  button.link = filler.fill(button.link, variables);
263
- if (log) { winston.debug("(TiledeskChatbotUtils) button.link filled: " + button.link) }
263
+ winston.debug("(TiledeskChatbotUtils) button.link filled: " + button.link)
264
264
  }
265
265
  if (button.value) {
266
266
  button.value = filler.fill(button.value, variables);
267
- if (log) { winston.debug("(TiledeskChatbotUtils) button.value filled: " + button.value) }
267
+ winston.debug("(TiledeskChatbotUtils) button.value filled: " + button.value)
268
268
  }
269
269
  });
270
270
  }
271
271
  else {
272
- if (log) { winston.debug("(TiledeskChatbotUtils) No attachments to fill in command") }
272
+ winston.debug("(TiledeskChatbotUtils) No attachments to fill in command")
273
273
  }
274
274
  }
275
275
 
@@ -520,7 +520,7 @@ class TiledeskChatbotUtil {
520
520
  static async updateRequestAttributes(chatbot, chatbotToken, message, projectId, requestId) {
521
521
  // update request context
522
522
  try {
523
- if (chatbot.log) { winston.debug("Updating request variables. Message:", message); }
523
+ winston.debug("Updating request variables. Message:", message);
524
524
  const messageId = message._id;
525
525
  const chat_url = `https://panel.tiledesk.com/v3/dashboard/#/project/${projectId}/wsrequest/${requestId}/messages`
526
526
 
@@ -591,12 +591,12 @@ class TiledeskChatbotUtil {
591
591
  }
592
592
 
593
593
  if (message && message.request && message.request.lead) {
594
- if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Lead found with email: " + message.request.lead.email + " and lead.fullname " + message.request.lead.fullname); }
594
+ winston.debug("(TiledeskChatbotUtil) Lead found with email: " + message.request.lead.email + " and lead.fullname " + message.request.lead.fullname);
595
595
  let currentLeadEmail = await chatbot.getParameter(TiledeskChatbotConst.REQ_LEAD_EMAIL_KEY);
596
- if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) You lead email from attributes: " + currentLeadEmail); }
596
+ winston.debug("(TiledeskChatbotUtil) You lead email from attributes: " + currentLeadEmail);
597
597
  if (message.request.lead.email && !currentLeadEmail) {
598
598
  // worth saving
599
- if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) worth saving email"); }
599
+ winston.debug("(TiledeskChatbotUtil) worth saving email");
600
600
  try {
601
601
  await chatbot.addParameter(TiledeskChatbotConst.REQ_LEAD_EMAIL_KEY, message.request.lead.email);
602
602
  }
@@ -685,10 +685,10 @@ class TiledeskChatbotUtil {
685
685
  message.attributes = {}
686
686
  }
687
687
  message.attributes.payload = { ...message.attributes.payload, ...message.request.attributes.payload }
688
- if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Forced Set message.attributes.payload ", message.attributes.payload); }
688
+ winston.debug("(TiledeskChatbotUtil) Forced Set message.attributes.payload ", message.attributes.payload);
689
689
  }
690
690
  if (message.attributes) {
691
- if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Ok message.attributes ", message.attributes); }
691
+ winston.debug("(TiledeskChatbotUtil) Ok message.attributes ", message.attributes);
692
692
 
693
693
  await chatbot.addParameter(TiledeskChatbotConst.REQ_END_USER_ID_KEY, message.attributes.requester_id);
694
694
  await chatbot.addParameter(TiledeskChatbotConst.REQ_END_USER_IP_ADDRESS_KEY, message.attributes.ipAddress);
@@ -722,12 +722,12 @@ class TiledeskChatbotUtil {
722
722
 
723
723
 
724
724
  const _bot = chatbot.bot; // aka FaqKB
725
- if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Adding Globals to context: ", _bot); }
725
+ winston.debug("(TiledeskChatbotUtil) Adding Globals to context: ", _bot);
726
726
 
727
727
  if (_bot.attributes && _bot.attributes.globals) {
728
- if (chatbot.log) { winston.error("(TiledeskChatbotUtil) Got Globals: ", _bot.attributes.globals); }
728
+ winston.error("(TiledeskChatbotUtil) Got Globals: ", _bot.attributes.globals);
729
729
  _bot.attributes.globals.forEach(async (global_var) => {
730
- if (chatbot.log) { winston.error("(TiledeskChatbotUtil) Adding global: " + global_var.key + " value: " + global_var.value); }
730
+ winston.error("(TiledeskChatbotUtil) Adding global: " + global_var.key + " value: " + global_var.value);
731
731
  await chatbot.addParameter(global_var.key, global_var.value);
732
732
  });
733
733
  }
@@ -740,20 +740,6 @@ class TiledeskChatbotUtil {
740
740
  // }
741
741
  // );
742
742
 
743
- if (chatbot.log) {
744
- if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) requestId: " + requestId); }
745
- if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Key: " + TiledeskChatbotConst.REQ_PROJECT_ID_KEY); }
746
-
747
- let proj_ = await chatbot.getParameter(TiledeskChatbotConst.REQ_PROJECT_ID_KEY);
748
- if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) request parameter proj_: " + proj_); }
749
-
750
- const all_parameters = await chatbot.allParameters();
751
- for (const [key, value] of Object.entries(all_parameters)) {
752
- const value_type = typeof value;
753
- if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) Request Attribute: " + key + " value: " + value + " type: " + value_type); }
754
-
755
- }
756
- }
757
743
  } catch(error) {
758
744
  winston.error("(TiledeskChatbotUtil) updateRequestAttributes Error: ", error);
759
745
  process.exit(1)