@tiledesk/tiledesk-whatsapp-connector 0.1.68 → 0.1.70

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/index.js CHANGED
@@ -776,9 +776,7 @@ router.post("/tiledesk", async (req, res) => {
776
776
  }
777
777
 
778
778
  if (!phone_number_id) {
779
- return res
780
- .status(400)
781
- .send({ success: false, message: "Phone number id undefined" });
779
+ return res.status(400).send({ success: false, message: "Phone number id undefined" });
782
780
  }
783
781
 
784
782
  /*
@@ -863,17 +861,13 @@ router.post("/tiledesk", async (req, res) => {
863
861
  twClient
864
862
  .sendMessage(phone_number_id, whatsappJsonMessage)
865
863
  .then((response) => {
866
- winston.verbose(
867
- "(wab) Message sent to WhatsApp! " +
868
- response.status +
869
- " " +
870
- response.statusText
871
- );
864
+ winston.verbose("(wab) Message sent to WhatsApp! " + response.status + " " + response.statusText);
872
865
  i += 1;
873
866
  if (i < commands.length) {
874
867
  execute(commands[i]);
875
868
  } else {
876
869
  winston.debug("(wab) End of commands");
870
+ return res.sendStatus(200);
877
871
  }
878
872
  })
879
873
  .catch((err) => {
@@ -892,14 +886,13 @@ router.post("/tiledesk", async (req, res) => {
892
886
  execute(commands[i]);
893
887
  } else {
894
888
  winston.debug("(wab) End of commands");
889
+ return res.sendStatus(200);
895
890
  }
896
891
  }, command.time);
897
892
  }
898
893
  }
899
894
  execute(commands[0]);
900
895
 
901
- return res.sendStatus(200);
902
-
903
896
  } else if (tiledeskChannelMessage.text || tiledeskChannelMessage.metadata) {
904
897
  let whatsappJsonMessage = await tlr.toWhatsapp(
905
898
  tiledeskChannelMessage,
@@ -918,33 +911,22 @@ router.post("/tiledesk", async (req, res) => {
918
911
  twClient
919
912
  .sendMessage(phone_number_id, whatsappJsonMessage)
920
913
  .then((response) => {
921
- winston.verbose(
922
- "(wab) Message sent to WhatsApp! " +
923
- response.status +
924
- " " +
925
- response.statusText
926
- );
914
+ winston.verbose("(wab) Message sent to WhatsApp! " + response.status + " " + response.statusText);
915
+ return res.sendStatus(200);
927
916
  })
928
917
  .catch((err) => {
929
918
  winston.error("(wab) error send message: ", err);
930
- return res
931
- .status(400)
932
- .send({ success: false, error: "Template not existing" });
919
+ return res.status(400).send({ success: false, error: "Template not existing" });
933
920
  });
934
921
  } else {
935
922
  winston.error("(wab) Whatsapp Json Message is undefined!");
936
- return res
937
- .status(400)
938
- .send({
939
- success: false,
940
- error: "An error occurred during message translation",
941
- });
923
+ return res.status(400).send({ success: false, error: "An error occurred during message translation" });
942
924
  }
943
925
  } else {
944
926
  winston.debug("(wab) no command, no text --> skip");
945
- return res.sendStatus(400).send({ success: false, error: "No command or text specified. Skip message."});
927
+ return res.sendStatus(400).send({ success: false, error: "No command or text specified. Skip message." });
946
928
  }
947
-
929
+
948
930
  });
949
931
 
950
932
  // Endpoint for Whatsapp Business
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-whatsapp-connector",
3
- "version": "0.1.68",
3
+ "version": "0.1.70",
4
4
  "description": "Tiledesk Whatsapp connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -115,7 +115,7 @@ class TemplateManager {
115
115
  header_params.push({ type: header_component.format, location: { latitude: null, longitude: null, name: null, address: null } })
116
116
  }
117
117
  else {
118
- console.log("(Template Manager) Unrecognized Header: ", header_component)
118
+ winston.verbose("(Template Manager) Unrecognized Header: ", header_component)
119
119
  }
120
120
 
121
121
  }
@@ -81,7 +81,6 @@ class TiledeskChannel {
81
81
  }
82
82
 
83
83
  var customToken = jwt.sign(payload, this.settings.secret);
84
- console.log("\n\ncustomToken: ", customToken)
85
84
 
86
85
  return await axios({
87
86
  url: this.API_URL + "/auth/signinWithCustomToken",
@@ -261,7 +261,6 @@ const path = require('path');
261
261
  }
262
262
  else if (tiledeskChannelMessage.attributes.attachment.template) {
263
263
  winston.debug("(wab) [Translator] template: ", tiledeskChannelMessage.attributes.attachment.template)
264
- console.log("(wab) [Translator] template: ", tiledeskChannelMessage.attributes.attachment.template)
265
264
 
266
265
  let template = tiledeskChannelMessage.attributes.attachment.template;
267
266
 
@@ -457,18 +456,19 @@ const path = require('path');
457
456
 
458
457
  // interactive message
459
458
  else if (whatsappChannelMessage.type == 'interactive') {
460
-
459
+
461
460
  // list reply
462
461
  if (whatsappChannelMessage.interactive.type == 'list_reply') {
463
462
  // action button
464
463
  if (whatsappChannelMessage.interactive.list_reply.id.startsWith("action")) {
465
464
  var tiledeskMessage = {
466
465
  senderFullname: from,
467
- text: ' ',
466
+ //text: ' ',
467
+ text: whatsappChannelMessage.interactive.list_reply.title,
468
468
  type: 'text',
469
469
  attributes: {
470
470
  action: whatsappChannelMessage.interactive.list_reply.id.substring(11),
471
- subtype: 'info'
471
+ //subtype: 'info'
472
472
  },
473
473
  channel: { name: TiledeskWhatsappTranslator.CHANNEL_NAME }
474
474
  }
@@ -477,7 +477,7 @@ const path = require('path');
477
477
  // quick reply button
478
478
  if (whatsappChannelMessage.interactive.list_reply.id.startsWith("quick")) {
479
479
  var tiledeskMessage = {
480
- text: whatsappChannelMessage.interactive.list_reply.id.substring(10),
480
+ text: whatsappChannelMessage.interactive.list_reply.title,
481
481
  senderFullname: from,
482
482
  channel: { name: TiledeskWhatsappTranslator.CHANNEL_NAME }
483
483
  }
@@ -491,11 +491,12 @@ const path = require('path');
491
491
  if (whatsappChannelMessage.interactive.button_reply.id.startsWith("action")) {
492
492
  var tiledeskMessage = {
493
493
  senderFullname: from,
494
- text: ' ',
494
+ //text: ' ',
495
+ text: whatsappChannelMessage.interactive.button_reply.title,
495
496
  type: 'text',
496
497
  attributes: {
497
498
  action: whatsappChannelMessage.interactive.button_reply.id.substring(11),
498
- subtype: 'info'
499
+ //subtype: 'info'
499
500
  },
500
501
  channel: { name: TiledeskWhatsappTranslator.CHANNEL_NAME }
501
502
  }
@@ -504,7 +505,8 @@ const path = require('path');
504
505
  // quick reply button
505
506
  if (whatsappChannelMessage.interactive.button_reply.id.startsWith("quick")) {
506
507
  var tiledeskMessage = {
507
- text: whatsappChannelMessage.interactive.button_reply.id.substring(10),
508
+ //text: whatsappChannelMessage.interactive.button_reply.id.substring(10),
509
+ text: whatsappChannelMessage.interactive.button_reply.title,
508
510
  senderFullname: from,
509
511
  channel: { name: TiledeskWhatsappTranslator.CHANNEL_NAME }
510
512
  }
@@ -13,8 +13,6 @@ class WhatsappLogger {
13
13
  let status_code = this.getCodeFromStatus(status);
14
14
  winston.debug("(wab) getCodeFromStatus result " + status_code);
15
15
 
16
- console.log("message_id: ", message_id)
17
-
18
16
  MessageLog.findOneAndUpdate({ message_id: message_id }, { $set: {status: status, status_code: status_code, error: error }}, { new: true }).then((messageLog) => {
19
17
 
20
18
  if (messageLog) {