@tiledesk/tiledesk-whatsapp-connector 0.1.18 → 0.1.19

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
 
@@ -650,13 +649,22 @@ router.get("/webhook/:project_id", async (req, res) => {
650
649
  * UPDATE YOUR VERIFY TOKEN
651
650
  *This will be the Verify Token value when you set up webhook
652
651
  **/
652
+ console.log("\nVerify the webhook: ", req);
653
+ console.log("\req.query: ", req.query);
653
654
 
654
655
  // Parse params from the webhook verification request
655
656
  let mode = req.query["hub.mode"];
656
657
  let token = req.query["hub.verify_token"];
657
658
  let challenge = req.query["hub.challenge"];
659
+
660
+ console.log("**********")
661
+ console.log("mode: ", mode)
662
+ console.log("token: ", token)
663
+ console.log("challenge: ", challenge)
664
+ console.log("**********")
658
665
 
659
666
  let CONTENT_KEY = "whatsapp-" + req.params.project_id;
667
+ console.log("\CONTENT_KEY: ", CONTENT_KEY);
660
668
 
661
669
  let settings = await db.get(CONTENT_KEY);
662
670
 
@@ -666,17 +674,25 @@ router.get("/webhook/:project_id", async (req, res) => {
666
674
  } else {
667
675
  let VERIFY_TOKEN = settings.verify_token;
668
676
 
677
+ console.log("token: ", token);
678
+ console.log("verify token: ", VERIFY_TOKEN);
679
+
669
680
  // Check if a token and mode were sent
670
681
  if (mode && token) {
671
682
  // Check the mode and token sent are correct
672
683
  if (mode === "subscribe" && token === VERIFY_TOKEN) {
684
+
673
685
  // Respond with 200 OK and challenge token from the request
674
686
  console.log("WEBHOOK_VERIFIED");
675
687
  res.status(200).send(challenge);
676
688
  } else {
677
689
  // Responds with '403 Forbidden' if verify tokens do not match
690
+ console.error("mode is not 'subscribe' or token do not match");
678
691
  res.sendStatus(403);
679
692
  }
693
+ } else {
694
+ console.error("mode or token undefined");
695
+ res.status(400).send("impossible to verify the webhook: mode or token undefined.")
680
696
  }
681
697
 
682
698
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-whatsapp-connector",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "description": "Tiledesk Whatsapp connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -158,7 +158,7 @@
158
158
 
159
159
 
160
160
  <div>
161
- <h7>Receive Whatsapp bot conversations in your Tiledesk dashboard. Seamlessly Chat with your targeted audience on Whatsapp right from the Tiledesk dashboard.</h7>
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
- whatsapp_message.type = 'image'
77
- whatsapp_message.image = {
78
- link: imgUrl,
79
- caption: text
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
- else if ((tiledeskChannelMessage.metadata.type && tiledeskChannelMessage.metadata.type.startsWith('video')) || tiledeskChannelMessage.type.startsWith('video')) {
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