@tiledesk/tiledesk-tybot-connector 2.0.10-rc2 → 2.0.10-rc20

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 (61) hide show
  1. package/Logger.js +6 -1
  2. package/logs/app.log +28600 -21124
  3. package/logs/app1.log +41129 -0
  4. package/logs/app2.log +16449 -45594
  5. package/logs/app6.log +44412 -0
  6. package/logs/app7.log +4726 -0
  7. package/package.json +2 -2
  8. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +7 -0
  9. package/tiledeskChatbotPlugs/directives/DirAddKbContent.js +333 -0
  10. package/tiledeskChatbotPlugs/directives/DirAddTags.js +13 -19
  11. package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +17 -17
  12. package/tiledeskChatbotPlugs/directives/DirAskGPT.js +2 -1
  13. package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +19 -16
  14. package/tiledeskChatbotPlugs/directives/DirAssign.js +0 -6
  15. package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +1 -6
  16. package/tiledeskChatbotPlugs/directives/DirAssistant.js +13 -2
  17. package/tiledeskChatbotPlugs/directives/DirBrevo.js +11 -6
  18. package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +10 -0
  19. package/tiledeskChatbotPlugs/directives/DirClearTranscript.js +5 -0
  20. package/tiledeskChatbotPlugs/directives/DirClose.js +8 -7
  21. package/tiledeskChatbotPlugs/directives/DirCode.js +9 -0
  22. package/tiledeskChatbotPlugs/directives/DirCondition.js +13 -0
  23. package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +7 -7
  24. package/tiledeskChatbotPlugs/directives/DirCustomerio.js +11 -1
  25. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +1 -6
  26. package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +14 -0
  27. package/tiledeskChatbotPlugs/directives/DirDepartment.js +14 -8
  28. package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +3 -7
  29. package/tiledeskChatbotPlugs/directives/DirFlowLog.js +22 -10
  30. package/tiledeskChatbotPlugs/directives/DirForm.js +4 -9
  31. package/tiledeskChatbotPlugs/directives/DirGptTask.js +19 -6
  32. package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +3 -1
  33. package/tiledeskChatbotPlugs/directives/DirHubspot.js +12 -2
  34. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +4 -8
  35. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +12 -8
  36. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +11 -0
  37. package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +4 -8
  38. package/tiledeskChatbotPlugs/directives/DirIntent.js +5 -6
  39. package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +14 -3
  40. package/tiledeskChatbotPlugs/directives/DirMake.js +6 -0
  41. package/tiledeskChatbotPlugs/directives/DirMessage.js +1 -6
  42. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +5 -7
  43. package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +6 -7
  44. package/tiledeskChatbotPlugs/directives/DirQapla.js +7 -2
  45. package/tiledeskChatbotPlugs/directives/DirRandomReply.js +7 -7
  46. package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +1 -6
  47. package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +7 -7
  48. package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +7 -7
  49. package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +7 -7
  50. package/tiledeskChatbotPlugs/directives/DirReply.js +9 -11
  51. package/tiledeskChatbotPlugs/directives/DirReplyV2.js +8 -8
  52. package/tiledeskChatbotPlugs/directives/DirSendEmail.js +7 -7
  53. package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +7 -1
  54. package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +7 -0
  55. package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +2 -7
  56. package/tiledeskChatbotPlugs/directives/DirWait.js +6 -0
  57. package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +16 -13
  58. package/tiledeskChatbotPlugs/directives/DirWebResponse.js +6 -4
  59. package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +7 -0
  60. package/tiledeskChatbotPlugs/directives/Directives.js +1 -0
  61. package/utils/TiledeskChatbotUtil.js +3 -1
@@ -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 DirCustomerio {
11
12
 
@@ -18,22 +19,27 @@ class DirCustomerio {
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
+
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 });
23
26
  }
24
27
 
