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

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 (83) hide show
  1. package/ExtApi.js +3 -13
  2. package/ExtUtil.js +0 -1
  3. package/TdCache.js +5 -3
  4. package/TiledeskClientTest.js +5 -28
  5. package/TiledeskExpression.js +6 -47
  6. package/index.js +87 -273
  7. package/logs/app.log +12983 -275
  8. package/logs/app1.log +62258 -0
  9. package/logs/app2.log +46280 -0
  10. package/logs/app3.log +28864 -0
  11. package/models/IntentForm.js +30 -44
  12. package/models/IntentsMachineFactory.js +4 -3
  13. package/models/MockBotsDataSource.js +1 -17
  14. package/models/MockTdCache.js +0 -9
  15. package/models/MongodbBotsDataSource.js +29 -53
  16. package/models/MongodbIntentsMachine.js +5 -4
  17. package/models/TiledeskChatbot.js +79 -258
  18. package/models/TiledeskChatbotConst.js +9 -0
  19. package/models/TiledeskChatbotUtil.js +79 -230
  20. package/models/TiledeskIntentsMachine.js +5 -14
  21. package/models/faqKbService.js +0 -1
  22. package/package.json +4 -2
  23. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +54 -140
  24. package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +7 -13
  25. package/tiledeskChatbotPlugs/Filler.js +0 -1
  26. package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +12 -20
  27. package/tiledeskChatbotPlugs/MessagePipeline.js +5 -15
  28. package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +4 -13
  29. package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +21 -89
  30. package/tiledeskChatbotPlugs/directives/DirAddTags.js +15 -98
  31. package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +3 -3
  32. package/tiledeskChatbotPlugs/directives/DirAskGPT.js +32 -57
  33. package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +46 -70
  34. package/tiledeskChatbotPlugs/directives/DirAssign.js +11 -22
  35. package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +15 -11
  36. package/tiledeskChatbotPlugs/directives/DirAssistant.js +48 -97
  37. package/tiledeskChatbotPlugs/directives/DirBrevo.js +37 -68
  38. package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +8 -18
  39. package/tiledeskChatbotPlugs/directives/DirClose.js +3 -1
  40. package/tiledeskChatbotPlugs/directives/DirCode.js +15 -22
  41. package/tiledeskChatbotPlugs/directives/DirCondition.js +18 -24
  42. package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +9 -13
  43. package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +7 -19
  44. package/tiledeskChatbotPlugs/directives/DirCustomerio.js +30 -57
  45. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +15 -20
  46. package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +7 -7
  47. package/tiledeskChatbotPlugs/directives/DirDepartment.js +13 -12
  48. package/tiledeskChatbotPlugs/directives/DirDisableInputText.js +2 -6
  49. package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +4 -4
  50. package/tiledeskChatbotPlugs/directives/DirForm.js +15 -22
  51. package/tiledeskChatbotPlugs/directives/DirGptTask.js +38 -65
  52. package/tiledeskChatbotPlugs/directives/DirHubspot.js +27 -58
  53. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +19 -26
  54. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +22 -40
  55. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +17 -32
  56. package/tiledeskChatbotPlugs/directives/DirIntent.js +10 -28
  57. package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +14 -13
  58. package/tiledeskChatbotPlugs/directives/DirLockIntent.js +7 -12
  59. package/tiledeskChatbotPlugs/directives/DirMake.js +20 -52
  60. package/tiledeskChatbotPlugs/directives/DirMessage.js +35 -28
  61. package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +10 -20
  62. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +4 -2
  63. package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +4 -2
  64. package/tiledeskChatbotPlugs/directives/DirQapla.js +21 -50
  65. package/tiledeskChatbotPlugs/directives/DirRandomReply.js +9 -17
  66. package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +4 -0
  67. package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +4 -1
  68. package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +10 -21
  69. package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +9 -19
  70. package/tiledeskChatbotPlugs/directives/DirReply.js +18 -34
  71. package/tiledeskChatbotPlugs/directives/DirReplyV2.js +25 -69
  72. package/tiledeskChatbotPlugs/directives/DirSendEmail.js +8 -9
  73. package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +13 -12
  74. package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +7 -4
  75. package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +22 -75
  76. package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +14 -13
  77. package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +3 -3
  78. package/tiledeskChatbotPlugs/directives/DirWait.js +4 -5
  79. package/tiledeskChatbotPlugs/directives/DirWebRequest.js +13 -48
  80. package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +11 -76
  81. package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +11 -14
  82. package/tiledeskChatbotPlugs/directives/Directives.js +0 -3
  83. package/utils/winston.js +42 -0
