@tiledesk/tiledesk-tybot-connector 2.5.0 → 2.6.0
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 +1 -52
- package/ExtUtil.js +1 -0
- package/TdCache copy.js +242 -0
- package/TiledeskExpression.js +1 -6
- package/TiledeskWhenExpression.js +1 -18
- package/engine/MongodbBotsDataSource.js +1 -3
- package/engine/MongodbIntentsMachine.js +2 -3
- package/engine/TiledeskChatbot.js +4 -76
- package/engine/TiledeskChatbotConst.js +1 -7
- package/engine/mock/MockBotsDataSource.js +6 -11
- package/index.js +36 -132
- package/models/faq_kb.js +0 -11
- package/package.json +1 -1
- package/services/AIController.js +1 -31
- package/services/AIService.js +33 -62
- package/services/IntegrationService.js +1 -4
- package/services/{LLMService.js → KbService.js} +3 -3
- package/services/RequestService.js +2 -23
- package/services/TilebotService.js +3 -19
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +17 -34
- package/tiledeskChatbotPlugs/directives/DirAiCondition.js +51 -18
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +52 -103
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +5 -108
- package/tiledeskChatbotPlugs/directives/DirCallSubagent.js +8 -34
- package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +11 -36
- package/tiledeskChatbotPlugs/directives/DirGptTask.js +4 -16
- package/tiledeskChatbotPlugs/directives/DirIntent.js +6 -12
- package/tiledeskChatbotPlugs/directives/DirIteration.js +10 -63
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +16 -69
- package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +2 -40
- package/tiledeskChatbotPlugs/directives/DirReply.js +6 -81
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +4 -58
- package/tiledeskChatbotPlugs/directives/DirWebRequest.js +0 -8
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +1 -11
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +418 -0
- package/tiledeskChatbotPlugs/directives/DirWebResponse.js +2 -5
- package/tiledeskChatbotPlugs/directives/Directives.js +0 -6
- package/utils/HttpUtils.js +17 -99
- package/utils/TiledeskChatbotUtil.js +5 -73
- package/utils/winston.js +2 -80
- package/services/InternalSubAgentService.js +0 -330
- package/tiledeskChatbotPlugs/directives/DirInviteHuman.js +0 -259
- package/tiledeskChatbotPlugs/directives/DirInvokeSubAgent.js +0 -345
- package/tiledeskChatbotPlugs/directives/DirJSONConditionMulti.js +0 -171
- package/tiledeskChatbotPlugs/directives/DirRemoveHuman.js +0 -129
- package/tiledeskChatbotPlugs/directives/DirReturn.js +0 -98
- package/utils/ConnectorsV3.js +0 -292
- package/utils/LlmStream.js +0 -215
- package/utils/SentenceChunker.js +0 -94
- package/utils/StreamSender.js +0 -109
package/CHANGELOG.md
CHANGED
|
@@ -6,30 +6,9 @@ available on:
|
|
|
6
6
|
▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
#
|
|
10
|
-
- changed: V3 agents — `ds_version` and `connectors` are fields of the bot (server 2.30.0): the model knows them, the data sources load the connectors list and hand both over; agents without the label are untouched
|
|
11
|
-
|
|
12
|
-
# features-2610/connectors-v3 14/10/2026
|
|
13
|
-
- changed: V3 agents — the connectors list adds and replaces destinations, never removes them: an exit without a record keeps what the block carries, an empty list changes nothing, a missing block descriptor is rebuilt from the block record
|
|
14
|
-
- added: V3 agents — Iteration runs the "when the list is done" block after the last item or at once with an empty list; agents without the label go on from the block's exit as before
|
|
15
|
-
- fixed: block jumps use the endpoint given at start-up (environment as fallback); AI Condition's vLLM error path no longer crashes and goes to the error block
|
|
16
|
-
|
|
17
|
-
# 2.2.1-rc16
|
|
18
|
-
- added: V3 agents — reply buttons (reply, replyv2, random reply, voice) are filled from the bot connectors list before the reply is sent: `button.action` gets `#id` plus the record params, so the agent JSON may carry buttons without `action`; a button with no record becomes a text button; bots without the V3 label or without the list are untouched
|
|
19
|
-
|
|
20
|
-
# 2.2.1-rc15
|
|
21
|
-
- added: V3 agents (`attributes.dsVersion = 'v3'`) with a connectors list in the bot attributes are routed from that list: before a block runs, every exit (block dot, true/false, cases, branches, noInput/noMatch, go-to) is resolved from the list, so the action fields may be empty on the server; reply buttons are unchanged. Bots without the version label or without the list run exactly as before
|
|
22
|
-
|
|
23
|
-
# 2.2.1-rc12
|
|
24
|
-
- fixed: Iteration — an empty, missing or unreadable list, a missing "Go to block" or an error on an element no longer stop the conversation: the flow goes on from the block's exit, as when the list is done
|
|
25
|
-
- fixed: Iteration — a loop left unfinished is not resumed by a later run on a different list: it starts over
|
|
26
|
-
|
|
27
|
-
# 2.2.0-rc22
|
|
9
|
+
# this branch
|
|
28
10
|
- added: Web Request V2 — support for `bodyType: 'raw'` with `rawType` `'text' | 'javascript' | 'json' | 'html' | 'xml'` (raw string body sent verbatim with the Content-Type set in headers; `'json'` keeps the legacy parse/falseIntent semantics); existing `'json'`, `'form-data'` and `'none'` body types unchanged
|
|
29
11
|
|
|
30
|
-
# 2.2.0-rc9
|
|
31
|
-
- added: JSON Condition V2 runtime — new `jsoncondition2` type routed to `DirJSONConditionV2` (evaluates the `when` expression via `TiledeskWhenExpression`, no eval/vm2); V1 `jsoncondition` dispatch left unchanged (`DirJSONCondition`) for full backward-compatibility
|
|
32
|
-
|
|
33
12
|
# 2.1.0
|
|
34
13
|
- added: support to analytics
|
|
35
14
|
|
|
@@ -47,9 +26,6 @@ available on:
|
|
|
47
26
|
|
|
48
27
|
# 2.0.26
|
|
49
28
|
|
|
50
|
-
# 2.0.26-rc1
|
|
51
|
-
- added: check and skip private message from internal-notes
|
|
52
|
-
|
|
53
29
|
# 2.0.9
|
|
54
30
|
|
|
55
31
|
# 2.0.9-rc1
|
|
@@ -65,8 +41,6 @@ available on:
|
|
|
65
41
|
|
|
66
42
|
# v0.5.0
|
|
67
43
|
- added: AI_ENDPOINT env var
|
|
68
|
-
|
|
69
|
-
# v0.5.0-rc1
|
|
70
44
|
- added: ability to get 'none' as bodytype in webresponse
|
|
71
45
|
|
|
72
46
|
# v0.4.2
|
|
@@ -81,19 +55,6 @@ available on:
|
|
|
81
55
|
- changed: refactoring of DIrWebRequestv2
|
|
82
56
|
- bug-fixed: erro while parsing webrequestv2 body
|
|
83
57
|
|
|
84
|
-
# v0.3.5-rc4
|
|
85
|
-
- added: webhook action (same as intent one)
|
|
86
|
-
|
|
87
|
-
# v0.3.5-rc3
|
|
88
|
-
- bug-fixed: jsonBody parse error in web-request-v2
|
|
89
|
-
|
|
90
|
-
# v0.3.5-rc2
|
|
91
|
-
- bug-fixed: cannot set status of undefined reading res.status in DirAssistant
|
|
92
|
-
|
|
93
|
-
# v0.3.5-rc1
|
|
94
|
-
- changed: refactoring web-request-v2
|
|
95
|
-
- bug-fixed: jsonBody parse error in web-request-v2
|
|
96
|
-
|
|
97
58
|
# v0.3.4
|
|
98
59
|
-bug-fixed: slit is undefined in TiledeskChatbotUtils
|
|
99
60
|
|
|
@@ -103,18 +64,6 @@ available on:
|
|
|
103
64
|
# v0.3.2
|
|
104
65
|
- bug-fixed: minor improvement
|
|
105
66
|
|
|
106
|
-
# v0.2.153-rc9
|
|
107
|
-
- changed: updated tiledesk-multi-worker to 0.2.1-rc2
|
|
108
|
-
|
|
109
|
-
# v0.2.153-rc8
|
|
110
|
-
- added: fixToken function in TiledeskService utils class
|
|
111
|
-
|
|
112
|
-
# v0.2.153-rc4
|
|
113
|
-
- log added
|
|
114
|
-
|
|
115
|
-
# v0.2.153-rc3
|
|
116
|
-
- added: specchToText function to transcript audio file
|
|
117
|
-
|
|
118
67
|
# v0.2.153-rc1
|
|
119
68
|
- changed: context for gpt-40 and gpt-40-mini
|
|
120
69
|
|
package/ExtUtil.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// DEV
|
|
2
2
|
const { MessagePipeline } = require('./tiledeskChatbotPlugs/MessagePipeline');
|
|
3
|
+
const { DirectivesChatbotPlug } = require('./tiledeskChatbotPlugs/DirectivesChatbotPlug');
|
|
3
4
|
const { SplitsChatbotPlug } = require('./tiledeskChatbotPlugs/SplitsChatbotPlug');
|
|
4
5
|
const { MarkbotChatbotPlug } = require('./tiledeskChatbotPlugs/MarkbotChatbotPlug');
|
|
5
6
|
const { FillParamsChatbotPlug } = require('./tiledeskChatbotPlugs/FillParamsChatbotPlug');
|
package/TdCache copy.js
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
const redis = require('redis');
|
|
2
|
+
|
|
3
|
+
class TdCache {
|
|
4
|
+
|
|
5
|
+
constructor(config) {
|
|
6
|
+
this.redis_host = config.host;
|
|
7
|
+
this.redis_port = config.port;
|
|
8
|
+
this.redis_password = config.password;
|
|
9
|
+
this.client = null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async connect(callback) {
|
|
13
|
+
// client = redis.createClient();
|
|
14
|
+
return new Promise( async (resolve, reject) => {
|
|
15
|
+
this.client = redis.createClient(
|
|
16
|
+
{
|
|
17
|
+
host: this.redis_host,
|
|
18
|
+
port: this.redis_port,
|
|
19
|
+
password: this.redis_password
|
|
20
|
+
});
|
|
21
|
+
this.client.on('error', err => {
|
|
22
|
+
reject(err);
|
|
23
|
+
if (callback) {
|
|
24
|
+
callback(err);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
// this.client.on('connect', function() {
|
|
28
|
+
// console.log('Redis Connected!');
|
|
29
|
+
// });
|
|
30
|
+
this.client.on('ready',function() {
|
|
31
|
+
console.log("connected")
|
|
32
|
+
resolve();
|
|
33
|
+
if (callback) {
|
|
34
|
+
callback();
|
|
35
|
+
}
|
|
36
|
+
//console.log("Redis is ready.");
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async set(key, value, options) {
|
|
42
|
+
//console.log("setting key value", key, value)
|
|
43
|
+
if (!options) {
|
|
44
|
+
options = {EX: 86400}
|
|
45
|
+
}
|
|
46
|
+
return new Promise( async (resolve, reject) => {
|
|
47
|
+
if (options && options.EX) {
|
|
48
|
+
//console.log("expires:", options.EX)
|
|
49
|
+
try {
|
|
50
|
+
await this.client.set(
|
|
51
|
+
key,
|
|
52
|
+
value,
|
|
53
|
+
'EX', options.EX);
|
|
54
|
+
}
|
|
55
|
+
catch(error) {
|
|
56
|
+
reject(error)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
try {
|
|
61
|
+
//console.log("setting here...key", key, value)
|
|
62
|
+
await this.client.set(
|
|
63
|
+
key,
|
|
64
|
+
value);
|
|
65
|
+
}
|
|
66
|
+
catch(error) {
|
|
67
|
+
console.error("Error", error);
|
|
68
|
+
reject(error)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (options && options.callback) {
|
|
72
|
+
options.callback();
|
|
73
|
+
}
|
|
74
|
+
//console.log("resolving...", key);
|
|
75
|
+
return resolve();
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async incr(key) {
|
|
80
|
+
// console.log("incr key:", key)
|
|
81
|
+
return new Promise( async (resolve, reject) => {
|
|
82
|
+
try {
|
|
83
|
+
// console.log("incr here...key", key)
|
|
84
|
+
await this.client.incr(key);
|
|
85
|
+
}
|
|
86
|
+
catch(error) {
|
|
87
|
+
console.error("Error on incr:", error);
|
|
88
|
+
reject(error)
|
|
89
|
+
}
|
|
90
|
+
return resolve();
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async hset(dict_key, key, value, options) {
|
|
95
|
+
//console.log("hsetting dict_key key value", dict_key, key, value)
|
|
96
|
+
return new Promise( async (resolve, reject) => {
|
|
97
|
+
if (options && options.EX) {
|
|
98
|
+
//console.log("expires:", options.EX)
|
|
99
|
+
try {
|
|
100
|
+
await this.client.hset(
|
|
101
|
+
dict_key,
|
|
102
|
+
key,
|
|
103
|
+
value,
|
|
104
|
+
'EX', options.EX);
|
|
105
|
+
}
|
|
106
|
+
catch(error) {
|
|
107
|
+
reject(error)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
try {
|
|
112
|
+
//console.log("setting here...key", key, value)
|
|
113
|
+
await this.client.hset(
|
|
114
|
+
dict_key,
|
|
115
|
+
key,
|
|
116
|
+
value);
|
|
117
|
+
}
|
|
118
|
+
catch(error) {
|
|
119
|
+
console.error("Error", error);
|
|
120
|
+
reject(error)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (options && options.callback) {
|
|
124
|
+
options.callback();
|
|
125
|
+
}
|
|
126
|
+
return resolve();
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async hdel(dict_key, key, options) {
|
|
131
|
+
//console.log("hsetting dict_key key value", dict_key, key, value)
|
|
132
|
+
return new Promise( async (resolve, reject) => {
|
|
133
|
+
if (options && options.EX) {
|
|
134
|
+
//console.log("expires:", options.EX)
|
|
135
|
+
try {
|
|
136
|
+
await this.client.hdel(
|
|
137
|
+
dict_key,
|
|
138
|
+
key,
|
|
139
|
+
'EX', options.EX);
|
|
140
|
+
}
|
|
141
|
+
catch(error) {
|
|
142
|
+
reject(error)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
try {
|
|
147
|
+
//console.log("setting here...key", key, value)
|
|
148
|
+
await this.client.hdel(
|
|
149
|
+
dict_key,
|
|
150
|
+
key);
|
|
151
|
+
}
|
|
152
|
+
catch(error) {
|
|
153
|
+
console.error("Error", error);
|
|
154
|
+
reject(error);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (options && options.callback) {
|
|
158
|
+
options.callback();
|
|
159
|
+
}
|
|
160
|
+
return resolve();
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async setJSON(key, value, options) {
|
|
165
|
+
const _string = JSON.stringify(value);
|
|
166
|
+
return await this.set(key, _string, options);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async get(key, callback) {
|
|
170
|
+
//console.log("getting key", key)
|
|
171
|
+
return new Promise( async (resolve, reject) => {
|
|
172
|
+
this.client.get(key, (err, value) => {
|
|
173
|
+
if (err) {
|
|
174
|
+
reject(err);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
if (callback) {
|
|
178
|
+
callback(value);
|
|
179
|
+
}
|
|
180
|
+
return resolve(value);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async hgetall(dict_key, callback) {
|
|
187
|
+
//console.log("hgetting dics", dict_key);
|
|
188
|
+
return new Promise( async (resolve, reject) => {
|
|
189
|
+
this.client.hgetall(dict_key, (err, value) => {
|
|
190
|
+
if (err) {
|
|
191
|
+
reject(err);
|
|
192
|
+
if (callback) {
|
|
193
|
+
callback(err, null);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
if (callback) {
|
|
198
|
+
callback(null, value);
|
|
199
|
+
}
|
|
200
|
+
resolve(value);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
async hget(dict_key, key, callback) {
|
|
207
|
+
//console.log("hgetting dics", dict_key);
|
|
208
|
+
return new Promise( async (resolve, reject) => {
|
|
209
|
+
this.client.hget(dict_key, key, (err, value) => {
|
|
210
|
+
if (err) {
|
|
211
|
+
reject(err);
|
|
212
|
+
if (callback) {
|
|
213
|
+
callback(err, null);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
if (callback) {
|
|
218
|
+
callback(null, value);
|
|
219
|
+
}
|
|
220
|
+
resolve(value);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async getJSON(key, callback) {
|
|
227
|
+
const value = await this.get(key);
|
|
228
|
+
return JSON.parse(value);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
async del(key, callback) {
|
|
232
|
+
return new Promise( async (resolve, reject) => {
|
|
233
|
+
await this.client.del(key);
|
|
234
|
+
if (callback) {
|
|
235
|
+
callback();
|
|
236
|
+
}
|
|
237
|
+
return resolve();
|
|
238
|
+
})
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
module.exports = { TdCache };
|
package/TiledeskExpression.js
CHANGED
|
@@ -140,12 +140,7 @@ class TiledeskExpression {
|
|
|
140
140
|
},
|
|
141
141
|
"endsWith": {
|
|
142
142
|
name: "endsWith",
|
|
143
|
-
|
|
144
|
-
// both sides, so "ends with" quietly ignored case while its neighbours did
|
|
145
|
-
// not, and nothing on the screen said so. A condition that wants case
|
|
146
|
-
// ignored asks for it explicitly -- the Design Studio wraps both operands
|
|
147
|
-
// in lowerCase() -- rather than getting it from one operator by accident.
|
|
148
|
-
applyPattern: "String(#1).endsWith(String(#2))"
|
|
143
|
+
applyPattern: "#1?.toLowerCase().endsWith(#2.toLowerCase())"
|
|
149
144
|
},
|
|
150
145
|
"isEmpty": {
|
|
151
146
|
name: "isEmpty",
|
|
@@ -388,11 +388,6 @@ const DEFAULT_FUNCTIONS = {
|
|
|
388
388
|
},
|
|
389
389
|
isNull: (a) => a === null,
|
|
390
390
|
isUndefined: (a) => a === undefined,
|
|
391
|
-
// exists: has a value at all. Deliberately stricter than !isUndefined, which the design
|
|
392
|
-
// studio used to send for this: a variable explicitly set to null holds no value, and saying
|
|
393
|
-
// it exists made "exists" and "is null" both true on it. `isNull` and `isUndefined` are still
|
|
394
|
-
// there for whoever needs to tell the two apart.
|
|
395
|
-
exists: (a) => a !== null && a !== undefined,
|
|
396
391
|
|
|
397
392
|
// --- Date / time (ISO-8601; any invalid/missing date -> false) ---------
|
|
398
393
|
dateEqual: (a, b) => { const x = parseDate(a), y = parseDate(b); return !!(x && y) && x.getTime() === y.getTime(); },
|
|
@@ -413,21 +408,9 @@ const DEFAULT_FUNCTIONS = {
|
|
|
413
408
|
return arr.some((el) => String(el) === String(b));
|
|
414
409
|
},
|
|
415
410
|
// length: array element count, or string character length, otherwise 0.
|
|
416
|
-
//
|
|
417
|
-
// A list reaching a flow -- from a web request, a data table, a knowledge base -- is held in a
|
|
418
|
-
// variable as JSON text, so the array branch above was almost never the one taken and
|
|
419
|
-
// `["a","b"]` counted as nine characters rather than two items. `arrayContains` reads that
|
|
420
|
-
// same value as a list; leaving `length` reading it as text meant one operator saw a list and
|
|
421
|
-
// its neighbour in the very same "Array" group saw a string.
|
|
422
|
-
//
|
|
423
|
-
// Text that merely looks like a list is now measured in items, which is the reading every
|
|
424
|
-
// caller asks for: `length()` is emitted only by the length operators of that group.
|
|
425
411
|
length: (a) => {
|
|
426
412
|
if (Array.isArray(a)) return a.length;
|
|
427
|
-
if (typeof a === 'string')
|
|
428
|
-
try { const parsed = JSON.parse(a); if (Array.isArray(parsed)) return parsed.length; } catch (e) { /* not a JSON array */ }
|
|
429
|
-
return a.length;
|
|
430
|
-
}
|
|
413
|
+
if (typeof a === 'string') return a.length;
|
|
431
414
|
return 0;
|
|
432
415
|
},
|
|
433
416
|
|
|
@@ -12,8 +12,7 @@ class MongodbBotsDataSource {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
async getBotById(botId) {
|
|
15
|
-
|
|
16
|
-
const bot = await Faq_kb.findById(botId).select('+secret +connectors').exec();
|
|
15
|
+
const bot = await Faq_kb.findById(botId).select('+secret').exec();
|
|
17
16
|
if (bot) {
|
|
18
17
|
return bot;
|
|
19
18
|
}
|
|
@@ -38,7 +37,6 @@ class MongodbBotsDataSource {
|
|
|
38
37
|
bot = await this.getBotById(botId);
|
|
39
38
|
winston.debug("(MongodbBotsDataSource) bot found in datasource: ", bot);
|
|
40
39
|
await tdcache.set(botCacheKey, JSON.stringify(bot));
|
|
41
|
-
|
|
42
40
|
// DEBUG CODE REMOVE
|
|
43
41
|
// let bot_ = await tdcache.get(botCacheKey);
|
|
44
42
|
}
|
|
@@ -32,11 +32,10 @@ class MongodbIntentsMachine {
|
|
|
32
32
|
}
|
|
33
33
|
query.$text = search_obj;
|
|
34
34
|
mongoproject = { score: { $meta: "textScore" } };
|
|
35
|
-
sort = { score: { $meta: "textScore" } }
|
|
36
|
-
winston.debug("(MongodbIntentsMachine) query: " + JSON.stringify(query, null, 2));
|
|
35
|
+
sort = { score: { $meta: "textScore" } }
|
|
37
36
|
// DA QUI RECUPERO LA RISPOSTA DATO (ID: SE EXT_AI) (QUERY FULLTEXT SE NATIVE-BASIC-AI)
|
|
38
37
|
Faq.find(query, mongoproject).sort(sort).lean().exec( (err, faqs) => {
|
|
39
|
-
winston.debug("(MongodbIntentsMachine) Found: "
|
|
38
|
+
winston.debug("(MongodbIntentsMachine) Found: ", faqs);
|
|
40
39
|
if (err) {
|
|
41
40
|
winston.error("(MongodbIntentsMachine) Error:", err);
|
|
42
41
|
}
|
|
@@ -5,7 +5,6 @@ const { WebhookChatbotPlug } = require('../tiledeskChatbotPlugs/WebhookChatbotPl
|
|
|
5
5
|
const { TiledeskClient } = require('@tiledesk/tiledesk-client');
|
|
6
6
|
const { IntentForm } = require('./IntentForm.js');
|
|
7
7
|
const { TiledeskChatbotUtil } = require('../utils/TiledeskChatbotUtil.js');
|
|
8
|
-
const { ConnectorsV3 } = require('../utils/ConnectorsV3');
|
|
9
8
|
const { DirLockIntent } = require('../tiledeskChatbotPlugs/directives/DirLockIntent');
|
|
10
9
|
const { DirUnlockIntent } = require('../tiledeskChatbotPlugs/directives/DirUnlockIntent');
|
|
11
10
|
const winston = require('../utils/winston');
|
|
@@ -180,28 +179,6 @@ class TiledeskChatbot {
|
|
|
180
179
|
return;
|
|
181
180
|
}
|
|
182
181
|
}
|
|
183
|
-
else if (message.text === '/start' && intent.name !== 'start') {
|
|
184
|
-
// A /start naming a missing start box falls back to the default start block
|
|
185
|
-
winston.warn("(TiledeskChatbot) Start box not found: " + explicit_intent_name + ", falling back to start");
|
|
186
|
-
const startFaq = await this.botsDataSource.getByIntentDisplayNameCache(this.botId, 'start', this.tdcache);
|
|
187
|
-
if (startFaq) {
|
|
188
|
-
try {
|
|
189
|
-
reply = await this.execIntent(startFaq, message, lead, { match_type: 'explicit' });
|
|
190
|
-
resolve(reply);
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
catch(error) {
|
|
194
|
-
winston.error("(TiledeskChatbot) Error executing start fallback: ", error);
|
|
195
|
-
reject(error);
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
winston.verbose("(TiledeskChatbot) Start box not found either");
|
|
201
|
-
resolve();
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
182
|
else {
|
|
206
183
|
winston.info("(TiledeskChatbot) explicit intent not found, stop " + JSON.stringify({
|
|
207
184
|
botId: this.botId,
|
|
@@ -220,7 +197,7 @@ class TiledeskChatbot {
|
|
|
220
197
|
let faqs;
|
|
221
198
|
try {
|
|
222
199
|
faqs = await this.botsDataSource.getByExactMatch(this.botId, message.text);
|
|
223
|
-
winston.verbose("(TiledeskChatbot) Got faq by exact match: " +
|
|
200
|
+
winston.verbose("(TiledeskChatbot) Got faq by exact match: " + faqs);
|
|
224
201
|
}
|
|
225
202
|
catch (error) {
|
|
226
203
|
winston.error("(TiledeskChatbot) An error occurred during exact match: ", error);
|
|
@@ -245,7 +222,7 @@ class TiledeskChatbot {
|
|
|
245
222
|
let intents;
|
|
246
223
|
try {
|
|
247
224
|
intents = await this.intentsFinder.decode(this.botId, message.text);
|
|
248
|
-
winston.verbose("(TiledeskChatbot) Tiledesk AI intents found:"
|
|
225
|
+
winston.verbose("(TiledeskChatbot) Tiledesk AI intents found:", intents);
|
|
249
226
|
}
|
|
250
227
|
catch(error) {
|
|
251
228
|
winston.error("(TiledeskChatbot) An error occurred on IntentsFinder.decode() (/model/parse error):" + error.message);
|
|
@@ -256,7 +233,7 @@ class TiledeskChatbot {
|
|
|
256
233
|
winston.debug("(TiledeskChatbot) Got intents from backup finder: ", intents);
|
|
257
234
|
}
|
|
258
235
|
}
|
|
259
|
-
winston.debug("(TiledeskChatbot) NLP intents found: "
|
|
236
|
+
winston.debug("(TiledeskChatbot) NLP intents found: ", intents);
|
|
260
237
|
if (intents && intents.length > 0) {
|
|
261
238
|
let faq = await this.botsDataSource.getByIntentDisplayNameCache(this.botId, intents[0].intent_display_name, this.tdcache);
|
|
262
239
|
let reply;
|
|
@@ -336,8 +313,6 @@ class TiledeskChatbot {
|
|
|
336
313
|
|
|
337
314
|
if (faq) {
|
|
338
315
|
if (faq.actions) {
|
|
339
|
-
// Agente V3: le destinazioni del blocco si leggono dalla lista dei connettori del bot (ConnectorsV3).
|
|
340
|
-
ConnectorsV3.projectIntent(this.bot, faq);
|
|
341
316
|
// Qui viene aggiornata faq perchè l'oggetto in js viene passato per riferimento. Viene modificato l'oggetto originale anche senza un return.
|
|
342
317
|
TiledeskChatbotUtil.addConnectAction(faq);
|
|
343
318
|
}
|
|
@@ -459,8 +434,6 @@ class TiledeskChatbot {
|
|
|
459
434
|
let static_bot_answer;
|
|
460
435
|
if (answerObj.actions) {
|
|
461
436
|
const actions_length = answerObj.actions.length;
|
|
462
|
-
// Agente V3: le destinazioni del blocco si leggono dalla lista dei connettori del bot (ConnectorsV3).
|
|
463
|
-
ConnectorsV3.projectIntent(this.bot, answerObj);
|
|
464
437
|
TiledeskChatbotUtil.addConnectAction(answerObj);
|
|
465
438
|
}
|
|
466
439
|
|
|
@@ -650,7 +623,7 @@ class TiledeskChatbot {
|
|
|
650
623
|
let _current_step = await _tdcache.get(parameter_key);
|
|
651
624
|
let current_step = Number(_current_step);
|
|
652
625
|
if (current_step > max_steps) {
|
|
653
|
-
winston.verbose("(TiledeskChatbot)
|
|
626
|
+
winston.verbose("(TiledeskChatbot) max_steps limit just violated");
|
|
654
627
|
winston.verbose("(TiledeskChatbot) Current Step > Max Steps: " + current_step);
|
|
655
628
|
return {
|
|
656
629
|
error: "Anomaly detection. MAX ACTIONS (" + max_steps + ") exeeded.",
|
|
@@ -708,51 +681,6 @@ class TiledeskChatbot {
|
|
|
708
681
|
const request_key = "tilebot:requests:" + requestId;
|
|
709
682
|
return request_key;
|
|
710
683
|
}
|
|
711
|
-
|
|
712
|
-
// Streaming channels (voice): "latest message wins". Each caller message starts a turn; a turn whose id is no
|
|
713
|
-
// longer the stored one has been superseded and must stop (directives, LLM streaming).
|
|
714
|
-
static turnCacheKey(requestId) {
|
|
715
|
-
return TiledeskChatbot.requestCacheKey(requestId) + ":turn";
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
static async setCurrentTurn(_tdcache, requestId, turnId) {
|
|
719
|
-
await _tdcache.set(TiledeskChatbot.turnCacheKey(requestId), turnId, { EX: 3600 });
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
static async isTurnSuperseded(_tdcache, requestId, turnId) {
|
|
723
|
-
if (!_tdcache || !turnId) {
|
|
724
|
-
return false;
|
|
725
|
-
}
|
|
726
|
-
const current = await _tdcache.get(TiledeskChatbot.turnCacheKey(requestId));
|
|
727
|
-
return current !== null && current !== undefined && current !== turnId;
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
// Text streamed by an AI action and not yet closed by a reply message (see DirAiPrompt, DirReply)
|
|
731
|
-
static pendingStreamCacheKey(requestId) {
|
|
732
|
-
return TiledeskChatbot.requestCacheKey(requestId) + ":stream:pending";
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
static isStreamingChannel(channelName) {
|
|
736
|
-
if (process.env.STREAM_ENABLED !== "true" || !channelName) {
|
|
737
|
-
return false;
|
|
738
|
-
}
|
|
739
|
-
const channels = (process.env.STREAM_CHANNELS || "voice_twilio").split(",").map(c => c.trim());
|
|
740
|
-
return channels.includes(channelName);
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
/**
|
|
744
|
-
* The caller's message belongs to a call the voice connector speaks with ConversationRelay: streaming channel AND
|
|
745
|
-
* the request attribute voice_stream (set by the connector on /start, the request's first message), or the previous
|
|
746
|
-
* per-message marker voice_relay (accepted for this release). Gather calls carry neither: unchanged behaviour.
|
|
747
|
-
*/
|
|
748
|
-
static isVoiceStreamMessage(message) {
|
|
749
|
-
if (!message || !message.request || !TiledeskChatbot.isStreamingChannel(message.request.channel && message.request.channel.name)) {
|
|
750
|
-
return false;
|
|
751
|
-
}
|
|
752
|
-
const requestAttributes = message.request.attributes || {};
|
|
753
|
-
const attributes = message.attributes || {};
|
|
754
|
-
return requestAttributes.voice_stream === true || attributes.voice_relay === true;
|
|
755
|
-
}
|
|
756
684
|
|
|
757
685
|
async execWebhook(static_bot_answer, userMessage, bot, context) {
|
|
758
686
|
winston.verbose("(TiledeskChatbot) static_bot_answer.attributes.webhook:" + static_bot_answer.attributes.webhook);
|
|
@@ -42,21 +42,15 @@ class TiledeskChatbotConst {
|
|
|
42
42
|
static REQ_LAST_USER_DOCUMENT_URL = 'lastUserDocumentURL';
|
|
43
43
|
static REQ_LAST_USER_DOCUMENT_NAME = 'lastUserDocumentName';
|
|
44
44
|
static REQ_LAST_USER_DOCUMENT_TYPE = 'lastUserDocumentType';
|
|
45
|
+
static REQ_EMAIL_ATTACHMENTS_LINK = 'link';
|
|
45
46
|
static REQ_EMAIL_SUBJECT = 'email_subject';
|
|
46
47
|
static REQ_EMAIL_TO = 'email_toEmail';
|
|
47
48
|
static REQ_EMAIL_FROM = 'email_fromEmail';
|
|
48
49
|
static REQ_EMAIL_MESSAGE_ID = 'email_messageId';
|
|
49
50
|
static REQ_EMAIL_REPLY_TO = 'email_replyTo';
|
|
50
51
|
static REQ_EMAIL_EML = 'email_eml';
|
|
51
|
-
static REQ_EMAIL_ATTACHMENTS_LINK = 'link';
|
|
52
52
|
static REQ_EMAIL_ATTACHMENTS_FILES = 'attachments'
|
|
53
53
|
static REQ_VOICE_STREAMING = 'voice_mode'
|
|
54
|
-
|
|
55
|
-
/** Set by DirWebResponse after publish; DirInvokeSubAgent waits via poll + pub/sub. */
|
|
56
|
-
static redisWebhookReadyKey(requestId) {
|
|
57
|
-
return `tilebot:webhook_ready:${requestId}`;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
54
|
}
|
|
61
55
|
|
|
62
56
|
module.exports = { TiledeskChatbotConst };
|
|
@@ -14,23 +14,18 @@ class MockBotsDataSource {
|
|
|
14
14
|
async getBotById(botId) {
|
|
15
15
|
return new Promise((resolve, reject)=>{
|
|
16
16
|
try{
|
|
17
|
-
const source = this.data.bots[botId];
|
|
18
17
|
const bot = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
name: source.name,
|
|
24
|
-
attributes: source.attributes
|
|
18
|
+
webhook_enabled: this.data.bots[botId].webhook_enabled,
|
|
19
|
+
webhook_url: this.data.bots[botId].webhook_url,
|
|
20
|
+
language: this.data.bots[botId].language,
|
|
21
|
+
name: this.data.bots[botId].name
|
|
25
22
|
}
|
|
26
|
-
// V3 agents: the version label and the connectors list are fields of the bot.
|
|
27
|
-
if (source.ds_version !== undefined) { bot.ds_version = source.ds_version; }
|
|
28
|
-
if (source.connectors !== undefined) { bot.connectors = source.connectors; }
|
|
29
23
|
resolve(bot)
|
|
30
24
|
}catch(err){
|
|
31
25
|
reject(err);
|
|
32
26
|
}
|
|
33
|
-
|
|
27
|
+
|
|
28
|
+
})
|
|
34
29
|
}
|
|
35
30
|
|
|
36
31
|
async getBotByIdCache(botId, tdcache) {
|