@tiledesk/tiledesk-whatsapp-connector 0.1.69 → 0.1.71

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,6 +886,7 @@ 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
  }
@@ -916,35 +911,22 @@ router.post("/tiledesk", async (req, res) => {
916
911
  twClient
917
912
  .sendMessage(phone_number_id, whatsappJsonMessage)
918
913
  .then((response) => {
919
- winston.verbose(
920
- "(wab) Message sent to WhatsApp! " +
921
- response.status +
922
- " " +
923
- response.statusText
924
- );
914
+ winston.verbose("(wab) Message sent to WhatsApp! " + response.status + " " + response.statusText);
915
+ return res.sendStatus(200);
925
916
  })
926
917
  .catch((err) => {
927
918
  winston.error("(wab) error send message: ", err);
928
- return res
929
- .status(400)
930
- .send({ success: false, error: "Template not existing" });
919
+ return res.status(400).send({ success: false, error: "Template not existing" });
931
920
  });
932
921
  } else {
933
922
  winston.error("(wab) Whatsapp Json Message is undefined!");
934
- return res
935
- .status(400)
936
- .send({
937
- success: false,
938
- error: "An error occurred during message translation",
939
- });
923
+ return res.status(400).send({ success: false, error: "An error occurred during message translation" });
940
924
  }
941
925
  } else {
942
926
  winston.debug("(wab) no command, no text --> skip");
943
- 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." });
944
928
  }
945
929
 
946
- return res.sendStatus(200);
947
-
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.69",
3
+ "version": "0.1.71",
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",
@@ -89,12 +89,21 @@ const path = require('path');
89
89
  }
90
90
 
91
91
  else if (tiledeskChannelMessage.metadata.type.startsWith('application')) {
92
- var doc = tiledeskChannelMessage.metadata.src;
92
+ //var doc = tiledeskChannelMessage.metadata.src;
93
+ var doc = tiledeskChannelMessage.metadata.downloadURL;
93
94
  whatsapp_message.type = 'document'
94
95
  whatsapp_message.document = {
95
96
  link: doc,
96
- caption: tiledeskChannelMessage.metadata.name || tiledeskChannelMessage.text
97
+ filename: tiledeskChannelMessage.metadata.name,
98
+ }
99
+
100
+ let index = tiledeskChannelMessage.text.indexOf(tiledeskChannelMessage.metadata.src);
101
+ if (index != -1) {
102
+ let length = tiledeskChannelMessage.metadata.src.length;
103
+ let caption = tiledeskChannelMessage.text.substring(index + length + 2);
104
+ whatsapp_message.document.caption = caption;
97
105
  }
106
+
98
107
  }
99
108
 
100
109
  else {
@@ -261,7 +270,6 @@ const path = require('path');
261
270
  }
262
271
  else if (tiledeskChannelMessage.attributes.attachment.template) {
263
272
  winston.debug("(wab) [Translator] template: ", tiledeskChannelMessage.attributes.attachment.template)
264
- console.log("(wab) [Translator] template: ", tiledeskChannelMessage.attributes.attachment.template)
265
273
 
266
274
  let template = tiledeskChannelMessage.attributes.attachment.template;
267
275
 
@@ -457,18 +465,19 @@ const path = require('path');
457
465
 
458
466
  // interactive message
459
467
  else if (whatsappChannelMessage.type == 'interactive') {
460
-
468
+
461
469
  // list reply
462
470
  if (whatsappChannelMessage.interactive.type == 'list_reply') {
463
471
  // action button
464
472
  if (whatsappChannelMessage.interactive.list_reply.id.startsWith("action")) {
465
473
  var tiledeskMessage = {
466
474
  senderFullname: from,
467
- text: ' ',
475
+ //text: ' ',
476
+ text: whatsappChannelMessage.interactive.list_reply.title,
468
477
  type: 'text',
469
478
  attributes: {
470
479
  action: whatsappChannelMessage.interactive.list_reply.id.substring(11),
471
- subtype: 'info'
480
+ //subtype: 'info'
472
481
  },
473
482
  channel: { name: TiledeskWhatsappTranslator.CHANNEL_NAME }
474
483
  }
@@ -477,7 +486,7 @@ const path = require('path');
477
486
  // quick reply button
478
487
  if (whatsappChannelMessage.interactive.list_reply.id.startsWith("quick")) {
479
488
  var tiledeskMessage = {
480
- text: whatsappChannelMessage.interactive.list_reply.id.substring(10),
489
+ text: whatsappChannelMessage.interactive.list_reply.title,
481
490
  senderFullname: from,
482
491
  channel: { name: TiledeskWhatsappTranslator.CHANNEL_NAME }
483
492
  }
@@ -491,11 +500,12 @@ const path = require('path');
491
500
  if (whatsappChannelMessage.interactive.button_reply.id.startsWith("action")) {
492
501
  var tiledeskMessage = {
493
502
  senderFullname: from,
494
- text: ' ',
503
+ //text: ' ',
504
+ text: whatsappChannelMessage.interactive.button_reply.title,
495
505
  type: 'text',
496
506
  attributes: {
497
507
  action: whatsappChannelMessage.interactive.button_reply.id.substring(11),
498
- subtype: 'info'
508
+ //subtype: 'info'
499
509
  },
500
510
  channel: { name: TiledeskWhatsappTranslator.CHANNEL_NAME }
501
511
  }
@@ -504,7 +514,8 @@ const path = require('path');
504
514
  // quick reply button
505
515
  if (whatsappChannelMessage.interactive.button_reply.id.startsWith("quick")) {
506
516
  var tiledeskMessage = {
507
- text: whatsappChannelMessage.interactive.button_reply.id.substring(10),
517
+ //text: whatsappChannelMessage.interactive.button_reply.id.substring(10),
518
+ text: whatsappChannelMessage.interactive.button_reply.title,
508
519
  senderFullname: from,
509
520
  channel: { name: TiledeskWhatsappTranslator.CHANNEL_NAME }
510
521
  }
@@ -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) {