25
28
  execute(directive, callback) {
29
+ this.logger.info("[Customer.io] Executing action");
26
30
  winston.verbose("Execute Customerio directive");
27
31
  let action;
28
32
  if (directive.action) {
29
33
  action = directive.action;
30
34
  }
31
35
  else {
36
+ this.logger.error("Incorrect action for ", directive.name, directive)
32
37
  winston.warn("DirCustomerio Incorrect directive: ", directive);
33
38
  callback();
34
39
  return;
35
40
  }
36
41
  this.go(action, (stop) => {
42
+ this.logger.info("[Customer.io] Action completed");
37
43
  callback(stop);
38
44
  })
39
45
  }
@@ -65,6 +71,7 @@ class DirCustomerio {
65
71
  winston.debug("(DirCustomerio) bodyParameters: ", bodyParameters);
66
72
 
67
73
  if (!bodyParameters || bodyParameters === '') {
74
+ this.logger.error("[Customer.io] bodyParameters is undefined or null or empty string");
68
75
  winston.debug("(DirCustomerio) Error: bodyParameters is undefined or null or empty string");
69
76
  callback();
70
77
  return;
@@ -75,6 +82,7 @@ class DirCustomerio {
75
82
 
76
83
  let key = await integrationService.getKeyFromIntegrations(this.projectId, 'customerio', this.token);
77
84
  if (!key) {
85
+ this.logger.error("[Customer.io] Key not found in Integrations");
78
86
  winston.debug("(DirCustomerio) - Key not found in Integrations.");
79
87
  let status = 422;
80
88
  let error = 'Missing customerio access token';
@@ -116,6 +124,7 @@ class DirCustomerio {
116
124
  CUSTOMERIO_HTTPREQUEST, async (err, resbody) => {
117
125
  if (err) {
118
126
  if (callback) {
127
+ this.logger.error("[Customer.io] Error response: ", err.response);
119
128
  winston.debug("(DirCustomerio) err response:", err.response)
120
129
  winston.debug("(DirCustomerio) err data:", err.response.data)
121
130
 
@@ -150,6 +159,7 @@ class DirCustomerio {
150
159
 
151
160
  let status = 204;
152
161
  let error = null;
162
+ this.logger.error("[Customer.io] Response status: ", status);
153
163
  await this.#assignAttributes(action, status, error);
154
164
  if (trueIntent) {
155
165
  await this.#executeCondition(true, trueIntent, null, falseIntent, null);
@@ -14,12 +14,7 @@ class DirDeflectToHelpCenter {
14
14
  this.context = context;
15
15
  this.API_ENDPOINT = context.API_ENDPOINT;
16
16
 
17
- this.tdClient = new TiledeskClient({
18
- projectId: this.context.projectId,
19
- token: this.context.token,
20
- APIURL: this.API_ENDPOINT,
21
- APIKEY: "___"
22
- });
17
+ this.tdClient = new TiledeskClient({ projectId: this.context.projectId, token: this.context.token, APIURL: this.API_ENDPOINT, APIKEY: "___", log: this.log });
23
18
  }
24
19
 
25
20
  async execute(directive, callback) {
@@ -3,6 +3,7 @@ const ms = require('minimist-string');
3
3
  const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
4
4
  const { Filler } = require('../Filler');
5
5
  const winston = require('../../utils/winston');
6
+ const { Logger } = require('../../Logger');
6
7
 
7
8
  class DirDeleteVariable {
8
9
 
@@ -11,9 +12,13 @@ class DirDeleteVariable {
11
12
  throw new Error('context object is mandatory.');
12
13
  }
13
14
  this.context = context;
15
+ this.requestId = this.context.requestId;
16
+
17
+ this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
14
18
  }
15
19
 
16
20
  async execute(directive, callback) {
21
+ this.logger.info("[Delete Attribute] Executing action");
17
22
  winston.verbose("Execute DeleteVariable directive");
18
23
  let action;
19
24
  if (directive.action) {
@@ -24,7 +29,14 @@ class DirDeleteVariable {
24
29
  variableName: directive.parameter
25
30
  }
26
31
  }
32
+ else {
33
+ this.logger.error("Incorrect action for ", directive.name, directive)
34
+ winston.warn("(DirDeleteVariable) Incorrect directive: ", directive);
35
+ callback();
36
+ return;
37
+ }
27
38
  this.go(action, () => {
39
+ this.logger.info("[Delete Attribute] Action completed");
28
40
  callback();
29
41
  });
30
42
  }
@@ -34,6 +46,7 @@ class DirDeleteVariable {
34
46
 
35
47
  let variableName = action.variableName;
36
48
  if (!variableName) {
49
+ this.logger.warn("[Delete Attribute] Missing 'variableName'. Skip")
37
50
  winston.error("(DirDeleteVariable) deleting variable. Missing 'variableName' error. Skipping");
38
51
  if (callback) {
39
52
  callback();
@@ -59,6 +72,7 @@ class DirDeleteVariable {
59
72
  }
60
73
  }
61
74
  catch(err) {
75
+ this.logger.error("[Delete Attribute] Error deleting attribute");
62
76
  winston.error("(DirDeleteVariable) error: ", err);
63
77
  if (completion) {
64
78
  completion();
@@ -1,5 +1,6 @@
1
1
  const { TiledeskClient } = require("@tiledesk/tiledesk-client");
2
2
  const winston = require('../../utils/winston');
3
+ const { Logger } = require("../../Logger");
3
4
 
4
5
  class DirDepartment {
5
6
 
@@ -10,16 +11,14 @@ class DirDepartment {
10
11
  this.context = context;
11
12
  this.requestId = context.requestId;
12
13
  this.API_ENDPOINT = context.API_ENDPOINT;
13
-
14
- this.tdClient = new TiledeskClient({
15
- projectId: this.context.projectId,
16
- token: this.context.token,
17
- APIURL: this.API_ENDPOINT,
18
- APIKEY: "___"
19
- });
14
+ this.log = context.log;
15
+
16
+ this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
17
+ this.tdClient = new TiledeskClient({ projectId: this.context.projectId, token: this.context.token, APIURL: this.API_ENDPOINT, APIKEY: "___" });
20
18
  }
21
19
 
22
20
  execute(directive, callback) {
21
+ this.logger.info("[Change Department] Executing action");
23
22
  winston.verbose("Execute Department directive");
24
23
  let action;
25
24
  if (directive.action) {
@@ -35,6 +34,7 @@ class DirDepartment {
35
34
  }
36
35
  }
37
36
  this.go(action, () => {
37
+ this.logger.info("[Change Department] Action executed");
38
38
  callback();
39
39
  });
40
40
 
@@ -64,6 +64,7 @@ class DirDepartment {
64
64
  const depName = action.depName;
65
65
  this.moveToDepartment(this.requestId, depName, (deps) => {
66
66
  if (!deps) {
67
+ this.logger.warn("[Change Department] Department not found");
67
68
  winston.warn("(DirDepartment) Dep not found");
68
69
  callback();
69
70
  return
@@ -92,14 +93,19 @@ class DirDepartment {
92
93
  this.requestId,
93
94
  message, (err) => {
94
95
  if (err) {
96
+ this.logger.error("[Change Department] Unable to trigger bot");
95
97
  winston.error("(DirDepartment) Error sending hidden message: " + err.message)
98
+ } else {
99
+ this.logger.debug("[Change Department] Bot triggered");
100
+ winston.debug("(DirDepartment) Hidden message sent.");
101
+
96
102
  }
97
- winston.debug("(DirDepartment) Hidden message sent.");
98
103
  callback();
99
104
  });
100
105
  }
101
106
  }
102
107
  else {
108
+ this.logger.debug("[Change Department] No triggering bot");
103
109
  winston.debug("(DirDepartment) No action.triggerBot");
104
110
  callback();
105
111
  }
@@ -10,14 +10,10 @@ class DirFireTiledeskEvent {
10
10
  }
11
11
 
12
12
  this.context = context;
13
-
13
+ this.log = context.log;
14
14
  this.API_ENDPOINT = context.API_ENDPOINT;
15
- this.tdClient = new TiledeskClient({
16
- projectId: this.context.projectId,
17
- token: this.context.token,
18
- APIURL: this.API_ENDPOINT,
19
- APIKEY: "___"
20
- });
15
+
16
+ this.tdClient = new TiledeskClient({ projectId: this.context.projectId, token: this.context.token, APIURL: this.API_ENDPOINT, APIKEY: "___", log: this.log });
21
17
  }
22
18
 
23
19
  execute(directive, callback) {
@@ -1,7 +1,10 @@
1
1
 
2
2
 
3
3
  const { Logger } = require('../../Logger');
4
+ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
5
+ const { Filler } = require('../Filler');
4
6
  const winston = require('../../utils/winston');
7
+
5
8
  let levels = ['error', 'warn', 'info', 'debug'];
6
9
 
7
10
  class DirFlowLog {
@@ -16,7 +19,7 @@ class DirFlowLog {
16
19
  this.requestId = context.requestId;
17
20
  this.log = context.log;
18
21
 
19
- this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest.draft });
22
+ this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
20
23
  }
21
24
 
22
25
  execute(directive, callback) {
@@ -38,7 +41,6 @@ class DirFlowLog {
38
41
 
39
42
  async go(action, callback) {
40
43
  winston.debug("(DirFlowLog) Action: ", action);
41
- console.log("(DirFlowLog) Action: ", action);
42
44
 
43
45
  let level = action.level || 'info';
44
46
  if (!levels.includes(level)) {
@@ -52,21 +54,31 @@ class DirFlowLog {
52
54
  callback();
53
55
  }
54
56
 
57
+ let requestVariables = null;
58
+ requestVariables =
59
+ await TiledeskChatbot.allParametersStatic(
60
+ this.tdcache, this.requestId
61
+ );
62
+
63
+ const filler = new Filler();
64
+ const filled_log = filler.fill(action.log, requestVariables);
65
+ winston.debug("(DirFlowLog) fille log: ", filled_log);
66
+
55
67
  if (level === 'error') {
56
- winston.info("Adding log " + action.log + " with level " + level);
57
- this.logger.error(action.log);
68
+ winston.info("Adding log '" + filled_log + "' with level " + level);
69
+ this.logger.error(filled_log);
58
70
  }
59
71
  else if (level === 'warn') {
60
- winston.info("Adding log " + action.log + " with level " + level);
61
- this.logger.warn(action.log);
72
+ winston.info("Adding log '" + filled_log + "' with level " + level);
73
+ this.logger.warn(filled_log);
62
74
  }
63
75
  else if (level === 'info') {
64
- winston.info("Adding log " + action.log + " with level " + level);
65
- this.logger.info(action.log);
76
+ winston.info("Adding log '" + filled_log + "' with level " + level);
77
+ this.logger.info(filled_log);
66
78
  }
67
79
  else if (level === 'debug') {
68
- winston.info("Adding log " + action.log + " with level " + level);
69
- this.logger.debug(action.log);
80
+ winston.info("Adding log '" + filled_log + "' with level " + level);
81
+ this.logger.debug(filled_log);
70
82
  }
71
83
 
72
84
  callback();
@@ -14,16 +14,11 @@ class DirForm {
14
14
  this.chatbot = context.chatbot;
15
15
  this.tdcache = context.tdcache;
16
16
  this.requestId = context.requestId;
17
- this.intentDir = new DirIntent(context);
18
-
17
+ this.log = context.log;
19
18
  this.API_ENDPOINT = context.API_ENDPOINT;
20
- this.tdClient = new TiledeskClient({
21
- projectId: this.context.projectId,
22
- token: this.context.token,
23
- APIURL: this.API_ENDPOINT,
24
- APIKEY: "___"
25
- });
26
-
19
+
20
+ this.intentDir = new DirIntent(context);
21
+ this.tdClient = new TiledeskClient({ projectId: this.context.projectId, token: this.context.token, APIURL: this.API_ENDPOINT, APIKEY: "___", log: this.log });
27
22
  }
28
23
 
29
24
  execute(directive, callback) {
@@ -9,6 +9,7 @@ require('dotenv').config();
9
9
  const winston = require('../../utils/winston');
10
10
  const httpUtils = require("../../utils/HttpUtils");
11
11
  const integrationService = require("../../services/IntegrationService");
12
+ const { Logger } = require("../../Logger");
12
13
 
13
14
  class DirGptTask {
14
15
 
@@ -22,22 +23,27 @@ class DirGptTask {
22
23
  this.requestId = this.context.requestId;
23
24
  this.projectId = this.context.projectId;
24
25
  this.token = this.context.token;
25
- this.intentDir = new DirIntent(context);
26
26
  this.API_ENDPOINT = this.context.API_ENDPOINT;
27
+
28
+ this.intentDir = new DirIntent(context);
29
+ this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
27
30
  }
28
31
 
29
32
  execute(directive, callback) {
33
+ this.logger.info("[ChatGPT Task] Executing action");
30
34
  winston.verbose("Execute GptTask directive");
31
35
  let action;
32
36
  if (directive.action) {
33
37
  action = directive.action;
34
38
  }
35
39
  else {
40
+ this.logger.error("Incorrect action for ", directive.name, directive)
36
41
  winston.warn("DirGptTask Incorrect directive: ", directive);
37
42
  callback();
38
43
  return;
39
44
  }
40
45
  this.go(action, (stop) => {
46
+ this.logger.info("[ChatGPT Task] Action completed");
41
47
  callback(stop);
42
48
  })
43
49
  }
@@ -67,6 +73,7 @@ class DirGptTask {
67
73
  let model = "gpt-3.5-turbo";
68
74
 
69
75
  if (!action.question || action.question === '') {
76
+ this.logger.warn("[ChatGPT Task] question attribute is mandatory");
70
77
  winston.debug("(DirGptTask) Error: question attribute is mandatory. Executing condition false...")
71
78
  if (falseIntent) {
72
79
  await this.chatbot.addParameter("flowError", "GPT Error: question attribute is undefined");
@@ -103,13 +110,13 @@ class DirGptTask {
103
110
  this.context.tdcache,
104
111
  this.context.requestId,
105
112
  TiledeskChatbotConst.REQ_TRANSCRIPT_KEY);
106
- winston.debug("(DirGptTask) transcript string: " + transcript_string)
113
+ winston.debug("(DirGptTask) transcript string: " + transcript_string)
107
114
 
108
115
  if (transcript_string) {
109
116
  transcript = await TiledeskChatbotUtil.transcriptJSON(transcript_string);
110
- winston.debug("(DirGptTask) transcript: ", transcript)
117
+ winston.debug("(DirGptTask) transcript: ", transcript)
111
118
  } else {
112
- winston.debug("(DirGptTask) transcript_string is undefined. Skip JSON translation for chat history");
119
+ winston.debug("(DirGptTask) transcript_string is undefined. Skip JSON translation for chat history");
113
120
  }
114
121
  }
115
122
 
@@ -118,17 +125,20 @@ class DirGptTask {
118
125
 
119
126
  let key = await integrationService.getKeyFromIntegrations(this.projectId, 'openai', this.token);
120
127
  if (!key) {
128
+ this.logger.debug("[ChatGPT Task] Key not found in Integrations.");
121
129
  winston.debug("(DirGptTask) - Key not found in Integrations. Searching in kb settings...");
122
130
  key = await this.getKeyFromKbSettings();
123
131
  }
124
132
 
125
133
  if (!key) {
126
- winston.debug("(DirGptTask) - Retrieve public gptkey")
134
+ this.logger.debug("[ChatGPT Task] Retrieve shared gptkey.");
135
+ winston.debug("(DirGptTask) - Retrieve public gptkey")
127
136
  key = process.env.GPTKEY;
128
137
  publicKey = true;
129
138
  }
130
139
 
131
140
  if (!key) {
141
+ this.logger.error("[ChatGPT Task] OpenAI key is mandatory");
132
142
  winston.error("(DirGptTask) gptkey is mandatory");
133
143
  await this.#assignAttributes(action, answer);
134
144
  if (falseIntent) {
@@ -144,7 +154,7 @@ class DirGptTask {
144
154
  if (publicKey === true) {
145
155
  let keep_going = await this.checkQuoteAvailability();
146
156
  if (keep_going === false) {
147
-
157
+ this.logger.warn("[ChatGPT Task] OpenAI tokens quota exceeded");
148
158
  await this.chatbot.addParameter("flowError", "GPT Error: tokens quota exceeded");
149
159
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
150
160
  callback();
@@ -201,6 +211,7 @@ class DirGptTask {
201
211
  if (err) {
202
212
  winston.debug("(DirGptTask) openai err: ", err);
203
213
  winston.debug("(DirGptTask) openai err: " + err.response?.data?.error?.message);
214
+ this.logger.error("[ChatGPT Task] Completions error: ", err.response?.data?.error?.message);
204
215
  await this.#assignAttributes(action, answer);
205
216
  if (falseIntent) {
206
217
  await this.chatbot.addParameter("flowError", "GPT Error: " + err.response?.data?.error?.message);
@@ -218,6 +229,8 @@ class DirGptTask {
218
229
  answer = await this.convertToJson(answer);
219
230
  }
220
231
 
232
+ this.logger.debug("[ChatGPT Task] Completions answer: ", answer);
233
+
221
234
  await this.#assignAttributes(action, answer);
222
235
 
223
236
  if (publicKey === true) {
@@ -16,8 +16,10 @@ class DirGptTask {
16
16
  this.context = context;
17
17
  this.tdcache = this.context.tdcache;
18
18
  this.requestId = this.context.requestId;
19
- this.intentDir = new DirIntent(context);
20
19
  this.API_ENDPOINT = this.context.API_ENDPOINT;
20
+ this.log = context.log;
21
+
22
+ this.intentDir = new DirIntent(context);
21
23
  }
22
24
 
23
25
  execute(directive, callback) {
@@ -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 DirHubspot {
11
12
 
@@ -18,22 +19,27 @@ class DirHubspot {
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
+
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 });
23
26
  }
24
27
 
25
28
  execute(directive, callback) {
29
+ this.logger.info("[Hubspot] Executing action");
26
30
  winston.verbose("Execute Hubspot directive");
27
31
  let action;
28
32
  if (directive.action) {
29
33
  action = directive.action;
30
34
  }
31
35
  else {
36
+ this.logger.error("Incorrect action for ", directive.name, directive)
32
37
  winston.warn("DirHubspot Incorrect directive: ", directive);
33
38
  callback();
34
39
  return;
35
40
  }
36
41
  this.go(action, (stop) => {
42
+ this.logger.info("[Hubspot] Action completed");
37
43
  callback(stop);
38
44
  })
39
45
  }
@@ -67,6 +73,7 @@ class DirHubspot {
67
73
  winston.debug("(DirHubspot) bodyParameters: ", bodyParameters);
68
74
 
69
75
  if (!bodyParameters || bodyParameters === '') {
76
+ this.logger.error("[Hubspot] bodyParameters is undefined or null or empty string");
70
77
  winston.error("(DirHubspot) Error: bodyParameters is undefined or null or empty string");
71
78
  callback();
72
79
  return;
@@ -77,7 +84,8 @@ class DirHubspot {
77
84
 
78
85
  let key = await integrationService.getKeyFromIntegrations(this.projectId, 'hubspot', this.token);
79
86
  if (!key) {
80
- winston.debug("(DirHubspot) - Key not found in Integrations.");
87
+ this.logger.error("[Hubspot] Key not found in Integrations");
88
+ winston.debug("(DirHubspot) - Key not found in Integrations.");
81
89
  if (falseIntent) {
82
90
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
83
91
  callback(true);
@@ -112,6 +120,7 @@ class DirHubspot {
112
120
  HUBSPOT_HTTPREQUEST, async (err, resbody) => {
113
121
  if (err) {
114
122
  if (callback) {
123
+ this.logger.error("[Hubspot] Error response: ", err.response);
115
124
  winston.error("(DirHubspot) err response: ", err.response.data)
116
125
  let result = null;
117
126
  let status = null;
@@ -147,6 +156,7 @@ class DirHubspot {
147
156
  let status = 201;
148
157
  let error = null;
149
158
  let result = resbody;
159
+ this.logger.error("[Hubspot] Result: ", result);
150
160
  await this.#assignAttributes(action, status, result, error);
151
161
  if (trueIntent) {
152
162
  await this.#executeCondition(true, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes)
@@ -11,15 +11,11 @@ class DirIfOnlineAgents {
11
11
  }
12
12
 
13
13
  this.context = context;
14
- this.intentDir = new DirIntent(context);
15
14
  this.API_ENDPOINT = context.API_ENDPOINT;
16
-
17
- this.tdClient = new TiledeskClient({
18
- projectId: this.context.projectId,
19
- token: this.context.token,
20
- APIURL: this.API_ENDPOINT,
21
- APIKEY: "___"
22
- });
15
+ this.log = context.log;
16
+
17
+ this.intentDir = new DirIntent(context);
18
+ this.tdClient = new TiledeskClient({ projectId: this.context.projectId, token: this.context.token, APIURL: this.API_ENDPOINT, APIKEY: "___", log: this.log });
23
19
  }
24
20
 
25
21
  execute(directive, callback) {
@@ -5,6 +5,7 @@ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
5
5
  const { TiledeskClient } = require('@tiledesk/tiledesk-client');
6
6
  const winston = require('../../utils/winston');
7
7
  const httpUtils = require('../../utils/HttpUtils');
8
+ const { Logger } = require('../../Logger');
8
9
 
9
10
  class DirIfOnlineAgentsV2 {
10
11
 
@@ -14,30 +15,30 @@ class DirIfOnlineAgentsV2 {
14
15
  }
15
16
  this.context = context;
16
17
  this.chatbot = context.chatbot;
17
- this.intentDir = new DirIntent(context);
18
+ this.requestId = this.context.requestId;
18
19
  this.API_ENDPOINT = context.API_ENDPOINT;
19
-
20
- this.tdClient = new TiledeskClient({
21
- projectId: this.context.projectId,
22
- token: this.context.token,
23
- APIURL: this.API_ENDPOINT,
24
- APIKEY: "___",
25
- });
20
+
21
+ this.intentDir = new DirIntent(context);
22
+ this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
23
+ this.tdClient = new TiledeskClient({ projectId: this.context.projectId, token: this.context.token, APIURL: this.API_ENDPOINT, APIKEY: "___" });
26
24
 
27
25
  }
28
26
 
29
27
  execute(directive, callback) {
28
+ this.logger.info("[If Online Agents] Executing action");
30
29
  winston.verbose("Execute IfOnlineAgentsV2 directive");
31
30
  let action;
32
31
  if (directive.action) {
33
32
  action = directive.action
34
33
  }
35
34
  else {
35
+ this.logger.error("Incorrect action for ", directive.name, directive)
36
36
  winston.warn("DirIfOnlineAgentsV2 Incorrect directive: ", directive);
37
37
  callback();
38
38
  return;
39
39
  }
40
40
  this.go(action, (stop) => {
41
+ this.logger.info("[If Online Agents] Action completed");
41
42
  callback(stop);
42
43
  });
43
44
  }
@@ -46,6 +47,7 @@ class DirIfOnlineAgentsV2 {
46
47
  winston.debug("(DirIfOnlineAgentsV2) Action: ", action);
47
48
 
48
49
  if (!action.trueIntent && !action.falseIntent) {
50
+ this.logger.error("[If Online Agents] missing both action.trueIntent & action.falseIntent");
49
51
  winston.error("(DirIfOnlineAgentsV2) Error: missing both action.trueIntent & action.falseIntent");
50
52
  callback();
51
53
  return;
@@ -90,6 +92,7 @@ class DirIfOnlineAgentsV2 {
90
92
  if (departmentId) {
91
93
  agents = await this.getProjectAvailableAgents(departmentId, true);
92
94
  } else {
95
+ this.logger.error("[If Online Agents] No departmentId found in attributes");
93
96
  winston.error("(DirIfOnlineAgentsV2) no departmentId found in attributes");
94
97
  await this.chatbot.addParameter("flowError", "(If online Agents) No departmentId found in attributes.");
95
98
  if (falseIntent) { // no agents available
@@ -153,6 +156,7 @@ class DirIfOnlineAgentsV2 {
153
156
  }
154
157
  }
155
158
  catch(err) {
159
+ this.logger.error("[If Online Agents] An error occurred: ", err);
156
160
  winston.error("(DirIfOnlineAgentsV2) An error occurred: ", err);
157
161
  this.chatbot.addParameter("flowError", "(If online Agents) An error occurred: " + err);
158
162
  callback();
@@ -4,6 +4,7 @@ let https = require("https");
4
4
  const ms = require('minimist-string');
5
5
  const winston = require('../../utils/winston');
6
6
  const httpUtils = require('../../utils/HttpUtils');
7
+ const { Logger } = require('../../Logger');
7
8
 
8
9
  class DirIfOpenHours {
9
10
 
@@ -13,11 +14,15 @@ class DirIfOpenHours {
13
14
  }
14
15
 
15
16
  this.context = context;
17
+ this.requestId = this.context.requestId;
16
18
  this.API_ENDPOINT = context.API_ENDPOINT;
19
+
17
20
  this.intentDir = new DirIntent(context);
21
+ this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
18
22
  }
19
23
 
20
24
  execute(directive, callback) {
25
+ this.logger.info("[If Operating Hours] Executing action");
21
26
  winston.verbose("Execute IfOpenHours directive");
22
27
  let action;
23
28
  if (directive.action) {
@@ -37,11 +42,13 @@ class DirIfOpenHours {
37
42
  }
38
43
  }
39
44
  else {
45
+ this.logger.error("Incorrect action for ", directive.name, directive)
40
46
  winston.warn("DirIfOpenHours Incorrect directive: ", directive);
41
47
  callback();
42
48
  return;
43
49
  }
44
50
  this.go(action, (stop) => {
51
+ this.logger.info("[If Operating Hours] Action complteted");
45
52
  callback(stop);
46
53
  });
47
54
  }
@@ -63,6 +70,7 @@ class DirIfOpenHours {
63
70
  }
64
71
 
65
72
  if (!trueIntent && !falseIntent) {
73
+ this.logger.error("[If Operating Hours] Invalid condition, no intents specified");
66
74
  winston.error("(DirIfOpenHours) Invalid condition, no intents specified");
67
75
  callback();
68
76
  return;
@@ -94,6 +102,7 @@ class DirIfOpenHours {
94
102
  winston.debug("(DirIfOpenHours) resbody:", resbody);
95
103
 
96
104
  if (err) {
105
+ this.logger.error("[If Operating Hours] Error response: ", err.response);
97
106
  winston.debug("(DirIfOpenHours) error: ", err);
98
107
  if (callback) {
99
108
  if (falseIntent) {
@@ -106,6 +115,7 @@ class DirIfOpenHours {
106
115
  }
107
116
  } else {
108
117
  if (resbody.isopen && resbody.isopen === true) {
118
+ this.logger.debug("[If Operating Hours] is open: true")
109
119
  if (trueIntent) {
110
120
  let intentDirective = DirIntent.intentDirectiveFor(trueIntent);
111
121
  winston.debug("(DirIfOpenHours) agents (openHours) => trueIntent");
@@ -116,6 +126,7 @@ class DirIfOpenHours {
116
126
  callback();
117
127
  return;
118
128
  } else {
129
+ this.logger.debug("[If Operating Hours] is open: false")
119
130
  if (falseIntent) {
120
131
  let intentDirective = DirIntent.intentDirectiveFor(falseIntent);
121
132
  winston.debug("(DirIfOpenHours) !agents (openHours) => falseIntent", falseIntent);