@tiledesk/tiledesk-tybot-connector 0.2.601-rc1 → 0.3.1

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 (73) hide show
  1. package/CHANGELOG.md +387 -1
  2. package/ExtApi.js +6 -7
  3. package/Logger.js +74 -0
  4. package/TdCache.js +81 -176
  5. package/TdCache_v3.js +261 -0
  6. package/TiledeskExpression.js +7 -3
  7. package/TiledeskServices/AIService.js +43 -0
  8. package/TiledeskServices/utils.js +99 -0
  9. package/index.js +305 -50
  10. package/logs/app.log +279 -0
  11. package/models/IntentsMachineFactory.js +5 -2
  12. package/models/MockBotsDataSource.js +19 -11
  13. package/models/TiledeskChatbot.js +97 -79
  14. package/models/TiledeskChatbotConst.js +12 -17
  15. package/models/TiledeskChatbotUtil.js +359 -109
  16. package/models/TiledeskIntentsMachine.js +1 -1
  17. package/models/faqKbService.js +1 -1
  18. package/package.json +8 -6
  19. package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +172 -106
  20. package/tiledeskChatbotPlugs/Filler.js +13 -2
  21. package/tiledeskChatbotPlugs/TildeskContextForCodeOrchestrator.js +8 -0
  22. package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +13 -7
  23. package/tiledeskChatbotPlugs/directives/DirAddTags.js +374 -0
  24. package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +476 -0
  25. package/tiledeskChatbotPlugs/directives/DirAskGPT.js +16 -19
  26. package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +221 -34
  27. package/tiledeskChatbotPlugs/directives/DirAssign.js +0 -11
  28. package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +11 -21
  29. package/tiledeskChatbotPlugs/directives/DirAssistant.js +728 -0
  30. package/tiledeskChatbotPlugs/directives/DirBrevo.js +353 -0
  31. package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +3 -30
  32. package/tiledeskChatbotPlugs/directives/DirClearTranscript.js +22 -0
  33. package/tiledeskChatbotPlugs/directives/DirClose.js +16 -3
  34. package/tiledeskChatbotPlugs/directives/DirCode.js +1 -1
  35. package/tiledeskChatbotPlugs/directives/DirCondition.js +0 -26
  36. package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +182 -0
  37. package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +121 -0
  38. package/tiledeskChatbotPlugs/directives/DirCustomerio.js +5 -8
  39. package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +11 -1
  40. package/tiledeskChatbotPlugs/directives/DirDepartment.js +15 -6
  41. package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +17 -6
  42. package/tiledeskChatbotPlugs/directives/DirForm.js +12 -2
  43. package/tiledeskChatbotPlugs/directives/DirGptTask.js +83 -38
  44. package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +4 -7
  45. package/tiledeskChatbotPlugs/directives/DirHubspot.js +5 -8
  46. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +14 -27
  47. package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +278 -0
  48. package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +147 -51
  49. package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +125 -0
  50. package/tiledeskChatbotPlugs/directives/DirIntent.js +8 -37
  51. package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +5 -26
  52. package/tiledeskChatbotPlugs/directives/DirMessage.js +19 -17
  53. package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +135 -0
  54. package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +20 -87
  55. package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +59 -0
  56. package/tiledeskChatbotPlugs/directives/DirQapla.js +6 -9
  57. package/tiledeskChatbotPlugs/directives/DirRandomReply.js +17 -7
  58. package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +17 -7
  59. package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +11 -2
  60. package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +135 -21
  61. package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +163 -0
  62. package/tiledeskChatbotPlugs/directives/DirReply.js +53 -9
  63. package/tiledeskChatbotPlugs/directives/DirReplyV2.js +347 -0
  64. package/tiledeskChatbotPlugs/directives/DirSendEmail.js +13 -23
  65. package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +247 -0
  66. package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +202 -15
  67. package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +13 -4
  68. package/tiledeskChatbotPlugs/directives/DirWait.js +21 -4
  69. package/tiledeskChatbotPlugs/directives/DirWebRequest.js +1 -2
  70. package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +166 -103
  71. package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +2 -60
  72. package/tiledeskChatbotPlugs/directives/Directives.js +16 -1
  73. /package/tiledeskChatbotPlugs/directives/{DirOfflineHours.js → DEPRECATED_DirOfflineHours.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -5,8 +5,394 @@
5
5
  available on:
6
6
  ▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
7
7
 
8
+ # v0.3.1
9
+ - bug-fixed: callback is not defined
8
10
 
9
- # v0.2.61 (next-release)
11
+ # v0.2.153-rc8
12
+ - added: fixToken function in TiledeskService utils class
13
+
14
+ # v0.2.153-rc4
15
+ - log added
16
+
17
+ # v0.2.153-rc3
18
+ - added: specchToText function to transcript audio file
19
+
20
+ # v0.2.153-rc1
21
+ - changed: context for gpt-40 and gpt-40-mini
22
+
23
+ # v0.2.152
24
+ - Restored old default context for AskKB Action
25
+ - Deleted message "Intent not found".
26
+
27
+ # v0.2.151
28
+ - bug-fixed: context for gpt-40 and gpt-40-mini
29
+
30
+ # v0.2.150
31
+ - changed: AiPrompt action to improves errors management
32
+
33
+ # v0.2.149
34
+
35
+ # v0.2.149-rc3
36
+ - changed: context for gpt-40 and gpt-40-mini
37
+
38
+ # v0.2.149-rc2
39
+ - bug-fixed: botid null or undefined while calling /ext/:boid
40
+
41
+ # v0.2.148
42
+ - bug-fixed: namespace is undefined and "engine" property if noIntent is not specified
43
+
44
+ # v0.2.147
45
+ - bug-fixed: namespace is undefined and "engine" property cannot be evaluated in DirAskGPTV2
46
+
47
+ # v0.2.146
48
+ - bug-fixed: message.attributes["flowAttributes"]
49
+
50
+ # v0.2.146-rc1
51
+ - bug-fixed: message.attributes["flowAttributes"] added only if value size is <= 1kb
52
+
53
+ # v0.2.145
54
+ - added: TILEBOT_ENDPOINT env variable to startApp method
55
+
56
+ # v0.2.144
57
+ - Removed userFlowAttributes from message.attributes (fix message too long issue)
58
+
59
+ # v0.2.143
60
+ - Changed: env var TILEBOT_ENDPOINT replaced with TILEBOT_ENDPOINT
61
+
62
+ # v0.2.142
63
+ - Bug-fix: action.isInfo added in DirMessage fo fix test
64
+
65
+ # v0.2.141
66
+ - Bug-fix: message.attributes.payload not visible on first message
67
+
68
+ # v0.2.140
69
+ - Bug-fix: block hidden message for non-dev conversation
70
+
71
+ # v0.2.139
72
+ - Added ReplaceBotV3 action
73
+ - Updated Redis to 4.7.0
74
+
75
+ # v0.2.138
76
+ - Bug-fixed: hiddenMessage not blocked
77
+ - Bug-fixed: DirAskGPTV2 has hardcoded engine
78
+
79
+ # v0.2.138-rc8
80
+ - Updated redis to 4.7.0
81
+ - Updated tdCache
82
+
83
+ # v0.2.138-rc6
84
+ - First deploy external
85
+
86
+ # v0.2.138-rc1
87
+ - Updated redis to 4.7.0
88
+ - Updated tdCache
89
+
90
+ # v0.2.137
91
+ - Updated: hidden message is enabled only in dev mode for dratf requests
92
+ - Bug-fixed: flows variables is not updated with attributes.payload
93
+
94
+ # v0.2.136
95
+ - TdCache rollback
96
+
97
+ # v0.2.135
98
+ - Updated to redis 4.7.0 + Tdcache.js
99
+ - Disabled close_directive_test.js - DirClose directive - too old, not passing
100
+ - Disabled conversation-gpt_assistant_test.js
101
+
102
+ # v0.2.134
103
+ - Added filter for mweb on hidden messages
104
+
105
+ # v0.2.133
106
+ - Removed MAX_STEPS and MAX_EXECUTION_TIME as static variable of TiledeskChatbot
107
+
108
+ # v0.2.132
109
+ - Added support for external API_ENDPOINT
110
+ - Removed logs
111
+
112
+ # v0.2.131-rc2
113
+ - changed API_URL with API_ENDPOINT
114
+
115
+ # v0.2.131
116
+ - added: AUDIO_RECORD vxml action as reply_v2 actionType
117
+ - added: DirAddTags action
118
+ - externalized: process.env.CHATBOT_MAX_STEPS and process.env.CHATBOT_MAX_EXECUTION_TIME
119
+
120
+ # v0.2.130
121
+ - (TiledeskChatbotUtil) fix process.env.API_ENDPOINT => process.env.API_URL
122
+ - index.js /block => added "token": "NO-TOKEN"
123
+ - (TiledeskChatbotUtil) added: chatbot.addParameter(TiledeskChatbotConst.API_BASE_URL, process.env.API_ENDPOINT);
124
+
125
+ # v0.2.130-rc5
126
+ - (TiledeskChatbotUtil) fix process.env.API_ENDPOINT => process.env.API_URL
127
+
128
+ # v0.2.130-rc4
129
+ - (TiledeskChatbotUtil) process.env.API_ENDPOINT => process.env.API_URL
130
+
131
+ # v0.2.130-rc3
132
+ - index.js /block => added "token": "NO-TOKEN"
133
+ - (TiledeskChatbotUtil) added: chatbot.addParameter(TiledeskChatbotConst.API_BASE_URL, process.env.API_ENDPOINT);
134
+
135
+ # v0.2.129 -> test
136
+ - (TiledeskChatbot) sending as "info": "An error occurred while getting locked intent:'" + locked_intent + "'"
137
+ - (DirectivesChatbotPlug) added try catch on new TiledeskClient() => try {tdclient = new TiledeskClient({...})}
138
+
139
+ # v0.2.128 -> test
140
+ - Updated axios from 0.27.2 to 1.7.7
141
+ - fixes tdcache .set() with callback
142
+
143
+ # v0.2.127 -> test
144
+ - TiledeskChatbot =>
145
+ - static MAX_STEPS = 1000;
146
+ - static MAX_EXECUTION_TIME = 1000 * 3600 * 8;
147
+
148
+ # v0.2.126 -> test
149
+ - TdCache async del(key, callback) FIXED (await unsupported problem)
150
+
151
+ # v0.2.125 -> test
152
+ - class TiledeskChatbot static MAX_STEPS = 1000;
153
+ - class TiledeskChatbot static MAX_EXECUTION_TIME = 1000 * 3600 * 6; Increased from 4 => 6 hours
154
+
155
+ # v0.2.124 -> test
156
+ - TiledeskChatbot.js: fixed problem with locked-intent error.
157
+ - DirectivesChatbotPlug -> errorMessage is now hidden
158
+ - TESTING WITH VALUES: static MAX_STEPS = 10 && MAX_EXECUTION_TIME = 1000 * 60 * 2; (2 minutes)
159
+
160
+ # v0.2.123 -> test
161
+ - DirSendEmail removed log
162
+
163
+ # v0.2.122 -> test
164
+ - fixed check if (!this.validWebhookURL(this.webhookurl)) {... on WebhookChatbotPlug.js with return
165
+ - removed logs, err => JSON.stringify(err)
166
+
167
+ # v0.2.121 -> test
168
+ - added check if (!this.validWebhookURL(this.webhookurl)) {... on WebhookChatbotPlug.js
169
+
170
+ # v0.2.120 -> prod
171
+ - removed check in go() - it is already in execute() - on SetAttributeV2: if (!action) {...}
172
+ - merged Whatsapp Action
173
+ - updated "@tiledesk/tiledesk-client": "^0.10.13"
174
+
175
+ # v0.2.119 -> test
176
+ - fixed: addParameter("payload", message) => addParameter("payload", message.attributes.payload)
177
+ - JSONCondition: added in constructor => this.chatbot = context.chatbot;
178
+
179
+ # v0.2.118 -> test
180
+ - added payload to attributes: await chatbot.addParameter("payload", message);
181
+
182
+ # v0.2.117 -> test
183
+ - block endpoint fixed with APIURL
184
+
185
+ # v0.2.116 -> test
186
+ - updates @tiledesk/tiledesk-client => v0.10.12
187
+
188
+ # v0.2.115 -> test
189
+ - removed log console.error("TiledeskExpression.evaluate() error:...")
190
+ - Log setting fix in DirectivesChatbotPlug: const tdclient = new TiledeskClient({...
191
+ - SetAttributeV2: added check for action null: if (!action) {...
192
+ - SetAttributeV2:added check with ? operator: if (action.operation?.operators === undefined && ...
193
+
194
+ # v0.2.114 -> test
195
+ - Creating draft webhook endpoint on index.js: router.post('/block/:project_id/:bot_id/:block_id' ...
196
+ - Added check on attribute size < 20Mb
197
+ - SetAttributeV2: added persistency service
198
+
199
+ # v0.2.113 -> prod
200
+ - Fixed DirClose not importing TiledeskChatbotConst
201
+
202
+ # v0.2.112 -> prod
203
+ - Fix index name in DirAskGPTV2
204
+
205
+ # v0.2.111 -> test
206
+ - Updated DirAskGPTV2 with engine support
207
+
208
+ # v0.2.110 -> test
209
+ - Added DirMoveToUnassigned
210
+ - Added DirConnectBlock
211
+
212
+ # v0.2.109 -> test
213
+ - Added DirMoveToUnassigned
214
+ - Fixed bug: GptTask doesn't work properly with trascript
215
+
216
+ # v0.2.108 -> test
217
+ - Added chatbot_id
218
+ - Added support for citations in AskGPTV2
219
+ - Added support Json type in GPT Task
220
+
221
+ # v0.2.107 -> production
222
+ - clean logs (more)
223
+
224
+ # v0.2.106 -> production
225
+ - clean logs
226
+
227
+ # v0.2.105 -> production
228
+ - clean logs
229
+
230
+ # v0.2.104 -> production
231
+ - isValid fixed
232
+
233
+ # v0.2.103 -> test
234
+ - isValid removed
235
+
236
+ # v0.2.102
237
+ - isValid modified: if (parts.length >= 4) instead of "if (parts.length === 4)" that blocked whatsapp requests
238
+
239
+ # v0.2.101
240
+ - Dynamic attribute "now" is a ISOString date
241
+ - MAX_EXECUTION_TIME = 1000 * 3600 * 4 // 4 hours
242
+
243
+ # v0.2.100 -> test
244
+ - Added "chatbotToken" to RESERVED attributes
245
+ - Added UUID, UUIDv4 dynamic attributes
246
+ - Remove console.error from Filler liquidJS catch clause
247
+
248
+ # v0.2.98
249
+ - Support for MAX_EXECUTION_TIME (total execution time of a flow without user interaction)
250
+ - MAX_STEPS = 1000
251
+ - MAX_EXECUTION_TIME = 12 hrs
252
+
253
+ # v0.2.97
254
+ - Added support for "chatbotToken” attribute
255
+ - Added new Action: clear_transcript
256
+ - Exclude transcript generation when request type differs from "support-group-*"
257
+ - "step" key reset on DirWait => this.chatbot.addParameter( step_key, 0 )
258
+
259
+ # v0.2.96
260
+ - Added timestamp (number) and now (Date Object) attributes
261
+
262
+ - Added a limit in upload and download for WebRequestV2: maxContentLength: 10000000, // max 10mb response size, maxBodyLength: 10000000 // max 10mb request body size
263
+ - Added jsonCondition test on json objects properties
264
+ - Added flowError on JSONCondition when result = null
265
+ - Added fix on Filler
266
+
267
+ - Added possibility to select namespace by name
268
+ - Added filler to namespace in DirAskGPTv2
269
+ - Added filler to command.settings in DirReply
270
+
271
+ # v0.2.95
272
+ - If Online Agents V2 - bug fix (If Project Available Agents V2 -> MWeb)
273
+
274
+ # v0.2.94
275
+ - Added support for chat history for AskGPTv2 action
276
+
277
+ # v0.2.93
278
+ - Added model contexts
279
+
280
+ # v0.2.92
281
+ - Improved GPTTask Action with support for history
282
+
283
+ # v0.2.91
284
+ - Added voice flow attributes: dnis, callId, ani
285
+
286
+ # v0.2.89
287
+ - Added convertToNumber to operations in setAttribute
288
+ - Added setAttributeV2 test
289
+
290
+ # v0.2.88
291
+ - Added DirContactUpdate (aka LeadUpdate). No test case added for LeadUpdate. Only testable with a validation test.
292
+ - Fixed: Attribute parameters userFullname & userEmail now are able to "bypass" the request.lead not correctly updating on the same conversation. If updated in the flow (through LeadUpdate action), they will maintain their own value through the current conversation flow.
293
+
294
+ # v0.2.87
295
+ - Fixed DirAssistant empty error {}
296
+ - Added to DirAssistant "lastMessageData" attribute (The message content original JSON structure useful to get annotations in messages, message type etc.)
297
+
298
+ # v0.2.86
299
+ - Added to ifOnlineAgents Action: ignoreProjectWideOperatingHours = action.ignoreOperatingHours;
300
+ - Updated ifOnlineAgents with get available agents with 'raw' option
301
+
302
+ # v0.2.85
303
+ - Improved "If operating hours" action with time slots
304
+ - Other fix (?)
305
+
306
+ # v0.2.84
307
+ - Fixed "guest#" bug
308
+ - Fixed default_context in AskGPTv2
309
+
310
+ # v0.2.83
311
+ - Added support for advanced context in AskGPTv2
312
+
313
+ # v0.2.82
314
+ - Added {context} in 'system_context' in AskGPTv2
315
+
316
+ # v0.2.81
317
+ - Changed from 'context' to 'system_context' in AskGPTv2
318
+
319
+ # v0.2.80
320
+ - Changed AskGPT Action to support namespaces
321
+
322
+ # v0.2.79 - dev
323
+ - Fixed. Get DepartmentId for default department in test-mode in IfOnelineAgentsV2 with correct attribute get with chatbot.getParameter()
324
+
325
+ # v0.2.78 - dev
326
+ - Fixed? Get DepartmentId for default department in test-mode in IfOnelineAgentsV2
327
+
328
+ # v0.2.77 - dev
329
+ - Fix. get images and urls. image URL was Wrongly removed after the upload message
330
+
331
+ # v0.2.76 - dev
332
+ - Added support to button alias
333
+
334
+ # v0.2.75 - dev
335
+ - Fix. get images and urls also without text
336
+ - "userLeadId" = message.request.lead._id (instead of the unuseful lead.lead_id)
337
+
338
+ # v0.2.74 - online
339
+ - Fix. Get DepartmentId for default department in test-mode in IfOnelineAgentsV2
340
+
341
+ # v0.2.73 - debug
342
+ - Fix. static getMachine with check on bot not null
343
+
344
+ # v0.2.72
345
+ - Fix. userParams not in /reserved...
346
+
347
+ # v0.2.71
348
+ - Fix. DirReplyV2 "NoInput" bug. Refactored with the introduction of "timeout_id", an ID specific for each noInput timeout: this.chatbot.addParameter(TiledeskChatbotConst.USER_INPUT, timeout_id)
349
+
350
+ # v0.2.70
351
+ - added DirIfOnlineAgentsV2
352
+ - Fix. TiledeskChatbot: WRONG: await chatbot.addParameter("userInput", true); ====> FIXED: this.addParameter("userInput", true)
353
+ - Fix. Fixed WRONG addParameter(key, value) invocation in TiledeskChatbot with 3 (instead of key, value) parameters
354
+
355
+ # v0.2.69
356
+ - added flow attributes in reply action (original)
357
+
358
+ # v0.2.68
359
+ - added flow attributes in replyv2 action
360
+ - ReplyV2 now "re-forwards" the original message when the "no-match" connector is undefined (behaving exactly like the classic Reply)
361
+
362
+ # v0.2.67
363
+ - console.log crash fixed on noinput
364
+
365
+ # v0.2.66
366
+ - changed updateQuotes method
367
+ - fix missing model in updateQuote
368
+ - added ReplyV2
369
+
370
+ # v0.2.66-rc1
371
+ - fix missing model in updateQuote
372
+
373
+ # v0.2.65 - online
374
+ - fix OPENAI_APIKEY: removed Bearer prefix
375
+
376
+ # v0.2.64
377
+ - removed system parameters from /reserved/parameters
378
+ - Web Request Action: added multipart form-data support with files binary from URL source
379
+ - Added DirAssistant Action
380
+
381
+ # v0.2.63
382
+ - BUG fix on /ext/parameters/requests/:requestid
383
+ - Moved getChatbotParameters function in TiledeskChatbotUtil
384
+
385
+ # v0.2.62
386
+ - Whatsapp fix (transcript error whitout "senderFullname")
387
+
388
+ # v0.2.62-rc4
389
+ - Whatsapp fix (transcript error whitout "senderFullname")
390
+
391
+ # v0.2.62-rc1
392
+ - Added VXML actions (speech_form, play_prompt)
393
+
394
+ # v0.2.61
395
+ - fixed WebRequestv2 timeout
10
396
 
11
397
  # v0.2.61-rc1
12
398
  - Added VXML actions (dmtf_menu, dtmf_form, blind_transfer)
package/ExtApi.js CHANGED
@@ -4,9 +4,9 @@ let https = require("https");
4
4
  class ExtApi {
5
5
 
6
6
  constructor(options) {
7
- if (!options.ENDPOINT) {
8
- throw new Error("options.ENDPOINT is mandatory");
9
- //this.extEndpoint = `${options.TYBOT_ENDPOINT}/;
7
+ if (!options.TILEBOT_ENDPOINT) {
8
+ throw new Error("options.TILEBOT_ENDPOINT is mandatory");
9
+ //this.extEndpoint = `${options.TILEBOT_ENDPOINT}/;
10
10
  }
11
11
  if (options.log) {
12
12
  this.log = options.log;
@@ -14,7 +14,7 @@ class ExtApi {
14
14
  else {
15
15
  this.log = false;
16
16
  }
17
- this.ENDPOINT = options.ENDPOINT;
17
+ this.TILEBOT_ENDPOINT = options.TILEBOT_ENDPOINT;
18
18
  }
19
19
 
20
20
  fixToken(token) {
@@ -37,7 +37,7 @@ class ExtApi {
37
37
  */
38
38
  sendSupportMessageExt(message, projectId, requestId, token, callback) {
39
39
  const jwt_token = this.fixToken(token);
40
- const url = `${this.ENDPOINT}/ext/${projectId}/requests/${requestId}/messages`;
40
+ const url = `${this.TILEBOT_ENDPOINT}/ext/${projectId}/requests/${requestId}/messages`;
41
41
  if (this.log) {console.log("sendSupportMessageExt URL", url);}
42
42
  const HTTPREQUEST = {
43
43
  url: url,
@@ -76,7 +76,6 @@ class ExtApi {
76
76
  * @param {string} token. User token
77
77
  */
78
78
  // sendMessageToBot(message, botId, token, callback) {
79
- // const jwt_token = this.fixToken(token);
80
79
  // const url = `${this.ENDPOINT}/ext/${botId}`;
81
80
  // if (this.log) {console.log("sendMessageToBot URL", url);}
82
81
  // const HTTPREQUEST = {
@@ -141,7 +140,7 @@ class ExtApi {
141
140
  }
142
141
  })
143
142
  .catch( (error) => {
144
- console.error("An error occurred:", error);
143
+ console.error("(ExtApi) An error occurred:", JSON.stringify(error));
145
144
  if (callback) {
146
145
  callback(error, null, null);
147
146
  }
package/Logger.js ADDED
@@ -0,0 +1,74 @@
1
+ let { Publisher } = require("@tiledesk/tiledesk-multi-worker");
2
+
3
+ const AMQP_MANAGER_URL = process.env.AMQP_MANAGER_URL;
4
+ let publisher = new Publisher(AMQP_MANAGER_URL, {
5
+ debug: false,
6
+ queueName: "logs_queue",
7
+ exchange: "tiledesk-multi",
8
+ topic: "logs",
9
+ })
10
+
11
+ class Logger {
12
+
13
+ constructor(config) {
14
+
15
+ if (!config) {
16
+ throw new Error('config is mandatory');
17
+ }
18
+
19
+ if (!config.request_id) {
20
+ console.error('config.request_id is mandatory');
21
+ //throw new Error('config.request_id is mandatory');
22
+ }
23
+
24
+ this.request_id = config.request_id;
25
+ this.dev = config.dev;
26
+
27
+ if (!AMQP_MANAGER_URL) {
28
+ console.error('AMQP_MANAGER_URL is undefined. Logger not available...');
29
+ return;
30
+ //throw new Error("Error starting logger: AMQP_MANAGER_URL is undefined.")
31
+ }
32
+
33
+ }
34
+
35
+ error(text) {
36
+ if (!this.request_id || !publisher) {
37
+ console.log("Return because request or publisher is undefined", this.request_id, publisher);
38
+ return;
39
+ }
40
+
41
+ let data = {
42
+ request_id: this.request_id,
43
+ text: text,
44
+ level: "error",
45
+ timestamp: new Date()
46
+ }
47
+ publisher.publish(data, (err, ok) => {
48
+ if (err) console.warn("publish log fail: ", err);
49
+ return;
50
+ })
51
+ }
52
+
53
+ info(text) {
54
+ if (!this.request_id || !publisher) {
55
+ console.log("Return because request or publisher is undefined", this.request_id, publisher);
56
+ return;
57
+ }
58
+
59
+ let data = {
60
+ request_id: this.request_id,
61
+ text: text,
62
+ level: "info",
63
+ timestamp: new Date()
64
+ }
65
+
66
+ publisher.publish(data, (err, ok) => {
67
+ if (err) console.warn("publish log fail: ", err);
68
+ return;
69
+ })
70
+ }
71
+
72
+ }
73
+
74
+ module.exports = { Logger }