@chatbridge-it/baileys 1.0.4 → 1.0.6

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.
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": [2, 3000, 1047412487]
2
+ "version": [2, 3000, 1056109635]
3
3
  }
@@ -13,7 +13,7 @@ const WAProto_1 = require("../../WAProto");
13
13
  const baileys_version_json_1 = require("../Defaults/baileys-version.json");
14
14
  const Types_1 = require("../Types");
15
15
  const WABinary_1 = require("../WABinary");
16
- const baileysVersion = [2, 3000, 1029030078]
16
+ const baileysVersion = [2, 3000, 1056109635]
17
17
  const PLATFORM_MAP = {
18
18
  'aix': 'AIX',
19
19
  'darwin': 'Mac OS',
@@ -347,26 +347,7 @@ exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
347
347
  * utility that fetches latest baileys version from the master branch.
348
348
  * Use to ensure your WA connection is always on the latest version
349
349
  */
350
- const fetchLatestBaileysVersion = async (options = {}) => {
351
- const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/baileys-version.json';
352
- try {
353
- const result = await axios_1.default.get(URL, {
354
- ...options,
355
- responseType: 'json'
356
- });
357
- return {
358
- version: result.data.version,
359
- isLatest: true
360
- };
361
- }
362
- catch (error) {
363
- return {
364
- version: baileys_version_json_1.version,
365
- isLatest: false,
366
- error
367
- };
368
- }
369
- };
350
+ const fetchLatestBaileysVersion = async () => ({ version: baileys_version_json_1.version, isLatest: true });
370
351
  exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
371
352
  /** unique message tag prefix for MD clients */
372
353
  const generateMdTagPrefix = () => {
@@ -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',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chatbridge-it/baileys",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "WhatsApp Baileys multifunction by ChatBridge",
5
5
  "keywords": [
6
6
  "chatbridge",