whalibmob 5.40.42 → 5.40.44

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/README.md CHANGED
@@ -159,6 +159,30 @@ main().catch(err => { console.error(err.message || err); process.exit(1) })
159
159
 
160
160
  The client reconnects by itself after a dropped connection — do not create a new one on `disconnected`. Prefer no code at all? The [CLI](https://github.com/Kunboruto20/whalibmob/blob/main/docs/cli-getting-started.md#cli--getting-started) does the same in a few commands: request the code, register, connect, then `/send`. A brand-new account is watched closely by WhatsApp's anti-abuse checks, so send the first messages to people who have your number saved — see [Accounts](https://github.com/Kunboruto20/whalibmob/blob/main/docs/accounts.md#why-registration-can-be-blocked--the-anti-abuse-landscape).
161
161
 
162
+ > [!NOTE]
163
+ > **🆕 whalibmob now supports interactive button messages.**
164
+ >
165
+ > Send a "card" message with up to **three tappable buttons** — a **link** button
166
+ > (opens a URL), a **call** button (dials a number), a **copy** button (copies a
167
+ > code), or a **quick-reply** — with an optional header image. One call does it,
168
+ > from both the Node API and the `wa` CLI, and it works the **same on a
169
+ > mobile-registered number and a linked web/companion session** (a WhatsApp
170
+ > message is encoded identically on both).
171
+ >
172
+ > ```js
173
+ > await client.sendInteractive('14155552671', {
174
+ > body: 'Check this out!',
175
+ > footer: 'whalibmob',
176
+ > buttons: [
177
+ > { text: 'Open site', url: 'https://example.com' }, // link button
178
+ > { text: 'Call us', phone: '14155552671' }, // call button
179
+ > { text: 'Copy code', copy: 'PROMO2026' } // copy button
180
+ > ]
181
+ > });
182
+ > ```
183
+ >
184
+ > 👉 **Full guide, all button types and the CLI command: [docs/interactive-buttons.md](https://github.com/Kunboruto20/whalibmob/blob/main/docs/interactive-buttons.md)**
185
+
162
186
 
163
187
  ## Approving a Companion Device
164
188
 
package/cli.js CHANGED
@@ -681,6 +681,7 @@ const HELP = `
681
681
  /reply <jid> <msgId> <senderJid> <text> reply quoting a message
682
682
  (senderJid = same as jid for DMs; member JID for groups)
683
683
  /image <jid> <file> [caption] send image
684
+ /button <jid> <body> | <Label>=<url> | ... send a card with link/call/copy/reply buttons
684
685
  /video <jid> <file> [caption] send video
685
686
  /audio <jid> <file> send audio file
686
687
  /ptt <jid> <file> send voice note
@@ -1897,6 +1898,41 @@ async function handleLine(line) {
1897
1898
  break;
1898
1899
  }
1899
1900
 
1901
+ case '/button':
1902
+ case '/card': {
1903
+ requireConn();
1904
+ const [, jR, ...restArr] = p;
1905
+ const jid = normalizeJid(jR);
1906
+ const rest = restArr.join(' ');
1907
+ if (!jid || !rest) {
1908
+ fail('usage: /button <jid> <body> | <Label>=<url> | <Label2> | <Label3>=call:<num>');
1909
+ out(' Label=https://site.com → link button');
1910
+ out(' Label=call:15551234567 → call button');
1911
+ out(' Label=copy:CODE123 → copy button');
1912
+ out(' Label → quick reply');
1913
+ break;
1914
+ }
1915
+ const segs = rest.split('|').map(s => s.trim()).filter(Boolean);
1916
+ const body = segs.shift();
1917
+ if (!segs.length) { fail('/button needs at least one button (separate with |)'); break; }
1918
+ if (segs.length > 3) { fail('WhatsApp allows at most 3 buttons'); break; }
1919
+ const buttons = segs.map(seg => {
1920
+ const eq = seg.indexOf('=');
1921
+ if (eq === -1) return { text: seg, id: seg }; // quick reply
1922
+ const text = seg.slice(0, eq).trim();
1923
+ const tgt = seg.slice(eq + 1).trim();
1924
+ if (/^call:/i.test(tgt)) return { text, phone: tgt.replace(/^call:/i, '') };
1925
+ if (/^copy:/i.test(tgt)) return { text, copy: tgt.replace(/^copy:/i, '') };
1926
+ if (/^https?:\/\//i.test(tgt)) return { text, url: tgt };
1927
+ return { text, id: tgt };
1928
+ });
1929
+ out('sending card...');
1930
+ _client.sendInteractive(jid, { body, buttons })
1931
+ .then(r => out('sent ' + (r && r.id ? r.id : r)))
1932
+ .catch(e => fail('button error: ' + e.message));
1933
+ break;
1934
+ }
1935
+
1900
1936
  case '/video': {
1901
1937
  requireConn();
1902
1938
  const [, jR, file, ...cap] = p;
@@ -0,0 +1,115 @@
1
+ # Interactive buttons ("card" messages)
2
+
3
+ Send a message with up to **three tappable buttons**: a link button, a call
4
+ button, a copy button, or a quick-reply. Optionally put an image on top for the
5
+ "card" look.
6
+
7
+ Works the same on a **mobile-registered** number and a **linked web/companion**
8
+ session — a WhatsApp message is encoded identically on both, so the same call
9
+ delivers buttons either way.
10
+
11
+ ## Works on both mobile API and web API
12
+
13
+ `sendInteractive` is routed through whalibmob's normal message pipeline, exactly
14
+ like `sendText`. It does **not** matter how the session came to exist:
15
+
16
+ | Session type | How you got it | Buttons work? |
17
+ |--------------|----------------|---------------|
18
+ | **Mobile API** | registered a number over SMS / voice / `wa_old` | ✅ yes |
19
+ | **Web / companion API** | linked by QR, pairing code or passkey | ✅ yes |
20
+
21
+ The reason: a WhatsApp message — text, image, or interactive — is encrypted and
22
+ encoded the same way regardless of how the account was created. The interactive
23
+ message is Signal-encrypted and fanned out to **every device** of the recipient
24
+ (phone + web + any linked companion), just like a normal text message. The only
25
+ extra is one `<biz>` native-flow node added to the stanza so clients render the
26
+ buttons.
27
+
28
+ So you write the call once and it behaves identically on a bot that registered
29
+ its own number and on a bot linked to an existing phone.
30
+
31
+ > **Deliverability / risk.** Sending interactive buttons is something only
32
+ > official and Business-API clients normally do. WhatsApp can flag an account
33
+ > that sends them. Use a warmed, trusted account, send to people who expect the
34
+ > message, and never blast strangers — that is the quickest route to a ban.
35
+ > `quick_reply` and `cta_url` are the most widely rendered; exotic flows may be
36
+ > silently ignored by some clients.
37
+
38
+ ## Node API
39
+
40
+ ```js
41
+ const { WhalibmobClient } = require('whalibmob');
42
+ const client = new WhalibmobClient();
43
+ await client.connect();
44
+
45
+ await client.sendInteractive('40712345678', {
46
+ body: 'Check this out!',
47
+ footer: 'whalibmob',
48
+ image: './banner.jpg', // optional header image (path, Buffer, or URL)
49
+ buttons: [
50
+ { text: 'Open site', url: 'https://example.com' }, // link button
51
+ { text: 'Call us', phone: '15551234567' }, // call button
52
+ { text: 'Copy code', copy: 'PROMO2026' }, // copy button
53
+ // { text: 'Yes', id: 'yes' } // quick reply (no url/phone/copy)
54
+ ]
55
+ });
56
+ ```
57
+
58
+ ### Button types
59
+
60
+ | Button | Fields | Effect when tapped |
61
+ |--------|--------|--------------------|
62
+ | Link | `{ text, url }` | opens the URL (`cta_url`) |
63
+ | Call | `{ text, phone }` | dials the number (`cta_call`) |
64
+ | Copy | `{ text, copy }` | copies the code (`cta_copy`) |
65
+ | Reply | `{ text, id }` | sends the text back as a reply (`quick_reply`) |
66
+
67
+ At most **3** buttons per message.
68
+
69
+ ### Options
70
+
71
+ | Option | Meaning |
72
+ |--------|---------|
73
+ | `body` / `text` | main text of the card |
74
+ | `footer` | small grey text under the buttons |
75
+ | `title` / `subtitle` | bold title / subtitle above the body |
76
+ | `image` | header image on top of the card |
77
+ | `buttons` | 1–3 buttons (see above) |
78
+ | `contextInfo` | quote/mention info, like any message |
79
+
80
+ Need an exotic native-flow button? Pass it raw and it is sent untouched:
81
+
82
+ ```js
83
+ buttons: [
84
+ { name: 'single_select', buttonParamsJson: JSON.stringify({ title: 'Pick', sections: [/* ... */] }) }
85
+ ]
86
+ ```
87
+
88
+ ## CLI
89
+
90
+ ```
91
+ /button <jid> <body> | <Label>=<target> | <Label2> | ...
92
+ ```
93
+
94
+ Each button is `Label=target`, separated by `|`:
95
+
96
+ | Target form | Button |
97
+ |-------------|--------|
98
+ | `https://site.com` | link button |
99
+ | `call:15551234567` | call button |
100
+ | `copy:CODE123` | copy button |
101
+ | *(no `=target`)* | quick reply |
102
+
103
+ Example:
104
+
105
+ ```
106
+ /button 40712345678 Check our offer! | Open=https://example.com | Call=call:15551234567 | Yes
107
+ ```
108
+
109
+ ## How it works
110
+
111
+ An interactive message is `Message.interactiveMessage` (protobuf field 45) with
112
+ a `nativeFlowMessage` carrying the buttons. whalibmob also attaches the
113
+ `<biz><interactive type="native_flow" v="1"><native_flow v="9" name="mixed"/></interactive></biz>`
114
+ stanza node — without it the server accepts the message but clients do not draw
115
+ the buttons.
@@ -0,0 +1,71 @@
1
+ 'use strict';
2
+
3
+ // ─── Interactive "card" messages (link / call / copy / quick-reply buttons) ──
4
+ //
5
+ // Shows how to send a message with tappable buttons from the whalibmob Node API.
6
+ // Works the same whether the session was registered over SMS (mobile) or linked
7
+ // as a companion (web) — a message is encoded identically on both.
8
+ //
9
+ // node examples/interactive-buttons.js <phone-number>
10
+ //
11
+ // NOTE on deliverability: sending interactive buttons is something only official
12
+ // clients normally do, so WhatsApp can flag the sending account. Use a warmed,
13
+ // trusted account, send to people who expect it, and do not blast strangers —
14
+ // that is the fastest way to get an account banned.
15
+
16
+ const { WhalibmobClient } = require('..'); // require('whalibmob') in your project
17
+
18
+ async function main() {
19
+ const to = process.argv[2];
20
+ if (!to) {
21
+ console.error('usage: node examples/interactive-buttons.js <phone-number>');
22
+ process.exit(1);
23
+ }
24
+
25
+ // Load an existing registered/linked session (adjust to your setup).
26
+ const client = new WhalibmobClient();
27
+ await client.connect(); // or connectWeb() for a companion session
28
+
29
+ client.on('ready', async () => {
30
+ // 1) A plain card: body + footer + one link button.
31
+ await client.sendInteractive(to, {
32
+ body: 'Welcome! Tap below to visit our site.',
33
+ footer: 'Sent with whalibmob',
34
+ buttons: [
35
+ { text: 'Open website', url: 'https://example.com' }
36
+ ]
37
+ });
38
+
39
+ // 2) A "card" with an image header and three mixed buttons.
40
+ await client.sendInteractive(to, {
41
+ image: './banner.jpg', // header image (path, Buffer, or URL)
42
+ title: 'VIP Offer',
43
+ body: 'Here is your personal bonus 🎁',
44
+ footer: 'whalibmob',
45
+ buttons: [
46
+ { text: 'Claim now', url: 'https://example.com/claim' },
47
+ { text: 'Call us', phone: '15551234567' },
48
+ { text: 'Copy code', copy: 'PROMO2026' }
49
+ ]
50
+ });
51
+
52
+ // 3) Quick-reply buttons (no url/phone/copy → the text comes back as a reply).
53
+ await client.sendInteractive(to, {
54
+ body: 'Do you confirm your order?',
55
+ buttons: [
56
+ { text: 'Yes', id: 'confirm_yes' },
57
+ { text: 'No', id: 'confirm_no' }
58
+ ]
59
+ });
60
+
61
+ console.log('All three interactive messages sent.');
62
+ });
63
+
64
+ // When the recipient taps a quick-reply button, it arrives as a normal message
65
+ // whose interactiveResponseMessage carries the button id.
66
+ client.on('message', (m) => {
67
+ console.log('incoming:', JSON.stringify(m).slice(0, 200));
68
+ });
69
+ }
70
+
71
+ main().catch((e) => { console.error(e); process.exit(1); });
package/index.d.ts CHANGED
@@ -394,6 +394,43 @@ export interface MediaSendOptions extends SendOptions {
394
394
  thumbnail?: Buffer;
395
395
  }
396
396
 
397
+ /** One tappable button on an interactive ("card") message. */
398
+ export interface InteractiveButton {
399
+ /** Button label shown to the user. */
400
+ text?: string;
401
+ /** A link button (cta_url): opens this URL when tapped. */
402
+ url?: string;
403
+ /** Optional merchant URL that pairs with `url`. */
404
+ merchantUrl?: string;
405
+ /** A call button (cta_call): dials this number. */
406
+ phone?: string;
407
+ /** A copy button (cta_copy): copies this code to the clipboard. */
408
+ copy?: string;
409
+ /** Quick-reply id sent back when the button (with no url/phone/copy) is tapped. */
410
+ id?: string;
411
+ /** Raw native-flow button name, for hand-crafted flows (overrides the above). */
412
+ name?: string;
413
+ /** Raw native-flow button params JSON, used together with `name`. */
414
+ buttonParamsJson?: string;
415
+ }
416
+
417
+ export interface InteractiveSendOptions extends SendOptions {
418
+ /** Main body text of the card. */
419
+ body?: string;
420
+ /** Alias for `body`. */
421
+ text?: string;
422
+ /** Small grey text under the buttons. */
423
+ footer?: string;
424
+ /** Bold title shown above the body. */
425
+ title?: string;
426
+ /** Subtitle shown under the title. */
427
+ subtitle?: string;
428
+ /** Optional header image on top of the card (path, Buffer, or URL/base64). */
429
+ image?: MediaSource;
430
+ /** 1 to 3 buttons. */
431
+ buttons: InteractiveButton[];
432
+ }
433
+
397
434
  export interface DocumentSendOptions extends SendOptions {
398
435
  fileName?: string;
399
436
  title?: string;
@@ -1470,6 +1507,12 @@ export declare class WhalibmobClient extends EventEmitter {
1470
1507
  // ─── Sending ─────────────────────────────────────────────────────────────
1471
1508
  sendText(to: Jid, text: string, opts?: SendOptions): Promise<SendResult>;
1472
1509
  sendImage(to: Jid, data: MediaSource, opts?: MediaSendOptions): Promise<SendResult>;
1510
+ /**
1511
+ * Send an interactive "card" message: body text, an optional header image and
1512
+ * up to three tappable buttons (link / call / copy / quick-reply). Works the
1513
+ * same on a mobile-registered number and a linked web/companion session.
1514
+ */
1515
+ sendInteractive(to: Jid, opts: InteractiveSendOptions): Promise<SendResult>;
1473
1516
  sendVideo(to: Jid, data: MediaSource, opts?: VideoSendOptions): Promise<SendResult>;
1474
1517
  sendAudio(to: Jid, data: MediaSource, opts?: AudioSendOptions): Promise<SendResult>;
1475
1518
  sendDocument(to: Jid, data: MediaSource, opts?: DocumentSendOptions): Promise<SendResult>;
package/lib/Client.js CHANGED
@@ -7844,6 +7844,25 @@ class WhalibmobClient extends EventEmitter {
7844
7844
  return this._sender.sendImage(to, data, opts);
7845
7845
  }
7846
7846
 
7847
+ // Send an interactive "card" message: body text, an optional header image and
7848
+ // up to three tappable buttons (a link button, a call button, a copy button
7849
+ // or a quick-reply). Same on mobile and web/companion sessions.
7850
+ //
7851
+ // client.sendInteractive('40712345678', {
7852
+ // body: 'Check this out!',
7853
+ // footer: 'whalibmob',
7854
+ // image: './banner.jpg',
7855
+ // buttons: [
7856
+ // { text: 'Open', url: 'https://example.com' },
7857
+ // { text: 'Call', phone: '15551234567' },
7858
+ // { text: 'Copy code', copy: 'PROMO2026' }
7859
+ // ]
7860
+ // });
7861
+ async sendInteractive(to, opts) {
7862
+ if (!this._sender || !this._connected) throw new Boom('Not connected', { statusCode: 428 });
7863
+ return this._sender.sendInteractive(to, opts);
7864
+ }
7865
+
7847
7866
  async sendVideo(to, data, opts) {
7848
7867
  if (!this._sender || !this._connected) throw new Boom('Not connected', { statusCode: 428 });
7849
7868
  return this._sender.sendVideo(to, data, opts);
@@ -12,6 +12,7 @@ const { BinaryNode } = require('../BinaryNode');
12
12
  const { DeviceManager, jidStrToObj } = require('../DeviceManager');
13
13
  const {
14
14
  encodeMessage,
15
+ encodeInteractiveMessage,
15
16
  encodeText, encodeImageMessage, encodeVideoMessage,
16
17
  encodeAudioMessage, encodeDocumentMessage,
17
18
  encodeStickerMessage, encodeReactionMessage,
@@ -39,6 +40,34 @@ function generateMessageId() {
39
40
 
40
41
  function msNow() { return Math.floor(Date.now() / 1000); }
41
42
 
43
+ // Turn a friendly button spec into a native-flow button {name, buttonParamsJson}.
44
+ // A button already in native-flow shape (it has name + buttonParamsJson) is
45
+ // passed through untouched, so a caller can hand-craft exotic flows.
46
+ // { url, text } → cta_url (a hyperlink/link button)
47
+ // { phone, text } → cta_call (dials the number)
48
+ // { copy, text } → cta_copy (copies a code to the clipboard)
49
+ // { text, id? } → quick_reply (sends the text back as a reply)
50
+ function toNativeFlowButton(b) {
51
+ b = b || {};
52
+ if (b.name && b.buttonParamsJson) return b;
53
+ const text = b.text || b.displayText || b.display_text || '';
54
+ if (b.url) {
55
+ const p = { display_text: text, url: b.url };
56
+ if (b.merchantUrl || b.merchant_url) p.merchant_url = b.merchantUrl || b.merchant_url;
57
+ return { name: 'cta_url', buttonParamsJson: JSON.stringify(p) };
58
+ }
59
+ if (b.phone || b.phoneNumber || b.phone_number) {
60
+ return { name: 'cta_call', buttonParamsJson: JSON.stringify({
61
+ display_text: text, phone_number: b.phone || b.phoneNumber || b.phone_number }) };
62
+ }
63
+ if (b.copy || b.copyCode || b.copy_code) {
64
+ return { name: 'cta_copy', buttonParamsJson: JSON.stringify({
65
+ display_text: text, copy_code: b.copy || b.copyCode || b.copy_code }) };
66
+ }
67
+ return { name: 'quick_reply', buttonParamsJson: JSON.stringify({
68
+ display_text: text, id: b.id || text || 'btn' }) };
69
+ }
70
+
42
71
  function isGroupJid(jid) {
43
72
  return jid.endsWith('@g.us') || jid.endsWith('@community');
44
73
  }
@@ -330,6 +359,88 @@ class MessageSender {
330
359
  return this._sendMessage(toJid, msgId, imgBuf, 'media', { ...options, _mediaSubtype: 'image' });
331
360
  }
332
361
 
362
+ // ─── Interactive (native-flow buttons / "card" message) ─────────────────────
363
+ //
364
+ // Sends a message with up to three tappable buttons: a link button (cta_url),
365
+ // a call button, a copy button, or a quick-reply. Optionally an image on top,
366
+ // giving the "card" look. Works the same on a mobile-registered number and a
367
+ // linked (web/companion) session — a message is encoded identically either way.
368
+ //
369
+ // sendInteractive(to, {
370
+ // body: 'Hello!',
371
+ // footer: 'Powered by whalibmob',
372
+ // image: './banner.jpg', // optional header image
373
+ // buttons: [
374
+ // { text: 'Open site', url: 'https://example.com' },
375
+ // { text: 'Call us', phone: '15551234567' },
376
+ // { text: 'Yes', id: 'yes' }
377
+ // ]
378
+ // })
379
+ async sendInteractive(to, options) {
380
+ options = options || {};
381
+ const msgId = options.id || generateMessageId();
382
+ const toJid = makeJid(to);
383
+
384
+ const raw = Array.isArray(options.buttons) ? options.buttons : [];
385
+ if (raw.length === 0) {
386
+ throw new Boom('sendInteractive needs at least one button', { statusCode: 400 });
387
+ }
388
+ if (raw.length > 3) {
389
+ throw new Boom('WhatsApp allows at most 3 interactive buttons', { statusCode: 400 });
390
+ }
391
+ const buttons = raw.map(toNativeFlowButton);
392
+
393
+ // The header image — the top of the "card". Uploaded like any photo.
394
+ let headerImage = null;
395
+ if (options.image) {
396
+ const buf = this._toMediaBuffer(options.image);
397
+ const [upload, meta] = await Promise.all([
398
+ this._uploadMedia('image', buf),
399
+ imageThumbnail(buf).catch(() => ({}))
400
+ ]);
401
+ headerImage = {
402
+ url: upload.url,
403
+ mimetype: upload.mimetype || 'image/jpeg',
404
+ caption: '',
405
+ fileSha256: upload.fileSha256,
406
+ fileLength: upload.fileLength || 0,
407
+ height: upload.height || meta.height || 0,
408
+ width: upload.width || meta.width || 0,
409
+ mediaKey: upload.mediaKey,
410
+ fileEncSha256: upload.fileEncSha256,
411
+ directPath: upload.directPath,
412
+ mediaKeyTimestamp: upload.mediaKeyTimestamp || Math.floor(Date.now() / 1000),
413
+ jpegThumbnail: upload.jpegThumbnail || meta.thumbnail || null
414
+ };
415
+ }
416
+
417
+ const content = encodeInteractiveMessage({
418
+ body: options.body != null ? options.body : (options.text || ''),
419
+ footer: options.footer,
420
+ title: options.title,
421
+ subtitle: options.subtitle,
422
+ headerImage,
423
+ buttons,
424
+ contextInfo: options.contextInfo
425
+ });
426
+ const msgBuf = encodeMessage('interactive', content);
427
+
428
+ // The <biz> addon that makes clients render the buttons. name='mixed'
429
+ // covers cta_url / quick_reply / cta_call / cta_copy; without this node the
430
+ // server accepts the message but the buttons never show.
431
+ const bizNode = new BinaryNode('biz', {}, [
432
+ new BinaryNode('interactive', { type: 'native_flow', v: '1' }, [
433
+ new BinaryNode('native_flow', { v: '9', name: 'mixed' }, null)
434
+ ])
435
+ ]);
436
+
437
+ const sendOpts = Object.assign({}, options, {
438
+ additionalNodes: [bizNode].concat(options.additionalNodes || [])
439
+ });
440
+ // Routed as a 'text' stanza — an interactive message is a text-type message.
441
+ return this._sendMessage(toJid, msgId, msgBuf, 'text', sendOpts);
442
+ }
443
+
333
444
  // ─── Video ────────────────────────────────────────────────────────────────
334
445
 
335
446
  async sendVideo(to, videoData, options) {
@@ -1613,6 +1724,12 @@ class MessageSender {
1613
1724
  retryDepth: options._retryDepth || 0
1614
1725
  });
1615
1726
 
1727
+ // Extra children a caller needs on the stanza — e.g. the <biz> native-flow
1728
+ // addon an interactive message carries.
1729
+ for (const extra of options.additionalNodes || []) {
1730
+ if (extra) msgContent.push(extra);
1731
+ }
1732
+
1616
1733
  // A poll says in the clear whether it is the poll or a vote on one.
1617
1734
  if (mediaType === 'poll') {
1618
1735
  msgContent.push(new BinaryNode('meta', { polltype: options._pollType || 'creation' }, null));
@@ -376,9 +376,76 @@ function encodeEncAddOnMessage(type, opts) {
376
376
  ]));
377
377
  }
378
378
 
379
+ // ─── InteractiveMessage (Message field 45) — native-flow buttons ─────────────
380
+ //
381
+ // A "card" message: an optional image/title header, body text, an optional
382
+ // footer, and up to three native-flow buttons — a link button (cta_url), a
383
+ // quick-reply button, a call button (cta_call) or a copy button (cta_copy).
384
+ //
385
+ // The matching <biz><interactive><native_flow/></biz> stanza node is attached
386
+ // by the sender (MessageSender.sendInteractive); without it the server accepts
387
+ // the message but clients do not render the buttons.
388
+ //
389
+ // InteractiveMessage { header=1, body=2, footer=3, nativeFlowMessage=6,
390
+ // contextInfo=15 }
391
+ // Body / Footer { text=1 }
392
+ // Header { title=1, subtitle=2, imageMessage=4, hasMediaAttachment=5 }
393
+ // NativeFlowMessage { buttons=1 (repeated), messageVersion=3 }
394
+ // NativeFlowButton { name=1, buttonParamsJson=2 }
395
+
396
+ function encodeNativeFlowButton(btn) {
397
+ return Buffer.concat([
398
+ field(1, WIRE_LEN, str(btn.name)),
399
+ field(2, WIRE_LEN, str(btn.buttonParamsJson))
400
+ ]);
401
+ }
402
+
403
+ function encodeInteractiveMessage(opts) {
404
+ opts = opts || {};
405
+ const parts = [];
406
+
407
+ // Header (field 1): title/subtitle and, optionally, an image on top. The
408
+ // image is a full ImageMessage, same shape as a standalone photo.
409
+ if (opts.title || opts.subtitle || opts.headerImage) {
410
+ const header = [];
411
+ if (opts.title) header.push(field(1, WIRE_LEN, str(opts.title)));
412
+ if (opts.subtitle) header.push(field(2, WIRE_LEN, str(opts.subtitle)));
413
+ if (opts.headerImage) {
414
+ header.push(field(4, WIRE_LEN, encodeImageMessage(opts.headerImage)));
415
+ header.push(field(5, WIRE_VARINT, bool(true))); // hasMediaAttachment
416
+ }
417
+ parts.push(field(1, WIRE_LEN, Buffer.concat(header)));
418
+ }
419
+
420
+ // Body (field 2 → text=1): the main text of the card.
421
+ if (opts.body != null) {
422
+ parts.push(field(2, WIRE_LEN, field(1, WIRE_LEN, str(opts.body))));
423
+ }
424
+
425
+ // Footer (field 3 → text=1): small grey text under the buttons.
426
+ if (opts.footer != null) {
427
+ parts.push(field(3, WIRE_LEN, field(1, WIRE_LEN, str(opts.footer))));
428
+ }
429
+
430
+ // NativeFlowMessage (field 6): the buttons. messageVersion is 1.
431
+ const buttons = Array.isArray(opts.buttons) ? opts.buttons : [];
432
+ const nf = [];
433
+ for (const b of buttons) nf.push(field(1, WIRE_LEN, encodeNativeFlowButton(b)));
434
+ nf.push(field(3, WIRE_VARINT, varint(opts.messageVersion || 1)));
435
+ parts.push(field(6, WIRE_LEN, Buffer.concat(nf)));
436
+
437
+ // ContextInfo (field 15): quotes and mentions, like any other message.
438
+ if (opts.contextInfo) {
439
+ parts.push(field(15, WIRE_LEN, encodeContextInfo(opts.contextInfo)));
440
+ }
441
+
442
+ return Buffer.concat(parts);
443
+ }
444
+
379
445
  function encodeMessage(type, payload) {
380
446
  switch (type) {
381
447
  case 'text': return payload;
448
+ case 'interactive': return field(45, WIRE_LEN, payload);
382
449
  case 'image': return field(3, WIRE_LEN, payload);
383
450
  case 'document': return field(7, WIRE_LEN, payload);
384
451
  case 'audio': return field(8, WIRE_LEN, payload);
@@ -1327,6 +1394,7 @@ function encodeSenderKeyDistributionMessage(groupId, axolotlBytes) {
1327
1394
 
1328
1395
  module.exports = {
1329
1396
  encodeText,
1397
+ encodeInteractiveMessage,
1330
1398
  encodeImageMessage,
1331
1399
  encodeVideoMessage,
1332
1400
  encodeAudioMessage,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whalibmob",
3
- "version": "5.40.42",
3
+ "version": "5.40.44",
4
4
  "description": "Node.js library for WhatsApp — register a number over SMS, or link as a companion by QR. Signal E2E encryption, media, groups, channels.",
5
5
  "author": "Kunboruto20",
6
6
  "main": "index.js",
@@ -14,6 +14,7 @@
14
14
  "cli.js",
15
15
  "lib/**/*.js",
16
16
  "tools/**/*.js",
17
+ "examples/**/*.js",
17
18
  "README.md",
18
19
  "docs/**/*.md",
19
20
  "llms.txt",