@tiledesk/tiledesk-tybot-connector 0.2.17 → 0.2.19

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.19
9
+ - Added native attribute lastUserMessageType
10
+ - Added integration with external intents decode engine
11
+ - Added support for automatic wait time on each reply
12
+
8
13
  ### v0.2.17
9
14
  - Added lastUserMessage JSON native attribute
10
15
  - Added attributes to access image and file properties from incoming messages
package/index.js CHANGED
@@ -261,6 +261,7 @@ async function updateRequestVariables(chatbot, message, projectId, requestId) {
261
261
  }
262
262
  if (message.text && message.sender !== "_tdinternal") {
263
263
  await chatbot.addParameter(TiledeskChatbotConst.REQ_LAST_USER_TEXT_KEY, message.text);
264
+ await chatbot.addParameter("lastUserMessageType", message.type);
264
265
  await chatbot.addParameter("lastUserMessage", lastUserMessageFrom(message)); // JSON TYPE *NEW
265
266
  // get image
266
267
  if (message.type && message.type === "image" && message.metadata) {
@@ -275,10 +275,11 @@ class TiledeskChatbot {
275
275
  return;
276
276
  }
277
277
  else { // NLP
278
- if (this.log) {console.log("Chatbot NLP decode intent...");}
278
+ if (this.log) {console.log("Chatbot NLP decoding intent...");}
279
279
  let intents;
280
280
  try {
281
281
  intents = await this.intentsFinder.decode(this.botId, message.text);
282
+ if (this.log) {console.log("Tiledesk AI intents found:", intents);}
282
283
  }
283
284
  catch(error) {
284
285
  console.error("An error occurred on IntentsFinder.decode() (/model/parse error):", error.message);
@@ -289,8 +290,9 @@ class TiledeskChatbot {
289
290
  if (this.log) {console.log("Got intents from backup finder:", intents);}
290
291
  }
291
292
  }
292
- if (this.log) {console.log("NLP decoded found:", intents);}
293
+ if (this.log) {console.log("NLP intents found:", intents);}
293
294
  if (intents && intents.length > 0) {
295
+ console.log("Matching intents found.");
294
296
  // let faq = await this.botsDataSource.getByIntentDisplayName(this.botId, intents[0].intent_display_name);
295
297
  let faq = await this.botsDataSource.getByIntentDisplayNameCache(this.botId, intents[0].intent_display_name, this.tdcache);
296
298
  let reply;
@@ -233,6 +233,25 @@ class TiledeskChatbotUtil {
233
233
  }
234
234
  }
235
235
 
236
+ static totalMessageWait(message) {
237
+ if (!message) {
238
+ return;
239
+ }
240
+ console.log("compute delay...", message)
241
+ if (message.attributes.commands.length > 0) {
242
+ console.log("going on delay")
243
+ let commands = message.attributes.commands;
244
+ console.log("got commands", commands)
245
+ let totalWaitTime = 0;
246
+ for (let i = commands.length - 1; i >= 0; i--) {
247
+ if (commands[i].type === "wait") { // is a wait
248
+ totalWaitTime += commands[i].time;
249
+ }
250
+ }
251
+ return totalWaitTime;
252
+ }
253
+ }
254
+
236
255
  static fillCommandAttachments(command, variables, log) {
237
256
  if (log) {
238
257
  console.log("filling command button:", JSON.stringify(command))
@@ -37,13 +37,14 @@ class TiledeskIntentsMachine {
37
37
  };
38
38
  this.myrequest(
39
39
  HTTPREQUEST,
40
- function(err, resbody) {
40
+ (err, resbody) => {
41
41
  if (err) {
42
42
  // console.error("An error occurred on /model/parse:", err)
43
43
  reject(err);
44
44
  }
45
45
  else {
46
- resolve(resbody);
46
+ console.log("Tiledesk AI replied:", resbody)
47
+ resolve(this.translateForTiledesk(resbody));
47
48
  }
48
49
  }, false
49
50
  );
@@ -83,7 +84,7 @@ class TiledeskIntentsMachine {
83
84
  // }
84
85
  let intents_array = intents.intent_ranking;
85
86
  let tiledesk_intents = [];
86
- for (i = 0; i < intents_array.length; i++) {
87
+ for (let i = 0; i < intents_array.length; i++) {
87
88
  let td_intent = {
88
89
  "intent_display_name": intents_array[i].name
89
90
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "0.2.17",
3
+ "version": "0.2.19",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -106,7 +106,18 @@ class DirReply {
106
106
  console.error("Error sending reply:", err);
107
107
  }
108
108
  if (this.log) {console.log("Reply message sent");}
109
- callback();
109
+ const delay = TiledeskChatbotUtil.totalMessageWait(message);
110
+ console.log("got total delay:", delay)
111
+ if (delay > 0 && delay <= 30000) { // prevent long delays
112
+ setTimeout(() => {
113
+ console.log("callback after delay")
114
+ callback();
115
+ }, delay);
116
+ }
117
+ else {
118
+ console.log("invalid delay.")
119
+ callback();
120
+ }
110
121
  });
111
122
 
112
123
  // this.sendSupportMessage(