@tiledesk/tiledesk-tybot-connector 0.2.88 → 0.2.90

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,13 @@
5
5
  available on:
6
6
  ▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
7
7
 
8
+ # v0.2.90
9
+ - Added voice flow attributes: dnis, callId, ani
10
+
11
+ # v0.2.89
12
+ - Added convertToNumber to operations in setAttribute
13
+ - Added setAttributeV2 test
14
+
8
15
  # v0.2.88
9
16
  - Added DirContactUpdate (aka LeadUpdate). No test case added for LeadUpdate. Only testable with a validation test.
10
17
  - Fixed: Attribute parameters userFullname & userEmail now are able to "bypass" the request.lead not correctly updating on the same conversation. If updated in the flow (through LeadUpdate action), they will maintain their own value through the current conversation flow.
@@ -218,6 +218,10 @@ class TiledeskExpression {
218
218
  name: "roundAsNumber",
219
219
  applyPattern: "TiledeskMath.round(Number(#1))"
220
220
  },
221
+ "convertToNumber": {
222
+ name: "convertToNumber",
223
+ applyPattern: "Number(#1)"
224
+ },
221
225
  "JSONparse": {
222
226
  name: "JSONparse",
223
227
  applyPattern: "JSON.parse(String(#1))"
@@ -715,7 +715,7 @@ class TiledeskChatbotUtil {
715
715
  const value_type = typeof value;
716
716
  //if (projectId === "641864da99c1fb00131ba495") {console.log("641864da99c1fb00131ba495 > importing payload parameter:", key, "value:", value, "type:", value_type);}
717
717
  //await chatbot.addParameter(key, String(value));
718
- console.log("Adding from message.attributes:", key, "->", value);
718
+ // console.log("Adding from message.attributes:", key, "->", value);
719
719
  await chatbot.addParameter(key, value);
720
720
  }
721
721
  }
@@ -723,6 +723,17 @@ class TiledeskChatbotUtil {
723
723
  console.error("Error importing message payload in request variables:", err);
724
724
  }
725
725
  }
726
+
727
+ // voice-vxml attributes
728
+ if (message.attributes.dnis) {
729
+ await chatbot.addParameter("dnis", message.attributes.dnis);
730
+ }
731
+ if (message.attributes.callId) {
732
+ await chatbot.addParameter("callId", message.attributes.callId);
733
+ }
734
+ if (message.attributes.ani) {
735
+ await chatbot.addParameter("ani", message.attributes.ani);
736
+ }
726
737
  }
727
738
 
728
739
  const _bot = chatbot.bot; // aka FaqKB
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "0.2.88",
3
+ "version": "0.2.90",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -57,6 +57,7 @@ class DirContactUpdate {
57
57
  let filled_value = filler.fill(value, requestAttributes);
58
58
  if (this.log) {console.log("(DirContactUpdate) setting property key:",key, "with value:", value, "filled value:", filled_value); }
59
59
  updateProperties[key] = filled_value;
60
+ // it's important that all the lead's properties are immediatly updated in the current flow invocation so the updated values will be available in the next actions
60
61
  if (key === "fullname") {
61
62
  await this.context.chatbot.addParameter(TiledeskChatbotConst.REQ_LEAD_USERFULLNAME_KEY, filled_value);
62
63
  if (this.log) {console.log("(DirContactUpdate) updating attribute:",TiledeskChatbotConst.REQ_LEAD_USERFULLNAME_KEY, "with property key:", key, "and value:", filled_value); }
@@ -97,10 +97,28 @@ class DirSetAttributeV2 {
97
97
 
98
98
  async go(action, callback) {
99
99
  if (this.log) {console.log("(DirSetAttribute) action before filling:", JSON.stringify(action));}
100
+ if (action && !action.operation) {
101
+ if (this.log) {console.log("(SetAttributeV2) Error operation is mandatory");}
102
+ callback();
103
+ }
100
104
  if (action && action.operation && action.operation.operands) {
101
- if (this.log) {console.log("filling in setattribute...");}
105
+ if (this.log) {console.log("(SetAttributeV2) filling in setattribute...");}
102
106
  await this.fillValues(action.operation.operands);
103
107
  }
108
+ console.log("action.operation.operands.length", action.operation.operands.length);
109
+ console.log("action.operation.operands[0].type", action.operation.operands[0].type);
110
+
111
+ // FUN FACT: THIS TOOK A LOT OF EFFERT BUT IT WAS NEVER USED. YOU CAN SIMPLY CREATE A JSON ATTRIBUTE APPLYING
112
+ // JSONparse FUNCTION TO AN ATTRIBUTE.
113
+ if (action.operation.operands && action.operation.operands.length === 1 && action.operation.operands[0].type === "json") {
114
+ if (this.log) {console.log("(SetAttributeV2) setting json value...");}
115
+ console.log("(SetAttributeV2) setting json value... destination:", action.destination);
116
+ const json_value = JSON.parse(action.operation.operands[0].value);
117
+ console.log("(SetAttributeV2) json_value:", json_value);
118
+ await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.destination, json_value);
119
+ callback();
120
+ return; // on json types no operations are permitted beyond assignment
121
+ }
104
122
  if (this.log) {console.log("filled in setattribute:", action.operation);}
105
123
  // let res = validate(action, schema);
106
124
  // if (res.errors) {
@@ -201,6 +219,44 @@ class DirSetAttributeV2 {
201
219
  console.error("Error while filling operands:", error);
202
220
  }
203
221
  }
222
+
223
+ convertOperandValues(operands) {
224
+ console.log("Converting operands:", operands);
225
+ // operation: {
226
+ // operators: ["addAsNumber", "subtractAsNumber", "divideAsNumber", "multiplyAsNumber"],
227
+ // operands: [
228
+ // {
229
+ // value: "previous",
230
+ // isVariable: true,
231
+ // type: "string"
232
+ // }
233
+ // ]
234
+ try {
235
+ operands.forEach(operand => {
236
+ if (operand.type) {
237
+ console.log("Converting operands - operand.type:", operand.type.toLowerCase());
238
+ if (operand.type.toLowerCase() === "number") {
239
+ console.log("Converting operands - number");
240
+ operand.value = Number(operand.value);
241
+ console.log("new value:", operand.value);
242
+ console.log("new value type:", typeof operand.value);
243
+ }
244
+ else if (operand.type.toLowerCase() === "json") {
245
+ console.log("Converting operands - json, value =", operand.value);
246
+ operand.value = JSON.parse(operand.value);
247
+ console.log("new value:", operand.value);
248
+ console.log("new value type:", typeof operand.value);
249
+ }
250
+ else {
251
+ console.log("Converting operands - ??");
252
+ }
253
+ }
254
+ });
255
+ }
256
+ catch(error) {
257
+ console.error("Error while converting operands:", error);
258
+ }
259
+ }
204
260
  }
205
261
 
206
262
  module.exports = { DirSetAttributeV2 };