@@ -3,6 +3,7 @@ const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
3
3
  const { TiledeskChatbotUtil } = require('../../models/TiledeskChatbotUtil');
4
4
  let axios = require('axios');
5
5
  const { TiledeskClient } = require('@tiledesk/tiledesk-client');
6
+ const winston = require('../../utils/winston');
6
7
  const { Logger } = require('../../Logger');
7
8
 
8
9
  class DirReply {
@@ -40,8 +41,7 @@ class DirReply {
40
41
  action.attributes.fillParams = true;
41
42
  }
42
43
  else {
43
- console.error("Incorrect directive (no action provided):", directive);
44
- this.logger.error("Incorrect directive (no action provided):", directive);
44
+ winston.error("DirReply Incorrect directive (no action provided):", directive);
45
45
  callback();
46
46
  return;
47
47
  }
@@ -71,7 +71,7 @@ class DirReply {
71
71
  message.text = filler.fill(message.text, requestAttributes);
72
72
 
73
73
  if (message.metadata) {
74
- if (this.log) {console.log("filling message 'metadata':", JSON.stringify(message.metadata));}
74
+ winston.debug("DirReply filling message 'metadata':", message.metadata);
75
75
  if (message.metadata.src) {
76
76
  message.metadata.src = filler.fill(message.metadata.src, requestAttributes);
77
77
  this.logger.debug("Filled metadata.src with ", message.metadata.src);
@@ -81,25 +81,24 @@ class DirReply {
81
81
  this.logger.debug("Filled metadata.name with ", message.metadata.name);
82
82
  }
83
83
  }
84
- if (this.log) {console.log("filling commands'. Message:", JSON.stringify(message));}
84
+ winston.debug("DirReply filling commands'. Message:", message);
85
85
  if (message.attributes && message.attributes.commands) {
86
- if (this.log) {console.log("filling commands'. commands found.");}
87
86
  let commands = message.attributes.commands;
88
- if (this.log) {console.log("commands:", JSON.stringify(commands), commands.length);}
87
+ winston.debug("DirReply commands: " + JSON.stringify(commands) + " length: " + commands.length);
88
+
89
89
  if (commands.length > 0) {
90
- if (this.log) {console.log("commands' found");}
91
90
  for (let i = 0; i < commands.length; i++) {
92
91
  let command = commands[i];
93
92
  if (command.type === 'message' && command.message && command.message.text) {
94
93
  command.message.text = filler.fill(command.message.text, requestAttributes);
95
94
  this.logger.debug("Filled message.text with ", command.message.text)
96
95
  TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes, this.log);
97
- if (this.log) {console.log("command filled:", command.message.text);}
96
+ winston.debug("DirReply command filled: " + command.message.text);
98
97
  }
99
98
  if (command.type === 'settings' && command.settings) {
100
99
  Object.keys(command.settings).forEach(k => {
101
100
  command.settings[k] = filler.fill(command.settings[k], requestAttributes)
102
- if (this.log) {console.log("settings command filled:", command.settings[k]);}
101
+ winston.debug("DirReply settings command filled: " + command.settings[k]);
103
102
  })
104
103
  }
105
104
  }
@@ -107,11 +106,10 @@ class DirReply {
107
106
  }
108
107
 
109
108
  // EVALUATE EXPRESSION AND REMOVE BASED ON EVALUATION
110
- if (this.log) {console.log("message before filters:", JSON.stringify(message));}
109
+ winston.debug("DirReply message before filters: ", message);
111
110
  if (message.attributes && message.attributes.commands) {
112
- if (this.log) {console.log("filterOnVariables...on commands", JSON.stringify(message.attributes.commands));}
113
- if (this.log) {console.log("filterOnVariables...on attributes", requestAttributes);}
114
- // TiledeskChatbotUtil.filterOnVariables(message.attributes.commands, requestAttributes);
111
+ winston.debug("DirReply filterOnVariables...on commands", message.attributes.commands)
112
+ winston.debug("DirReply filterOnVariables...on attributes", requestAttributes);
115
113
  TiledeskChatbotUtil.filterOnVariables(message, requestAttributes);
116
114
  }
117
115
  // temporary send back of reserved attributes
@@ -131,7 +129,7 @@ class DirReply {
131
129
  }
132
130
  // userFlowAttributes
133
131
  let userFlowAttributes = TiledeskChatbotUtil.userFlowAttributes(requestAttributes);
134
- if (this.log) { console.log("userFlowAttributes:", userFlowAttributes); }
132
+ winston.debug("DirReply userFlowAttributes:", userFlowAttributes);
135
133
  if (userFlowAttributes) {
136
134
  message.attributes["flowAttributes"] = {};
137
135
  for (const [key, value] of Object.entries(userFlowAttributes)) {
@@ -141,46 +139,32 @@ class DirReply {
141
139
  }
142
140
  }
143
141
  catch(err) {
144
- console.error("An error occurred while JSON.parse(). Parsed value:" + value + " in allParametersStatic(). Error:", err);
145
- this.logger.error("An error occurred while JSON.parse(). Parsed value:" + value + " in allParametersStatic(). Error:", err);
142
+ winston.error("DirReply An error occurred while JSON.parse(). Parsed value:" + value + " in allParametersStatic(). Error:", err);
146
143
  }
147
144
  }
148
145
  }
149
146
  }
150
- // send!
147
+
151
148
  let cleanMessage = message;
152
- this.logger.info("Sending reply with text ", cleanMessage.text);
153
- // cleanMessage = TiledeskChatbotUtil.removeEmptyReplyCommands(message);
154
- // if (!TiledeskChatbotUtil.isValidReply(cleanMessage)) {
155
- // console.log("invalid message", cleanMessage);
156
- // callback(); // cancel reply operation
157
- // return;
158
- // }
159
-
160
149
  cleanMessage.senderFullname = this.context.chatbot.bot.name;
161
- if (this.log) {console.log("Reply:", JSON.stringify(cleanMessage))};
150
+ winston.debug("DirReply reply with clean message: ", cleanMessage);
151
+
162
152
  await TiledeskChatbotUtil.updateConversationTranscript(this.context.chatbot, cleanMessage);
163
- // console.log("sending message!", cleanMessage);
164
153
  this.tdClient.sendSupportMessage(
165
154
  this.requestId,
166
155
  cleanMessage,
167
156
  (err) => {
168
157
  if (err) {
169
- console.error("Error sending reply:", err);
170
- this.logger.error("Error sending reply ", err.response.data);
158
+ winston.error("DirReply Error sending reply: ", err);
171
159
  }
172
- if (this.log) {console.log("Reply message sent:", JSON.stringify(cleanMessage));}
173
- this.logger.info("Reply message sent!", cleanMessage.text);
160
+ winston.verbose("DirReply reply message sent")
174
161
  const delay = TiledeskChatbotUtil.totalMessageWait(cleanMessage);
175
- // console.log("got total delay:", delay)
176
162
  if (delay > 0 && delay <= 30000) { // prevent long delays
177
163
  setTimeout(() => {
178
- // console.log("callback after delay")
179
164
  callback();
180
165
  }, delay);
181
166
  }
182
167
  else {
183
- // console.log("invalid delay.")
184
168
  callback();
185
169
  }
186
170
  });
@@ -7,6 +7,7 @@ const { DirIntent } = require("./DirIntent");
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
@@ -85,110 +86,87 @@ class DirReplyV2 {
85
86
  // lock/unlock + no-match
86
87
  // get buttons if available
87
88
  const buttons = TiledeskChatbotUtil.allReplyButtons(message);
88
- if (this.log) { console.log("Action Buttons:", JSON.stringify(buttons)); }
89
89
  if (buttons && buttons.length > 0) {
90
90
  const locked = await this.lockUnlock(action); // first execution returns locked, then unlocked
91
91
  if (locked) { // fist execution returns (just) locked
92
- if (this.log) { console.log("first time pass!"); }
93
92
  must_stop = true; // you must stop after next callbacks (in this flow) if there are buttons
94
- // console.log("action:", action);
95
93
  if (action.noInputIntent) {
96
- if (this.log) { console.log("NoInputIntent found:", action.noInputIntent); }
97
94
  const noInputIntent = action.noInputIntent;
98
95
  const noInputTimeout = action.noInputTimeout;
99
- if (this.log) { console.log("noInputTimeout found:", noInputTimeout); }
100
96
  if (noInputTimeout > 0 && noInputTimeout < 7776000) {
101
97
  const timeout_id = uuidv4();
102
98
  await this.chatbot.addParameter(TiledeskChatbotConst.USER_INPUT, timeout_id); // control variable. On each user input is removed
103
- if (this.log) { console.log("Set userInput: false, checking...", await this.chatbot.getParameter(TiledeskChatbotConst.USER_INPUT)); }
104
99
  setTimeout(async () => {
105
- if (this.log) { console.log("noinput timeout triggered!"); }
100
+ winston.debug("(DirReplyV2) noinput timeout triggered!");
106
101
  const userInput = await this.chatbot.getParameter(TiledeskChatbotConst.USER_INPUT);
107
- if (this.log) { console.log("got 'userInput':", userInput); }
108
102
  if (userInput && userInput === timeout_id) {
109
- if (this.log) { console.log("no 'userInput'. Executing noinput action:", noInputIntent); }
110
103
  await this.chatbot.unlockIntent(this.requestId);
111
104
  await this.chatbot.unlockAction(this.requestId);
112
- if (this.log) { console.log("unlocked (for noInput) ReplyV2"); }
105
+ winston.debug("(DirReplyV2) Unlocked (for noInput) ReplyV2");
113
106
  let noinput_action = DirIntent.intentDirectiveFor(noInputIntent, null);
114
107
  this.intentDir.execute(noinput_action, () => {
115
- if (this.log) { console.log("noinput action invoked", noinput_action); }
108
+ winston.debug("(DirReplyV2) noinput action invoked", noinput_action);
116
109
  });
117
110
  }
118
111
  else {
119
- if (this.log) { console.log("skipping noinput action because of userInput", userInput); }
112
+ winston.debug("(DirReplyV2) Skipping noinput action because of userInput", userInput);
120
113
  }
121
114
  }, noInputTimeout);
122
115
  }
123
116
  }
124
117
  }
125
118
  else { // second execution
126
- if (this.log) { console.log("second pass! unlocked!"); }
119
+
127
120
  const last_user_text = await this.chatbot.getParameter(TiledeskChatbotConst.REQ_LAST_USER_TEXT_v2_KEY);
128
- if (this.log) { console.log("got last user text"); }
129
121
  const button = TiledeskChatbotUtil.buttonByText(last_user_text, buttons);
130
- if (this.log) { console.log("button found", JSON.stringify(button)); }
122
+
131
123
  // invoke button
132
124
  if (button && button.action) {
133
- if (this.log) { console.log("moving to button action", button.action); }
134
125
  let button_action = DirIntent.intentDirectiveFor(button.action, null);
135
- if (this.log) { console.log("action with .intentName:", button_action); }
136
126
  this.intentDir.execute(button_action, () => {
137
- if (this.log) { console.log("action invoked", button_action); }
127
+ winston.debug("(DirReplyV2) action invoked", button_action);
138
128
  });
139
- if (this.log) { console.log("callback(true) + return", current); }
140
129
  callback(true); // must_stop = true
141
130
  return;
142
131
  }
143
132
  else { // no match (treating text buttons as no-match for the moment)
144
133
  // if noMatchIntent invoke
145
134
  // const button = TiledeskChatbotUtil.buttonByText("nomatch", buttons);
146
- if (this.log) { console.log("nomatch button found", JSON.stringify(button)); }
135
+ winston.debug("(DirReplyV2) nomatch button found ", button);
147
136
  // // invoke button
148
137
  // if (button && button.action) {
149
- // console.log("moving to nomatch action", button.action);
150
138
  // let button_action = DirIntent.intentDirectiveFor(button.action, null);
151
139
  // this.intentDir.execute(button_action, () => {
152
- // console.log("nomatch action invoked", button_action);
153
140
  // });
154
- // console.log("callback(true) + return 2", current);
155
141
  // callback(true);
156
142
  // return;
157
143
  // }
158
144
  if (action.noMatchIntent) {
159
- if (this.log) { console.log("moving to nomatch action", action.noMatchIntent); }
160
145
  let nomatch_action = DirIntent.intentDirectiveFor(action.noMatchIntent, null);
161
146
  this.intentDir.execute(nomatch_action, () => {
162
- if (this.log) { console.log("nomatch action invoked", nomatch_action); }
147
+ winston.debug("(DirReplyV2) nomatch action invoked", nomatch_action);
163
148
  });
164
- if (this.log) { console.log("callback(true) + return no-match", current); }
165
149
  callback(true); // must_stop = true
166
150
  return;
167
151
  }
168
152
  else {
169
153
  // const defaultFallbackAction = { action: { intentName: "defaultFallback" } };
170
154
 
171
- // console.log("re-send original message:",JSON.stringify(this.originalMessage));
172
155
  const messageDir = new DirMessageToBot(this.context);
173
156
  messageDir.execute( { action: { message: this.originalMessage } }, () => {
174
- if (this.log) { console.log("messageDir invoked"); }
157
+ winston.debug("(DirReplyV2) messageDir invoked");
175
158
  });
176
- if (this.log) { console.log("callback(true) + return no-match", current); }
177
159
  callback(true); // must_stop = true
178
160
  return;
179
161
 
180
162
  // const textAction = { action: { text: last_user_text } };
181
- // console.log("textAction invoked:",textAction ); //, defaultFallbackAction);
182
163
  // this.intentDir.execute( textAction, () => {
183
- // if (this.log) { console.log("textAction invoked", textAction); }
184
164
  // });
185
- // if (this.log) { console.log("callback(true) + return no-match", current); }
186
165
  // callback(true); // must_stop = true
187
166
  // return;
188
167
 
189
168
 
190
169
  // // there is no "no-match", go on...
191
- // if (this.log) { console.log("callback(false) + return 3", current); }
192
170
  // callback(false);
193
171
  // return;
194
172
  }
@@ -197,16 +175,14 @@ class DirReplyV2 {
197
175
  }
198
176
  }
199
177
  catch(error) {
200
- console.error("Error in DirReplyV2:", error);
178
+ winston.error("(DirReplyV2) Error: ", error);
201
179
  }
202
180
 
203
-
204
- if (this.log) { console.log("proceding normally to render and send the reply", current); }
205
181
  const filler = new Filler();
182
+
206
183
  // fill text attribute
207
184
  message.text = filler.fill(message.text, requestAttributes);
208
185
  if (message.metadata) {
209
- if (this.log) {console.log("filling message 'metadata':", JSON.stringify(message.metadata));}
210
186
  if (message.metadata.src) {
211
187
  message.metadata.src = filler.fill(message.metadata.src, requestAttributes);
212
188
  }
@@ -214,29 +190,22 @@ class DirReplyV2 {
214
190
  message.metadata.name = filler.fill(message.metadata.name, requestAttributes);
215
191
  }
216
192
  }
217
- if (this.log) {console.log("filling commands'. Message:", JSON.stringify(message));}
218
193
  if (message.attributes && message.attributes.commands) {
219
- if (this.log) {console.log("filling commands'. commands found.");}
220
194
  let commands = message.attributes.commands;
221
- if (this.log) {console.log("commands:", JSON.stringify(commands), commands.length);}
222
195
  if (commands.length > 0) {
223
- if (this.log) {console.log("commands' found");}
224
196
  for (let i = 0; i < commands.length; i++) {
225
197
  let command = commands[i];
226
198
  if (command.type === 'message' && command.message && command.message.text) {
227
199
  command.message.text = filler.fill(command.message.text, requestAttributes);
228
200
  TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes, this.log);
229
- if (this.log) {console.log("command filled:", command.message.text);}
230
201
  }
231
202
  }
232
203
  }
233
204
  }
234
205
 
235
206
  // EVALUATE EXPRESSION AND REMOVE BASED ON EVALUATION
236
- if (this.log) {console.log("message before filters:", JSON.stringify(message));}
207
+ winston.debug("(DirReplyV2) message before filters:", message);
237
208
  if (message.attributes && message.attributes.commands) {
238
- if (this.log) {console.log("filterOnVariables...on commands", JSON.stringify(message.attributes.commands));}
239
- if (this.log) {console.log("filterOnVariables...on attributes", requestAttributes);}
240
209
  // TiledeskChatbotUtil.filterOnVariables(message.attributes.commands, requestAttributes);
241
210
  TiledeskChatbotUtil.filterOnVariables(message, requestAttributes);
242
211
  }
@@ -258,7 +227,6 @@ class DirReplyV2 {
258
227
  }
259
228
  // userFlowAttributes
260
229
  let userFlowAttributes = TiledeskChatbotUtil.userFlowAttributes(requestAttributes);
261
- if (this.log) { console.log("userFlowAttributes:", userFlowAttributes); }
262
230
  if (userFlowAttributes) {
263
231
  message.attributes["flowAttributes"] = {};
264
232
  for (const [key, value] of Object.entries(userFlowAttributes)) {
@@ -268,7 +236,7 @@ class DirReplyV2 {
268
236
  }
269
237
  }
270
238
  catch(err) {
271
- 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));
272
240
  }
273
241
  }
274
242
  }
@@ -278,33 +246,29 @@ class DirReplyV2 {
278
246
  let cleanMessage = message;
279
247
  // cleanMessage = TiledeskChatbotUtil.removeEmptyReplyCommands(message);
280
248
  // if (!TiledeskChatbotUtil.isValidReply(cleanMessage)) {
281
- // console.log("invalid message", cleanMessage);
282
249
  // callback(); // cancel reply operation
283
250
  // return;
284
251
  // }
285
- // console.log("valid message!", cleanMessage);
286
252
  cleanMessage.senderFullname = this.context.chatbot.bot.name;
287
- if (this.log) {console.log("Reply:", JSON.stringify(cleanMessage))};
253
+ winston.debug("(DirReplyV2) Reply: ", cleanMessage);
288
254
  await TiledeskChatbotUtil.updateConversationTranscript(this.context.chatbot, cleanMessage);
289
255
  this.tdClient.sendSupportMessage(
290
256
  this.requestId,
291
257
  cleanMessage,
292
258
  (err) => {
293
259
  if (err) {
294
- console.error("Error sending reply:", err);
260
+ winston.error("(DirReplyV2) Error sending reply: ", err);
295
261
  }
296
- if (this.log) {console.log("Reply message sent");}
262
+ winston.debug("(DirReplyV2) Reply message sent");
297
263
  const delay = TiledeskChatbotUtil.totalMessageWait(cleanMessage);
298
- // console.log("got total delay:", delay)
299
264
  if (delay > 0 && delay <= 30000) { // prevent long delays
300
- if (this.log) { console.log("start timeout callback(" + must_stop + ") for:", current); }
265
+ winston.debug("(DirReplyV2) start timeout callback(" + must_stop + ") for:", current);
301
266
  setTimeout(async () => {
302
- if (this.log) { console.log("callback(" + must_stop + ") after delay", current); }
267
+ winston.debug("(DirReplyV2) callback(" + must_stop + ") after delay", current);
303
268
  callback(must_stop);
304
269
  }, delay);
305
270
  }
306
271
  else {
307
- // console.log("invalid delay.")
308
272
  callback(must_stop);
309
273
  }
310
274
  });
@@ -314,32 +278,24 @@ class DirReplyV2 {
314
278
 
315
279
  async lockUnlock(action, callback) {
316
280
  let lockedAction = await this.chatbot.currentLockedAction(this.requestId);
317
- // console.log("(DirReplyV2) lockedAction:", lockedAction);
281
+
318
282
  if (!lockedAction) {
319
- // console.log("(DirReplyV2) !lockedAction");
320
283
  const intent_name = this.reply.attributes.intent_info.intent_name
321
284
  const actionId = action["_tdActionId"];
322
- // console.log("(DirReplyV2) intent_name:", intent_name);
323
- // console.log("(DirReplyV2) actionId:", actionId);
324
285
  await this.chatbot.lockIntent(this.requestId, intent_name);
325
- // console.log("(DirReplyV2) lockIntent");
326
286
  await this.chatbot.lockAction(this.requestId, actionId);
327
- // console.log("(DirReplyV2) lockAction");
328
287
  let _lockedAction = await this.chatbot.currentLockedAction(this.requestId);
329
288
  let _lockedIntent = await this.chatbot.currentLockedIntent(this.requestId);
330
- // console.log("(DirReplyV2) _lockedAction", _lockedAction);
331
- // console.log("(DirReplyV2) _lockedIntent", _lockedIntent);
332
289
  // callback();
333
290
  return true;
334
291
  } else {
335
292
  try {
336
293
  await this.chatbot.unlockIntent(this.requestId);
337
294
  await this.chatbot.unlockAction(this.requestId);
338
- // console.log("unlocked ReplyV2");
339
295
  return false;
340
296
  }
341
297
  catch(e) {
342
- console.error("Error", e);
298
+ winston.error("(DirReplyV2) Error", e);
343
299
  }
344
300
  }
345
301
  }
@@ -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
  }
@@ -2,6 +2,7 @@ const axios = require("axios").default;
2
2
  const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
3
3
  const { Filler } = require("../Filler");
4
4
  const { DirIntent } = require("./DirIntent");
5
+ const winston = require('../../utils/winston');
5
6
 
6
7
  let whatsapp_api_url;
7
8
 
@@ -21,13 +22,13 @@ class DirSendWhatsapp {
21
22
  }
22
23
 
23
24
  execute(directive, callback) {
24
- if (this.log) { console.log("DirWhatsappStatic directive: ", directive); }
25
+ winston.verbose("Execute SendWhatsapp directive");
25
26
  let action;
26
27
  if (directive.action) {
27
28
  action = directive.action;
28
29
  }
29
30
  else {
30
- console.error("Incorrect directive: ", JSON.stringify(directive));
31
+ winston.warn("DirSendWhatsapp Incorrect directive: ", directive);
31
32
  callback();
32
33
  return;
33
34
  }
@@ -38,9 +39,9 @@ class DirSendWhatsapp {
38
39
 
39
40
  async go(action, callback) {
40
41
 
41
- if (this.log) { console.log("DirWhatsappStatic action: ", JSON.stringify(action)) }
42
+ winston.debug("(DirSendWhatsapp) Action: ", action);
42
43
  if (!this.tdcache) {
43
- console.error("Error: DirAskGPT tdcache is mandatory");
44
+ winston.error("(DirSendWhatsapp) Error: tdcache is mandatory");
44
45
  callback();
45
46
  return;
46
47
  }
@@ -80,7 +81,7 @@ class DirSendWhatsapp {
80
81
  } else {
81
82
  whatsapp_api_url = this.API_ENDPOINT + "/modules/whatsapp/api"
82
83
  }
83
- if (this.log) { console.log("DirSendWhatsapp whatsapp_api_url: ", whatsapp_api_url); };
84
+ winston.debug("(DirSendWhatsapp) whatsapp_api_url: " + whatsapp_api_url);
84
85
 
85
86
  const HTTPREQUEST = {
86
87
  url: whatsapp_api_url + "/tiledesk/broadcast",
@@ -91,12 +92,12 @@ class DirSendWhatsapp {
91
92
  method: 'POST'
92
93
  }
93
94
 
94
- if (this.log) { console.log("DirSendWhatsapp HTTPREQUEST: ", HTTPREQUEST); }
95
+ winston.debug("(DirSendWhatsapp) HttpRequest: ", HTTPREQUEST);
95
96
 
96
97
  this.#myrequest(
97
98
  HTTPREQUEST, async (err, resbody) => {
98
99
  if (err) {
99
- console.error("DirSendWhatsapp error: ", err);
100
+ winston.error("(DirSendWhatsapp) error: ", err)
100
101
  await this.chatbot.addParameter("flowError", "SendWhatsapp Error: " + err);
101
102
  if (callback) {
102
103
  if (falseIntent) {
@@ -118,7 +119,7 @@ class DirSendWhatsapp {
118
119
  return;
119
120
  }
120
121
  } else {
121
- if (this.log) { console.log("DirSendWhatsapp unexpected resbody: ", resbody); }
122
+ winston.debug("(DirSendWhatsapp) unexpected resbody: ", resbody);
122
123
  if (callback) {
123
124
  if (falseIntent) {
124
125
  await this.#executeCondition(false, trueIntent, null, falseIntent, null);
@@ -151,7 +152,7 @@ class DirSendWhatsapp {
151
152
  })
152
153
  }
153
154
  else {
154
- if (this.log) { console.log("No trueIntentDirective specified"); }
155
+ winston.debug("(DirSendWhatsapp) No trueIntentDirective specified");
155
156
  if (callback) {
156
157
  callback();
157
158
  }
@@ -166,7 +167,7 @@ class DirSendWhatsapp {
166
167
  });
167
168
  }
168
169
  else {
169
- if (this.log) { console.log("No falseIntentDirective specified"); }
170
+ winston.debug("(DirSendWhatsapp) No falseIntentDirective specified");
170
171
  if (callback) {
171
172
  callback();
172
173
  }
@@ -209,7 +210,7 @@ class DirSendWhatsapp {
209
210
  resolve(receiver);
210
211
 
211
212
  } catch(err) {
212
- console.error("DirSendWhatsapp fillWholeReceiver error: ", err)
213
+ winston.error("(DirSendWhatsapp) fillWholeReceiver error: ", err)
213
214
  resolve(null);
214
215
  }
215
216
 
@@ -236,7 +237,7 @@ class DirSendWhatsapp {
236
237
  }
237
238
  }
238
239
  }).catch((err) => {
239
- console.error("(tybot request) An error occured: ", err);
240
+ winston.error("(DirSendWhatsapp) Axios errro: ", err);
240
241
  if (callback) {
241
242
  callback(err, null, null);
242
243
  }
@@ -4,6 +4,7 @@ const { TiledeskMath } = require('../../TiledeskMath');
4
4
  const { TiledeskString } = require('../../TiledeskString');
5
5
  const { Filler } = require('../Filler');
6
6
  const validate = require('jsonschema').validate;
7
+ const winston = require('../../utils/winston');
7
8
 
8
9
  const schema = {
9
10
  "type": "object",
@@ -80,37 +81,39 @@ class DirSetAttribute {
80
81
  }
81
82
 
82
83
  execute(directive, callback) {
84
+ winston.verbose("Execute SetAttribute directive");
83
85
  let action;
84
86
  if (directive.action) {
85
87
  action = directive.action
86
88
  }
87
89
  else {
90
+ winston.warn("DirSetAttribute Incorrect directive: ", directive);
88
91
  callback();
89
92
  return;
90
93
  }
91
- // console.log("go DirAssign with action:", action);
92
94
  this.go(action, () => {
93
95
  callback();
94
96
  });
95
97
  }
96
98
 
97
99
  async go(action, callback) {
100
+ winston.debug("(DirSetAttribute) Action: ", action);
98
101
  let res = validate(action, schema);
99
102
  if (!res.valid) {
100
- if (this.log) {console.error("(DirSetAttribute) Invalid action:", res.errors)};
103
+ winston.error("(DirSetAttribute) Invalid action:", res.errors);
101
104
  callback();
102
105
  return;
103
106
  }
104
107
 
105
108
  if(action.operation.operators === undefined && action.operation.operands.length !== 1) {
106
- if (this.log) {console.error("(DirSetAttribute) Invalid action: operators === undefined && operands.length !== 1")};
109
+ winston.error("(DirSetAttribute) Invalid action: operators === undefined && operands.length !== 1");
107
110
  callback();
108
111
  return;
109
112
  }
110
113
 
111
114
 
112
115
  if (action.operation.operators !== undefined && action.operation.operators.length !== action.operation.operands.length - 1) {
113
- if (this.log) {console.error("(DirSetAttribute) Invalid action: operators.length !== operands.length - 1")};
116
+ winston.error("(DirSetAttribute) Invalid action: operators.length !== operands.length - 1");
114
117
  callback();
115
118
  return;
116
119
  }