@tiledesk/tiledesk-tybot-connector 2.0.12-rc5 → 2.0.12-rc6

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 (44) hide show
  1. package/ExtApi.js +1 -8
  2. package/ExtUtil.js +5 -6
  3. package/engine/IntentForm.js +0 -1
  4. package/engine/IntentsMachineFactory.js +4 -4
  5. package/engine/MongodbBotsDataSource.js +0 -1
  6. package/engine/MongodbIntentsMachine.js +0 -1
  7. package/engine/TiledeskChatbot.js +11 -16
  8. package/engine/TiledeskIntentsMachine.js +1 -2
  9. package/index.js +11 -23
  10. package/package.json +1 -1
  11. package/services/AIService.js +1 -1
  12. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +10 -10
  13. package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +1 -2
  14. package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +1 -3
  15. package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +1 -3
  16. package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +7 -9
  17. package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfNotOpenHours.js +3 -10
  18. package/tiledeskChatbotPlugs/directives/DEPRECATED_DirIfOpenHours.js +2 -9
  19. package/tiledeskChatbotPlugs/directives/DirAddKbContent.js +333 -0
  20. package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +0 -1
  21. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +1 -3
  22. package/tiledeskChatbotPlugs/directives/DirFlowLog.js +1 -1
  23. package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +36 -54
  24. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +0 -1
  25. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +1 -2
  26. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +0 -1
  27. package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +7 -9
  28. package/tiledeskChatbotPlugs/directives/DirIntent.js +0 -1
  29. package/tiledeskChatbotPlugs/directives/DirLockIntent.js +0 -1
  30. package/tiledeskChatbotPlugs/directives/DirMake.js +1 -15
  31. package/tiledeskChatbotPlugs/directives/DirMessage.js +0 -1
  32. package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +0 -1
  33. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +0 -1
  34. package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +0 -1
  35. package/tiledeskChatbotPlugs/directives/DirReply.js +1 -1
  36. package/tiledeskChatbotPlugs/directives/DirReplyV2.js +8 -10
  37. package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +0 -1
  38. package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +1 -3
  39. package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +0 -1
  40. package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +0 -1
  41. package/tiledeskChatbotPlugs/directives/DirWebRequest.js +0 -1
  42. package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +1 -15
  43. package/tiledeskChatbotPlugs/directives/Directives.js +1 -0
  44. package/utils/TiledeskChatbotUtil.js +14 -28
