@tiledesk/tiledesk-tybot-connector 0.2.38 → 0.2.39
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
CHANGED
|
@@ -373,207 +373,226 @@ class TiledeskChatbotUtil {
|
|
|
373
373
|
static async updateRequestAttributes(chatbot, message, projectId, requestId) {
|
|
374
374
|
// update request context
|
|
375
375
|
try {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
376
|
+
if (chatbot.log) {console.log("Updating request variables. Message:", JSON.stringify(message));}
|
|
377
|
+
const messageId = message._id;
|
|
378
|
+
const chat_url = `https://panel.tiledesk.com/v3/dashboard/#/project/${projectId}/wsrequest/${requestId}/messages`
|
|
379
|
+
// await chatbot.addParameter("chatbot", chatbot);
|
|
380
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_CHAT_URL, chat_url);
|
|
381
|
+
// console.log("Adding proj_", projectId);
|
|
382
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_PROJECT_ID_KEY, projectId);
|
|
383
|
+
// TODO add projectName too
|
|
384
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_REQUEST_ID_KEY, requestId);
|
|
385
|
+
if (chatbot.bot) {
|
|
386
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_NAME_KEY, chatbot.bot.name);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
if (message.text && message.sender !== "_tdinternal") {
|
|
390
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_TEXT_KEY, message.text); // DEPRECATED
|
|
391
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_TEXT_v2_KEY, message.text);
|
|
392
|
+
if (message.channel) {
|
|
393
|
+
if (message.channel.name === "chat21") {
|
|
394
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_CHAT_CHANNEL, "web"); // renames the channel in chat21
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_CHAT_CHANNEL, message.channel.name);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_MESSAGE_TYPE_KEY, message.type);
|
|
401
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_MESSAGE_KEY, TiledeskChatbotUtil.lastUserMessageFrom(message)); // JSON TYPE *NEW
|
|
402
|
+
// get image
|
|
403
|
+
if (message.type && message.type === "image" && message.metadata) {
|
|
404
|
+
// "text": "\nimage text",
|
|
405
|
+
// "id_project": "65203e12f8c0cf002cf4110b",
|
|
406
|
+
// "createdBy": "8ac52a30-133f-4ee1-8b4b-96055bb81757",
|
|
407
|
+
// "metadata": {
|
|
408
|
+
// "height": 905,
|
|
409
|
+
// "name": "tiledesk_Open graph_general.png",
|
|
410
|
+
// "src": "https://firebasestorage.googleapis.com/v0/b/chat21-pre-01.appspot.com/o/public%2Fimages%2F8ac52a30-133f-4ee1-8b4b-96055bb81757%2Fda5bbc8d-5174-49a8-a041-3d9355242da5%2Ftiledesk_Open%20graph_general.png?alt=media&token=be82fecb-3cd1-45b9-a135-c2c57a932862",
|
|
411
|
+
// "type": "image/png",
|
|
412
|
+
// "uid": "lo68iyq5",
|
|
413
|
+
// "width": 1724
|
|
414
|
+
// }
|
|
415
|
+
if (message.metadata.src) {
|
|
416
|
+
await chatbot.addParameter("lastUserImageURL", message.metadata.src);
|
|
417
|
+
await chatbot.addParameter("lastUserImageName", message.metadata.name);
|
|
418
|
+
await chatbot.addParameter("lastUserImageWidth", message.metadata.width);
|
|
419
|
+
await chatbot.addParameter("lastUserImageHeight", message.metadata.height);
|
|
420
|
+
await chatbot.addParameter("lastUserImageType", message.metadata.type);
|
|
421
|
+
}
|
|
395
422
|
}
|
|
396
423
|
else {
|
|
397
|
-
await chatbot.addParameter(
|
|
424
|
+
await chatbot.addParameter("lastUserImageURL", null);
|
|
425
|
+
await chatbot.addParameter("lastUserImageName", null);
|
|
426
|
+
await chatbot.addParameter("lastUserImageWidth", null);
|
|
427
|
+
await chatbot.addParameter("lastUserImageHeight", null);
|
|
428
|
+
await chatbot.addParameter("lastUserImageType", null);
|
|
398
429
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
430
|
+
// get document
|
|
431
|
+
if (message.type && message.type === "file" && message.metadata) {
|
|
432
|
+
// "type": "file",
|
|
433
|
+
// "text": "[LIBRETTO-WEB-ISTRUZIONI-GENITORI.pdf](https://firebasestorage.googleapis.com/v0/b/chat21-pre-01.appspot.com/o/public%2Fimages%2F8ac52a30-133f-4ee1-8b4b-96055bb81757%2F502265ee-4f4a-47a4-9375-172bb0e6bf39%2FLIBRETTO-WEB-ISTRUZIONI-GENITORI.pdf?alt=media&token=a09d065a-9b56-4507-8960-344cc294e4d1)\nistruzioni",
|
|
434
|
+
// "metadata": {
|
|
435
|
+
// "name": "LIBRETTO-WEB-ISTRUZIONI-GENITORI.pdf",
|
|
436
|
+
// "src": "https://firebasestorage.googleapis.com/v0/b/chat21-pre-01.appspot.com/o/public%2Fimages%2F8ac52a30-133f-4ee1-8b4b-96055bb81757%2F502265ee-4f4a-47a4-9375-172bb0e6bf39%2FLIBRETTO-WEB-ISTRUZIONI-GENITORI.pdf?alt=media&token=a09d065a-9b56-4507-8960-344cc294e4d1",
|
|
437
|
+
// "type": "application/pdf",
|
|
438
|
+
// "uid": "lo68oz8i"
|
|
439
|
+
// }
|
|
440
|
+
if (message.metadata.src) {
|
|
441
|
+
await chatbot.addParameter("lastUserDocumentURL", message.metadata.src);
|
|
442
|
+
await chatbot.addParameter("lastUserDocumentName", message.metadata.name);
|
|
443
|
+
await chatbot.addParameter("lastUserDocumentType", message.metadata.type);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
else {
|
|
447
|
+
await chatbot.addParameter("lastUserDocumentURL", null);
|
|
448
|
+
await chatbot.addParameter("lastUserDocumentName", null);
|
|
449
|
+
await chatbot.addParameter("lastUserDocumentType", null);
|
|
450
|
+
}
|
|
451
|
+
if (message && message.request && message.request.lead) {
|
|
452
|
+
if (message.request.lead.email) {
|
|
453
|
+
await chatbot.addParameter("userEmail", message.request.lead.email);
|
|
454
|
+
}
|
|
455
|
+
if (message.request.lead.fullname) {
|
|
456
|
+
console.log("got lead.fullname:", message.request.lead.fullname);
|
|
457
|
+
try {
|
|
458
|
+
const current_userFullname = await chatbot.getParameter("userFullname");
|
|
459
|
+
console.log("current_userFullname:", current_userFullname);
|
|
460
|
+
if (current_userFullname && current_userFullname.startsWith("guest#")) {
|
|
461
|
+
console.log("current_userFullname && current_userFullname.startsWith('guest#')");
|
|
462
|
+
await chatbot.addParameter("userFullname", message.request.lead.fullname);
|
|
463
|
+
}
|
|
464
|
+
else if (!current_userFullname) {
|
|
465
|
+
console.log("no current_userFullname");
|
|
466
|
+
await chatbot.addParameter("userFullname", message.request.lead.fullname);
|
|
467
|
+
console.log("it was null, set to the incoming one");
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
catch(error) {
|
|
471
|
+
console.error("Error on setting userFullname:", error);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
console.log("!lead.fullname");
|
|
476
|
+
}
|
|
477
|
+
if (message.request.lead.phone) {
|
|
478
|
+
await chatbot.addParameter("userPhone", message.request.lead.phone);
|
|
479
|
+
}
|
|
480
|
+
if (message.request.lead.lead_id) {
|
|
481
|
+
await chatbot.addParameter("userLeadId", message.request.lead.lead_id);
|
|
482
|
+
}
|
|
483
|
+
if (message.request.lead.company) {
|
|
484
|
+
await chatbot.addParameter("userCompany", message.request.lead.company);
|
|
485
|
+
}
|
|
421
486
|
}
|
|
422
487
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_MESSAGE_ID_KEY, messageId);
|
|
491
|
+
if (message.request && message.request.location && message.request.location.country) {
|
|
492
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_COUNTRY_KEY, message.request.location.country);
|
|
493
|
+
}
|
|
494
|
+
if (message.request && message.request.location && message.request.location.city) {
|
|
495
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_CITY_KEY, message.request.location.city);
|
|
429
496
|
}
|
|
430
|
-
//
|
|
431
|
-
if (message.
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
// "
|
|
435
|
-
|
|
436
|
-
//
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
// }
|
|
440
|
-
if (message.metadata.src) {
|
|
441
|
-
await chatbot.addParameter("lastUserDocumentURL", message.metadata.src);
|
|
442
|
-
await chatbot.addParameter("lastUserDocumentName", message.metadata.name);
|
|
443
|
-
await chatbot.addParameter("lastUserDocumentType", message.metadata.type);
|
|
497
|
+
// console.log("message.request.language", message.request["language"]);
|
|
498
|
+
if (message.request) {
|
|
499
|
+
let user_language = message.request["language"];
|
|
500
|
+
if (message.request["language"]) {
|
|
501
|
+
// console.log("HTTP language:", message.request["language"]);
|
|
502
|
+
var languages = parser.parse(message.request["language"]);
|
|
503
|
+
// console.log("languages:", languages);
|
|
504
|
+
if (languages && languages.length > 0 && languages[0].code) {
|
|
505
|
+
user_language = languages[0].code;
|
|
444
506
|
}
|
|
445
507
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
await chatbot.addParameter("lastUserDocumentType", null);
|
|
508
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_USER_SOURCE_PAGE_KEY, message.request.sourcePage);
|
|
509
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_USER_LANGUAGE_KEY, user_language);
|
|
510
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_USER_AGENT_KEY, message.request.userAgent);
|
|
450
511
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
512
|
+
// console.log("message.request.language", message.request["language"])
|
|
513
|
+
if (message.request && message.request.department) {
|
|
514
|
+
// It was an error when getting this from widget message's attributes
|
|
515
|
+
// await chatbot.addParameter(TiledeskChatbotConst.REQ_DEPARTMENT_ID_KEY, message.attributes.departmentId);
|
|
516
|
+
// await chatbot.addParameter(TiledeskChatbotConst.REQ_DEPARTMENT_NAME_KEY, message.attributes.departmentName);
|
|
517
|
+
// get from request.department instead
|
|
518
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_DEPARTMENT_ID_KEY, message.request.department._id);
|
|
519
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_DEPARTMENT_NAME_KEY, message.request.department.name);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
if (projectId === "641864da99c1fb00131ba495") {
|
|
523
|
+
console.log("641864da99c1fb00131ba495 > for projectId:", JSON.stringify(message))
|
|
524
|
+
}
|
|
525
|
+
// for BUG
|
|
526
|
+
// if (chatbot.log) {console.log("message.request.attributes.payload", JSON.stringify(message.request.attributes.payload))}
|
|
527
|
+
if (message && message.request && message.request.attributes && message.request.attributes.payload) {
|
|
528
|
+
if (!message.attributes) {
|
|
529
|
+
message.attributes = {}
|
|
530
|
+
}
|
|
531
|
+
message.attributes.payload = message.request.attributes.payload
|
|
532
|
+
if (chatbot.log) {console.log("FORCED SET message.attributes.payload:", JSON.stringify(message.attributes.payload))}
|
|
533
|
+
// if (projectId === "641864da99c1fb00131ba495") {console.log("641864da99c1fb00131ba495 > FORCED SET message.attributes.payload:", JSON.stringify(message.attributes.payload))}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
if (message.attributes) {
|
|
537
|
+
if (chatbot.log) {console.log("Ok message.attributes", JSON.stringify(message.attributes));}
|
|
538
|
+
if (projectId === "641864da99c1fb00131ba495") {console.log("641864da99c1fb00131ba495 > Ok message.attributes", JSON.stringify(message.attributes));}
|
|
539
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_END_USER_ID_KEY, message.attributes.requester_id);
|
|
540
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_END_USER_IP_ADDRESS_KEY, message.attributes.ipAddress);
|
|
541
|
+
if (message.attributes.payload) {
|
|
542
|
+
try {
|
|
543
|
+
for (const [key, value] of Object.entries(message.attributes.payload)) {
|
|
544
|
+
// const value = all_parameters[key];
|
|
545
|
+
const value_type = typeof value;
|
|
546
|
+
//if (projectId === "641864da99c1fb00131ba495") {console.log("641864da99c1fb00131ba495 > importing payload parameter:", key, "value:", value, "type:", value_type);}
|
|
547
|
+
//await chatbot.addParameter(key, String(value));
|
|
548
|
+
await chatbot.addParameter(key, value);
|
|
460
549
|
}
|
|
461
|
-
if (message.request.lead.lead_id) {
|
|
462
|
-
await chatbot.addParameter("userLeadId", message.request.lead.lead_id);
|
|
463
550
|
}
|
|
464
|
-
|
|
465
|
-
|
|
551
|
+
catch(err) {
|
|
552
|
+
console.error("Error importing message payload in request variables:", err);
|
|
466
553
|
}
|
|
467
554
|
}
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_MESSAGE_ID_KEY, messageId);
|
|
472
|
-
if (message.request && message.request.location && message.request.location.country) {
|
|
473
|
-
await chatbot.addParameter(TiledeskChatbotConst.REQ_COUNTRY_KEY, message.request.location.country);
|
|
474
|
-
}
|
|
475
|
-
if (message.request && message.request.location && message.request.location.city) {
|
|
476
|
-
await chatbot.addParameter(TiledeskChatbotConst.REQ_CITY_KEY, message.request.location.city);
|
|
477
|
-
}
|
|
478
|
-
// console.log("message.request.language", message.request["language"]);
|
|
479
|
-
if (message.request) {
|
|
480
|
-
let user_language = message.request["language"];
|
|
481
|
-
if (message.request["language"]) {
|
|
482
|
-
// console.log("HTTP language:", message.request["language"]);
|
|
483
|
-
var languages = parser.parse(message.request["language"]);
|
|
484
|
-
// console.log("languages:", languages);
|
|
485
|
-
if (languages && languages.length > 0 && languages[0].code) {
|
|
486
|
-
user_language = languages[0].code;
|
|
487
555
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
}
|
|
493
|
-
// console.log("message.request.language", message.request["language"])
|
|
494
|
-
if (message.request && message.request.department) {
|
|
495
|
-
// It was an error when getting this from widget message's attributes
|
|
496
|
-
// await chatbot.addParameter(TiledeskChatbotConst.REQ_DEPARTMENT_ID_KEY, message.attributes.departmentId);
|
|
497
|
-
// await chatbot.addParameter(TiledeskChatbotConst.REQ_DEPARTMENT_NAME_KEY, message.attributes.departmentName);
|
|
498
|
-
// get from request.department instead
|
|
499
|
-
await chatbot.addParameter(TiledeskChatbotConst.REQ_DEPARTMENT_ID_KEY, message.request.department._id);
|
|
500
|
-
await chatbot.addParameter(TiledeskChatbotConst.REQ_DEPARTMENT_NAME_KEY, message.request.department.name);
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
if (projectId === "641864da99c1fb00131ba495") {
|
|
504
|
-
console.log("641864da99c1fb00131ba495 > for projectId:", JSON.stringify(message))
|
|
505
|
-
}
|
|
506
|
-
// for BUG
|
|
507
|
-
// if (chatbot.log) {console.log("message.request.attributes.payload", JSON.stringify(message.request.attributes.payload))}
|
|
508
|
-
if (message && message.request && message.request.attributes && message.request.attributes.payload) {
|
|
509
|
-
if (!message.attributes) {
|
|
510
|
-
message.attributes = {}
|
|
511
|
-
}
|
|
512
|
-
message.attributes.payload = message.request.attributes.payload
|
|
513
|
-
if (chatbot.log) {console.log("FORCED SET message.attributes.payload:", JSON.stringify(message.attributes.payload))}
|
|
514
|
-
// if (projectId === "641864da99c1fb00131ba495") {console.log("641864da99c1fb00131ba495 > FORCED SET message.attributes.payload:", JSON.stringify(message.attributes.payload))}
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
if (message.attributes) {
|
|
518
|
-
if (chatbot.log) {console.log("Ok message.attributes", JSON.stringify(message.attributes));}
|
|
519
|
-
if (projectId === "641864da99c1fb00131ba495") {console.log("641864da99c1fb00131ba495 > Ok message.attributes", JSON.stringify(message.attributes));}
|
|
520
|
-
await chatbot.addParameter(TiledeskChatbotConst.REQ_END_USER_ID_KEY, message.attributes.requester_id);
|
|
521
|
-
await chatbot.addParameter(TiledeskChatbotConst.REQ_END_USER_IP_ADDRESS_KEY, message.attributes.ipAddress);
|
|
522
|
-
if (message.attributes.payload) {
|
|
523
|
-
try {
|
|
524
|
-
for (const [key, value] of Object.entries(message.attributes.payload)) {
|
|
525
|
-
// const value = all_parameters[key];
|
|
526
|
-
const value_type = typeof value;
|
|
527
|
-
//if (projectId === "641864da99c1fb00131ba495") {console.log("641864da99c1fb00131ba495 > importing payload parameter:", key, "value:", value, "type:", value_type);}
|
|
528
|
-
//await chatbot.addParameter(key, String(value));
|
|
529
|
-
await chatbot.addParameter(key, value);
|
|
530
|
-
}
|
|
556
|
+
|
|
557
|
+
const _bot = chatbot.bot; // aka FaqKB
|
|
558
|
+
if (chatbot.log) {
|
|
559
|
+
console.log("Adding Globals to context..., chatbot.attributes?", JSON.stringify(_bot));
|
|
531
560
|
}
|
|
532
|
-
|
|
533
|
-
|
|
561
|
+
|
|
562
|
+
if (_bot.attributes && _bot.attributes.globals) {
|
|
563
|
+
if (chatbot.log) {console.log("Got Globals:", JSON.stringify(_bot.attributes.globals));}
|
|
564
|
+
_bot.attributes.globals.forEach(async (global_var) => {
|
|
565
|
+
if (chatbot.log) {console.log("Adding global:", global_var.key, "value:", global_var.value);}
|
|
566
|
+
await chatbot.addParameter(global_var.key, global_var.value);
|
|
567
|
+
});
|
|
534
568
|
}
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
if (chatbot.log) {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
console.log("requestId:", requestId);
|
|
562
|
-
console.log("KEY:", TiledeskChatbotConst.REQ_PROJECT_ID_KEY);
|
|
563
|
-
// console.log("TiledeskChatbot:", TiledeskChatbot);
|
|
564
|
-
let proj_ = await chatbot.getParameter(TiledeskChatbotConst.REQ_PROJECT_ID_KEY);
|
|
565
|
-
console.log("request parameter proj_:", proj_);
|
|
566
|
-
const all_parameters = await chatbot.allParameters();
|
|
567
|
-
for (const [key, value] of Object.entries(all_parameters)) {
|
|
568
|
-
// const value = all_parameters[key];
|
|
569
|
-
const value_type = typeof value;
|
|
570
|
-
if (chatbot.log) {console.log("REQUEST ATTRIBUTE:", key, "VALUE:", value, "TYPE:", value_type)}
|
|
571
|
-
}
|
|
569
|
+
// await chatbot.addParameter("testVar",
|
|
570
|
+
// {
|
|
571
|
+
// name: "Andrea",
|
|
572
|
+
// coords: {
|
|
573
|
+
// x: 2, y: 1
|
|
574
|
+
// }
|
|
575
|
+
// }
|
|
576
|
+
// );
|
|
577
|
+
|
|
578
|
+
if (chatbot.log) {
|
|
579
|
+
// console.log("tdcache:", chatbot.tdcache);
|
|
580
|
+
console.log("requestId:", requestId);
|
|
581
|
+
console.log("KEY:", TiledeskChatbotConst.REQ_PROJECT_ID_KEY);
|
|
582
|
+
// console.log("TiledeskChatbot:", TiledeskChatbot);
|
|
583
|
+
let proj_ = await chatbot.getParameter(TiledeskChatbotConst.REQ_PROJECT_ID_KEY);
|
|
584
|
+
console.log("request parameter proj_:", proj_);
|
|
585
|
+
const all_parameters = await chatbot.allParameters();
|
|
586
|
+
for (const [key, value] of Object.entries(all_parameters)) {
|
|
587
|
+
// const value = all_parameters[key];
|
|
588
|
+
const value_type = typeof value;
|
|
589
|
+
if (chatbot.log) {console.log("REQUEST ATTRIBUTE:", key, "VALUE:", value, "TYPE:", value_type)}
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
} catch(error) {
|
|
593
|
+
console.error("Error", error)
|
|
594
|
+
process.exit(1)
|
|
572
595
|
}
|
|
573
|
-
} catch(error) {
|
|
574
|
-
console.error("Error", error)
|
|
575
|
-
process.exit(1)
|
|
576
|
-
}
|
|
577
596
|
// message["attributes"]: {
|
|
578
597
|
// "departmentId": "63c980054f857c00350535bc",
|
|
579
598
|
// "departmentName": "Default Department",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiledesk/tiledesk-tybot-connector",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.39",
|
|
4
4
|
"description": "Tiledesk Tybot connector",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,7 +14,7 @@
|
|
|
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.5",
|
|
18
18
|
"accept-language-parser": "^1.5.0",
|
|
19
19
|
"axios": "^0.27.2",
|
|
20
20
|
"body-parser": "^1.19.0",
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
const { Filler } = require('../Filler');
|
|
2
|
+
|
|
3
|
+
class DirSetConversationTags {
|
|
4
|
+
|
|
5
|
+
constructor(context) {
|
|
6
|
+
if (!context) {
|
|
7
|
+
throw new Error('context object is mandatory.');
|
|
8
|
+
}
|
|
9
|
+
this.context = context;
|
|
10
|
+
this.log = context.log;
|
|
11
|
+
this.tdclient = context.tdclient;
|
|
12
|
+
this.requestId = context.requestId;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
execute(directive, callback) {
|
|
16
|
+
let action;
|
|
17
|
+
if (directive.action) {
|
|
18
|
+
action = directive.action
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
callback();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
this.go(action, () => {
|
|
25
|
+
callback();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async go(action, callback) {
|
|
30
|
+
if (this.log) {console.log("(DirSetConversationTags) Adding conversation tags:", action.depName);}
|
|
31
|
+
let tagsString = action.tags;
|
|
32
|
+
tagsString = tagsString.replace(/ /g,"");
|
|
33
|
+
if (tagsString.length === 0) {
|
|
34
|
+
if (this.log) {console.error("(DirSetConversationTags) Invalid action: tags string is empty")};
|
|
35
|
+
callback();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
if (this.tdcache) {
|
|
40
|
+
const requestAttributes =
|
|
41
|
+
await TiledeskChatbot.allParametersStatic(this.tdcache, this.context.requestId);
|
|
42
|
+
const filler = new Filler();
|
|
43
|
+
tags = filler.fill(tags, requestAttributes);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch(error) {
|
|
47
|
+
console.error("Error while filling operands:", error);
|
|
48
|
+
}
|
|
49
|
+
this.moveToDepartment(this.requestId, depName, (deps) => {
|
|
50
|
+
if (!deps) {
|
|
51
|
+
if (this.log) {console.log("Dep not found");}
|
|
52
|
+
callback();
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
if (this.log) {console.log("Switched to dept:", depName, "action:", JSON.stringify(action));}
|
|
56
|
+
if (action.triggerBot) {
|
|
57
|
+
let dep = null;
|
|
58
|
+
let i;
|
|
59
|
+
for (i = 0; i < deps.length; i++) {
|
|
60
|
+
let d = deps[i];
|
|
61
|
+
if (d.name.toLowerCase() === depName.toLowerCase()) {
|
|
62
|
+
dep = d;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (dep && dep.hasBot === true && dep.id_bot) {
|
|
67
|
+
if (this.log) {console.log("Sending hidden /start message to bot in dept");}
|
|
68
|
+
const message = {
|
|
69
|
+
type: "text",
|
|
70
|
+
text: "/start",
|
|
71
|
+
attributes : {
|
|
72
|
+
subtype: "info"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
this.tdclient.sendSupportMessage(
|
|
76
|
+
this.requestId,
|
|
77
|
+
message, (err) => {
|
|
78
|
+
if (err) {
|
|
79
|
+
console.error("Error sending hidden message:", err.message);
|
|
80
|
+
}
|
|
81
|
+
if (this.log) {console.log("Hidden message sent.");}
|
|
82
|
+
callback();
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
if (this.log) {console.log("No action.triggerBot");}
|
|
88
|
+
callback();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
moveToDepartment(requestId, depName, callback) {
|
|
94
|
+
this.tdclient.getAllDepartments((err, deps) => {
|
|
95
|
+
if (this.log) {console.log("deps:", JSON.stringify(deps));}
|
|
96
|
+
if (err) {
|
|
97
|
+
console.error("getAllDepartments() error:", err);
|
|
98
|
+
callback();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
let dep = null;
|
|
102
|
+
let i;
|
|
103
|
+
for (i = 0; i < deps.length; i++) {
|
|
104
|
+
let d = deps[i];
|
|
105
|
+
if (d.name.toLowerCase() === depName.toLowerCase()) {
|
|
106
|
+
dep = d;
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (dep) {
|
|
111
|
+
this.tdclient.updateRequestDepartment(requestId, dep._id, null, (err, res) => {
|
|
112
|
+
if (err) {
|
|
113
|
+
console.error("DirDepartment error:", err);
|
|
114
|
+
callback();
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
console.log("DirDepartment response:",JSON.stringify(res));
|
|
118
|
+
callback(deps);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
module.exports = { DirSetConversationTags };
|