@tiledesk/tiledesk-tybot-connector 0.2.47 → 0.2.49

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,14 @@
5
5
  available on:
6
6
  ▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
7
7
 
8
+ # v0.2.49
9
+ - resplacebotv2, added "/" + blockName (so the blockname will be implicitly executed), removing the need to specify the "/" in the body of the replacebot editor
10
+ - Never add "guest#" as lead userFullname
11
+
12
+ # v0.2.48
13
+ - resplacebotv2
14
+ - fixed jsoncondition expression. added ? in some "static OPERATORS" (i.e. contains) to correctly evaluate undefined operands
15
+
8
16
  # v0.2.47
9
17
  - added isNull isUndefined conditions
10
18
 
@@ -131,15 +131,15 @@ class TiledeskExpression {
131
131
  },
132
132
  "contains": {
133
133
  name: "contains",
134
- applyPattern: "#1.includes(#2)"
134
+ applyPattern: "#1?.includes(#2)"
135
135
  },
136
136
  "containsIgnoreCase": {
137
137
  name: "containsIgnoreCase",
138
- applyPattern: "#1.toLowerCase().includes(#2.toLowerCase())"
138
+ applyPattern: "#1?.toLowerCase().includes(#2.toLowerCase())"
139
139
  },
140
140
  "endsWith": {
141
141
  name: "endsWith",
142
- applyPattern: "#1.toLowerCase().endsWith(#2.toLowerCase())"
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.match(String(#2)) ? true : false"
158
+ applyPattern: "#1?.match(String(#2)) ? true : false"
159
159
  },
160
160
  // Francesco
161
161
  "addAsNumber": {
@@ -282,11 +282,11 @@ class TiledeskExpression {
282
282
  const applyPattern = operator.applyPattern;
283
283
  let operand = operands[i + 1].isVariable ? TiledeskExpression.variableOperand(operands[i + 1].value) : TiledeskExpression.quotedString(operands[i + 1].value);
284
284
  operand = operands[i + 1].function ? TiledeskExpression.applyFunctionToOperand(operand, operands[i + 1].function) : operand;
285
- console.log("1. expression is:", expression)
286
- console.log("operand is:", operand)
285
+ // console.log("1. expression is:", expression)
286
+ // console.log("operand is:", operand)
287
287
 
288
288
  expression = applyPattern.replace("#1", expression).replace("#2", operand);
289
- console.log("2. expression is:", expression)
289
+ // console.log("2. expression is:", expression)
290
290
 
291
291
  }
292
292
  return expression;
@@ -458,22 +458,23 @@ class TiledeskChatbotUtil {
458
458
  if (message.request.lead.email) {
459
459
  await chatbot.addParameter("userEmail", message.request.lead.email);
460
460
  }
461
- if (message.request.lead.fullname) {
461
+ if (message.request.lead.fullname && !message.request.lead.fullname.startsWith("guest#")) {
462
+ // worth saving
462
463
  try {
463
- const current_userFullname = await chatbot.getParameter("userFullname");
464
- if (current_userFullname && current_userFullname.startsWith("guest#")) {
464
+ // const current_userFullname = await chatbot.getParameter("userFullname");
465
+ // if (current_userFullname && current_userFullname.startsWith("guest#")) { // replace if exists as guest#
466
+ // await chatbot.addParameter("userFullname", message.request.lead.fullname);
467
+ // }
468
+ // else if (!current_userFullname) {
465
469
  await chatbot.addParameter("userFullname", message.request.lead.fullname);
466
- }
467
- else if (!current_userFullname) {
468
- await chatbot.addParameter("userFullname", message.request.lead.fullname);
469
- }
470
+ // }
470
471
  }
471
472
  catch(error) {
472
473
  console.error("Error on setting userFullname:", error);
473
474
  }
474
475
  }
475
476
  else {
476
- console.log("!lead.fullname");
477
+ // console.log("!lead.fullname");
477
478
  }
478
479
  // console.log("Getting userPhone:", JSON.stringify(message.request));
479
480
  if (message.request.lead.phone) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "0.2.47",
3
+ "version": "0.2.49",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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