@tiledesk/tiledesk-whatsapp-connector 1.0.4-rc3 → 1.0.4
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/package.json +1 -1
- package/routes/api.js +8 -110
- package/template/template_detail.html +1 -1
- package/tiledesk/KVBaseMongo.js +0 -1
- package/tiledesk/WhatsappService.js +1 -1
package/package.json
CHANGED
package/routes/api.js
CHANGED
|
@@ -192,9 +192,9 @@ router.post('/tiledesk/broadcast', async (req, res) => {
|
|
|
192
192
|
})
|
|
193
193
|
|
|
194
194
|
router.post('/tiledesk/broadcast/csv', upload.single('uploadFile'), async (req, res) => {
|
|
195
|
-
const { id_project,
|
|
195
|
+
const { id_project, template_name, template_language, transaction_id, broadcast = true } = req.body;
|
|
196
196
|
|
|
197
|
-
const requiredFields = ['id_project', '
|
|
197
|
+
const requiredFields = ['id_project', 'template_name', 'template_language'];
|
|
198
198
|
const missingFields = requiredFields.filter(field => !req.body[field]);
|
|
199
199
|
|
|
200
200
|
if (missingFields.length > 0) {
|
|
@@ -220,14 +220,12 @@ router.post('/tiledesk/broadcast/csv', upload.single('uploadFile'), async (req,
|
|
|
220
220
|
})
|
|
221
221
|
|
|
222
222
|
parser.on("end", async () => {
|
|
223
|
-
console.log("records: ", records);
|
|
224
223
|
|
|
225
224
|
const tlr = new TiledeskWhatsappTranslator();
|
|
226
225
|
const receiver_list = await tlr.createReceiversList(records);
|
|
227
226
|
|
|
228
227
|
winston.debug("(wab) broadcast from csv receiver_list: ", receiver_list);
|
|
229
228
|
|
|
230
|
-
console.log("project: ", id_project)
|
|
231
229
|
const final_transaction_id = transaction_id || `automation-request-${id_project}-${Date.now()}`;
|
|
232
230
|
|
|
233
231
|
let settings = await utils.getSettingsByProjectId(id_project);
|
|
@@ -235,11 +233,15 @@ router.post('/tiledesk/broadcast/csv', upload.single('uploadFile'), async (req,
|
|
|
235
233
|
settings = await utils.getSettings(id_project, null);
|
|
236
234
|
}
|
|
237
235
|
|
|
238
|
-
console.log("settings: ", settings)
|
|
239
236
|
if (!settings || !settings.business_account_id) {
|
|
240
237
|
return res.status(400).json({ success: false, error: "WhatsApp not configured or missing business_account_id." });
|
|
241
238
|
}
|
|
242
239
|
|
|
240
|
+
const template = {
|
|
241
|
+
name: template_name,
|
|
242
|
+
language: template_language
|
|
243
|
+
}
|
|
244
|
+
|
|
243
245
|
const scheduler = new Scheduler({ AMQP_MANAGER_URL, JOB_TOPIC_EXCHANGE });
|
|
244
246
|
const data = {
|
|
245
247
|
project_id: id_project,
|
|
@@ -254,113 +256,9 @@ router.post('/tiledesk/broadcast/csv', upload.single('uploadFile'), async (req,
|
|
|
254
256
|
const schedulerResult = await scheduler.goSchedule(data);
|
|
255
257
|
winston.verbose("(wab) scheduler result: ", schedulerResult);
|
|
256
258
|
|
|
257
|
-
res.status(200).send({ success: true, message: "Job started. Send messages in queue." })
|
|
259
|
+
res.status(200).send({ success: true, message: "Job started. Send messages in queue.", automation_id: final_transaction_id })
|
|
258
260
|
})
|
|
259
261
|
|
|
260
|
-
|
|
261
|
-
// const parser = csv.parseString({
|
|
262
|
-
// delimiter: ";",
|
|
263
|
-
// columns: true,
|
|
264
|
-
// trim: true,
|
|
265
|
-
// skip_empty_lines: true
|
|
266
|
-
// // });
|
|
267
|
-
|
|
268
|
-
// parser.on('readable', () => {
|
|
269
|
-
// let record;
|
|
270
|
-
// while ((record = parser.read())) {
|
|
271
|
-
// console.log("-> record: ", record)
|
|
272
|
-
// records.push(record);
|
|
273
|
-
// }
|
|
274
|
-
// });
|
|
275
|
-
|
|
276
|
-
// parser.on('error', err => {
|
|
277
|
-
// return res.status(400).json({ success: false, error: 'Invalid CSV format.' });
|
|
278
|
-
// });
|
|
279
|
-
|
|
280
|
-
// parser.on('end', async () => {
|
|
281
|
-
// console.log("records: ", records)
|
|
282
|
-
// const receiver_list = records.map(row => {
|
|
283
|
-
// console.log(Object.keys(row));
|
|
284
|
-
// console.log("row: ", row);
|
|
285
|
-
// console.log("header: ", row.header_0);
|
|
286
|
-
// console.log("phone: ", row.phone_number);
|
|
287
|
-
// const phone_number = row.phone_number.startsWith('+') ? row.phone_number : `+39${row.phone_number}`;
|
|
288
|
-
// const receiver = { phone_number };
|
|
289
|
-
|
|
290
|
-
// let header_params = [];
|
|
291
|
-
// let body_params = [];
|
|
292
|
-
// let buttons_params = [];
|
|
293
|
-
|
|
294
|
-
// for (const [key, value] of Object.entries(row)) {
|
|
295
|
-
// if (!value || key === 'phone_number') continue;
|
|
296
|
-
|
|
297
|
-
// if (key.startsWith('header')) {
|
|
298
|
-
// if (value.startsWith('http')) {
|
|
299
|
-
// header_params.push({
|
|
300
|
-
// type: "IMAGE",
|
|
301
|
-
// image: { link: value }
|
|
302
|
-
// });
|
|
303
|
-
// } else {
|
|
304
|
-
// header_params.push({
|
|
305
|
-
// type: "text",
|
|
306
|
-
// text: value
|
|
307
|
-
// });
|
|
308
|
-
// }
|
|
309
|
-
// } else if (key.startsWith('body')) {
|
|
310
|
-
// body_params.push({
|
|
311
|
-
// type: "text",
|
|
312
|
-
// text: value
|
|
313
|
-
// });
|
|
314
|
-
// } else if (key.startsWith('buttons')) {
|
|
315
|
-
// buttons_params.push({
|
|
316
|
-
// type: "text",
|
|
317
|
-
// text: value
|
|
318
|
-
// });
|
|
319
|
-
// }
|
|
320
|
-
// }
|
|
321
|
-
|
|
322
|
-
// if (header_params.length) receiver.header_params = header_params;
|
|
323
|
-
// if (body_params.length) receiver.body_params = body_params;
|
|
324
|
-
// if (buttons_params.length) receiver.buttons_params = buttons_params;
|
|
325
|
-
|
|
326
|
-
// return receiver;
|
|
327
|
-
// });
|
|
328
|
-
|
|
329
|
-
// console.log("receiver_list: ", receiver_list);
|
|
330
|
-
// return res.status(200).send(receiver_list);
|
|
331
|
-
|
|
332
|
-
// const final_transaction_id = transaction_id || `automation-request-${id_project}-${Date.now()}`;
|
|
333
|
-
|
|
334
|
-
// let settings = await utils.getSettingsByProjectId(id_project);
|
|
335
|
-
// if (!settings) {
|
|
336
|
-
// settings = await utils.getSettings(id_project, null);
|
|
337
|
-
// }
|
|
338
|
-
|
|
339
|
-
// if (!settings || !settings.business_account_id) {
|
|
340
|
-
// return res.status(400).json({ success: false, error: "WhatsApp not configured or missing business_account_id." });
|
|
341
|
-
// }
|
|
342
|
-
|
|
343
|
-
// const scheduler = new Scheduler({ AMQP_MANAGER_URL, JOB_TOPIC_EXCHANGE });
|
|
344
|
-
// const data_To_scheduler = {
|
|
345
|
-
// project_id: id_project,
|
|
346
|
-
// receiver_list,
|
|
347
|
-
// phone_number_id,
|
|
348
|
-
// transaction_id: final_transaction_id,
|
|
349
|
-
// template,
|
|
350
|
-
// settings,
|
|
351
|
-
// broadcast
|
|
352
|
-
// };
|
|
353
|
-
|
|
354
|
-
// winston.debug('(wab) data_To_scheduler (CSV): ', data_To_scheduler);
|
|
355
|
-
|
|
356
|
-
// const schedulerResult = await scheduler.goSchedule(data_To_scheduler);
|
|
357
|
-
// winston.verbose('(wab) schedulerResult: ', schedulerResult);
|
|
358
|
-
|
|
359
|
-
// return res.status(200).json({ success: true, message: "CSV job started." });
|
|
360
|
-
// });
|
|
361
|
-
|
|
362
|
-
// parser.write(req.file.buffer);
|
|
363
|
-
// parser.end();
|
|
364
262
|
});
|
|
365
263
|
|
|
366
264
|
|
|
@@ -150,7 +150,7 @@
|
|
|
150
150
|
const counter = document.getElementById('counter');
|
|
151
151
|
|
|
152
152
|
let header = template.components.find(c => c.type === "HEADER");
|
|
153
|
-
|
|
153
|
+
|
|
154
154
|
sBtn_text.innerText = header.format.charAt(0) + header.format.slice(1).toLowerCase();
|
|
155
155
|
if (sBtn_text.innerText == "None") {
|
|
156
156
|
inputHeader.style.display = "none";
|
package/tiledesk/KVBaseMongo.js
CHANGED
|
@@ -70,7 +70,6 @@ class KVBaseMongo {
|
|
|
70
70
|
winston.debug("Searching on " + this.db)
|
|
71
71
|
winston.debug("Searching on Collection " + this.KV_COLLECTION)
|
|
72
72
|
|
|
73
|
-
console.log("query: ", query)
|
|
74
73
|
this.db.collection(this.KV_COLLECTION).findOne(query, function(err, doc) {
|
|
75
74
|
if (err) {
|
|
76
75
|
winston.error("Error reading mongodb value", err);
|