@tiledesk/tiledesk-whatsapp-connector 0.1.26 → 0.1.28
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
|
@@ -1031,21 +1031,25 @@ async function startApp(settings, callback) {
|
|
|
1031
1031
|
log = settings.log;
|
|
1032
1032
|
}
|
|
1033
1033
|
|
|
1034
|
-
console.log("try to create client")
|
|
1035
1034
|
redis_client = redis.createClient({
|
|
1036
|
-
socket: {
|
|
1037
1035
|
host: REDIS_HOST,
|
|
1038
1036
|
port: REDIS_PORT,
|
|
1039
|
-
},
|
|
1040
1037
|
password: REDIS_PASSWORD
|
|
1041
1038
|
});
|
|
1039
|
+
|
|
1040
|
+
redis_client.on('error', err => {
|
|
1041
|
+
console.log('Error ' + err);
|
|
1042
|
+
})
|
|
1043
|
+
/*
|
|
1042
1044
|
redis_client.on('connect', () => {
|
|
1043
1045
|
console.log('Redis Connected!'); // Connected!
|
|
1044
1046
|
});
|
|
1045
|
-
|
|
1046
|
-
redis_client.on('
|
|
1047
|
-
console.log(
|
|
1047
|
+
*/
|
|
1048
|
+
redis_client.on('ready', () => {
|
|
1049
|
+
console.log("Redis ready")
|
|
1048
1050
|
})
|
|
1051
|
+
//await redis_client.connect(); // only for v4
|
|
1052
|
+
|
|
1049
1053
|
|
|
1050
1054
|
db.connect(settings.MONGODB_URL, () => {
|
|
1051
1055
|
console.log("KVBaseMongo successfully connected.");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var assert = require('assert');
|
|
2
2
|
const { TiledeskWhatsappTranslator } = require('../tiledesk/TiledeskWhatsappTranslator');
|
|
3
|
-
const log =
|
|
3
|
+
const log = false;
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
describe('Test Translator\n', function() {
|
|
@@ -57,8 +57,8 @@ describe('Test Translator\n', function() {
|
|
|
57
57
|
assert(whatsappJsonMessage.image);
|
|
58
58
|
assert(whatsappJsonMessage.image.link === tiledeskChannelMessage.metadata.src);
|
|
59
59
|
assert(whatsappJsonMessage.image.caption === tiledeskChannelMessage.text);
|
|
60
|
-
console.log("(test) whatsappJsonMessage: ", whatsappJsonMessage);
|
|
61
60
|
if (log) {
|
|
61
|
+
console.log("(test) whatsappJsonMessage: ", whatsappJsonMessage);
|
|
62
62
|
}
|
|
63
63
|
})
|
|
64
64
|
|
|
@@ -201,7 +201,56 @@ describe('Test Translator\n', function() {
|
|
|
201
201
|
assert(whatsappJsonMessage.interactive.action.sections);
|
|
202
202
|
assert(whatsappJsonMessage.interactive.action.sections[0].rows.length === 4);
|
|
203
203
|
assert(whatsappJsonMessage.interactive.action.sections[1].rows.length === 1);
|
|
204
|
-
if (log) {
|
|
204
|
+
if (!log) {
|
|
205
|
+
console.log("(test) whatsappJsonMessage: ", whatsappJsonMessage);
|
|
206
|
+
}
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
it("Translates a message with BUTTONS (more than 10) from Tiledesk to Whatsapp", function() {
|
|
210
|
+
|
|
211
|
+
let tiledeskChannelMessage = {
|
|
212
|
+
text: 'Test Message',
|
|
213
|
+
recipient: 'support-group-62c3f10152dc7400352bab0d-86a2293e-wab-104777398965560-393484506627',
|
|
214
|
+
attributes: {
|
|
215
|
+
attachment: {
|
|
216
|
+
buttons: [
|
|
217
|
+
{ type: 'text', value: 'Button 1' },
|
|
218
|
+
{ type: 'text', value: 'Button 2' },
|
|
219
|
+
{ type: 'text', value: 'Button 3' },
|
|
220
|
+
{ type: 'text', value: 'Button 4' },
|
|
221
|
+
{ type: 'text', value: 'Button 5' },
|
|
222
|
+
{ type: 'text', value: 'Button 6' },
|
|
223
|
+
{ type: 'text', value: 'Button 7' },
|
|
224
|
+
{ type: 'text', value: 'Button 8' },
|
|
225
|
+
{ type: 'text', value: 'Button 9' },
|
|
226
|
+
{ type: 'text', value: 'Button 10' },
|
|
227
|
+
{ type: 'text', value: 'Button 11' },
|
|
228
|
+
{ type: 'text', value: 'Button 12' },
|
|
229
|
+
{ type: 'action', value: '↩︎ Back', action: 'main_menu' }
|
|
230
|
+
]
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
let whatsapp_receiver = tiledeskChannelMessage.recipient.substring(tiledeskChannelMessage.recipient.lastIndexOf("-") + 1)
|
|
235
|
+
|
|
236
|
+
const tlr = new TiledeskWhatsappTranslator();
|
|
237
|
+
assert(tlr != null);
|
|
238
|
+
const whatsappJsonMessage = tlr.toWhatsapp(tiledeskChannelMessage, whatsapp_receiver);
|
|
239
|
+
assert(whatsappJsonMessage != null);
|
|
240
|
+
assert(whatsappJsonMessage.messaging_product === TiledeskWhatsappTranslator.WHATSAPP_MESSAGING_PRODUCT);
|
|
241
|
+
/*
|
|
242
|
+
assert(!whatsappJsonMessage.text);
|
|
243
|
+
assert(whatsappJsonMessage.type === "interactive");
|
|
244
|
+
assert(whatsappJsonMessage.interactive);
|
|
245
|
+
assert(whatsappJsonMessage.interactive.type === "list");
|
|
246
|
+
assert(whatsappJsonMessage.interactive.body.text === tiledeskChannelMessage.text);
|
|
247
|
+
assert(whatsappJsonMessage.interactive.action);
|
|
248
|
+
assert(whatsappJsonMessage.interactive.action.button === 'Choose an option');
|
|
249
|
+
assert(whatsappJsonMessage.interactive.action.sections);
|
|
250
|
+
assert(whatsappJsonMessage.interactive.action.sections[0].rows.length === 4);
|
|
251
|
+
assert(whatsappJsonMessage.interactive.action.sections[1].rows.length === 1);
|
|
252
|
+
*/
|
|
253
|
+
if (!log) {
|
|
205
254
|
console.log("(test) whatsappJsonMessage: ", whatsappJsonMessage);
|
|
206
255
|
}
|
|
207
256
|
})
|
|
@@ -285,6 +285,7 @@ const path = require('path');
|
|
|
285
285
|
// Option 2: Cut buttons array -> display first 10 buttons only
|
|
286
286
|
// Option 3: Send message with *buttons (questa)
|
|
287
287
|
|
|
288
|
+
console.log("\n\ntiledeskChannelMessage.attributes._raw_message: ", JSON.stringify(tiledeskChannelMessage))
|
|
288
289
|
whatsapp_message.text = { body: tiledeskChannelMessage.attributes._raw_message };
|
|
289
290
|
|
|
290
291
|
if (this.log) {
|