@tiledesk/tiledesk-tybot-connector 2.0.11 → 2.0.12-rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/Logger.js +28 -16
  2. package/logs/app2.log +1882 -0
  3. package/package.json +3 -2
  4. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +7 -0
  5. package/tiledeskChatbotPlugs/directives/DirAddTags.js +17 -11
  6. package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +18 -2
  7. package/tiledeskChatbotPlugs/directives/DirAskGPT.js +2 -2
  8. package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +18 -2
  9. package/tiledeskChatbotPlugs/directives/DirAssign.js +0 -9
  10. package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +1 -8
  11. package/tiledeskChatbotPlugs/directives/DirAssistant.js +13 -3
  12. package/tiledeskChatbotPlugs/directives/DirBrevo.js +11 -8
  13. package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +10 -1
  14. package/tiledeskChatbotPlugs/directives/DirClearTranscript.js +5 -0
  15. package/tiledeskChatbotPlugs/directives/DirClose.js +8 -9
  16. package/tiledeskChatbotPlugs/directives/DirCode.js +9 -1
  17. package/tiledeskChatbotPlugs/directives/DirCondition.js +13 -1
  18. package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +7 -9
  19. package/tiledeskChatbotPlugs/directives/DirCustomerio.js +11 -2
  20. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +1 -7
  21. package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +14 -1
  22. package/tiledeskChatbotPlugs/directives/DirDepartment.js +13 -9
  23. package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +2 -8
  24. package/tiledeskChatbotPlugs/directives/DirFlowLog.js +88 -0
  25. package/tiledeskChatbotPlugs/directives/DirForm.js +3 -10
  26. package/tiledeskChatbotPlugs/directives/DirGptTask.js +19 -7
  27. package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +2 -1
  28. package/tiledeskChatbotPlugs/directives/DirHubspot.js +12 -3
  29. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +3 -9
  30. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +12 -10
  31. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +11 -1
  32. package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +3 -9
  33. package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +14 -4
  34. package/tiledeskChatbotPlugs/directives/DirMake.js +6 -1
  35. package/tiledeskChatbotPlugs/directives/DirMessage.js +1 -7
  36. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +5 -9
  37. package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +6 -9
  38. package/tiledeskChatbotPlugs/directives/DirQapla.js +7 -3
  39. package/tiledeskChatbotPlugs/directives/DirRandomReply.js +7 -9
  40. package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +1 -7
  41. package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +7 -9
  42. package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +7 -9
  43. package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +7 -9
  44. package/tiledeskChatbotPlugs/directives/DirReply.js +9 -16
  45. package/tiledeskChatbotPlugs/directives/DirReplyV2.js +8 -10
  46. package/tiledeskChatbotPlugs/directives/DirSendEmail.js +7 -9
  47. package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +7 -2
  48. package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +7 -1
  49. package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +2 -8
  50. package/tiledeskChatbotPlugs/directives/DirWait.js +6 -1
  51. package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +20 -5
  52. package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +2 -1
  53. package/tiledeskChatbotPlugs/directives/DirWebResponse.js +8 -40
  54. package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +7 -1
  55. package/tiledeskChatbotPlugs/directives/Directives.js +1 -0
  56. package/utils/TiledeskChatbotUtil.js +2 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "2.0.11",
3
+ "version": "2.0.12-rc1",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -15,7 +15,7 @@
15
15
  "@tiledesk/tiledesk-chatbot-client": "^0.5.30",
16
16
  "@tiledesk/tiledesk-chatbot-util": "^0.8.39",
17
17
  "@tiledesk/tiledesk-client": "^0.10.13",
18
- "@tiledesk/tiledesk-multi-worker": "^0.2.1-rc2",
18
+ "@tiledesk/tiledesk-multi-worker": "^0.3.1-rc10",
19
19
  "accept-language-parser": "^1.5.0",
20
20
  "app-root-path": "^3.1.0",
21
21
  "axios": "^1.7.7",
@@ -29,6 +29,7 @@
29
29
  "liquidjs": "^10.8.4",
30
30
  "minimist-string": "^1.0.2",
31
31
  "mongoose": "^6.3.5",
32
+ "mqtt": "^5.10.4",
32
33
  "multer": "^1.4.5-lts.1",
33
34
  "nanoid": "^3.1.25",
34
35
  "redis": "^4.7.0",
@@ -59,6 +59,7 @@ const { DirWebResponse } = require('./directives/DirWebResponse');
59
59
  const { DirConnectBlock } = require('./directives/DirConnectBlock');
