@kyyinfinite/zapo-message 0.0.0-stage → 1.0.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.
Files changed (191) hide show
  1. package/CHANGELOG.md +159 -0
  2. package/LICENSE +20 -0
  3. package/README.md +1401 -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 +36 -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,1073 @@
1
+ import { isGroupJid, proto } from "zapo-js";
2
+ import type { Proto } from "zapo-js";
3
+ import { BaseBuilder, type SendResolutionArg } from "../core/base-builder.js";
4
+ import { sendConfigured, type MessageSendOptions } from "../core/async-send.js";
5
+ import type { MessageSendResult } from "../zapo-client.js";
6
+ import {
7
+ MessageError,
8
+ ValidationError,
9
+ DuplicateIdError,
10
+ } from "../core/errors.js";
11
+ import type { ZapoClient, ZapoSendOptions } from "../zapo-client.js";
12
+ import type {
13
+ ButtonBuildResult,
14
+ ButtonsMessagePayload,
15
+ InteractiveCardPayload,
16
+ InteractiveHeaderPayload,
17
+ LegacyButtonBuildResult,
18
+ ListBuildResult,
19
+ ListMessagePayload,
20
+ LocationMessagePayload,
21
+ MediaSlotResolution,
22
+ NativeFlowMessagePayload,
23
+ } from "../payloads.js";
24
+ import {
25
+ resolveMediaSlot,
26
+ type MediaSlot,
27
+ type MediaSlotOptions,
28
+ } from "./media-slot.js";
29
+ import type { MediaSource } from "./media-source.js";
30
+ import {
31
+ generateImageThumbnail,
32
+ validateJpegThumbnail,
33
+ asThumbnailBytes,
34
+ } from "./thumbnail.js";
35
+ import {
36
+ assertText,
37
+ assertId,
38
+ assertUniqueId,
39
+ assertUrl,
40
+ assertPhoneNumber,
41
+ assertPositiveInt,
42
+ validateNativeSections,
43
+ stringifyParams,
44
+ DISPLAY_TEXT_MAX,
45
+ SELECT_TITLE_MAX,
46
+ COPY_CODE_MAX,
47
+ LEGACY_BUTTON_LIMIT,
48
+ type NativeSection,
49
+ type NativeSectionRow,
50
+ } from "./validators.js";
51
+
52
+ const HeaderType = proto.Message.ButtonsMessage.HeaderType;
53
+ const ButtonType = proto.Message.ButtonsMessage.Button.Type;
54
+ const ListType = proto.Message.ListMessage.ListType;
55
+
56
+ interface CoordinateRange {
57
+ min: number;
58
+ max: number;
59
+ }
60
+
61
+ const assertCoordinate = (
62
+ value: unknown,
63
+ label: string,
64
+ { min, max }: CoordinateRange,
65
+ ): number => {
66
+ if (
67
+ typeof value !== "number" ||
68
+ !Number.isFinite(value) ||
69
+ value < min ||
70
+ value > max
71
+ ) {
72
+ throw new ValidationError(
73
+ `${label} harus number antara ${min} dan ${max}, diterima ${value}`,
74
+ );
75
+ }
76
+ return value;
77
+ };
78
+
79
+ const LEGACY_HEADER_TYPE_BY_KIND: Record<
80
+ "image" | "video" | "document",
81
+ proto.Message.ButtonsMessage.HeaderType
82
+ > = {
83
+ image: HeaderType.IMAGE,
84
+ video: HeaderType.VIDEO,
85
+ document: HeaderType.DOCUMENT,
86
+ };
87
+
88
+ type HeaderMediaSlot = MediaSlot & { kind: "image" | "video" | "document" };
89
+
90
+ export interface ImageHeaderOptions {
91
+ mimetype?: string;
92
+ width?: number;
93
+ height?: number;
94
+ caption?: string;
95
+ thumbnail?: Buffer | Uint8Array | false;
96
+ }
97
+
98
+ export interface VideoHeaderOptions {
99
+ mimetype?: string;
100
+ seconds?: number;
101
+ width?: number;
102
+ height?: number;
103
+ thumbnail?: Buffer | Uint8Array | false;
104
+ }
105
+
106
+ export interface DocumentHeaderOptions {
107
+ mimetype?: string;
108
+ fileName?: string;
109
+ title?: string;
110
+ thumbnail?: Buffer | Uint8Array | false;
111
+ }
112
+
113
+ export interface LocationHeaderOptions {
114
+ latitude?: number;
115
+ longitude?: number;
116
+ name?: string;
117
+ address?: string;
118
+ thumbnail?: Buffer | Uint8Array;
119
+ }
120
+
121
+ interface StoredLocation {
122
+ latitude: number;
123
+ longitude: number;
124
+ name?: string;
125
+ address?: string;
126
+ }
127
+
128
+ class BaseMessage extends BaseBuilder {
129
+ _body: string;
130
+ _footer: string | undefined;
131
+
132
+ constructor(client?: ZapoClient) {
133
+ super(client);
134
+ this._body = "";
135
+ this._footer = undefined;
136
+ }
137
+
138
+ body(text: string): this {
139
+ if (typeof text !== "string")
140
+ throw new ValidationError(`body harus string, diterima ${typeof text}`);
141
+ this._body = text;
142
+ return this;
143
+ }
144
+
145
+ footer(text: string | undefined): this {
146
+ if (text !== undefined && typeof text !== "string") {
147
+ throw new ValidationError(`footer harus string, diterima ${typeof text}`);
148
+ }
149
+ this._footer = text;
150
+ return this;
151
+ }
152
+ }
153
+
154
+ class HeaderMessage extends BaseMessage {
155
+ _title: string | undefined;
156
+ _subtitle: string | undefined;
157
+ _location: StoredLocation | null;
158
+ _thumb: Uint8Array | null;
159
+ _headerThumbnail: Uint8Array | null;
160
+ _mediaSlot: HeaderMediaSlot | null;
161
+
162
+ constructor(client?: ZapoClient) {
163
+ super(client);
164
+ this._title = undefined;
165
+ this._subtitle = undefined;
166
+ this._location = null;
167
+ this._thumb = null;
168
+ this._headerThumbnail = null;
169
+ this._mediaSlot = null;
170
+ }
171
+
172
+ location({
173
+ latitude,
174
+ longitude,
175
+ name,
176
+ address,
177
+ thumbnail,
178
+ }: LocationHeaderOptions = {}): this {
179
+ this.#assertNoMediaSlot(".location()");
180
+ if (this._headerThumbnail) {
181
+ throw new ValidationError(
182
+ ".headerThumbnail() tidak bisa dipakai bareng .location() — thumbnail location pakai .location({ thumbnail })",
183
+ );
184
+ }
185
+ const lat = assertCoordinate(latitude, "latitude", { min: -90, max: 90 });
186
+ const lng = assertCoordinate(longitude, "longitude", {
187
+ min: -180,
188
+ max: 180,
189
+ });
190
+ assertText(name, "name location", { required: false });
191
+ assertText(address, "address location", { required: false });
192
+ this._location = {
193
+ latitude: lat,
194
+ longitude: lng,
195
+ ...(name !== undefined ? { name } : {}),
196
+ ...(address !== undefined ? { address } : {}),
197
+ };
198
+ if (thumbnail) this.thumb(thumbnail);
199
+ return this;
200
+ }
201
+
202
+ thumb(buffer?: Buffer | Uint8Array | null): this {
203
+ if (this._headerThumbnail) {
204
+ throw new ValidationError(
205
+ ".thumb() tidak bisa dipakai bareng .headerThumbnail() — .thumb() khusus thumbnail location",
206
+ );
207
+ }
208
+ this.#assertNoMediaSlot(".thumb()");
209
+ this._thumb = buffer ? asThumbnailBytes(buffer) : null;
210
+ return this;
211
+ }
212
+
213
+ headerThumbnail(bytes: Buffer | Uint8Array): this {
214
+ if (this._location || this._thumb) {
215
+ throw new ValidationError(
216
+ ".headerThumbnail() tidak bisa dipakai bareng .location()/.thumb() — itu thumbnail location, bukan thumbnail header interaktif",
217
+ );
218
+ }
219
+ this.#assertNoMediaSlot(".headerThumbnail()");
220
+ this._headerThumbnail = validateJpegThumbnail(bytes, {
221
+ label: ".headerThumbnail()",
222
+ });
223
+ return this;
224
+ }
225
+
226
+ image(source: MediaSource, options: ImageHeaderOptions = {}): this {
227
+ return this.#setMediaSlot("image", source, options);
228
+ }
229
+
230
+ video(source: MediaSource, options: VideoHeaderOptions = {}): this {
231
+ return this.#setMediaSlot("video", source, options);
232
+ }
233
+
234
+ document(source: MediaSource, options: DocumentHeaderOptions = {}): this {
235
+ return this.#setMediaSlot("document", source, options);
236
+ }
237
+
238
+ #assertNoMediaSlot(caller: string): void {
239
+ if (this._mediaSlot) {
240
+ throw new ValidationError(
241
+ `${caller} tidak bisa dipakai bareng header media (${this._mediaSlot.kind}) — satu header hanya satu jenis konten`,
242
+ );
243
+ }
244
+ }
245
+
246
+ #setMediaSlot(
247
+ kind: "image" | "video" | "document",
248
+ source: MediaSource,
249
+ options: MediaSlotOptions | null,
250
+ ): this {
251
+ if (
252
+ options === null ||
253
+ typeof options !== "object" ||
254
+ Array.isArray(options)
255
+ ) {
256
+ throw new ValidationError(
257
+ `options ${kind}() harus object, diterima ${options === null ? "null" : typeof options}`,
258
+ );
259
+ }
260
+ if (this._location || this._thumb) {
261
+ throw new ValidationError(
262
+ `.${kind}() tidak bisa dipakai bareng .location()/.thumb() — satu header hanya satu jenis konten`,
263
+ );
264
+ }
265
+ if (this._headerThumbnail) {
266
+ throw new ValidationError(
267
+ `.${kind}() tidak bisa dipakai bareng .headerThumbnail() — thumbnail gambar header pakai .${kind}(source, { thumbnail })`,
268
+ );
269
+ }
270
+ this._mediaSlot = {
271
+ kind,
272
+ source,
273
+ options: { ...options },
274
+ label: `header ${kind}`,
275
+ };
276
+ return this;
277
+ }
278
+
279
+ protected async _resolveLocation(): Promise<LocationMessagePayload | null> {
280
+ if (!this._location) {
281
+ if (this._thumb) {
282
+ throw new ValidationError(
283
+ ".thumb() butuh .location() — thumbnail ini dipasang di locationMessage, bukan header interaktif",
284
+ );
285
+ }
286
+ return null;
287
+ }
288
+
289
+ const { latitude, longitude, name, address } = this._location;
290
+ const location: LocationMessagePayload = {
291
+ degreesLatitude: latitude,
292
+ degreesLongitude: longitude,
293
+ };
294
+ if (name !== undefined) location.name = name;
295
+ if (address !== undefined) location.address = address;
296
+ if (this._thumb?.length) {
297
+ location.jpegThumbnail = await generateImageThumbnail(this._thumb, {
298
+ label: "location .thumb()",
299
+ });
300
+ }
301
+ return location;
302
+ }
303
+
304
+ protected async _resolveSlotMedia(): Promise<MediaSlotResolution | null> {
305
+ const slot = this._mediaSlot;
306
+ if (!slot) return null;
307
+ if (slot.result) return slot.result;
308
+ if (!slot.promise) {
309
+ const client = this.client;
310
+ if (!client)
311
+ throw new MessageError(
312
+ "client belum diset — media header butuh client.message.upload",
313
+ "NO_CLIENT",
314
+ );
315
+ slot.promise = resolveMediaSlot(client, slot).then(
316
+ (result) => {
317
+ slot.result = result;
318
+ slot.promise = undefined;
319
+ return result;
320
+ },
321
+ (error: unknown) => {
322
+ slot.promise = undefined;
323
+ throw error;
324
+ },
325
+ );
326
+ }
327
+ return slot.promise;
328
+ }
329
+
330
+ protected async _resolveInteractiveHeader(): Promise<InteractiveHeaderPayload | null> {
331
+ const title = this._title;
332
+ const subtitle = this._subtitle;
333
+ const hasTitle = title !== undefined;
334
+ const hasSubtitle = subtitle !== undefined;
335
+
336
+ if (this._mediaSlot) {
337
+ const media = await this._resolveSlotMedia();
338
+ if (!media)
339
+ throw new ValidationError("header media tidak bisa diselesaikan");
340
+ const header: InteractiveHeaderPayload = { hasMediaAttachment: true };
341
+ if (media.field === "imageMessage") header.imageMessage = media.message;
342
+ else if (media.field === "videoMessage")
343
+ header.videoMessage = media.message;
344
+ else header.documentMessage = media.message;
345
+ if (hasTitle) header.title = title;
346
+ if (hasSubtitle) header.subtitle = subtitle;
347
+ return header;
348
+ }
349
+
350
+ if (this._location) {
351
+ const location = await this._resolveLocation();
352
+ const header: InteractiveHeaderPayload = {
353
+ hasMediaAttachment: true,
354
+ locationMessage: location,
355
+ };
356
+ if (hasTitle) header.title = title;
357
+ if (hasSubtitle) header.subtitle = subtitle;
358
+ return header;
359
+ }
360
+
361
+ if (this._headerThumbnail) {
362
+ const header: InteractiveHeaderPayload = {
363
+ hasMediaAttachment: false,
364
+ jpegThumbnail: this._headerThumbnail,
365
+ };
366
+ if (hasTitle) header.title = title;
367
+ if (hasSubtitle) header.subtitle = subtitle;
368
+ return header;
369
+ }
370
+
371
+ if (this._thumb) {
372
+ throw new ValidationError(
373
+ ".thumb() butuh .location() — thumbnail ini dipasang di locationMessage, bukan header interaktif",
374
+ );
375
+ }
376
+
377
+ if (hasTitle || hasSubtitle) {
378
+ const header: InteractiveHeaderPayload = { hasMediaAttachment: false };
379
+ if (hasTitle) header.title = title;
380
+ if (hasSubtitle) header.subtitle = subtitle;
381
+ return header;
382
+ }
383
+
384
+ return null;
385
+ }
386
+ }
387
+
388
+ export class Button extends HeaderMessage {
389
+ _buttons: { name: string; buttonParamsJson: string }[];
390
+ _params: Record<string, unknown>;
391
+ _offer: {
392
+ text?: string;
393
+ url?: string;
394
+ copy_code?: string;
395
+ expiresIn: number;
396
+ } | null;
397
+ _offerExpiration: number | null;
398
+ _ids: Set<string>;
399
+
400
+ constructor(client?: ZapoClient) {
401
+ super(client);
402
+ this._buttons = [];
403
+ this._params = {};
404
+ this._offer = null;
405
+ this._offerExpiration = null;
406
+ this._ids = new Set();
407
+ }
408
+
409
+ title(text: string | undefined): this {
410
+ assertText(text, "title", { max: SELECT_TITLE_MAX, required: false });
411
+ this._title = text;
412
+ return this;
413
+ }
414
+
415
+ subtitle(text: string | undefined): this {
416
+ assertText(text, "subtitle", { max: SELECT_TITLE_MAX, required: false });
417
+ this._subtitle = text;
418
+ return this;
419
+ }
420
+
421
+ #push(name: string, params: unknown): this {
422
+ this._buttons.push({
423
+ name,
424
+ buttonParamsJson: stringifyParams(params, `buttonParamsJson (${name})`),
425
+ });
426
+ return this;
427
+ }
428
+
429
+ quick_reply(display_text: string, id: string): this {
430
+ assertText(display_text, "display_text quick_reply", {
431
+ max: DISPLAY_TEXT_MAX,
432
+ });
433
+ assertId(id, "id quick_reply");
434
+ assertUniqueId(this._ids, id);
435
+ return this.#push("quick_reply", { display_text, id });
436
+ }
437
+
438
+ cta_url(display_text: string, url: string): this {
439
+ assertText(display_text, "display_text cta_url", { max: DISPLAY_TEXT_MAX });
440
+ assertUrl(url);
441
+ return this.#push("cta_url", { display_text, url });
442
+ }
443
+
444
+ cta_copy(display_text: string, copy_code: string): this {
445
+ assertText(display_text, "display_text cta_copy", {
446
+ max: DISPLAY_TEXT_MAX,
447
+ });
448
+ assertText(copy_code, "copy_code cta_copy", { max: COPY_CODE_MAX });
449
+ return this.#push("cta_copy", { display_text, copy_code });
450
+ }
451
+
452
+ cta_call(display_text: string, phone_number: string): this {
453
+ assertText(display_text, "display_text cta_call", {
454
+ max: DISPLAY_TEXT_MAX,
455
+ });
456
+ assertPhoneNumber(phone_number);
457
+ return this.#push("cta_call", { display_text, phone_number });
458
+ }
459
+
460
+ send_location(display_text?: string): this {
461
+ const params =
462
+ display_text === undefined
463
+ ? {}
464
+ : {
465
+ display_text: assertText(
466
+ display_text,
467
+ "display_text send_location",
468
+ { max: DISPLAY_TEXT_MAX },
469
+ ),
470
+ };
471
+ return this.#push("send_location", params);
472
+ }
473
+
474
+ single_select(title: string, sections: NativeSection[]): this {
475
+ assertText(title, "title single_select", { max: SELECT_TITLE_MAX });
476
+ validateNativeSections(sections);
477
+ return this.#push("single_select", { title, sections });
478
+ }
479
+
480
+ bottom_sheet({
481
+ limit = 1,
482
+ listTitle,
483
+ buttonTitle,
484
+ }: { limit?: number; listTitle?: string; buttonTitle?: string } = {}): this {
485
+ assertPositiveInt(limit, "limit bottom_sheet", { min: 1 });
486
+ assertText(listTitle, "listTitle bottom_sheet", { required: false });
487
+ assertText(buttonTitle, "buttonTitle bottom_sheet", { required: false });
488
+ this._params.bottom_sheet = {
489
+ in_thread_buttons_limit: limit,
490
+ ...(listTitle !== undefined ? { list_title: listTitle } : {}),
491
+ ...(buttonTitle !== undefined ? { button_title: buttonTitle } : {}),
492
+ };
493
+ return this;
494
+ }
495
+
496
+ limited_time_offer({
497
+ text,
498
+ url,
499
+ copyCode,
500
+ expiresIn = 24 * 60 * 60,
501
+ }: {
502
+ text?: string;
503
+ url?: string;
504
+ copyCode?: string;
505
+ expiresIn?: number;
506
+ } = {}): this {
507
+ assertText(text, "text limited_time_offer", { required: false });
508
+ if (url !== undefined) assertUrl(url, "url limited_time_offer");
509
+ assertText(copyCode, "copy_code limited_time_offer", {
510
+ max: COPY_CODE_MAX,
511
+ required: false,
512
+ });
513
+ assertPositiveInt(expiresIn, "expiresIn limited_time_offer", { min: 1 });
514
+ this._offer = {
515
+ ...(text !== undefined ? { text } : {}),
516
+ ...(url !== undefined ? { url } : {}),
517
+ ...(copyCode !== undefined ? { copy_code: copyCode } : {}),
518
+ expiresIn,
519
+ };
520
+ this._offerExpiration = null;
521
+ return this;
522
+ }
523
+
524
+ async toCard(): Promise<InteractiveCardPayload> {
525
+ if (!this._buttons.length) throw new ValidationError("minimal satu button");
526
+
527
+ const header = await this._resolveInteractiveHeader();
528
+ const footer = this._footer;
529
+ const card: InteractiveCardPayload = {
530
+ body: { text: this._body },
531
+ nativeFlowMessage: this.#buildNativeFlow(),
532
+ };
533
+ if (header) card.header = header;
534
+ if (footer !== undefined) card.footer = { text: footer };
535
+ return card;
536
+ }
537
+
538
+ override async build(): Promise<ButtonBuildResult> {
539
+ return { interactiveMessage: await this.toCard() };
540
+ }
541
+
542
+ #buildNativeFlow(): NativeFlowMessagePayload {
543
+ const params: Record<string, unknown> = { ...this._params };
544
+ if (this._offer) {
545
+ if (this._offerExpiration === null) {
546
+ this._offerExpiration =
547
+ Math.floor(Date.now() / 1000) + Math.floor(this._offer.expiresIn);
548
+ }
549
+ const { expiresIn: expires, ...offer } = this._offer;
550
+ params.limited_time_offer = {
551
+ ...offer,
552
+ expiration_time: this._offerExpiration,
553
+ };
554
+ }
555
+
556
+ const nativeFlowMessage: NativeFlowMessagePayload = {
557
+ buttons: [...this._buttons],
558
+ messageVersion: 1,
559
+ };
560
+ if (Object.keys(params).length) {
561
+ nativeFlowMessage.messageParamsJson = stringifyParams(
562
+ params,
563
+ "messageParamsJson",
564
+ );
565
+ }
566
+ return nativeFlowMessage;
567
+ }
568
+ }
569
+
570
+ export class LegacyButton extends HeaderMessage {
571
+ _buttons: Proto.Message.ButtonsMessage.Button.$Properties[];
572
+ _ids: Set<string>;
573
+
574
+ constructor(client?: ZapoClient) {
575
+ super(client);
576
+ this._buttons = [];
577
+ this._ids = new Set();
578
+ }
579
+
580
+ title(text: string | undefined): this {
581
+ assertText(text, "title legacy", {
582
+ max: DISPLAY_TEXT_MAX,
583
+ required: false,
584
+ });
585
+ this._title = text;
586
+ return this;
587
+ }
588
+
589
+ override headerThumbnail(_bytes?: Buffer | Uint8Array): this {
590
+ throw new ValidationError(
591
+ "LegacyButton tidak mendukung .headerThumbnail() — ButtonsMessage tidak punya field jpegThumbnail header; pakai .thumb() untuk location atau .image()/.video()/.document() untuk attachment",
592
+ );
593
+ }
594
+
595
+ button(id: string, text: string): this {
596
+ if (this._buttons.length >= LEGACY_BUTTON_LIMIT) {
597
+ throw new ValidationError(
598
+ `legacy buttons maksimal ${LEGACY_BUTTON_LIMIT}, tombol ke-${this._buttons.length + 1} ditolak`,
599
+ );
600
+ }
601
+ assertId(id, "buttonId legacy");
602
+ assertUniqueId(this._ids, id);
603
+ assertText(text, "displayText legacy button", { max: DISPLAY_TEXT_MAX });
604
+ this._buttons.push({
605
+ buttonId: id,
606
+ buttonText: { displayText: text },
607
+ type: ButtonType.RESPONSE,
608
+ });
609
+ return this;
610
+ }
611
+
612
+ override async build(): Promise<LegacyButtonBuildResult> {
613
+ if (!this._buttons.length) throw new ValidationError("minimal satu button");
614
+
615
+ const title = this._title;
616
+ const footer = this._footer;
617
+ const buttonsMessage: ButtonsMessagePayload = {
618
+ contentText: this._body,
619
+ buttons: [...this._buttons],
620
+ headerType: HeaderType.EMPTY,
621
+ };
622
+
623
+ if (this._mediaSlot) {
624
+ const media = await this._resolveSlotMedia();
625
+ if (!media)
626
+ throw new ValidationError("header media tidak bisa diselesaikan");
627
+ const kind = this._mediaSlot.kind;
628
+ buttonsMessage.headerType = LEGACY_HEADER_TYPE_BY_KIND[kind];
629
+ if (media.field === "imageMessage")
630
+ buttonsMessage.imageMessage = media.message;
631
+ else if (media.field === "videoMessage")
632
+ buttonsMessage.videoMessage = media.message;
633
+ else buttonsMessage.documentMessage = media.message;
634
+ if (title !== undefined) buttonsMessage.text = title;
635
+ } else if (this._location) {
636
+ buttonsMessage.headerType = HeaderType.LOCATION;
637
+ buttonsMessage.locationMessage = await this._resolveLocation();
638
+ } else if (title !== undefined) {
639
+ buttonsMessage.headerType = HeaderType.TEXT;
640
+ buttonsMessage.text = title;
641
+ } else {
642
+ buttonsMessage.headerType = HeaderType.EMPTY;
643
+ }
644
+
645
+ if (footer !== undefined) buttonsMessage.footerText = footer;
646
+
647
+ return { buttonsMessage };
648
+ }
649
+ }
650
+
651
+ export interface ListRowInput {
652
+ id: string;
653
+ title: string;
654
+ description?: string;
655
+ }
656
+
657
+ export type ListFallbackMode = "auto" | "native" | "never";
658
+
659
+ export class ListMessage extends BaseMessage {
660
+ _title: string;
661
+ _buttonText: string;
662
+ _sections: Proto.Message.ListMessage.Section.$Properties[];
663
+ _fallback: ListFallbackMode;
664
+ _inGroupOverride: boolean | null;
665
+ _rowIds: Set<string>;
666
+
667
+ constructor(client?: ZapoClient) {
668
+ super(client);
669
+ this._title = "";
670
+ this._buttonText = "Buka";
671
+ this._sections = [];
672
+ this._fallback = "auto";
673
+ this._inGroupOverride = null;
674
+ this._rowIds = new Set();
675
+ }
676
+
677
+ title(text: string | undefined): this {
678
+ assertText(text, "title list", { max: DISPLAY_TEXT_MAX, required: false });
679
+ this._title = text ?? "";
680
+ return this;
681
+ }
682
+
683
+ buttonText(text: string): this {
684
+ assertText(text, "buttonText list", { max: DISPLAY_TEXT_MAX });
685
+ this._buttonText = text;
686
+ return this;
687
+ }
688
+
689
+ section(title: string | undefined, rows: ListRowInput[]): this {
690
+ assertText(title, "title section", {
691
+ max: SELECT_TITLE_MAX,
692
+ required: false,
693
+ });
694
+ if (!Array.isArray(rows) || rows.length === 0) {
695
+ throw new ValidationError(
696
+ "section butuh array rows berisi minimal satu row",
697
+ );
698
+ }
699
+ rows.forEach((row: unknown, index: number) => {
700
+ if (!row || typeof row !== "object" || Array.isArray(row)) {
701
+ throw new ValidationError(`rows[${index}] harus object row`);
702
+ }
703
+ const record = row as Partial<ListRowInput>;
704
+ const rowId = assertId(record.id, `rows[${index}].id`);
705
+ assertText(record.title, `rows[${index}].title`);
706
+ assertText(record.description, `rows[${index}].description`, {
707
+ max: 200,
708
+ required: false,
709
+ });
710
+ if (this._rowIds.has(rowId)) throw new DuplicateIdError(rowId);
711
+ this._rowIds.add(rowId);
712
+ });
713
+
714
+ this._sections.push({
715
+ ...(title !== undefined ? { title } : {}),
716
+ rows: rows.map(({ id, title: rowTitle, description }) => ({
717
+ rowId: id,
718
+ title: rowTitle,
719
+ ...(description !== undefined ? { description } : {}),
720
+ })),
721
+ });
722
+ return this;
723
+ }
724
+
725
+ fallback(mode: ListFallbackMode): this {
726
+ if (mode !== "auto" && mode !== "native" && mode !== "never") {
727
+ throw new ValidationError(
728
+ `fallback harus 'auto' | 'native' | 'never', diterima "${mode}"`,
729
+ );
730
+ }
731
+ this._fallback = mode;
732
+ return this;
733
+ }
734
+
735
+ inGroup(flag: boolean): this {
736
+ if (typeof flag !== "boolean") {
737
+ throw new ValidationError(
738
+ `inGroup() butuh boolean, diterima ${typeof flag}`,
739
+ );
740
+ }
741
+ this._inGroupOverride = flag;
742
+ return this;
743
+ }
744
+
745
+ toNativeFlow(): ButtonBuildResult {
746
+ if (!this._sections.length)
747
+ throw new ValidationError("minimal satu section");
748
+
749
+ const footer = this._footer;
750
+ const buttonParamsJson = stringifyParams(
751
+ {
752
+ title: this._buttonText,
753
+ sections: this._sections.map(({ title, rows }) => ({
754
+ ...(title !== undefined ? { title } : {}),
755
+ rows: (rows ?? []).map(({ rowId, title, description }) => ({
756
+ id: rowId,
757
+ title,
758
+ ...(description !== undefined ? { description } : {}),
759
+ })),
760
+ })),
761
+ },
762
+ "buttonParamsJson (single_select)",
763
+ );
764
+
765
+ return {
766
+ interactiveMessage: {
767
+ body: { text: this._body },
768
+ ...(footer !== undefined ? { footer: { text: footer } } : {}),
769
+ nativeFlowMessage: {
770
+ messageVersion: 1,
771
+ buttons: [{ name: "single_select", buttonParamsJson }],
772
+ },
773
+ },
774
+ };
775
+ }
776
+
777
+ override build(): ListBuildResult {
778
+ if (!this._sections.length)
779
+ throw new ValidationError("minimal satu section");
780
+
781
+ const footer = this._footer;
782
+ const listMessage: ListMessagePayload = {
783
+ title: this._title,
784
+ description: this._body,
785
+ buttonText: this._buttonText,
786
+ listType: ListType.SINGLE_SELECT,
787
+ sections: this._sections.map((section) => ({
788
+ ...section,
789
+ rows: [...(section.rows ?? [])],
790
+ })),
791
+ };
792
+
793
+ if (footer !== undefined) listMessage.footerText = footer;
794
+
795
+ return { listMessage };
796
+ }
797
+
798
+ override async send(jid?: string, arg?: SendResolutionArg): Promise<unknown> {
799
+ const { client, options } = this._resolve(arg);
800
+ const target = typeof jid === "string" && jid ? jid : this._defaultTarget();
801
+ if (!target) {
802
+ throw new MessageError(
803
+ "tujuan listMessage tidak diketahui. panggil send(jid) atau .defaultTo(jid)",
804
+ "NO_TARGET",
805
+ );
806
+ }
807
+ const isGroup = this._inGroupOverride ?? isGroupJid(target);
808
+ const useNativeFlow =
809
+ this._fallback === "native" || (this._fallback === "auto" && isGroup);
810
+ const content = useNativeFlow ? this.toNativeFlow() : this.build();
811
+ const send = client.message.send.bind(client.message);
812
+ return Object.keys(options).length
813
+ ? send(target, content, options as ZapoSendOptions)
814
+ : send(target, content);
815
+ }
816
+ }
817
+
818
+ export function button(client?: ZapoClient): Button;
819
+ export function button(
820
+ client: ZapoClient | undefined,
821
+ jid: string,
822
+
823
+ config: ButtonConfig,
824
+ options?: MessageSendOptions,
825
+ ): Promise<MessageSendResult>;
826
+ export function button(
827
+ client?: ZapoClient,
828
+ jid?: string,
829
+ config?: ButtonConfig,
830
+ options?: MessageSendOptions,
831
+ ): Button | Promise<MessageSendResult> {
832
+ if (config === undefined) return new Button(client);
833
+ return sendButton(client, jid, config, options);
834
+ }
835
+
836
+ export function legacyButton(client?: ZapoClient): LegacyButton;
837
+ export function legacyButton(
838
+ client: ZapoClient | undefined,
839
+ jid: string,
840
+ config: LegacyButtonConfig,
841
+ options?: MessageSendOptions,
842
+ ): Promise<MessageSendResult>;
843
+ export function legacyButton(
844
+ client?: ZapoClient,
845
+ jid?: string,
846
+ config?: LegacyButtonConfig,
847
+ options?: MessageSendOptions,
848
+ ): LegacyButton | Promise<MessageSendResult> {
849
+ if (config === undefined) return new LegacyButton(client);
850
+ return sendLegacyButton(client, jid, config, options);
851
+ }
852
+
853
+ export function listMessage(client?: ZapoClient): ListMessage;
854
+ export function listMessage(
855
+ client: ZapoClient | undefined,
856
+ jid: string,
857
+ config: ListMessageConfig,
858
+ options?: MessageSendOptions,
859
+ ): Promise<MessageSendResult>;
860
+ export function listMessage(
861
+ client?: ZapoClient,
862
+ jid?: string,
863
+ config?: ListMessageConfig,
864
+ options?: MessageSendOptions,
865
+ ): ListMessage | Promise<MessageSendResult> {
866
+ if (config === undefined) return new ListMessage(client);
867
+ return sendListMessage(client, jid, config, options);
868
+ }
869
+
870
+ export type InteractiveHeaderConfig =
871
+ | ({ type: "image"; source: MediaSource } & ImageHeaderOptions)
872
+ | ({ type: "video"; source: MediaSource } & VideoHeaderOptions)
873
+ | ({ type: "document"; source: MediaSource } & DocumentHeaderOptions)
874
+ | {
875
+ type: "location";
876
+ latitude: number;
877
+ longitude: number;
878
+ name?: string;
879
+ address?: string;
880
+ thumbnail?: Buffer | Uint8Array;
881
+ }
882
+ | { type: "thumbnail"; jpegThumbnail: Buffer | Uint8Array };
883
+
884
+ export type LegacyButtonHeaderConfig = Extract<
885
+ InteractiveHeaderConfig,
886
+ { type: "image" | "video" | "document" | "location" }
887
+ >;
888
+
889
+ export type ButtonItemConfig =
890
+ | { type: "quick_reply"; text: string; id: string }
891
+ | { type: "cta_url"; text: string; url: string }
892
+ | { type: "cta_copy"; text: string; copyCode: string }
893
+ | { type: "cta_call"; text: string; phoneNumber: string }
894
+ | { type: "send_location"; text?: string }
895
+ | {
896
+ type: "single_select";
897
+ title: string;
898
+ sections: readonly NativeSection[];
899
+ };
900
+
901
+ export interface BottomSheetConfig {
902
+ limit?: number;
903
+ listTitle?: string;
904
+ buttonTitle?: string;
905
+ }
906
+
907
+ export interface LimitedTimeOfferConfig {
908
+ text?: string;
909
+ url?: string;
910
+ copyCode?: string;
911
+ expiresIn?: number;
912
+ }
913
+
914
+ export interface ButtonConfig {
915
+ title?: string;
916
+ subtitle?: string;
917
+ body: string;
918
+ footer?: string;
919
+ header?: InteractiveHeaderConfig;
920
+ buttons?: readonly ButtonItemConfig[];
921
+ bottomSheet?: BottomSheetConfig;
922
+ limitedTimeOffer?: LimitedTimeOfferConfig;
923
+ }
924
+
925
+ export interface LegacyButtonConfig {
926
+ title?: string;
927
+ body: string;
928
+ footer?: string;
929
+ header?: LegacyButtonHeaderConfig;
930
+ buttons: readonly { id: string; text: string }[];
931
+ }
932
+
933
+ export interface ListSectionConfig {
934
+ title?: string;
935
+ rows: readonly ListRowInput[];
936
+ }
937
+
938
+ export interface ListMessageConfig {
939
+ title?: string;
940
+ body: string;
941
+ footer?: string;
942
+ buttonText: string;
943
+ sections: readonly ListSectionConfig[];
944
+ fallback?: ListFallbackMode;
945
+ inGroup?: boolean;
946
+ }
947
+
948
+ const applyInteractiveHeader = (
949
+ builder: HeaderMessage,
950
+ header: InteractiveHeaderConfig,
951
+ ): void => {
952
+ if (header.type === "image") {
953
+ const { type: _kind, source, ...options } = header;
954
+ builder.image(source, options);
955
+ } else if (header.type === "video") {
956
+ const { type: _kind, source, ...options } = header;
957
+ builder.video(source, options);
958
+ } else if (header.type === "document") {
959
+ const { type: _kind, source, ...options } = header;
960
+ builder.document(source, options);
961
+ } else if (header.type === "location") {
962
+ builder.location({
963
+ latitude: header.latitude,
964
+ longitude: header.longitude,
965
+ ...(header.name !== undefined ? { name: header.name } : {}),
966
+ ...(header.address !== undefined ? { address: header.address } : {}),
967
+ ...(header.thumbnail !== undefined
968
+ ? { thumbnail: header.thumbnail }
969
+ : {}),
970
+ });
971
+ } else {
972
+ builder.headerThumbnail(header.jpegThumbnail);
973
+ }
974
+ };
975
+
976
+ const applyButtonItem = (builder: Button, item: ButtonItemConfig): void => {
977
+ if (item.type === "quick_reply") builder.quick_reply(item.text, item.id);
978
+ else if (item.type === "cta_url") builder.cta_url(item.text, item.url);
979
+ else if (item.type === "cta_copy") builder.cta_copy(item.text, item.copyCode);
980
+ else if (item.type === "cta_call")
981
+ builder.cta_call(item.text, item.phoneNumber);
982
+ else if (item.type === "send_location") builder.send_location(item.text);
983
+ else builder.single_select(item.title, [...item.sections]);
984
+ };
985
+
986
+ export const applyButtonConfig = (
987
+ builder: Button,
988
+ config: ButtonConfig,
989
+ ): void => {
990
+ if (config.title !== undefined) builder.title(config.title);
991
+ if (config.subtitle !== undefined) builder.subtitle(config.subtitle);
992
+ builder.body(config.body);
993
+ if (config.footer !== undefined) builder.footer(config.footer);
994
+ if (config.header !== undefined)
995
+ applyInteractiveHeader(builder, config.header);
996
+ if (config.buttons !== undefined) {
997
+ for (const item of config.buttons) applyButtonItem(builder, item);
998
+ }
999
+ if (config.bottomSheet !== undefined)
1000
+ builder.bottom_sheet(config.bottomSheet);
1001
+ if (config.limitedTimeOffer !== undefined) {
1002
+ const { text, url, copyCode, expiresIn } = config.limitedTimeOffer;
1003
+ builder.limited_time_offer({
1004
+ ...(text !== undefined ? { text } : {}),
1005
+ ...(url !== undefined ? { url } : {}),
1006
+ ...(copyCode !== undefined ? { copyCode } : {}),
1007
+ ...(expiresIn !== undefined ? { expiresIn } : {}),
1008
+ });
1009
+ }
1010
+ };
1011
+
1012
+ export const sendButton = async (
1013
+ client: ZapoClient | undefined,
1014
+ jid: string | undefined,
1015
+ config: ButtonConfig,
1016
+ options?: MessageSendOptions,
1017
+ ): Promise<MessageSendResult> => {
1018
+ const builder = new Button(client);
1019
+ applyButtonConfig(builder, config);
1020
+ return sendConfigured(builder, jid, options);
1021
+ };
1022
+
1023
+ export const applyLegacyButtonConfig = (
1024
+ builder: LegacyButton,
1025
+ config: LegacyButtonConfig,
1026
+ ): void => {
1027
+ if (config.title !== undefined) builder.title(config.title);
1028
+ builder.body(config.body);
1029
+ if (config.footer !== undefined) builder.footer(config.footer);
1030
+ if (config.header !== undefined)
1031
+ applyInteractiveHeader(builder, config.header);
1032
+ for (const item of config.buttons) builder.button(item.id, item.text);
1033
+ };
1034
+
1035
+ export const sendLegacyButton = async (
1036
+ client: ZapoClient | undefined,
1037
+ jid: string | undefined,
1038
+ config: LegacyButtonConfig,
1039
+ options?: MessageSendOptions,
1040
+ ): Promise<MessageSendResult> => {
1041
+ const builder = new LegacyButton(client);
1042
+ applyLegacyButtonConfig(builder, config);
1043
+ return sendConfigured(builder, jid, options);
1044
+ };
1045
+
1046
+ export const applyListMessageConfig = (
1047
+ builder: ListMessage,
1048
+ config: ListMessageConfig,
1049
+ ): void => {
1050
+ if (config.title !== undefined) builder.title(config.title);
1051
+ builder.body(config.body);
1052
+ if (config.footer !== undefined) builder.footer(config.footer);
1053
+ builder.buttonText(config.buttonText);
1054
+ for (const section of config.sections) {
1055
+ builder.section(section.title, [...section.rows]);
1056
+ }
1057
+ if (config.fallback !== undefined) builder.fallback(config.fallback);
1058
+ if (config.inGroup !== undefined) builder.inGroup(config.inGroup);
1059
+ };
1060
+
1061
+ export const sendListMessage = async (
1062
+ client: ZapoClient | undefined,
1063
+ jid: string | undefined,
1064
+ config: ListMessageConfig,
1065
+ options?: MessageSendOptions,
1066
+ ): Promise<MessageSendResult> => {
1067
+ const builder = new ListMessage(client);
1068
+ applyListMessageConfig(builder, config);
1069
+ return sendConfigured(builder, jid, options);
1070
+ };
1071
+
1072
+ export type { NativeSection, NativeSectionRow };
1073
+ export type { MediaSlot, MediaSlotOptions };