@@ -0,0 +1,333 @@
1
+ const axios = require("axios").default;
2
+ const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
3
+ const { Filler } = require('../Filler');
4
+ let https = require("https");
5
+ const { DirIntent } = require("./DirIntent");
6
+ const { TiledeskChatbotConst } = require("../../engine/TiledeskChatbotConst");
7
+ const { TiledeskChatbotUtil } = require("../../utils/TiledeskChatbotUtil");
8
+ const assert = require("assert");
9
+ require('dotenv').config();
10
+ const winston = require('../../utils/winston');
11
+ const httpUtils = require("../../utils/HttpUtils");
12
+ const integrationService = require("../../services/IntegrationService");
13
+ const { Logger } = require("../../Logger");
14
+
15
+ class DirAddKbContent {
16
+
17
+ constructor(context) {
18
+ if (!context) {
19
+ throw new Error('context object is mandatory');
20
+ }
21
+ this.context = context;
22
+ this.chatbot = context.chatbot;
23
+ this.tdcache = this.context.tdcache;
24
+ this.requestId = this.context.requestId;
25
+ this.projectId = this.context.projectId;
26
+ this.token = this.context.token;
27
+ this.API_ENDPOINT = this.context.API_ENDPOINT;
28
+ this.log = context.log;
29
+
30
+ this.intentDir = new DirIntent(context);
31
+ this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
32
+ }
33
+
34
+ execute(directive, callback) {
35
+ this.logger.info("Execute AskKnowledgeBase action")
36
+ winston.debug("DirAskGPTV2 directive: ", directive);
37
+ let action;
38
+ if (directive.action) {
39
+ action = directive.action;
40
+ }
41
+ else {
42
+ this.logger.error("Incorrect action for ", directive.name, directive)
43
+ winston.debug("DirAskGPTV2 Incorrect directive: ", directive);
44
+ callback();
45
+ return;
46
+ }
47
+ this.go(action, (stop) => {
48
+ this.logger.info("Acion AskKnowledgeBase completed");
49
+ callback(stop);
50
+ })
51
+ }
52
+
53
+ async go(action, callback) {
54
+ winston.debug("[DirAddKbContent] action:", action);
55
+ if (!this.tdcache) {
56
+ winston.error("[DirAddKbContent] Error: tdcache is mandatory");
57
+ callback();
58
+ return;
59
+ }
60
+
61
+ let publicKey = false;
62
+ let type = action.type;
63
+ let name = action.name;
64
+ let content = action.content;
65
+ let engine;
66
+
67
+ // default values
68
+ let namespace = this.context.projectId;
69
+
70
+ if (action.namespace) {
71
+ namespace = action.namespace;
72
+ }
73
+
74
+ let requestVariables = null;
75
+ requestVariables =
76
+ await TiledeskChatbot.allParametersStatic(
77
+ this.tdcache, this.requestId
78
+ );
79
+
80
+ const filler = new Filler();
81
+ const filled_content = filler.fill(content, requestVariables);
82
+ const filled_name = filler.fill(name, requestVariables);
83
+
84
+ const kb_endpoint = process.env.API_ENDPOINT;
85
+ winston.verbose("[DirAddKbContent] KbEndpoint URL: " + kb_endpoint);
86
+
87
+ let key = await integrationService.getKeyFromIntegrations(this.projectId, 'openai', this.token);
88
+ if (!key) {
89
+ this.logger.debug("[DirAddKbContent] OpenAI key not found in Integration. Using shared OpenAI key");
90
+ winston.verbose("[DirAddKbContent] - Key not found in Integrations. Searching in kb settings...");
91
+ key = await this.getKeyFromKbSettings();
92
+ }
93
+
94
+ if (!key) {
95
+ winston.verbose("[DirAddKbContent] - Retrieve public gptkey")
96
+ key = process.env.GPTKEY;
97
+ publicKey = true;
98
+ } else {
99
+ this.logger.debug("[DirAddKbContent] use your own OpenAI key")
100
+ }
101
+
102
+ if (!key) {
103
+ winston.info("[DirAddKbContent] Error: gptkey is mandatory");
104
+ await this.chatbot.addParameter("flowError", "[DirAddKbContent] Error: gptkey is mandatory");
105
+ callback();
106
+ return;
107
+ }
108
+
109
+ if (publicKey === true) {
110
+ let keep_going = await this.checkQuoteAvailability();
111
+ if (keep_going === false) {
112
+ this.logger.warn("[DirAddKbContent] Tokens quota exceeded. Skip the action")
113
+ winston.verbose("[DirAddKbContent] - Quota exceeded for tokens. Skip the action")
114
+ await this.chatbot.addParameter("flowError", "[DirAddKbContent] Error: tokens quota exceeded");
115
+ callback(true);
116
+ return;
117
+ }
118
+ }
119
+
120
+ let ns;
121
+
122
+ if (action.namespaceAsName) {
123
+ // Namespace could be an attribute
124
+ const filled_namespace = filler.fill(action.namespace, requestVariables)
125
+ this.logger.debug("[DirAddKbContent] Searching namespace by name ", filled_namespace);
126
+ ns = await this.getNamespace(filled_namespace, null);
127
+ namespace = ns?.id;
128
+ winston.verbose("[DirAddKbContent] - Retrieved namespace id from name " + namespace);
129
+ } else {
130
+ this.logger.debug("[DirAddKbContent] Searching namespace by id ", namespace);
131
+ ns = await this.getNamespace(null, namespace);
132
+ }
133
+
134
+ if (!ns) {
135
+ this.logger.error("[DirAddKbContent] Namespace not found");
136
+ await this.chatbot.addParameter("flowError", "[DirAddKbContent] Error: namespace not found");
137
+ callback();
138
+ return;
139
+ }
140
+
141
+ if (ns.engine) {
142
+ engine = ns.engine;
143
+ } else {
144
+ engine = await this.setDefaultEngine()
145
+ }
146
+
147
+ if (!namespace) {
148
+ this.logger.error("[DirAddKbContent] Namespace is undefined")
149
+ winston.verbose("[DirAddKbContent] - Error: namespace is undefined")
150
+ await this.chatbot.addParameter("flowError", "[DirAddKbContent] Error: namespace is undefined");
151
+ callback(true);
152
+ return;
153
+ }
154
+
155
+ let json = {
156
+ content: filled_content,
157
+ namespace: namespace,
158
+ type: type,
159
+ name: filled_name,
160
+ source: filled_name
161
+ };
162
+
163
+ winston.debug("[DirAddKbContent] json:", json);
164
+
165
+ const HTTPREQUEST = {
166
+ url: kb_endpoint + "/" + this.projectId + "/kb",
167
+ headers: {
168
+ 'Content-Type': 'application/json',
169
+ 'Authorization': 'JWT ' + this.context.token
170
+ },
171
+ json: json,
172
+ method: "POST"
173
+ }
174
+ winston.debug("[DirAddKbContent] HttpRequest: ", HTTPREQUEST);
175
+
176
+ httpUtils.request(
177
+ HTTPREQUEST, async (err, resbody) => {
178
+
179
+ if (err) {
180
+ this.logger.error("[DirAddKbContent] error: " + JSON.stringify(err?.response));
181
+ winston.error("[DirAddKbContent] error: ", err?.response);
182
+ if (callback) {
183
+ callback();
184
+ return;
185
+ }
186
+ }
187
+ else if (resbody.success === true) {
188
+ winston.debug("[DirAddKbContent] resbody: ", resbody);
189
+ callback();
190
+ return;
191
+ } else {
192
+ callback();
193
+ return;
194
+ }
195
+ }
196
+ )
197
+ }
198
+
199
+ async getKeyFromKbSettings() {
200
+ return new Promise((resolve) => {
201
+
202
+ const KB_HTTPREQUEST = {
203
+ url: this.API_ENDPOINT + "/" + this.context.projectId + "/kbsettings",
204
+ headers: {
205
+ 'Content-Type': 'application/json',
206
+ 'Authorization': 'JWT ' + this.context.token
207
+ },
208
+ method: "GET"
209
+ }
210
+ winston.debug("DirAskGPTV2 KB HttpRequest", KB_HTTPREQUEST);
211
+
212
+ httpUtils.request(
213
+ KB_HTTPREQUEST, async (err, resbody) => {
214
+ if (err) {
215
+ winston.error("DirAskGPTV2 Get kb settings error ", err?.response?.data);
216
+ resolve(null);
217
+ } else {
218
+ if (!resbody.gptkey) {
219
+ resolve(null);
220
+ } else {
221
+ resolve(resbody.gptkey);
222
+ }
223
+ }
224
+ }
225
+ )
226
+ })
227
+ }
228
+
229
+ async checkQuoteAvailability() {
230
+ return new Promise((resolve) => {
231
+
232
+ const HTTPREQUEST = {
233
+ url: this.API_ENDPOINT + "/" + this.context.projectId + "/quotes/tokens",
234
+ headers: {
235
+ 'Content-Type': 'application/json',
236
+ 'Authorization': 'JWT ' + this.context.token
237
+ },
238
+ method: "GET"
239
+ }
240
+ winston.debug("DirAskGPTV2 check quote availability HttpRequest", HTTPREQUEST);
241
+
242
+ httpUtils.request(
243
+ HTTPREQUEST, async (err, resbody) => {
244
+ if (err) {
245
+ winston.error("DirAskGPTV2 Check quote availability err: ", err);
246
+ resolve(true)
247
+ } else {
248
+ if (resbody.isAvailable === true) {
249
+ resolve(true)
250
+ } else {
251
+ resolve(false)
252
+ }
253
+ }
254
+ }
255
+ )
256
+ })
257
+ }
258
+
259
+ async updateQuote(tokens_usage) {
260
+ return new Promise((resolve, reject) => {
261
+
262
+ const HTTPREQUEST = {
263
+ url: this.API_ENDPOINT + "/" + this.context.projectId + "/quotes/incr/tokens",
264
+ headers: {
265
+ 'Content-Type': 'application/json',
266
+ 'Authorization': 'JWT ' + this.context.token
267
+ },
268
+ json: tokens_usage,
269
+ method: "POST"
270
+ }
271
+ winston.debug("DirAskGPTV2 update quote HttpRequest ", HTTPREQUEST);
272
+
273
+ httpUtils.request(
274
+ HTTPREQUEST, async (err, resbody) => {
275
+ if (err) {
276
+ winston.error("DirAskGPTV2 Increment tokens quote err: ", err);
277
+ reject(false)
278
+ } else {
279
+ resolve(true);
280
+ }
281
+ }
282
+ )
283
+ })
284
+ }
285
+
286
+ async getNamespace(name, id) {
287
+ return new Promise((resolve) => {
288
+ const HTTPREQUEST = {
289
+ url: this.API_ENDPOINT + "/" + this.context.projectId + "/kb/namespace/all",
290
+ headers: {
291
+ 'Content-Type': 'application/json',
292
+ 'Authorization': 'JWT ' + this.context.token
293
+ },
294
+ method: "GET"
295
+ }
296
+ winston.debug("DirAskGPTV2 get all namespaces HttpRequest", HTTPREQUEST);
297
+ httpUtils.request(
298
+ HTTPREQUEST, async (err, namespaces) => {
299
+ if (err) {
300
+ winston.error("DirAskGPTV2 get all namespaces err: ", err);
301
+ resolve(null)
302
+ } else {
303
+ winston.debug("DirAskGPTV2 get all namespaces resbody: ", namespaces);
304
+ if (name) {
305
+ let namespace = namespaces.find(n => n.name === name);
306
+ resolve(namespace);
307
+ } else {
308
+ let namespace = namespaces.find(n => n.id === id);
309
+ resolve(namespace);
310
+ }
311
+
312
+ }
313
+ }
314
+ )
315
+ })
316
+ }
317
+
318
+ async setDefaultEngine() {
319
+ return new Promise((resolve) => {
320
+ let engine = {
321
+ name: "pinecone",
322
+ type: process.env.PINECONE_TYPE,
323
+ apikey: "",
324
+ vector_size: 1536,
325
+ index_name: process.env.PINECONE_INDEX
326
+ }
327
+ resolve(engine);
328
+ })
329
+ }
330
+
331
+ }
332
+
333
+ module.exports = { DirAddKbContent }
@@ -15,7 +15,6 @@ class DirConnectBlock {
15
15
  this.TILEBOT_ENDPOINT = context.TILEBOT_ENDPOINT;
16
16
  this.supportRequest = context.supportRequest;
17
17
  this.token = context.token;
18
- this.log = context.log;
19
18
  }
