@tiledesk/tiledesk-whatsapp-connector 0.1.18 → 0.1.20
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
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const express = require("express");
|
|
3
|
-
const app = express();
|
|
4
3
|
const router = express.Router();
|
|
5
4
|
const bodyParser = require("body-parser");
|
|
6
5
|
const appRoot = require('app-root-path');
|
|
@@ -174,7 +173,7 @@ router.get('/configure', async (req, res) => {
|
|
|
174
173
|
let token = "";
|
|
175
174
|
|
|
176
175
|
projectId = req.query.project_id;
|
|
177
|
-
token = req.query.token
|
|
176
|
+
token = req.query.token;
|
|
178
177
|
|
|
179
178
|
let CONTENT_KEY = "whatsapp-" + projectId;
|
|
180
179
|
|
|
@@ -585,6 +584,10 @@ router.post("/webhook/:project_id", async (req, res) => {
|
|
|
585
584
|
|
|
586
585
|
const filename = await util.downloadMedia(media.id);
|
|
587
586
|
console.log("File position: ", filename);
|
|
587
|
+
if (!filename) {
|
|
588
|
+
console.log("Unable to download media. Message not sent.");
|
|
589
|
+
res.status(500).send({ success: false, error: "unable to download media" })
|
|
590
|
+
}
|
|
588
591
|
let file_path = path.join(__dirname, 'tmp', filename);
|
|
589
592
|
|
|
590
593
|
const image_url = await util.uploadMedia(file_path, "images");
|
|
@@ -599,6 +602,10 @@ router.post("/webhook/:project_id", async (req, res) => {
|
|
|
599
602
|
|
|
600
603
|
const filename = await util.downloadMedia(media.id);
|
|
601
604
|
console.log("File position: ", filename);
|
|
605
|
+
if (!filename) {
|
|
606
|
+
console.log("Unable to download media. Message not sent.");
|
|
607
|
+
res.status(500).send({ success: false, error: "unable to download media" })
|
|
608
|
+
}
|
|
602
609
|
let file_path = path.join(__dirname, 'tmp', filename);
|
|
603
610
|
|
|
604
611
|
|
|
@@ -613,6 +620,10 @@ router.post("/webhook/:project_id", async (req, res) => {
|
|
|
613
620
|
|
|
614
621
|
const filename = await util.downloadMedia(media.id);
|
|
615
622
|
console.log("File position: ", filename);
|
|
623
|
+
if (!filename) {
|
|
624
|
+
console.log("Unable to download media. Message not sent.");
|
|
625
|
+
res.status(500).send({ success: false, error: "unable to download media" })
|
|
626
|
+
}
|
|
616
627
|
let file_path = path.join(__dirname, 'tmp', filename);
|
|
617
628
|
|
|
618
629
|
const media_url = await util.uploadMedia(file_path, "files");
|
|
@@ -650,13 +661,22 @@ router.get("/webhook/:project_id", async (req, res) => {
|
|
|
650
661
|
* UPDATE YOUR VERIFY TOKEN
|
|
651
662
|
*This will be the Verify Token value when you set up webhook
|
|
652
663
|
**/
|
|
664
|
+
console.log("\nVerify the webhook: ", req);
|
|
665
|
+
console.log("\req.query: ", req.query);
|
|
653
666
|
|
|
654
667
|
// Parse params from the webhook verification request
|
|
655
668
|
let mode = req.query["hub.mode"];
|
|
656
669
|
let token = req.query["hub.verify_token"];
|
|
657
670
|
let challenge = req.query["hub.challenge"];
|
|
658
671
|
|
|
672
|
+
console.log("**********")
|
|
673
|
+
console.log("mode: ", mode)
|
|
674
|
+
console.log("token: ", token)
|
|
675
|
+
console.log("challenge: ", challenge)
|
|
676
|
+
console.log("**********")
|
|
677
|
+
|
|
659
678
|
let CONTENT_KEY = "whatsapp-" + req.params.project_id;
|
|
679
|
+
console.log("\CONTENT_KEY: ", CONTENT_KEY);
|
|
660
680
|
|
|
661
681
|
let settings = await db.get(CONTENT_KEY);
|
|
662
682
|
|
|
@@ -666,17 +686,25 @@ router.get("/webhook/:project_id", async (req, res) => {
|
|
|
666
686
|
} else {
|
|
667
687
|
let VERIFY_TOKEN = settings.verify_token;
|
|
668
688
|
|
|
689
|
+
console.log("token: ", token);
|
|
690
|
+
console.log("verify token: ", VERIFY_TOKEN);
|
|
691
|
+
|
|
669
692
|
// Check if a token and mode were sent
|
|
670
693
|
if (mode && token) {
|
|
671
694
|
// Check the mode and token sent are correct
|
|
672
695
|
if (mode === "subscribe" && token === VERIFY_TOKEN) {
|
|
696
|
+
|
|
673
697
|
// Respond with 200 OK and challenge token from the request
|
|
674
698
|
console.log("WEBHOOK_VERIFIED");
|
|
675
699
|
res.status(200).send(challenge);
|
|
676
700
|
} else {
|
|
677
701
|
// Responds with '403 Forbidden' if verify tokens do not match
|
|
702
|
+
console.error("mode is not 'subscribe' or token do not match");
|
|
678
703
|
res.sendStatus(403);
|
|
679
704
|
}
|
|
705
|
+
} else {
|
|
706
|
+
console.error("mode or token undefined");
|
|
707
|
+
res.status(400).send("impossible to verify the webhook: mode or token undefined.")
|
|
680
708
|
}
|
|
681
709
|
|
|
682
710
|
}
|
|
@@ -729,7 +757,7 @@ function startApp(settings, callback) {
|
|
|
729
757
|
|
|
730
758
|
db.connect(settings.MONGODB_URL, () => {
|
|
731
759
|
console.log("KVBaseMongo successfully connected.");
|
|
732
|
-
|
|
760
|
+
|
|
733
761
|
if (callback) {
|
|
734
762
|
callback();
|
|
735
763
|
}
|
package/package.json
CHANGED
package/template/detail.html
CHANGED
|
@@ -158,7 +158,7 @@
|
|
|
158
158
|
|
|
159
159
|
|
|
160
160
|
<div>
|
|
161
|
-
<h7>Receive Whatsapp
|
|
161
|
+
<h7>Receive Whatsapp conversations in your Tiledesk dashboard. Seamlessly Chat with your targeted audience on Whatsapp right from the Tiledesk dashboard.</h7>
|
|
162
162
|
|
|
163
163
|
<ul style="margin-top: 10px; padding: 0px;">
|
|
164
164
|
<div class="list-element">
|
|
@@ -8,7 +8,6 @@ class TiledeskSubscriptionClient {
|
|
|
8
8
|
* @example
|
|
9
9
|
* const { TiledeskSubscriptionClient } = require('tiledesk-subscription-client');
|
|
10
10
|
* const tdClient = new TiledeskSubscriptionClient({API_URL: tiledeskApiUrl, token: jwt_token, log: log});
|
|
11
|
-
*
|
|
12
11
|
* @param {Object} config JSON configuration.
|
|
13
12
|
* @param {string} config.API_URL Mandatory. The Tiledesk api url.
|
|
14
13
|
* @param {string} config.token Optional. Token required for authentication.
|
|
@@ -73,17 +73,17 @@ const path = require('path');
|
|
|
73
73
|
if ((tiledeskChannelMessage.metadata.type && tiledeskChannelMessage.metadata.type.startsWith('image')) || tiledeskChannelMessage.type.startsWith('image')) {
|
|
74
74
|
|
|
75
75
|
var imgUrl = tiledeskChannelMessage.metadata.src;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
whatsapp_message.type = 'image'
|
|
77
|
+
whatsapp_message.image = {
|
|
78
|
+
link: imgUrl,
|
|
79
|
+
caption: text
|
|
80
|
+
}
|
|
81
|
+
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
|
|
85
84
|
|
|
86
|
-
|
|
85
|
+
|
|
86
|
+
else if ((tiledeskChannelMessage.metadata.type && tiledeskChannelMessage.metadata.type.startsWith('video')) || tiledeskChannelMessage.type.startsWith('video')) {
|
|
87
87
|
//if (tiledeskChannelMessage.metadata.type.startsWith('video/')) {
|
|
88
88
|
var videoUrl = tiledeskChannelMessage.metadata.src;
|
|
89
89
|
whatsapp_message.type = 'video'
|
|
Binary file
|
|
Binary file
|