@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,8 +1,10 @@
1
1
  const { Filler } = require('../Filler');
2
- const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
3
- const { TiledeskChatbotUtil } = require('../../models/TiledeskChatbotUtil');
2
+ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
3
+ const { TiledeskChatbotUtil } = require('../../utils/TiledeskChatbotUtil');
4
4
  let axios = require('axios');
5
5
  const { TiledeskClient } = require('@tiledesk/tiledesk-client');
6
+ const { Logger } = require('../../Logger');
7
+ const winston = require('../../utils/winston')
6
8
 
7
9
  class DirReply {
8
10
 
@@ -16,6 +18,8 @@ class DirReply {
16
18
  this.token = context.token;
17
19
  this.tdcache = context.tdcache;
18
20
  this.log = context.log;
21
+ console.log("is draft request: ", this.context.supportRequest.draft);
22
+ this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest.draft });
19
23
 
20
24
  this.API_ENDPOINT = context.API_ENDPOINT;
21
25
  this.tdClient = new TiledeskClient({
@@ -37,17 +41,21 @@ class DirReply {
37
41
  action.attributes.fillParams = true;
38
42
  }
39
43
  else {
40
- console.error("Incorrect directive (no action provided):", directive);
44
+ winston.error("DirReply Incorrect directive (no action provided):", directive);
41
45
  callback();
42
46
  return;
43
47
  }
48
+ this.logger.info("1 Execute action reply for " + directive.action.text)
49
+
44
50
  this.go(action, () => {
51
+ this.logger.info("6 End of action reply " + directive.action.text + " -> callback")
45
52
  callback();
46
53
  });
47
54
  }
48
55
 
49
56
  async go(action, callback) {
50
57
  const message = action;
58
+
51
59
  // fill
52
60
  let requestAttributes = null;
53
61
  if (this.tdcache) {
@@ -55,17 +63,16 @@ class DirReply {
55
63
  await TiledeskChatbot.allParametersStatic(
56
64
  this.tdcache, this.requestId
57
65
  );
58
- if (this.log) {
59
- for (const [key, value] of Object.entries(requestAttributes)) {
60
- const value_type = typeof value;
61
- // if (this.log) {console.log("(DirReply) request parameter:", key, "value:", value, "type:", value_type)}
62
- }
63
- }
66
+
67
+ TiledeskChatbotUtil.replaceJSONButtons(message, requestAttributes);
68
+
64
69
  const filler = new Filler();
65
70
  // fill text attribute
66
71
  message.text = filler.fill(message.text, requestAttributes);
72
+ this.logger.info("2 Sending reply " + message.text);
73
+
67
74
  if (message.metadata) {
68
- if (this.log) {console.log("filling message 'metadata':", JSON.stringify(message.metadata));}
75
+ winston.debug("DirReply filling message 'metadata':", message.metadata);
69
76
  if (message.metadata.src) {
70
77
  message.metadata.src = filler.fill(message.metadata.src, requestAttributes);
71
78
  }
@@ -73,24 +80,23 @@ class DirReply {
73
80
  message.metadata.name = filler.fill(message.metadata.name, requestAttributes);
74
81
  }
75
82
  }
76
- if (this.log) {console.log("filling commands'. Message:", JSON.stringify(message));}
83
+ winston.debug("DirReply filling commands'. Message:", message);
77
84
  if (message.attributes && message.attributes.commands) {
78
- if (this.log) {console.log("filling commands'. commands found.");}
79
85
  let commands = message.attributes.commands;
80
- if (this.log) {console.log("commands:", JSON.stringify(commands), commands.length);}
86
+ winston.debug("DirReply commands: " + JSON.stringify(commands) + " length: " + commands.length);
87
+
81
88
  if (commands.length > 0) {
82
- if (this.log) {console.log("commands' found");}
83
89
  for (let i = 0; i < commands.length; i++) {
84
90
  let command = commands[i];
85
91
  if (command.type === 'message' && command.message && command.message.text) {
86
92
  command.message.text = filler.fill(command.message.text, requestAttributes);
87
93
  TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes, this.log);
88
- if (this.log) {console.log("command filled:", command.message.text);}
94
+ winston.debug("DirReply command filled: " + command.message.text);
89
95
  }
90
96
  if (command.type === 'settings' && command.settings) {
91
97
  Object.keys(command.settings).forEach(k => {
92
98
  command.settings[k] = filler.fill(command.settings[k], requestAttributes)
93
- if (this.log) {console.log("settings command filled:", command.settings[k]);}
99
+ winston.debug("DirReply settings command filled: " + command.settings[k]);
94
100
  })
95
101
  }
96
102
  }
@@ -98,11 +104,10 @@ class DirReply {
98
104
  }
99
105
 
100
106
  // EVALUATE EXPRESSION AND REMOVE BASED ON EVALUATION
101
- if (this.log) {console.log("message before filters:", JSON.stringify(message));}
107
+ winston.debug("DirReply message before filters: ", message);
102
108
  if (message.attributes && message.attributes.commands) {
103
- if (this.log) {console.log("filterOnVariables...on commands", JSON.stringify(message.attributes.commands));}
104
- if (this.log) {console.log("filterOnVariables...on attributes", requestAttributes);}
105
- // TiledeskChatbotUtil.filterOnVariables(message.attributes.commands, requestAttributes);
109
+ winston.debug("DirReply filterOnVariables...on commands", message.attributes.commands)
110
+ winston.debug("DirReply filterOnVariables...on attributes", requestAttributes);
106
111
  TiledeskChatbotUtil.filterOnVariables(message, requestAttributes);
107
112
  }
108
113
  // temporary send back of reserved attributes
@@ -122,7 +127,7 @@ class DirReply {
122
127
  }
123
128
  // userFlowAttributes
124
129
  let userFlowAttributes = TiledeskChatbotUtil.userFlowAttributes(requestAttributes);
125
- if (this.log) { console.log("userFlowAttributes:", userFlowAttributes); }
130
+ winston.debug("DirReply userFlowAttributes:", userFlowAttributes);
126
131
  if (userFlowAttributes) {
127
132
  message.attributes["flowAttributes"] = {};
128
133
  for (const [key, value] of Object.entries(userFlowAttributes)) {
@@ -132,13 +137,15 @@ class DirReply {
132
137
  }
133
138
  }
134
139
  catch(err) {
135
- console.error("An error occurred while JSON.parse(). Parsed value:" + value + " in allParametersStatic(). Error:", err);
140
+ winston.error("DirReply An error occurred while JSON.parse(). Parsed value:" + value + " in allParametersStatic(). Error:", err);
136
141
  }
137
142
  }
138
143
  }
139
144
  }
140
- // send!
145
+
141
146
  let cleanMessage = message;
147
+ this.logger.info("3 Sending reply (text) " + cleanMessage.text);
148
+ this.logger.info("4 Sending reply with clean message " + JSON.stringify(cleanMessage));
142
149
  // cleanMessage = TiledeskChatbotUtil.removeEmptyReplyCommands(message);
143
150
  // if (!TiledeskChatbotUtil.isValidReply(cleanMessage)) {
144
151
  // console.log("invalid message", cleanMessage);
@@ -147,27 +154,26 @@ class DirReply {
147
154
  // }
148
155
 
149
156
  cleanMessage.senderFullname = this.context.chatbot.bot.name;
150
- if (this.log) {console.log("Reply:", JSON.stringify(cleanMessage))};
157
+ winston.debug("DirReply reply with clean message: ", cleanMessage);
158
+
151
159
  await TiledeskChatbotUtil.updateConversationTranscript(this.context.chatbot, cleanMessage);
152
- // console.log("sending message!", cleanMessage);
153
160
  this.tdClient.sendSupportMessage(
154
161
  this.requestId,
155
162
  cleanMessage,
156
163
  (err) => {
157
164
  if (err) {
158
- console.error("Error sending reply:", err);
165
+ winston.error("DirReply Error sending reply: ", err);
166
+ this.logger.error("Error sending reply: " + err);
159
167
  }
160
- if (this.log) {console.log("Reply message sent:", JSON.stringify(cleanMessage));}
168
+ winston.verbose("DirReply reply message sent")
169
+ this.logger.info("5 Reply message sent");
161
170
  const delay = TiledeskChatbotUtil.totalMessageWait(cleanMessage);
162
- // console.log("got total delay:", delay)
163
171
  if (delay > 0 && delay <= 30000) { // prevent long delays
164
172
  setTimeout(() => {
165
- // console.log("callback after delay")
166
173
  callback();
167
174
  }, delay);
168
175
  }
169
176
  else {
170
- // console.log("invalid delay.")
171
177
  callback();
172
178
  }
173
179
  });
@@ -1,12 +1,13 @@
1
1
  const { Filler } = require('../Filler');
2
- const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
3
- const { TiledeskChatbotConst } = require('../../models/TiledeskChatbotConst');
4
- const { TiledeskChatbotUtil } = require('../../models/TiledeskChatbotUtil');
2
+ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
3
+ const { TiledeskChatbotConst } = require('../../engine/TiledeskChatbotConst');
4
+ const { TiledeskChatbotUtil } = require('../../utils/TiledeskChatbotUtil');
5
5
  const { DirIntent } = require("./DirIntent");
6
6
  // const { defaultOptions } = require('liquidjs');
7
7
  const { DirMessageToBot } = require('./DirMessageToBot');
8
8
  const { v4: uuidv4 } = require('uuid');
9
9
  const { TiledeskClient } = require('@tiledesk/tiledesk-client');
10
+ const winston = require('../../utils/winston');
10
11
 
11
12
  class DirReplyV2 {
12
13
 
@@ -36,6 +37,7 @@ class DirReplyV2 {
36
37
  }
37
38
 
38
39
  execute(directive, callback) {
40
+ winston.verbose("Execute ReplyV2 directive");
39
41
  let action;
40
42
  if (directive.action) {
41
43
  action = directive.action;
@@ -45,7 +47,7 @@ class DirReplyV2 {
45
47
  action.attributes.fillParams = true;
46
48
  }
47
49
  else {
48
- console.error("Incorrect directive (no action provided):", directive);
50
+ winston.warn("DirReplyV2 Incorrect directive: ", directive);
49
51
  callback();
50
52
  return;
51
53
  }
@@ -55,7 +57,7 @@ class DirReplyV2 {
55
57
  }
56
58
 
57
59
  async go(action, callback) {
58
- if (this.log) { console.log("ReplyV2 action!", JSON.stringify(action)); }
60
+ winston.debug("(DirReplyV2) Action: ", action);
59
61
  const message = action;
60
62
 
61
63
  let current; // debug only
@@ -63,7 +65,6 @@ class DirReplyV2 {
63
65
  if (message.attributes.commands[1].message.text) {
64
66
  current = message.attributes.commands[1].message.text
65
67
  }
66
- console.log("current:", current);
67
68
  }
68
69
  let must_stop = false;
69
70
  // fill
@@ -79,114 +80,93 @@ class DirReplyV2 {
79
80
  }
80
81
  }
81
82
 
83
+ TiledeskChatbotUtil.replaceJSONButtons(message, requestAttributes);
84
+
82
85
  try {
83
86
  // lock/unlock + no-match
84
87
  // get buttons if available
85
88
  const buttons = TiledeskChatbotUtil.allReplyButtons(message);
86
- if (this.log) { console.log("Action Buttons:", JSON.stringify(buttons)); }
87
89
  if (buttons && buttons.length > 0) {
88
90
  const locked = await this.lockUnlock(action); // first execution returns locked, then unlocked
89
91
  if (locked) { // fist execution returns (just) locked
90
- if (this.log) { console.log("first time pass!"); }
91
92
  must_stop = true; // you must stop after next callbacks (in this flow) if there are buttons
92
- // console.log("action:", action);
93
93
  if (action.noInputIntent) {
94
- if (this.log) { console.log("NoInputIntent found:", action.noInputIntent); }
95
94
  const noInputIntent = action.noInputIntent;
96
95
  const noInputTimeout = action.noInputTimeout;
97
- if (this.log) { console.log("noInputTimeout found:", noInputTimeout); }
98
96
  if (noInputTimeout > 0 && noInputTimeout < 7776000) {
99
97
  const timeout_id = uuidv4();
100
98
  await this.chatbot.addParameter(TiledeskChatbotConst.USER_INPUT, timeout_id); // control variable. On each user input is removed
101
- if (this.log) { console.log("Set userInput: false, checking...", await this.chatbot.getParameter(TiledeskChatbotConst.USER_INPUT)); }
102
99
  setTimeout(async () => {
103
- if (this.log) { console.log("noinput timeout triggered!"); }
100
+ winston.debug("(DirReplyV2) noinput timeout triggered!");
104
101
  const userInput = await this.chatbot.getParameter(TiledeskChatbotConst.USER_INPUT);
105
- if (this.log) { console.log("got 'userInput':", userInput); }
106
102
  if (userInput && userInput === timeout_id) {
107
- if (this.log) { console.log("no 'userInput'. Executing noinput action:", noInputIntent); }
108
103
  await this.chatbot.unlockIntent(this.requestId);
109
104
  await this.chatbot.unlockAction(this.requestId);
110
- if (this.log) { console.log("unlocked (for noInput) ReplyV2"); }
105
+ winston.debug("(DirReplyV2) Unlocked (for noInput) ReplyV2");
111
106
  let noinput_action = DirIntent.intentDirectiveFor(noInputIntent, null);
112
107
  this.intentDir.execute(noinput_action, () => {
113
- if (this.log) { console.log("noinput action invoked", noinput_action); }
108
+ winston.debug("(DirReplyV2) noinput action invoked", noinput_action);
114
109
  });
115
110
  }
116
111
  else {
117
- if (this.log) { console.log("skipping noinput action because of userInput", userInput); }
112
+ winston.debug("(DirReplyV2) Skipping noinput action because of userInput", userInput);
118
113
  }
119
114
  }, noInputTimeout);
120
115
  }
121
116
  }
122
117
  }
123
118
  else { // second execution
124
- if (this.log) { console.log("second pass! unlocked!"); }
119
+
125
120
  const last_user_text = await this.chatbot.getParameter(TiledeskChatbotConst.REQ_LAST_USER_TEXT_v2_KEY);
126
- if (this.log) { console.log("got last user text"); }
127
121
  const button = TiledeskChatbotUtil.buttonByText(last_user_text, buttons);
128
- if (this.log) { console.log("button found", JSON.stringify(button)); }
122
+
129
123
  // invoke button
130
124
  if (button && button.action) {
131
- if (this.log) { console.log("moving to button action", button.action); }
132
125
  let button_action = DirIntent.intentDirectiveFor(button.action, null);
133
- if (this.log) { console.log("action with .intentName:", button_action); }
134
126
  this.intentDir.execute(button_action, () => {
135
- if (this.log) { console.log("action invoked", button_action); }
127
+ winston.debug("(DirReplyV2) action invoked", button_action);
136
128
  });
137
- if (this.log) { console.log("callback(true) + return", current); }
138
129
  callback(true); // must_stop = true
139
130
  return;
140
131
  }
141
132
  else { // no match (treating text buttons as no-match for the moment)
142
133
  // if noMatchIntent invoke
143
134
  // const button = TiledeskChatbotUtil.buttonByText("nomatch", buttons);
144
- if (this.log) { console.log("nomatch button found", JSON.stringify(button)); }
135
+ winston.debug("(DirReplyV2) nomatch button found ", button);
145
136
  // // invoke button
146
137
  // if (button && button.action) {
147
- // console.log("moving to nomatch action", button.action);
148
138
  // let button_action = DirIntent.intentDirectiveFor(button.action, null);
149
139
  // this.intentDir.execute(button_action, () => {
150
- // console.log("nomatch action invoked", button_action);
151
140
  // });
152
- // console.log("callback(true) + return 2", current);
153
141
  // callback(true);
154
142
  // return;
155
143
  // }
156
144
  if (action.noMatchIntent) {
157
- if (this.log) { console.log("moving to nomatch action", action.noMatchIntent); }
158
145
  let nomatch_action = DirIntent.intentDirectiveFor(action.noMatchIntent, null);
159
146
  this.intentDir.execute(nomatch_action, () => {
160
- if (this.log) { console.log("nomatch action invoked", nomatch_action); }
147
+ winston.debug("(DirReplyV2) nomatch action invoked", nomatch_action);
161
148
  });
162
- if (this.log) { console.log("callback(true) + return no-match", current); }
163
149
  callback(true); // must_stop = true
164
150
  return;
165
151
  }
166
152
  else {
167
153
  // const defaultFallbackAction = { action: { intentName: "defaultFallback" } };
168
154
 
169
- // console.log("re-send original message:",JSON.stringify(this.originalMessage));
170
155
  const messageDir = new DirMessageToBot(this.context);
171
156
  messageDir.execute( { action: { message: this.originalMessage } }, () => {
172
- if (this.log) { console.log("messageDir invoked"); }
157
+ winston.debug("(DirReplyV2) messageDir invoked");
173
158
  });
174
- if (this.log) { console.log("callback(true) + return no-match", current); }
175
159
  callback(true); // must_stop = true
176
160
  return;
177
161
 
178
162
  // const textAction = { action: { text: last_user_text } };
179
- // console.log("textAction invoked:",textAction ); //, defaultFallbackAction);
180
163
  // this.intentDir.execute( textAction, () => {
181
- // if (this.log) { console.log("textAction invoked", textAction); }
182
164
  // });
183
- // if (this.log) { console.log("callback(true) + return no-match", current); }
184
165
  // callback(true); // must_stop = true
185
166
  // return;
186
167
 
187
168
 
188
169
  // // there is no "no-match", go on...
189
- // if (this.log) { console.log("callback(false) + return 3", current); }
190
170
  // callback(false);
191
171
  // return;
192
172
  }
@@ -195,16 +175,14 @@ class DirReplyV2 {
195
175
  }
196
176
  }
197
177
  catch(error) {
198
- console.error("Error in DirReplyV2:", error);
178
+ winston.error("(DirReplyV2) Error: ", error);
199
179
  }
200
180
 
201
-
202
- if (this.log) { console.log("proceding normally to render and send the reply", current); }
203
181
  const filler = new Filler();
182
+
204
183
  // fill text attribute
205
184
  message.text = filler.fill(message.text, requestAttributes);
206
185
  if (message.metadata) {
207
- if (this.log) {console.log("filling message 'metadata':", JSON.stringify(message.metadata));}
208
186
  if (message.metadata.src) {
209
187
  message.metadata.src = filler.fill(message.metadata.src, requestAttributes);
210
188
  }
@@ -212,29 +190,22 @@ class DirReplyV2 {
212
190
  message.metadata.name = filler.fill(message.metadata.name, requestAttributes);
213
191
  }
214
192
  }
215
- if (this.log) {console.log("filling commands'. Message:", JSON.stringify(message));}
216
193
  if (message.attributes && message.attributes.commands) {
217
- if (this.log) {console.log("filling commands'. commands found.");}
218
194
  let commands = message.attributes.commands;
219
- if (this.log) {console.log("commands:", JSON.stringify(commands), commands.length);}
220
195
  if (commands.length > 0) {
221
- if (this.log) {console.log("commands' found");}
222
196
  for (let i = 0; i < commands.length; i++) {
223
197
  let command = commands[i];
224
198
  if (command.type === 'message' && command.message && command.message.text) {
225
199
  command.message.text = filler.fill(command.message.text, requestAttributes);
226
200
  TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes, this.log);
227
- if (this.log) {console.log("command filled:", command.message.text);}
228
201
  }
229
202
  }
230
203
  }
231
204
  }
232
205
 
233
206
  // EVALUATE EXPRESSION AND REMOVE BASED ON EVALUATION
234
- if (this.log) {console.log("message before filters:", JSON.stringify(message));}
207
+ winston.debug("(DirReplyV2) message before filters:", message);
235
208
  if (message.attributes && message.attributes.commands) {
236
- if (this.log) {console.log("filterOnVariables...on commands", JSON.stringify(message.attributes.commands));}
237
- if (this.log) {console.log("filterOnVariables...on attributes", requestAttributes);}
238
209
  // TiledeskChatbotUtil.filterOnVariables(message.attributes.commands, requestAttributes);
239
210
  TiledeskChatbotUtil.filterOnVariables(message, requestAttributes);
240
211
  }
@@ -256,7 +227,6 @@ class DirReplyV2 {
256
227
  }
257
228
  // userFlowAttributes
258
229
  let userFlowAttributes = TiledeskChatbotUtil.userFlowAttributes(requestAttributes);
259
- if (this.log) { console.log("userFlowAttributes:", userFlowAttributes); }
260
230
  if (userFlowAttributes) {
261
231
  message.attributes["flowAttributes"] = {};
262
232
  for (const [key, value] of Object.entries(userFlowAttributes)) {
@@ -266,7 +236,7 @@ class DirReplyV2 {
266
236
  }
267
237
  }
268
238
  catch(err) {
269
- console.error("An error occurred while JSON.parse(). Parsed value:" + value + " in allParametersStatic(). Error:", err);
239
+ winston.errpr("(DirReplyV2) An error occurred while JSON.parse(). Parsed value: " + value + " in allParametersStatic(). Error: " + JSON.stringify(err));
270
240
  }
271
241
  }
272
242
  }
@@ -276,33 +246,29 @@ class DirReplyV2 {
276
246
  let cleanMessage = message;
277
247
  // cleanMessage = TiledeskChatbotUtil.removeEmptyReplyCommands(message);
278
248
  // if (!TiledeskChatbotUtil.isValidReply(cleanMessage)) {
279
- // console.log("invalid message", cleanMessage);
280
249
  // callback(); // cancel reply operation
281
250
  // return;
282
251
  // }
283
- // console.log("valid message!", cleanMessage);
284
252
  cleanMessage.senderFullname = this.context.chatbot.bot.name;
285
- if (this.log) {console.log("Reply:", JSON.stringify(cleanMessage))};
253
+ winston.debug("(DirReplyV2) Reply: ", cleanMessage);
286
254
  await TiledeskChatbotUtil.updateConversationTranscript(this.context.chatbot, cleanMessage);
287
255
  this.tdClient.sendSupportMessage(
288
256
  this.requestId,
289
257
  cleanMessage,
290
258
  (err) => {
291
259
  if (err) {
292
- console.error("Error sending reply:", err);
260
+ winston.error("(DirReplyV2) Error sending reply: ", err);
293
261
  }
294
- if (this.log) {console.log("Reply message sent");}
262
+ winston.debug("(DirReplyV2) Reply message sent");
295
263
  const delay = TiledeskChatbotUtil.totalMessageWait(cleanMessage);
296
- // console.log("got total delay:", delay)
297
264
  if (delay > 0 && delay <= 30000) { // prevent long delays
298
- if (this.log) { console.log("start timeout callback(" + must_stop + ") for:", current); }
265
+ winston.debug("(DirReplyV2) start timeout callback(" + must_stop + ") for:", current);
299
266
  setTimeout(async () => {
300
- if (this.log) { console.log("callback(" + must_stop + ") after delay", current); }
267
+ winston.debug("(DirReplyV2) callback(" + must_stop + ") after delay", current);
301
268
  callback(must_stop);
302
269
  }, delay);
303
270
  }
304
271
  else {
305
- // console.log("invalid delay.")
306
272
  callback(must_stop);
307
273
  }
308
274
  });
@@ -312,32 +278,24 @@ class DirReplyV2 {
312
278
 
313
279
  async lockUnlock(action, callback) {
314
280
  let lockedAction = await this.chatbot.currentLockedAction(this.requestId);
315
- // console.log("(DirReplyV2) lockedAction:", lockedAction);
281
+
316
282
  if (!lockedAction) {
317
- // console.log("(DirReplyV2) !lockedAction");
318
283
  const intent_name = this.reply.attributes.intent_info.intent_name
319
284
  const actionId = action["_tdActionId"];
320
- // console.log("(DirReplyV2) intent_name:", intent_name);
321
- // console.log("(DirReplyV2) actionId:", actionId);
322
285
  await this.chatbot.lockIntent(this.requestId, intent_name);
323
- // console.log("(DirReplyV2) lockIntent");
324
286
  await this.chatbot.lockAction(this.requestId, actionId);
325
- // console.log("(DirReplyV2) lockAction");
326
287
  let _lockedAction = await this.chatbot.currentLockedAction(this.requestId);
327
288
  let _lockedIntent = await this.chatbot.currentLockedIntent(this.requestId);
328
- // console.log("(DirReplyV2) _lockedAction", _lockedAction);
329
- // console.log("(DirReplyV2) _lockedIntent", _lockedIntent);
330
289
  // callback();
331
290
  return true;
332
291
  } else {
333
292
  try {
334
293
  await this.chatbot.unlockIntent(this.requestId);
335
294
  await this.chatbot.unlockAction(this.requestId);
336
- // console.log("unlocked ReplyV2");
337
295
  return false;
338
296
  }
339
297
  catch(e) {
340
- console.error("Error", e);
298
+ winston.error("(DirReplyV2) Error", e);
341
299
  }
342
300
  }
343
301
  }
@@ -1,6 +1,6 @@
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
5
  const { TiledeskClient } = require('@tiledesk/tiledesk-client');
6
6
  // const { TiledeskClient } = require('@tiledesk/tiledesk-client');
@@ -27,6 +27,7 @@ class DirSendEmail {
27
27
  }
28
28
 
29
29
  execute(directive, callback) {
30
+ winston.verbose("Execute SendEmail directive");
30
31
  let action;
31
32
  if (directive.action) {
32
33
  action = directive.action;
@@ -40,7 +41,7 @@ class DirSendEmail {
40
41
  }
41
42
  }
42
43
  else {
43
- console.error("Incorrect directive:", JSON.stringify(directive));
44
+ winston.warn("DirSendEmail Incorrect directive: ", directive);
44
45
  callback();
45
46
  return;
46
47
  }
@@ -50,8 +51,7 @@ class DirSendEmail {
50
51
  }
51
52
 
52
53
  async go(action, completion) {
53
- // let params = action.body;
54
- if (this.log) {console.log("email action:", JSON.stringify(action));}
54
+ winston.debug("(DirSendEmail) Action: ", action);
55
55
  if (action.subject && action.text && action.to) {
56
56
  try {
57
57
  let requestVariables = null;
@@ -72,19 +72,18 @@ class DirSendEmail {
72
72
  to: filled_to,
73
73
  replyto: reply_to
74
74
  }
75
- // console.log("email message:", JSON.stringify(message));
76
75
  const message_echo = await this.tdClient.sendEmail(message);
77
- if (this.log) {console.log("email sent. filled_subject:", filled_subject);}
78
- if (this.log) {console.log("email sent. filled_text:", filled_text);}
79
- if (this.log) {console.log("email sent. filled_to:", filled_to);}
80
- if (this.log) {console.log("email sent. reply_to:", reply_to);}
76
+ winston.debug("(DirSendEmail) filled_subject: " + filled_subject);
77
+ winston.debug("(DirSendEmail) filled_text: " + filled_text);
78
+ winston.debug("(DirSendEmail) filled_to: " + filled_to);
79
+ winston.debug("(DirSendEmail) reply_to: " + reply_to);
81
80
  if (completion) {
82
81
  completion(null, message_echo);
83
82
  }
84
83
  return message_echo;
85
84
  }
86
85
  catch(err) {
87
- console.error("sendEmail error:", err);
86
+ winston.error("(DirSendEmail) sendEmail error: ", err);
88
87
  if (completion) {
89
88
  completion(err);
90
89
  }