60
60
 
61
61
  const winston = require('../utils/winston');
62
+ const { DirFlowLog } = require('./directives/DirFlowLog');
62
63
 
63
64
  class DirectivesChatbotPlug {
64
65
 
@@ -707,6 +708,12 @@ class DirectivesChatbotPlug {
707
708
  this.process(next_dir);
708
709
  });
709
710
  }
711
+ else if (directive_name === Directives.FLOW_LOG) {
712
+ new DirFlowLog(context).execute(directive, async () => {
713
+ let next_dir = await this.nextDirective(this.directives);
714
+ this.process(next_dir);
715
+ })
716
+ }
710
717
  else {
711
718
  let next_dir = await this.nextDirective(this.directives);
712
719
  this.process(next_dir);
@@ -8,6 +8,7 @@ const { TiledeskChatbotUtil } = require("../../utils/TiledeskChatbotUtil");
8
8
  const req = require("express/lib/request");
9
9
  const { update } = require("../../models/faq");
10
10
  const { TiledeskClient } = require("@tiledesk/tiledesk-client");
11
+ const { Logger } = require("../../Logger");
11
12
  require('dotenv').config();
12
13
  const winston = require('../../utils/winston');
13
14
  const httpUtils = require("../../utils/HttpUtils");
@@ -23,29 +24,26 @@ class DirAddTags {
23
24
  this.tdcache = this.context.tdcache;
24
25
  this.requestId = this.context.requestId;
25
26
  this.API_ENDPOINT = this.context.API_ENDPOINT;
26
- this.log = context.log;
27
-
28
- this.tdClient = new TiledeskClient({
29
- projectId: this.context.projectId,
30
- token: this.context.token,
31
- APIURL: this.API_ENDPOINT,
32
- APIKEY: "___",
33
- log: this.log
34
- });
27
+
28
+ this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
29
+ this.tdClient = new TiledeskClient({ projectId: this.context.projectId, token: this.context.token, APIURL: this.API_ENDPOINT, APIKEY: "___" });
35
30
  }
36
31
 
37
32
  execute(directive, callback) {
38
- winston.verbose("Execute AddTags directive");
33
+ this.logger.info("[Add Tag] Executing action")
34
+ winston.verbose("Execute AddTags action");
39
35
  let action;
40
36
  if (directive.action) {
41
37
  action = directive.action;
42
38
  }
43
39
  else {
44
- winston.warn("Incorrect directive: ", directive);
40
+ this.logger.error("Incorrect action for ", directive.name, directive)
41
+ winston.debug("Incorrect directive: ", directive);
45
42
  callback();
46
43
  return;
47
44
  }
48
45
  this.go(action, (stop) => {
46
+ this.logger.info("[Add Tag] Action completed");
49
47
  callback(stop);
50
48
  })
51
49
  }
@@ -66,6 +64,7 @@ class DirAddTags {
66
64
  pushToList = action.pushToList
67
65
 
68
66
  if (!action.tags || action.tags === '') {
67
+ this.logger.error("[Add Tag] tags attribute is mandatory");
69
68
  winston.error("(DirAddTags) Error: tags attribute is mandatory")
70
69
  await this.chatbot.addParameter("flowError", "Add tags Error: tags attribute is mandatory");
71
70
  callback();
@@ -86,6 +85,7 @@ class DirAddTags {
86
85
  if(target === 'request'){
87
86
 
88
87
  let newTags = filled_tags.split(',').filter(tag => tag !== '').map(el => el.trim())
88
+ this.logger.debug("[Add Tag] Adding following tags to conversation: ", newTags)
89
89
 
90
90
  if(action.pushToList){
91
91
  newTags.forEach(async (tag) => {
@@ -99,6 +99,7 @@ class DirAddTags {
99
99
 
100
100
  winston.debug('(DirAddTags) UPDATE request with newTags', newTags)
101
101
  let updatedRequest = await this.updateRequestWithTags(newTags)
102
+ this.logger.info("[Add Tag] Tags added to conversation")
102
103
  if(!updatedRequest){
103
104
  callback();
104
105
  return;
@@ -109,6 +110,7 @@ class DirAddTags {
109
110
  /** use case: LEAD */
110
111
  if(target === 'lead'){
111
112
  let newTags = filled_tags.split(',').filter(tag => tag !== '').map(el => el.trim())
113
+ this.logger.debug("[Add Tag] Adding following tags to lead: ", newTags)
112
114
 
113
115
  let request = await this.tdClient.getRequestById(this.requestId);
114
116
  winston.debug('(DirAddTags) request detail: ', request)
@@ -130,6 +132,7 @@ class DirAddTags {
130
132
 
131
133
  winston.debug('(DirAddTags) UPDATE lead with newTags ', newTags)
132
134
  let updatedLead = await this.updateLeadWithTags(request.lead._id, newTags)
135
+ this.logger.info("[Add Tag] Tags added to lead")
133
136
  if(!updatedLead){
134
137
  callback();
135
138
  return;
@@ -174,6 +177,7 @@ class DirAddTags {
174
177
  httpUtils.request(
175
178
  HTTPREQUEST, async (err, resbody) => {
176
179
  if (err) {
180
+ this.logger.error("[Add Tag] Add tags to list error ", err?.response?.data)
177
181
  winston.error("(httprequest) DirAddTags add tags to list err: ", err);
178
182
  resolve(true)
179
183
  } else {
@@ -208,6 +212,7 @@ class DirAddTags {
208
212
  httpUtils.request(
209
213
  HTTPREQUEST, async (err, resbody) => {
210
214
  if (err) {
215
+ this.logger.error("[Add Tag] Add tag to conversation error ", err?.response?.data);
211
216
  winston.error("(httprequest) DirAddTags patch request with new tags err: ", err);
212
217
  resolve(true)
213
218
  } else {
@@ -237,6 +242,7 @@ class DirAddTags {
237
242
  httpUtils.request(
238
243
  HTTPREQUEST, async (err, resbody) => {
239
244
  if (err) {
245
+ this.logger.error("[Add Tag] Add tag to lead error ", err?.response?.data);
240
246
  winston.error("(httprequest) DirAddTags put lead with new tags err: ", err);
241
247
  resolve(true)
242
248
  } else {
@@ -11,6 +11,7 @@ const Utils = require("../../utils/HttpUtils");
11
11
  const utils = require("../../utils/HttpUtils");
12
12
  const httpUtils = require("../../utils/HttpUtils");
13
13
  const integrationService = require("../../services/IntegrationService");
14
+ const { Logger } = require("../../Logger");
14
15
 
15
16
 
16
17
  class DirAiPrompt {
@@ -25,23 +26,27 @@ class DirAiPrompt {
25
26
  this.requestId = this.context.requestId;
26
27
  this.projectId = this.context.projectId;
27
28
  this.token = this.context.token;
28
- this.intentDir = new DirIntent(context);
29
29
  this.API_ENDPOINT = this.context.API_ENDPOINT;
30
- this.log = context.log;
30
+
31
+ this.intentDir = new DirIntent(context);
32
+ this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
31
33
  }
32
34
 
33
35
  execute(directive, callback) {
36
+ this.logger.info("[AI Prompt] Executing action");
34
37
  winston.verbose("Execute AiPrompt directive");
35
38
  let action;
36
39
  if (directive.action) {
37
40
  action = directive.action;
38
41
  }
39
42
  else {
43
+ this.logger.error("Incorrect action for ", directive.name, directive)
40
44
  winston.debug("DirAiPrompt Incorrect directive: ", directive);
41
45
  callback();
42
46
  return;
43
47
  }
44
48
  this.go(action, (stop) => {
49
+ this.logger.info("[AI Prompt] Action completed");
45
50
  callback(stop);
46
51
  })
47
52
  }
@@ -65,6 +70,7 @@ class DirAiPrompt {
65
70
  winston.debug("DirAskGPTV2 falseIntent", falseIntent)
66
71
 
67
72
  await this.checkMandatoryParameters(action).catch( async (missing_param) => {
73
+ this.logger.error(`[AI Prompt] missing attribute '${missing_param}'`);
68
74
  await this.chatbot.addParameter("flowError", "AiPrompt Error: '" + missing_param + "' attribute is undefined");
69
75
  if (falseIntent) {
70
76
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
@@ -86,6 +92,7 @@ class DirAiPrompt {
86
92
  const filled_context = filler.fill(action.context, requestVariables);
87
93
 
88
94
  if (action.history) {
95
+ this.logger.info("[AI Prompt] using chat transcript");
89
96
  let transcript_string = await TiledeskChatbot.getParameterStatic(
90
97
  this.context.tdcache,
91
98
  this.context.requestId,
@@ -96,6 +103,7 @@ class DirAiPrompt {
96
103
  transcript = await TiledeskChatbotUtil.transcriptJSON(transcript_string);
97
104
  winston.debug("DirAiPrompt transcript: ", transcript)
98
105
  } else {
106
+ this.logger.warn("[AI Prompt] no chat transcript found, skipping history translation");
99
107
  winston.verbose("DirAiPrompt transcript_string is undefined. Skip JSON translation for chat history")
100
108
  }
101
109
  }
@@ -112,6 +120,7 @@ class DirAiPrompt {
112
120
 
113
121
  if (action.llm === 'ollama') {
114
122
  ollama_integration = await integrationService.getIntegration(this.projectId, action.llm, this.token).catch( async (err) => {
123
+ this.logger.error("[AI Prompt] Error getting ollama integration.")
115
124
  winston.error("DirAiPrompt Error getting ollama integration: ", err);
116
125
  await this.chatbot.addParameter("flowError", "Ollama integration not found");
117
126
  if (falseIntent) {
@@ -127,6 +136,7 @@ class DirAiPrompt {
127
136
  key = await integrationService.getKeyFromIntegrations(this.projectId, action.llm, this.token);
128
137
 
129
138
  if (!key) {
139
+ this.logger.error("[AI Prompt] llm key not found in integrations");
130
140
  winston.error("Error: DirAiPrompt llm key not found in integrations");
131
141
  await this.chatbot.addParameter("flowError", "AiPrompt Error: missing key for llm " + action.llm);
132
142
  if (falseIntent) {
@@ -189,6 +199,7 @@ class DirAiPrompt {
189
199
  } else {
190
200
  error = JSON.stringify(err.response.data);
191
201
  }
202
+ this.logger.error("[AI Prompt] error executing action: ", error);
192
203
  if (falseIntent) {
193
204
  await this.chatbot.addParameter("flowError", "AiPrompt Error: " + error);
194
205
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
@@ -201,6 +212,7 @@ class DirAiPrompt {
201
212
 
202
213
  winston.debug("DirAiPrompt resbody: ", resbody);
203
214
  answer = resbody.answer;
215
+ this.logger.info("[AI Prompt] answer: ", answer);
204
216
 
205
217
  await this.#assignAttributes(action, answer);
206
218
 
@@ -288,6 +300,7 @@ class DirAiPrompt {
288
300
  }
289
301
  if (result === true) {
290
302
  if (trueIntentDirective) {
303
+ this.logger.info("[AI Prompt] executing true condition");
291
304
  this.intentDir.execute(trueIntentDirective, () => {
292
305
  if (callback) {
293
306
  callback();
@@ -295,6 +308,7 @@ class DirAiPrompt {
295
308
  })
296
309
  }
297
310
  else {
311
+ this.logger.info("[AI Prompt] no block connected to true condition");
298
312
  winston.debug("DirAiPrompt No trueIntentDirective specified");
299
313
  if (callback) {
300
314
  callback();
@@ -303,6 +317,7 @@ class DirAiPrompt {
303
317
  }
304
318
  else {
305
319
  if (falseIntentDirective) {
320
+ this.logger.info("[AI Prompt] executing false condition");
306
321
  this.intentDir.execute(falseIntentDirective, () => {
307
322
  if (callback) {
308
323
  callback();
@@ -310,6 +325,7 @@ class DirAiPrompt {
310
325
  });
311
326
  }
312
327
  else {
328
+ this.logger.info("[AI Prompt] no block connected to false condition");
313
329
  winston.debug("DirAiPrompt No falseIntentDirective specified");
314
330
  if (callback) {
315
331
  callback();
@@ -19,9 +19,9 @@ class DirAskGPT {
19
19
  this.requestId = this.context.requestId;
20
20
  this.projectId = this.context.projectId;
21
21
  this.token = this.context.token;
22
- this.intentDir = new DirIntent(context);
23
22
  this.API_ENDPOINT = this.context.API_ENDPOINT;
24
- this.log = context.log;
23
+
24
+ this.intentDir = new DirIntent(context);
25
25
  }
26
26
 
27
27
  execute(directive, callback) {
@@ -10,6 +10,7 @@ require('dotenv').config();
10
10
  const winston = require('../../utils/winston');
11
11
  const httpUtils = require("../../utils/HttpUtils");
12
12
  const integrationService = require("../../services/IntegrationService");
13
+ const { Logger } = require("../../Logger");
13
14
 
14
15
  class DirAskGPTV2 {
15
16
 
@@ -23,23 +24,27 @@ class DirAskGPTV2 {
23
24
  this.requestId = this.context.requestId;
24
25
  this.projectId = this.context.projectId;
25
26
  this.token = this.context.token;
26
- this.intentDir = new DirIntent(context);
27
27
  this.API_ENDPOINT = this.context.API_ENDPOINT;
28
- this.log = context.log;
28
+
29
+ this.intentDir = new DirIntent(context);
30
+ this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
29
31
  }
30
32
 
31
33
  execute(directive, callback) {
34
+ this.logger.info("[Ask Knowledge Base] Executing action");
32
35
  winston.debug("DirAskGPTV2 directive: ", directive);
33
36
  let action;
34
37
  if (directive.action) {
35
38
  action = directive.action;
36
39
  }
37
40
  else {
41
+ this.logger.error("Incorrect action for ", directive.name, directive)
38
42
  winston.debug("DirAskGPTV2 Incorrect directive: ", directive);
39
43
  callback();
40
44
  return;
41
45
  }
42
46
  this.go(action, (stop) => {
47
+ this.logger.info("[Ask Knowledge Base] Action completed");
43
48
  callback(stop);
44
49
  })
45
50
  }
@@ -90,6 +95,7 @@ class DirAskGPTV2 {
90
95
  let source = null;
91
96
 
92
97
  if (!action.question || action.question === '') {
98
+ this.logger.error("[Ask Knowledge Base] question attribute is mandatory");
93
99
  winston.error("DirAskGPTV2 Error: question attribute is mandatory. Executing condition false...");
94
100
  await this.#assignAttributes(action, answer, source);
95
101
  if (falseIntent) {
@@ -133,6 +139,7 @@ class DirAskGPTV2 {
133
139
  const filled_context = filler.fill(action.context, requestVariables)
134
140
 
135
141
  if (action.history) {
142
+ this.logger.info("[Ask Knowledge Base] use chat transcript")
136
143
  let transcript_string = await TiledeskChatbot.getParameterStatic(
137
144
  this.context.tdcache,
138
145
  this.context.requestId,
@@ -144,6 +151,7 @@ class DirAskGPTV2 {
144
151
  transcript = await TiledeskChatbotUtil.transcriptJSON(transcript_string);
145
152
  winston.debug("DirAskGPTV2 transcript ", transcript)
146
153
  } else {
154
+ this.logger.warn("[Ask Knowledge Base] chat transcript is undefined. Skip JSON translation for chat history.");
147
155
  winston.verbose("DirAskGPT transcript_string is undefined. Skip JSON translation for chat history")
148
156
  }
149
157
  }
@@ -153,6 +161,7 @@ class DirAskGPTV2 {
153
161
 
154
162
  let key = await integrationService.getKeyFromIntegrations(this.projectId, 'openai', this.token);
155
163
  if (!key) {
164
+ this.logger.debug("[Ask Knowledge Base] OpenAI key not found in Integration. Using shared OpenAI key");
156
165
  winston.verbose("DirAskGPTV2 - Key not found in Integrations. Searching in kb settings...");
157
166
  key = await this.getKeyFromKbSettings();
158
167
  }
@@ -161,6 +170,8 @@ class DirAskGPTV2 {
161
170
  winston.verbose("DirAskGPTV2 - Retrieve public gptkey")
162
171
  key = process.env.GPTKEY;
163
172
  publicKey = true;
173
+ } else {
174
+ this.logger.debug("[Ask Knowledge Base] use your own OpenAI key")
164
175
  }
165
176
 
166
177
  if (!key) {
@@ -178,6 +189,7 @@ class DirAskGPTV2 {
178
189
  if (publicKey === true) {
179
190
  let keep_going = await this.checkQuoteAvailability();
180
191
  if (keep_going === false) {
192
+ this.logger.warn("[Ask Knowledge Base] Tokens quota exceeded. Skip the action")
181
193
  winston.verbose("DirAskGPTV2 - Quota exceeded for tokens. Skip the action")
182
194
  await this.chatbot.addParameter("flowError", "AskGPT Error: tokens quota exceeded");
183
195
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
@@ -191,14 +203,17 @@ class DirAskGPTV2 {
191
203
  if (action.namespaceAsName) {
192
204
  // Namespace could be an attribute
193
205
  const filled_namespace = filler.fill(action.namespace, requestVariables)
206
+ this.logger.debug("[Ask Knowledge Base] Searching namespace by name ", filled_namespace);
194
207
  ns = await this.getNamespace(filled_namespace, null);
195
208
  namespace = ns?.id;
196
209
  winston.verbose("DirAskGPTV2 - Retrieved namespace id from name " + namespace);
197
210
  } else {
211
+ this.logger.debug("[Ask Knowledge Base] Searching namespace by id ", namespace);
198
212
  ns = await this.getNamespace(null, namespace);
199
213
  }
200
214
 
201
215
  if (!ns) {
216
+ this.logger.error("[Ask Knowledge Base] Namespace not found")
202
217
  await this.#assignAttributes(action, answer);
203
218
  await this.chatbot.addParameter("flowError", "AskGPT Error: namespace not found");
204
219
  if (falseIntent) {
@@ -217,6 +232,7 @@ class DirAskGPTV2 {
217
232
  }
218
233
 
219
234
  if (!namespace) {
235
+ this.logger.error("[Ask Knowledge Base] Namespace is undefined")
220
236
  winston.verbose("DirAskGPTV2 - Error: namespace is undefined")
221
237
  if (falseIntent) {
222
238
  await this.chatbot.addParameter("flowError", "AskGPT Error: namespace is undefined");
@@ -11,7 +11,6 @@ class DirAssign {
11
11
  throw new Error('context object is mandatory.');
12
12
  }
13
13
  this.context = context;
14
- this.log = context.log;
15
14
  }
16
15
 
17
16
  execute(directive, callback) {
@@ -63,14 +62,6 @@ class DirAssign {
63
62
  const value = new TiledeskExpression().evaluateExpression(expression, variables);
64
63
  winston.debug("(DirAssign) executed expression: " + expression + " value: " + value);
65
64
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, variableName, value);
66
- if (this.log) {
67
- winston.debug("(DirAssign) Assigned: " + variableName + " = " + value);
68
- const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
69
- for (const [key, value] of Object.entries(all_parameters)) {
70
- const value_type = typeof value;
71
- winston.debug("(DirAssign) request parameter: " + key + " value: " + value + " type: " + value_type)
72
- }
73
- }
74
65
 
75
66
  callback();
76
67
  }
@@ -10,17 +10,10 @@ class DirAssignFromFunction {
10
10
  throw new Error('context object is mandatory.');
11
11
  }
12
12
  this.context = context;
13
- this.log = context.log;
14
13
  this.tdcache = context.tdcache;
15
14
  this.API_ENDPOINT = context.API_ENDPOINT;
16
15
 
17
- this.tdClient = new TiledeskClient({
18
- projectId: this.context.projectId,
19
- token: this.context.token,
20
- APIURL: this.API_ENDPOINT,
21
- APIKEY: "___",
22
- log: this.log
23
- });
16
+ this.tdClient = new TiledeskClient({ projectId: this.context.projectId, token: this.context.token, APIURL: this.API_ENDPOINT, APIKEY: "___" });
24
17
  }
25
18
 
26
19
  async execute(directive, callback) {
@@ -6,6 +6,7 @@ const { DirIntent } = require('./DirIntent');
6
6
  const winston = require('../../utils/winston')
7
7
  const httpUtils = require('../../utils/HttpUtils');
8
8
  const integrationService = require('../../services/IntegrationService');
9
+ const { Logger } = require('../../Logger');
9
10
 
10
11
  class DirAssistant {
11
12
  constructor(context) {
@@ -17,23 +18,27 @@ class DirAssistant {
17
18
  this.requestId = context.requestId;
18
19
  this.projectId = this.context.projectId;
19
20
  this.token = this.context.token;
20
- this.intentDir = new DirIntent(context);
21
21
  this.API_ENDPOINT = context.API_ENDPOINT;
22
- this.log = context.log;
22
+
23
+ this.intentDir = new DirIntent(context);
24
+ this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
23
25
  }
24
26
 
25
27
  execute(directive, callback) {
28
+ this.logger.info("[ChatGPT Assistant] Executing action");
26
29
  winston.verbose("Execute Assistant directive");
27
30
  let action;
28
31
  if (directive.action) {
29
32
  action = directive.action;
30
33
  }
31
34
  else {
32
- winston.warn("Incorrect directive: ", directive);
35
+ this.logger.error("Incorrect action for ", directive.name, directive)
36
+ winston.debug("Incorrect directive: ", directive);
33
37
  callback();
34
38
  return;
35
39
  }
36
40
  this.go(action, (stop) => {
41
+ this.logger.info("[ChatGPT Assistant] Action completed");
37
42
  callback(stop);
38
43
  });
39
44
  }
@@ -78,6 +83,7 @@ class DirAssistant {
78
83
  }
79
84
  else {
80
85
  // TODO: LOG SETTINGS ERROR
86
+ this.logger.error("[ChatGPT Assistant] No assistantId provided");
81
87
  winston.error("(DirAssistant) Error: no assistantId.");
82
88
  callback();
83
89
  return;
@@ -89,6 +95,7 @@ class DirAssistant {
89
95
  }
90
96
  else {
91
97
  // TODO: LOG SETTINGS ERROR
98
+ this.logger.error("[ChatGPT Assistant] No prompt provided");
92
99
  winston.error("(DirAssistant) Error: no prompt.");
93
100
  callback();
94
101
  return;
@@ -99,6 +106,7 @@ class DirAssistant {
99
106
  assistantId = filler.fill(_assistantId, requestAttributes);
100
107
  }
101
108
  catch(error) {
109
+ this.logger.error("[ChatGPT Assistant] Error while filling assistantId");
102
110
  winston.error("(DirAssistant) Error while filling assistantId:", error);
103
111
  }
104
112
 
@@ -107,6 +115,7 @@ class DirAssistant {
107
115
  prompt = filler.fill(_prompt, requestAttributes);
108
116
  }
109
117
  catch(error) {
118
+ this.logger.error("[ChatGPT Assistant] Error while filling prompt");
110
119
  winston.error("(DirAssistant) Error while filling prompt:", error);
111
120
  }
112
121
 
@@ -129,6 +138,7 @@ class DirAssistant {
129
138
  let apikey = await this.getGPT_APIKEY();
130
139
  if (!apikey) {
131
140
  const reply = "OpenAI APIKEY is mandatory for ChatGPT Assistants. Add your personal OpenAI APIKEY in Settings > Integrations";
141
+ this.logger.error("[ChatGPT Assistant] OpenAI APIKEY is mandatory for ChatGPT Assistants. Add your personal OpenAI APIKEY in Settings > Integrations");
132
142
  winston.error("(DirAssistant) Error: " + reply)
133
143
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, assignErrorTo, reply);
134
144
  if (falseIntent) {
@@ -6,6 +6,7 @@ let https = require("https");
6
6
  require('dotenv').config();
7
7
  const winston = require('../../utils/winston');
8
8
  const integrationService = require("../../services/IntegrationService");
9
+ const { Logger } = require("../../Logger");
9
10
 
10
11
  class DirBrevo {
11
12
 
@@ -18,23 +19,27 @@ class DirBrevo {
18
19
  this.requestId = this.context.requestId;
19
20
  this.projectId = this.context.projectId;
20
21
  this.token = this.context.token;
21
- this.intentDir = new DirIntent(context);
22
22
  this.API_ENDPOINT = this.context.API_ENDPOINT;
23
- this.log = context.log;
23
+
24
+ this.intentDir = new DirIntent(context);
25
+ this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
24
26
  }
25
27
 
26
28
  execute(directive, callback) {
29
+ this.logger.info("[Brevo] Executing action");
27
30
  winston.verbose("Execute DirBrevo directive");
28
31
  let action;
29
32
  if (directive.action) {
30
33
  action = directive.action;
31
34
  }
32
35
  else {
36
+ this.logger.error("Incorrect action for ", directive.name, directive)
33
37
  winston.warn("(DirBrevo) Incorrect directive: ", directive);
34
38
  callback();
35
39
  return;
36
40
  }
37
41
  this.go(action, (stop) => {
42
+ this.logger.info("[Brevo] Action completed");
38
43
  callback(stop);
39
44
  })
40
45
  }
@@ -69,6 +74,7 @@ class DirBrevo {
69
74
  winston.debug("(DirBrevo) bodyParameters: ", bodyParameters);
70
75
 
71
76
  if (!bodyParameters || bodyParameters === '') {
77
+ this.logger.error("[Brevo] bodyParameters is undefined or null or empty string");
72
78
  winston.error("(DirBrevo) Error: bodyParameters is undefined or null or empty string");
73
79
  callback();
74
80
  return;
@@ -80,6 +86,7 @@ class DirBrevo {
80
86
  let key = await integrationService.getKeyFromIntegrations(this.projectId, 'Brevo', this.token);
81
87
  winston.debug("(DirBrevo) key: ", key)
82
88
  if (!key) {
89
+ this.logger.error("[Brevo] Key not found in Integrations");
83
90
  winston.debug("(DirBrevo) - Key not found in Integrations.");
84
91
  if (falseIntent) {
85
92
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
@@ -140,6 +147,7 @@ class DirBrevo {
140
147
  BREVO_HTTPREQUEST, async (err, resbody) => {
141
148
  if (err) {
142
149
  if (callback) {
150
+ this.logger.error("[Brevo] Error response: ", err.response);
143
151
  winston.debug("(DirBrevo) err response: ", err.response)
144
152
  winston.debug("(DirBrevo) err data:", err.response.data)
145
153
 
@@ -158,12 +166,6 @@ class DirBrevo {
158
166
  error = err.response.data.message;
159
167
  }
160
168
 
161
- if (this.log) {
162
- winston.error("(DirBrevo) DirBrevo err data result:", result); // CONTROLLA IL VALORE
163
- winston.error("(DirBrevo) DirBrevo err data status:", status);
164
- winston.error("(DirBrevo) DirBrevo err data error:", error);
165
- }
166
-
167
169
  await this.#assignAttributes(action, status, result, error);
168
170
  if (falseIntent) {
169
171
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
@@ -179,6 +181,7 @@ class DirBrevo {
179
181
  let status = 201;
180
182
  let error = null;
181
183
  let result = JSON.stringify(resbody, null, 2).slice(2, -1);
184
+ this.logger.error("[Brevo] Result: ", result);
182
185
  await this.#assignAttributes(action, status, result, error);
183
186
  if (trueIntent) {
184
187
  await this.#executeCondition(true, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes)
@@ -2,6 +2,7 @@ const { Filler } = require('../Filler');
2
2
  const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
3
3
  const { DirIntent } = require('./DirIntent');
4
4
  const winston = require('../../utils/winston');
5
+ const { Logger } = require('../../Logger');
5
6
 
6
7
  class DirCaptureUserReply {
7
8
  constructor(context) {
@@ -15,17 +16,20 @@ class DirCaptureUserReply {
15
16
  this.chatbot = context.chatbot;
16
17
  this.tdcache = context.tdcache;
17
18
  this.requestId = context.requestId;
19
+
18
20
  this.intentDir = new DirIntent(context);
19
- this.log = context.log;
21
+ this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
20
22
  }
21
23
 
22
24
  execute(directive, callback) {
25
+ this.logger.info("[Capture User Reply] Executing action");
23
26
  winston.verbose("Execute CaptureUserReply directive");
24
27
  let action;
25
28
  if (directive.action) {
26
29
  action = directive.action;
27
30
  }
28
31
  else {
32
+ this.logger.error("Incorrect action for ", directive.name, directive)
29
33
  winston.warn("DirCaptureUserReply Incorrect directive: ", directive);
30
34
  callback();
31
35
  return;
@@ -44,6 +48,7 @@ class DirCaptureUserReply {
44
48
  const actionId = action["_tdActionId"];;
45
49
  await this.chatbot.lockIntent(this.requestId, intent_name);
46
50
  await this.chatbot.lockAction(this.requestId, actionId);
51
+ this.logger.info("[Capture User Reply] Waiting for user reply...");
47
52
  callback();
48
53
  return;
49
54
  } else {
@@ -58,6 +63,7 @@ class DirCaptureUserReply {
58
63
  }
59
64
  try {
60
65
  const user_reply = this.message.text;
66
+ this.logger.info("[Capture User Reply] User replied with: ", user_reply);
61
67
  if (this.context.tdcache) {
62
68
  if (action.assignResultTo) {
63
69
  winston.debug("(DirCaptureUserReply) assign assignResultTo: " + action.assignResultTo);
@@ -68,16 +74,19 @@ class DirCaptureUserReply {
68
74
  if (callback) {
69
75
  if (goToIntent) {
70
76
  this.#executeGoTo(goToIntent, () => {
77
+ this.logger.info("[Capture User Reply] Action completed");
71
78
  callback(); // continue the flow
72
79
  });
73
80
  }
74
81
  else {
82
+ this.logger.info("[Capture User Reply] Action completed");
75
83
  callback(); // continue the flow
76
84
  }
77
85
 
78
86
  }
79
87
  }
80
88
  catch(error) {
89
+ this.logger.error("[Capture User Reply] Error: ", error);
81
90
  winston.error("(DirCaptureUserReply) error: ", error);
82
91
  }
83
92
  }