@tiledesk/tiledesk-tybot-connector 0.5.0 → 2.0.0

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 (100) hide show
  1. package/ExtApi.js +4 -83
  2. package/ExtUtil.js +0 -1
  3. package/Logger.js +105 -0
  4. package/TdCache.js +5 -3
  5. package/TiledeskClientTest.js +5 -28
  6. package/TiledeskExpression.js +6 -47
  7. package/{models → engine}/IntentForm.js +30 -44
  8. package/{models → engine}/IntentsMachineFactory.js +5 -4
  9. package/{models → engine}/MongodbBotsDataSource.js +31 -55
  10. package/{models → engine}/MongodbIntentsMachine.js +6 -5
  11. package/{models → engine}/TiledeskChatbot.js +82 -259
  12. package/{models → engine}/TiledeskChatbotConst.js +9 -0
  13. package/{models → engine}/TiledeskIntentsMachine.js +5 -15
  14. package/{models → engine/mock}/MockBotsDataSource.js +3 -19
  15. package/{models → engine/mock}/MockTdCache.js +0 -9
  16. package/index.js +103 -380
  17. package/logs/app.log +12723 -277
  18. package/logs/app1.log +62258 -0
  19. package/logs/app2.log +46280 -0
  20. package/logs/app3.log +31686 -0
  21. package/logs/app4.log +46163 -0
  22. package/logs/app5.log +33173 -0
  23. package/models/faq.js +2 -5
  24. package/package.json +5 -2
  25. package/{TiledeskServices → services}/AIService.js +4 -3
  26. package/{models/faqKbService.js → services/FaqKbService.js} +1 -2
  27. package/{models/faqService.js → services/FaqService.js} +4 -3
  28. package/services/IntegrationService.js +43 -0
  29. package/services/TilebotService.js +47 -0
  30. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +49 -135
  31. package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +8 -14
  32. package/tiledeskChatbotPlugs/Filler.js +0 -1
  33. package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +12 -20
  34. package/tiledeskChatbotPlugs/MessagePipeline.js +5 -15
  35. package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +4 -13
  36. package/tiledeskChatbotPlugs/TiledeskRequestVariables.js +1 -1
  37. package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +21 -89
  38. package/tiledeskChatbotPlugs/directives/DEPRECATED_DirSetAttribute.js +1 -1
  39. package/tiledeskChatbotPlugs/directives/DirAddTags.js +23 -140
  40. package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +42 -128
  41. package/tiledeskChatbotPlugs/directives/DirAskGPT.js +37 -127
  42. package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +52 -145
  43. package/tiledeskChatbotPlugs/directives/DirAssign.js +12 -23
  44. package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +16 -12
  45. package/tiledeskChatbotPlugs/directives/DirAssistant.js +56 -198
  46. package/tiledeskChatbotPlugs/directives/DirBrevo.js +41 -101
  47. package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +9 -19
  48. package/tiledeskChatbotPlugs/directives/DirClearTranscript.js +1 -1
  49. package/tiledeskChatbotPlugs/directives/DirClose.js +4 -2
  50. package/tiledeskChatbotPlugs/directives/DirCode.js +16 -23
  51. package/tiledeskChatbotPlugs/directives/DirCondition.js +19 -25
  52. package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +9 -82
  53. package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +10 -22
  54. package/tiledeskChatbotPlugs/directives/DirCustomerio.js +34 -89
  55. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +17 -22
  56. package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +8 -8
  57. package/tiledeskChatbotPlugs/directives/DirDepartment.js +13 -12
  58. package/tiledeskChatbotPlugs/directives/DirDisableInputText.js +2 -6
  59. package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +4 -4
  60. package/tiledeskChatbotPlugs/directives/DirForm.js +17 -24
  61. package/tiledeskChatbotPlugs/directives/DirGptTask.js +49 -139
  62. package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +8 -53
  63. package/tiledeskChatbotPlugs/directives/DirHubspot.js +31 -91
  64. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +19 -26
  65. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +24 -78
  66. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +17 -68
  67. package/tiledeskChatbotPlugs/directives/DirIntent.js +6 -100
  68. package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +15 -14
  69. package/tiledeskChatbotPlugs/directives/DirLockIntent.js +7 -12
  70. package/tiledeskChatbotPlugs/directives/DirMake.js +21 -53
  71. package/tiledeskChatbotPlugs/directives/DirMessage.js +35 -28
  72. package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +8 -87
  73. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +6 -4
  74. package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +6 -4
  75. package/tiledeskChatbotPlugs/directives/DirQapla.js +26 -120
  76. package/tiledeskChatbotPlugs/directives/DirRandomReply.js +11 -19
  77. package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +4 -0
  78. package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +5 -2
  79. package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +12 -58
  80. package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +11 -57
  81. package/tiledeskChatbotPlugs/directives/DirReply.js +36 -30
  82. package/tiledeskChatbotPlugs/directives/DirReplyV2.js +30 -72
  83. package/tiledeskChatbotPlugs/directives/DirSendEmail.js +9 -10
  84. package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +15 -40
  85. package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +8 -5
  86. package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +25 -113
  87. package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +14 -13
  88. package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +3 -3
  89. package/tiledeskChatbotPlugs/directives/DirWait.js +5 -6
  90. package/tiledeskChatbotPlugs/directives/DirWebRequest.js +14 -49
  91. package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +22 -77
  92. package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +1 -1
  93. package/tiledeskChatbotPlugs/directives/DirWebResponse.js +11 -14
  94. package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +13 -42
  95. package/tiledeskChatbotPlugs/directives/Directives.js +0 -3
  96. package/utils/HttpUtils.js +128 -0
  97. package/{models → utils}/TiledeskChatbotUtil.js +164 -234
  98. package/utils/winston.js +42 -0
  99. package/TiledeskServices/utils.js +0 -99
  100. /package/{models → engine/mock}/MockIntentsMachine.js +0 -0
