@tiledesk/tiledesk-whatsapp-connector 0.1.71 → 0.1.73
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 +16 -5
- package/package.json +1 -1
- package/test/test_translate_whatsapp.js +9 -2
package/index.js
CHANGED
|
@@ -583,7 +583,7 @@ router.post("/tiledesk/broadcast", async (req, res) => {
|
|
|
583
583
|
tiledeskChannelMessage,
|
|
584
584
|
whatsapp_receiver
|
|
585
585
|
);
|
|
586
|
-
winston.
|
|
586
|
+
winston.verbose("customTiledeskJsonMessage: ", customTiledeskJsonMessage);
|
|
587
587
|
|
|
588
588
|
let whatsappJsonMessage = await tlr.toWhatsapp(
|
|
589
589
|
customTiledeskJsonMessage,
|
|
@@ -724,7 +724,7 @@ router.post("/tiledesk", async (req, res) => {
|
|
|
724
724
|
var tiledeskChannelMessage = req.body.payload;
|
|
725
725
|
winston.debug("(wab) tiledeskChannelMessage: ", tiledeskChannelMessage);
|
|
726
726
|
var project_id = req.body.payload.id_project;
|
|
727
|
-
|
|
727
|
+
|
|
728
728
|
// get settings from mongo
|
|
729
729
|
let CONTENT_KEY = "whatsapp-" + project_id;
|
|
730
730
|
let settings = await db.get(CONTENT_KEY);
|
|
@@ -935,14 +935,20 @@ router.post("/webhook/:project_id", async (req, res) => {
|
|
|
935
935
|
// Parse the request body from the POST
|
|
936
936
|
let project_id = req.params.project_id;
|
|
937
937
|
winston.verbose("(wab) Message received from WhatsApp");
|
|
938
|
-
|
|
938
|
+
|
|
939
939
|
// Check the Incoming webhook message
|
|
940
940
|
// info on WhatsApp text message payload: https://developers.facebook.com/docs/whatsapp/cloud-api/webhooks/payload-examples#text-messages
|
|
941
941
|
if (req.body.object) {
|
|
942
|
-
|
|
942
|
+
|
|
943
943
|
let CONTENT_KEY = "whatsapp-" + project_id;
|
|
944
944
|
let settings = await db.get(CONTENT_KEY);
|
|
945
945
|
winston.debug("(wab) settings: ", settings);
|
|
946
|
+
|
|
947
|
+
if (!settings) {
|
|
948
|
+
winston.warn("(wab) settings not found for project_id: " + project_id);
|
|
949
|
+
winston.warn("(wab) settings not found for request: ", req.body)
|
|
950
|
+
return res.sendStatus(200);
|
|
951
|
+
}
|
|
946
952
|
|
|
947
953
|
const tdClient = new TiledeskClient({
|
|
948
954
|
projectId: project_id,
|
|
@@ -966,6 +972,11 @@ router.post("/webhook/:project_id", async (req, res) => {
|
|
|
966
972
|
winston.verbose("(wab) Skip system message");
|
|
967
973
|
return res.sendStatus(200);
|
|
968
974
|
}
|
|
975
|
+
|
|
976
|
+
if (req.body.entry[0].id !== settings.business_account_id) {
|
|
977
|
+
winston.verbose("(wab) Skip message with waba that not belong to Tiledesk project id");
|
|
978
|
+
return res.sendStatus(200);
|
|
979
|
+
}
|
|
969
980
|
|
|
970
981
|
let whatsappChannelMessage =
|
|
971
982
|
req.body.entry[0].changes[0].value.messages[0];
|
|
@@ -1027,7 +1038,7 @@ router.post("/webhook/:project_id", async (req, res) => {
|
|
|
1027
1038
|
lastname: " ",
|
|
1028
1039
|
},
|
|
1029
1040
|
};
|
|
1030
|
-
|
|
1041
|
+
|
|
1031
1042
|
let tiledeskJsonMessage;
|
|
1032
1043
|
|
|
1033
1044
|
/*
|
package/package.json
CHANGED
|
@@ -96,10 +96,11 @@ describe('Test Translator\n', function() {
|
|
|
96
96
|
it("Translates a message containing a DOCUMENT from Tiledesk to Whatsapp", function() {
|
|
97
97
|
|
|
98
98
|
let tiledeskChannelMessage = {
|
|
99
|
-
text: 'Document Caption', // can be empty --> ""
|
|
99
|
+
text: '[fakedocument.pdf](https://fakedocumenturl.com/)\n' + 'Document Caption', // can be empty --> ""
|
|
100
100
|
type: 'application',
|
|
101
101
|
recipient: 'support-group-62c3f10152dc7400352bab0d-86a2293e-wab-104777398965560-393484506627',
|
|
102
102
|
metadata: {
|
|
103
|
+
downloadURL: 'https://fakedocumenturl.com/',
|
|
103
104
|
src: 'https://fakedocumenturl.com/',
|
|
104
105
|
name: "fakedocument.pdf",
|
|
105
106
|
type: 'application/pdf'
|
|
@@ -119,7 +120,12 @@ describe('Test Translator\n', function() {
|
|
|
119
120
|
assert(!whatsappJsonMessage.text);
|
|
120
121
|
assert(whatsappJsonMessage.document);
|
|
121
122
|
assert(whatsappJsonMessage.document.link === tiledeskChannelMessage.metadata.src);
|
|
122
|
-
assert(whatsappJsonMessage.document.
|
|
123
|
+
assert(whatsappJsonMessage.document.filename === tiledeskChannelMessage.metadata.name);
|
|
124
|
+
let index = tiledeskChannelMessage.text.indexOf(tiledeskChannelMessage.metadata.src);
|
|
125
|
+
if (index != -1) {
|
|
126
|
+
let length = tiledeskChannelMessage.metadata.src.length;
|
|
127
|
+
assert(whatsappJsonMessage.document.caption === tiledeskChannelMessage.text.substring(index + length + 2));
|
|
128
|
+
}
|
|
123
129
|
if (log) {
|
|
124
130
|
console.log("(test) whatsappJsonMessage: ", whatsappJsonMessage);
|
|
125
131
|
}
|
|
@@ -319,6 +325,7 @@ describe('Test Translator\n', function() {
|
|
|
319
325
|
assert(tlr != null);
|
|
320
326
|
const tiledeskJsonMessage = await tlr.toTiledesk(whatsappChannelMessage, fullname, null)
|
|
321
327
|
assert(tiledeskJsonMessage != null);
|
|
328
|
+
console.log("(test) tiledeskJsonMessage: ", tiledeskJsonMessage);
|
|
322
329
|
assert(tiledeskJsonMessage.channel.name === TiledeskWhatsappTranslator.CHANNEL_NAME);
|
|
323
330
|
assert(tiledeskJsonMessage.text === ' ');
|
|
324
331
|
assert(tiledeskJsonMessage.type === 'text');
|