@tiledesk/tiledesk-whatsapp-connector 0.1.4 → 0.1.7
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
|
@@ -42,7 +42,7 @@ router.use(bodyParser.urlencoded({ extended: true }));
|
|
|
42
42
|
var API_URL = null;
|
|
43
43
|
var GRAPH_URL = null;
|
|
44
44
|
var BASE_URL = null;
|
|
45
|
-
var log =
|
|
45
|
+
var log = true;
|
|
46
46
|
|
|
47
47
|
const db = new KVBaseMongo(kvbase_collection);
|
|
48
48
|
/*
|
|
@@ -165,9 +165,9 @@ router.post('/update', async (req, res) => {
|
|
|
165
165
|
subscription_id: settings.subscriptionId,
|
|
166
166
|
}
|
|
167
167
|
if (log) {
|
|
168
|
-
console.log("Replacements: ", replacements);
|
|
168
|
+
console.log("Replacements: ", replacements);
|
|
169
169
|
}
|
|
170
|
-
|
|
170
|
+
|
|
171
171
|
var html = template(replacements);
|
|
172
172
|
res.send(html);
|
|
173
173
|
})
|
|
@@ -192,9 +192,9 @@ router.post('/update', async (req, res) => {
|
|
|
192
192
|
tdClient.subscribe(subscription_info).then((data) => {
|
|
193
193
|
let subscription = data;
|
|
194
194
|
if (log) {
|
|
195
|
-
console.log("\nSubscription: ", subscription)
|
|
195
|
+
console.log("\nSubscription: ", subscription)
|
|
196
196
|
}
|
|
197
|
-
|
|
197
|
+
|
|
198
198
|
let settings = {
|
|
199
199
|
project_id: projectId,
|
|
200
200
|
token: token,
|
|
@@ -223,9 +223,9 @@ router.post('/update', async (req, res) => {
|
|
|
223
223
|
subscription_id: settings.subscriptionId,
|
|
224
224
|
}
|
|
225
225
|
if (log) {
|
|
226
|
-
console.log("Replacements: ", replacements);
|
|
226
|
+
console.log("Replacements: ", replacements);
|
|
227
227
|
}
|
|
228
|
-
|
|
228
|
+
|
|
229
229
|
var html = template(replacements);
|
|
230
230
|
res.send(html);
|
|
231
231
|
})
|
|
@@ -240,7 +240,7 @@ router.post('/update', async (req, res) => {
|
|
|
240
240
|
router.post('/disconnect', async (req, res) => {
|
|
241
241
|
console.log("\n/disconnect")
|
|
242
242
|
if (log) {
|
|
243
|
-
console.log("/disconnect body: ", req.body)
|
|
243
|
+
console.log("/disconnect body: ", req.body)
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
let projectId = req.body.project_id;
|
|
@@ -277,9 +277,9 @@ router.post('/disconnect', async (req, res) => {
|
|
|
277
277
|
proxy_url: proxy_url,
|
|
278
278
|
}
|
|
279
279
|
if (log) {
|
|
280
|
-
console.log("Replacements: ", replacements);
|
|
280
|
+
console.log("Replacements: ", replacements);
|
|
281
281
|
}
|
|
282
|
-
|
|
282
|
+
|
|
283
283
|
var html = template(replacements);
|
|
284
284
|
res.send(html);
|
|
285
285
|
})
|
|
@@ -487,7 +487,7 @@ router.post("/webhook/:project_id", async (req, res) => {
|
|
|
487
487
|
// tdClient.getRequests
|
|
488
488
|
const tdChannel = new TiledeskChannel({ settings: settings, API_URL: API_URL })
|
|
489
489
|
const response = await tdChannel.send(tiledeskJsonMessage, message_info);
|
|
490
|
-
if (log) {
|
|
490
|
+
if (log) {
|
|
491
491
|
console.log("Send response: ", response)
|
|
492
492
|
}
|
|
493
493
|
|
|
@@ -550,7 +550,7 @@ function startApp(settings, callback) {
|
|
|
550
550
|
if (!settings.MONGODB_URL) {
|
|
551
551
|
throw new Error("settings.MONGODB_URL is mandatory");
|
|
552
552
|
}
|
|
553
|
-
|
|
553
|
+
|
|
554
554
|
if (!settings.API_URL) {
|
|
555
555
|
throw new Error("settings.API_URL is mandatory");
|
|
556
556
|
} else {
|
|
@@ -586,11 +586,6 @@ function startApp(settings, callback) {
|
|
|
586
586
|
|
|
587
587
|
function readHTMLFile(templateName, callback) {
|
|
588
588
|
console.log("Reading file: ", templateName)
|
|
589
|
-
console.log("appRoot: ", appRoot)
|
|
590
|
-
let file = appRoot + '/template' + templateName;
|
|
591
|
-
console.log("file: ", file);
|
|
592
|
-
console.log("*** appRoot: ", appRoot.toString());
|
|
593
|
-
console.log("type: ", typeof(appRoot))
|
|
594
589
|
fs.readFile(__dirname + '/template' + templateName, { encoding: 'utf-8' },
|
|
595
590
|
function(err, html) {
|
|
596
591
|
if (err) {
|
|
@@ -602,4 +597,4 @@ function readHTMLFile(templateName, callback) {
|
|
|
602
597
|
})
|
|
603
598
|
}
|
|
604
599
|
|
|
605
|
-
module.exports = { router: router, startApp: startApp};
|
|
600
|
+
module.exports = { router: router, startApp: startApp };
|
package/package.json
CHANGED
package/template/configure.html
CHANGED
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
<div>
|
|
44
44
|
|
|
45
45
|
<h1 style="margin-top: 0px; margin-bottom: 2px; min-width: 500px;">WhatsApp Business (Test)</h1>
|
|
46
|
-
<h7 style="color: rgb(140, 140, 140);">by Tiledesk (v. 0.1.
|
|
46
|
+
<h7 style="color: rgb(140, 140, 140);">by Tiledesk (v. 0.1.7)</h7>
|
|
47
47
|
|
|
48
48
|
{{#if wab_token}}
|
|
49
49
|
<div style="margin-top: 20px;">
|
|
@@ -35,10 +35,10 @@ describe('Test Translator\n', function() {
|
|
|
35
35
|
|
|
36
36
|
let tiledeskChannelMessage = {
|
|
37
37
|
text: 'Image Caption', // can be empty --> ""
|
|
38
|
+
type: 'image',
|
|
38
39
|
recipient: 'support-group-62c3f10152dc7400352bab0d-86a2293e-c7dc-4e62-89b1-ffe9bba7fd59-wab-104777398965560-tel393484506627',
|
|
39
40
|
metadata: {
|
|
40
41
|
src: 'https://fakeimageurl.com/',
|
|
41
|
-
type: 'image/png',
|
|
42
42
|
},
|
|
43
43
|
attributes: {
|
|
44
44
|
userFullname: 'John Doe'
|
|
@@ -66,10 +66,10 @@ describe('Test Translator\n', function() {
|
|
|
66
66
|
|
|
67
67
|
let tiledeskChannelMessage = {
|
|
68
68
|
text: 'Video Caption', // can be empty --> ""
|
|
69
|
+
type: 'video',
|
|
69
70
|
recipient: 'support-group-62c3f10152dc7400352bab0d-86a2293e-c7dc-4e62-89b1-ffe9bba7fd59-wab-104777398965560-393484506627',
|
|
70
71
|
metadata: {
|
|
71
|
-
src: 'https://fakevideourl.com/'
|
|
72
|
-
type: 'video/png',
|
|
72
|
+
src: 'https://fakevideourl.com/'
|
|
73
73
|
},
|
|
74
74
|
attributes: {
|
|
75
75
|
userFullname: 'John Doe'
|
|
@@ -97,10 +97,10 @@ describe('Test Translator\n', function() {
|
|
|
97
97
|
|
|
98
98
|
let tiledeskChannelMessage = {
|
|
99
99
|
text: 'Document Caption', // can be empty --> ""
|
|
100
|
+
type: 'application',
|
|
100
101
|
recipient: 'support-group-62c3f10152dc7400352bab0d-86a2293e-c7dc-4e62-89b1-ffe9bba7fd59-wab-104777398965560-tel393484506627',
|
|
101
102
|
metadata: {
|
|
102
|
-
src: 'https://fakedocumenturl.com/'
|
|
103
|
-
type: 'application/pdf',
|
|
103
|
+
src: 'https://fakedocumenturl.com/'
|
|
104
104
|
},
|
|
105
105
|
attributes: {
|
|
106
106
|
userFullname: 'John Doe'
|
|
@@ -283,13 +283,13 @@ describe('Test Translator\n', function() {
|
|
|
283
283
|
assert(tiledeskJsonMessage.senderFullname === fullname);
|
|
284
284
|
|
|
285
285
|
if (log) {
|
|
286
|
-
console.log("(test) tiledeskJsonMessage: ", tiledeskJsonMessage);
|
|
286
|
+
console.log("(test) tiledeskJsonMessage: ", tiledeskJsonMessage);
|
|
287
287
|
}
|
|
288
|
-
|
|
288
|
+
|
|
289
289
|
})
|
|
290
290
|
|
|
291
291
|
|
|
292
|
-
|
|
292
|
+
it("Translates a message with QUICK REPLY (button_reply) from Whatsapp to Tiledesk", function() {
|
|
293
293
|
|
|
294
294
|
let whatsappChannelMessage = {
|
|
295
295
|
type: "interactive",
|
|
@@ -314,7 +314,7 @@ describe('Test Translator\n', function() {
|
|
|
314
314
|
console.log("(test) tiledeskJsonMessage: ", tiledeskJsonMessage);
|
|
315
315
|
}
|
|
316
316
|
})
|
|
317
|
-
|
|
317
|
+
|
|
318
318
|
|
|
319
319
|
it("Translates a message with ACTION BUTTON (button_reply) from Whatsapp to Tiledesk", function() {
|
|
320
320
|
|
|
@@ -364,7 +364,7 @@ describe('Test Translator\n', function() {
|
|
|
364
364
|
const tiledeskJsonMessage = tlr.toTiledesk(fullname, media_url);
|
|
365
365
|
assert(tiledeskJsonMessage != null);
|
|
366
366
|
if (log) {
|
|
367
|
-
console.log("(test) tiledeskJsonMessage: ", tiledeskJsonMessage);
|
|
367
|
+
console.log("(test) tiledeskJsonMessage: ", tiledeskJsonMessage);
|
|
368
368
|
}
|
|
369
369
|
})
|
|
370
370
|
|
|
@@ -384,7 +384,7 @@ describe('Test Translator\n', function() {
|
|
|
384
384
|
const tiledeskJsonMessage = tlr.toTiledesk(fullname, media_url);
|
|
385
385
|
assert(tiledeskJsonMessage != null);
|
|
386
386
|
if (log) {
|
|
387
|
-
console.log("(test) tiledeskJsonMessage: ", tiledeskJsonMessage);
|
|
387
|
+
console.log("(test) tiledeskJsonMessage: ", tiledeskJsonMessage);
|
|
388
388
|
}
|
|
389
389
|
})
|
|
390
390
|
|
|
@@ -404,9 +404,9 @@ describe('Test Translator\n', function() {
|
|
|
404
404
|
const tiledeskJsonMessage = tlr.toTiledesk(fullname, media_url);
|
|
405
405
|
assert(tiledeskJsonMessage != null);
|
|
406
406
|
if (log) {
|
|
407
|
-
console.log("(test) tiledeskJsonMessage: ", tiledeskJsonMessage);
|
|
407
|
+
console.log("(test) tiledeskJsonMessage: ", tiledeskJsonMessage);
|
|
408
408
|
}
|
|
409
409
|
})
|
|
410
410
|
|
|
411
|
-
|
|
411
|
+
|
|
412
412
|
})
|
|
@@ -32,7 +32,7 @@ class TiledeskChannel {
|
|
|
32
32
|
throw new Error('config.API_URL is mandatory');
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
this.log =
|
|
35
|
+
this.log = true;
|
|
36
36
|
if (config.log) {
|
|
37
37
|
this.log = config.log;
|
|
38
38
|
}
|
|
@@ -104,8 +104,10 @@ class TiledeskChannel {
|
|
|
104
104
|
let request_id;
|
|
105
105
|
if (response.data.requests[0]) {
|
|
106
106
|
request_id = response.data.requests[0].request_id;
|
|
107
|
+
console.log("Old request id: ", request_id);
|
|
107
108
|
} else {
|
|
108
109
|
request_id = new_request_id;
|
|
110
|
+
console.log("New request id: ", request_id);
|
|
109
111
|
}
|
|
110
112
|
|
|
111
113
|
if (this.log) {
|
|
@@ -32,10 +32,15 @@ class TiledeskWhatsapp {
|
|
|
32
32
|
// this.media = config.channelMedia;
|
|
33
33
|
this.token = config.token;
|
|
34
34
|
this.GRAPH_URL = config.GRAPH_URL
|
|
35
|
+
|
|
36
|
+
this.log = false;
|
|
37
|
+
if (config.log) {
|
|
38
|
+
this.log = config.log;
|
|
39
|
+
}
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
async sendMessage(phone_number_id, message) {
|
|
38
|
-
if (log) {
|
|
43
|
+
if (this.log) {
|
|
39
44
|
console.log("[Tiledesk Whatsapp] Sending message...", message);
|
|
40
45
|
} else {
|
|
41
46
|
console.log("[Tiledesk Whatsapp] Sending message...");
|
|
@@ -58,7 +63,7 @@ class TiledeskWhatsapp {
|
|
|
58
63
|
}
|
|
59
64
|
|
|
60
65
|
async downloadMedia(mediaId) {
|
|
61
|
-
if (log) {
|
|
66
|
+
if (this.log) {
|
|
62
67
|
console.log("[Tiledesk Whatsapp] Download media with id: ", mediaId);
|
|
63
68
|
}
|
|
64
69
|
|
|
@@ -128,7 +133,7 @@ class TiledeskWhatsapp {
|
|
|
128
133
|
}
|
|
129
134
|
|
|
130
135
|
return await axios.post(url, form, request_config).then((response) => {
|
|
131
|
-
if (log) {
|
|
136
|
+
if (this.log) {
|
|
132
137
|
console.log("[Tiledesk Whatsapp] upload response: ", response.data);
|
|
133
138
|
}
|
|
134
139
|
|
|
@@ -146,7 +151,7 @@ class TiledeskWhatsapp {
|
|
|
146
151
|
|
|
147
152
|
// HTTP REQUEST
|
|
148
153
|
static async myrequest(options, callback, log) {
|
|
149
|
-
if (log) {
|
|
154
|
+
if (this.log) {
|
|
150
155
|
console.log("API URL: ", options.url);
|
|
151
156
|
console.log("** Options: ", options);
|
|
152
157
|
}
|
|
@@ -157,7 +162,7 @@ class TiledeskWhatsapp {
|
|
|
157
162
|
params: options.params,
|
|
158
163
|
headers: options.headers
|
|
159
164
|
}).then((res) => {
|
|
160
|
-
if (log) {
|
|
165
|
+
if (this.log) {
|
|
161
166
|
console.log("Response for url:", options.url);
|
|
162
167
|
console.log("Response headers:\n", res.headers);
|
|
163
168
|
}
|
|
@@ -33,7 +33,7 @@ class TiledeskWhatsappTranslator {
|
|
|
33
33
|
throw new Error('config.channelMessage is mandatory');
|
|
34
34
|
}
|
|
35
35
|
this.channelMessage = config.channelMessage;
|
|
36
|
-
this.log =
|
|
36
|
+
this.log = true;
|
|
37
37
|
if (config.log) {
|
|
38
38
|
this.log = true;
|
|
39
39
|
}
|
|
@@ -63,8 +63,9 @@ class TiledeskWhatsappTranslator {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
if (tiledeskChannelMessage.metadata) {
|
|
66
|
-
|
|
67
|
-
if (tiledeskChannelMessage.
|
|
66
|
+
|
|
67
|
+
if (tiledeskChannelMessage.type.startsWith('image')) {
|
|
68
|
+
//if (tiledeskChannelMessage.metadata.type.startsWith('image/')) {
|
|
68
69
|
var imgUrl = tiledeskChannelMessage.metadata.src;
|
|
69
70
|
whatsapp_message.type = 'image'
|
|
70
71
|
whatsapp_message.image = {
|
|
@@ -73,7 +74,8 @@ class TiledeskWhatsappTranslator {
|
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
if (tiledeskChannelMessage.
|
|
77
|
+
if (tiledeskChannelMessage.type.startsWith('video')) {
|
|
78
|
+
//if (tiledeskChannelMessage.metadata.type.startsWith('video/')) {
|
|
77
79
|
var videoUrl = tiledeskChannelMessage.metadata.src;
|
|
78
80
|
whatsapp_message.type = 'document'
|
|
79
81
|
whatsapp_message.document = {
|
|
@@ -89,7 +91,8 @@ class TiledeskWhatsappTranslator {
|
|
|
89
91
|
*/
|
|
90
92
|
}
|
|
91
93
|
|
|
92
|
-
if (tiledeskChannelMessage.
|
|
94
|
+
if (tiledeskChannelMessage.type.startsWith('application')) {
|
|
95
|
+
//if (tiledeskChannelMessage.metadata.type.startsWith('application/')) {
|
|
93
96
|
var doc = tiledeskChannelMessage.metadata.src;
|
|
94
97
|
whatsapp_message.type = 'document'
|
|
95
98
|
whatsapp_message.document = {
|