@@ -1,7 +1,8 @@
1
1
  const { param } = require('express/lib/request');
2
2
  const ms = require('minimist-string');
3
- const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
3
+ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
4
4
  const { Filler } = require('../Filler');
5
+ const winston = require('../../utils/winston');
5
6
 
6
7
  class DirDeleteVariable {
7
8
 
@@ -14,6 +15,7 @@ class DirDeleteVariable {
14
15
  }
15
16
 
16
17
  async execute(directive, callback) {
18
+ winston.verbose("Execute DeleteVariable directive");
17
19
  let action;
18
20
  if (directive.action) {
19
21
  action = directive.action
@@ -29,11 +31,11 @@ class DirDeleteVariable {
29
31
  }
30
32
 
31
33
  async go(action, callback) {
32
- // let variableName = action.body.variableName;
34
+ winston.debug("(DirDeleteVariable) Action: ", action);
35
+
33
36
  let variableName = action.variableName;
34
- // console.log("DirDeleteVariable:", directive);
35
37
  if (!variableName) {
36
- if (this.log) {console.log("Error deleting variable. Missing 'variableName' error. Skipping");}
38
+ winston.error("(DirDeleteVariable) deleting variable. Missing 'variableName' error. Skipping");
37
39
  if (callback) {
38
40
  callback();
39
41
  }
@@ -46,11 +48,9 @@ class DirDeleteVariable {
46
48
  await TiledeskChatbot.allParametersStatic(
47
49
  this.context.tdcache, this.context.requestId
48
50
  );
49
- // console.log("All availabe variables before deletion:", variables);
51
+
50
52
  const filler = new Filler();
51
- // console.log("delete variable name:", variableName);
52
53
  variableName = filler.fill(variableName, variables);
53
- // console.log("delete variable name (after filling):", variableName);
54
54
  await TiledeskChatbot.deleteParameterStatic(
55
55
  this.context.tdcache, this.context.requestId, variableName
56
56
  );
@@ -60,7 +60,7 @@ class DirDeleteVariable {
60
60
  }
61
61
  }
62
62
  catch(err) {
63
- console.error("DirDeleteVariable error:", err);
63
+ winston.error("(DirDeleteVariable) error: ", err);
64
64
  if (completion) {
65
65
  completion();
66
66
  }
@@ -1,4 +1,5 @@
1
1
  const { TiledeskClient } = require("@tiledesk/tiledesk-client");
2
+ const winston = require('../../utils/winston');
2
3
 
3
4
  class DirDepartment {
4
5
 
@@ -21,7 +22,7 @@ class DirDepartment {
21
22
  }
22
23
 
23
24
  execute(directive, callback) {
24
- // if (this.log) {console.log("DirDepartment:", dep_name);}
25
+ winston.verbose("Execute Department directive");
25
26
  let action;
26
27
  if (directive.action) {
27
28
  action = directive.action;
@@ -61,15 +62,15 @@ class DirDepartment {
61
62
  // }
62
63
 
63
64
  go(action, callback) {
64
- if (this.log) {console.log("Switching to department:", action.depName);}
65
+ winston.debug("(DirDepartment) Action: ", action);
65
66
  const depName = action.depName;
66
67
  this.moveToDepartment(this.requestId, depName, (deps) => {
67
68
  if (!deps) {
68
- if (this.log) {console.log("Dep not found");}
69
+ winston.warn("(DirDepartment) Dep not found");
69
70
  callback();
70
71
  return
71
72
  }
72
- if (this.log) {console.log("Switched to dept:", depName, "action:", JSON.stringify(action));}
73
+ winston.debug("(DirDepartment) Switched to dept: " + depName + " action: " + JSON.stringify(action));
73
74
  if (action.triggerBot) {
74
75
  let dep = null;
75
76
  let i;
@@ -81,7 +82,7 @@ class DirDepartment {
81
82
  }
82
83
  }
83
84
  if (dep && dep.hasBot === true && dep.id_bot) {
84
- if (this.log) {console.log("Sending hidden /start message to bot in dept");}
85
+ winston.debug("(DirDepartment) Sending hidden /start message to bot in dept");
85
86
  const message = {
86
87
  type: "text",
87
88
  text: "/start",
@@ -93,15 +94,15 @@ class DirDepartment {
93
94
  this.requestId,
94
95
  message, (err) => {
95
96
  if (err) {
96
- console.error("Error sending hidden message:", err.message);
97
+ winston.error("(DirDepartment) Error sending hidden message: " + err.message)
97
98
  }
98
- if (this.log) {console.log("Hidden message sent.");}
99
+ winston.debug("(DirDepartment) Hidden message sent.");
99
100
  callback();
100
101
  });
101
102
  }
102
103
  }
103
104
  else {
104
- if (this.log) {console.log("No action.triggerBot");}
105
+ winston.debug("(DirDepartment) No action.triggerBot");
105
106
  callback();
106
107
  }
107
108
  });
@@ -109,9 +110,9 @@ class DirDepartment {
109
110
 
110
111
  moveToDepartment(requestId, depName, callback) {
111
112
  this.tdClient.getAllDepartments((err, deps) => {
112
- if (this.log) {console.log("deps:", JSON.stringify(deps));}
113
+ winston.debug("(DirDepartment) deps: ", deps);
113
114
  if (err) {
114
- console.error("getAllDepartments() error:", err);
115
+ winston.error("(DirDepartment) getAllDepartments() error: ", err);
115
116
  callback();
116
117
  return;
117
118
  }
@@ -127,11 +128,11 @@ class DirDepartment {
127
128
  if (dep) {
128
129
  this.tdClient.updateRequestDepartment(requestId, dep._id, null, (err, res) => {
129
130
  if (err) {
130
- console.error("DirDepartment error:", err);
131
+ winston.error("(DirDepartment) updatedRequestDepartment error: ", err);
131
132
  callback();
132
133
  }
133
134
  else {
134
- if (this.log) { console.log("DirDepartment response:",JSON.stringify(res)); }
135
+ winston.debug("(DirDepartment) response: ", res);
135
136
  callback(deps);
136
137
  }
137
138
  });
@@ -1,4 +1,5 @@
1
1
  const ms = require('minimist-string');
2
+ const winston = require('../../utils/winston');
2
3
 
3
4
  // DEPRECATED
4
5
  class DirDisableInputText {
@@ -7,7 +8,7 @@ class DirDisableInputText {
7
8
  }
8
9
 
9
10
  execute(directive, pipeline, callback) {
10
- // console.log("disable input text...pipeline");
11
+ winston.verbose("Execute DisableInputText directive");
11
12
  let message = pipeline.message
12
13
  if (!message.attributes) {
13
14
  message.attributes = {}
@@ -15,10 +16,8 @@ class DirDisableInputText {
15
16
  message.attributes.disableInputMessage = true;
16
17
  if (directive.parameter) {
17
18
  const options = this.parseParams(directive.parameter);
18
- // console.log("Options", options)
19
19
  directive.options = options;
20
20
  if (options.label) {
21
- // console.log("options.label", options.label)
22
21
  message.attributes.inputMessagePlaceholder = options.label;
23
22
  }
24
23
  }
@@ -28,13 +27,10 @@ class DirDisableInputText {
28
27
  parseParams(directive_parameter) {
29
28
  let label = null;
30
29
  const params = ms(directive_parameter);
31
- // console.log("params:", params);
32
30
  if (params.l) {
33
- // console.log("_param l", params.l);
34
31
  label = params.l;
35
32
  }
36
33
  if (params.label) {
37
- // console.log("_param label", params.label);
38
34
  label = params.label;
39
35
  }
40
36
  return {
@@ -1,5 +1,6 @@
1
1
  const { TiledeskClient } = require('@tiledesk/tiledesk-client');
2
2
  const ms = require('minimist-string');
3
+ const winston = require('../../utils/winston');
3
4
 
4
5
  class DirFireTiledeskEvent {
5
6
 
@@ -22,6 +23,7 @@ class DirFireTiledeskEvent {
22
23
  }
23
24
 
24
25
  execute(directive, callback) {
26
+ winston.verbose("Execute FireTiledeskEvent directive");
25
27
  if (directive.parameter) {
26
28
  const params = this.parseParams(directive.parameter);
27
29
  const event_name = params.name;
@@ -31,15 +33,13 @@ class DirFireTiledeskEvent {
31
33
  }
32
34
  this.tdClient.fireEvent(event, function(err, result) {
33
35
  if (err) {
34
- console.error("An error occurred invoking an event:", err);
36
+ winston.error("(FireTiledeskEvent) An error occurred invoking an event: ", err);
35
37
  }
36
38
  callback();
37
39
  });
38
40
  }
39
41
  else {
40
- if (this.log) {
41
- console.log("DirFireTiledeskEvent: no parameter");
42
- }
42
+ winston.verbose("(DirFireTiledeskEvent) no parameter");
43
43
  callback();
44
44
  }
45
45
  }
@@ -1,8 +1,9 @@
1
1
  const { Filler } = require('../Filler');
2
- const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
2
+ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
3
3
  const { DirIntent } = require('./DirIntent');
4
- const { IntentForm } = require('../../models/IntentForm.js');
4
+ const { IntentForm } = require('../../engine/IntentForm.js');
5
5
  const { TiledeskClient } = require('@tiledesk/tiledesk-client');
6
+ const winston = require('../../utils/winston');
6
7
 
7
8
  class DirForm {
8
9
  constructor(context) {
@@ -28,17 +29,17 @@ class DirForm {
28
29
  }
29
30
 
30
31
  execute(directive, callback) {
32
+ winston.verbose("Execute Form directive");
31
33
  let action;
32
34
  if (directive.action) {
33
35
  action = directive.action;
34
36
  }
35
37
  else {
36
- console.error("Incorrect directive:", JSON.stringify(directive));
38
+ winston.warn("DirForm Incorrect directive: ", directive);
37
39
  callback();
38
40
  return;
39
41
  }
40
42
  this.go(action, (stop) => {
41
- if (this.log) {console.log("(DirForm, stop?", stop); }
42
43
  callback(stop);
43
44
  });
44
45
  }
@@ -72,18 +73,15 @@ class DirForm {
72
73
  const trueIntent = action.trueIntent; // edit-end (success)
73
74
  const falseIntent = action.falseIntent; // cancel
74
75
  let form = action.form;
75
- if (this.log) {
76
- console.log("IntentForm.isValidForm(intent_form)", IntentForm.isValidForm(form));
77
- }
76
+ winston.debug("(DirForm) IntentForm.isValidForm(intent_form) " + IntentForm.isValidForm(form));
77
+
78
78
  let clientUpdateUserFullname = null;
79
79
  if (IntentForm.isValidForm(form)) {
80
80
  await this.chatbot.lockAction(this.requestId, action.action_id);
81
81
  const user_reply = message.text;
82
82
  let form_reply = await this.execIntentForm(user_reply, form);
83
- // console.log("got form reply", form_reply)
84
83
  if (!form_reply.canceled && form_reply.message) {
85
- // console.log("Form replying for next field...");
86
- if (this.log) {console.log("Sending form reply...", form_reply.message)}
84
+ winston.debug("(DirForm) Sending form reply...", form_reply.message)
87
85
  // reply with this message (ex. please enter your fullname)
88
86
  if (!form_reply.message.attributes) {
89
87
  form_reply.message.attributes = {}
@@ -98,18 +96,17 @@ class DirForm {
98
96
  form_reply.message,
99
97
  (err) => {
100
98
  if (err) {
101
- console.error("Error sending form reply:", err.message);
99
+ winston.error("(DirForm) Error sending form reply: " + err.message);
102
100
  }
103
- if (this.log) {console.log("Form reply message sent.");}
101
+ winston.debug("(DirForm) Form reply message sent.");
104
102
  callback(true);
105
103
  });
106
104
  }
107
105
  else if (form_reply.end) {
108
- if (this.log) {
109
- console.log("FORM end.", );
110
- console.log("unlocking intent for request:", this.requestId);
111
- console.log("populate data on lead:", JSON.stringify(lead));
112
- }
106
+ winston.debug("(DirForm) FORM end.", );
107
+ winston.debug("(DirForm) unlocking intent for request: " + this.requestId);
108
+ winston.debug("(DirForm) populate data on lead: ", lead);
109
+
113
110
  this.chatbot.unlockAction(this.requestId);
114
111
 
115
112
  if (callback) {
@@ -121,16 +118,13 @@ class DirForm {
121
118
  // if (lead) {
122
119
  // this.populatePrechatFormAndLead(lead._id, this.requestId);
123
120
  // }
124
- // else {
125
- // if (this.log) {console.log("No lead. Skipping populatePrechatFormAndLead()");}
126
- // }
127
121
  // const all_parameters = await this.chatbot.allParameters();
128
122
  // if (all_parameters && all_parameters["userFullname"]) {
129
123
  // clientUpdateUserFullname = all_parameters["userFullname"];
130
124
  // }
131
125
  }
132
126
  else if (form_reply.canceled) {
133
- if (this.log) {console.log("unlocking intent due to canceling, for request", this.requestId);}
127
+ winston.debug("(DirForm) unlocking intent due to canceling, for request " + this.requestId);
134
128
  this.unlockAction(this.requestId);
135
129
 
136
130
  // TODO: INVOKE DIR_INTENT FOR CANCEL.
@@ -140,7 +134,6 @@ class DirForm {
140
134
  });
141
135
  }
142
136
 
143
- // if (this.log) {console.log("sending form 'cancel' reply...", form_reply.message)}
144
137
  // TODO: REMOVE CANCEL REPLY
145
138
  // reply with this message (ex. please enter your fullname)
146
139
  // if (!form_reply.message.attributes) {
@@ -174,7 +167,7 @@ class DirForm {
174
167
  });
175
168
  }
176
169
  else {
177
- if (this.log) {console.log("No trueIntentDirective specified");}
170
+ winston.debug("(DirForm) No trueIntentDirective specified");
178
171
  callback();
179
172
  }
180
173
  }
@@ -185,7 +178,7 @@ class DirForm {
185
178
  });
186
179
  }
187
180
  else {
188
- if (this.log) {console.log("No falseIntentDirective specified");}
181
+ winston.debug("(DirForm) No falseIntentDirective specified");
189
182
  callback();
190
183
  }
191
184
  }