@tiledesk/tiledesk-tybot-connector 0.1.83 → 0.1.85
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 +1 -1
- package/index.js +3 -24
- package/models/TiledeskChatbot.js +1 -0
- package/models/TiledeskChatbotUtil.js +47 -30
- package/package.json +3 -3
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +9 -1
- package/tiledeskChatbotPlugs/TiledeskRequestVariables.js +65 -0
- package/tiledeskChatbotPlugs/directives/DirCode.js +91 -0
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirRandomReply.js +0 -6
- package/tiledeskChatbotPlugs/directives/DirReply.js +12 -16
- package/tiledeskChatbotPlugs/directives/Directives.js +15 -16
- /package/tiledeskChatbotPlugs/directives/{DirWhenOpen.js → DEPRECATED_DirWhenOpen.js} +0 -0
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
|
+
### 0.1.85
|
|
9
|
+
- "Match (regex) operator" fix
|
|
10
|
+
- Text in multiple message commands is now merged in main "message.text" property based on filtered commands
|
|
11
|
+
|
|
12
|
+
### 0.1.84
|
|
13
|
+
- removed debug logs
|
|
14
|
+
|
|
8
15
|
### 0.1.83
|
|
9
16
|
- added "attributes.intentName" in chatbot replies, showing the last block involved in generating the reply
|
|
10
17
|
|
package/TiledeskExpression.js
CHANGED
package/index.js
CHANGED
|
@@ -1,28 +1,18 @@
|
|
|
1
1
|
const express = require('express');
|
|
2
2
|
const router = express.Router();
|
|
3
3
|
const bodyParser = require('body-parser');
|
|
4
|
-
//var cors = require('cors');
|
|
5
|
-
//let path = require("path");
|
|
6
|
-
//let fs = require('fs');
|
|
7
|
-
// const { TiledeskChatbotClient } = require('@tiledesk/tiledesk-chatbot-client');
|
|
8
4
|
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
9
|
-
//const { TiledeskClientTest } = require('./TiledeskClientTest');
|
|
10
|
-
//const jwt = require('jsonwebtoken');
|
|
11
|
-
//const { v4: uuidv4 } = require('uuid');
|
|
12
5
|
const { ExtApi } = require('./ExtApi.js');
|
|
13
6
|
const { ExtUtil } = require('./ExtUtil.js');
|
|
14
7
|
const { TdCache } = require('./TdCache.js');
|
|
15
|
-
//const { IntentForm } = require('./IntentForm.js');
|
|
16
8
|
const { TiledeskChatbot } = require('./models/TiledeskChatbot.js');
|
|
17
9
|
const { MongodbBotsDataSource } = require('./models/MongodbBotsDataSource.js');
|
|
18
10
|
const { MongodbIntentsMachine } = require('./models/MongodbIntentsMachine.js');
|
|
19
11
|
const { TiledeskIntentsMachine } = require('./models/TiledeskIntentsMachine.js');
|
|
20
|
-
// const { MockActions } = require('./MockActions');
|
|
21
12
|
const { MockBotsDataSource } = require('./models/MockBotsDataSource.js');
|
|
22
13
|
const { TiledeskChatbotConst } = require('./models/TiledeskChatbotConst');
|
|
23
14
|
const { IntentsMachineFactory } = require('./models/IntentsMachineFactory');
|
|
24
15
|
|
|
25
|
-
//router.use(cors());
|
|
26
16
|
router.use(bodyParser.json({limit: '50mb'}));
|
|
27
17
|
router.use(bodyParser.urlencoded({ extended: true , limit: '50mb'}));
|
|
28
18
|
|
|
@@ -32,20 +22,9 @@ let tdcache = null;
|
|
|
32
22
|
// DEV
|
|
33
23
|
// const { MessagePipeline } = require('./tiledeskChatbotPlugs/MessagePipeline');
|
|
34
24
|
const { DirectivesChatbotPlug } = require('./tiledeskChatbotPlugs/DirectivesChatbotPlug');
|
|
35
|
-
// const { SplitsChatbotPlug } = require('./tiledeskChatbotPlugs/SplitsChatbotPlug');
|
|
36
|
-
// const { MarkbotChatbotPlug } = require('./tiledeskChatbotPlugs/MarkbotChatbotPlug');
|
|
37
|
-
// const { WebhookChatbotPlug } = require('./tiledeskChatbotPlugs/WebhookChatbotPlug');
|
|
38
|
-
|
|
39
|
-
// PROD
|
|
40
|
-
// const { MessagePipeline } = require('@tiledesk/tiledesk-chatbot-plugs/MessagePipeline');
|
|
41
|
-
// const { DirectivesChatbotPlug } = require('@tiledesk/tiledesk-chatbot-plugs/DirectivesChatbotPlug');
|
|
42
|
-
// const { SplitsChatbotPlug } = require('@tiledesk/tiledesk-chatbot-plugs/SplitsChatbotPlug');
|
|
43
|
-
// const { MarkbotChatbotPlug } = require('@tiledesk/tiledesk-chatbot-plugs/MarkbotChatbotPlug');
|
|
44
|
-
// const { WebhookChatbotPlug } = require('@tiledesk/tiledesk-chatbot-plugs/WebhookChatbotPlug');
|
|
45
25
|
|
|
46
26
|
// THE IMPORT
|
|
47
27
|
let mongoose = require('mongoose');
|
|
48
|
-
// const { DirSendEmail } = require('./tiledeskChatbotPlugs/directives/DirSendEmail.js');
|
|
49
28
|
const { Directives } = require('./tiledeskChatbotPlugs/directives/Directives.js');
|
|
50
29
|
let APIURL = null;
|
|
51
30
|
let staticBots;
|
|
@@ -269,7 +248,7 @@ async function updateRequestVariables(chatbot, message, projectId, requestId) {
|
|
|
269
248
|
if (message.request && message.request.location && message.request.location.city) {
|
|
270
249
|
await chatbot.addParameter(TiledeskChatbotConst.REQ_CITY_KEY, message.request.location.city);
|
|
271
250
|
}
|
|
272
|
-
// console.log("message.request.language", message.request["language"])
|
|
251
|
+
// console.log("message.request.language", message.request["language"]);
|
|
273
252
|
if (message.request) {
|
|
274
253
|
await chatbot.addParameter(TiledeskChatbotConst.REQ_USER_SOURCE_PAGE_KEY, message.request.sourcePage);
|
|
275
254
|
await chatbot.addParameter(TiledeskChatbotConst.REQ_USER_LANGUAGE_KEY, message.request["language"]);
|
|
@@ -296,7 +275,7 @@ async function updateRequestVariables(chatbot, message, projectId, requestId) {
|
|
|
296
275
|
}
|
|
297
276
|
message.attributes.payload = message.request.attributes.payload
|
|
298
277
|
if (chatbot.log) {console.log("FORCED SET message.attributes.payload:", JSON.stringify(message.attributes.payload))}
|
|
299
|
-
if (projectId === "641864da99c1fb00131ba495") {console.log("641864da99c1fb00131ba495 > FORCED SET message.attributes.payload:", JSON.stringify(message.attributes.payload))}
|
|
278
|
+
// if (projectId === "641864da99c1fb00131ba495") {console.log("641864da99c1fb00131ba495 > FORCED SET message.attributes.payload:", JSON.stringify(message.attributes.payload))}
|
|
300
279
|
}
|
|
301
280
|
|
|
302
281
|
if (message.attributes) {
|
|
@@ -309,7 +288,7 @@ async function updateRequestVariables(chatbot, message, projectId, requestId) {
|
|
|
309
288
|
for (const [key, value] of Object.entries(message.attributes.payload)) {
|
|
310
289
|
// const value = all_parameters[key];
|
|
311
290
|
const value_type = typeof value;
|
|
312
|
-
if (projectId === "641864da99c1fb00131ba495") {console.log("641864da99c1fb00131ba495 > importing payload parameter:", key, "value:", value, "type:", value_type);}
|
|
291
|
+
//if (projectId === "641864da99c1fb00131ba495") {console.log("641864da99c1fb00131ba495 > importing payload parameter:", key, "value:", value, "type:", value_type);}
|
|
313
292
|
await chatbot.addParameter(key, String(value));
|
|
314
293
|
}
|
|
315
294
|
}
|
|
@@ -466,6 +466,7 @@ class TiledeskChatbot {
|
|
|
466
466
|
bot: this.bot
|
|
467
467
|
}
|
|
468
468
|
static_bot_answer.attributes.intent_info = intent_info;
|
|
469
|
+
// console.log("static_bot_answer.attributes.intent_info",)
|
|
469
470
|
// static_bot_answer.attributes.directives = true;
|
|
470
471
|
// static_bot_answer.attributes.splits = true;
|
|
471
472
|
// static_bot_answer.attributes.markbot = true;
|
|
@@ -146,44 +146,61 @@ class TiledeskChatbotUtil {
|
|
|
146
146
|
// }
|
|
147
147
|
// }
|
|
148
148
|
|
|
149
|
-
static filterOnVariables(commands, variables) {
|
|
149
|
+
//static filterOnVariables(commands, variables) {
|
|
150
|
+
static filterOnVariables(message, variables) {
|
|
150
151
|
if (!variables) {
|
|
151
152
|
return;
|
|
152
153
|
}
|
|
153
|
-
if (commands.length > 0) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
// console.log("commands[
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
//
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
// console.log("
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
if (commands[i-1]
|
|
177
|
-
|
|
178
|
-
i
|
|
154
|
+
if (message.attributes.commands.length > 0) {
|
|
155
|
+
let commands = message.attributes.commands;
|
|
156
|
+
message.text = "";
|
|
157
|
+
for (let i = commands.length - 1; i >= 0; i--) {
|
|
158
|
+
// console.log("...commands[" + i + "]");
|
|
159
|
+
if (commands[i].type === "message") { // is a message, not wait
|
|
160
|
+
// console.log("commands[i]:", commands[i].message.text);
|
|
161
|
+
// console.log("commands[i]:", lang, (commands[i].message["lang"] === lang));
|
|
162
|
+
|
|
163
|
+
// if (commands[i].message["lang"] && !(commands[i].message["lang"] === lang)) { // if there is a filter and the filter is false, remove
|
|
164
|
+
const jsonCondition = commands[i].message["_tdJSONCondition"];
|
|
165
|
+
// console.log("jsonCondition:", jsonCondition);
|
|
166
|
+
if (jsonCondition) {
|
|
167
|
+
// const expression = TiledeskExpression.JSONGroupsToExpression(jsonCondition.groups);
|
|
168
|
+
const expression = TiledeskExpression.JSONGroupToExpression(jsonCondition);
|
|
169
|
+
// console.log("full json condition expression eval on command.message:", expression);
|
|
170
|
+
const conditionResult = new TiledeskExpression().evaluateStaticExpression(expression, variables);
|
|
171
|
+
// console.log("conditionResult:", conditionResult);
|
|
172
|
+
// FALSE
|
|
173
|
+
// console.log("commands[i]lang:", commands[i]);
|
|
174
|
+
if (conditionResult === false) {
|
|
175
|
+
// console.log("deleting command:", commands[i]);
|
|
176
|
+
commands.splice(i, 1);
|
|
177
|
+
if (commands[i-1]) {
|
|
178
|
+
// console.log("commands[i-1]?:", commands[i-1]);
|
|
179
|
+
if (commands[i-1].type === "wait") {
|
|
180
|
+
commands.splice(i-1, 1);
|
|
181
|
+
i--;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
// console.log("comands[i]:", commands[i], commands[i].message, commands[i].message.text)
|
|
187
|
+
if (commands[i] && commands[i].message && commands[i].message.text) {
|
|
188
|
+
// console.log("curr text:", message.text)
|
|
189
|
+
if (message.text === "") {
|
|
190
|
+
message.text = commands[i].message.text;
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
message.text = commands[i].message.text + "\n\n" + message.text;
|
|
194
|
+
}
|
|
195
|
+
// console.log("new text:", message.text)
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
// console.log("commands@", commands[i])
|
|
179
199
|
}
|
|
180
200
|
}
|
|
181
201
|
}
|
|
182
202
|
}
|
|
183
203
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
204
|
// for (let i = 0; i < commands.length; i++) {
|
|
188
205
|
// if (commands[i].type === 'message' && commands[i].message && commands[i].message.text) {
|
|
189
206
|
// if (this.log) {console.log("[" + commands[i].message.lang + "]commands[i].message.text:", commands[i].message.text);}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiledesk/tiledesk-tybot-connector",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.85",
|
|
4
4
|
"description": "Tiledesk Tybot connector",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
"jsonschema": "^1.4.1",
|
|
25
25
|
"jsonwebtoken": "^8.5.1",
|
|
26
26
|
"minimist-string": "^1.0.2",
|
|
27
|
-
"mocha": "^10.2.0",
|
|
28
27
|
"mongoose": "^6.3.5",
|
|
29
28
|
"nanoid": "^3.1.25",
|
|
30
29
|
"redis": "^3.1.2",
|
|
31
30
|
"uuid": "^3.3.3",
|
|
32
|
-
"vm2": "^3.9.13"
|
|
31
|
+
"vm2": "^3.9.13",
|
|
32
|
+
"mocha": "^10.2.0"
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -26,6 +26,7 @@ const { DirJSONCondition } = require('./directives/DirJSONCondition');
|
|
|
26
26
|
const { DirAssign } = require('./directives/DirAssign');
|
|
27
27
|
const { DirSetAttribute } = require('./directives/DirSetAttribute');
|
|
28
28
|
const { DirWebRequest } = require('./directives/DirWebRequest');
|
|
29
|
+
const { DirCode } = require('./directives/DirCode');
|
|
29
30
|
|
|
30
31
|
const { TiledeskChatbot } = require('../models/TiledeskChatbot');
|
|
31
32
|
const { DirIfOnlineAgents } = require('./directives/DirIfOnlineAgents');
|
|
@@ -380,7 +381,7 @@ class DirectivesChatbotPlug {
|
|
|
380
381
|
// });
|
|
381
382
|
// }
|
|
382
383
|
else if (directive_name === Directives.AGENT) {
|
|
383
|
-
console.log("...DirMoveToAgent");
|
|
384
|
+
// console.log("...DirMoveToAgent");
|
|
384
385
|
new DirMoveToAgent(context).execute(directive, async () => {
|
|
385
386
|
let next_dir = await this.nextDirective(this.directives);
|
|
386
387
|
this.process(next_dir);
|
|
@@ -473,6 +474,13 @@ class DirectivesChatbotPlug {
|
|
|
473
474
|
this.process(next_dir);
|
|
474
475
|
});
|
|
475
476
|
}
|
|
477
|
+
else if (directive_name === Directives.CODE) {
|
|
478
|
+
console.log("...DirCode", directive);
|
|
479
|
+
new DirCode(context).execute(directive, async () => {
|
|
480
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
481
|
+
this.process(next_dir);
|
|
482
|
+
});
|
|
483
|
+
}
|
|
476
484
|
else if (directive_name === Directives.DELETE) {
|
|
477
485
|
// console.log("got delete dir...")
|
|
478
486
|
new DirDeleteVariable(context).execute(directive, async () => {
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const { TiledeskChatbot } = require('../models/TiledeskChatbot');
|
|
2
|
+
|
|
3
|
+
class TiledeskRequestVariables {
|
|
4
|
+
|
|
5
|
+
constructor(requestId, tdcache, vars) {
|
|
6
|
+
this.requestId = requestId;
|
|
7
|
+
this.tdcache = tdcache;
|
|
8
|
+
this.vars = vars;
|
|
9
|
+
this.ops = {
|
|
10
|
+
set: {
|
|
11
|
+
},
|
|
12
|
+
del: {
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async set(name, value, callback) {
|
|
18
|
+
const parameter_key = TiledeskChatbot.requestCacheKey(this.requestId) + ":parameters";
|
|
19
|
+
await this.tdcache.hset(parameter_key, name, value);
|
|
20
|
+
if (callback) {
|
|
21
|
+
callback();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async get(name, callback) {
|
|
26
|
+
const parameter_key = TiledeskChatbot.requestCacheKey(this.requestId) + ":parameters";
|
|
27
|
+
const value = await this.tdcache.hget(parameter_key, name);
|
|
28
|
+
if (callback) {
|
|
29
|
+
callback(value);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async delete(name) {
|
|
37
|
+
const parameter_key = TiledeskChatbot.requestCacheKey(this.requestId) + ":parameters";
|
|
38
|
+
return await this.tdcache.hdel(parameter_key, name);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async all(callback) {
|
|
42
|
+
const parameter_key = TiledeskChatbot.requestCacheKey(this.requestId) + ":parameters";
|
|
43
|
+
const values = await this.tdcache.hgetall(parameter_key);
|
|
44
|
+
if (callback) {
|
|
45
|
+
callback(values);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
return values;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
setVar(key, value) {
|
|
53
|
+
this.ops.set[key] = value;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
delVar(key) {
|
|
57
|
+
this.ops.del[key] = true;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
allVars() {
|
|
61
|
+
return this.vars;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
module.exports = { TiledeskRequestVariables };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
|
|
2
|
+
const { TiledeskExpression } = require('../../TiledeskExpression');
|
|
3
|
+
const { TiledeskRequestVariables } = require('../TiledeskRequestVariables');
|
|
4
|
+
|
|
5
|
+
class DirCode {
|
|
6
|
+
|
|
7
|
+
constructor(context) {
|
|
8
|
+
if (!context) {
|
|
9
|
+
throw new Error('context object is mandatory.');
|
|
10
|
+
}
|
|
11
|
+
this.context = context;
|
|
12
|
+
this.log = context.log;
|
|
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, (stop) => {
|
|
25
|
+
callback(stop);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async go(action, callback) {
|
|
31
|
+
console.log("action.source:", action.source)
|
|
32
|
+
const source_code = action.source;
|
|
33
|
+
if (!source_code || source_code.trim() === "") {
|
|
34
|
+
if (this.log) {console.log("Invalid source_code");}
|
|
35
|
+
callback();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
let script_context = {
|
|
39
|
+
console: console
|
|
40
|
+
}
|
|
41
|
+
let variables = null;
|
|
42
|
+
if (this.context.tdcache) {
|
|
43
|
+
variables =
|
|
44
|
+
await TiledeskChatbot.allParametersStatic(
|
|
45
|
+
this.context.tdcache, this.context.requestId
|
|
46
|
+
);
|
|
47
|
+
if (this.log) {console.log("Variables:", JSON.stringify(variables))}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
console.error("(DirCode) No this.context.tdcache");
|
|
51
|
+
callback();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
console.log("before variables:", variables);
|
|
55
|
+
for (const [key, value] of Object.entries(variables)) {
|
|
56
|
+
script_context[key] = value;
|
|
57
|
+
}
|
|
58
|
+
let variablesManager = new TiledeskRequestVariables(this.context.requestId, this.context.tdcache, variables)
|
|
59
|
+
script_context.tiledeskVars = variablesManager;
|
|
60
|
+
//console.log("script_context:", script_context);
|
|
61
|
+
const tdExpression = new TiledeskExpression();
|
|
62
|
+
//console.log("tdExpression:", tdExpression.evaluateJavascriptExpression);
|
|
63
|
+
try {
|
|
64
|
+
const result = new TiledeskExpression().evaluateJavascriptExpression(source_code, script_context);
|
|
65
|
+
console.log("result:", result);
|
|
66
|
+
// console.log("script_context.tiledeskVars:", script_context.tiledeskVars);
|
|
67
|
+
for (const [key, value] of Object.entries(script_context.tiledeskVars.ops.set)) {
|
|
68
|
+
// await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, key, value);
|
|
69
|
+
await variablesManager.set(key, value);
|
|
70
|
+
}
|
|
71
|
+
// if (this.log) {
|
|
72
|
+
let newvars_set = await variablesManager.all();
|
|
73
|
+
// console.log("newvars_set:", newvars_set);
|
|
74
|
+
// }
|
|
75
|
+
for (const [key, value] of Object.entries(script_context.tiledeskVars.ops.del)) {
|
|
76
|
+
// await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, key, value);
|
|
77
|
+
await variablesManager.delete(key);
|
|
78
|
+
}
|
|
79
|
+
const newvars_del = await variablesManager.all();
|
|
80
|
+
console.log("newvars_del:", newvars_del);
|
|
81
|
+
}
|
|
82
|
+
catch(err) {
|
|
83
|
+
console.error("An error occurred:", err);
|
|
84
|
+
}
|
|
85
|
+
callback();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
module.exports = { DirCode };
|
|
@@ -73,12 +73,6 @@ class DirRandomReply {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
// EVALUATE EXPRESSION AND REMOVE BASED ON EVALUATION
|
|
77
|
-
// if (message.attributes && message.attributes.commands) {
|
|
78
|
-
// if (this.log) {console.log("filterOnVariables...on commands", JSON.stringify(message.attributes.commands));}
|
|
79
|
-
// TiledeskChatbotUtil.filterOnVariables(message.attributes.commands, requestVariables);
|
|
80
|
-
// }
|
|
81
|
-
|
|
82
76
|
// temporary send back of reserved attributes
|
|
83
77
|
if (!message.attributes) {
|
|
84
78
|
message.attributes = {}
|
|
@@ -38,21 +38,21 @@ class DirReply {
|
|
|
38
38
|
async go(action, callback) {
|
|
39
39
|
const message = action;
|
|
40
40
|
// fill
|
|
41
|
-
let
|
|
41
|
+
let requestAttributes = null;
|
|
42
42
|
if (this.tdcache) {
|
|
43
|
-
|
|
43
|
+
requestAttributes =
|
|
44
44
|
await TiledeskChatbot.allParametersStatic(
|
|
45
45
|
this.tdcache, this.requestId
|
|
46
46
|
);
|
|
47
47
|
if (this.log) {
|
|
48
|
-
for (const [key, value] of Object.entries(
|
|
48
|
+
for (const [key, value] of Object.entries(requestAttributes)) {
|
|
49
49
|
const value_type = typeof value;
|
|
50
50
|
if (this.log) {console.log("(DirReply) request parameter:", key, "value:", value, "type:", value_type)}
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
const filler = new Filler();
|
|
54
54
|
// fill text attribute
|
|
55
|
-
message.text = filler.fill(message.text,
|
|
55
|
+
message.text = filler.fill(message.text, requestAttributes);
|
|
56
56
|
if (this.log) {console.log("filling commands'. Message:", JSON.stringify(message));}
|
|
57
57
|
if (message.attributes && message.attributes.commands) {
|
|
58
58
|
if (this.log) {console.log("filling commands'. commands found.");}
|
|
@@ -63,8 +63,8 @@ class DirReply {
|
|
|
63
63
|
for (let i = 0; i < commands.length; i++) {
|
|
64
64
|
let command = commands[i];
|
|
65
65
|
if (command.type === 'message' && command.message && command.message.text) {
|
|
66
|
-
command.message.text = filler.fill(command.message.text,
|
|
67
|
-
TiledeskChatbotUtil.fillCommandAttachments(command,
|
|
66
|
+
command.message.text = filler.fill(command.message.text, requestAttributes);
|
|
67
|
+
TiledeskChatbotUtil.fillCommandAttachments(command, requestAttributes, this.log);
|
|
68
68
|
if (this.log) {console.log("command filled:", command.message.text);}
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -72,25 +72,21 @@ class DirReply {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
// EVALUATE EXPRESSION AND REMOVE BASED ON EVALUATION
|
|
75
|
-
// const mylang = requestVariables["mylang"];
|
|
76
|
-
// console.log("filterOnVariables:", JSON.stringify(requestVariables));
|
|
77
|
-
// if (message.attributes && message.attributes.commands) {
|
|
78
|
-
// TiledeskChatbotUtil.filterOnLanguage(message.attributes.commands, mylang);
|
|
79
|
-
// }
|
|
80
75
|
if (message.attributes && message.attributes.commands) {
|
|
81
76
|
if (this.log) {console.log("filterOnVariables...on commands", JSON.stringify(message.attributes.commands));}
|
|
82
|
-
TiledeskChatbotUtil.filterOnVariables(message.attributes.commands,
|
|
77
|
+
// TiledeskChatbotUtil.filterOnVariables(message.attributes.commands, requestAttributes);
|
|
78
|
+
TiledeskChatbotUtil.filterOnVariables(message, requestAttributes);
|
|
83
79
|
}
|
|
84
80
|
// temporary send back of reserved attributes
|
|
85
81
|
if (!message.attributes) {
|
|
86
82
|
message.attributes = {}
|
|
87
83
|
}
|
|
88
84
|
// Reserved names: userEmail, userFullname
|
|
89
|
-
if (
|
|
90
|
-
message.attributes.updateUserEmail =
|
|
85
|
+
if (requestAttributes['userEmail']) {
|
|
86
|
+
message.attributes.updateUserEmail = requestAttributes['userEmail'];
|
|
91
87
|
}
|
|
92
|
-
if (
|
|
93
|
-
message.attributes.updateUserFullname =
|
|
88
|
+
if (requestAttributes['userFullname']) {
|
|
89
|
+
message.attributes.updateUserFullname = requestAttributes['userFullname'];
|
|
94
90
|
}
|
|
95
91
|
// intent_info
|
|
96
92
|
if (this.context.reply && this.context.reply.attributes && this.context.reply.attributes.intent_info) {
|
|
@@ -1,23 +1,13 @@
|
|
|
1
1
|
class Directives {
|
|
2
2
|
static AGENT = 'agent';
|
|
3
|
-
static WHEN_ONLINE_MOVE_TO_AGENT = "whenonlinemovetoagent"; // DEPRECATED?
|
|
4
3
|
static CLOSE = 'close';
|
|
5
4
|
static DEPARTMENT = 'department';
|
|
6
|
-
static JSONMESSAGE = 'jsonmessage'; // DEPRECATED?
|
|
7
5
|
static MESSAGE = 'message';
|
|
8
6
|
static HMESSAGE = 'hmessage';
|
|
9
7
|
static INTENT = 'intent';
|
|
10
8
|
static REMOVE_CURRENT_BOT = "removecurrentbot";
|
|
11
9
|
static REPLACE_BOT = "replacebot";
|
|
12
|
-
static
|
|
13
|
-
static WHEN_OFFLINE_HOURS = "whenofflinehours"; // DEPRECATED // adds a message on top of the original message when offline hours opts: --replace
|
|
14
|
-
//static WHEN_OFFLINE_HOURS_REPLACE_MESSAGE = "whenofflinehoursreplacemessage"; // REMOVE
|
|
15
|
-
static DISABLE_INPUT_TEXT = "disableinputtext"; // DEPRECATED
|
|
16
|
-
static WHEN_OPEN = "whenopen"; // DEPRECATED
|
|
17
|
-
static WHEN_CLOSED = "whenclosed"; // DEPRECATED
|
|
18
|
-
static IF_NO_AGENTS = "ifnoagents"; // DEPRECATED
|
|
19
|
-
static IF_AGENTS = "ifagents"; // DEPRECATED
|
|
20
|
-
|
|
10
|
+
static ASSIGN = "assign"; // DEPRECATED
|
|
21
11
|
static ASK_HELP_CENTER = "askhelpcenter";
|
|
22
12
|
static WAIT = "wait";
|
|
23
13
|
static LOCK_INTENT = "lockintent";
|
|
@@ -28,16 +18,25 @@ class Directives {
|
|
|
28
18
|
static DELETE = "delete";
|
|
29
19
|
static IF_OPEN_HOURS = "ifopenhours";
|
|
30
20
|
static IF_ONLINE_AGENTS = "ifonlineagents";
|
|
31
|
-
static IF_NOT_OPEN_HOURS = "ifnotopenhours"; // DEPRECATED
|
|
32
21
|
static FUNCTION_VALUE = "functionvalue";
|
|
33
|
-
static CONDITION = "condition"; // DEPRECATED
|
|
34
22
|
static JSON_CONDITION = "jsoncondition";
|
|
35
|
-
static ASSIGN = "assign"; // DEPRECATED
|
|
36
23
|
static SET_ATTRIBUTE = "setattribute";
|
|
37
|
-
// static IF_AVAILABLE_AGENTS = "ifavailableagents"; // TODO
|
|
38
|
-
// static IF_NO_AVAILABLE_AGENTS = "ifnotavailableagents"; // TODO
|
|
39
24
|
static REPLY = 'reply';
|
|
40
25
|
static RANDOM_REPLY = 'randomreply';
|
|
26
|
+
static CODE = 'code';
|
|
27
|
+
|
|
28
|
+
// static WHEN_ONLINE_MOVE_TO_AGENT = "whenonlinemovetoagent"; // DEPRECATED?
|
|
29
|
+
// static WHEN_OFFLINE_HOURS = "whenofflinehours"; // DEPRECATED // adds a message on top of the original message when offline hours opts: --replace
|
|
30
|
+
//static WHEN_OFFLINE_HOURS_REPLACE_MESSAGE = "whenofflinehoursreplacemessage"; // REMOVE
|
|
31
|
+
// static DISABLE_INPUT_TEXT = "disableinputtext"; // DEPRECATED
|
|
32
|
+
// static WHEN_OPEN = "whenopen"; // DEPRECATED
|
|
33
|
+
// static WHEN_CLOSED = "whenclosed"; // DEPRECATED
|
|
34
|
+
// static IF_NO_AGENTS = "ifnoagents"; // DEPRECATED
|
|
35
|
+
// static IF_AGENTS = "ifagents"; // DEPRECATED
|
|
36
|
+
// static WHEN_NO_AVAILABLE_AGENTS = "whennoavailableagents"; // DEPRECATED
|
|
37
|
+
// static JSONMESSAGE = 'jsonmessage'; // DEPRECATED?
|
|
38
|
+
// static IF_NOT_OPEN_HOURS = "ifnotopenhours"; // DEPRECATED
|
|
39
|
+
// static CONDITION = "condition"; // DEPRECATED
|
|
41
40
|
|
|
42
41
|
static actionToDirective(action) {
|
|
43
42
|
// console.log("actionToDirective:", action);
|
|
File without changes
|