@tiledesk/tiledesk-tybot-connector 2.0.12-rc7 → 2.0.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "2.0.12-rc7",
3
+ "version": "2.0.12",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -69,9 +69,11 @@ class DirReply {
69
69
  winston.debug("DirReply filling message 'metadata':", message.metadata);
70
70
  if (message.metadata.src) {
71
71
  message.metadata.src = filler.fill(message.metadata.src, requestAttributes);
72
+ this.logger.debug("Filled metadata.src with ", message.metadata.src);
72
73
  }
73
74
  if (message.metadata.name) {
74
75
  message.metadata.name = filler.fill(message.metadata.name, requestAttributes);
76
+ this.logger.debug("Filled metadata.name with ", message.metadata.name);
75
77
  }
76
78
  }
77
79
  winston.debug("DirReply filling commands'. Message:", message);
@@ -138,14 +140,7 @@ class DirReply {
138
140
  }
139
141
 
140
142
  let cleanMessage = message;
141
-
142
- // cleanMessage = TiledeskChatbotUtil.removeEmptyReplyCommands(message);
143
- // if (!TiledeskChatbotUtil.isValidReply(cleanMessage)) {
144
- // console.log("invalid message", cleanMessage);
145
- // callback(); // cancel reply operation
146
- // return;
147
- // }
148
-
143
+
149
144
  cleanMessage.senderFullname = this.context.chatbot.bot.name;
150
145
  winston.debug("DirReply reply with clean message: ", cleanMessage);
151
146
 
@@ -21,7 +21,6 @@ class DirReplyV2 {
21
21
  this.requestId = context.requestId;
22
22
  this.token = context.token;
23
23
  this.tdcache = context.tdcache;
24
- this.intentDir = new DirIntent(context);
25
24
  this.chatbot = context.chatbot;
26
25
  this.reply = context.reply;
27
26
  this.originalMessage = context.message;
@@ -23,19 +23,21 @@ class DirWebRequestV2 {
23
23
  }
24
24
 
25
25
  execute(directive, callback) {
26
+ this.logger.info("[Web Request] Executing action");
26
27
  winston.verbose("Execute WebRequestV2 directive");
27
28
  let action;
28
29
  if (directive.action) {
29
30
  action = directive.action;
30
31
  }
31
32
  else {
33
+ this.logger.error("Incorrect action for ", directive.name, directive)
32
34
  winston.warn("DirWebRequestV2 Incorrect directive: ", directive);
33
35
  callback();
34
36
  return;
35
37
  }
36
38
  this.logger.info("Executing WebRequest action ", directive.action)
37
39
  this.go(action, (stop) => {
38
- this.logger.info("WebRequest action terminated")
40
+ this.logger.info("[Web Request] Action completed");
39
41
  callback(stop);
40
42
  }).catch((err) => {
41
43
  // do not nothing
@@ -70,7 +72,7 @@ class DirWebRequestV2 {
70
72
  const url = filler.fill(action.url, requestAttributes);
71
73
 
72
74
  let headers = await this.getHeadersFromAction(action, filler, requestAttributes).catch( async (err) => {
73
- this.logger.error("WebRequest: error getting headers");
75
+ this.logger.error("[Web Request] Error getting headers");
74
76
  await this.chatbot.addParameter("flowError", "Error getting headers");
75
77
  if (falseIntent) {
76
78
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
@@ -82,7 +84,7 @@ class DirWebRequestV2 {
82
84
  });
83
85
 
84
86
  let json = await this.getJsonFromAction(action, filler, requestAttributes).catch( async (err) => {
85
- this.logger.error("WebRequest: error parsing json body");
87
+ this.logger.error("[Web Request] Error parsing json body");
86
88
  await this.chatbot.addParameter("flowError", "Error parsing json body");
87
89
  if (falseIntent) {
88
90
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
@@ -114,7 +116,7 @@ class DirWebRequestV2 {
114
116
  let error = res.error;
115
117
  await this.#assignAttributes(action, resbody, status, error)
116
118
  winston.debug("DirWebRequestV2 resbody:", resbody);
117
- this.logger.info("WebRequest resbody: ", resbody);
119
+ this.logger.debug("[Web Request] resbody: ", resbody);
118
120
 
119
121
  if (err) {
120
122
  this.logger.error("WebRequest error: ", err);
@@ -139,8 +141,8 @@ class DirWebRequestV2 {
139
141
  return;
140
142
  }
141
143
  else {
142
- this.logger.warn("WebRequest status ", status);
143
- this.logger.error("WebRequest error ", error);
144
+ this.logger.warn("[Web Request] status ", status);
145
+ this.logger.error("[Web Request] error ", error);
144
146
  if (falseIntent) {
145
147
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
146
148
  callback(true);
@@ -313,27 +313,23 @@ class TiledeskChatbotUtil {
313
313
  // fill buttons
314
314
  const filler = new Filler();
315
315
  json_buttons_string = filler.fill(json_buttons_string, flow_attributes);
316
- // console.log("json_buttons_string:", json_buttons_string);
317
316
  json_buttons = JSON.parse(json_buttons_string);
318
317
  if (Array.isArray(json_buttons)) {
319
318
  json_buttons.forEach(button => {
320
319
  if (button.value && button.type === "action" && button.action) {
321
320
  button.show_echo = true;
322
- // console.log("pushing:", button)
323
321
  final_buttons.push(button);
324
322
  }
325
323
  else if (button.value && button.type === "text") {
326
324
  button.show_echo = true;
327
- // console.log("pushing:", button)
328
325
  final_buttons.push(button);
329
326
  }
330
327
  else if (button.value && button.type === "url" && button.link) {
331
328
  button.show_echo = true;
332
- // console.log("pushing:", button)
333
329
  final_buttons.push(button);
334
330
  }
335
331
  else {
336
- console.log("Invalid button. Skipping:", JSON.stringify(button) );
332
+ winston.verbose("Invalid button. Skipping:", button);
337
333
  }
338
334
  });
339
335
  }
@@ -360,14 +356,14 @@ class TiledeskChatbotUtil {
360
356
  // ]
361
357
  }
362
358
  catch(error) {
363
- console.error("Invalid json_buttons:", error)
359
+ winston.warn("Invalid json_buttons:", error)
364
360
  }
365
361
  if (final_buttons && final_buttons.length > 0) {
366
362
  command.message.attributes.attachment.buttons = final_buttons;
367
363
  delete command.message.attributes.attachment.json_buttons;
368
364
  }
369
365
  else {
370
- console.log("Invalid json_buttons. Skipping")
366
+ winston.verbose("Invalid json_buttons. Skipping...")
371
367
  }
372
368
  }
373
369
  }
@@ -605,10 +601,10 @@ class TiledeskChatbotUtil {
605
601
  }
606
602
  }
607
603
  let currentLeadName = await chatbot.getParameter(TiledeskChatbotConst.REQ_LEAD_USERFULLNAME_KEY);
608
- if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) You lead name from attributes: " + currentLeadName); }
604
+ winston.debug("(TiledeskChatbotUtil) You lead email from attributes: " + currentLeadEmail);
609
605
  if (message.request.lead.fullname && !currentLeadName) {
610
606
  // worth saving
611
- if (chatbot.log) { winston.debug("(TiledeskChatbotUtil) worth saving name"); }
607
+ winston.debug("(TiledeskChatbotUtil) worth saving email");
612
608
  try {
613
609
  await chatbot.addParameter(TiledeskChatbotConst.REQ_LEAD_USERFULLNAME_KEY, message.request.lead.fullname);
614
610
  }