@tiledesk/tiledesk-tybot-connector 0.4.2 → 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 (87) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/ExtApi.js +3 -13
  3. package/ExtUtil.js +0 -1
  4. package/Logger.js +86 -0
  5. package/TdCache.js +5 -3
  6. package/TiledeskClientTest.js +5 -28
  7. package/TiledeskExpression.js +6 -47
  8. package/index.js +87 -273
  9. package/logs/app.log +12983 -275
  10. package/logs/app1.log +62258 -0
  11. package/logs/app2.log +46280 -0
  12. package/logs/app3.log +28864 -0
  13. package/models/IntentForm.js +30 -44
  14. package/models/IntentsMachineFactory.js +4 -3
  15. package/models/MockBotsDataSource.js +1 -17
  16. package/models/MockTdCache.js +0 -9
  17. package/models/MongodbBotsDataSource.js +29 -53
  18. package/models/MongodbIntentsMachine.js +5 -4
  19. package/models/TiledeskChatbot.js +79 -258
  20. package/models/TiledeskChatbotConst.js +9 -0
  21. package/models/TiledeskChatbotUtil.js +180 -232
  22. package/models/TiledeskIntentsMachine.js +5 -14
  23. package/models/faqKbService.js +0 -1
  24. package/package.json +5 -2
  25. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +66 -139
  26. package/tiledeskChatbotPlugs/FillParamsChatbotPlug.js +7 -13
  27. package/tiledeskChatbotPlugs/Filler.js +0 -1
  28. package/tiledeskChatbotPlugs/MarkbotChatbotPlug.js +12 -20
  29. package/tiledeskChatbotPlugs/MessagePipeline.js +5 -15
  30. package/tiledeskChatbotPlugs/SplitsChatbotPlug.js +4 -13
  31. package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +21 -89
  32. package/tiledeskChatbotPlugs/directives/DirAddTags.js +15 -98
  33. package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +3 -3
  34. package/tiledeskChatbotPlugs/directives/DirAskGPT.js +32 -57
  35. package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +46 -70
  36. package/tiledeskChatbotPlugs/directives/DirAssign.js +11 -22
  37. package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +15 -11
  38. package/tiledeskChatbotPlugs/directives/DirAssistant.js +48 -97
  39. package/tiledeskChatbotPlugs/directives/DirBrevo.js +37 -68
  40. package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +8 -18
  41. package/tiledeskChatbotPlugs/directives/DirClose.js +3 -1
  42. package/tiledeskChatbotPlugs/directives/DirCode.js +15 -22
  43. package/tiledeskChatbotPlugs/directives/DirCondition.js +18 -24
  44. package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +9 -13
  45. package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +7 -19
  46. package/tiledeskChatbotPlugs/directives/DirCustomerio.js +30 -57
  47. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +15 -20
  48. package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +7 -7
  49. package/tiledeskChatbotPlugs/directives/DirDepartment.js +13 -12
  50. package/tiledeskChatbotPlugs/directives/DirDisableInputText.js +2 -6
  51. package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +4 -4
  52. package/tiledeskChatbotPlugs/directives/DirForm.js +15 -22
  53. package/tiledeskChatbotPlugs/directives/DirGptTask.js +38 -65
  54. package/tiledeskChatbotPlugs/directives/DirHubspot.js +27 -58
  55. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +19 -26
  56. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +22 -40
  57. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +17 -32
  58. package/tiledeskChatbotPlugs/directives/DirIntent.js +16 -33
  59. package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +14 -13
  60. package/tiledeskChatbotPlugs/directives/DirLockIntent.js +7 -12
  61. package/tiledeskChatbotPlugs/directives/DirMake.js +20 -52
  62. package/tiledeskChatbotPlugs/directives/DirMessage.js +35 -28
  63. package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +10 -20
  64. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +4 -2
  65. package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +4 -2
  66. package/tiledeskChatbotPlugs/directives/DirQapla.js +21 -50
  67. package/tiledeskChatbotPlugs/directives/DirRandomReply.js +9 -17
  68. package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +4 -0
  69. package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +4 -1
  70. package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +10 -21
  71. package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +9 -19
  72. package/tiledeskChatbotPlugs/directives/DirReply.js +32 -35
  73. package/tiledeskChatbotPlugs/directives/DirReplyV2.js +27 -69
  74. package/tiledeskChatbotPlugs/directives/DirSendEmail.js +8 -9
  75. package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +13 -12
  76. package/tiledeskChatbotPlugs/directives/DirSetAttribute.js +7 -4
  77. package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +22 -75
  78. package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +14 -13
  79. package/tiledeskChatbotPlugs/directives/DirUnlockIntent.js +3 -3
  80. package/tiledeskChatbotPlugs/directives/DirWait.js +4 -5
  81. package/tiledeskChatbotPlugs/directives/DirWebRequest.js +13 -48
  82. package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +11 -76
  83. package/tiledeskChatbotPlugs/directives/DirWebResponse.js +34 -7
  84. package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +11 -14
  85. package/tiledeskChatbotPlugs/directives/Directives.js +1 -3
  86. package/utils/winston.js +42 -0
  87. package/TdCache copy.js +0 -242
