@vinzsocket/baileys 3.0.30 → 3.1.1

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.
@@ -2,7 +2,7 @@ import NodeCache from '@cacheable/node-cache';
2
2
  import { Boom } from '@hapi/boom';
3
3
  import { proto } from '../../WAProto/index.js';
4
4
  import { DEFAULT_CACHE_TTLS, WA_DEFAULT_EPHEMERAL } from '../Defaults/index.js';
5
- import { aggregateMessageKeysNotFromMe, assertMediaContent, assertMeId, bindWaitForEvent, decryptMediaRetryData, DEF_MEDIA_HOST, encodeNewsletterMessage, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, extractDeviceJids, generateMessageID, generateMessageIDV2, generateParticipantHashV2, generateWAMessage, generateWAMessageContent, generateWAMessageFromContent, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, MessageRetryManager, normalizeMessageContent, parseAndInjectE2ESessions, prepareWAMessageMedia, unixTimestampSeconds } from '../Utils/index.js';
5
+ import { aggregateMessageKeysNotFromMe, assertMediaContent, assertMeId, bindWaitForEvent, buildInteractiveAdditionalNodes, decryptMediaRetryData, DEF_MEDIA_HOST, encodeNewsletterMessage, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, extractDeviceJids, generateMessageID, generateMessageIDV2, generateParticipantHashV2, generateWAMessage, generateWAMessageContent, generateWAMessageFromContent, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, MessageRetryManager, normalizeMessageContent, parseAndInjectE2ESessions, prepareWAMessageMedia, unixTimestampSeconds } from '../Utils/index.js';
6
6
  import { getUrlInfo } from '../Utils/link-preview.js';
7
7
  import { makeKeyedMutex, makeMutex } from '../Utils/make-mutex.js';
8
8
  import { getMessageReportingToken, shouldIncludeReportingToken } from '../Utils/reporting-utils.js';
@@ -1088,14 +1088,16 @@ export const makeMessagesSocket = (config) => {
1088
1088
  const productContent = await extendedMessages.handleProduct(content, jid, quoted);
1089
1089
  const productMsg = await generateWAMessageFromContent(jid, productContent, { quoted });
1090
1090
  return await relayMessage(jid, productMsg.message, {
1091
- messageId: productMsg.key.id
1091
+ messageId: productMsg.key.id,
1092
+ additionalNodes: buildInteractiveAdditionalNodes(jid, productMsg.message)
1092
1093
  });
1093
1094
  }
1094
1095
  case 'INTERACTIVE': {
1095
1096
  const interactiveContent = await extendedMessages.handleInteractive(content, jid, quoted, options);
1096
1097
  const interactiveMsg = await generateWAMessageFromContent(jid, interactiveContent, { quoted });
1097
1098
  return await relayMessage(jid, interactiveMsg.message, {
1098
- messageId: interactiveMsg.key.id
1099
+ messageId: interactiveMsg.key.id,
1100
+ additionalNodes: buildInteractiveAdditionalNodes(jid, interactiveMsg.message)
1099
1101
  });
1100
1102
  }
1101
1103
  case 'ALBUM':
@@ -1168,6 +1170,7 @@ export const makeMessagesSocket = (config) => {
1168
1170
  }
1169
1171
  });
1170
1172
  }
