@tiledesk/tiledesk-tybot-connector 0.2.601-rc1 → 0.3.0
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.
- package/CHANGELOG.md +378 -1
- package/ExtApi.js +6 -6
- package/TdCache copy.js +242 -0
- package/TdCache.js +81 -176
- package/TdCache_v3.js +261 -0
- package/TiledeskExpression.js +7 -3
- package/index.js +290 -43
- package/logs/app.log +279 -0
- package/models/IntentsMachineFactory.js +5 -2
- package/models/MockBotsDataSource.js +19 -11
- package/models/TiledeskChatbot.js +97 -79
- package/models/TiledeskChatbotConst.js +12 -17
- package/models/TiledeskChatbotUtil.js +353 -109
- package/models/TiledeskIntentsMachine.js +1 -1
- package/models/faqKbService.js +1 -1
- package/package.json +7 -6
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +172 -106
- package/tiledeskChatbotPlugs/Filler.js +13 -2
- package/tiledeskChatbotPlugs/TildeskContextForCodeOrchestrator.js +8 -0
- package/tiledeskChatbotPlugs/WebhookChatbotPlug.js +13 -7
- package/tiledeskChatbotPlugs/directives/DirAddTags.js +374 -0
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +476 -0
- package/tiledeskChatbotPlugs/directives/DirAskGPT.js +16 -19
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +221 -34
- package/tiledeskChatbotPlugs/directives/DirAssign.js +0 -11
- package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +11 -21
- package/tiledeskChatbotPlugs/directives/DirAssistant.js +728 -0
- package/tiledeskChatbotPlugs/directives/DirBrevo.js +353 -0
- package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +3 -30
- package/tiledeskChatbotPlugs/directives/DirClearTranscript.js +22 -0
- package/tiledeskChatbotPlugs/directives/DirClose.js +16 -3
- package/tiledeskChatbotPlugs/directives/DirCode.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirCondition.js +0 -26
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +183 -0
- package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +121 -0
- package/tiledeskChatbotPlugs/directives/DirCustomerio.js +5 -8
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +11 -1
- package/tiledeskChatbotPlugs/directives/DirDepartment.js +15 -6
- package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +17 -6
- package/tiledeskChatbotPlugs/directives/DirForm.js +12 -2
- package/tiledeskChatbotPlugs/directives/DirGptTask.js +83 -38
- package/tiledeskChatbotPlugs/directives/DirGptTask_OLD.js +4 -7
- package/tiledeskChatbotPlugs/directives/DirHubspot.js +5 -8
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +14 -27
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgentsV2.js +278 -0
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +147 -51
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +125 -0
- package/tiledeskChatbotPlugs/directives/DirIntent.js +8 -36
- package/tiledeskChatbotPlugs/directives/DirJSONCondition.js +5 -26
- package/tiledeskChatbotPlugs/directives/DirMessage.js +19 -17
- package/tiledeskChatbotPlugs/directives/DirMessageToBot.js +136 -0
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +20 -87
- package/tiledeskChatbotPlugs/directives/DirMoveToUnassigned.js +59 -0
- package/tiledeskChatbotPlugs/directives/DirQapla.js +6 -9
- package/tiledeskChatbotPlugs/directives/DirRandomReply.js +17 -7
- package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +17 -7
- package/tiledeskChatbotPlugs/directives/DirReplaceBot.js +11 -2
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +135 -21
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +163 -0
- package/tiledeskChatbotPlugs/directives/DirReply.js +42 -9
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +347 -0
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +13 -23
- package/tiledeskChatbotPlugs/directives/DirSendWhatsapp.js +247 -0
- package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +202 -15
- package/tiledeskChatbotPlugs/directives/DirSetConversationTags.js +13 -4
- package/tiledeskChatbotPlugs/directives/DirWait.js +21 -4
- package/tiledeskChatbotPlugs/directives/DirWebRequest.js +1 -2
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +166 -103
- package/tiledeskChatbotPlugs/directives/DirWhatsappByAttribute.js +2 -60
- package/tiledeskChatbotPlugs/directives/Directives.js +16 -1
- /package/tiledeskChatbotPlugs/directives/{DirOfflineHours.js → DEPRECATED_DirOfflineHours.js} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiledesk/tiledesk-tybot-connector",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Tiledesk Tybot connector",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"@tiledesk/helpcenter-query-client": "^0.1.8",
|
|
15
15
|
"@tiledesk/tiledesk-chatbot-client": "^0.5.30",
|
|
16
16
|
"@tiledesk/tiledesk-chatbot-util": "^0.8.39",
|
|
17
|
-
"@tiledesk/tiledesk-client": "^0.10.
|
|
17
|
+
"@tiledesk/tiledesk-client": "^0.10.13",
|
|
18
18
|
"accept-language-parser": "^1.5.0",
|
|
19
|
-
"axios": "^
|
|
19
|
+
"axios": "^1.7.7",
|
|
20
20
|
"body-parser": "^1.19.0",
|
|
21
21
|
"cors": "^2.8.5",
|
|
22
22
|
"dotenv": "^16.0.3",
|
|
@@ -24,13 +24,14 @@
|
|
|
24
24
|
"handlebars": "^4.7.7",
|
|
25
25
|
"jsonschema": "^1.4.1",
|
|
26
26
|
"jsonwebtoken": "^8.5.1",
|
|
27
|
+
"liquidjs": "^10.8.4",
|
|
27
28
|
"minimist-string": "^1.0.2",
|
|
28
29
|
"mongoose": "^6.3.5",
|
|
30
|
+
"multer": "^1.4.5-lts.1",
|
|
29
31
|
"nanoid": "^3.1.25",
|
|
30
|
-
"redis": "^
|
|
32
|
+
"redis": "^4.7.0",
|
|
31
33
|
"uuid": "^3.3.3",
|
|
32
|
-
"vm2": "^3.9.13"
|
|
33
|
-
"liquidjs": "^10.8.4"
|
|
34
|
+
"vm2": "^3.9.13"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"mocha": "^8.4.0"
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const { TiledeskChatbotUtil } = require('@tiledesk/tiledesk-chatbot-util');
|
|
2
2
|
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
3
3
|
const { DirDeflectToHelpCenter } = require('./directives/DirDeflectToHelpCenter');
|
|
4
|
-
// const { DirOfflineHours } = require('./directives/DirOfflineHours'); // DEPRECATED
|
|
5
4
|
const { DirMoveToAgent } = require('./directives/DirMoveToAgent');
|
|
6
5
|
const { DirMessage } = require('./directives/DirMessage');
|
|
7
6
|
const { DirWait } = require('./directives/DirWait');
|
|
@@ -44,7 +43,18 @@ const { DirMake } = require('./directives/DirMake');
|
|
|
44
43
|
const { DirReplaceBotV2 } = require('./directives/DirReplaceBotV2');
|
|
45
44
|
const { DirHubspot } = require('./directives/DirHubspot');
|
|
46
45
|
const { DirCustomerio } = require('./directives/DirCustomerio');
|
|
46
|
+
const { DirBrevo } = require('./directives/DirBrevo');
|
|
47
47
|
const { DirAskGPTV2 } = require('./directives/DirAskGPTV2');
|
|
48
|
+
const { DirAssistant } = require('./directives/DirAssistant');
|
|
49
|
+
const { DirReplyV2 } = require('./directives/DirReplyV2');
|
|
50
|
+
const { DirIfOnlineAgentsV2 } = require('./directives/DirIfOnlineAgentsV2');
|
|
51
|
+
const { DirContactUpdate } = require('./directives/DirContactUpdate');
|
|
52
|
+
const { DirClearTranscript } = require('./directives/DirClearTranscript');
|
|
53
|
+
const { DirMoveToUnassigned } = require('./directives/DirMoveToUnassigned');
|
|
54
|
+
const { DirAddTags } = require('./directives/DirAddTags');
|
|
55
|
+
const { DirSendWhatsapp } = require('./directives/DirSendWhatsapp');
|
|
56
|
+
const { DirReplaceBotV3 } = require('./directives/DirReplaceBotV3');
|
|
57
|
+
const { DirAiTask, DirAiPrompt } = require('./directives/DirAiPrompt');
|
|
48
58
|
|
|
49
59
|
class DirectivesChatbotPlug {
|
|
50
60
|
|
|
@@ -56,7 +66,7 @@ class DirectivesChatbotPlug {
|
|
|
56
66
|
|
|
57
67
|
constructor(config) {
|
|
58
68
|
this.supportRequest = config.supportRequest;
|
|
59
|
-
this.
|
|
69
|
+
this.API_ENDPOINT = config.API_ENDPOINT;
|
|
60
70
|
this.TILEBOT_ENDPOINT = config.TILEBOT_ENDPOINT;
|
|
61
71
|
this.token = config.token;
|
|
62
72
|
this.log = config.log;
|
|
@@ -116,7 +126,7 @@ class DirectivesChatbotPlug {
|
|
|
116
126
|
// console.log("supportRequest is:", JSON.stringify(supportRequest))
|
|
117
127
|
|
|
118
128
|
const token = this.token;
|
|
119
|
-
const
|
|
129
|
+
const API_ENDPOINT = this.API_ENDPOINT;
|
|
120
130
|
const TILEBOT_ENDPOINT = this.TILEBOT_ENDPOINT;
|
|
121
131
|
|
|
122
132
|
// const requestId = supportRequest.request_id
|
|
@@ -128,13 +138,19 @@ class DirectivesChatbotPlug {
|
|
|
128
138
|
}
|
|
129
139
|
const projectId = supportRequest.id_project;
|
|
130
140
|
const tdcache = this.tdcache;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
141
|
+
let tdclient = null;
|
|
142
|
+
try {
|
|
143
|
+
tdclient = new TiledeskClient({
|
|
144
|
+
projectId: projectId,
|
|
145
|
+
token: token,
|
|
146
|
+
APIURL: API_ENDPOINT,
|
|
147
|
+
APIKEY: "___",
|
|
148
|
+
log: this.log
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
catch(err) {
|
|
152
|
+
console.log("An error occurred while creating TiledeskClient in DirectivesChatbotPlug:", err);
|
|
153
|
+
}
|
|
138
154
|
|
|
139
155
|
this.context = {
|
|
140
156
|
projectId: projectId,
|
|
@@ -144,11 +160,10 @@ class DirectivesChatbotPlug {
|
|
|
144
160
|
supportRequest: supportRequest,
|
|
145
161
|
reply: this.reply,
|
|
146
162
|
requestId: supportRequest.request_id,
|
|
147
|
-
|
|
163
|
+
API_ENDPOINT: API_ENDPOINT,
|
|
148
164
|
TILEBOT_ENDPOINT: TILEBOT_ENDPOINT,
|
|
149
165
|
departmentId: depId,
|
|
150
166
|
tdcache: tdcache,
|
|
151
|
-
tdclient: tdclient,
|
|
152
167
|
HELP_CENTER_API_ENDPOINT: this.HELP_CENTER_API_ENDPOINT,
|
|
153
168
|
log: this.log
|
|
154
169
|
}
|
|
@@ -165,13 +180,13 @@ class DirectivesChatbotPlug {
|
|
|
165
180
|
async nextDirective(directives) {
|
|
166
181
|
if (this.log) {console.log("....nextDirective() checkStep():");}
|
|
167
182
|
const go_on = await TiledeskChatbot.checkStep(
|
|
168
|
-
this.context.tdcache, this.context.requestId,
|
|
183
|
+
this.context.tdcache, this.context.requestId, this.chatbot?.MAX_STEPS, this.chatbot?.MAX_EXECUTION_TIME, this.log
|
|
169
184
|
);
|
|
170
185
|
// const current_step = await TiledeskChatbot.currentStep(this.context.tdcache, this.context.requestId);
|
|
171
186
|
// if (this.log) {console.log("........nextDirective() currentStep:", current_step);}
|
|
172
|
-
if (go_on
|
|
187
|
+
if (go_on.error) {
|
|
173
188
|
if (this.log) {console.log("go_on == false! nextDirective() Stopped!");}
|
|
174
|
-
return this.errorMessage("Request error: anomaly detection. MAX ACTIONS exeeded.");
|
|
189
|
+
return this.errorMessage(go_on.error); //"Request error: anomaly detection. MAX ACTIONS exeeded.");
|
|
175
190
|
}
|
|
176
191
|
// else if (go_on == 2) {
|
|
177
192
|
// return null;
|
|
@@ -195,11 +210,13 @@ class DirectivesChatbotPlug {
|
|
|
195
210
|
name: "message",
|
|
196
211
|
action: {
|
|
197
212
|
"_tdThenStop": true,
|
|
213
|
+
isInfo: true,
|
|
198
214
|
text: message,
|
|
199
215
|
attributes: {
|
|
200
216
|
runtimeError: {
|
|
201
217
|
message: message
|
|
202
|
-
}
|
|
218
|
+
},
|
|
219
|
+
subtype: "info"
|
|
203
220
|
}
|
|
204
221
|
}
|
|
205
222
|
}
|
|
@@ -235,10 +252,6 @@ class DirectivesChatbotPlug {
|
|
|
235
252
|
// go on
|
|
236
253
|
// console.log("Going on to next directive...");
|
|
237
254
|
}
|
|
238
|
-
// }
|
|
239
|
-
// catch(error) {
|
|
240
|
-
// console.error("Error on locks:", error);
|
|
241
|
-
// }
|
|
242
255
|
|
|
243
256
|
}
|
|
244
257
|
if (directive == null || (directive !== null && directive["name"] === undefined)) {
|
|
@@ -268,8 +281,6 @@ class DirectivesChatbotPlug {
|
|
|
268
281
|
let next_dir = await this.nextDirective(this.directives);
|
|
269
282
|
this.process(next_dir);
|
|
270
283
|
}
|
|
271
|
-
// let next_dir = await this.nextDirective(this.directives);
|
|
272
|
-
// this.process(next_dir);
|
|
273
284
|
});
|
|
274
285
|
}
|
|
275
286
|
else if (directive_name === Directives.MESSAGE) {
|
|
@@ -291,6 +302,19 @@ class DirectivesChatbotPlug {
|
|
|
291
302
|
this.process(next_dir);
|
|
292
303
|
});
|
|
293
304
|
}
|
|
305
|
+
else if (directive_name === Directives.REPLY_V2) {
|
|
306
|
+
// console.log("...DirReplyV2");
|
|
307
|
+
new DirReplyV2(context).execute(directive, async (stop) => {
|
|
308
|
+
if (stop) {
|
|
309
|
+
if (context.log) { console.log("Stopping Actions on:", JSON.stringify(directive));}
|
|
310
|
+
this.theend();
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
314
|
+
this.process(next_dir);
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
}
|
|
294
318
|
else if (directive_name === Directives.DTMF_FORM) {
|
|
295
319
|
// console.log("...DirReply");
|
|
296
320
|
new DirReply(context).execute(directive, async () => {
|
|
@@ -312,6 +336,27 @@ class DirectivesChatbotPlug {
|
|
|
312
336
|
this.process(next_dir);
|
|
313
337
|
});
|
|
314
338
|
}
|
|
339
|
+
else if (directive_name === Directives.SPEECH_FORM) {
|
|
340
|
+
// console.log("...DirReply");
|
|
341
|
+
new DirReply(context).execute(directive, async () => {
|
|
342
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
343
|
+
this.process(next_dir);
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
else if (directive_name === Directives.PLAY_PROMPT) {
|
|
347
|
+
// console.log("...DirReply");
|
|
348
|
+
new DirReply(context).execute(directive, async () => {
|
|
349
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
350
|
+
this.process(next_dir);
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
else if (directive_name === Directives.AUDIO_RECORD) {
|
|
354
|
+
// console.log("...DirReply");
|
|
355
|
+
new DirReply(context).execute(directive, async () => {
|
|
356
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
357
|
+
this.process(next_dir);
|
|
358
|
+
});
|
|
359
|
+
}
|
|
315
360
|
else if (directive_name === Directives.RANDOM_REPLY) {
|
|
316
361
|
// console.log("...DirRandomReply");
|
|
317
362
|
new DirRandomReply(context).execute(directive, async () => {
|
|
@@ -329,8 +374,6 @@ class DirectivesChatbotPlug {
|
|
|
329
374
|
let next_dir = await this.nextDirective(this.directives);
|
|
330
375
|
this.process(next_dir);
|
|
331
376
|
}
|
|
332
|
-
// let next_dir = await this.nextDirective(this.directives);
|
|
333
|
-
// this.process(next_dir);
|
|
334
377
|
});
|
|
335
378
|
}
|
|
336
379
|
else if (directive_name === Directives.IF_ONLINE_AGENTS) {
|
|
@@ -348,6 +391,19 @@ class DirectivesChatbotPlug {
|
|
|
348
391
|
// this.process(next_dir);
|
|
349
392
|
});
|
|
350
393
|
}
|
|
394
|
+
else if (directive_name === Directives.IF_ONLINE_AGENTS_V2) {
|
|
395
|
+
// console.log("...DirIfOnlineAgents")
|
|
396
|
+
new DirIfOnlineAgentsV2(context).execute(directive, async (stop) => {
|
|
397
|
+
if (stop) {
|
|
398
|
+
if (context.log) { console.log("Stopping Actions on:", JSON.stringify(directive));}
|
|
399
|
+
this.theend();
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
403
|
+
this.process(next_dir);
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
}
|
|
351
407
|
else if (directive_name === Directives.FUNCTION_VALUE) {
|
|
352
408
|
// console.log("...DirAssignFromFunction")
|
|
353
409
|
new DirAssignFromFunction(context).execute(directive, async () => {
|
|
@@ -404,57 +460,6 @@ class DirectivesChatbotPlug {
|
|
|
404
460
|
this.process(next_dir);
|
|
405
461
|
});
|
|
406
462
|
}
|
|
407
|
-
// else if (directive_name === Directives.WHEN_OPEN) {
|
|
408
|
-
// // DEPRECATED
|
|
409
|
-
// const whenOpenDir = new DirWhenOpen(
|
|
410
|
-
// {
|
|
411
|
-
// tdclient: this.context.tdclient, // matches open hours
|
|
412
|
-
// log: false
|
|
413
|
-
// });
|
|
414
|
-
// whenOpenDir.execute(directive, directives, curr_directive_index, async () => {
|
|
415
|
-
// let next_dir = await this.nextDirective(this.directives);
|
|
416
|
-
// this.process(next_dir);
|
|
417
|
-
// });
|
|
418
|
-
// }
|
|
419
|
-
// else if (directive_name === Directives.WHEN_CLOSED) {
|
|
420
|
-
// // DEPRECATED
|
|
421
|
-
// const whenOpenDir = new DirWhenOpen(
|
|
422
|
-
// {
|
|
423
|
-
// tdclient: this.context.tdclient,
|
|
424
|
-
// checkOpen: false, // matches closed hours
|
|
425
|
-
// log: false
|
|
426
|
-
// });
|
|
427
|
-
// whenOpenDir.execute(directive, directives, curr_directive_index, async () => {
|
|
428
|
-
// let next_dir = await this.nextDirective(this.directives);
|
|
429
|
-
// this.process(next_dir);
|
|
430
|
-
// });
|
|
431
|
-
// }
|
|
432
|
-
// else if (directive_name === Directives.IF_AGENTS) {
|
|
433
|
-
// // DEPRECATED
|
|
434
|
-
// const ifNoAgentsDir = new DirIfAvailableAgents(
|
|
435
|
-
// {
|
|
436
|
-
// tdclient: this.context.tdclient,
|
|
437
|
-
// checkAgents: true, // check available agents > 0
|
|
438
|
-
// log: false
|
|
439
|
-
// });
|
|
440
|
-
// ifNoAgentsDir.execute(directive, directives, curr_directive_index, async () => {
|
|
441
|
-
// let next_dir = await this.nextDirective(this.directives);
|
|
442
|
-
// this.process(next_dir);
|
|
443
|
-
// });
|
|
444
|
-
// }
|
|
445
|
-
// else if (directive_name === Directives.IF_NO_AGENTS) {
|
|
446
|
-
// // DEPRECATED
|
|
447
|
-
// const ifNoAgentsDir = new DirIfAvailableAgents(
|
|
448
|
-
// {
|
|
449
|
-
// tdclient: this.context.tdclient,
|
|
450
|
-
// checkAgents: false, // check no available agents
|
|
451
|
-
// log: false
|
|
452
|
-
// });
|
|
453
|
-
// ifNoAgentsDir.execute(directive, directives, curr_directive_index, async () => {
|
|
454
|
-
// let next_dir = await this.nextDirective(this.directives);
|
|
455
|
-
// this.process(next_dir);
|
|
456
|
-
// });
|
|
457
|
-
// }
|
|
458
463
|
else if (directive_name === Directives.AGENT) {
|
|
459
464
|
// console.log("...DirMoveToAgent");
|
|
460
465
|
new DirMoveToAgent(context).execute(directive, async () => {
|
|
@@ -462,35 +467,6 @@ class DirectivesChatbotPlug {
|
|
|
462
467
|
this.process(next_dir);
|
|
463
468
|
});
|
|
464
469
|
}
|
|
465
|
-
// else if (directive_name === Directives.WHEN_ONLINE_MOVE_TO_AGENT) { // DEPRECATED?
|
|
466
|
-
// // let depId;
|
|
467
|
-
// // if (context.supportRequest && context.supportRequest.department && context.supportRequest.department._id) {
|
|
468
|
-
// // depId = context.supportRequest.department._id;
|
|
469
|
-
// // console.log("context.supportRequest", JSON.stringify(context.supportRequest));
|
|
470
|
-
// // const agentDir = new DirMoveToAgent(
|
|
471
|
-
// // {
|
|
472
|
-
// // tdclient: context.tdclient,
|
|
473
|
-
// // requestId: context.requestId,
|
|
474
|
-
// // depId: depId
|
|
475
|
-
// // }
|
|
476
|
-
// // );
|
|
477
|
-
// // if (!directive.action) {
|
|
478
|
-
// // directive.action = {}
|
|
479
|
-
// // directive.action = {
|
|
480
|
-
// // whenOnlineOnly: true
|
|
481
|
-
// // }
|
|
482
|
-
// // }
|
|
483
|
-
// new DirMoveToAgent(context).execute(directive, async () => {
|
|
484
|
-
// let next_dir = await this.nextDirective(this.directives);
|
|
485
|
-
// this.process(next_dir);
|
|
486
|
-
// });
|
|
487
|
-
// // }
|
|
488
|
-
// // else {
|
|
489
|
-
// // console.log("Warning. DepId null while calling 'WHEN_ONLINE_MOVE_TO_AGENT' directive")
|
|
490
|
-
// // let next_dir = await this.nextDirective(this.directives);
|
|
491
|
-
// // this.process(next_dir);
|
|
492
|
-
// // }
|
|
493
|
-
// }
|
|
494
470
|
else if (directive_name === Directives.CLOSE) {
|
|
495
471
|
// console.log("Exec close()")
|
|
496
472
|
new DirClose(context).execute(directive, async () => {
|
|
@@ -516,6 +492,12 @@ class DirectivesChatbotPlug {
|
|
|
516
492
|
this.process(next_dir);
|
|
517
493
|
});
|
|
518
494
|
}
|
|
495
|
+
else if (directive_name === Directives.REPLACE_BOT_V3) {
|
|
496
|
+
new DirReplaceBotV3(context).execute(directive, async () => {
|
|
497
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
498
|
+
this.process(next_dir);
|
|
499
|
+
});
|
|
500
|
+
}
|
|
519
501
|
else if (directive_name === Directives.WAIT) {
|
|
520
502
|
// console.log("........ DirWait");
|
|
521
503
|
new DirWait(context).execute(directive, async () => {
|
|
@@ -656,12 +638,36 @@ class DirectivesChatbotPlug {
|
|
|
656
638
|
}
|
|
657
639
|
});
|
|
658
640
|
}
|
|
641
|
+
else if (directive_name === Directives.AI_PROMPT) {
|
|
642
|
+
new DirAiPrompt(context).execute(directive, async (stop) => {
|
|
643
|
+
if (context.log) { console.log("AiPrompt stop?", stop);}
|
|
644
|
+
if (stop == true) {
|
|
645
|
+
if (context.log) { console.log("Stopping Actions on:", JSON.stringify(directive));}
|
|
646
|
+
this.theend();
|
|
647
|
+
}
|
|
648
|
+
else {
|
|
649
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
650
|
+
this.process(next_dir);
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
}
|
|
659
654
|
else if (directive_name === Directives.WHATSAPP_ATTRIBUTE) {
|
|
660
655
|
new DirWhatsappByAttribute(context).execute(directive, async (stop) => {
|
|
661
656
|
let next_dir = await this.nextDirective(this.directives);
|
|
662
657
|
this.process(next_dir);
|
|
663
658
|
});
|
|
664
659
|
}
|
|
660
|
+
else if (directive_name === Directives.SEND_WHATSAPP) {
|
|
661
|
+
new DirSendWhatsapp(context).execute(directive, async (stop) => {
|
|
662
|
+
if (stop == true) {
|
|
663
|
+
if (context.log) { console.log("Stoppin Actions on:", JSON.stringify(directive));}
|
|
664
|
+
this.theend();
|
|
665
|
+
} else {
|
|
666
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
667
|
+
this.process(next_dir);
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
}
|
|
665
671
|
else if (directive_name === Directives.QAPLA) {
|
|
666
672
|
new DirQapla(context).execute(directive, async (stop) => {
|
|
667
673
|
if (context.log) { console.log("DirQapla stop?", stop);}
|
|
@@ -706,6 +712,66 @@ class DirectivesChatbotPlug {
|
|
|
706
712
|
this.process(next_dir);
|
|
707
713
|
})
|
|
708
714
|
}
|
|
715
|
+
else if (directive_name === Directives.BREVO) {
|
|
716
|
+
new DirBrevo(context).execute(directive, async () => {
|
|
717
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
718
|
+
this.process(next_dir);
|
|
719
|
+
})
|
|
720
|
+
}
|
|
721
|
+
else if (directive_name === Directives.GPT_ASSISTANT) {
|
|
722
|
+
// console.log("...GPT_ASSISTANT");
|
|
723
|
+
new DirAssistant(context).execute(directive, async (stop) => {
|
|
724
|
+
if (context.log) { console.log("stop on condition?", stop);}
|
|
725
|
+
if (stop == true) {
|
|
726
|
+
if (context.log) { console.log("Stopping Actions on:", JSON.stringify(directive));}
|
|
727
|
+
this.theend();
|
|
728
|
+
}
|
|
729
|
+
else {
|
|
730
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
731
|
+
this.process(next_dir);
|
|
732
|
+
}
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
else if (directive_name === Directives.CONTACT_UPDATE) {
|
|
736
|
+
// console.log("...CONTACT_UPDATE");
|
|
737
|
+
new DirContactUpdate(context).execute(directive, async () => {
|
|
738
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
739
|
+
this.process(next_dir);
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
else if (directive_name === Directives.CLEAR_TRANSCRIPT) {
|
|
743
|
+
new DirClearTranscript(context).execute(directive, async () => {
|
|
744
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
745
|
+
this.process(next_dir);
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
else if (directive_name === Directives.MOVE_TO_UNASSIGNED) {
|
|
749
|
+
new DirMoveToUnassigned(context).execute(directive, async () => {
|
|
750
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
751
|
+
this.process(next_dir);
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
else if (directive_name === Directives.CONNECT_BLOCK) {
|
|
755
|
+
// console.log(".....DirIntent")
|
|
756
|
+
new DirConnectBlock(context).execute(directive, async () => {
|
|
757
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
758
|
+
this.process(next_dir);
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
else if (directive_name === Directives.ADD_TAGS) {
|
|
762
|
+
// console.log(".....DirAddTags")
|
|
763
|
+
new DirAddTags(context).execute(directive, async (stop) => {
|
|
764
|
+
if (context.log) { console.log("GPTTask stop?", stop);}
|
|
765
|
+
if (stop == true) {
|
|
766
|
+
if (context.log) { console.log("Stopping Actions on:", JSON.stringify(directive));}
|
|
767
|
+
this.theend();
|
|
768
|
+
}
|
|
769
|
+
else {
|
|
770
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
771
|
+
this.process(next_dir);
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
}
|
|
709
775
|
else {
|
|
710
776
|
//console.log("Unhandled Post-message Directive:", directive_name);
|
|
711
777
|
let next_dir = await this.nextDirective(this.directives);
|
|
@@ -722,7 +788,7 @@ class DirectivesChatbotPlug {
|
|
|
722
788
|
}
|
|
723
789
|
const supportRequest = this.supportRequest;
|
|
724
790
|
const token = this.token;
|
|
725
|
-
const
|
|
791
|
+
const API_ENDPOINT = this.API_ENDPOINT;
|
|
726
792
|
// const requestId = supportRequest.request_id
|
|
727
793
|
// let depId;
|
|
728
794
|
// if (supportRequest.department && supportRequest.department._id) {
|
|
@@ -732,7 +798,7 @@ class DirectivesChatbotPlug {
|
|
|
732
798
|
const tdclient = new TiledeskClient({
|
|
733
799
|
projectId: projectId,
|
|
734
800
|
token: token,
|
|
735
|
-
APIURL:
|
|
801
|
+
APIURL: API_ENDPOINT,
|
|
736
802
|
APIKEY: "___",
|
|
737
803
|
log: false
|
|
738
804
|
});
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
var { Liquid } = require('liquidjs');
|
|
2
2
|
var engine = new Liquid();
|
|
3
|
+
const { v4: uuidv4 } = require('uuid');
|
|
3
4
|
|
|
4
5
|
class Filler {
|
|
5
6
|
|
|
6
7
|
fill(text, parameters) {
|
|
8
|
+
// create dynamic attributes
|
|
9
|
+
if (!parameters) {
|
|
10
|
+
parameters = {};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
parameters["timestamp"] = Date.now(); // type number
|
|
14
|
+
parameters["now"] = new Date().toISOString(); // type Object
|
|
15
|
+
parameters["UUID"] = uuidv4().replace(/-/g, '');
|
|
16
|
+
parameters["UUIDv4"] = uuidv4();
|
|
17
|
+
|
|
7
18
|
// legacy parser first
|
|
8
19
|
if (text == null || text == undefined || typeof text !== 'string') {
|
|
9
20
|
// console.log("Skip filling. 'text' is null or not a string");
|
|
@@ -16,13 +27,13 @@ class Filler {
|
|
|
16
27
|
}
|
|
17
28
|
|
|
18
29
|
// then post process with new LiquidJS!
|
|
19
|
-
let result;
|
|
30
|
+
let result = text;
|
|
20
31
|
try {
|
|
21
32
|
result = engine
|
|
22
33
|
.parseAndRenderSync(text, parameters, null);
|
|
23
34
|
}
|
|
24
35
|
catch(e) {
|
|
25
|
-
|
|
36
|
+
// console.error(e)
|
|
26
37
|
}
|
|
27
38
|
return result;
|
|
28
39
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Only prototype code for the new "Code orchestrator"
|
|
3
|
+
*/
|
|
4
|
+
class Context {
|
|
5
|
+
constructor(env) {this.attributes = env;this.ops = {set: {},del: {} } } setAttribute(key, value) { this.ops.set[key] = value; }
|
|
6
|
+
deleteAttribute(key) { this.ops.del[key] = true; }
|
|
7
|
+
allAttributes() { return this.attributes; }
|
|
8
|
+
}
|
|
@@ -2,12 +2,6 @@ let axios = require('axios');
|
|
|
2
2
|
|
|
3
3
|
class WebhookChatbotPlug {
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* @example
|
|
7
|
-
* const { DirectivesChatbotPlug } = require('./DirectivesChatbotPlug');
|
|
8
|
-
*
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
5
|
constructor(supportRequest, webhookurl, token, log) {
|
|
12
6
|
this.supportRequest = supportRequest;
|
|
13
7
|
this.webhookurl = webhookurl;
|
|
@@ -22,6 +16,11 @@ class WebhookChatbotPlug {
|
|
|
22
16
|
if (answer.attributes && answer.attributes.webhook && answer.attributes.webhook === true) {
|
|
23
17
|
if (this.log) {console.log("EXECUTING WEBHOOK URL!", this.webhookurl);}
|
|
24
18
|
if (this.log) {console.log("EXECUTING WEBHOOK ON CONTEXT:", JSON.stringify(context));}
|
|
19
|
+
if (!this.validWebhookURL(this.webhookurl)) {
|
|
20
|
+
if (this.log) {console.error("(WebhookChatbotPlug) Error. Invalid webhook URL:", this.webhookurl, "on context:", JSON.stringify(context));}
|
|
21
|
+
pipeline.nextplug();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
25
24
|
this.execWebhook(answer, context, this.webhookurl, (err, message_from_webhook) => {
|
|
26
25
|
if (this.log) {console.log("message_from_webhook:", message_from_webhook);}
|
|
27
26
|
if (err) {
|
|
@@ -67,6 +66,13 @@ class WebhookChatbotPlug {
|
|
|
67
66
|
if (this.log) {console.log("Start processing webhook...");}
|
|
68
67
|
}
|
|
69
68
|
|
|
69
|
+
validWebhookURL(webhookurl) {
|
|
70
|
+
if (!webhookurl) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
|
|
70
76
|
execWebhook(reply_message, context, webhookurl, callback) {
|
|
71
77
|
if (this.log) {
|
|
72
78
|
console.log("WEBHOOK. on context", JSON.stringify(context));
|
|
@@ -194,7 +200,7 @@ class WebhookChatbotPlug {
|
|
|
194
200
|
}
|
|
195
201
|
})
|
|
196
202
|
.catch(function (error) {
|
|
197
|
-
console.error("
|
|
203
|
+
console.error("(WebhookChatbotPlug) Axios error: ", JSON.stringify(error));
|
|
198
204
|
if (callback) {
|
|
199
205
|
callback(error, null, null);
|
|
200
206
|
}
|