@chatbridge-it/baileys 1.0.4 → 1.0.5
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/lib/Utils/messages.js +27 -2
- package/lib/WABinary/generic-utils.js +13 -0
- package/package.json +1 -1
package/lib/Utils/messages.js
CHANGED
|
@@ -334,6 +334,31 @@ const normalizeInteractiveButton = (b) => {
|
|
|
334
334
|
}
|
|
335
335
|
return { name: b.name, buttonParamsJson: params === undefined ? '{}' : params };
|
|
336
336
|
};
|
|
337
|
+
/**
|
|
338
|
+
* Righe e sezioni di una lista.
|
|
339
|
+
* Accetta sia `rowId` (formato classico) sia `id` (formato delle liste native):
|
|
340
|
+
* se manca l'id viene usato il titolo, cosi la riga e sempre selezionabile.
|
|
341
|
+
*/
|
|
342
|
+
const normalizeListSections = (sections) => {
|
|
343
|
+
if (!Array.isArray(sections) || !sections.length) {
|
|
344
|
+
throw new boom_1.Boom('Invalid list: "sections" must be a non-empty array', { statusCode: 400 });
|
|
345
|
+
}
|
|
346
|
+
return sections.map((section) => {
|
|
347
|
+
const rows = (section && Array.isArray(section.rows) ? section.rows : []).map((row) => {
|
|
348
|
+
const title = row && row.title !== undefined && row.title !== null ? String(row.title) : '';
|
|
349
|
+
const rawId = row && row.rowId !== undefined && row.rowId !== null ? row.rowId : (row ? row.id : undefined);
|
|
350
|
+
const out = { title, rowId: String(rawId !== undefined && rawId !== null && rawId !== '' ? rawId : title) };
|
|
351
|
+
if (row && row.description !== undefined && row.description !== null && row.description !== '') {
|
|
352
|
+
out.description = String(row.description);
|
|
353
|
+
}
|
|
354
|
+
return out;
|
|
355
|
+
});
|
|
356
|
+
if (!rows.length) {
|
|
357
|
+
throw new boom_1.Boom('Invalid list: every section needs at least one row', { statusCode: 400 });
|
|
358
|
+
}
|
|
359
|
+
return { title: section.title !== undefined && section.title !== null ? String(section.title) : '', rows };
|
|
360
|
+
});
|
|
361
|
+
};
|
|
337
362
|
const generateWAMessageContent = async (message, options) => {
|
|
338
363
|
var _a;
|
|
339
364
|
var _b;
|
|
@@ -548,8 +573,8 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
548
573
|
}
|
|
549
574
|
if ('sections' in message && !!message.sections) {
|
|
550
575
|
const listMessage = {
|
|
551
|
-
sections: message.sections,
|
|
552
|
-
buttonText: message.buttonText,
|
|
576
|
+
sections: normalizeListSections(message.sections),
|
|
577
|
+
buttonText: message.buttonText || 'Select',
|
|
553
578
|
title: message.title,
|
|
554
579
|
footerText: message.footer,
|
|
555
580
|
description: message.text,
|
|
@@ -147,6 +147,19 @@ const getAdditionalNode = (name) => {
|
|
|
147
147
|
},
|
|
148
148
|
content: []
|
|
149
149
|
}]
|
|
150
|
+
} else if (name === 'list') {
|
|
151
|
+
// lista classica (listMessage): serve il nodo <list type="product_list" v="2"/>
|
|
152
|
+
return [{
|
|
153
|
+
tag: 'biz',
|
|
154
|
+
attrs: {},
|
|
155
|
+
content: [{
|
|
156
|
+
tag: 'list',
|
|
157
|
+
attrs: {
|
|
158
|
+
v: '2',
|
|
159
|
+
type: 'product_list'
|
|
160
|
+
}
|
|
161
|
+
}]
|
|
162
|
+
}]
|
|
150
163
|
} else if (flow_name[name] || name === 'interactive' || name === 'buttons') {
|
|
151
164
|
return [{
|
|
152
165
|
tag: 'biz',
|