20
19
 
21
20
  execute(directive, callback) {
@@ -13,7 +13,6 @@ class DirDeflectToHelpCenter {
13
13
  }
14
14
  this.context = context;
15
15
  this.API_ENDPOINT = context.API_ENDPOINT;
16
- this.log = context.log;
17
16
 
18
17
  this.tdClient = new TiledeskClient({ projectId: this.context.projectId, token: this.context.token, APIURL: this.API_ENDPOINT, APIKEY: "___", log: this.log });
19
18
  }
@@ -64,8 +63,7 @@ class DirDeflectToHelpCenter {
64
63
  if (last_user_text && last_user_text.trim() !== '') {
65
64
  const helpcenter = new HelpCenterQuery({
66
65
  APIKEY: "__",
67
- projectId: project_id,
68
- log: false
66
+ projectId: project_id
69
67
  });
70
68
  if (this.helpcenter_api_endpoint) {
71
69
  helpcenter.APIURL = this.helpcenter_api_endpoint
@@ -19,7 +19,7 @@ class DirFlowLog {
19
19
  this.requestId = context.requestId;
20
20
  this.log = context.log;
21
21
 
22
- 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 });
23
23
  }
24
24
 
25
25
  execute(directive, callback) {
@@ -3,6 +3,7 @@ const { TiledeskChatbot } = require("../../engine/TiledeskChatbot");
3
3
  const { Filler } = require("../Filler");
4
4
  let https = require("https");
5
5
  const { DirIntent } = require("./DirIntent");
6
+ const winston = require('../../utils/winston');
6
7
  const httpUtils = require("../../utils/HttpUtils");
7
8
  require('dotenv').config();
8
9
 
@@ -22,13 +23,13 @@ class DirGptTask {
22
23
  }
23
24
 
24
25
  execute(directive, callback) {
25
- if (this.log) { console.log("GptTask directive: ", directive); }
26
+ winston.verbose("Execute GptTask directive");
26
27
  let action;
27
28
  if (directive.action) {
28
29
  action = directive.action;
29
30
  }
30
31
  else {
31
- console.error("Incorrect directive: ", JSON.stringify(directive));
32
+ winston.warn("DirGptTask Incorrect directive: ", directive);
32
33
  callback();
33
34
  return;
34
35
  }
@@ -38,9 +39,9 @@ class DirGptTask {
38
39
  }
39
40
 
40
41
  async go(action, callback) {
41
- if (this.log) { console.log("DirGptTask action:", JSON.stringify(action)); }
42
+ winston.debug("(DirGptTask) Action: ", action);
42
43
  if (!this.tdcache) {
43
- console.error("Error: DirGptTask tdcache is mandatory");
44
+ winston.error("(DirGptTask) Error: tdcache is mandatory");
44
45
  callback();
45
46
  return;
46
47
  }
@@ -50,18 +51,16 @@ class DirGptTask {
50
51
  let trueIntentAttributes = action.trueIntentAttributes;
51
52
  let falseIntentAttributes = action.falseIntentAttributes;
52
53
 
53
- if (this.log) {
54
- console.log("DirGptTask trueIntent", trueIntent)
55
- console.log("DirGptTask falseIntent", falseIntent)
56
- console.log("DirGptTask trueIntentAttributes", trueIntentAttributes)
57
- console.log("DirGptTask falseIntentAttributes", falseIntentAttributes)
58
- }
54
+ winston.debug("(DirGptTask) trueIntent " + trueIntent)
55
+ winston.debug("(DirGptTask) falseIntent " + falseIntent)
56
+ winston.debug("(DirGptTask) trueIntentAttributes " + trueIntentAttributes)
57
+ winston.debug("(DirGptTask) falseIntentAttributes " + falseIntentAttributes)
59
58
 
60
59
  // default value
61
60
  let answer = "No answer.";
62
61
 
63
62
  if (!action.question || action.question === '') {
64
- console.error("Error: DirGptTask question attribute is mandatory. Executing condition false...")
63
+ winston.debug("(DirGptTask) Error: question attribute is mandatory. Executing condition false...")
65
64
  if (falseIntent) {
66
65
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
67
66
  callback(true);
@@ -83,13 +82,11 @@ class DirGptTask {
83
82
  let max_tokens = action.max_tokens;
84
83
  let temperature = action.temperature;
85
84
 
86
- if (this.log) {
87
- console.log("DirGptTask max_tokens: ", max_tokens);
88
- console.log("DirGptTask temperature: ", temperature);
89
- }
85
+ winston.debug("(DirGptTask) max_tokens: " + max_tokens);
86
+ winston.debug("(DirGptTask) temperature: " + temperature);
90
87
 
91
88
  const openai_url = process.env.OPENAI_ENDPOINT + "/chat/completions";
92
- if (this.log) { console.log("DirGptTask openai_url ", openai_url); }
89
+ winston.debug("(DirGptTask) openai_url ", openai_url);
93
90
 
94
91
  const INTEGRATIONS_HTTPREQUEST = {
95
92
  url: this.API_ENDPOINT + "/" + this.context.projectId + "/integration/name/openai",
@@ -99,7 +96,7 @@ class DirGptTask {
99
96
  },
100
97
  method: "GET"
101
98
  }
102
- if (this.log) { console.log("DirGptTask INTEGRATIONS_HTTPREQUEST ", INTEGRATIONS_HTTPREQUEST) }
99
+ winston.debug("(DirGptTask) INTEGRATIONS_HTTPREQUEST ", INTEGRATIONS_HTTPREQUEST);
103
100
 
104
101
  httpUtils.request(
105
102
  INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
@@ -111,7 +108,7 @@ class DirGptTask {
111
108
  // return;
112
109
  }
113
110
  } else if (callback) {
114
- if (this.log) { console.log("DirGptTask get integration resbody: ", integration); }
111
+ winston.debug("(DirGptTask) get integration resbody: ", integration);
115
112
 
116
113
  let key;
117
114
  if (integration &&
@@ -122,8 +119,7 @@ class DirGptTask {
122
119
  // key not present in integrations - for retro compatibility search in kbsettings
123
120
  if (!key) {
124
121
 
125
- // if (this.log) { console.log("DirGptTask - Key not found in Integrations. Searching in kb settings...")}
126
- if (this.log) { console.log("DirGptTask - Key not found in Integrations. Searching in kb settings..."); }
122
+ winston.debug("(DirGptTask) Key not found in Integrations. Searching in kb settings...");
127
123
 
128
124
  const KB_HTTPREQUEST = {
129
125
  url: this.API_ENDPOINT + "/" + this.context.projectId + "/kbsettings",
@@ -133,16 +129,15 @@ class DirGptTask {
133
129
  },
134
130
  method: "GET"
135
131
  }
136
- if (this.log) { console.log("DirGptTask KB_HTTPREQUEST", KB_HTTPREQUEST); }
132
+ winston.debug("(DirGptTask) KB_HTTPREQUEST", KB_HTTPREQUEST);
137
133
 
138
134
  httpUtils.request(
139
135
  KB_HTTPREQUEST, async (err, resbody) => {
140
136
  if (err) {
141
137
  if (callback) {
142
138
  console.error("(httprequest) DirGptTask Get KnowledgeBase err:", err.message);
143
- if (this.log) {
144
- console.error("(httprequest) DirGptTask Get KnowledgeBase full err", err);
145
- }
139
+ console.error("(httprequest) DirGptTask Get KnowledgeBase full err", err);
140
+
146
141
  await this.#assignAttributes(action, answer);
147
142
  if (falseIntent) {
148
143
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
@@ -153,7 +148,7 @@ class DirGptTask {
153
148
  return;
154
149
  }
155
150
  } else if (callback) {
156
- if (this.log) { console.log("DirGptTask Get KnowledgeBase settings resbody:", resbody); }
151
+ winston.debug("(DirGptTask) Get KnowledgeBase settings resbody:", resbody);
157
152
 
158
153
  if (!resbody.gptkey) {
159
154
  await this.#assignAttributes(action, answer);
@@ -167,7 +162,7 @@ class DirGptTask {
167
162
 
168
163
  } else {
169
164
 
170
- if (this.log) { console.log("DirGptTask - Key found in KbSettings") };
165
+ winston.debug("(DirGptTask) Key found in KbSettings");
171
166
 
172
167
  key = resbody.gptkey;
173
168
 
@@ -189,7 +184,7 @@ class DirGptTask {
189
184
  message.content = action.context;
190
185
  json.messages.unshift(message);
191
186
  }
192
- if (this.log) { console.log("DirGptTask json: ", json) }
187
+ winston.debug("(DirGptTask) json: ", json);
193
188
 
194
189
  const HTTPREQUEST = {
195
190
  url: openai_url,
@@ -200,14 +195,12 @@ class DirGptTask {
200
195
  json: json,
201
196
  method: 'POST'
202
197
  }
203
- if (this.log) { console.log("DirGptTask HTTPREQUEST: ", HTTPREQUEST); }
198
+ winston.debug("(DirGptTask) HTTPREQUEST: ", HTTPREQUEST);
204
199
  httpUtils.request(
205
200
  HTTPREQUEST, async (err, resbody) => {
206
201
  if (err) {
207
- if (this.log) {
208
- console.error("(httprequest) DirGptTask openai err:", err);
209
- console.error("(httprequest) DirGptTask openai err:", err.response.data);
210
- }
202
+ console.error("(httprequest) DirGptTask openai err:", err);
203
+ console.error("(httprequest) DirGptTask openai err:", err.response.data);
211
204
  await this.#assignAttributes(action, answer);
212
205
  if (falseIntent) {
213
206
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
@@ -217,7 +210,7 @@ class DirGptTask {
217
210
  callback();
218
211
  return;
219
212
  } else {
220
- if (this.log) { console.log("DirGptTask resbody: ", JSON.stringify(resbody)); }
213
+ winston.debug("(DirGptTask) resbody: ", JSON.stringify(resbody));
221
214
  answer = resbody.choices[0].message.content;
222
215
  let answer_json = await this.convertToJson(answer);
223
216
  await this.#assignAttributes(action, answer_json);
@@ -237,7 +230,7 @@ class DirGptTask {
237
230
  )
238
231
  } else {
239
232
 
240
- if (this.log) { console.log("DirGptTask - Key found in Integrations") };
233
+ winston.debug("(DirGptTask) Key found in Integrations");
241
234
 
242
235
  let json = {
243
236
  "model": action.model,
@@ -257,7 +250,7 @@ class DirGptTask {
257
250
  message.content = action.context;
258
251
  json.messages.unshift(message);
259
252
  }
260
- if (this.log) { console.log("DirGptTask json: ", json) }
253
+ winston.debug("(DirGptTask) json: ", json);
261
254
 
262
255
  const HTTPREQUEST = {
263
256
  url: openai_url,
@@ -268,14 +261,12 @@ class DirGptTask {
268
261
  json: json,
269
262
  method: 'POST'
270
263
  }
271
- if (this.log) { console.log("DirGptTask HTTPREQUEST: ", HTTPREQUEST); }
264
+ winston.debug("(DirGptTask) HTTPREQUEST: ", HTTPREQUEST);
272
265
  httpUtils.request(
273
266
  HTTPREQUEST, async (err, resbody) => {
274
267
  if (err) {
275
- if (this.log) {
276
- console.error("(httprequest) DirGptTask openai err:", err);
277
- console.error("(httprequest) DirGptTask openai err:", err.response.data);
278
- }
268
+ console.error("(httprequest) DirGptTask openai err:", err);
269
+ console.error("(httprequest) DirGptTask openai err:", err.response.data);
279
270
  await this.#assignAttributes(action, answer);
280
271
  if (falseIntent) {
281
272
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
@@ -285,7 +276,7 @@ class DirGptTask {
285
276
  callback();
286
277
  return;
287
278
  } else {
288
- if (this.log) { console.log("DirGptTask resbody: ", JSON.stringify(resbody)); }
279
+ winston.debug("(DirGptTask) resbody: ", JSON.stringify(resbody));
289
280
  answer = resbody.choices[0].message.content;
290
281
  // check if answer is a json
291
282
  let answer_json = await this.convertToJson(answer);
@@ -339,7 +330,7 @@ class DirGptTask {
339
330
  })
340
331
  }
341
332
  else {
342
- if (this.log) { console.log("No trueIntentDirective specified"); }
333
+ winston.debug("(DirGptTask) No trueIntentDirective specified");
343
334
  if (callback) {
344
335
  callback();
345
336
  }
@@ -354,7 +345,7 @@ class DirGptTask {
354
345
  });
355
346
  }
356
347
  else {
357
- if (this.log) { console.log("No falseIntentDirective specified"); }
348
+ winston.debug("(DirGptTask) No falseIntentDirective specified");
358
349
  if (callback) {
359
350
  callback();
360
351
  }
@@ -363,10 +354,8 @@ class DirGptTask {
363
354
  }
364
355
 
365
356
  async #assignAttributes(action, answer) {
366
- if (this.log) {
367
- console.log("assignAttributes action:", action)
368
- console.log("assignAttributes answer:", answer)
369
- }
357
+ winston.debug("(DirGptTask) assignAttributes action:", action)
358
+ winston.debug("(DirGptTask) assignAttributes answer:", answer)
370
359
  if (this.context.tdcache) {
371
360
  if (action.assignReplyTo && answer) {
372
361
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignReplyTo, answer);
@@ -374,13 +363,6 @@ class DirGptTask {
374
363
  // if (action.assignSourceTo && source) {
375
364
  // await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignSourceTo, source);
376
365
  // }
377
- // Debug log
378
- if (this.log) {
379
- const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
380
- for (const [key, value] of Object.entries(all_parameters)) {
381
- if (this.log) { console.log("(gpttask) request parameter:", key, "value:", value, "type:", typeof value) }
382
- }
383
- }
384
366
  }
385
367
  }
386
368
 
@@ -1,4 +1,3 @@
1
- // const { TiledeskClient } = require('@tiledesk/tiledesk-client');
2
1
  const { TiledeskClient } = require('@tiledesk/tiledesk-client');
3
2
  const { DirIntent } = require('./DirIntent');
4
3
  const ms = require('minimist-string');
@@ -1,4 +1,3 @@
1
- // const { TiledeskClient } = require('@tiledesk/tiledesk-client');
2
1
  const { DirIntent } = require('./DirIntent');
3
2
  const axios = require("axios").default;
4
3
  let https = require("https");
@@ -208,7 +207,7 @@ class DirIfOnlineAgentsV2 {
208
207
  }
209
208
  resolve(resbody);
210
209
  }
211
- }, this.log);
210
+ });
212
211
  });
213
212
 
214
213
  }
@@ -1,4 +1,3 @@
1
- // const { TiledeskClient } = require('@tiledesk/tiledesk-client');
2
1
  let axios = require('axios');
3
2
  const { DirIntent } = require('./DirIntent');
4
3
  let https = require("https");