@tiledesk/tiledesk-whatsapp-connector 0.1.69 → 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,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
|
-
|
|
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
|
@@ -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
|
-
|
|
118
|
+
winston.verbose("(Template Manager) Unrecognized Header: ", header_component)
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
}
|
|
@@ -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.
|
|
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) {
|