@tiledesk/tiledesk-tybot-connector 0.2.30 → 0.2.32
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 +7 -0
- package/TiledeskExpression.js +2 -2
- package/models/TiledeskChatbot.js +2 -2
- package/package.json +1 -1
- package/tiledeskChatbotPlugs/directives/DirMake.js +25 -22
- package/tiledeskChatbotPlugs/directives/DirReply.js +16 -83
- package/tiledeskChatbotPlugs/directives/DirSetAttributeV2.js +14 -11
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.32
|
|
9
|
+
- Added attributes filling to message.metadata.src
|
|
10
|
+
- Added attributes filling to message.metadata.name
|
|
11
|
+
|
|
12
|
+
# v0.2.31
|
|
13
|
+
- Removed patch: Added support for removing empty text from replies: TiledeskChatbotUtil.removeEmptyReplyCommands()
|
|
14
|
+
|
|
8
15
|
### v0.2.30
|
|
9
16
|
- Updated WhatsappByAttribute action
|
|
10
17
|
- Fixed bug: WhatsappByAttribute action pointed to whatsapp pre
|
package/TiledeskExpression.js
CHANGED
|
@@ -234,8 +234,8 @@ class TiledeskExpression {
|
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
evaluateJavascriptExpression(expression, context) {
|
|
237
|
-
console.log("(evaluateJavascriptExpression) evaluating:", expression)
|
|
238
|
-
console.log("context:", context)
|
|
237
|
+
// console.log("(evaluateJavascriptExpression) evaluating:", expression)
|
|
238
|
+
// console.log("context:", context)
|
|
239
239
|
let res = null;
|
|
240
240
|
try {
|
|
241
241
|
const vm = new VM({
|
|
@@ -80,7 +80,7 @@ class TiledeskChatbot {
|
|
|
80
80
|
if (this.log) {console.log("RESETTING LOCKED INTENT. Intent was explicitly invoked with an action:", message.attributes.action);}
|
|
81
81
|
await this.unlockIntent(this.requestId);
|
|
82
82
|
await this.unlockAction(this.requestId);
|
|
83
|
-
console.log("RESET LOCKED INTENT.");
|
|
83
|
+
// console.log("RESET LOCKED INTENT.");
|
|
84
84
|
if (this.log) {console.log("RESET LOCKED INTENT. Intent was explicitly invoked with an action:", message.attributes.action);}
|
|
85
85
|
}
|
|
86
86
|
} catch(error) {
|
|
@@ -296,7 +296,7 @@ class TiledeskChatbot {
|
|
|
296
296
|
}
|
|
297
297
|
if (this.log) {console.log("NLP intents found:", intents);}
|
|
298
298
|
if (intents && intents.length > 0) {
|
|
299
|
-
console.log("Matching intents found.");
|
|
299
|
+
// console.log("Matching intents found.");
|
|
300
300
|
// let faq = await this.botsDataSource.getByIntentDisplayName(this.botId, intents[0].intent_display_name);
|
|
301
301
|
let faq = await this.botsDataSource.getByIntentDisplayNameCache(this.botId, intents[0].intent_display_name, this.tdcache);
|
|
302
302
|
let reply;
|
package/package.json
CHANGED
|
@@ -9,6 +9,7 @@ require('dotenv').config();
|
|
|
9
9
|
class DirMake {
|
|
10
10
|
|
|
11
11
|
constructor(context) {
|
|
12
|
+
console.log('context object LOG: ', context.log)
|
|
12
13
|
if (!context) {
|
|
13
14
|
throw new Error('context object is mandatory');
|
|
14
15
|
}
|
|
@@ -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
|
+
//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) {
|
|
@@ -69,39 +73,38 @@ class DirMake {
|
|
|
69
73
|
}
|
|
70
74
|
if (!webhook_url || webhook_url === '') {
|
|
71
75
|
console.error("DirMake ERROR - webhook_url is undefined or null or empty string");
|
|
72
|
-
|
|
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
|
-
console.log('CIAOkkkk',bodyParameters)
|
|
78
86
|
let make_base_url = process.env.MAKE_ENDPOINT;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const filler = new Filler();
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
if (make_base_url) {
|
|
88
|
+
url = make_base_url + "/make/";
|
|
89
|
+
} else {
|
|
90
|
+
url = action.url;
|
|
91
|
+
}
|
|
92
|
+
const filler = new Filler();
|
|
88
93
|
for (const [key, value] of Object.entries(bodyParameters)) {
|
|
89
|
-
if (this.log) {console.log("bodyParam:", key, "value:", value)}
|
|
94
|
+
//if (this.log) {console.log("bodyParam:", key, "value:", value)}
|
|
90
95
|
let filled_value = filler.fill(value, requestVariables);
|
|
91
96
|
bodyParameters[key] = filled_value;
|
|
92
97
|
}
|
|
98
|
+
if (this.log) {console.log('DirMake bodyParameters filler: ',bodyParameters)}
|
|
93
99
|
|
|
94
|
-
console.log('CIAO',bodyParameters)
|
|
95
|
-
|
|
96
|
-
|
|
97
100
|
|
|
98
101
|
|
|
99
102
|
// Condition branches
|
|
100
|
-
let trueIntent = action.trueIntent;
|
|
101
|
-
let falseIntent = action.falseIntent;
|
|
102
|
-
console.log('trueIntent',trueIntent)
|
|
103
|
+
//let trueIntent = action.trueIntent;
|
|
104
|
+
//let falseIntent = action.falseIntent;
|
|
105
|
+
//console.log('DirMake trueIntent',trueIntent)
|
|
103
106
|
|
|
104
|
-
if (this.log) { console.log("DirMake MakeEndpoint URL: ",
|
|
107
|
+
if (this.log) { console.log("DirMake MakeEndpoint URL: ", url); }
|
|
105
108
|
const MAKE_HTTPREQUEST = {
|
|
106
109
|
url: url,
|
|
107
110
|
headers: {
|
|
@@ -133,8 +136,8 @@ class DirMake {
|
|
|
133
136
|
await this.#executeCondition(true, trueIntent, null, falseIntent, null, () => {
|
|
134
137
|
callback(); // stop the flow
|
|
135
138
|
});
|
|
136
|
-
console.log('myrequest/status: ',status)
|
|
137
|
-
callback();
|
|
139
|
+
if (this.log) {console.log('myrequest/status: ',status)}
|
|
140
|
+
//callback();
|
|
138
141
|
}
|
|
139
142
|
}
|
|
140
143
|
);
|
|
@@ -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.");}
|
|
@@ -97,11 +106,13 @@ class DirReply {
|
|
|
97
106
|
}
|
|
98
107
|
}
|
|
99
108
|
// send!
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
109
|
+
let cleanMessage = message;
|
|
110
|
+
// cleanMessage = TiledeskChatbotUtil.removeEmptyReplyCommands(message);
|
|
111
|
+
// if (!TiledeskChatbotUtil.isValidReply(cleanMessage)) {
|
|
112
|
+
// console.log("invalid message", cleanMessage);
|
|
113
|
+
// callback(); // cancel reply operation
|
|
114
|
+
// return;
|
|
115
|
+
// }
|
|
105
116
|
// console.log("valid message!", cleanMessage);
|
|
106
117
|
cleanMessage.senderFullname = this.context.chatbot.bot.name;
|
|
107
118
|
if (this.log) {console.log("Reply:", JSON.stringify(cleanMessage))};
|
|
@@ -128,86 +139,8 @@ class DirReply {
|
|
|
128
139
|
}
|
|
129
140
|
});
|
|
130
141
|
|
|
131
|
-
// this.sendSupportMessage(
|
|
132
|
-
// this.requestId,
|
|
133
|
-
// message,
|
|
134
|
-
// (err) => {
|
|
135
|
-
// if (err) {
|
|
136
|
-
// console.error("Error sending reply:", err);
|
|
137
|
-
// }
|
|
138
|
-
// // if (this.log) {console.log("Reply message sent.");}
|
|
139
|
-
// console.log("Reply message sent.", JSON.stringify(message));
|
|
140
|
-
// callback();
|
|
141
|
-
// }
|
|
142
|
-
// );
|
|
143
142
|
}
|
|
144
143
|
|
|
145
|
-
// sendSupportMessage(requestId, message, callback) {
|
|
146
|
-
// const url = `${this.context.tdclient.APIURL}/${this.projectId}/requests/${requestId}/messages`
|
|
147
|
-
// const HTTPREQUEST = {
|
|
148
|
-
// url: url,
|
|
149
|
-
// headers: {
|
|
150
|
-
// 'Content-Type' : 'application/json',
|
|
151
|
-
// 'Authorization': "JWT " + this.token
|
|
152
|
-
// },
|
|
153
|
-
// json: message,
|
|
154
|
-
// method: 'POST'
|
|
155
|
-
// };
|
|
156
|
-
// this.myrequest(
|
|
157
|
-
// HTTPREQUEST,
|
|
158
|
-
// function(err, resbody) {
|
|
159
|
-
// if (err) {
|
|
160
|
-
// if (callback) {
|
|
161
|
-
// callback(err);
|
|
162
|
-
// }
|
|
163
|
-
// }
|
|
164
|
-
// else {
|
|
165
|
-
// if (callback) {
|
|
166
|
-
// callback(null, resbody);
|
|
167
|
-
// }
|
|
168
|
-
// }
|
|
169
|
-
// }, this.log
|
|
170
|
-
// );
|
|
171
|
-
// }
|
|
172
|
-
|
|
173
|
-
// myrequest(options, callback, log) {
|
|
174
|
-
// console.log("API URL:", options.url);
|
|
175
|
-
// console.log("** Options:", JSON.stringify(options));
|
|
176
|
-
// console.log("** Sending reply json:", JSON.stringify(options.json));
|
|
177
|
-
// axios(
|
|
178
|
-
// {
|
|
179
|
-
// url: options.url,
|
|
180
|
-
// method: options.method,
|
|
181
|
-
// data: options.json,
|
|
182
|
-
// params: options.params,
|
|
183
|
-
// headers: options.headers
|
|
184
|
-
// })
|
|
185
|
-
// .then((res) => {
|
|
186
|
-
// console.log("Reply: Response for url:", options.url);
|
|
187
|
-
// console.log("Reply: Response headers:\n", JSON.stringify(res.headers));
|
|
188
|
-
// console.log("Reply: Status:", res.status);
|
|
189
|
-
// console.log("Reply: Data:", JSON.stringify(res.data));
|
|
190
|
-
// if (res && res.status == 200 && res.data) {
|
|
191
|
-
// console.log("Status 200 OK");
|
|
192
|
-
// if (callback) {
|
|
193
|
-
// callback(null, res.data);
|
|
194
|
-
// }
|
|
195
|
-
// }
|
|
196
|
-
// else {
|
|
197
|
-
// console.error("Status ! 200");
|
|
198
|
-
// if (callback) {
|
|
199
|
-
// callback({ message: "Response status not 200" }, null);
|
|
200
|
-
// }
|
|
201
|
-
// }
|
|
202
|
-
// })
|
|
203
|
-
// .catch((error) => {
|
|
204
|
-
// console.error("Reply error:", error);
|
|
205
|
-
// if (callback) {
|
|
206
|
-
// callback(error, null);
|
|
207
|
-
// }
|
|
208
|
-
// });
|
|
209
|
-
// }
|
|
210
|
-
|
|
211
144
|
}
|
|
212
145
|
|
|
213
146
|
module.exports = { DirReply };
|
|
@@ -96,12 +96,12 @@ class DirSetAttributeV2 {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
async go(action, callback) {
|
|
99
|
-
console.log("(DirSetAttribute) action before filling:", JSON.stringify(action));
|
|
99
|
+
if (this.log) {console.log("(DirSetAttribute) action before filling:", JSON.stringify(action));}
|
|
100
100
|
if (action && action.operation && action.operation.operands) {
|
|
101
|
-
console.log("filling in setattribute...");
|
|
101
|
+
if (this.log) {console.log("filling in setattribute...");}
|
|
102
102
|
await this.fillValues(action.operation.operands);
|
|
103
103
|
}
|
|
104
|
-
console.log("filled in setattribute:", action.operation);
|
|
104
|
+
if (this.log) {console.log("filled in setattribute:", action.operation);}
|
|
105
105
|
// let res = validate(action, schema);
|
|
106
106
|
// if (res.errors) {
|
|
107
107
|
// console.log("(DirSetAttribute) failed validation action:", JSON.stringify(action));
|
|
@@ -126,14 +126,17 @@ class DirSetAttributeV2 {
|
|
|
126
126
|
// console.log("filling in setattribute...");
|
|
127
127
|
// await this.fillValues(action.operation.operands);
|
|
128
128
|
// }
|
|
129
|
-
console.log("dirsetattribute, action.operation.operands:", action.operation.operands);
|
|
129
|
+
// console.log("dirsetattribute, action.operation.operands:", action.operation.operands);
|
|
130
130
|
const expression = TiledeskExpression.JSONOperationToExpression(action.operation.operators, action.operation.operands);
|
|
131
131
|
const attributes = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId);
|
|
132
|
-
console.log("dirsetattribute, attributes:", attributes);
|
|
132
|
+
// console.log("dirsetattribute, attributes:", attributes);
|
|
133
133
|
attributes.TiledeskMath = TiledeskMath;
|
|
134
134
|
attributes.TiledeskString = TiledeskString;
|
|
135
135
|
const result = new TiledeskExpression().evaluateJavascriptExpression(expression, attributes);
|
|
136
|
-
console.log("filling in setattribute, result:", result);
|
|
136
|
+
// console.log("filling in setattribute, result:", result);
|
|
137
|
+
// THE GOAL OF ATTRIBUTE-FILLING THE "DESTINATION" FIELD IS TO SUPPORT DYNAMIC ATTRIBUTES
|
|
138
|
+
// (ATTRS WHOSE NAME IS UNKNOWN AD DESIGN-TIME)
|
|
139
|
+
// STILL UNSUPPORTED IN UI
|
|
137
140
|
let destination = await this.fillDestination(action.destination);
|
|
138
141
|
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, destination, result);
|
|
139
142
|
callback();
|
|
@@ -147,7 +150,7 @@ class DirSetAttributeV2 {
|
|
|
147
150
|
// console.log("requestAttributes in setattribute...", requestAttributes);
|
|
148
151
|
const filler = new Filler();
|
|
149
152
|
destination = filler.fill(destination, requestAttributes);
|
|
150
|
-
console.log("setattribute, final destination:", destination);
|
|
153
|
+
// console.log("setattribute, final destination:", destination);
|
|
151
154
|
}
|
|
152
155
|
return destination
|
|
153
156
|
}
|
|
@@ -186,11 +189,11 @@ class DirSetAttributeV2 {
|
|
|
186
189
|
// console.log("requestAttributes in setattribute...", requestAttributes);
|
|
187
190
|
const filler = new Filler();
|
|
188
191
|
operands.forEach(operand => {
|
|
189
|
-
if (!operand.isVariable) {
|
|
190
|
-
console.log("setattribute, liquid operand:", operand);
|
|
192
|
+
// if (!operand.isVariable) {
|
|
193
|
+
// console.log("setattribute, liquid operand:", operand);
|
|
191
194
|
operand.value = filler.fill(operand.value, requestAttributes);
|
|
192
|
-
console.log("setattribute, final operand:", operand);
|
|
193
|
-
}
|
|
195
|
+
// console.log("setattribute, final operand:", operand);
|
|
196
|
+
// }
|
|
194
197
|
});
|
|
195
198
|
}
|
|
196
199
|
}
|