@tiledesk/tiledesk-tybot-connector 2.0.22 → 2.0.23
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/logs/app.log +40887 -11058
- package/logs/app1.log +996 -0
- package/logs/app8.log +37636 -0
- package/package.json +1 -1
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirReply.js +1 -0
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +1 -0
- package/utils/TiledeskChatbotUtil.js +189 -28
package/package.json
CHANGED
|
@@ -599,7 +599,7 @@ class DirAskGPTV2 {
|
|
|
599
599
|
return new Promise((resolve) => {
|
|
600
600
|
let engine = {
|
|
601
601
|
name: "pinecone",
|
|
602
|
-
type: isHybrid ? "serverless" :
|
|
602
|
+
type: isHybrid ? "serverless" : process.env.PINECONE_TYPE,
|
|
603
603
|
apikey: "",
|
|
604
604
|
vector_size: 1536,
|
|
605
605
|
index_name: isHybrid ? process.env.PINECONE_INDEX_HYBRID : process.env.PINECONE_INDEX
|
|
@@ -307,34 +307,195 @@ class TiledeskChatbotUtil {
|
|
|
307
307
|
let command = commands[i];
|
|
308
308
|
if (command.type === 'message' && command.message) {
|
|
309
309
|
if (command.message.attributes && command.message.attributes.attachment && command.message.attributes.attachment.json_buttons){
|
|
310
|
-
// console.log("command with buttons ok:")
|
|
311
310
|
let json_buttons_string = command.message.attributes.attachment.json_buttons;
|
|
312
|
-
let
|
|
313
|
-
let final_buttons = [];
|
|
311
|
+
let final_buttons = this.renderJSONButtons(json_buttons_string, flow_attributes);
|
|
312
|
+
// let final_buttons = [];
|
|
313
|
+
// try {
|
|
314
|
+
// // fill buttons
|
|
315
|
+
// const filler = new Filler();
|
|
316
|
+
// json_buttons_string = filler.fill(json_buttons_string, flow_attributes);
|
|
317
|
+
// let json_buttons = JSON.parse(json_buttons_string);
|
|
318
|
+
// if (Array.isArray(json_buttons)) {
|
|
319
|
+
// json_buttons.forEach(button => {
|
|
320
|
+
// if (button.value && button.type === "action" && button.action) {
|
|
321
|
+
// button.show_echo = true;
|
|
322
|
+
// final_buttons.push(button);
|
|
323
|
+
// }
|
|
324
|
+
// else if (button.value && button.type === "text") {
|
|
325
|
+
// button.show_echo = true;
|
|
326
|
+
// final_buttons.push(button);
|
|
327
|
+
// }
|
|
328
|
+
// else if (button.value && button.type === "url" && button.link) {
|
|
329
|
+
// button.show_echo = true;
|
|
330
|
+
// final_buttons.push(button);
|
|
331
|
+
// }
|
|
332
|
+
// else {
|
|
333
|
+
// winston.verbose("Invalid button. Skipping:", button);
|
|
334
|
+
// }
|
|
335
|
+
// });
|
|
336
|
+
// }
|
|
337
|
+
|
|
338
|
+
// // "buttons": [
|
|
339
|
+
// // {
|
|
340
|
+
// // "type": "action",
|
|
341
|
+
// // "value": "Button1", // obbligatorio sempre
|
|
342
|
+
// // "action": "#bb347206-d639-4926-94c9-e94930623dce", // mandatory
|
|
343
|
+
// // "show_echo": true, // lo inserisco sempre
|
|
344
|
+
// // "alias": "button1 alias"
|
|
345
|
+
// // },
|
|
346
|
+
// // {
|
|
347
|
+
// // "type": "text",
|
|
348
|
+
// // "value": "Button2 text", // obbligatorio sempre
|
|
349
|
+
// // "show_echo": true // lo inserisco sempre
|
|
350
|
+
// // },
|
|
351
|
+
// // {
|
|
352
|
+
// // "type": "url",
|
|
353
|
+
// // "value": "Button3 link", // obbligatorio sempre
|
|
354
|
+
// // "link": "http://", // obbligatorio
|
|
355
|
+
// // "show_echo": true // lo inserisco sempre
|
|
356
|
+
// // }
|
|
357
|
+
// // ]
|
|
358
|
+
// }
|
|
359
|
+
// catch(error) {
|
|
360
|
+
// winston.warn("Invalid json_buttons:", error)
|
|
361
|
+
// }
|
|
362
|
+
if (final_buttons && final_buttons.length > 0) {
|
|
363
|
+
command.message.attributes.attachment.buttons = final_buttons;
|
|
364
|
+
delete command.message.attributes.attachment.json_buttons;
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
winston.verbose("Invalid json_buttons. Skipping...")
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return all_buttons;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
static renderJSONButtons(json_buttons_string, flow_attributes) {
|
|
378
|
+
let final_buttons = [];
|
|
379
|
+
try {
|
|
380
|
+
// fill buttons
|
|
381
|
+
const filler = new Filler();
|
|
382
|
+
json_buttons_string = filler.fill(json_buttons_string, flow_attributes);
|
|
383
|
+
let json_buttons = JSON.parse(json_buttons_string);
|
|
384
|
+
if (Array.isArray(json_buttons)) {
|
|
385
|
+
json_buttons.forEach(button => {
|
|
386
|
+
if (button.value && button.type === "action" && button.action) {
|
|
387
|
+
button.show_echo = true;
|
|
388
|
+
final_buttons.push(button);
|
|
389
|
+
}
|
|
390
|
+
else if (button.value && button.type === "text") {
|
|
391
|
+
button.show_echo = true;
|
|
392
|
+
final_buttons.push(button);
|
|
393
|
+
}
|
|
394
|
+
else if (button.value && button.type === "url" && button.link) {
|
|
395
|
+
button.show_echo = true;
|
|
396
|
+
final_buttons.push(button);
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
winston.verbose("Invalid button. Skipping:", button);
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// "buttons": [
|
|
405
|
+
// {
|
|
406
|
+
// "type": "action",
|
|
407
|
+
// "value": "Button1", // obbligatorio sempre
|
|
408
|
+
// "action": "#bb347206-d639-4926-94c9-e94930623dce", // mandatory
|
|
409
|
+
// "show_echo": true, // lo inserisco sempre
|
|
410
|
+
// "alias": "button1 alias"
|
|
411
|
+
// },
|
|
412
|
+
// {
|
|
413
|
+
// "type": "text",
|
|
414
|
+
// "value": "Button2 text", // obbligatorio sempre
|
|
415
|
+
// "show_echo": true // lo inserisco sempre
|
|
416
|
+
// },
|
|
417
|
+
// {
|
|
418
|
+
// "type": "url",
|
|
419
|
+
// "value": "Button3 link", // obbligatorio sempre
|
|
420
|
+
// "link": "http://", // obbligatorio
|
|
421
|
+
// "show_echo": true // lo inserisco sempre
|
|
422
|
+
// }
|
|
423
|
+
// ]
|
|
424
|
+
}
|
|
425
|
+
catch(error) {
|
|
426
|
+
winston.warn("Invalid json_buttons:", error)
|
|
427
|
+
return null;
|
|
428
|
+
}
|
|
429
|
+
return final_buttons;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
static replaceJSONGalleries(message, flow_attributes) {
|
|
433
|
+
if (message.attributes && message.attributes.commands) {
|
|
434
|
+
let commands = message.attributes.commands;
|
|
435
|
+
if (commands.length > 0) {
|
|
436
|
+
for (let i = 0; i < commands.length; i++) {
|
|
437
|
+
let command = commands[i];
|
|
438
|
+
if (command.type === 'message' && command.message) {
|
|
439
|
+
if (command.message.attributes && command.message.attributes.attachment && command.message.attributes.attachment.json_gallery){
|
|
440
|
+
let final_gallery = [];
|
|
314
441
|
try {
|
|
315
|
-
// fill
|
|
442
|
+
// fill previews
|
|
316
443
|
const filler = new Filler();
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
}
|
|
325
|
-
else if (button.value && button.type === "text") {
|
|
326
|
-
button.show_echo = true;
|
|
327
|
-
final_buttons.push(button);
|
|
328
|
-
}
|
|
329
|
-
else if (button.value && button.type === "url" && button.link) {
|
|
330
|
-
button.show_echo = true;
|
|
331
|
-
final_buttons.push(button);
|
|
332
|
-
}
|
|
333
|
-
else {
|
|
334
|
-
winston.verbose("Invalid button. Skipping:", button);
|
|
444
|
+
let json_gallery_string = command.message.attributes.attachment.json_gallery;
|
|
445
|
+
json_gallery_string = filler.fill(json_gallery_string, flow_attributes);
|
|
446
|
+
let json_gallery = JSON.parse(json_gallery_string);
|
|
447
|
+
if (Array.isArray(json_gallery)) {
|
|
448
|
+
json_gallery.forEach(el => {
|
|
449
|
+
if (el.buttons) {
|
|
450
|
+
el.buttons = TiledeskChatbotUtil.renderJSONButtons(JSON.stringify(el.buttons));
|
|
335
451
|
}
|
|
452
|
+
final_gallery.push(el);
|
|
336
453
|
});
|
|
337
454
|
}
|
|
455
|
+
else {
|
|
456
|
+
winston.verbose("Invalid json_gallery.");
|
|
457
|
+
}
|
|
458
|
+
// "gallery": [
|
|
459
|
+
// {
|
|
460
|
+
// "preview": {
|
|
461
|
+
// "src": "https://eu.rtmv3.tiledesk.com/api/images?path=uploads%2Fusers%2F63a05d755f117f0013541383%2Fimages%2F8913ff2c-d788-45e1-ac71-ee5bae8479e2%2Fhybrid-settings.png",
|
|
462
|
+
// "uid": "mcamfa6s"
|
|
463
|
+
// },
|
|
464
|
+
// "title": "Title 1",
|
|
465
|
+
// "description": "Description 1",
|
|
466
|
+
// "buttons": [
|
|
467
|
+
// {
|
|
468
|
+
// "uid": "0a956f4637584ee4862360c19a161f8f",
|
|
469
|
+
// "type": "url",
|
|
470
|
+
// "value": "Prod1",
|
|
471
|
+
// "link": "https://URL1",
|
|
472
|
+
// "target": "blank",
|
|
473
|
+
// "action": "",
|
|
474
|
+
// "attributes": "",
|
|
475
|
+
// "show_echo": true
|
|
476
|
+
// },
|
|
477
|
+
// {
|
|
478
|
+
// "uid": "4a87abe3d03a4b6fbdbc3fc33c4a8430",
|
|
479
|
+
// "type": "action",
|
|
480
|
+
// "value": "Prod1.1 (connector)",
|
|
481
|
+
// "link": "",
|
|
482
|
+
// "target": "blank",
|
|
483
|
+
// "action": "#0f7aaefd-3147-466b-82a4-06756f36eea5",
|
|
484
|
+
// "attributes": "",
|
|
485
|
+
// "show_echo": true
|
|
486
|
+
// },
|
|
487
|
+
// {
|
|
488
|
+
// "uid": "31fac2c82ce24da0a2e9850a32165fe8",
|
|
489
|
+
// "type": "text",
|
|
490
|
+
// "value": "Prod1.2 (text)",
|
|
491
|
+
// "link": "https://url2",
|
|
492
|
+
// "target": "blank",
|
|
493
|
+
// "action": "",
|
|
494
|
+
// "attributes": "",
|
|
495
|
+
// "show_echo": true
|
|
496
|
+
// }
|
|
497
|
+
// ]
|
|
498
|
+
// },
|
|
338
499
|
|
|
339
500
|
// "buttons": [
|
|
340
501
|
// {
|
|
@@ -358,21 +519,21 @@ class TiledeskChatbotUtil {
|
|
|
358
519
|
// ]
|
|
359
520
|
}
|
|
360
521
|
catch(error) {
|
|
361
|
-
winston.warn("
|
|
522
|
+
winston.warn("Error on JSON gallery parsing:", error);
|
|
362
523
|
}
|
|
363
|
-
if (
|
|
364
|
-
command.message.attributes.attachment.
|
|
365
|
-
delete command.message.attributes.attachment.
|
|
524
|
+
if (final_gallery && final_gallery.length > 0) {
|
|
525
|
+
command.message.attributes.attachment.gallery = final_gallery;
|
|
526
|
+
delete command.message.attributes.attachment.json_gallery;
|
|
366
527
|
}
|
|
367
528
|
else {
|
|
368
|
-
winston.verbose("Invalid
|
|
529
|
+
winston.verbose("Invalid JSON Gallery.")
|
|
369
530
|
}
|
|
370
531
|
}
|
|
371
532
|
}
|
|
372
533
|
}
|
|
373
534
|
}
|
|
374
535
|
}
|
|
375
|
-
return
|
|
536
|
+
return message;
|
|
376
537
|
}
|
|
377
538
|
|
|
378
539
|
static buttonByText(text, buttons) {
|