@tiledesk/tiledesk-tybot-connector 2.0.36-rc12 → 2.0.37
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 +3 -0
- package/engine/TiledeskChatbot.js +21 -67
- package/engine/TiledeskChatbotConst.js +0 -2
- package/index.js +0 -26
- package/logs/app.log +13651 -12759
- package/logs/app1.log +13327 -13395
- package/logs/app2.log +7679 -10185
- package/logs/app8.log +4066 -0
- package/logs/app9.log +5452 -0
- package/package.json +4 -3
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +1 -22
- package/tiledeskChatbotPlugs/directives/DEPRECATED_DirOfflineHours.js +4 -3
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +12 -11
- package/tiledeskChatbotPlugs/directives/DirAssign.js +7 -5
- package/tiledeskChatbotPlugs/directives/DirAssignFromFunction.js +0 -26
- package/tiledeskChatbotPlugs/directives/DirCondition.js +0 -35
- package/tiledeskChatbotPlugs/directives/DirConnectBlock.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirDeflectToHelpCenter.js +0 -34
- package/tiledeskChatbotPlugs/directives/DirDeleteVariable.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirDisableInputText.js +0 -22
- package/tiledeskChatbotPlugs/directives/DirFireTiledeskEvent.js +4 -2
- package/tiledeskChatbotPlugs/directives/DirIfOnlineAgents.js +0 -24
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours.js +0 -30
- package/tiledeskChatbotPlugs/directives/DirIfOpenHours_OLD.js +0 -29
- package/tiledeskChatbotPlugs/directives/DirIntent.js +0 -1
- package/tiledeskChatbotPlugs/directives/DirLockIntent.js +1 -25
- package/tiledeskChatbotPlugs/directives/DirSendEmail.js +1 -32
- package/tiledeskChatbotPlugs/directives/DirWait.js +0 -8
- package/utils/TiledeskChatbotUtil.js +163 -139
- package/logs/app3.log +0 -161
- package/logs/app4.log +0 -46163
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const { param } = require('express/lib/request');
|
|
2
|
-
const ms = require('minimist-string');
|
|
3
2
|
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
4
3
|
const { Filler } = require('../Filler');
|
|
5
4
|
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
@@ -27,16 +26,7 @@ class DirSendEmail {
|
|
|
27
26
|
let action;
|
|
28
27
|
if (directive.action) {
|
|
29
28
|
action = directive.action;
|
|
30
|
-
}
|
|
31
|
-
else if (directive.parameter && directive.parameter.trim() !== "") {
|
|
32
|
-
const params = this.parseParams(directive.parameter);
|
|
33
|
-
action = {
|
|
34
|
-
subject: params.subject,
|
|
35
|
-
text: params.text,
|
|
36
|
-
to: params.to
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
29
|
+
} else {
|
|
40
30
|
this.logger.error("Incorrect action for ", directive.name, directive)
|
|
41
31
|
winston.warn("DirSendEmail Incorrect directive: ", directive);
|
|
42
32
|
callback();
|
|
@@ -94,27 +84,6 @@ class DirSendEmail {
|
|
|
94
84
|
}
|
|
95
85
|
}
|
|
96
86
|
}
|
|
97
|
-
|
|
98
|
-
parseParams(directive_parameter) {
|
|
99
|
-
let subject = null;
|
|
100
|
-
let text = null;
|
|
101
|
-
let to = null
|
|
102
|
-
const params = ms(directive_parameter);
|
|
103
|
-
if (params.subject) {
|
|
104
|
-
subject = params.subject
|
|
105
|
-
}
|
|
106
|
-
if (params.text) {
|
|
107
|
-
text = params.text.replace(/\\n/g, "\n");
|
|
108
|
-
}
|
|
109
|
-
if (params.to) {
|
|
110
|
-
to = params.to;
|
|
111
|
-
}
|
|
112
|
-
return {
|
|
113
|
-
subject: subject,
|
|
114
|
-
to: to,
|
|
115
|
-
text: text
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
87
|
}
|
|
119
88
|
|
|
120
89
|
module.exports = { DirSendEmail };
|
|
@@ -18,7 +18,6 @@ class DirWait {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
execute(directive, callback) {
|
|
21
|
-
console.log(`(GAB) called DirWait execute at : ${new Date().getTime()}, directive:`, directive)
|
|
22
21
|
// 500ms < wait-time < 10.000ms
|
|
23
22
|
winston.verbose("Execute Wait directive");
|
|
24
23
|
let action;
|
|
@@ -48,7 +47,6 @@ class DirWait {
|
|
|
48
47
|
}
|
|
49
48
|
|
|
50
49
|
this.go(action, () => {
|
|
51
|
-
console.log(`(DirWait) go callback exit at: ${new Date().getTime()} . . .` )
|
|
52
50
|
this.logger.native("[Wait] Executed");
|
|
53
51
|
callback();
|
|
54
52
|
})
|
|
@@ -60,16 +58,10 @@ class DirWait {
|
|
|
60
58
|
// const step_key = TiledeskChatbot.requestCacheKey(this.requestId) + ":step";
|
|
61
59
|
if (action && action.millis >= 1000) {//2000 * 60) { // at list 2 minutes waiting time to reset the steps counter
|
|
62
60
|
// await this.tdcache.set(step_key, 0);
|
|
63
|
-
let start1= new Date()
|
|
64
61
|
await TiledeskChatbot.resetStep(this.tdcache, this.requestId);
|
|
65
|
-
let end1 = new Date()
|
|
66
|
-
console.log(`(GAB) called DirWait go() 1-> after TiledeskChatbot.resetStep at : ${end1.getTime()}, diff: ${end1-start1}[ms]`)
|
|
67
|
-
|
|
68
62
|
}
|
|
69
|
-
console.log(`(GAB) called DirWait go() at :${new Date().getTime()}, millis: ${action.millis}`)
|
|
70
63
|
this.logger.native("[Wait] Waiting for ", action.millis, "[ms]")
|
|
71
64
|
setTimeout(() => {
|
|
72
|
-
console.log(`(GAB) called DirWait go() settimeout at : ${new Date().getTime()}`)
|
|
73
65
|
callback();
|
|
74
66
|
}, action.millis);
|
|
75
67
|
}
|
|
@@ -680,172 +680,189 @@ class TiledeskChatbotUtil {
|
|
|
680
680
|
// update request context
|
|
681
681
|
try {
|
|
682
682
|
winston.debug("Updating request variables. Message:", message);
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
const addQueue = [];
|
|
686
|
-
const deleteQueue = [];
|
|
687
|
-
const add = (k, v) => { if (v !== undefined && v !== null && k !== undefined && k !== null) addQueue.push([k, v]); };
|
|
688
|
-
const remove = (k) => { if(k) deleteQueue.push(k);}
|
|
683
|
+
const messageId = message._id;
|
|
689
684
|
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
add(TiledeskChatbotConst.REQ_CHAT_URL, `${process.env.BASE_URL}/dashboard/#/project/${projectId}/wsrequest/${requestId}/messages`);
|
|
685
|
+
if(process.env.BASE_URL){
|
|
686
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_CHAT_URL, `${process.env.BASE_URL}/dashboard/#/project/${projectId}/wsrequest/${requestId}/messages`);
|
|
693
687
|
}
|
|
694
688
|
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
// --- CHATBOT INFO ---
|
|
689
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_PROJECT_ID_KEY, projectId);
|
|
690
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_REQUEST_ID_KEY, requestId);
|
|
691
|
+
|
|
699
692
|
if (chatbot.bot) {
|
|
700
|
-
|
|
701
|
-
|
|
693
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_NAME_KEY, chatbot.bot.name);
|
|
694
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_ID_KEY, chatbot.bot._id);
|
|
702
695
|
}
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
add(TiledeskChatbotConst.REQ_CHATBOT_TOKEN_v2, "JWT " + chatbotToken);
|
|
696
|
+
|
|
697
|
+
if (chatbotToken) {
|
|
698
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN, chatbotToken); // DEPRECATED
|
|
699
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN_v2, "JWT " + chatbotToken);
|
|
708
700
|
}
|
|
709
|
-
|
|
701
|
+
|
|
702
|
+
if (process.env.TILEDESK_API) {
|
|
703
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN, chatbotToken); // DEPRECATED
|
|
704
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_CHATBOT_TOKEN_v2, "JWT " + chatbotToken);
|
|
705
|
+
}
|
|
706
|
+
|
|
710
707
|
if (process.env.API_URL) {
|
|
711
|
-
|
|
708
|
+
await chatbot.addParameter(TiledeskChatbotConst.API_BASE_URL, process.env.API_URL);
|
|
712
709
|
}
|
|
713
710
|
|
|
714
|
-
// --- USER MESSAGE ---
|
|
715
711
|
if (message.text && message.sender !== "_tdinternal") {
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
add(TiledeskChatbotConst.REQ_LAST_USER_TEXT_v2_KEY, message.text);
|
|
720
|
-
|
|
721
|
-
add(TiledeskChatbotConst.REQ_LAST_USER_MESSAGE_TYPE_KEY, message.type);
|
|
722
|
-
add(TiledeskChatbotConst.REQ_LAST_USER_MESSAGE_KEY,
|
|
723
|
-
TiledeskChatbotUtil.lastUserMessageFrom(message));
|
|
724
|
-
|
|
712
|
+
await chatbot.deleteParameter(TiledeskChatbotConst.USER_INPUT); // user wrote, delete userInput, replyv2 will not trigger timeout action
|
|
713
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_TEXT_KEY, message.text); // DEPRECATED
|
|
714
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_TEXT_v2_KEY, message.text);
|
|
725
715
|
if (message.channel) {
|
|
726
|
-
|
|
727
|
-
|
|
716
|
+
if (message.channel.name === "chat21") {
|
|
717
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_CHAT_CHANNEL, "web"); // renames the channel in chat21
|
|
718
|
+
}
|
|
719
|
+
else {
|
|
720
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_CHAT_CHANNEL, message.channel.name);
|
|
721
|
+
}
|
|
728
722
|
}
|
|
723
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_MESSAGE_TYPE_KEY, message.type);
|
|
724
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_MESSAGE_KEY, TiledeskChatbotUtil.lastUserMessageFrom(message)); // JSON TYPE *NEW
|
|
729
725
|
}
|
|
730
726
|
|
|
731
|
-
//
|
|
732
|
-
if (message.type && message.type === "image" && message.metadata
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
727
|
+
// get image
|
|
728
|
+
if (message.type && message.type === "image" && message.metadata) {
|
|
729
|
+
if (message.metadata.src) {
|
|
730
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_IMAGE_URL, message.metadata.src);
|
|
731
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_IMAGE_NAME, message.metadata.name);
|
|
732
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_IMAGE_WIDTH, message.metadata.width);
|
|
733
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_IMAGE_HEIGHT, message.metadata.height);
|
|
734
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_IMAGE_TYPE, message.metadata.type);
|
|
735
|
+
}
|
|
738
736
|
}
|
|
739
737
|
|
|
740
|
-
//
|
|
741
|
-
if (message.type && message.type === "file" && message.metadata
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
add(TiledeskChatbotConst.REQ_LAST_USER_DOCUMENT_TYPE, m.type);
|
|
738
|
+
// get document
|
|
739
|
+
if (message.type && message.type === "file" && message.metadata) {
|
|
740
|
+
if (message.metadata.src) {
|
|
741
|
+
await chatbot.addParameter("lastUserDocumentURL", message.metadata.src); // legacy. will be deprecated
|
|
742
|
+
const url_as_attachment = message.metadata.src;
|
|
743
|
+
await chatbot.addParameter("lastUserDocumentAsAttachmentURL", url_as_attachment);
|
|
744
|
+
let url_inline = url_as_attachment;
|
|
745
|
+
if (url_as_attachment.match(/.*\/download.*/)) { // removing "/download" removes the "Content-disposion: attachment" HTTP header
|
|
746
|
+
url_inline = url_as_attachment.replace('/download', '/');
|
|
747
|
+
}
|
|
748
|
+
await chatbot.addParameter("lastUserDocumentAsInlineURL", url_inline);
|
|
749
|
+
await chatbot.addParameter("lastUserDocumentName", message.metadata.name);
|
|
750
|
+
await chatbot.addParameter("lastUserDocumentType", message.metadata.type);
|
|
754
751
|
}
|
|
755
752
|
}
|
|
756
753
|
|
|
757
|
-
// --- LEAD ---
|
|
758
754
|
if (message && message.request && message.request.lead) {
|
|
759
755
|
winston.debug("(TiledeskChatbotUtil) Lead found with email: " + message.request.lead.email + " and lead.fullname " + message.request.lead.fullname);
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
756
|
+
let currentLeadEmail = await chatbot.getParameter(TiledeskChatbotConst.REQ_LEAD_EMAIL_KEY);
|
|
757
|
+
winston.debug("(TiledeskChatbotUtil) You lead email from attributes: " + currentLeadEmail);
|
|
758
|
+
if (message.request.lead.email && !currentLeadEmail) {
|
|
759
|
+
// worth saving
|
|
760
|
+
winston.debug("(TiledeskChatbotUtil) worth saving email");
|
|
761
|
+
try {
|
|
762
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_LEAD_EMAIL_KEY, message.request.lead.email);
|
|
763
|
+
}
|
|
764
|
+
catch(error) {
|
|
765
|
+
winston.error("(TiledeskChatbotUtil) Error on setting userEmail:", error);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
let currentLeadName = await chatbot.getParameter(TiledeskChatbotConst.REQ_LEAD_USERFULLNAME_KEY);
|
|
769
|
+
winston.debug("(TiledeskChatbotUtil) You lead email from attributes: " + currentLeadEmail);
|
|
770
|
+
if (message.request.lead.fullname && !currentLeadName) {
|
|
771
|
+
// worth saving
|
|
772
|
+
winston.debug("(TiledeskChatbotUtil) worth saving email");
|
|
773
|
+
try {
|
|
774
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_LEAD_USERFULLNAME_KEY, message.request.lead.fullname);
|
|
775
|
+
}
|
|
776
|
+
catch(error) {
|
|
777
|
+
winston.error("(TiledeskChatbotUtil) Error on setting userFullname: ", error);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
767
780
|
|
|
768
781
|
if (message.request.lead.phone) {
|
|
769
|
-
|
|
782
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_USER_PHONE_KEY, message.request.lead.phone);
|
|
770
783
|
}
|
|
771
|
-
if (lead.lead_id)
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
784
|
+
if (message.request.lead.lead_id && (message.request.lead.lead_id.startsWith("wab-") ||
|
|
785
|
+
message.request.lead.lead_id.startsWith("vxml-") ||
|
|
786
|
+
message.request.lead.lead_id.startsWith(CHANNEL_NAME.VOICE_TWILIO) ||
|
|
787
|
+
message.request.lead.lead_id.startsWith(CHANNEL_NAME.SMS))) {
|
|
788
|
+
const splits = message.request.lead.lead_id.split("-");
|
|
789
|
+
if (splits && splits.length > 1) {
|
|
790
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_CURRENT_PHONE_NUMBER_KEY,splits[1]);
|
|
776
791
|
}
|
|
777
792
|
}
|
|
778
793
|
if (message.request.lead._id) {
|
|
779
|
-
|
|
794
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_USER_LEAD_ID_KEY, message.request.lead._id);
|
|
780
795
|
}
|
|
781
796
|
if (message.request.lead.company) {
|
|
782
|
-
|
|
797
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_USER_COMPANY_KEY, message.request.lead.company);
|
|
783
798
|
}
|
|
784
799
|
if (message.request.ticket_id) {
|
|
785
|
-
|
|
800
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_TICKET_ID_KEY, message.request.ticket_id);
|
|
786
801
|
}
|
|
787
802
|
}
|
|
788
803
|
|
|
789
|
-
|
|
790
|
-
const messageId = message._id;
|
|
791
|
-
add(TiledeskChatbotConst.REQ_LAST_MESSAGE_ID_KEY, messageId);
|
|
792
|
-
|
|
793
|
-
// --- LOCATION ---
|
|
804
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_MESSAGE_ID_KEY, messageId);
|
|
794
805
|
if (message.request && message.request.location && message.request.location.country) {
|
|
795
|
-
|
|
806
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_COUNTRY_KEY, message.request.location.country);
|
|
796
807
|
}
|
|
797
808
|
if (message.request && message.request.location && message.request.location.city) {
|
|
798
|
-
|
|
809
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_CITY_KEY, message.request.location.city);
|
|
799
810
|
}
|
|
800
|
-
|
|
801
|
-
// --- USER CONTEXT ---
|
|
802
811
|
if (message.request) {
|
|
803
|
-
let
|
|
804
|
-
if (
|
|
805
|
-
|
|
806
|
-
if (
|
|
812
|
+
let user_language = message.request["language"];
|
|
813
|
+
if (message.request["language"]) {
|
|
814
|
+
var languages = parser.parse(message.request["language"]);
|
|
815
|
+
if (languages && languages.length > 0 && languages[0].code) {
|
|
816
|
+
user_language = languages[0].code;
|
|
817
|
+
}
|
|
807
818
|
}
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
add(TiledeskChatbotConst.REQ_USER_AGENT_KEY, message.request.userAgent);
|
|
812
|
-
|
|
819
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_USER_SOURCE_PAGE_KEY, message.request.sourcePage);
|
|
820
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_USER_LANGUAGE_KEY, user_language);
|
|
821
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_USER_AGENT_KEY, message.request.userAgent);
|
|
813
822
|
if (message.request.attributes && message.request.attributes.decoded_jwt) {
|
|
814
|
-
|
|
823
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_DECODED_JWT_KEY, message.request.attributes.decoded_jwt);
|
|
824
|
+
}
|
|
825
|
+
if (message.request.requester) {
|
|
826
|
+
if (message.request.requester.isAuthenticated === true) {
|
|
827
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_REQUESTER_IS_AUTHENTICATED_KEY, true);
|
|
828
|
+
}
|
|
829
|
+
else {
|
|
830
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_REQUESTER_IS_AUTHENTICATED_KEY, false);
|
|
831
|
+
}
|
|
815
832
|
}
|
|
816
|
-
|
|
817
|
-
const auth = !!message.request.requester?.isAuthenticated;
|
|
818
|
-
add(TiledeskChatbotConst.REQ_REQUESTER_IS_AUTHENTICATED_KEY, auth);
|
|
819
833
|
}
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
834
|
+
if (message.request && message.request.department) {
|
|
835
|
+
// It was an error when getting this from widget message's attributes
|
|
836
|
+
// await chatbot.addParameter(TiledeskChatbotConst.REQ_DEPARTMENT_ID_KEY, message.attributes.departmentId);
|
|
837
|
+
// await chatbot.addParameter(TiledeskChatbotConst.REQ_DEPARTMENT_NAME_KEY, message.attributes.departmentName);
|
|
838
|
+
// get from request.department instead
|
|
839
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_DEPARTMENT_ID_KEY, message.request.department._id);
|
|
840
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_DEPARTMENT_NAME_KEY, message.request.department.name);
|
|
841
|
+
}
|
|
842
|
+
else if (message.attributes && message.attributes.departmentId) {
|
|
843
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_DEPARTMENT_ID_KEY, message.attributes.departmentId);
|
|
844
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_DEPARTMENT_NAME_KEY, message.attributes.departmentName);
|
|
826
845
|
}
|
|
827
846
|
|
|
828
|
-
// --- EMAIL ATTRIBUTES ---
|
|
829
847
|
if (message.attributes) {
|
|
830
|
-
const
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
848
|
+
const attrFields = [
|
|
849
|
+
{ key: TiledeskChatbotConst.REQ_EMAIL_SUBJECT, attr: "email_subject" },
|
|
850
|
+
{ key: TiledeskChatbotConst.REQ_EMAIL_TO, attr: "email_toEmail" },
|
|
851
|
+
{ key: TiledeskChatbotConst.REQ_EMAIL_FROM, attr: "email_fromEmail" },
|
|
852
|
+
{ key: TiledeskChatbotConst.REQ_EMAIL_MESSAGE_ID, attr: "email_messageId" },
|
|
853
|
+
{ key: TiledeskChatbotConst.REQ_EMAIL_REPLY_TO, attr: "email_replyTo" },
|
|
854
|
+
{ key: TiledeskChatbotConst.REQ_EMAIL_EML, attr: "email_eml" },
|
|
855
|
+
{ key: TiledeskChatbotConst.REQ_EMAIL_ATTACHMENTS_LINK, attr: "link" },
|
|
856
|
+
{ key: TiledeskChatbotConst.REQ_EMAIL_ATTACHMENTS_FILES, attr: "attachments" },
|
|
857
|
+
// aggiungi qui altri campi se necessario
|
|
839
858
|
];
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
add(key, message.attributes[attr]);
|
|
859
|
+
for (const field of attrFields) {
|
|
860
|
+
if (message.attributes[field.attr] !== undefined && message.attributes[field.attr] !== null) {
|
|
861
|
+
await chatbot.addParameter(field.key, message.attributes[field.attr]);
|
|
844
862
|
}
|
|
845
863
|
}
|
|
846
864
|
}
|
|
847
865
|
|
|
848
|
-
// --- PAYLOAD ---
|
|
849
866
|
if (message && message.request && message.request.attributes && message.request.attributes.payload) {
|
|
850
867
|
if (!message.attributes) {
|
|
851
868
|
message.attributes = {}
|
|
@@ -856,15 +873,15 @@ class TiledeskChatbotUtil {
|
|
|
856
873
|
if (message.attributes) {
|
|
857
874
|
winston.debug("(TiledeskChatbotUtil) Ok message.attributes ", message.attributes);
|
|
858
875
|
|
|
859
|
-
|
|
860
|
-
|
|
876
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_END_USER_ID_KEY, message.attributes.requester_id);
|
|
877
|
+
await chatbot.addParameter(TiledeskChatbotConst.REQ_END_USER_IP_ADDRESS_KEY, message.attributes.ipAddress);
|
|
861
878
|
if (message.attributes.payload) {
|
|
862
879
|
try {
|
|
863
880
|
for (const [key, value] of Object.entries(message.attributes.payload)) {
|
|
864
881
|
const value_type = typeof value;
|
|
865
|
-
|
|
882
|
+
await chatbot.addParameter(key, value);
|
|
866
883
|
}
|
|
867
|
-
|
|
884
|
+
await chatbot.addParameter("payload", message.attributes.payload);
|
|
868
885
|
}
|
|
869
886
|
catch(err) {
|
|
870
887
|
winston.error("(TiledeskChatbotUtil) Error importing message payload in request variables: ", err);
|
|
@@ -874,19 +891,19 @@ class TiledeskChatbotUtil {
|
|
|
874
891
|
// TODO - REMOVE - THEY ARE IN ATTRIBUTES.PAYLOAD
|
|
875
892
|
// voice-vxml attributes
|
|
876
893
|
if (message.attributes.dnis) {
|
|
877
|
-
|
|
894
|
+
await chatbot.addParameter("dnis", message.attributes.dnis);
|
|
878
895
|
}
|
|
879
896
|
if (message.attributes.callId) {
|
|
880
|
-
|
|
897
|
+
await chatbot.addParameter("callId", message.attributes.callId);
|
|
881
898
|
}
|
|
882
899
|
if (message.attributes.ani) {
|
|
883
|
-
|
|
900
|
+
await chatbot.addParameter("ani", message.attributes.ani);
|
|
884
901
|
}
|
|
885
902
|
}
|
|
886
903
|
|
|
887
904
|
|
|
888
905
|
|
|
889
|
-
|
|
906
|
+
|
|
890
907
|
const _bot = chatbot.bot; // aka FaqKB
|
|
891
908
|
winston.debug("(TiledeskChatbotUtil) Adding Globals to context: ", _bot);
|
|
892
909
|
|
|
@@ -894,7 +911,7 @@ class TiledeskChatbotUtil {
|
|
|
894
911
|
winston.debug("(TiledeskChatbotUtil) Got Globals: ", _bot.attributes.globals);
|
|
895
912
|
_bot.attributes.globals.forEach(async (global_var) => {
|
|
896
913
|
winston.error("(TiledeskChatbotUtil) Adding global: " + global_var.key + " value: " + global_var.value);
|
|
897
|
-
|
|
914
|
+
await chatbot.addParameter(global_var.key, global_var.value);
|
|
898
915
|
});
|
|
899
916
|
}
|
|
900
917
|
// await chatbot.addParameter("testVar",
|
|
@@ -905,13 +922,6 @@ class TiledeskChatbotUtil {
|
|
|
905
922
|
// }
|
|
906
923
|
// }
|
|
907
924
|
// );
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
// --- FINAL BATCH EXECUTION ---
|
|
911
|
-
await Promise.all([
|
|
912
|
-
...addQueue.map(([key, value]) => chatbot.addParameter(key, value)),
|
|
913
|
-
...deleteQueue.map(key => chatbot.deleteParameter(key))
|
|
914
|
-
]);
|
|
915
925
|
|
|
916
926
|
} catch(error) {
|
|
917
927
|
winston.error("(TiledeskChatbotUtil) updateRequestAttributes Error: ", error);
|
|
@@ -941,14 +951,28 @@ class TiledeskChatbotUtil {
|
|
|
941
951
|
}
|
|
942
952
|
|
|
943
953
|
static validateRequestId(requestId, projectId) {
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
954
|
+
let isValid = false;
|
|
955
|
+
if (requestId.startsWith("support-group-")) {
|
|
956
|
+
const parts = requestId.split("-");
|
|
957
|
+
if (parts.length >= 4) {
|
|
958
|
+
isValid = (parts[0] === "support" && parts[1] === "group" && parts[2] === projectId && parts[3].length > 0);
|
|
959
|
+
}
|
|
960
|
+
else {
|
|
961
|
+
isValid = false;
|
|
962
|
+
}
|
|
963
|
+
} else if (requestId.startsWith("automation-request-")) {
|
|
964
|
+
const parts = requestId.split("-");
|
|
965
|
+
if (parts.length === 4 || parts.length === 5) {
|
|
966
|
+
isValid = (parts[0] === "automation" && parts[1] === "request" && parts[2] === projectId && parts[3].length > 0);
|
|
967
|
+
}
|
|
968
|
+
else {
|
|
969
|
+
isValid = false;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
else {
|
|
973
|
+
isValid = false;
|
|
974
|
+
}
|
|
975
|
+
return isValid;
|
|
952
976
|
}
|
|
953
977
|
|
|
954
978
|
static userFlowAttributes(flowAttributes) {
|