@tiledesk/tiledesk-tybot-connector 2.1.15 → 2.2.1
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/TdCache.js +21 -1
- package/engine/TiledeskChatbot.js +10 -3
- package/index.js +23 -4
- package/logs/app1.log +681 -0
- package/package.json +1 -1
- package/services/RequestService.js +34 -0
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +4 -0
- package/tiledeskChatbotPlugs/SubagentStack.js +60 -0
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +25 -3
- package/tiledeskChatbotPlugs/directives/DirCallSubagent.js +152 -0
- package/tiledeskChatbotPlugs/directives/DirReturnStack.js +107 -0
- package/tiledeskChatbotPlugs/directives/Directives.js +2 -0
package/TdCache.js
CHANGED
|
@@ -134,7 +134,27 @@ class TdCache {
|
|
|
134
134
|
async del(key) {
|
|
135
135
|
await this.client.del(key);
|
|
136
136
|
}
|
|
137
|
-
|
|
137
|
+
|
|
138
|
+
async lPush(key, value) {
|
|
139
|
+
await this.client.LPUSH(key, value);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async lPop(key) {
|
|
143
|
+
return await this.client.LPOP(key);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async lLen(key) {
|
|
147
|
+
return await this.client.LLEN(key);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async lIndex(key, index) {
|
|
151
|
+
return await this.client.LINDEX(key, index);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async expire(key, seconds) {
|
|
155
|
+
await this.client.EXPIRE(key, seconds);
|
|
156
|
+
}
|
|
157
|
+
|
|
138
158
|
async publish(key, value) {
|
|
139
159
|
await this.client.publish(key, value);
|
|
140
160
|
}
|
|
@@ -96,7 +96,6 @@ class TiledeskChatbot {
|
|
|
96
96
|
// Checking locked intent (for non-internal intents)
|
|
97
97
|
// internal intents always "skip" the locked intent
|
|
98
98
|
const locked_intent = await this.currentLockedIntent(this.requestId);
|
|
99
|
-
winston.verbose("(TiledeskChatbot) Got locked intent: -" + locked_intent + "-");
|
|
100
99
|
if (locked_intent) {
|
|
101
100
|
// const tdclient = new TiledeskClient({
|
|
102
101
|
// projectId: this.projectId,
|
|
@@ -156,6 +155,7 @@ class TiledeskChatbot {
|
|
|
156
155
|
winston.verbose("(TiledeskChatbot) Invalid intent:", explicit_intent_name)
|
|
157
156
|
reply = { "text": "Invalid intent: *" + explicit_intent_name + "*" }
|
|
158
157
|
resolve();
|
|
158
|
+
return;
|
|
159
159
|
}
|
|
160
160
|
else {
|
|
161
161
|
winston.verbose("(TiledeskChatbot) Processing intent:", explicit_intent_name)
|
|
@@ -176,12 +176,19 @@ class TiledeskChatbot {
|
|
|
176
176
|
catch(error) {
|
|
177
177
|
winston.error("(TiledeskChatbot) Error adding parameter: ", error);
|
|
178
178
|
reject(error);
|
|
179
|
+
return;
|
|
179
180
|
}
|
|
180
181
|
}
|
|
181
182
|
else {
|
|
182
|
-
winston.
|
|
183
|
+
winston.info("(TiledeskChatbot) explicit intent not found, stop " + JSON.stringify({
|
|
184
|
+
botId: this.botId,
|
|
185
|
+
requestId: this.requestId,
|
|
186
|
+
intent: explicit_intent_name,
|
|
187
|
+
text: message.text
|
|
188
|
+
}));
|
|
183
189
|
reply = { "text": "Intent not found: " + explicit_intent_name }
|
|
184
|
-
resolve()
|
|
190
|
+
resolve();
|
|
191
|
+
return;
|
|
185
192
|
}
|
|
186
193
|
}
|
|
187
194
|
}
|
package/index.js
CHANGED
|
@@ -61,7 +61,6 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
61
61
|
const token = req.body.token;
|
|
62
62
|
const requestId = message.request.request_id;
|
|
63
63
|
const projectId = message.id_project;
|
|
64
|
-
winston.verbose("(tybotRoute) message.id_project: " + message.id_project)
|
|
65
64
|
|
|
66
65
|
// adding info for internal context workflow
|
|
67
66
|
message.request.bot_id = botId;
|
|
@@ -74,7 +73,7 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
74
73
|
winston.verbose("(tybotRoute) Skipping internal note message: " + message.text);
|
|
75
74
|
return res.status(200).send({"success":true});
|
|
76
75
|
}
|
|
77
|
-
|
|
76
|
+
|
|
78
77
|
// validate reuqestId
|
|
79
78
|
let isValid = TiledeskChatbotUtil.validateRequestId(requestId, projectId);
|
|
80
79
|
if (isValid) {
|
|
@@ -92,6 +91,11 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
92
91
|
{EX: 604800} // 7 days
|
|
93
92
|
);
|
|
94
93
|
|
|
94
|
+
if (isBotBubble(message)) {
|
|
95
|
+
winston.info("(tybotRoute) skip bot bubble " + JSON.stringify({ botId: botId, requestId: requestId, text: message.text, sender: message.sender }));
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
95
99
|
let botsDS;
|
|
96
100
|
if (!staticBots) {
|
|
97
101
|
botsDS = new MongodbBotsDataSource({projectId: projectId, botId: botId});
|
|
@@ -134,7 +138,7 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
134
138
|
MAX_EXECUTION_TIME: MAX_EXECUTION_TIME
|
|
135
139
|
});
|
|
136
140
|
winston.verbose("(tybotRoute) Message text: " + message.text)
|
|
137
|
-
|
|
141
|
+
|
|
138
142
|
try {
|
|
139
143
|
await TiledeskChatbotUtil.updateRequestAttributes(chatbot, token, message, projectId, requestId);
|
|
140
144
|
if (requestId.startsWith("support-group-")) {
|
|
@@ -144,7 +148,7 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
144
148
|
winston.error("Error on /ext updating request attributes or transcript: ", e)
|
|
145
149
|
return;
|
|
146
150
|
}
|
|
147
|
-
|
|
151
|
+
|
|
148
152
|
let reply = null;
|
|
149
153
|
try {
|
|
150
154
|
reply = await chatbot.replyToMessage(message);
|
|
@@ -810,4 +814,19 @@ function myrequest(options, callback) {
|
|
|
810
814
|
);
|
|
811
815
|
}
|
|
812
816
|
|
|
817
|
+
// A bubble written by a bot is not a user turn. Slash commands and button
|
|
818
|
+
// actions stay, because those are how a bot invokes a block on another bot.
|
|
819
|
+
function isBotBubble(message) {
|
|
820
|
+
if (!message || typeof message.sender !== "string" || !message.sender.startsWith("bot_")) {
|
|
821
|
+
return false;
|
|
822
|
+
}
|
|
823
|
+
if (message.attributes && message.attributes.action) {
|
|
824
|
+
return false;
|
|
825
|
+
}
|
|
826
|
+
if (typeof message.text === "string" && message.text.startsWith("/")) {
|
|
827
|
+
return false;
|
|
828
|
+
}
|
|
829
|
+
return true;
|
|
830
|
+
}
|
|
831
|
+
|
|
813
832
|
module.exports = { router: router, startApp: startApp};
|