@tiledesk/tiledesk-tybot-connector 0.2.19 → 0.2.20
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,11 @@
|
|
|
5
5
|
available on:
|
|
6
6
|
▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
|
|
7
7
|
|
|
8
|
+
### v0.2.20
|
|
9
|
+
- updateRequestVariables renamed in updateRequestAttributes
|
|
10
|
+
- Added TildeskChatbot instance method async getParameter(parameter_name)
|
|
11
|
+
- Added "transcript" attribute
|
|
12
|
+
|
|
8
13
|
### v0.2.19
|
|
9
14
|
- Added native attribute lastUserMessageType
|
|
10
15
|
- Added integration with external intents decode engine
|
package/index.js
CHANGED
|
@@ -27,6 +27,7 @@ const { DirectivesChatbotPlug } = require('./tiledeskChatbotPlugs/DirectivesChat
|
|
|
27
27
|
// THE IMPORT
|
|
28
28
|
let mongoose = require('mongoose');
|
|
29
29
|
const { Directives } = require('./tiledeskChatbotPlugs/directives/Directives.js');
|
|
30
|
+
const { TiledeskChatbotUtil } = require('./models/TiledeskChatbotUtil.js'); //require('@tiledesk/tiledesk-chatbot-util');
|
|
30
31
|
let APIURL = null;
|
|
31
32
|
let staticBots;
|
|
32
33
|
|
|
@@ -146,7 +147,8 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
146
147
|
projectId: projectId,
|
|
147
148
|
log: log
|
|
148
149
|
});
|
|
149
|
-
await
|
|
150
|
+
await updateRequestAttributes(chatbot, message, projectId, requestId);
|
|
151
|
+
await TiledeskChatbotUtil.updateConversationTranscript(chatbot, message);
|
|
150
152
|
|
|
151
153
|
let reply = await chatbot.replyToMessage(message);
|
|
152
154
|
if (!reply) {
|
|
@@ -216,36 +218,7 @@ router.post('/ext/:botid', async (req, res) => {
|
|
|
216
218
|
|
|
217
219
|
});
|
|
218
220
|
|
|
219
|
-
|
|
220
|
-
// let bot = null;
|
|
221
|
-
// // let botCacheKey = "cacheman:cachegoose-cache:" + projectId + ":faq_kbs:id:" + botId;
|
|
222
|
-
// let botCacheKey = "cacheman:cachegoose-cache:faq_kbs:id:" + botId;
|
|
223
|
-
// try {
|
|
224
|
-
// let _bot_as_string = await tdcache.get(botCacheKey);
|
|
225
|
-
// const value_type = typeof _bot_as_string;
|
|
226
|
-
// console.log("_bot_as_string found in chache:", _bot_as_string);
|
|
227
|
-
// console.log("value_type:", value_type);
|
|
228
|
-
// if (_bot_as_string) {
|
|
229
|
-
// bot = JSON.parse(_bot_as_string);
|
|
230
|
-
// console.log("got bot from cache:", JSON.stringify(bot));
|
|
231
|
-
// }
|
|
232
|
-
// else {
|
|
233
|
-
// console.log("bot not found, getting from datasource...");
|
|
234
|
-
// bot = await botsDS.getBotById(botId);
|
|
235
|
-
// console.log("bot found in datasource:", JSON.stringify(bot));
|
|
236
|
-
// await tdcache.set(botCacheKey, JSON.stringify(bot));
|
|
237
|
-
// // DEBUG CODE REMOVE
|
|
238
|
-
// let bot_ = await tdcache.get(botCacheKey);
|
|
239
|
-
// console.log("_bot_as_string from cache debug:", bot_)
|
|
240
|
-
// }
|
|
241
|
-
// }
|
|
242
|
-
// catch(err) {
|
|
243
|
-
// console.error("error getting bot by id:", err);
|
|
244
|
-
// }
|
|
245
|
-
// return bot;
|
|
246
|
-
// }
|
|
247
|
-
|
|
248
|
-
async function updateRequestVariables(chatbot, message, projectId, requestId) {
|
|
221
|
+
async function updateRequestAttributes(chatbot, message, projectId, requestId) {
|
|
249
222
|
// update request context
|
|
250
223
|
if (chatbot.log) {console.log("Updating request variables. Message:", JSON.stringify(message));}
|
|
251
224
|
const messageId = message._id;
|
|
@@ -579,6 +579,14 @@ class TiledeskChatbot {
|
|
|
579
579
|
await TiledeskChatbot.addParameterStatic(this.tdcache, this.requestId, parameter_name, parameter_value);
|
|
580
580
|
}
|
|
581
581
|
|
|
582
|
+
async getParameter(parameter_name) {
|
|
583
|
+
// console.log("this.tdcache::", this.tdcache)
|
|
584
|
+
// console.log("this.requestId::", this.requestId)
|
|
585
|
+
// console.log("parameter_name::", parameter_name)
|
|
586
|
+
|
|
587
|
+
return await TiledeskChatbot.getParameterStatic(this.tdcache, this.requestId, parameter_name);
|
|
588
|
+
}
|
|
589
|
+
|
|
582
590
|
async deleteParameter(parameter_name) {
|
|
583
591
|
await TiledeskChatbot.deleteParameterStatic(this.tdcache, this.requestId, parameter_name);
|
|
584
592
|
}
|
|
@@ -596,8 +604,8 @@ class TiledeskChatbot {
|
|
|
596
604
|
static async allParametersStatic(_tdcache, requestId) {
|
|
597
605
|
const parameters_key = TiledeskChatbot.requestCacheKey(requestId) + ":parameters";
|
|
598
606
|
const attributes__as_string_map = await _tdcache.hgetall(parameters_key);
|
|
599
|
-
console.log("** getting parameters for requestId:", requestId);
|
|
600
|
-
console.log("** for key:", parameters_key, "parameters:", JSON.stringify(attributes__as_string_map));
|
|
607
|
+
// console.log("** getting parameters for requestId:", requestId);
|
|
608
|
+
// console.log("** for key:", parameters_key, "parameters:", JSON.stringify(attributes__as_string_map));
|
|
601
609
|
let attributes_native_values = {};
|
|
602
610
|
if (attributes__as_string_map !== null) {
|
|
603
611
|
for (const [key, value] of Object.entries(attributes__as_string_map)) {
|
|
@@ -273,6 +273,31 @@ class TiledeskChatbotUtil {
|
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
+
static async updateConversationTranscript(chatbot, message) {
|
|
277
|
+
// console.log("transcript updating with:", message)
|
|
278
|
+
if (message && message.text && message.text.trim() !== "" && message.sender !== "_tdinternal" && !this.isHiddenMessage(message)) {
|
|
279
|
+
let transcript = await chatbot.getParameter("transcript");
|
|
280
|
+
// console.log("transcript got:", transcript);
|
|
281
|
+
if (transcript) {
|
|
282
|
+
transcript = transcript + "\n[" + message.senderFullname + "] says: " + message.text;
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
transcript = "[" + message.senderFullname + "] says: " + message.text;
|
|
286
|
+
}
|
|
287
|
+
// console.log("transcript update:", transcript);
|
|
288
|
+
await chatbot.addParameter("transcript", transcript);
|
|
289
|
+
let transcript2 = await chatbot.getParameter("transcript");
|
|
290
|
+
// console.log("transcript updated:", transcript2);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
static isHiddenMessage(message) {
|
|
295
|
+
if (message && message.attributes && message.attributes.subtype === "info") {
|
|
296
|
+
return true;
|
|
297
|
+
}
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
|
|
276
301
|
}
|
|
277
302
|
|
|
278
303
|
module.exports = { TiledeskChatbotUtil };
|
package/package.json
CHANGED
|
@@ -97,7 +97,9 @@ class DirReply {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
// send!
|
|
100
|
+
message.senderFullname = this.context.chatbot.bot.name;
|
|
100
101
|
if (this.log) {console.log("Reply:", JSON.stringify(message))};
|
|
102
|
+
await TiledeskChatbotUtil.updateConversationTranscript(this.context.chatbot, message);
|
|
101
103
|
this.context.tdclient.sendSupportMessage(
|
|
102
104
|
this.requestId,
|
|
103
105
|
message,
|