@kyyinfinite/zapo-message 0.0.0-stage → 1.0.0

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.
Files changed (191) hide show
  1. package/CHANGELOG.md +159 -0
  2. package/LICENSE +20 -0
  3. package/README.md +532 -2
  4. package/build.config.json +28 -0
  5. package/dist/airich/airich.d.ts +180 -0
  6. package/dist/airich/airich.js +548 -0
  7. package/dist/airich/context.d.ts +24 -0
  8. package/dist/airich/context.js +48 -0
  9. package/dist/airich/encode.d.ts +3 -0
  10. package/dist/airich/encode.js +16 -0
  11. package/dist/airich/index.d.ts +20 -0
  12. package/dist/airich/index.js +11 -0
  13. package/dist/airich/inline.d.ts +45 -0
  14. package/dist/airich/inline.js +152 -0
  15. package/dist/airich/nodes.d.ts +30 -0
  16. package/dist/airich/nodes.js +121 -0
  17. package/dist/airich/primitives.d.ts +144 -0
  18. package/dist/airich/primitives.js +230 -0
  19. package/dist/airich/protocol.d.ts +35 -0
  20. package/dist/airich/protocol.js +65 -0
  21. package/dist/airich/table.d.ts +22 -0
  22. package/dist/airich/table.js +35 -0
  23. package/dist/airich/tokenizer.d.ts +13 -0
  24. package/dist/airich/tokenizer.js +717 -0
  25. package/dist/airich/transport.d.ts +15 -0
  26. package/dist/airich/transport.js +56 -0
  27. package/dist/branding.d.ts +5 -0
  28. package/dist/branding.js +9 -0
  29. package/dist/btn/builders.d.ts +246 -0
  30. package/dist/btn/builders.js +710 -0
  31. package/dist/btn/media-slot.d.ts +28 -0
  32. package/dist/btn/media-slot.js +323 -0
  33. package/dist/btn/media-source.d.ts +38 -0
  34. package/dist/btn/media-source.js +116 -0
  35. package/dist/btn/sharp-loader.d.ts +5 -0
  36. package/dist/btn/sharp-loader.js +18 -0
  37. package/dist/btn/thumbnail.d.ts +21 -0
  38. package/dist/btn/thumbnail.js +124 -0
  39. package/dist/btn/validators.d.ts +40 -0
  40. package/dist/btn/validators.js +135 -0
  41. package/dist/btn.d.ts +1 -0
  42. package/dist/btn.js +1 -0
  43. package/dist/core/async-send.d.ts +20 -0
  44. package/dist/core/async-send.js +1 -0
  45. package/dist/core/base-builder.d.ts +20 -0
  46. package/dist/core/base-builder.js +67 -0
  47. package/dist/core/errors.d.ts +30 -0
  48. package/dist/core/errors.js +61 -0
  49. package/dist/download.d.ts +24 -0
  50. package/dist/download.js +123 -0
  51. package/dist/index.d.ts +38 -0
  52. package/dist/index.js +22 -0
  53. package/dist/integration/augment.d.ts +97 -0
  54. package/dist/integration/augment.js +1 -0
  55. package/dist/integration/auto.d.ts +8 -0
  56. package/dist/integration/auto.js +79 -0
  57. package/dist/integration/index.d.ts +4 -0
  58. package/dist/integration/index.js +2 -0
  59. package/dist/integration/methods.d.ts +25 -0
  60. package/dist/integration/methods.js +24 -0
  61. package/dist/interactive.d.ts +24 -0
  62. package/dist/interactive.js +121 -0
  63. package/dist/media-gate.d.ts +99 -0
  64. package/dist/media-gate.js +322 -0
  65. package/dist/message/album.d.ts +33 -0
  66. package/dist/message/album.js +107 -0
  67. package/dist/message/contact.d.ts +29 -0
  68. package/dist/message/contact.js +123 -0
  69. package/dist/message/forward.d.ts +23 -0
  70. package/dist/message/forward.js +77 -0
  71. package/dist/message/index.d.ts +26 -0
  72. package/dist/message/index.js +13 -0
  73. package/dist/message/link-preview.d.ts +28 -0
  74. package/dist/message/link-preview.js +98 -0
  75. package/dist/message/location.d.ts +24 -0
  76. package/dist/message/location.js +94 -0
  77. package/dist/message/media.d.ts +90 -0
  78. package/dist/message/media.js +123 -0
  79. package/dist/message/poll.d.ts +24 -0
  80. package/dist/message/poll.js +98 -0
  81. package/dist/message/reaction.d.ts +20 -0
  82. package/dist/message/reaction.js +71 -0
  83. package/dist/message/sticker.d.ts +29 -0
  84. package/dist/message/sticker.js +44 -0
  85. package/dist/message/target.d.ts +18 -0
  86. package/dist/message/target.js +24 -0
  87. package/dist/message/text.d.ts +17 -0
  88. package/dist/message/text.js +29 -0
  89. package/dist/message/vcard.d.ts +9 -0
  90. package/dist/message/vcard.js +23 -0
  91. package/dist/message/webp.d.ts +6 -0
  92. package/dist/message/webp.js +57 -0
  93. package/dist/payloads.d.ts +180 -0
  94. package/dist/payloads.js +1 -0
  95. package/dist/serialize.d.ts +41 -0
  96. package/dist/serialize.js +93 -0
  97. package/dist/status.d.ts +3 -0
  98. package/dist/status.js +21 -0
  99. package/dist/zapo-client.d.ts +44 -0
  100. package/dist/zapo-client.js +1 -0
  101. package/examples/airich.ts +59 -0
  102. package/examples/buttons.ts +48 -0
  103. package/examples/client-methods.ts +58 -0
  104. package/examples/hybrid.ts +133 -0
  105. package/examples/serialize.ts +61 -0
  106. package/package.json +271 -4
  107. package/scripts/check-no-comments.mjs +101 -0
  108. package/scripts/compare-golden.mjs +461 -0
  109. package/scripts/lib-config.mjs +9 -0
  110. package/scripts/smoke-auto.mjs +75 -0
  111. package/scripts/test-external-consumer.mjs +316 -0
  112. package/scripts/verify-package.mjs +78 -0
  113. package/src/airich/airich.ts +970 -0
  114. package/src/airich/context.ts +96 -0
  115. package/src/airich/encode.ts +25 -0
  116. package/src/airich/index.ts +98 -0
  117. package/src/airich/inline.ts +272 -0
  118. package/src/airich/nodes.ts +174 -0
  119. package/src/airich/primitives.ts +474 -0
  120. package/src/airich/protocol.ts +133 -0
  121. package/src/airich/table.ts +70 -0
  122. package/src/airich/tokenizer.ts +799 -0
  123. package/src/airich/transport.ts +106 -0
  124. package/src/branding.ts +23 -0
  125. package/src/btn/builders.ts +1073 -0
  126. package/src/btn/media-slot.ts +486 -0
  127. package/src/btn/media-source.ts +189 -0
  128. package/src/btn/sharp-loader.ts +23 -0
  129. package/src/btn/thumbnail.ts +182 -0
  130. package/src/btn/validators.ts +237 -0
  131. package/src/btn.ts +8 -0
  132. package/src/core/async-send.ts +28 -0
  133. package/src/core/base-builder.ts +104 -0
  134. package/src/core/errors.ts +82 -0
  135. package/src/download.ts +212 -0
  136. package/src/index.ts +229 -0
  137. package/src/integration/augment.ts +262 -0
  138. package/src/integration/auto.ts +103 -0
  139. package/src/integration/index.ts +8 -0
  140. package/src/integration/methods.ts +45 -0
  141. package/src/interactive.ts +188 -0
  142. package/src/media-gate.ts +499 -0
  143. package/src/message/album.ts +187 -0
  144. package/src/message/contact.ts +170 -0
  145. package/src/message/forward.ts +123 -0
  146. package/src/message/index.ts +83 -0
  147. package/src/message/link-preview.ts +148 -0
  148. package/src/message/location.ts +150 -0
  149. package/src/message/media.ts +323 -0
  150. package/src/message/poll.ts +158 -0
  151. package/src/message/reaction.ts +133 -0
  152. package/src/message/sticker.ts +100 -0
  153. package/src/message/target.ts +38 -0
  154. package/src/message/text.ts +61 -0
  155. package/src/message/vcard.ts +36 -0
  156. package/src/message/webp.ts +78 -0
  157. package/src/payloads.ts +204 -0
  158. package/src/serialize.ts +180 -0
  159. package/src/status.ts +29 -0
  160. package/src/zapo-client.ts +84 -0
  161. package/test/airich-inline.test.ts +200 -0
  162. package/test/airich-primitives.test.ts +226 -0
  163. package/test/airich-tokenizer.test.ts +145 -0
  164. package/test/airich.golden.test.ts +406 -0
  165. package/test/airich.test.ts +1006 -0
  166. package/test/btn-button.test.ts +416 -0
  167. package/test/btn-header.test.ts +646 -0
  168. package/test/btn-legacy.test.ts +342 -0
  169. package/test/btn-lifecycle.test.ts +295 -0
  170. package/test/btn-list.test.ts +261 -0
  171. package/test/btn-media-source.test.ts +150 -0
  172. package/test/btn-thumbnail.test.ts +160 -0
  173. package/test/builder-compat.test.ts +264 -0
  174. package/test/helpers.ts +27 -0
  175. package/test/hybrid-airich.test.ts +345 -0
  176. package/test/hybrid-client.test.ts +239 -0
  177. package/test/hybrid-errors.test.ts +557 -0
  178. package/test/hybrid-interactive.test.ts +455 -0
  179. package/test/hybrid.golden.test.ts +349 -0
  180. package/test/hybrid.test.ts +479 -0
  181. package/test/integration-auto.test.ts +159 -0
  182. package/test/integration.fakeserver.test.ts +440 -0
  183. package/test/media-gate.test.ts +215 -0
  184. package/test/message-album.test.ts +145 -0
  185. package/test/message-builders.test.ts +401 -0
  186. package/test/message-media.test.ts +303 -0
  187. package/test/message.fakeserver.test.ts +284 -0
  188. package/test/message.golden.test.ts +254 -0
  189. package/test/serializer.test.ts +448 -0
  190. package/tsconfig.json +26 -0
  191. package/tsconfig.test.json +10 -0
