@tiledesk/tiledesk-whatsapp-connector 0.1.22 → 0.1.23
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
|
@@ -28,7 +28,7 @@ var API_URL = null;
|
|
|
28
28
|
var GRAPH_URL = null;
|
|
29
29
|
var BASE_URL = null;
|
|
30
30
|
var APPS_API_URL = null;
|
|
31
|
-
var log =
|
|
31
|
+
var log = false;
|
|
32
32
|
|
|
33
33
|
const db = new KVBaseMongo(kvbase_collection);
|
|
34
34
|
|
|
@@ -426,9 +426,9 @@ router.post('/disconnect', async (req, res) => {
|
|
|
426
426
|
router.post('/tiledesk', async (req, res) => {
|
|
427
427
|
|
|
428
428
|
console.log("\n/tiledesk")
|
|
429
|
-
if (log) {
|
|
430
|
-
|
|
431
|
-
}
|
|
429
|
+
//if (log) {
|
|
430
|
+
//console.log("/tiledesk ---> tiledeskChannelMessage: " + JSON.stringify(req.body.payload));
|
|
431
|
+
//}
|
|
432
432
|
|
|
433
433
|
var tiledeskChannelMessage = req.body.payload;
|
|
434
434
|
//console.log("(TILEDESK) Payload: ", JSON.stringify(req.body.payload));
|
|
@@ -445,7 +445,9 @@ router.post('/tiledesk', async (req, res) => {
|
|
|
445
445
|
console.log("(TILEDESK) TEXT: ", text);
|
|
446
446
|
|
|
447
447
|
var attributes = req.body.payload.attributes;
|
|
448
|
-
|
|
448
|
+
if (log) {
|
|
449
|
+
console.log("(TILEDESK) ATTRIBUTES: ", attributes)
|
|
450
|
+
}
|
|
449
451
|
|
|
450
452
|
var sender_id = req.body.payload.sender;
|
|
451
453
|
console.log("(TILEDESK) SENDER ID: ", sender_id);
|
|
@@ -465,6 +467,8 @@ router.post('/tiledesk', async (req, res) => {
|
|
|
465
467
|
return res.send(200);
|
|
466
468
|
}
|
|
467
469
|
|
|
470
|
+
console.log("/tiledesk ---> tiledeskChannelMessage: " + JSON.stringify(req.body.payload));
|
|
471
|
+
|
|
468
472
|
let recipient_id = tiledeskChannelMessage.recipient;
|
|
469
473
|
console.log("(Tiledesk) Recipient_id: ", recipient_id);
|
|
470
474
|
|
package/package.json
CHANGED
package/template/detail.html
CHANGED
|
@@ -215,27 +215,27 @@
|
|
|
215
215
|
|
|
216
216
|
<div style="width: 100%; display: flex; flex-direction: row; justify-content: space-between; margin-bottom: 15px;">
|
|
217
217
|
<div>
|
|
218
|
-
<p style="margin-bottom: 0px;">New User Interface!</p>
|
|
219
|
-
<p style="margin-bottom: 0px">Added support for tdImage</p>
|
|
220
218
|
<p style="margin-bottom: 0px">Bug Fixes</p>
|
|
221
219
|
<!--<p>Bug fixes and performance improvements</p>-->
|
|
222
220
|
</div>
|
|
223
|
-
<p style="font-size: 12px; color: #676767; margin-bottom: 0px;">Version <b>0.1.
|
|
221
|
+
<p style="font-size: 12px; color: #676767; margin-bottom: 0px;">Version <b>0.1.23</b></p>
|
|
224
222
|
</div>
|
|
225
223
|
|
|
226
224
|
<div style="width: 100%; display: flex; flex-direction: row; justify-content: space-between; margin-bottom: 15px;">
|
|
227
225
|
<div>
|
|
228
|
-
<p style="margin-bottom: 0px;">
|
|
226
|
+
<p style="margin-bottom: 0px;">New User Interface!</p>
|
|
227
|
+
<p style="margin-bottom: 0px">Added support for tdImage</p>
|
|
228
|
+
<p style="margin-bottom: 0px">Bug Fixes</p>
|
|
229
|
+
<!--<p>Bug fixes and performance improvements</p>-->
|
|
229
230
|
</div>
|
|
230
|
-
<p style="font-size: 12px; color: #676767; margin-bottom: 0px;">Version <b>0.1.
|
|
231
|
+
<p style="font-size: 12px; color: #676767; margin-bottom: 0px;">Version <b>0.1.18</b></p>
|
|
231
232
|
</div>
|
|
232
233
|
|
|
233
234
|
<div style="width: 100%; display: flex; flex-direction: row; justify-content: space-between; margin-bottom: 15px;">
|
|
234
235
|
<div>
|
|
235
|
-
<p style="margin-bottom: 0px;">
|
|
236
|
-
<p>Bug fixes</p>
|
|
236
|
+
<p style="margin-bottom: 0px;">Graphics improvements</p>
|
|
237
237
|
</div>
|
|
238
|
-
<p style="font-size: 12px; color: #676767; margin-bottom: 0px;">Version <b>0.1.
|
|
238
|
+
<p style="font-size: 12px; color: #676767; margin-bottom: 0px;">Version <b>0.1.16</b></p>
|
|
239
239
|
</div>
|
|
240
240
|
|
|
241
241
|
<!--
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var assert = require('assert');
|
|
2
2
|
const { TiledeskWhatsappTranslator } = require('../tiledesk/TiledeskWhatsappTranslator');
|
|
3
|
-
const log =
|
|
3
|
+
const log = true;
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
describe('Test Translator\n', function() {
|
|
@@ -202,7 +202,7 @@ describe('Test Translator\n', function() {
|
|
|
202
202
|
assert(whatsappJsonMessage.interactive.action.sections[0].rows.length === 4);
|
|
203
203
|
assert(whatsappJsonMessage.interactive.action.sections[1].rows.length === 1);
|
|
204
204
|
if (log) {
|
|
205
|
-
console.log("(test)
|
|
205
|
+
console.log("(test) whatsappJsonMessage: ", whatsappJsonMessage);
|
|
206
206
|
}
|
|
207
207
|
})
|
|
208
208
|
|
|
@@ -239,7 +239,7 @@ describe('Test Translator\n', function() {
|
|
|
239
239
|
interactive: {
|
|
240
240
|
type: "list_reply",
|
|
241
241
|
list_reply: {
|
|
242
|
-
id: "
|
|
242
|
+
id: "quick1234_Tiledesk Overview",
|
|
243
243
|
title: "Tiledesk Overview"
|
|
244
244
|
}
|
|
245
245
|
}
|
|
@@ -254,7 +254,7 @@ describe('Test Translator\n', function() {
|
|
|
254
254
|
assert(tiledeskJsonMessage.text === whatsappChannelMessage.interactive.list_reply.title);
|
|
255
255
|
assert(tiledeskJsonMessage.senderFullname === fullname);
|
|
256
256
|
if (log) {
|
|
257
|
-
console.log("(test) tiledeskJsonMessage: ", tiledeskJsonMessage);
|
|
257
|
+
console.log("(test) --> tiledeskJsonMessage: ", tiledeskJsonMessage);
|
|
258
258
|
}
|
|
259
259
|
})
|
|
260
260
|
|
|
@@ -266,7 +266,7 @@ describe('Test Translator\n', function() {
|
|
|
266
266
|
interactive: {
|
|
267
267
|
type: "list_reply",
|
|
268
268
|
list_reply: {
|
|
269
|
-
id: "
|
|
269
|
+
id: "action1234_main_menu",
|
|
270
270
|
title: "↩︎ Back"
|
|
271
271
|
}
|
|
272
272
|
}
|
|
@@ -282,7 +282,7 @@ describe('Test Translator\n', function() {
|
|
|
282
282
|
assert(tiledeskJsonMessage.type === 'text');
|
|
283
283
|
assert(tiledeskJsonMessage.attributes);
|
|
284
284
|
assert(tiledeskJsonMessage.attributes.action);
|
|
285
|
-
assert(tiledeskJsonMessage.attributes.action === whatsappChannelMessage.interactive.list_reply.id.substring(
|
|
285
|
+
assert(tiledeskJsonMessage.attributes.action === whatsappChannelMessage.interactive.list_reply.id.substring(11));
|
|
286
286
|
assert(tiledeskJsonMessage.attributes.subtype);
|
|
287
287
|
assert(tiledeskJsonMessage.attributes.subtype === "info");
|
|
288
288
|
assert(tiledeskJsonMessage.senderFullname === fullname);
|
|
@@ -301,7 +301,7 @@ describe('Test Translator\n', function() {
|
|
|
301
301
|
interactive: {
|
|
302
302
|
type: "button_reply",
|
|
303
303
|
button_reply: {
|
|
304
|
-
id: "
|
|
304
|
+
id: "quick1234_Cloud pricing",
|
|
305
305
|
title: "Cloud pricing"
|
|
306
306
|
}
|
|
307
307
|
}
|
|
@@ -344,7 +344,7 @@ describe('Test Translator\n', function() {
|
|
|
344
344
|
assert(tiledeskJsonMessage.type === 'text');
|
|
345
345
|
assert(tiledeskJsonMessage.attributes);
|
|
346
346
|
assert(tiledeskJsonMessage.attributes.action);
|
|
347
|
-
assert(tiledeskJsonMessage.attributes.action === whatsappChannelMessage.interactive.button_reply.id.substring(
|
|
347
|
+
assert(tiledeskJsonMessage.attributes.action === whatsappChannelMessage.interactive.button_reply.id.substring(11));
|
|
348
348
|
assert(tiledeskJsonMessage.attributes.subtype);
|
|
349
349
|
assert(tiledeskJsonMessage.attributes.subtype === 'info');
|
|
350
350
|
assert(tiledeskJsonMessage.senderFullname === fullname);
|
|
@@ -58,7 +58,7 @@ class TiledeskWhatsapp {
|
|
|
58
58
|
console.log("[Tiledesk Whatsapp] Message sent!");
|
|
59
59
|
return response
|
|
60
60
|
}).catch((err) => {
|
|
61
|
-
console.error("[Tiledesk Whatsapp ERROR] Send message: ", err);
|
|
61
|
+
console.error("[Tiledesk Whatsapp ERROR] Send message: ", err.response.data);
|
|
62
62
|
throw err;
|
|
63
63
|
})
|
|
64
64
|
}
|
|
@@ -115,10 +115,10 @@ class TiledeskWhatsapp {
|
|
|
115
115
|
})
|
|
116
116
|
})
|
|
117
117
|
}).catch((err) => {
|
|
118
|
-
console.log("axios err: ", err);
|
|
118
|
+
console.log("axios err: ", err.data);
|
|
119
119
|
})
|
|
120
120
|
}).catch((err) => {
|
|
121
|
-
console.log("axios err: ", err);
|
|
121
|
+
console.log("axios err: ", err.data);
|
|
122
122
|
})
|
|
123
123
|
}
|
|
124
124
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { v4: uuidv4 } = require('uuid');
|
|
2
|
+
|
|
1
3
|
class TiledeskWhatsappTranslator {
|
|
2
4
|
|
|
3
5
|
/**
|
|
@@ -163,7 +165,8 @@ const path = require('path');
|
|
|
163
165
|
let text_btn = {
|
|
164
166
|
type: "reply",
|
|
165
167
|
reply: {
|
|
166
|
-
id: "quick_" + btn.value,
|
|
168
|
+
//id: "quick_" + btn.value,
|
|
169
|
+
id: "quick" + uuidv4().substring(0,4) + "_"+ btn.value,
|
|
167
170
|
title: title
|
|
168
171
|
}
|
|
169
172
|
}
|
|
@@ -174,7 +177,8 @@ const path = require('path');
|
|
|
174
177
|
let action_btn = {
|
|
175
178
|
type: "reply",
|
|
176
179
|
reply: {
|
|
177
|
-
id: "
|
|
180
|
+
//id: "action" + "_" + btn.action,
|
|
181
|
+
id: "action" + uuidv4().substring(0, 4) + "_" + btn.action,
|
|
178
182
|
title: title
|
|
179
183
|
}
|
|
180
184
|
}
|
|
@@ -206,7 +210,7 @@ const path = require('path');
|
|
|
206
210
|
|
|
207
211
|
if (btn.type == 'text') {
|
|
208
212
|
let row = {
|
|
209
|
-
id: "
|
|
213
|
+
id: "quick" + uuidv4().substring(0,4) + "_"+ btn.value,
|
|
210
214
|
title: title
|
|
211
215
|
}
|
|
212
216
|
option_rows.push(row);
|
|
@@ -214,7 +218,7 @@ const path = require('path');
|
|
|
214
218
|
|
|
215
219
|
if (btn.type == 'action') {
|
|
216
220
|
let row = {
|
|
217
|
-
id: "
|
|
221
|
+
id: "action" + uuidv4().substring(0, 4) + "_" + btn.action,
|
|
218
222
|
title: title
|
|
219
223
|
}
|
|
220
224
|
action_rows.push(row);
|
|
@@ -305,7 +309,7 @@ const path = require('path');
|
|
|
305
309
|
whatsapp_message.text = { body: text };
|
|
306
310
|
|
|
307
311
|
if (this.log) {
|
|
308
|
-
console.log("[Translator] whatsapp message: ", whatsapp_message)
|
|
312
|
+
console.log("[Translator] simple whatsapp message: ", whatsapp_message)
|
|
309
313
|
}
|
|
310
314
|
return whatsapp_message;
|
|
311
315
|
}
|
|
@@ -345,13 +349,13 @@ const path = require('path');
|
|
|
345
349
|
// list reply
|
|
346
350
|
if (whatsappChannelMessage.interactive.type == 'list_reply') {
|
|
347
351
|
// action button
|
|
348
|
-
if (whatsappChannelMessage.interactive.list_reply.id.startsWith("
|
|
352
|
+
if (whatsappChannelMessage.interactive.list_reply.id.startsWith("action")) {
|
|
349
353
|
var tiledeskMessage = {
|
|
350
354
|
senderFullname: from,
|
|
351
355
|
text: ' ',
|
|
352
356
|
type: 'text',
|
|
353
357
|
attributes: {
|
|
354
|
-
action: whatsappChannelMessage.interactive.list_reply.id.substring(
|
|
358
|
+
action: whatsappChannelMessage.interactive.list_reply.id.substring(11),
|
|
355
359
|
subtype: 'info'
|
|
356
360
|
},
|
|
357
361
|
channel: { name: TiledeskWhatsappTranslator.CHANNEL_NAME }
|
|
@@ -359,9 +363,9 @@ const path = require('path');
|
|
|
359
363
|
return tiledeskMessage;
|
|
360
364
|
}
|
|
361
365
|
// quick reply button
|
|
362
|
-
if (whatsappChannelMessage.interactive.list_reply.id.startsWith("
|
|
366
|
+
if (whatsappChannelMessage.interactive.list_reply.id.startsWith("quick")) {
|
|
363
367
|
var tiledeskMessage = {
|
|
364
|
-
text: whatsappChannelMessage.interactive.list_reply.id.substring(
|
|
368
|
+
text: whatsappChannelMessage.interactive.list_reply.id.substring(10),
|
|
365
369
|
senderFullname: from,
|
|
366
370
|
channel: { name: TiledeskWhatsappTranslator.CHANNEL_NAME }
|
|
367
371
|
}
|
|
@@ -372,13 +376,13 @@ const path = require('path');
|
|
|
372
376
|
// inline button reply
|
|
373
377
|
if (whatsappChannelMessage.interactive.type == 'button_reply') {
|
|
374
378
|
// action button
|
|
375
|
-
if (whatsappChannelMessage.interactive.button_reply.id.startsWith("
|
|
379
|
+
if (whatsappChannelMessage.interactive.button_reply.id.startsWith("action")) {
|
|
376
380
|
var tiledeskMessage = {
|
|
377
381
|
senderFullname: from,
|
|
378
382
|
text: ' ',
|
|
379
383
|
type: 'text',
|
|
380
384
|
attributes: {
|
|
381
|
-
action: whatsappChannelMessage.interactive.button_reply.id.substring(
|
|
385
|
+
action: whatsappChannelMessage.interactive.button_reply.id.substring(11),
|
|
382
386
|
subtype: 'info'
|
|
383
387
|
},
|
|
384
388
|
channel: { name: TiledeskWhatsappTranslator.CHANNEL_NAME }
|
|
@@ -386,9 +390,9 @@ const path = require('path');
|
|
|
386
390
|
return tiledeskMessage;
|
|
387
391
|
}
|
|
388
392
|
// quick reply button
|
|
389
|
-
if (whatsappChannelMessage.interactive.button_reply.id.startsWith("
|
|
393
|
+
if (whatsappChannelMessage.interactive.button_reply.id.startsWith("quick")) {
|
|
390
394
|
var tiledeskMessage = {
|
|
391
|
-
text: whatsappChannelMessage.interactive.button_reply.id.substring(
|
|
395
|
+
text: whatsappChannelMessage.interactive.button_reply.id.substring(10),
|
|
392
396
|
senderFullname: from,
|
|
393
397
|
channel: { name: TiledeskWhatsappTranslator.CHANNEL_NAME }
|
|
394
398
|
}
|