@@ -9,6 +9,7 @@ const req = require("express/lib/request");
9
9
  const { update } = require("../../models/faq");
10
10
  const { TiledeskClient } = require("@tiledesk/tiledesk-client");
11
11
  require('dotenv').config();
12
+ const winston = require('../../utils/winston');
12
13
 
13
14
  class DirAddTags {
14
15
 
@@ -33,13 +34,13 @@ class DirAddTags {
33
34
  }
34
35
 
35
36
  execute(directive, callback) {
36
- if (this.log) { console.log("AddTags directive: ", directive); }
37
+ winston.verbose("Execute AddTags directive");
37
38
  let action;
38
39
  if (directive.action) {
39
40
  action = directive.action;
40
41
  }
41
42
  else {
42
- console.error("Incorrect directive: ", JSON.stringify(directive));
43
+ winston.warn("Incorrect directive: ", directive);
43
44
  callback();
44
45
  return;
45
46
  }
@@ -49,9 +50,9 @@ class DirAddTags {
49
50
  }
50
51
 
51
52
  async go(action, callback) {
52
- if (this.log) { console.log("(DirAddTags) action:", JSON.stringify(action)); }
53
+ winston.debug("(DirAddTags) Action: ", action);
53
54
  if (!this.tdcache) {
54
- console.error("Error: (DirAddTags) tdcache is mandatory");
55
+ winston.error("(DirAddTags) Error: tdcache is mandatory");
55
56
  callback();
56
57
  return;
57
58
  }
@@ -64,7 +65,7 @@ class DirAddTags {
64
65
  pushToList = action.pushToList
65
66
 
66
67
  if (!action.tags || action.tags === '') {
67
- console.error("Error: (DirAddTags) tags attribute is mandatory")
68
+ winston.error("(DirAddTags) Error: tags attribute is mandatory")
68
69
  await this.chatbot.addParameter("flowError", "Add tags Error: tags attribute is mandatory");
69
70
  callback();
70
71
  return;
@@ -78,18 +79,7 @@ class DirAddTags {
78
79
 
79
80
  const filler = new Filler();
80
81
  const filled_tags = filler.fill(action.tags, requestVariables);
81
-
82
- if (this.log) {
83
- console.log("(DirAddTags) tags: ", filled_tags);
84
- }
85
-
86
- // let request = await this.tdClient.getRequestById(this.requestId);
87
- // if (this.log) { console.log('(DirAddTags) request detail: ', request) }
88
- // if(!request){
89
- // if (this.log) { console.log("(DirAddTags) - request not found for request_id:", this.requestId); }
90
- // callback();
91
- // return;
92
- // }
82
+ winston.debug("(DirAddTags) filled_tags: ", filled_tags);
93
83
 
94
84
  /** use case: CONVERSATION */
95
85
  if(target === 'request'){
@@ -106,7 +96,7 @@ class DirAddTags {
106
96
  })
107
97
  }
108
98
 
109
- if (this.log) { console.log('(DirAddTags) UPDATE request with newTags', newTags) }
99
+ winston.debug('(DirAddTags) UPDATE request with newTags', newTags)
110
100
  let updatedRequest = await this.updateRequestWithTags(newTags)
111
101
  if(!updatedRequest){
112
102
  callback();
@@ -120,9 +110,9 @@ class DirAddTags {
120
110
  let newTags = filled_tags.split(',').filter(tag => tag !== '').map(el => el.trim())
121
111
 
122
112
  let request = await this.tdClient.getRequestById(this.requestId);
123
- if (this.log) { console.log('(DirAddTags) request detail: ', request) }
113
+ winston.debug('(DirAddTags) request detail: ', request)
124
114
  if(!request){
125
- if (this.log) { console.log("(DirAddTags) - request not found for request_id:", this.requestId); }
115
+ winston.debug("(DirAddTags) - request not found for request_id: " + this.requestId);
126
116
  callback();
127
117
  return;
128
118
  }
@@ -137,7 +127,7 @@ class DirAddTags {
137
127
  })
138
128
  }
139
129
 
140
- if (this.log) { console.log('(DirAddTags) UPDATE lead with newTags', newTags) }
130
+ winston.debug('(DirAddTags) UPDATE lead with newTags ', newTags)
141
131
  let updatedLead = await this.updateLeadWithTags(request.lead._id, newTags)
142
132
  if(!updatedLead){
143
133
  callback();
@@ -165,71 +155,7 @@ class DirAddTags {
165
155
 
166
156
  }
167
157
 
168
- async #executeCondition(result, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes, callback) {
169
- let trueIntentDirective = null;
170
- if (trueIntent) {
171
- trueIntentDirective = DirIntent.intentDirectiveFor(trueIntent, trueIntentAttributes);
172
- }
173
- let falseIntentDirective = null;
174
- if (falseIntent) {
175
- falseIntentDirective = DirIntent.intentDirectiveFor(falseIntent, falseIntentAttributes);
176
- }
177
- if (result === true) {
178
- if (trueIntentDirective) {
179
- this.intentDir.execute(trueIntentDirective, () => {
180
- if (callback) {
181
- callback();
182
- }
183
- })
184
- }
185
- else {
186
- if (this.log) { console.log("No trueIntentDirective specified"); }
187
- if (callback) {
188
- callback();
189
- }
190
- }
191
- }
192
- else {
193
- if (falseIntentDirective) {
194
- this.intentDir.execute(falseIntentDirective, () => {
195
- if (callback) {
196
- callback();
197
- }
198
- });
199
- }
200
- else {
201
- if (this.log) { console.log("No falseIntentDirective specified"); }
202
- if (callback) {
203
- callback();
204
- }
205
- }
206
- }
207
- }
208
-
209
- async #assignAttributes(action, answer) {
210
- if (this.log) {
211
- console.log("assignAttributes action:", action)
212
- console.log("assignAttributes answer:", answer)
213
- }
214
- if (this.context.tdcache) {
215
- if (action.assignReplyTo && answer) {
216
- await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignReplyTo, answer);
217
- }
218
- // Debug log
219
- if (this.log) {
220
- const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
221
- for (const [key, value] of Object.entries(all_parameters)) {
222
- if (this.log) { console.log("(DirAddTags) request parameter:", key, "value:", value, "type:", typeof value) }
223
- }
224
- }
225
- }
226
- }
227
-
228
158
  #myrequest(options, callback) {
229
- if (this.log) {
230
- console.log("API URL:", options.url);
231
- console.log("** Options:", JSON.stringify(options));
232
- }
233
159
  let axios_options = {
234
160
  url: options.url,
235
161
  method: options.method,
@@ -239,9 +165,6 @@ class DirAddTags {
239
165
  if (options.json !== null) {
240
166
  axios_options.data = options.json
241
167
  }
242
- if (this.log) {
243
- console.log("axios_options:", JSON.stringify(axios_options));
244
- }
245
168
  if (options.url.startsWith("https:")) {
246
169
  const httpsAgent = new https.Agent({
247
170
  rejectUnauthorized: false,
@@ -250,10 +173,6 @@ class DirAddTags {
250
173
  }
251
174
  axios(axios_options)
252
175
  .then((res) => {
253
- if (this.log) {
254
- console.log("Response for url:", options.url);
255
- console.log("Response headers:\n", JSON.stringify(res.headers));
256
- }
257
176
  if (res && res.status == 200 && res.data) {
258
177
  if (callback) {
259
178
  callback(null, res.data);
@@ -289,7 +208,7 @@ class DirAddTags {
289
208
  this.#myrequest(
290
209
  HTTPREQUEST, async (err, resbody) => {
291
210
  if (err) {
292
- console.error("(httprequest) DirAddTags add tags to list err: ", err);
211
+ winston.error("(httprequest) DirAddTags add tags to list err: ", err);
293
212
  resolve(true)
294
213
  } else {
295
214
  if (resbody) {
@@ -309,9 +228,7 @@ class DirAddTags {
309
228
  let json = []
310
229
  let filteredTags = tags.map((tag) => ({tag: tag, color: '#f0806f'}))
311
230
  json.push(...filteredTags)
312
- if (this.log) {
313
- console.log('(httprequest) DirAddTags updateRequestWithTags tags--> ', json)
314
- }
231
+ winston.debug('(httprequest) DirAddTags updateRequestWithTags tags: ', json)
315
232
  const HTTPREQUEST = {
316
233
  url: this.API_ENDPOINT + "/" + this.context.projectId + "/requests/" + this.requestId + '/tag',
317
234
  headers: {
@@ -325,7 +242,7 @@ class DirAddTags {
325
242
  this.#myrequest(
326
243
  HTTPREQUEST, async (err, resbody) => {
327
244
  if (err) {
328
- console.error("(httprequest) DirAddTags patch request with new tags err: ", err);
245
+ winston.error("(httprequest) DirAddTags patch request with new tags err: ", err);
329
246
  resolve(true)
330
247
  } else {
331
248
  if (resbody) {
@@ -354,7 +271,7 @@ class DirAddTags {
354
271
  this.#myrequest(
355
272
  HTTPREQUEST, async (err, resbody) => {
356
273
  if (err) {
357
- console.error("(httprequest) DirAddTags put lead with new tags err: ", err);
274
+ winston.error("(httprequest) DirAddTags put lead with new tags err: ", err);
358
275
  resolve(true)
359
276
  } else {
360
277
  if (resbody) {
@@ -94,8 +94,8 @@ class DirAiPrompt {
94
94
  }
95
95
  }
96
96
 
97
- const llm_endpoint = process.env.KB_ENDPOINT_QA;
98
- if (this.log) { console.log("DirAiPrompt llm_endpoint ", llm_endpoint); }
97
+ const AI_endpoint = process.env.AI_ENDPOINT
98
+ if (this.log) { console.log("DirAiPrompt AI_endpoint ", AI_endpoint); }
99
99
 
100
100
  let key = await this.getKeyFromIntegrations(action.llm);
101
101
 
@@ -130,7 +130,7 @@ class DirAiPrompt {
130
130
  if (this.log) { console.log("DirAiPrompt json: ", json) }
131
131
 
132
132
  const HTTPREQUEST = {
133
- url: llm_endpoint + '/ask',
133
+ url: AI_endpoint + '/ask',
134
134
  headers: {
135
135
  'Content-Type': 'application/json'
136
136
  },
@@ -4,6 +4,7 @@ const { Filler } = require('../Filler');
4
4
  let https = require("https");
5
5
  const { DirIntent } = require("./DirIntent");
6
6
  require('dotenv').config();
7
+ const winston = require('../../utils/winston')
7
8
 
8
9
  class DirAskGPT {
9
10
 
@@ -20,13 +21,13 @@ class DirAskGPT {
20
21
  }
21
22
 
22
23
  execute(directive, callback) {
23
- if (this.log) { console.log("AskGPT directive: ", directive); }
24
+ winston.verbose("Execute AskGPT directive");
24
25
  let action;
25
26
  if (directive.action) {
26
27
  action = directive.action;
27
28
  }
28
29
  else {
29
- console.error("Incorrect directive: ", JSON.stringify(directive));
30
+ winston.warn("DirAskGPT Incorrect directive: ", directive);
30
31
  callback();
31
32
  return;
32
33
  }
@@ -36,9 +37,9 @@ class DirAskGPT {
36
37
  }
37
38
 
38
39
  async go(action, callback) {
39
- if (this.log) { console.log("DirAskGPT action:", JSON.stringify(action)); }
40
+ winston.debug("(DirAskGPT) Action: ", action);
40
41
  if (!this.tdcache) {
41
- console.error("Error: DirAskGPT tdcache is mandatory");
42
+ winston.error("Error: DirAskGPT tdcache is mandatory");
42
43
  callback();
43
44
  return;
44
45
  }
@@ -49,19 +50,17 @@ class DirAskGPT {
49
50
  let trueIntentAttributes = action.trueIntentAttributes;
50
51
  let falseIntentAttributes = action.falseIntentAttributes;
51
52
 
52
- if (this.log) {
53
- console.log("DirAskGPT trueIntent", trueIntent)
54
- console.log("DirAskGPT falseIntent", falseIntent)
55
- console.log("DirAskGPT trueIntentAttributes", trueIntentAttributes)
56
- console.log("DirAskGPT falseIntentAttributes", falseIntentAttributes)
57
- }
53
+ winston.debug("(DirAskGPT) trueIntent " + trueIntent)
54
+ winston.debug("(DirAskGPT) falseIntent " + falseIntent)
55
+ winston.debug("(DirAskGPT) trueIntentAttributes " + trueIntentAttributes)
56
+ winston.debug("(DirAskGPT) falseIntentAttributes " + falseIntentAttributes)
58
57
 
59
58
  // default values
60
59
  let answer = "No answers";
61
60
  let source = null;
62
61
 
63
62
  if (!action.question || action.question === '') {
64
- console.error("Error: DirAskGPT question attribute is mandatory. Executing condition false...");
63
+ winston.error("(DirAskGPT) Error: question attribute is mandatory. Executing condition false...");
65
64
  await this.#assignAttributes(action, answer, source);
66
65
  if (falseIntent) {
67
66
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
@@ -71,7 +70,7 @@ class DirAskGPT {
71
70
  }
72
71
 
73
72
  if (!action.kbid) {
74
- console.error("Error: DirAskGPT kbid attribute is mandatory. Executing condition false...");
73
+ winston.error("(DirAskGPT) Error: kbid attribute is mandatory. Executing condition false...");
75
74
  await this.#assignAttributes(action, answer, source);
76
75
  if (falseIntent) {
77
76
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes)
@@ -90,22 +89,22 @@ class DirAskGPT {
90
89
  const filled_question = filler.fill(action.question, requestVariables);
91
90
 
92
91
  const kb_endpoint = process.env.KB_ENDPOINT;
93
- if (this.log) { console.log("DirAskGPT KbEndpoint URL: ", kb_endpoint); }
92
+ winston.verbose("DirAskGPT KbEndpoint URL: ", kb_endpoint);
94
93
 
95
94
  let key = await this.getKeyFromIntegrations();
96
95
  if (!key) {
97
- if (this.log) { console.log("DirAskGPT - Key not found in Integrations. Searching in kb settings..."); }
96
+ winston.debug("(DirAskGPT) - Key not found in Integrations. Searching in kb settings...");
98
97
  key = await this.getKeyFromKbSettings();
99
98
  }
100
99
 
101
100
  if (!key) {
102
- if (this.log) { console.log("DirAskGPT - Retrieve public gptkey")}
101
+ winston.debug("(DirAskGPT) - Retrieve public gptkey")
103
102
  key = process.env.GPTKEY;
104
103
  publicKey = true;
105
104
  }
106
105
 
107
106
  if (!key) {
108
- console.error("Error: DirAskGPT gptkey is mandatory");
107
+ winston.error("(DirAskGPT) Error: gptkey is mandatory");
109
108
  await this.#assignAttributes(action, answer);
110
109
  if (falseIntent) {
111
110
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
@@ -119,7 +118,7 @@ class DirAskGPT {
119
118
  if (publicKey === true) {
120
119
  let keep_going = await this.checkQuoteAvailability();
121
120
  if (keep_going === false) {
122
- if (this.log) { console.log("DirAskGPT - Quota exceeded for tokens. Skip the action")}
121
+ winston.debug("(DirAskGPT) - Quota exceeded for tokens. Skip the action")
123
122
  callback();
124
123
  return;
125
124
  }
@@ -130,26 +129,25 @@ class DirAskGPT {
130
129
  kbid: action.kbid,
131
130
  gptkey: key
132
131
  };
133
- if (this.log) { console.log("DirAskGPT json:", json); }
132
+ winston.debug("(DirAskGPT)DirAskGPT json:", json);
134
133
 
135
134
  const HTTPREQUEST = {
136
135
  url: kb_endpoint + "/qa",
137
136
  json: json,
138
137
  method: "POST"
139
138
  }
140
- if (this.log) { console.log("DirAskGPT HTTPREQUEST", HTTPREQUEST); }
139
+ winston.debug("(DirAskGPT) HttpRequest", HTTPREQUEST);
141
140
 
142
141
  this.#myrequest(
143
142
  HTTPREQUEST, async (err, resbody) => {
144
- if (this.log && err) {
145
- console.log("DirAskGPT error: ", err);
146
- }
147
- if (this.log) { console.log("DirAskGPT resbody:", resbody); }
143
+
144
+ winston.debug("(DirAskGPT) resbody:", resbody);
148
145
  let answer = resbody.answer;
149
146
  let source = resbody.source_url;
150
147
  await this.#assignAttributes(action, answer, source);
151
-
148
+
152
149
  if (err) {
150
+ winston.error("(DirAskGPT) error: ", err);
153
151
  if (callback) {
154
152
  if (falseIntent) {
155
153
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
@@ -205,7 +203,7 @@ class DirAskGPT {
205
203
  })
206
204
  }
207
205
  else {
208
- if (this.log) { console.log("No trueIntentDirective specified"); }
206
+ winston.debug("(DirAskGPT) No trueIntentDirective specified");
209
207
  if (callback) {
210
208
  callback();
211
209
  }
@@ -220,7 +218,7 @@ class DirAskGPT {
220
218
  });
221
219
  }
222
220
  else {
223
- if (this.log) { console.log("No falseIntentDirective specified"); }
221
+ winston.debug("(DirAskGPT) No falseIntentDirective specified");
224
222
  if (callback) {
225
223
  callback();
226
224
  }
@@ -229,36 +227,20 @@ class DirAskGPT {
229
227
  }
230
228
 
231
229
  async #assignAttributes(action, answer, source) {
232
- if (this.log) {
233
- console.log("assignAttributes action:", action)
234
- console.log("assignAttributes answer:", answer)
235
- console.log("assignAttributes source:", source)
236
- }
230
+ winston.debug("(DirAskGPT) assignAttributes action:", action)
231
+ winston.debug("(DirAskGPT) assignAttributes answer:", answer)
232
+ winston.debug("(DirAskGPT) assignAttributes source:", source)
237
233
  if (this.context.tdcache) {
238
234
  if (action.assignReplyTo && answer) {
239
235
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignReplyTo, answer);
240
236
  }
241
- // console.log("--> action.assignSourceTo: ", action.assignSourceTo)
242
- // console.log("--> source: ", source)
243
237
  if (action.assignSourceTo && source) {
244
- // console.log("--> source: ", source)
245
238
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignSourceTo, source);
246
239
  }
247
- // Debug log
248
- if (this.log) {
249
- const all_parameters = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
250
- for (const [key, value] of Object.entries(all_parameters)) {
251
- if (this.log) { console.log("(askgpt) request parameter:", key, "value:", value, "type:", typeof value) }
252
- }
253
- }
254
240
  }
255
241
  }
256
242
 
257
243
  #myrequest(options, callback) {
258
- if (this.log) {
259
- console.log("API URL:", options.url);
260
- console.log("** Options:", JSON.stringify(options));
261
- }
262
244
  let axios_options = {
263
245
  url: options.url,
264
246
  method: options.method,
@@ -268,9 +250,6 @@ class DirAskGPT {
268
250
  if (options.json !== null) {
269
251
  axios_options.data = options.json
270
252
  }
271
- if (this.log) {
272
- console.log("axios_options:", JSON.stringify(axios_options));
273
- }
274
253
  if (options.url.startsWith("https:")) {
275
254
  const httpsAgent = new https.Agent({
276
255
  rejectUnauthorized: false,
@@ -279,10 +258,6 @@ class DirAskGPT {
279
258
  }
280
259
  axios(axios_options)
281
260
  .then((res) => {
282
- if (this.log) {
283
- console.log("Response for url:", options.url);
284
- console.log("Response headers:\n", JSON.stringify(res.headers));
285
- }
286
261
  if (res && res.status == 200 && res.data) {
287
262
  if (callback) {
288
263
  callback(null, res.data);
@@ -295,7 +270,7 @@ class DirAskGPT {
295
270
  }
296
271
  })
297
272
  .catch((error) => {
298
- console.error("(DirAskGPT) Axios error: ", JSON.stringify(error));
273
+ winston.error("(DirAskGPT) Axios error: ", error.response.data);
299
274
  if (callback) {
300
275
  callback(error, null);
301
276
  }
@@ -313,12 +288,12 @@ class DirAskGPT {
313
288
  },
314
289
  method: "GET"
315
290
  }
316
- if (this.log) { console.log("DirAskGPT INTEGRATIONS_HTTPREQUEST ", INTEGRATIONS_HTTPREQUEST) }
291
+ winston.debug("(DirAskGPT) Integrations HttpRequest ", INTEGRATIONS_HTTPREQUEST)
317
292
 
318
293
  this.#myrequest(
319
294
  INTEGRATIONS_HTTPREQUEST, async (err, integration) => {
320
295
  if (err) {
321
- if (this.log) { console.error("DirAskGPT Get integrations error ", err); }
296
+ if (this.log) { winston.error("DirAskGPT Get integrations error ", err); }
322
297
  resolve(null);
323
298
  } else {
324
299
 
@@ -345,12 +320,12 @@ class DirAskGPT {
345
320
  },
346
321
  method: "GET"
347
322
  }
348
- if (this.log) { console.log("DirAskGPT KB_HTTPREQUEST", KB_HTTPREQUEST); }
323
+ winston.debug("(DirAskGPT) KB HttpRequest ", KB_HTTPREQUEST);
349
324
 
350
325
  this.#myrequest(
351
326
  KB_HTTPREQUEST, async (err, resbody) => {
352
327
  if (err) {
353
- if (this.log) { console.error("DirAskGPT Get kb settings error ", err); }
328
+ winston.error("DirAskGPT Get kb settings error ", err?.response?.data);
354
329
  resolve(null);
355
330
  } else {
356
331
  if (!resbody.gptkey) {