whalibmob 5.40.41 → 5.40.43

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
@@ -27,12 +27,38 @@ code, and bring the account into being. Both transports, one API.
27
27
  [![Send messages](https://img.shields.io/badge/Send_messages-text_media_polls-34B7F1?style=for-the-badge)](https://github.com/Kunboruto20/whalibmob/blob/main/docs/messaging.md#sending-messages)
28
28
  [![Handle events](https://img.shields.io/badge/Handle_events-incoming_%26_receipts-34B7F1?style=for-the-badge)](https://github.com/Kunboruto20/whalibmob/blob/main/docs/events-history.md#handling-events)
29
29
 
30
+ [![NEW — Interactive buttons](https://img.shields.io/badge/NEW-Interactive_buttons_·_link_·_call_·_copy_·_reply-25D366?style=for-the-badge)](https://github.com/Kunboruto20/whalibmob/blob/main/docs/interactive-buttons.md)
31
+
30
32
  [![Device attestation](https://img.shields.io/badge/Device_attestation-Play_Integrity_%2B_App_Attest-8E44AD?style=for-the-badge)](https://github.com/Kunboruto20/whalibmob/blob/main/docs/attestation.md#device-attestation--play-integrity-and-app-attest)
31
33
 
32
34
  [![Why registration can be blocked](https://img.shields.io/badge/Why_registration_can_be_blocked-anti--abuse_%26_unofficial--client_checks-C0392B?style=for-the-badge)](https://github.com/Kunboruto20/whalibmob/blob/main/docs/accounts.md#why-registration-can-be-blocked--the-anti-abuse-landscape)
33
35
 
34
36
  </div>
35
37
 
38
+ > [!NOTE]
39
+ > **🆕 whalibmob now supports interactive button messages.**
40
+ >
41
+ > Send a "card" message with up to **three tappable buttons** — a **link** button
42
+ > (opens a URL), a **call** button (dials a number), a **copy** button (copies a
43
+ > code), or a **quick-reply** — with an optional header image. One call does it,
44
+ > from both the Node API and the `wa` CLI, and it works the **same on a
45
+ > mobile-registered number and a linked web/companion session** (a WhatsApp
46
+ > message is encoded identically on both).
47
+ >
48
+ > ```js
49
+ > await client.sendInteractive('14155552671', {
50
+ > body: 'Check this out!',
51
+ > footer: 'whalibmob',
52
+ > buttons: [
53
+ > { text: 'Open site', url: 'https://example.com' }, // link button
54
+ > { text: 'Call us', phone: '14155552671' }, // call button
55
+ > { text: 'Copy code', copy: 'PROMO2026' } // copy button
56
+ > ]
57
+ > });
58
+ > ```
59
+ >
60
+ > 👉 **Full guide, all button types and the CLI command: [docs/interactive-buttons.md](https://github.com/Kunboruto20/whalibmob/blob/main/docs/interactive-buttons.md)**
61
+
36
62
  > [!TIP]
37
63
  > **Registration not working on some numbers? Here is the 100% success route.**
38
64
  >
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);