@tiledesk/tiledesk-whatsapp-connector 1.0.17 → 1.0.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/.env +2 -0
- package/index.js +10 -26
- package/package.json +1 -1
- package/publish.sh +23 -1
- package/routes/api.js +5 -9
- package/tiledesk/TiledeskWhatsapp.js +8 -14
- package/tiledesk/TiledeskWhatsappTranslator.js +1 -1
package/.env
ADDED
package/index.js
CHANGED
|
@@ -57,7 +57,6 @@ let APPS_API_URL = null;
|
|
|
57
57
|
let REDIS_HOST = null;
|
|
58
58
|
let REDIS_PORT = null;
|
|
59
59
|
let REDIS_PASSWORD = null;
|
|
60
|
-
let BASE_FILE_URL = null;
|
|
61
60
|
let AMQP_MANAGER_URL = null;
|
|
62
61
|
let JOB_TOPIC_EXCHANGE = null;
|
|
63
62
|
let BRAND_NAME = null;
|
|
@@ -348,8 +347,7 @@ router.post("/update", async (req, res) => {
|
|
|
348
347
|
const twClient = new TiledeskWhatsapp({
|
|
349
348
|
token: settings.wab_token,
|
|
350
349
|
GRAPH_URL: GRAPH_URL,
|
|
351
|
-
API_URL: API_URL
|
|
352
|
-
BASE_FILE_URL: BASE_FILE_URL,
|
|
350
|
+
API_URL: API_URL
|
|
353
351
|
});
|
|
354
352
|
|
|
355
353
|
await twClient.getBusinessAccountInfo(business_account_id).then((info) => {
|
|
@@ -477,8 +475,7 @@ router.post("/getinfo", async (req, res) => {
|
|
|
477
475
|
const twClient = new TiledeskWhatsapp({
|
|
478
476
|
token: settings.wab_token,
|
|
479
477
|
GRAPH_URL: GRAPH_URL,
|
|
480
|
-
API_URL: API_URL
|
|
481
|
-
BASE_FILE_URL: BASE_FILE_URL,
|
|
478
|
+
API_URL: API_URL
|
|
482
479
|
});
|
|
483
480
|
|
|
484
481
|
await twClient.getBusinessAccountInfo(settings.business_account_id).then((info) => {
|
|
@@ -687,8 +684,7 @@ router.post("/tiledesk", async (req, res) => {
|
|
|
687
684
|
const twClient = new TiledeskWhatsapp({
|
|
688
685
|
token: settings.wab_token,
|
|
689
686
|
GRAPH_URL: GRAPH_URL,
|
|
690
|
-
API_URL: API_URL
|
|
691
|
-
BASE_FILE_URL: BASE_FILE_URL,
|
|
687
|
+
API_URL: API_URL
|
|
692
688
|
});
|
|
693
689
|
twClient.sendMessage(phone_number_id, whatsappJsonMessage).then((response) => {
|
|
694
690
|
winston.verbose(
|
|
@@ -739,8 +735,7 @@ router.post("/tiledesk", async (req, res) => {
|
|
|
739
735
|
const twClient = new TiledeskWhatsapp({
|
|
740
736
|
token: wab_token,
|
|
741
737
|
GRAPH_URL: GRAPH_URL,
|
|
742
|
-
API_URL: API_URL
|
|
743
|
-
BASE_FILE_URL: BASE_FILE_URL,
|
|
738
|
+
API_URL: API_URL
|
|
744
739
|
});
|
|
745
740
|
|
|
746
741
|
twClient.sendMessage(phone_number_id, whatsappJsonMessage).then((response) => {
|
|
@@ -850,9 +845,9 @@ router.post('/webhook', async (req, res) => {
|
|
|
850
845
|
|
|
851
846
|
const util = new TiledeskWhatsapp({
|
|
852
847
|
token: settings.wab_token,
|
|
848
|
+
ID_PROJECT: settings.project_id,
|
|
853
849
|
GRAPH_URL: GRAPH_URL,
|
|
854
|
-
API_URL: API_URL
|
|
855
|
-
BASE_FILE_URL: BASE_FILE_URL,
|
|
850
|
+
API_URL: API_URL
|
|
856
851
|
});
|
|
857
852
|
|
|
858
853
|
const media = whatsappChannelMessage[whatsappChannelMessage.type];
|
|
@@ -1026,9 +1021,9 @@ router.post("/webhook/:project_id", async (req, res) => {
|
|
|
1026
1021
|
let media;
|
|
1027
1022
|
const util = new TiledeskWhatsapp({
|
|
1028
1023
|
token: settings.wab_token,
|
|
1024
|
+
ID_PROJECT: settings.project_id,
|
|
1029
1025
|
GRAPH_URL: GRAPH_URL,
|
|
1030
|
-
API_URL: API_URL
|
|
1031
|
-
BASE_FILE_URL: BASE_FILE_URL,
|
|
1026
|
+
API_URL: API_URL
|
|
1032
1027
|
});
|
|
1033
1028
|
|
|
1034
1029
|
if (whatsappChannelMessage.type == "image") {
|
|
@@ -1482,8 +1477,7 @@ router.get("/direct/tiledesk", async (req, res) => {
|
|
|
1482
1477
|
const twClient = new TiledeskWhatsapp({
|
|
1483
1478
|
token: settings.wab_token,
|
|
1484
1479
|
GRAPH_URL: GRAPH_URL,
|
|
1485
|
-
API_URL: API_URL
|
|
1486
|
-
BASE_FILE_URL: BASE_FILE_URL,
|
|
1480
|
+
API_URL: API_URL
|
|
1487
1481
|
});
|
|
1488
1482
|
|
|
1489
1483
|
let whatsappJsonMessage = await tlr.toWhatsapp(
|
|
@@ -1538,8 +1532,7 @@ router.post("/tiledesk/broadcast", async (req, res) => {
|
|
|
1538
1532
|
const twClient = new TiledeskWhatsapp({
|
|
1539
1533
|
token: settings.wab_token,
|
|
1540
1534
|
GRAPH_URL: GRAPH_URL,
|
|
1541
|
-
API_URL: API_URL
|
|
1542
|
-
BASE_FILE_URL: BASE_FILE_URL,
|
|
1535
|
+
API_URL: API_URL
|
|
1543
1536
|
});
|
|
1544
1537
|
|
|
1545
1538
|
let response = await tm.getTemplates();
|
|
@@ -1619,14 +1612,6 @@ async function startApp(settings, callback) {
|
|
|
1619
1612
|
winston.info("(wab) API_URL: " + API_URL);
|
|
1620
1613
|
}
|
|
1621
1614
|
|
|
1622
|
-
if (!settings.BASE_FILE_URL) {
|
|
1623
|
-
winston.error("(wab) BASE_FILE_URL is mandatory. Exit...");
|
|
1624
|
-
return callback("Missing parameter: BASE_FILE_URL");
|
|
1625
|
-
} else {
|
|
1626
|
-
BASE_FILE_URL = settings.BASE_FILE_URL;
|
|
1627
|
-
winston.info("(wab) BASE_FILE_URL: " + BASE_FILE_URL);
|
|
1628
|
-
}
|
|
1629
|
-
|
|
1630
1615
|
if (!settings.BASE_URL) {
|
|
1631
1616
|
winston.error("(wab) BASE_URL is mandatory. Exit...");
|
|
1632
1617
|
return callback("Missing parameter: BASE_URL");
|
|
@@ -1743,7 +1728,6 @@ async function startApp(settings, callback) {
|
|
|
1743
1728
|
DB: db,
|
|
1744
1729
|
API_URL: API_URL,
|
|
1745
1730
|
GRAPH_URL: GRAPH_URL,
|
|
1746
|
-
BASE_FILE_URL: BASE_FILE_URL,
|
|
1747
1731
|
AMQP_MANAGER_URL: AMQP_MANAGER_URL,
|
|
1748
1732
|
JOB_TOPIC_EXCHANGE: JOB_TOPIC_EXCHANGE,
|
|
1749
1733
|
},
|
package/package.json
CHANGED
package/publish.sh
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Load .env variables
|
|
2
|
+
if [ -f .env ]; then
|
|
3
|
+
export $(grep -v '^#' .env | xargs)
|
|
4
|
+
fi
|
|
5
|
+
|
|
6
|
+
# Check if the token is set
|
|
7
|
+
if [ -z "$NPM_PUBLISH_TOKEN" ]; then
|
|
8
|
+
echo "⚠️ Missing NPM_PUBLISH_TOKEN in environment."
|
|
9
|
+
echo "You can speed up the process by setting the environment variable with your publish token."
|
|
10
|
+
read -p "Do you want to continue with manual login? (y/n): " choice
|
|
11
|
+
if [[ "$choice" != "y" && "$choice" != "Y" ]]; then
|
|
12
|
+
echo "❌ Deploy aborted."
|
|
13
|
+
exit 1
|
|
14
|
+
else
|
|
15
|
+
echo "💡 Proceed with 'npm login' manually..."
|
|
16
|
+
npm login
|
|
17
|
+
fi
|
|
18
|
+
else
|
|
19
|
+
# Create temporary .npmrc with the token
|
|
20
|
+
echo "//registry.npmjs.org/:_authToken=${NPM_PUBLISH_TOKEN}" > ~/.npmrc
|
|
21
|
+
fi
|
|
22
|
+
|
|
23
|
+
npm version patch
|
|
2
24
|
version=`node -e 'console.log(require("./package.json").version)'`
|
|
3
25
|
echo "version $version"
|
|
4
26
|
|
package/routes/api.js
CHANGED
|
@@ -15,7 +15,6 @@ const Utils = require('../tiledesk/Utils');
|
|
|
15
15
|
let db = null;
|
|
16
16
|
let API_URL = null;
|
|
17
17
|
let GRAPH_URL = null;
|
|
18
|
-
let BASE_FILE_URL = null;
|
|
19
18
|
let AMQP_MANAGER_URL = null;
|
|
20
19
|
let JOB_TOPIC_EXCHANGE = null;
|
|
21
20
|
let utils = null;
|
|
@@ -77,7 +76,11 @@ router.post('/customer/io', async (req, res) => {
|
|
|
77
76
|
winston.debug("[ CUSTOMER.IO ] whatsappJsonMessage: ", JSON.stringify(whatsappJsonMessage, null, 2));
|
|
78
77
|
|
|
79
78
|
if (whatsappJsonMessage) {
|
|
80
|
-
const twClient = new TiledeskWhatsapp({
|
|
79
|
+
const twClient = new TiledeskWhatsapp({
|
|
80
|
+
token: settings.wab_token,
|
|
81
|
+
GRAPH_URL: GRAPH_URL,
|
|
82
|
+
API_URL: API_URL
|
|
83
|
+
});
|
|
81
84
|
|
|
82
85
|
twClient.sendMessage(phone_number_id, whatsappJsonMessage).then((response) => {
|
|
83
86
|
winston.verbose("(wab) Message sent to WhatsApp! " + response.status + " " + response.statusText);
|
|
@@ -294,13 +297,6 @@ async function startRoute(settings, callback) {
|
|
|
294
297
|
winston.info("(wab api) API_URL: " + API_URL);
|
|
295
298
|
}
|
|
296
299
|
|
|
297
|
-
if (!settings.BASE_FILE_URL) {
|
|
298
|
-
winston.error("(wab api) BASE_FILE_URL is mandatory. Exit...");
|
|
299
|
-
return callback('Missing parameter: BASE_FILE_URL');
|
|
300
|
-
} else {
|
|
301
|
-
BASE_FILE_URL = settings.BASE_FILE_URL;
|
|
302
|
-
winston.info("(wab api) BASE_FILE_URL: " + BASE_FILE_URL);
|
|
303
|
-
}
|
|
304
300
|
|
|
305
301
|
if (!settings.AMQP_MANAGER_URL) {
|
|
306
302
|
winston.error("(wab api) AMQP_MANAGER_URL is mandatory (?). Exit...");
|
|
@@ -36,15 +36,16 @@ class TiledeskWhatsapp {
|
|
|
36
36
|
throw new Error('config.API_URL is mandatory');
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
if (!config.
|
|
40
|
-
throw new Error('config.
|
|
39
|
+
if (!config.ID_PROJECT) {
|
|
40
|
+
throw new Error('config.ID_PROJECT is mandatory');
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// this.media = config.channelMedia;
|
|
44
44
|
this.token = config.token;
|
|
45
45
|
this.GRAPH_URL = config.GRAPH_URL
|
|
46
46
|
this.api_url = config.API_URL;
|
|
47
|
-
this.
|
|
47
|
+
this.id_project = config.ID_PROJECT;
|
|
48
|
+
|
|
48
49
|
|
|
49
50
|
this.log = false;
|
|
50
51
|
if (config.log) {
|
|
@@ -147,8 +148,8 @@ class TiledeskWhatsapp {
|
|
|
147
148
|
})
|
|
148
149
|
}
|
|
149
150
|
|
|
150
|
-
async uploadMedia(path
|
|
151
|
-
let url = this.
|
|
151
|
+
async uploadMedia(path) {
|
|
152
|
+
let url = `${this.api_url}/${this.id_project}/files/chat`;
|
|
152
153
|
winston.debug("(wab) [TiledeskWhatsapp] Uploading file...");
|
|
153
154
|
|
|
154
155
|
const form = new FormData();
|
|
@@ -164,15 +165,8 @@ class TiledeskWhatsapp {
|
|
|
164
165
|
return await axios.post(url, form, request_config).then((response) => {
|
|
165
166
|
|
|
166
167
|
winston.debug("(wab) [TiledeskWhatsapp] upload response: ", response.data);
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
let image_url = this.base_file_url + "/images/?path=" + response.data.filename;
|
|
170
|
-
return image_url;
|
|
171
|
-
} else {
|
|
172
|
-
//let file_url = "https://tiledesk-server-pre.herokuapp.com/files/download?path=" + response.data.filename;
|
|
173
|
-
let file_url = this.base_file_url + "/files/download?path=" + response.data.filename;
|
|
174
|
-
return file_url;
|
|
175
|
-
}
|
|
168
|
+
let file_url = this.api_url + "/files/download?path=" + response.data.filename;
|
|
169
|
+
return file_url;
|
|
176
170
|
|
|
177
171
|
}).catch((err) => {
|
|
178
172
|
if (err.response?.status === 413) {
|
|
@@ -727,7 +727,7 @@ const path = require('path');
|
|
|
727
727
|
if (!value || key === 'phone_number') continue;
|
|
728
728
|
|
|
729
729
|
if (key.startsWith('header')) {
|
|
730
|
-
const type = detectMediaType(value);
|
|
730
|
+
const type = this.detectMediaType(value);
|
|
731
731
|
|
|
732
732
|
if (type === "text") {
|
|
733
733
|
header_params.push({
|