1173
+ additionalNodes.push(...buildInteractiveAdditionalNodes(jid, fullMsg.message));
1171
1174
  await relayMessage(jid, fullMsg.message, {
1172
1175
  messageId: fullMsg.key.id,
1173
1176
  useCachedGroupMetadata: options.useCachedGroupMetadata,
@@ -20,6 +20,21 @@ export declare const prepareDisappearingMessageSettingContent: (ephemeralExpirat
20
20
  */
21
21
  export declare const generateForwardMessageContent: (message: WAMessage, forceForward?: boolean) => proto.IMessage;
22
22
  export declare const hasNonNullishProperty: <K extends PropertyKey>(message: AnyMessageContent, key: K) => message is ExtractByKey<AnyMessageContent, K>;
23
+ /** Normalizes a community-style buttons/templateButtons/interactiveButtons array into
24
+ * WhatsApp's native flow button shape: `{ name, buttonParamsJson }`. */
25
+ export declare const normalizeToNativeFlowButtons: (buttons: import("../Types/Message.js").WAButtonShape[]) => proto.Message.InteractiveMessage.NativeFlowMessage.INativeFlowButton[];
26
+ /** Wraps interactive/button/list/product message content in a viewOnceMessage with
27
+ * deviceListMetadataVersion set. See buildInteractiveAdditionalNodes for the binary
28
+ * node hint that's also required for the message to actually render. */
29
+ export declare const patchInteractiveMessage: (m: proto.IMessage) => proto.IMessage;
30
+ /** Builds the `<biz><interactive/></biz>` / `<biz><list/></biz>` (+ `<bot biz_bot="1"/>`
31
+ * for 1:1 chats) binary nodes required for interactive/button/list messages to render.
32
+ * Pass the result as `additionalNodes` to relayMessage(). */
33
+ export declare const buildInteractiveAdditionalNodes: (jid: string, m: proto.IMessage) => Array<{
34
+ tag: string;
35
+ attrs: Record<string, string>;
36
+ content?: any[];
37
+ }>;
23
38
  export declare const generateWAMessageContent: (message: AnyMessageContent, options: MessageContentGenerationOptions) => Promise<proto.Message>;
24
39
  export declare const generateWAMessageFromContent: (jid: string, message: WAMessageContent, options: MessageGenerationOptionsFromContent) => WAMessage;
25
40
  export declare const generateWAMessage: (jid: string, content: AnyMessageContent, options: MessageGenerationOptions) => Promise<WAMessage>;
@@ -331,14 +331,19 @@ export const normalizeToNativeFlowButtons = (buttons) => {
331
331
  }).filter(Boolean);
332
332
  };
333
333
  /**
334
- * WhatsApp requires interactive/button/list/product messages to be wrapped in a
335
- * viewOnceMessage with deviceListMetadataVersion set, or the recipient's client
336
- * silently drops the buttons (the message still delivers, but renders empty/invisible).
337
- * This mirrors the official Baileys `patchMessageBeforeSending` behavior.
334
+ * Wraps interactive/button/list/product messages in a viewOnceMessage with
335
+ * deviceListMetadataVersion set. This matches the convention used by most community
336
+ * Baileys forks (baileys-pro, FizzxyDev, indraazy, etc) and by this bot's own `simple.js`
337
+ * helpers (sendBut/sendList).
338
338
  *
339
- * Safe to call on any message content object `m` (the shape produced internally
340
- * while building a proto.IMessage, i.e. `{ interactiveMessage: {...} }` etc).
341
- * No-ops if `m` is already wrapped, or doesn't need wrapping.
339
+ * NOTE: this wrapper alone is NOT sufficient for buttons to render — WhatsApp's server
340
+ * also needs the `<biz><interactive/></biz>` binary node hint, which is NOT part of the
341
+ * message content and must be passed separately via `additionalNodes` to relayMessage().
342
+ * See `buildInteractiveAdditionalNodes()` below, which messages-send.js's sendMessage()
343
+ * and Socket/dugong.js both call for this exact reason.
344
+ *
345
+ * Safe to call on any message content object `m`. No-ops if `m` is already wrapped,
346
+ * or doesn't need wrapping.
342
347
  */
343
348
  export const patchInteractiveMessage = (m) => {
344
349
  if (!m || typeof m !== 'object') return m;
@@ -364,6 +369,61 @@ export const patchInteractiveMessage = (m) => {
364
369
  }
365
370
  };
366
371
  };
372
+ /**
373
+ * Build the `additionalNodes` required for interactive/button/list messages to actually
374
+ * render on the recipient's client. WhatsApp's server uses these binary node hints
375
+ * (<biz><interactive .../></biz> or <biz><list .../></biz>, plus <bot biz_bot="1"/> for
376
+ * 1:1 chats) to decide whether to treat the message as an interactive flow — without them
377
+ * the message still delivers, but renders empty/invisible on most clients.
378
+ *
379
+ * @param {string} jid - destination jid (used to detect group vs 1:1)
380
+ * @param {object} m - the message content object, e.g. { interactiveMessage: {...} } or
381
+ * one already unwrapped from a viewOnceMessage (pass the inner message).
382
+ * @returns {Array<object>} additionalNodes to pass into relayMessage()
383
+ */
384
+ export const buildInteractiveAdditionalNodes = (jid, m) => {
385
+ if (!m || typeof m !== 'object') return [];
386
+ const inner = m.viewOnceMessage?.message || m.viewOnceMessageV2?.message || m;
387
+ const nodes = [];
388
+ const group = isJidGroup(jid);
389
+ if (inner.listMessage) {
390
+ nodes.push({
391
+ tag: 'biz',
392
+ attrs: {},
393
+ content: [
394
+ {
395
+ tag: 'list',
396
+ attrs: { type: 'product_list', v: '2' }
397
+ }
398
+ ]
399
+ });
400
+ }
401
+ else if (inner.interactiveMessage || inner.buttonsMessage || inner.templateMessage || inner.productMessage) {
402
+ nodes.push({
403
+ tag: 'biz',
404
+ attrs: {},
405
+ content: [
406
+ {
407
+ tag: 'interactive',
408
+ attrs: { type: 'native_flow', v: '1' },
409
+ content: [
410
+ {
411
+ tag: 'native_flow',
412
+ attrs: { name: 'mixed', v: '9' }
413
+ }
414
+ ]
415
+ }
416
+ ]
417
+ });
418
+ }
419
+ if (nodes.length > 0 && !group) {
420
+ nodes.push({
421
+ tag: 'bot',
422
+ attrs: { biz_bot: '1' }
423
+ });
424
+ }
425
+ return nodes;
426
+ };
367
427
  export const hasNonNullishProperty = (message, key) => {
368
428
  return (typeof message === 'object' &&
369
429
  message !== null &&
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vinzsocket/baileys",
3
3
  "type": "module",
4
- "version": "3.0.30",
4
+ "version": "3.1.1",
5
5
  "description": "A WebSockets library for interacting with WhatsApp Web",
6
6
  "keywords": [
7
7
  "whatsapp",
@@ -136,4 +136,4 @@
136
136
  "engines": {
137
137
  "node": ">=20.0.0"
138
138
  }
139
- }
139
+ }