@tiledesk/tiledesk-tybot-connector 0.2.86 → 0.2.88
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 +8 -0
- package/models/TiledeskChatbotUtil.js +20 -5
- package/package.json +1 -1
- package/tiledeskChatbotPlugs/directives/DirAssistant.js +88 -3
- package/tiledeskChatbotPlugs/directives/DirContactUpdate.js +15 -2
- package/tiledeskChatbotPlugs/directives/DirRandomReply.js +6 -6
- package/tiledeskChatbotPlugs/directives/DirReply.js +6 -6
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,14 @@
|
|
|
5
5
|
available on:
|
|
6
6
|
▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
|
|
7
7
|
|
|
8
|
+
# v0.2.88
|
|
9
|
+
- Added DirContactUpdate (aka LeadUpdate). No test case added for LeadUpdate. Only testable with a validation test.
|
|
10
|
+
- 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.
|
|
11
|
+
|
|
12
|
+
# v0.2.87
|
|
13
|
+
- Fixed DirAssistant empty error {}
|
|
14
|
+
- Added to DirAssistant "lastMessageData" attribute (The message content original JSON structure useful to get annotations in messages, message type etc.)
|
|
15
|
+
|
|
8
16
|
# v0.2.86
|
|
9
17
|
- Added to ifOnlineAgents Action: ignoreProjectWideOperatingHours = action.ignoreOperatingHours;
|
|
10
18
|
- Updated ifOnlineAgents with get available agents with 'raw' option
|
|
@@ -436,6 +436,9 @@ class TiledeskChatbotUtil {
|
|
|
436
436
|
if (fullName.trim() === chatbot_name) {
|
|
437
437
|
fullName = "bot:" + fullName;
|
|
438
438
|
}
|
|
439
|
+
else {
|
|
440
|
+
fullName = "user:" + fullName;
|
|
441
|
+
}
|
|
439
442
|
return "<" + fullName + ">";
|
|
440
443
|
}
|
|
441
444
|
}
|
|
@@ -594,14 +597,26 @@ class TiledeskChatbotUtil {
|
|
|
594
597
|
// await chatbot.addParameter("lastUserDocumentType", null);
|
|
595
598
|
// }
|
|
596
599
|
if (message && message.request && message.request.lead) {
|
|
597
|
-
console.log("lead found. lead.email:", message.request.lead.email, "lead.fullname:", message.request.lead.fullname)
|
|
598
|
-
|
|
599
|
-
|
|
600
|
+
if (chatbot.log) {console.log("lead found. lead.email:", message.request.lead.email, "lead.fullname:", message.request.lead.fullname)}
|
|
601
|
+
let currentLeadEmail = await chatbot.getParameter(TiledeskChatbotConst.REQ_LEAD_EMAIL_KEY);
|
|
602
|
+
if (chatbot.log) {console.log("You lead email from attributes:", currentLeadEmail, "message.request.lead.email:", message.request.lead.email);}
|
|
603
|
+
if (message.request.lead.email && !currentLeadEmail) {
|
|
604
|
+
// worth saving
|
|
605
|
+
if (chatbot.log) {console.log("worth saving email. lead found. lead.email:", message.request.lead.email, "lead.fullname:", message.request.lead.fullname)}
|
|
606
|
+
try {
|
|
607
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_LEAD_EMAIL_KEY, message.request.lead.email);
|
|
608
|
+
}
|
|
609
|
+
catch(error) {
|
|
610
|
+
console.error("Error on setting userEmail:", error);
|
|
611
|
+
}
|
|
600
612
|
}
|
|
601
|
-
|
|
613
|
+
let currentLeadName = await chatbot.getParameter(TiledeskChatbotConst.REQ_LEAD_USERFULLNAME_KEY);
|
|
614
|
+
if (chatbot.log) {console.log("You lead name from attributes:", currentLeadName, "message.request.lead.fullname:", message.request.lead.fullname)}
|
|
615
|
+
// if (message.request.lead.fullname && message.request.lead.fullname.startsWith("guest#") && !currentLeadName) {
|
|
602
616
|
// if (message.request.lead.fullname) {
|
|
617
|
+
if (message.request.lead.fullname && !currentLeadName) {
|
|
603
618
|
// worth saving
|
|
604
|
-
console.log("worth saving. lead found. lead.email:", message.request.lead.email, "lead.fullname:", message.request.lead.fullname)
|
|
619
|
+
if (chatbot.log) {console.log("worth saving fullname. lead found. lead.email:", message.request.lead.email, "lead.fullname:", message.request.lead.fullname)}
|
|
605
620
|
try {
|
|
606
621
|
await chatbot.addParameter(TiledeskChatbotConst.REQ_LEAD_USERFULLNAME_KEY, message.request.lead.fullname);
|
|
607
622
|
}
|
package/package.json
CHANGED
|
@@ -170,6 +170,7 @@ class DirAssistant {
|
|
|
170
170
|
// process.exit(0);
|
|
171
171
|
if (lastMessage !== null) {
|
|
172
172
|
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, assignResultTo, lastMessage);
|
|
173
|
+
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, "lastMessageData", messages.data[0].content); // content is an array, see on this source end for messages structure example, including content. Ex get annotation[0]: content[0].text.annotations[0]
|
|
173
174
|
if (trueIntent) {
|
|
174
175
|
await this.#executeCondition(true, trueIntent, null, falseIntent, null);
|
|
175
176
|
callback(true);
|
|
@@ -624,11 +625,11 @@ class DirAssistant {
|
|
|
624
625
|
data = err.response.data;
|
|
625
626
|
}
|
|
626
627
|
callback(
|
|
627
|
-
|
|
628
|
+
{
|
|
628
629
|
status: status,
|
|
629
630
|
data: data,
|
|
630
631
|
error: errorMessage
|
|
631
|
-
}
|
|
632
|
+
}, data
|
|
632
633
|
);
|
|
633
634
|
}
|
|
634
635
|
});
|
|
@@ -642,4 +643,88 @@ class DirAssistant {
|
|
|
642
643
|
|
|
643
644
|
|
|
644
645
|
|
|
645
|
-
module.exports = { DirAssistant };
|
|
646
|
+
module.exports = { DirAssistant };
|
|
647
|
+
|
|
648
|
+
// Messages list response example
|
|
649
|
+
|
|
650
|
+
/*
|
|
651
|
+
{
|
|
652
|
+
"object": "list",
|
|
653
|
+
"data": [
|
|
654
|
+
{
|
|
655
|
+
"id": "msg_FfKaNU82uBYQU9gANFkKJ5Wi",
|
|
656
|
+
"object": "thread.message",
|
|
657
|
+
"created_at": 1721681044,
|
|
658
|
+
"assistant_id": null,
|
|
659
|
+
"thread_id": "thread_fN0rAdyJlPmN9uteMP0yWsCl",
|
|
660
|
+
"run_id": null,
|
|
661
|
+
"role": "user",
|
|
662
|
+
"content": [
|
|
663
|
+
{
|
|
664
|
+
"type": "text",
|
|
665
|
+
"text": {
|
|
666
|
+
"value": "vendete sedie di altezza superiore o uguale a 50 cm?",
|
|
667
|
+
"annotations": []
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
],
|
|
671
|
+
"file_ids": [],
|
|
672
|
+
"metadata": {}
|
|
673
|
+
},
|
|
674
|
+
{
|
|
675
|
+
"id": "msg_Ddxnqi7M9vvLdS9YYO4FHjVt",
|
|
676
|
+
"object": "thread.message",
|
|
677
|
+
"created_at": 1721680934,
|
|
678
|
+
"assistant_id": "asst_qNjiwCVxo3kL2mnN1QyP50Zb",
|
|
679
|
+
"thread_id": "thread_fN0rAdyJlPmN9uteMP0yWsCl",
|
|
680
|
+
"run_id": "run_k8mPIrZPnsO0hAiezD9y2f1t",
|
|
681
|
+
"role": "assistant",
|
|
682
|
+
"content": [
|
|
683
|
+
{
|
|
684
|
+
"type": "text",
|
|
685
|
+
"text": {
|
|
686
|
+
"value": "Una delle best practices raccomandate per garantire un alto livello di sicurezza informatica per la linea di prodotti \"boss\" è la seguente:\n\n- Aggiornare i dispositivi con l'ultima versione del firmware disponibile. È possibile consultare il portale KSA per verificare la disponibilità degli aggiornamenti【6:0†source】.\n\nSe hai altri dubbi o necessiti di ulteriori informazioni, non esitare a chiedere!",
|
|
687
|
+
"annotations": [
|
|
688
|
+
{
|
|
689
|
+
"type": "file_citation",
|
|
690
|
+
"text": "【6:0†source】",
|
|
691
|
+
"start_index": 305,
|
|
692
|
+
"end_index": 317,
|
|
693
|
+
"file_citation": {
|
|
694
|
+
"file_id": "file-dwR6qSwVUIrhImd9espzExGw",
|
|
695
|
+
"quote": ""
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
]
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
],
|
|
702
|
+
"file_ids": [],
|
|
703
|
+
"metadata": {}
|
|
704
|
+
},
|
|
705
|
+
{
|
|
706
|
+
"id": "msg_ng244T4mymroFWZ912r9DvWZ",
|
|
707
|
+
"object": "thread.message",
|
|
708
|
+
"created_at": 1721680931,
|
|
709
|
+
"assistant_id": null,
|
|
710
|
+
"thread_id": "thread_fN0rAdyJlPmN9uteMP0yWsCl",
|
|
711
|
+
"run_id": null,
|
|
712
|
+
"role": "user",
|
|
713
|
+
"content": [
|
|
714
|
+
{
|
|
715
|
+
"type": "text",
|
|
716
|
+
"text": {
|
|
717
|
+
"value": "dimmi una delle best practices che conosci",
|
|
718
|
+
"annotations": []
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
],
|
|
722
|
+
"file_ids": [],
|
|
723
|
+
"metadata": {}
|
|
724
|
+
}
|
|
725
|
+
],
|
|
726
|
+
"first_id": "msg_FfKaNU82uBYQU9gANFkKJ5Wi",
|
|
727
|
+
"last_id": "msg_ng244T4mymroFWZ912r9DvWZ",
|
|
728
|
+
"has_more": false
|
|
729
|
+
}
|
|
730
|
+
*/
|
|
@@ -54,8 +54,21 @@ class DirContactUpdate {
|
|
|
54
54
|
const filler = new Filler();
|
|
55
55
|
let updateProperties = {}
|
|
56
56
|
for (const [key, value] of Object.entries(contactProperties)) {
|
|
57
|
-
|
|
58
|
-
if (this.log) {console.log("(DirContactUpdate)
|
|
57
|
+
let filled_value = filler.fill(value, requestAttributes);
|
|
58
|
+
if (this.log) {console.log("(DirContactUpdate) setting property key:",key, "with value:", value, "filled value:", filled_value); }
|
|
59
|
+
updateProperties[key] = filled_value;
|
|
60
|
+
if (key === "fullname") {
|
|
61
|
+
await this.context.chatbot.addParameter(TiledeskChatbotConst.REQ_LEAD_USERFULLNAME_KEY, filled_value);
|
|
62
|
+
if (this.log) {console.log("(DirContactUpdate) updating attribute:",TiledeskChatbotConst.REQ_LEAD_USERFULLNAME_KEY, "with property key:", key, "and value:", filled_value); }
|
|
63
|
+
}
|
|
64
|
+
else if ( key === "email") {
|
|
65
|
+
await this.context.chatbot.addParameter(TiledeskChatbotConst.REQ_LEAD_EMAIL_KEY, filled_value);
|
|
66
|
+
if (this.log) {console.log("(DirContactUpdate) updating attribute:",TiledeskChatbotConst.REQ_LEAD_EMAIL_KEY, "with property key:", key, "and value:", filled_value); }
|
|
67
|
+
}
|
|
68
|
+
// else if (key === "phone") {
|
|
69
|
+
// static REQ_USER_PHONE_KEY = "userPhone";
|
|
70
|
+
// }
|
|
71
|
+
if (this.log) {console.log("(DirContactUpdate) updating property:", key, "value:", filled_value); }
|
|
59
72
|
}
|
|
60
73
|
const leadId = requestAttributes[TiledeskChatbotConst.REQ_USER_LEAD_ID_KEY];
|
|
61
74
|
this.tdclient.updateLead(leadId, updateProperties, null, null, () => {
|
|
@@ -78,12 +78,12 @@ class DirRandomReply {
|
|
|
78
78
|
message.attributes = {}
|
|
79
79
|
}
|
|
80
80
|
// Reserved names: userEmail, userFullname
|
|
81
|
-
if (requestVariables['userEmail']) {
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
if (requestVariables['userFullname']) {
|
|
85
|
-
|
|
86
|
-
}
|
|
81
|
+
// if (requestVariables['userEmail']) {
|
|
82
|
+
// message.attributes.updateUserEmail = requestVariables['userEmail'];
|
|
83
|
+
// }
|
|
84
|
+
// if (requestVariables['userFullname']) {
|
|
85
|
+
// message.attributes.updateUserFullname = requestVariables['userFullname'];
|
|
86
|
+
// }
|
|
87
87
|
}
|
|
88
88
|
// send!
|
|
89
89
|
if (this.log) {console.log("Reply:", JSON.stringify(message))};
|
|
@@ -94,12 +94,12 @@ class DirReply {
|
|
|
94
94
|
message.attributes = {}
|
|
95
95
|
}
|
|
96
96
|
// Reserved names: userEmail, userFullname
|
|
97
|
-
if (requestAttributes['userEmail']) {
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
if (requestAttributes['userFullname']) {
|
|
101
|
-
|
|
102
|
-
}
|
|
97
|
+
// if (requestAttributes['userEmail']) {
|
|
98
|
+
// message.attributes.updateUserEmail = requestAttributes['userEmail'];
|
|
99
|
+
// }
|
|
100
|
+
// if (requestAttributes['userFullname']) {
|
|
101
|
+
// message.attributes.updateUserFullname = requestAttributes['userFullname'];
|
|
102
|
+
// }
|
|
103
103
|
// intent_info
|
|
104
104
|
if (this.context.reply && this.context.reply.attributes && this.context.reply.attributes.intent_info) {
|
|
105
105
|
message.attributes.intentName = this.context.reply.attributes.intent_info.intent_name;
|
|
@@ -234,12 +234,12 @@ class DirReplyV2 {
|
|
|
234
234
|
message.attributes = {}
|
|
235
235
|
}
|
|
236
236
|
// Reserved names: userEmail, userFullname
|
|
237
|
-
if (requestAttributes['userEmail']) {
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
if (requestAttributes['userFullname']) {
|
|
241
|
-
|
|
242
|
-
}
|
|
237
|
+
// if (requestAttributes['userEmail']) {
|
|
238
|
+
// message.attributes.updateUserEmail = requestAttributes['userEmail'];
|
|
239
|
+
// }
|
|
240
|
+
// if (requestAttributes['userFullname']) {
|
|
241
|
+
// message.attributes.updateUserFullname = requestAttributes['userFullname'];
|
|
242
|
+
// }
|
|
243
243
|
// intent_info
|
|
244
244
|
if (this.context.reply && this.context.reply.attributes && this.context.reply.attributes.intent_info) {
|
|
245
245
|
message.attributes.intentName = this.context.reply.attributes.intent_info.intent_name;
|