@@ -0,0 +1,455 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import sharp from "sharp";
4
+
5
+ import {
6
+ button,
7
+ legacyButton,
8
+ listMessage,
9
+ type Button,
10
+ type ButtonBuildResult,
11
+ } from "@kyyinfinite/zapo-message";
12
+ import { asClient } from "./helpers.js";
13
+
14
+ const GOLDEN_UPLOAD = {
15
+ url: "https://mmg.whatsapp.net/v/t62.7118-24/golden",
16
+ directPath: "/v/t62.7118-24/golden",
17
+ mediaKey: new Uint8Array(32).fill(1),
18
+ fileSha256: new Uint8Array(32).fill(2),
19
+ fileEncSha256: new Uint8Array(32).fill(3),
20
+ fileLength: 1000,
21
+ mediaKeyTimestamp: 1730000000,
22
+ };
23
+
24
+ interface CapturedSend {
25
+ to: unknown;
26
+ content: unknown;
27
+ options: unknown;
28
+ }
29
+
30
+ const captureClient = () => {
31
+ const sends: CapturedSend[] = [];
32
+ const uploads: unknown[] = [];
33
+ const client = asClient({
34
+ message: {
35
+ upload: async (source: unknown, options: unknown) => {
36
+ uploads.push({ source, options });
37
+ return GOLDEN_UPLOAD;
38
+ },
39
+ send: async (to: unknown, content: unknown, options: unknown) => {
40
+ sends.push({ to, content, options });
41
+ return { id: `ID-${sends.length}`, attempts: 1, ack: {} };
42
+ },
43
+ },
44
+ });
45
+ return { client, sends, uploads };
46
+ };
47
+
48
+ const PNG_BYTES = await sharp({
49
+ create: { width: 120, height: 90, channels: 3, background: "#3060ff" },
50
+ })
51
+ .png()
52
+ .toBuffer();
53
+
54
+ const JPEG_BYTES = Buffer.concat([
55
+ Buffer.from([0xff, 0xd8, 0xff, 0xe0]),
56
+ Buffer.alloc(28, 1),
57
+ ]);
58
+
59
+ const plain = (value: unknown): unknown =>
60
+ JSON.parse(
61
+ JSON.stringify(value, (_key, raw) => {
62
+ if (raw instanceof Uint8Array) return { $bytes: raw.byteLength };
63
+ if (
64
+ raw &&
65
+ typeof raw === "object" &&
66
+ !Array.isArray(raw) &&
67
+ (raw as { type?: unknown }).type === "Buffer" &&
68
+ Array.isArray((raw as { data?: unknown }).data)
69
+ ) {
70
+ return { $bytes: (raw as { data: number[] }).data.length };
71
+ }
72
+ return raw;
73
+ }),
74
+ );
75
+
76
+ const maskExpiry = (value: unknown): unknown => {
77
+ const text = JSON.stringify(plain(value), (_key, raw) =>
78
+ typeof raw === "string" && raw.includes('"limited_time_offer"')
79
+ ? raw.replace(/"expiration_time":\d+/g, '"expiration_time":"MASKED"')
80
+ : raw,
81
+ );
82
+ return JSON.parse(text, (key, raw) => {
83
+ if (
84
+ key === "buttonParamsJson" &&
85
+ typeof raw === "string" &&
86
+ raw.includes("expiration_time")
87
+ ) {
88
+ return raw.replace(/"expiration_time":\d+/, '"expiration_time":0');
89
+ }
90
+ return raw;
91
+ });
92
+ };
93
+
94
+ const assertSameSend = (
95
+ a: CapturedSend | undefined,
96
+ b: CapturedSend | undefined,
97
+ label: string,
98
+ ): void => {
99
+ assert.ok(a, `async send tercatat: ${label}`);
100
+ assert.ok(b, `chain send tercatat: ${label}`);
101
+ assert.equal(a.to, b.to, `${label}: tujuan sama`);
102
+ assert.deepEqual(
103
+ maskExpiry(a.content),
104
+ maskExpiry(b.content),
105
+ `${label}: payload sama`,
106
+ );
107
+ assert.deepEqual(a.options, b.options, `${label}: opsi sama`);
108
+ };
109
+
110
+ test("hybrid button: async dan chain identik untuk seluruh primitive", async () => {
111
+ const asyncCap = captureClient();
112
+ const chainCap = captureClient();
113
+ const config = {
114
+ title: "Main Menu",
115
+ subtitle: "Welcome",
116
+ body: "Choose one",
117
+ footer: "Powered by Avelyna",
118
+ buttons: [
119
+ { type: "quick_reply" as const, text: "Profile", id: "profile" },
120
+ {
121
+ type: "cta_url" as const,
122
+ text: "Website",
123
+ url: "https://example.com",
124
+ },
125
+ { type: "cta_copy" as const, text: "Copy Code", copyCode: "AVELYNA" },
126
+ {
127
+ type: "cta_call" as const,
128
+ text: "Contact",
129
+ phoneNumber: "+628123456789",
130
+ },
131
+ { type: "send_location" as const, text: "Kirim lokasi" },
132
+ {
133
+ type: "single_select" as const,
134
+ title: "Pilih salah satu",
135
+ sections: [
136
+ {
137
+ title: "Utama",
138
+ rows: [
139
+ { id: "a", title: "Opsi A", description: "deskripsi A" },
140
+ { id: "b", title: "Opsi B" },
141
+ ],
142
+ },
143
+ ],
144
+ },
145
+ ],
146
+ };
147
+
148
+ await button(asyncCap.client, "6281@s.whatsapp.net", config);
149
+ await button(chainCap.client)
150
+ .to("6281@s.whatsapp.net")
151
+ .title("Main Menu")
152
+ .subtitle("Welcome")
153
+ .body("Choose one")
154
+ .footer("Powered by Avelyna")
155
+ .quick_reply("Profile", "profile")
156
+ .cta_url("Website", "https://example.com")
157
+ .cta_copy("Copy Code", "AVELYNA")
158
+ .cta_call("Contact", "+628123456789")
159
+ .send_location("Kirim lokasi")
160
+ .single_select("Pilih salah satu", config.buttons[5]!.sections!)
161
+ .send();
162
+
163
+ assertSameSend(asyncCap.sends[0], chainCap.sends[0], "button primitives");
164
+
165
+ const payload = plain(asyncCap.sends[0]?.content) as {
166
+ interactiveMessage: {
167
+ header: Record<string, unknown>;
168
+ nativeFlowMessage: {
169
+ buttons: { name: string; buttonParamsJson: string }[];
170
+ };
171
+ };
172
+ };
173
+ assert.equal(payload.interactiveMessage.header.title, "Main Menu");
174
+ assert.equal(payload.interactiveMessage.header.subtitle, "Welcome");
175
+ const names = payload.interactiveMessage.nativeFlowMessage.buttons.map(
176
+ (entry) => entry.name,
177
+ );
178
+ assert.deepEqual(names, [
179
+ "quick_reply",
180
+ "cta_url",
181
+ "cta_copy",
182
+ "cta_call",
183
+ "send_location",
184
+ "single_select",
185
+ ]);
186
+ });
187
+
188
+ test("hybrid button: bottom sheet dan limited time offer", async () => {
189
+ const asyncCap = captureClient();
190
+ const chainCap = captureClient();
191
+ const config = {
192
+ body: "Promo",
193
+ buttons: [{ type: "quick_reply" as const, text: "Ambil", id: "ambil" }],
194
+ bottomSheet: { limit: 2, listTitle: "Daftar", buttonTitle: "Buka" },
195
+ limitedTimeOffer: {
196
+ text: "Promo akhir tahun",
197
+ url: "https://example.com/promo",
198
+ copyCode: "PROMO2026",
199
+ expiresIn: 3600,
200
+ },
201
+ };
202
+ await button(asyncCap.client, "6281@s.whatsapp.net", config);
203
+ const builder: Button = button(chainCap.client)
204
+ .body("Promo")
205
+ .quick_reply("Ambil", "ambil")
206
+ .bottom_sheet({
207
+ limit: 2,
208
+ listTitle: "Daftar",
209
+ buttonTitle: "Buka",
210
+ })
211
+ .limited_time_offer({
212
+ text: "Promo akhir tahun",
213
+ url: "https://example.com/promo",
214
+ copyCode: "PROMO2026",
215
+ expiresIn: 3600,
216
+ });
217
+ await builder.send("6281@s.whatsapp.net");
218
+ assertSameSend(asyncCap.sends[0], chainCap.sends[0], "button extras");
219
+
220
+ const payload = asyncCap.sends[0]?.content as ButtonBuildResult;
221
+ const paramsJson = (
222
+ payload.interactiveMessage.nativeFlowMessage as unknown as {
223
+ messageParamsJson?: string;
224
+ }
225
+ ).messageParamsJson;
226
+ assert.ok(paramsJson, "messageParamsJson ada");
227
+ const params = JSON.parse(paramsJson!) as Record<string, unknown>;
228
+ assert.deepEqual(params.bottom_sheet, {
229
+ in_thread_buttons_limit: 2,
230
+ list_title: "Daftar",
231
+ button_title: "Buka",
232
+ });
233
+ const offer = params.limited_time_offer as Record<string, unknown>;
234
+ assert.equal(offer.copy_code, "PROMO2026");
235
+ assert.equal(typeof offer.expiration_time, "number");
236
+ });
237
+
238
+ test("hybrid button: seluruh header media identik", async () => {
239
+ const headerCases = [
240
+ {
241
+ label: "header image",
242
+ config: { type: "image" as const, source: PNG_BYTES },
243
+ chain: (b: Button) => b.image(PNG_BYTES),
244
+ },
245
+ {
246
+ label: "header document",
247
+ config: {
248
+ type: "document" as const,
249
+ source: PNG_BYTES,
250
+ fileName: "menu.pdf",
251
+ },
252
+ chain: (b: Button) => b.document(PNG_BYTES, { fileName: "menu.pdf" }),
253
+ },
254
+ ];
255
+
256
+ for (const { label, config, chain } of headerCases) {
257
+ const asyncCap = captureClient();
258
+ const chainCap = captureClient();
259
+ await button(asyncCap.client, "6281@s.whatsapp.net", {
260
+ body: "Pilih",
261
+ header: config,
262
+ buttons: [{ type: "quick_reply" as const, text: "OK", id: "ok" }],
263
+ });
264
+ const builder = chain(button(chainCap.client).body("Pilih")).quick_reply(
265
+ "OK",
266
+ "ok",
267
+ );
268
+ await builder.send("6281@s.whatsapp.net");
269
+ assertSameSend(asyncCap.sends[0], chainCap.sends[0], label);
270
+ const payload = plain(asyncCap.sends[0]?.content) as {
271
+ interactiveMessage: { header: { hasMediaAttachment: boolean } };
272
+ };
273
+ assert.equal(payload.interactiveMessage.header.hasMediaAttachment, true);
274
+ }
275
+ });
276
+
277
+ test("hybrid button: header location dan header thumbnail", async () => {
278
+ const asyncCap = captureClient();
279
+ await button(asyncCap.client, "6281@s.whatsapp.net", {
280
+ body: "Lokasi kami",
281
+ header: { type: "location", latitude: -6.2, longitude: 106.8 },
282
+ buttons: [{ type: "quick_reply" as const, text: "OK", id: "ok" }],
283
+ });
284
+ const payload = plain(asyncCap.sends[0]?.content) as {
285
+ interactiveMessage: {
286
+ header: { locationMessage: Record<string, unknown> };
287
+ };
288
+ };
289
+ assert.deepEqual(payload.interactiveMessage.header.locationMessage, {
290
+ degreesLatitude: -6.2,
291
+ degreesLongitude: 106.8,
292
+ });
293
+
294
+ const thumbCap = captureClient();
295
+ await button(thumbCap.client, "6281@s.whatsapp.net", {
296
+ body: "Info",
297
+ header: { type: "thumbnail", jpegThumbnail: JPEG_BYTES },
298
+ buttons: [{ type: "quick_reply" as const, text: "OK", id: "ok" }],
299
+ });
300
+ const thumbPayload = plain(thumbCap.sends[0]?.content) as {
301
+ interactiveMessage: { header: { jpegThumbnail: unknown } };
302
+ };
303
+ assert.deepEqual(thumbPayload.interactiveMessage.header.jpegThumbnail, {
304
+ $bytes: JPEG_BYTES.byteLength,
305
+ });
306
+ });
307
+
308
+ test("hybrid legacyButton: async dan chain identik", async () => {
309
+ const asyncCap = captureClient();
310
+ const chainCap = captureClient();
311
+ const config = {
312
+ title: "Menu",
313
+ body: "Select an option",
314
+ footer: "Avelyna",
315
+ buttons: [
316
+ { id: "profile", text: "Profile" },
317
+ { id: "help", text: "Bantuan" },
318
+ ],
319
+ };
320
+ await legacyButton(asyncCap.client, "6281@s.whatsapp.net", config);
321
+ await legacyButton(chainCap.client)
322
+ .to("6281@s.whatsapp.net")
323
+ .title("Menu")
324
+ .body("Select an option")
325
+ .footer("Avelyna")
326
+ .button("profile", "Profile")
327
+ .button("help", "Bantuan")
328
+ .send();
329
+ assertSameSend(asyncCap.sends[0], chainCap.sends[0], "legacyButton");
330
+ const payload = plain(asyncCap.sends[0]?.content) as {
331
+ buttonsMessage: { headerType: number; contentText: string };
332
+ };
333
+ assert.equal(payload.buttonsMessage.headerType, 2);
334
+ assert.equal(payload.buttonsMessage.contentText, "Select an option");
335
+ });
336
+
337
+ test("hybrid legacyButton: header location identik", async () => {
338
+ const asyncCap = captureClient();
339
+ const chainCap = captureClient();
340
+ await legacyButton(asyncCap.client, "6281@s.whatsapp.net", {
341
+ body: "Titik temu",
342
+ header: {
343
+ type: "location",
344
+ latitude: -6.175,
345
+ longitude: 106.827,
346
+ name: "Monas",
347
+ },
348
+ buttons: [{ id: "ok", text: "OK" }],
349
+ });
350
+ await legacyButton(chainCap.client)
351
+ .body("Titik temu")
352
+ .location({ latitude: -6.175, longitude: 106.827, name: "Monas" })
353
+ .button("ok", "OK")
354
+ .send("6281@s.whatsapp.net");
355
+ assertSameSend(asyncCap.sends[0], chainCap.sends[0], "legacy location");
356
+ });
357
+
358
+ test("hybrid listMessage: async dan chain identik", async () => {
359
+ const asyncCap = captureClient();
360
+ const chainCap = captureClient();
361
+ const config = {
362
+ title: "Main Menu",
363
+ body: "Choose a menu",
364
+ footer: "Avelyna",
365
+ buttonText: "Open",
366
+ sections: [
367
+ {
368
+ title: "General",
369
+ rows: [
370
+ { id: "profile", title: "Profile", description: "Your profile" },
371
+ { id: "settings", title: "Settings" },
372
+ ],
373
+ },
374
+ {
375
+ rows: [{ id: "about", title: "About" }],
376
+ },
377
+ ],
378
+ };
379
+ await listMessage(asyncCap.client, "6281@s.whatsapp.net", config);
380
+ await listMessage(chainCap.client)
381
+ .to("6281@s.whatsapp.net")
382
+ .title("Main Menu")
383
+ .body("Choose a menu")
384
+ .footer("Avelyna")
385
+ .buttonText("Open")
386
+ .section("General", [
387
+ { id: "profile", title: "Profile", description: "Your profile" },
388
+ { id: "settings", title: "Settings" },
389
+ ])
390
+ .section(undefined, [{ id: "about", title: "About" }])
391
+ .send();
392
+ assertSameSend(asyncCap.sends[0], chainCap.sends[0], "listMessage");
393
+ const payload = plain(asyncCap.sends[0]?.content) as {
394
+ listMessage: { title: string; buttonText: string; sections: unknown[] };
395
+ };
396
+ assert.equal(payload.listMessage.title, "Main Menu");
397
+ assert.equal(payload.listMessage.buttonText, "Open");
398
+ assert.equal(payload.listMessage.sections.length, 2);
399
+ });
400
+
401
+ test("hybrid listMessage: fallback native di grup identik", async () => {
402
+ const groupJid = "6281-1234@g.us";
403
+ const sections = [{ title: "Menu", rows: [{ id: "a", title: "A" }] }];
404
+ const asyncCap = captureClient();
405
+ const chainCap = captureClient();
406
+ await listMessage(asyncCap.client, groupJid, {
407
+ body: "Pilih",
408
+ buttonText: "Buka",
409
+ sections,
410
+ });
411
+ await listMessage(chainCap.client)
412
+ .body("Pilih")
413
+ .buttonText("Buka")
414
+ .section("Menu", [{ id: "a", title: "A" }])
415
+ .send(groupJid);
416
+ assertSameSend(asyncCap.sends[0], chainCap.sends[0], "list auto native");
417
+
418
+ const forcedNative = captureClient();
419
+ const forcedChain = captureClient();
420
+ await listMessage(forcedNative.client, "6281@s.whatsapp.net", {
421
+ body: "Pilih",
422
+ buttonText: "Buka",
423
+ sections,
424
+ fallback: "native",
425
+ });
426
+ await listMessage(forcedChain.client)
427
+ .body("Pilih")
428
+ .buttonText("Buka")
429
+ .section("Menu", [{ id: "a", title: "A" }])
430
+ .fallback("native")
431
+ .send("6281@s.whatsapp.net");
432
+ assertSameSend(
433
+ forcedNative.sends[0],
434
+ forcedChain.sends[0],
435
+ "list forced native",
436
+ );
437
+ const payload = plain(forcedNative.sends[0]?.content) as Record<
438
+ string,
439
+ unknown
440
+ >;
441
+ assert.ok(payload.interactiveMessage, "fallback native memakai interactive");
442
+
443
+ const inGroupCap = captureClient();
444
+ await listMessage(inGroupCap.client, "6281@s.whatsapp.net", {
445
+ body: "Pilih",
446
+ buttonText: "Buka",
447
+ sections,
448
+ inGroup: true,
449
+ });
450
+ const inGroupPayload = plain(inGroupCap.sends[0]?.content) as Record<
451
+ string,
452
+ unknown
453
+ >;
454
+ assert.ok(inGroupPayload.interactiveMessage, "inGroup memakai native flow");
455
+ });