@tiledesk/tiledesk-tybot-connector 0.2.47 → 0.2.48
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,10 @@
|
|
|
5
5
|
available on:
|
|
6
6
|
▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
|
|
7
7
|
|
|
8
|
+
# v0.2.48
|
|
9
|
+
- resplacebotv2
|
|
10
|
+
- fixed jsoncondition expression. added ? in some "static OPERATORS" (i.e. contains) to correctly evaluate undefined operands
|
|
11
|
+
|
|
8
12
|
# v0.2.47
|
|
9
13
|
- added isNull isUndefined conditions
|
|
10
14
|
|
package/TiledeskExpression.js
CHANGED
|
@@ -131,15 +131,15 @@ class TiledeskExpression {
|
|
|
131
131
|
},
|
|
132
132
|
"contains": {
|
|
133
133
|
name: "contains",
|
|
134
|
-
applyPattern: "#1
|
|
134
|
+
applyPattern: "#1?.includes(#2)"
|
|
135
135
|
},
|
|
136
136
|
"containsIgnoreCase": {
|
|
137
137
|
name: "containsIgnoreCase",
|
|
138
|
-
applyPattern: "#1
|
|
138
|
+
applyPattern: "#1?.toLowerCase().includes(#2.toLowerCase())"
|
|
139
139
|
},
|
|
140
140
|
"endsWith": {
|
|
141
141
|
name: "endsWith",
|
|
142
|
-
applyPattern: "#1
|
|
142
|
+
applyPattern: "#1?.toLowerCase().endsWith(#2.toLowerCase())"
|
|
143
143
|
},
|
|
144
144
|
"isEmpty": {
|
|
145
145
|
name: "isEmpty",
|
|
@@ -155,7 +155,7 @@ class TiledeskExpression {
|
|
|
155
155
|
},
|
|
156
156
|
"matches": {
|
|
157
157
|
name: "matches",
|
|
158
|
-
applyPattern: "#1
|
|
158
|
+
applyPattern: "#1?.match(String(#2)) ? true : false"
|
|
159
159
|
},
|
|
160
160
|
// Francesco
|
|
161
161
|
"addAsNumber": {
|
package/package.json
CHANGED
|
@@ -41,6 +41,7 @@ const { DirGptTask } = require('./directives/DirGptTask');
|
|
|
41
41
|
const { DirForm } = require('./directives/DirForm');
|
|
42
42
|
const { DirCaptureUserReply } = require('./directives/DirCaptureUserReply');
|
|
43
43
|
const { DirMake } = require('./directives/DirMake');
|
|
44
|
+
const { DirReplaceBotV2 } = require('./directives/DirReplaceBotV2');
|
|
44
45
|
|
|
45
46
|
class DirectivesChatbotPlug {
|
|
46
47
|
|
|
@@ -485,6 +486,12 @@ class DirectivesChatbotPlug {
|
|
|
485
486
|
this.process(next_dir);
|
|
486
487
|
});
|
|
487
488
|
}
|
|
489
|
+
else if (directive_name === Directives.REPLACE_BOT_V2) {
|
|
490
|
+
new DirReplaceBotV2(context).execute(directive, async () => {
|
|
491
|
+
let next_dir = await this.nextDirective(this.directives);
|
|
492
|
+
this.process(next_dir);
|
|
493
|
+
});
|
|
494
|
+
}
|
|
488
495
|
else if (directive_name === Directives.WAIT) {
|
|
489
496
|
// console.log("........ DirWait");
|
|
490
497
|
new DirWait(context).execute(directive, async () => {
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const { TiledeskChatbot } = require('../../models/TiledeskChatbot');
|
|
2
|
+
const { Filler } = require('../Filler');
|
|
3
|
+
|
|
4
|
+
class DirReplaceBotV2 {
|
|
5
|
+
|
|
6
|
+
constructor(context) {
|
|
7
|
+
if (!context) {
|
|
8
|
+
throw new Error('context object is mandatory.');
|
|
9
|
+
}
|
|
10
|
+
this.context = context;
|
|
11
|
+
this.tdclient = context.tdclient;
|
|
12
|
+
this.requestId = context.requestId;
|
|
13
|
+
this.log = context.log;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
execute(directive, callback) {
|
|
17
|
+
if (this.log) {console.log("Replacing bot");}
|
|
18
|
+
let action;
|
|
19
|
+
if (directive.action) {
|
|
20
|
+
action = directive.action;
|
|
21
|
+
}
|
|
22
|
+
else if (directive.parameter) {
|
|
23
|
+
let botName = directive.parameter.trim();
|
|
24
|
+
action = {
|
|
25
|
+
botName: botName
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
callback();
|
|
30
|
+
}
|
|
31
|
+
this.go(action, () => {
|
|
32
|
+
callback();
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async go(action, callback) {
|
|
37
|
+
let botName = action.botName;
|
|
38
|
+
let blockName = action.blockName;
|
|
39
|
+
let variables = null;
|
|
40
|
+
variables =
|
|
41
|
+
await TiledeskChatbot.allParametersStatic(
|
|
42
|
+
this.context.tdcache, this.context.requestId
|
|
43
|
+
);
|
|
44
|
+
const filler = new Filler();
|
|
45
|
+
botName = filler.fill(botName, variables);
|
|
46
|
+
this.tdclient.replaceBotByName(this.requestId, botName, () => {
|
|
47
|
+
if (blockName) {
|
|
48
|
+
if (this.log) {console.log("Sending hidden /start message to bot in dept");}
|
|
49
|
+
const message = {
|
|
50
|
+
type: "text",
|
|
51
|
+
text: blockName,
|
|
52
|
+
attributes : {
|
|
53
|
+
subtype: "info"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
this.tdclient.sendSupportMessage(
|
|
57
|
+
this.requestId,
|
|
58
|
+
message, (err) => {
|
|
59
|
+
if (err) {
|
|
60
|
+
console.error("Error sending hidden message:", err.message);
|
|
61
|
+
}
|
|
62
|
+
if (this.log) {console.log("Hidden message sent.");}
|
|
63
|
+
callback();
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
callback();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
module.exports = { DirReplaceBotV2 };
|
|
@@ -33,6 +33,7 @@ class Directives {
|
|
|
33
33
|
static CAPTURE_USER_REPLY = "capture_user_reply";
|
|
34
34
|
static QAPLA = 'qapla';
|
|
35
35
|
static MAKE = 'make';
|
|
36
|
+
static REPLACE_BOT_V2 = "replacebotv2";
|
|
36
37
|
|
|
37
38
|
// static WHEN_ONLINE_MOVE_TO_AGENT = "whenonlinemovetoagent"; // DEPRECATED?
|
|
38
39
|
// static WHEN_OFFLINE_HOURS = "whenofflinehours"; // DEPRECATED // adds a message on top of the original message when offline hours opts: --replace
|