@tiledesk/tiledesk-tybot-connector 0.2.31 → 0.2.33
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
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
available on:
|
|
6
6
|
▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
|
|
7
7
|
|
|
8
|
+
# v0.2.33
|
|
9
|
+
- Added lead attributes (userEmail, userPhone, userFullname, userLeadId, userCompany)
|
|
10
|
+
|
|
11
|
+
# v0.2.32
|
|
12
|
+
- Added attributes filling to message.metadata.src
|
|
13
|
+
- Added attributes filling to message.metadata.name
|
|
14
|
+
|
|
8
15
|
# v0.2.31
|
|
9
16
|
- Removed patch: Added support for removing empty text from replies: TiledeskChatbotUtil.removeEmptyReplyCommands()
|
|
10
17
|
|
|
@@ -448,6 +448,23 @@ class TiledeskChatbotUtil {
|
|
|
448
448
|
await chatbot.addParameter("lastUserDocumentName", null);
|
|
449
449
|
await chatbot.addParameter("lastUserDocumentType", null);
|
|
450
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
|
+
await chatbot.addParameter("userFullname", message.request.lead.fullname);
|
|
457
|
+
}
|
|
458
|
+
if (message.request.lead.phone) {
|
|
459
|
+
await chatbot.addParameter("userPhone", message.request.lead.phone);
|
|
460
|
+
}
|
|
461
|
+
if (message.request.lead.lead_id) {
|
|
462
|
+
await chatbot.addParameter("userLeadId", message.request.lead.lead_id);
|
|
463
|
+
}
|
|
464
|
+
if (message.request.lead.company) {
|
|
465
|
+
await chatbot.addParameter("userCompany", message.request.lead.company);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
451
468
|
}
|
|
452
469
|
|
|
453
470
|
|
package/package.json
CHANGED
|
@@ -17,6 +17,7 @@ class DirMake {
|
|
|
17
17
|
this.requestId = this.context.requestId;
|
|
18
18
|
this.log = context.log;
|
|
19
19
|
this.intentDir = new DirIntent(context);
|
|
20
|
+
if (this.log) {console.log('LOG: ', this.log)};
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
execute(directive, callback) {
|
|
@@ -37,6 +38,9 @@ class DirMake {
|
|
|
37
38
|
|
|
38
39
|
async go(action, callback) {
|
|
39
40
|
if (this.log) { console.log("DirMake action:", JSON.stringify(action)); }
|
|
41
|
+
let trueIntent = action.trueIntent;
|
|
42
|
+
let falseIntent = action.falseIntent;
|
|
43
|
+
if (this.log) {console.log('DirMake trueIntent',trueIntent)}
|
|
40
44
|
if (!this.tdcache) {
|
|
41
45
|
console.error("Error: DirMake tdcache is mandatory");
|
|
42
46
|
callback();
|
|
@@ -55,7 +59,7 @@ class DirMake {
|
|
|
55
59
|
if (this.log) { console.log("DirMake request parameter:", key, "value:", value, "type:", typeof value) }
|
|
56
60
|
}
|
|
57
61
|
}
|
|
58
|
-
|
|
62
|
+
|
|
59
63
|
let webhook_url = action.url;
|
|
60
64
|
let bodyParameters = action.bodyParameters;
|
|
61
65
|
if (this.log) {
|
|
@@ -63,43 +67,44 @@ class DirMake {
|
|
|
63
67
|
console.log("DirMake bodyParameters: ", bodyParameters);
|
|
64
68
|
}
|
|
65
69
|
if (!bodyParameters || bodyParameters === '') {
|
|
66
|
-
console.error("DirMake ERROR - bodyParameters is undefined or null or empty string");
|
|
70
|
+
if (this.log) {console.error("DirMake ERROR - bodyParameters is undefined or null or empty string")};
|
|
67
71
|
callback();
|
|
68
72
|
return;
|
|
69
73
|
}
|
|
70
74
|
if (!webhook_url || webhook_url === '') {
|
|
71
|
-
console.error("DirMake ERROR - webhook_url is undefined or null or empty string");
|
|
72
|
-
|
|
75
|
+
if (this.log) {console.error("DirMake ERROR - webhook_url is undefined or null or empty string:")};
|
|
76
|
+
let status = 422;
|
|
77
|
+
let error = 'Missing make webhook url';
|
|
78
|
+
await this.#assignAttributes(action, status, error);
|
|
79
|
+
this.#executeCondition(false, trueIntent, null, falseIntent, null, () => {
|
|
80
|
+
callback(); // stop the flow
|
|
81
|
+
});
|
|
73
82
|
return;
|
|
74
83
|
}
|
|
75
84
|
let url;
|
|
76
85
|
try {
|
|
77
86
|
let make_base_url = process.env.MAKE_ENDPOINT;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
87
|
+
if (make_base_url) {
|
|
88
|
+
url = make_base_url + "/make/";
|
|
89
|
+
} else {
|
|
90
|
+
url = action.url;
|
|
91
|
+
}
|
|
92
|
+
const filler = new Filler();
|
|
86
93
|
for (const [key, value] of Object.entries(bodyParameters)) {
|
|
87
|
-
if (this.log) {console.log("bodyParam:", key, "value:", value)}
|
|
94
|
+
//if (this.log) {console.log("bodyParam:", key, "value:", value)}
|
|
88
95
|
let filled_value = filler.fill(value, requestVariables);
|
|
89
96
|
bodyParameters[key] = filled_value;
|
|
90
97
|
}
|
|
98
|
+
if (this.log) {console.log('DirMake bodyParameters filler: ',bodyParameters)}
|
|
91
99
|
|
|
92
|
-
console.log('CIAO',bodyParameters)
|
|
93
|
-
|
|
94
|
-
|
|
95
100
|
|
|
96
101
|
|
|
97
102
|
// Condition branches
|
|
98
|
-
let trueIntent = action.trueIntent;
|
|
99
|
-
let falseIntent = action.falseIntent;
|
|
100
|
-
console.log('trueIntent',trueIntent)
|
|
103
|
+
//let trueIntent = action.trueIntent;
|
|
104
|
+
//let falseIntent = action.falseIntent;
|
|
105
|
+
//console.log('DirMake trueIntent',trueIntent)
|
|
101
106
|
|
|
102
|
-
if (this.log) { console.log("DirMake MakeEndpoint URL: ",
|
|
107
|
+
if (this.log) { console.log("DirMake MakeEndpoint URL: ", url); }
|
|
103
108
|
const MAKE_HTTPREQUEST = {
|
|
104
109
|
url: url,
|
|
105
110
|
headers: {
|
|
@@ -114,9 +119,9 @@ class DirMake {
|
|
|
114
119
|
MAKE_HTTPREQUEST, async (err, resbody) => {
|
|
115
120
|
if (err) {
|
|
116
121
|
if (callback) {
|
|
117
|
-
console.error("myrequest/(httprequest) DirMake make err:", err);
|
|
122
|
+
if (this.log) {console.error("myrequest/(httprequest) DirMake make err:", err)};
|
|
118
123
|
let status = 404;
|
|
119
|
-
let error = '
|
|
124
|
+
let error = 'Make url not found';
|
|
120
125
|
await this.#assignAttributes(action, status, error);
|
|
121
126
|
this.#executeCondition(false, trueIntent, null, falseIntent, null, () => {
|
|
122
127
|
callback(false); // continue the flow
|
|
@@ -131,8 +136,8 @@ class DirMake {
|
|
|
131
136
|
await this.#executeCondition(true, trueIntent, null, falseIntent, null, () => {
|
|
132
137
|
callback(); // stop the flow
|
|
133
138
|
});
|
|
134
|
-
console.log('myrequest/status: ',status)
|
|
135
|
-
callback();
|
|
139
|
+
if (this.log) {console.log('myrequest/status: ',status)}
|
|
140
|
+
//callback();
|
|
136
141
|
}
|
|
137
142
|
}
|
|
138
143
|
);
|
|
@@ -207,7 +212,7 @@ class DirMake {
|
|
|
207
212
|
}
|
|
208
213
|
})
|
|
209
214
|
.catch((error) => {
|
|
210
|
-
|
|
215
|
+
if (this.log) {console.error("An error occurred:", JSON.stringify(error.message))};
|
|
211
216
|
if (callback) {
|
|
212
217
|
callback(error, null);
|
|
213
218
|
}
|
|
@@ -54,6 +54,15 @@ class DirReply {
|
|
|
54
54
|
const filler = new Filler();
|
|
55
55
|
// fill text attribute
|
|
56
56
|
message.text = filler.fill(message.text, requestAttributes);
|
|
57
|
+
if (message.metadata) {
|
|
58
|
+
if (this.log) {console.log("filling message 'metadata':", JSON.stringify(message.metadata));}
|
|
59
|
+
if (message.metadata.src) {
|
|
60
|
+
message.metadata.src = filler.fill(message.metadata.src, requestAttributes);
|
|
61
|
+
}
|
|
62
|
+
if (message.metadata.name) {
|
|
63
|
+
message.metadata.name = filler.fill(message.metadata.name, requestAttributes);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
57
66
|
if (this.log) {console.log("filling commands'. Message:", JSON.stringify(message));}
|
|
58
67
|
if (message.attributes && message.attributes.commands) {
|
|
59
68
|
if (this.log) {console.log("filling commands'. commands found.");}
|