@tiledesk/tiledesk-tybot-connector 0.1.53 → 0.1.55

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,12 @@
5
5
  available on:
6
6
  ▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
7
7
 
8
+ ### 0.1.55
9
+ - fixed bug on DirCondition $data. replace with regex
10
+
11
+ ### 0.1.54
12
+ - bug fixing
13
+
8
14
  ### 0.1.53
9
15
  - removed projectId from query MongodbBotsDataSource.getByExactMatch()
10
16
  - removed projectId from query MongodbIntentsMachine.decode()
@@ -19,7 +19,7 @@ class IntentForm {
19
19
  return null;
20
20
  }
21
21
  if (this.log) {
22
- console.log("this.requestParameters:", this.requestParameters);
22
+ console.log("this.requestParameters:", JSON.stringify(this.requestParameters));
23
23
  console.log("this.requestParameters[" + paramKey + "]:", this.requestParameters[paramKey]);
24
24
  }
25
25
  return this.requestParameters[paramKey];
@@ -103,7 +103,7 @@ class IntentForm {
103
103
  // set the first field under the "await the response-value" state (=0)
104
104
  await this.setValue(this.CURRENT_FIELD_INDEX_KEY, current_field);
105
105
  // now look for an already set value for this field in request parameters
106
- if (this.log) {console.log("params", this.requestParameters);}
106
+ if (this.log) {console.log("IntentForm parameters", JSON.stringify(this.requestParameters));}
107
107
  if (this.log) {console.log("checking field:", this.form.fields[current_field].name);}
108
108
  const is_current_value = this.getParam(this.form.fields[current_field].name);
109
109
  if (is_current_value) {
@@ -187,7 +187,7 @@ class IntentForm {
187
187
  if (this.log) {console.log("Processing next field:", current_field)}
188
188
  await this.setValue(this.CURRENT_FIELD_INDEX_KEY, current_field);
189
189
 
190
- if (this.log) {console.log("params", this.requestParameters);}
190
+ // if (this.log) {console.log("params", this.requestParameters);}
191
191
  if (this.log) {console.log("checking field:", this.form.fields[current_field].name);}
192
192
 
193
193
  const is_current_value = this.getParam(this.form.fields[current_field].name);
@@ -98,7 +98,7 @@ class TiledeskChatbot {
98
98
  });
99
99
  // it only gets the locked_intent
100
100
  const faq = await this.botsDataSource.getByIntentDisplayName(this.botId, locked_intent);
101
- if (this.log) {console.log("locked intent. got faqs", faq)}
101
+ if (this.log) {console.log("locked intent. got faqs", JSON.stringify(faq))}
102
102
  let reply;
103
103
  if (faq) {
104
104
  reply = await this.execIntent(faq, message, lead);//, bot);
@@ -340,7 +340,7 @@ class TiledeskChatbot {
340
340
  if (this.log) {
341
341
  console.log("FORM end.", );
342
342
  console.log("unlocking intent for request:", this.requestId);
343
- console.log("populate data on lead:", lead);
343
+ console.log("populate data on lead:", JSON.stringify(lead));
344
344
  }
345
345
  this.unlockIntent(this.requestId);
346
346
  if (lead) {
@@ -350,7 +350,7 @@ class TiledeskChatbot {
350
350
  if (this.log) {console.log("No lead. Skipping populatePrechatFormAndLead()");}
351
351
  }
352
352
  const all_parameters = await this.allParameters();
353
- if (this.log) {console.log("We have all_parameters:", all_parameters)};
353
+ // if (this.log) {console.log("We have all_parameters:", all_parameters)};
354
354
  if (all_parameters && all_parameters["userFullname"]) {
355
355
  clientUpdateUserFullname = all_parameters["userFullname"];
356
356
  }
@@ -576,7 +576,7 @@ class TiledeskChatbot {
576
576
  async execIntentForm(userInputReply, form) {
577
577
  if (this.log) {console.log("executing intent form...")}
578
578
  let all_parameters = await this.allParameters();
579
- if (this.log) {console.log("allParameters for IntentForm:", all_parameters)}
579
+ // if (this.log) {console.log("allParameters for IntentForm:", all_parameters)}
580
580
  let intentForm = new IntentForm(
581
581
  {
582
582
  form: form,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "0.1.53",
3
+ "version": "0.1.55",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -229,9 +229,17 @@ class DirectivesChatbotPlug {
229
229
  });
230
230
  }
231
231
  else if (directive_name === Directives.IF_OPEN_HOURS) {
232
- new DirIfOpenHours(context).execute(directive, async () => {
233
- let next_dir = await this.nextDirective(this.directives);
234
- this.process(next_dir);
232
+ new DirIfOpenHours(context).execute(directive, async (stop) => {
233
+ if (stop) {
234
+ if (context.log) { console.log("Stopping Actions on:", directive);}
235
+ this.theend();
236
+ }
237
+ else {
238
+ let next_dir = await this.nextDirective(this.directives);
239
+ this.process(next_dir);
240
+ }
241
+ // let next_dir = await this.nextDirective(this.directives);
242
+ // this.process(next_dir);
235
243
  });
236
244
  }
237
245
  else if (directive_name === Directives.IF_ONLINE_AGENTS) {
@@ -274,7 +282,7 @@ class DirectivesChatbotPlug {
274
282
  // DEPRECATED
275
283
  const whenOpenDir = new DirWhenOpen(
276
284
  {
277
- tdclient: tdclient, // matches open hours
285
+ tdclient: this.context.tdclient, // matches open hours
278
286
  log: false
279
287
  });
280
288
  whenOpenDir.execute(directive, directives, curr_directive_index, async () => {
@@ -286,7 +294,7 @@ class DirectivesChatbotPlug {
286
294
  // DEPRECATED
287
295
  const whenOpenDir = new DirWhenOpen(
288
296
  {
289
- tdclient: tdclient,
297
+ tdclient: this.context.tdclient,
290
298
  checkOpen: false, // matches closed hours
291
299
  log: false
292
300
  });
@@ -299,7 +307,7 @@ class DirectivesChatbotPlug {
299
307
  // DEPRECATED
300
308
  const ifNoAgentsDir = new DirIfAvailableAgents(
301
309
  {
302
- tdclient: tdclient,
310
+ tdclient: this.context.tdclient,
303
311
  checkAgents: true, // check available agents > 0
304
312
  log: false
305
313
  });
@@ -312,7 +320,7 @@ class DirectivesChatbotPlug {
312
320
  // DEPRECATED
313
321
  const ifNoAgentsDir = new DirIfAvailableAgents(
314
322
  {
315
- tdclient: tdclient,
323
+ tdclient: this.context.tdclient,
316
324
  checkAgents: false, // check no available agents
317
325
  log: false
318
326
  });
@@ -402,7 +410,7 @@ class DirectivesChatbotPlug {
402
410
  });
403
411
  }
404
412
  else if (directive_name === Directives.SEND_EMAIL) {
405
- // console.log("...DirSendEmail");
413
+ console.log("...DirSendEmail");
406
414
  new DirSendEmail(context).execute(directive, async () => {
407
415
  let next_dir = await this.nextDirective(this.directives);
408
416
  this.process(next_dir);
@@ -61,7 +61,7 @@ class MarkbotChatbotPlug {
61
61
  // if already present, do not modify metadata
62
62
  message.metadata = parsed_reply.message.metadata;
63
63
  }
64
- if (this.log) {console.log("parsed_reply.message.attributes", parsed_reply.message.attributes);}
64
+ if (this.log) {console.log("parsed_reply.message.attributes", JSON.stringify(parsed_reply.message.attributes));}
65
65
  //this.mergeCurrentMessageButtons(message, parsed_reply);
66
66
  if (parsed_reply.message.attributes) {
67
67
  for(const [key, value] of Object.entries(parsed_reply.message.attributes)) {
@@ -75,7 +75,8 @@ class DirAssign {
75
75
  // console.log("assign variable name (after filling):", variableName);
76
76
 
77
77
  if (this.log) {console.log("(DirAssign) Variables:", JSON.stringify(variables));}
78
- const value = await new TiledeskExpression().evaluateExpression(expression, variables);
78
+ // const value = await new TiledeskExpression().evaluateExpression(expression, variables);
79
+ const value = new TiledeskExpression().evaluateExpression(expression, variables);
79
80
  if (this.log) {console.log("(DirAssign) executed expression:", expression, "value:", value);}
80
81
  await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, variableName, value);
81
82
  if (this.log) {
@@ -65,7 +65,6 @@ class DirCondition {
65
65
  this.go(action, (stop) => {
66
66
  callback(stop);
67
67
  });
68
-
69
68
  }
70
69
 
71
70
  async go(action, callback) {
@@ -133,7 +132,7 @@ class DirCondition {
133
132
  if (trueIntentDirective) {
134
133
  this.intentDir.execute(trueIntentDirective, () => {
135
134
  console.log("result === true. stopOnConditionMet?", stopOnConditionMet);
136
- callback(true);
135
+ callback(stopOnConditionMet);
137
136
  });
138
137
  }
139
138
  else {
@@ -157,13 +156,14 @@ class DirCondition {
157
156
  }
158
157
  }
159
158
 
160
- async evaluateCondition(_condition, variables) {
161
- let condition = _condition.replace("$", "$data.");
159
+ async evaluateCondition(expression, variables) {
160
+ // let condition = _condition.replace("$", "$data.");
162
161
  if (this.log) {
163
- console.log("Evaluating expression:", condition);
162
+ console.log("Evaluating expression:", expression);
164
163
  console.log("With variables:", variables);
165
164
  }
166
- const result = new TiledeskExpression().evaluate(condition, variables)
165
+ // const result = new TiledeskExpression().evaluate(condition, variables)
166
+ const result = await new TiledeskExpression().evaluateExpression(expression, variables);
167
167
  if (this.log) {
168
168
  console.log("Expression result:", result);
169
169
  }
@@ -53,22 +53,35 @@ class DirIfOpenHours {
53
53
  return;
54
54
  }
55
55
  action = {
56
- body: {
57
- trueIntent: params.trueIntent,
58
- falseIntent: params.falseIntent
59
- }
56
+ trueIntent: params.trueIntent,
57
+ falseIntent: params.falseIntent
60
58
  }
61
59
  }
62
60
  else {
63
61
  callback();
64
62
  return;
65
63
  }
66
- this.go(action, () => {
67
- callback();
64
+ this.go(action, (stop) => {
65
+ callback(stop);
68
66
  });
69
67
  }
70
68
 
71
69
  go(action, callback) {
70
+ let trueIntent = action.trueIntent;
71
+ let falseIntent = action.falseIntent;
72
+ const stopOnConditionMet = action.stopOnConditionMet;
73
+ if (trueIntent && trueIntent.trim() === "") {
74
+ trueIntent = null;
75
+ }
76
+ if (falseIntent && falseIntent.trim() === "") {
77
+ falseIntent = null;
78
+ }
79
+ if (this.log) {console.log("condition action:", action);}
80
+ if (!trueIntent && !falseIntent) {
81
+ if (this.log) {console.log("Invalid condition, no intents specified");}
82
+ callback();
83
+ return;
84
+ }
72
85
  this.tdclient.openNow((err, result) => {
73
86
  if (this.log) {console.log("openNow():", result);}
74
87
  if (err) {
@@ -76,11 +89,11 @@ class DirIfOpenHours {
76
89
  callback();
77
90
  }
78
91
  else if (result && result.isopen) {
79
- if (action.body.trueIntent) {
80
- let intentDirective = DirIntent.intentDirectiveFor(action.body.trueIntent);
92
+ if (trueIntent) {
93
+ let intentDirective = DirIntent.intentDirectiveFor(trueIntent);
81
94
  if (this.log) {console.log("agents (openHours) => trueIntent");}
82
95
  this.intentDir.execute(intentDirective, () => {
83
- callback();
96
+ callback(stopOnConditionMet);
84
97
  });
85
98
  }
86
99
  else {
@@ -88,11 +101,11 @@ class DirIfOpenHours {
88
101
  return;
89
102
  }
90
103
  }
91
- else if (action.body.falseIntent) {
92
- let intentDirective = DirIntent.intentDirectiveFor(action.body.falseIntent);
93
- if (this.log) {console.log("!agents (openHours) => falseIntent", action.body.falseIntent);}
104
+ else if (falseIntent) {
105
+ let intentDirective = DirIntent.intentDirectiveFor(falseIntent);
106
+ if (this.log) {console.log("!agents (openHours) => falseIntent", falseIntent);}
94
107
  this.intentDir.execute(intentDirective, () => {
95
- callback();
108
+ callback(stopOnConditionMet);
96
109
  });
97
110
  }
98
111
  else {
@@ -101,17 +114,6 @@ class DirIfOpenHours {
101
114
  });
102
115
  }
103
116
 
104
- // intentDirectiveFor(intent) {
105
- // let intentDirective = {
106
- // action: {
107
- // body: {
108
- // intentName: intent
109
- // }
110
- // }
111
- // }
112
- // return intentDirective;
113
- // }
114
-
115
117
  parseParams(directive_parameter) {
116
118
  let trueIntent = null;
117
119
  let falseIntent = null;
@@ -24,10 +24,10 @@ class DirLockIntent {
24
24
  else if (directive.parameter && directive.parameter.trim() !== "") {
25
25
  const params = this.parseParams(directive.parameter);
26
26
  action = {
27
- body: {
28
- intentName: params.intentName // directive.parameter.trim()
27
+ // body: {
28
+ intentName: params.intentName // directive.parameter.trim()
29
29
  // variableName: params.variableName
30
- }
30
+ // }
31
31
  }
32
32
  }
33
33
  else {
@@ -49,10 +49,11 @@ class DirLockIntent {
49
49
  }
50
50
 
51
51
  async go(action, callback) {
52
- let intent_name = action.body.intentName;
52
+ // let intent_name = action.body.intentName;
53
+ let intent_name = action.intentName;
53
54
  // let variable_name = action.body.variableName;
54
55
  await DirLockIntent.lockIntent(this.tdcache, this.context.requestId, intent_name); //, variable_name);
55
- if (this.log) {console.log("Locked intent:", action.body.intentName);}
56
+ if (this.log) {console.log("Locked intent:", action.intentName);}
56
57
  if (callback) {
57
58
  callback();
58
59
  }
@@ -88,7 +88,7 @@ class DirMessage {
88
88
  go(action, callback) {
89
89
  // const message = action.body.message;
90
90
  const message = action;
91
- if (this.log) {console.log("Message to extEndpoint:", message)};
91
+ if (this.log) {console.log("Message to extEndpoint:", JSON.stringify(message))};
92
92
  let extEndpoint = `${this.API_ENDPOINT}/modules/tilebot`;
93
93
  if (this.TILEBOT_ENDPOINT) {
94
94
  extEndpoint = `${this.TILEBOT_ENDPOINT}`;
@@ -91,7 +91,7 @@ class DirReply {
91
91
  }
92
92
  }
93
93
  // send!
94
- if (this.log) {console.log("Message to extEndpoint:", message)};
94
+ if (this.log) {console.log("Reply:", JSON.stringify(message))};
95
95
  this.context.tdclient.sendSupportMessage(
96
96
  this.requestId,
97
97
  message,
@@ -99,7 +99,7 @@ class DirReply {
99
99
  if (err) {
100
100
  console.error("Error sending reply:", err.message);
101
101
  }
102
- if (this.log) {console.log("Message sent.");}
102
+ if (this.log) {console.log("Reply message sent.");}
103
103
  callback();
104
104
  });
105
105
  }
@@ -40,7 +40,6 @@ class DirSendEmail {
40
40
  execute(directive, callback) {
41
41
  let action;
42
42
  if (directive.action) {
43
- console.log("got intent action:", JSON.stringify(directive.action));
44
43
  action = directive.action;
45
44
  }
46
45
  else if (directive.parameter && directive.parameter.trim() !== "") {
@@ -52,7 +51,7 @@ class DirSendEmail {
52
51
  }
53
52
  }
54
53
  else {
55
- console.error("Incorrect directive:", directive);
54
+ console.error("Incorrect directive:", JSON.stringify(directive));
56
55
  callback();
57
56
  return;
58
57
  }
@@ -63,6 +62,7 @@ class DirSendEmail {
63
62
 
64
63
  async go(action, completion) {
65
64
  // let params = action.body;
65
+ if (this.log) {console.log("email action:", JSON.stringify(action));}
66
66
  if (action.subject && action.text && action.to) {
67
67
  try {
68
68
  let requestVariables = null;
@@ -73,11 +73,17 @@ class DirSendEmail {
73
73
  );
74
74
  }
75
75
  const filler = new Filler();
76
+ const filled_subject = filler.fill(action.subject, requestVariables);
77
+ const filled_text = filler.fill(action.text, requestVariables);
78
+ const filled_to = filler.fill(action.to, requestVariables);
76
79
  const message_echo = await this.tdclient.sendEmail({
77
- subject: filler.fill(action.subject, requestVariables),
78
- text: filler.fill(action.text, requestVariables),
79
- to: filler.fill(action.to, requestVariables)
80
+ subject: filled_subject,
81
+ text: filled_text,
82
+ to: filled_to
80
83
  });
84
+ if (this.log) {console.log("email sent. filled_subject:", filled_subject);}
85
+ if (this.log) {console.log("email sent. filled_text:", filled_text);}
86
+ if (this.log) {console.log("email sent. filled_to:", filled_to);}
81
87
  if (completion) {
82
88
  completion(null, message_echo);
83
89
  }