@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,41 @@
1
+ import { type ExtractedInteractiveResponse } from "./interactive.js";
2
+ import type { ZapoDownloadCapableClient } from "./zapo-client.js";
3
+ export interface SerializedKey {
4
+ remoteJid?: string | undefined;
5
+ participant?: string | undefined;
6
+ id?: string | undefined;
7
+ fromMe?: boolean | undefined;
8
+ isGroup?: boolean | undefined;
9
+ remoteJidAlt?: string | undefined;
10
+ participantAlt?: string | undefined;
11
+ [key: string]: unknown;
12
+ }
13
+ export interface SerializedEvent {
14
+ key: SerializedKey;
15
+ message?: Record<string, unknown>;
16
+ [key: string]: unknown;
17
+ }
18
+ export interface MSerialized extends SerializedEvent {
19
+ content: string | undefined;
20
+ text: string | undefined;
21
+ interactive: ExtractedInteractiveResponse | undefined;
22
+ q: QSerialized | undefined;
23
+ reply(text: string): Promise<unknown>;
24
+ react(emoji: string): Promise<unknown>;
25
+ download(dataType: "buffer" | "stream"): Promise<unknown>;
26
+ readonly client: ZapoDownloadCapableClient;
27
+ }
28
+ export interface QSerialized {
29
+ key: SerializedKey;
30
+ message: Record<string, unknown>;
31
+ content: string | undefined;
32
+ text: string | undefined;
33
+ interactive: ExtractedInteractiveResponse | undefined;
34
+ reply(text: string): Promise<unknown>;
35
+ react(emoji: string): Promise<unknown>;
36
+ download(dataType: "bytes" | "stream"): Promise<unknown>;
37
+ readonly client: ZapoDownloadCapableClient;
38
+ }
39
+ export declare const extractText: (message: Record<string, unknown> | undefined, content: string | undefined) => string | undefined;
40
+ export declare const mSerialize: (event: SerializedEvent, client: ZapoDownloadCapableClient) => MSerialized;
41
+ export declare const qSerialize: (m: MSerialized) => QSerialized | undefined;
@@ -0,0 +1,93 @@
1
+ import { getContentType, toUserJid, unwrapMessage } from "zapo-js";
2
+ import { mDownload, qDownload } from "./download.js";
3
+ import { extractInteractiveResponse, } from "./interactive.js";
4
+ import { applyReplyBranding } from "./branding.js";
5
+ export const extractText = (message, content) => {
6
+ const contentMessage = message?.[content ?? ""];
7
+ return (contentMessage?.text ??
8
+ message?.conversation ??
9
+ contentMessage?.caption ??
10
+ extractInteractiveText(message));
11
+ };
12
+ const extractInteractiveText = (message) => {
13
+ if (!message || typeof message !== "object")
14
+ return undefined;
15
+ const msg = unwrapMessage(message);
16
+ if (!(msg.buttonsResponseMessage ||
17
+ msg.listResponseMessage ||
18
+ msg.templateButtonReplyMessage ||
19
+ msg.interactiveResponseMessage))
20
+ return undefined;
21
+ return extractInteractiveResponse(msg)?.id;
22
+ };
23
+ function mReply(text) {
24
+ return this.client.message.send(this.key.remoteJid, text, applyReplyBranding(text, {}));
25
+ }
26
+ function mReact(emoji) {
27
+ return this.client.message.send(this.key.remoteJid, {
28
+ type: "reaction",
29
+ target: this,
30
+ emoji,
31
+ });
32
+ }
33
+ function qReply(text) {
34
+ return this.client.message.send(this.key.remoteJid, text, applyReplyBranding(text, {}));
35
+ }
36
+ function qReact(emoji) {
37
+ return this.client.message.send(this.key.remoteJid, {
38
+ type: "reaction",
39
+ target: this.key,
40
+ emoji,
41
+ });
42
+ }
43
+ export const mSerialize = (event, client) => {
44
+ const m = {
45
+ ...event,
46
+ content: getContentType(event?.message),
47
+ reply: mReply,
48
+ download: mDownload,
49
+ react: mReact,
50
+ };
51
+ Object.defineProperty(m, "client", {
52
+ enumerable: false,
53
+ get() {
54
+ return client;
55
+ },
56
+ });
57
+ m.text = extractText(event?.message, m.content);
58
+ m.interactive = extractInteractiveResponse(event?.message);
59
+ m.q = qSerialize(m);
60
+ return m;
61
+ };
62
+ export const qSerialize = (m) => {
63
+ const contentMessage = m.message?.[m.content];
64
+ const contextInfo = contentMessage?.contextInfo;
65
+ if (!contextInfo?.quotedMessage)
66
+ return undefined;
67
+ const message = contextInfo.quotedMessage;
68
+ const key = {
69
+ remoteJid: m.key.remoteJid,
70
+ participant: contextInfo.participant,
71
+ id: contextInfo.stanzaId,
72
+ fromMe: contextInfo.participant ===
73
+ toUserJid(m.client.auth?.getCurrentCredentials?.()?.meLid),
74
+ };
75
+ const content = getContentType(message);
76
+ const q = {
77
+ key,
78
+ message,
79
+ content,
80
+ reply: qReply,
81
+ react: qReact,
82
+ download: qDownload,
83
+ };
84
+ q.text = extractText(message, content);
85
+ q.interactive = extractInteractiveResponse(message);
86
+ Object.defineProperty(q, "client", {
87
+ enumerable: false,
88
+ get() {
89
+ return m.client;
90
+ },
91
+ });
92
+ return q;
93
+ };
@@ -0,0 +1,3 @@
1
+ export declare const toBoldSans: (text: string) => string;
2
+ export type StatusType = "ok" | "warn" | "fail";
3
+ export declare const formatStatus: (type: StatusType, text: string | string[]) => string;
package/dist/status.js ADDED
@@ -0,0 +1,21 @@
1
+ const BOLD_SANS_BASE = 0x1d5d4;
2
+ export const toBoldSans = (text) => [...text]
3
+ .map((ch) => {
4
+ const code = ch.codePointAt(0);
5
+ if (code === undefined)
6
+ return ch;
7
+ if (code >= 65 && code <= 90)
8
+ return String.fromCodePoint(BOLD_SANS_BASE + (code - 65));
9
+ return ch;
10
+ })
11
+ .join("");
12
+ const STATUS_MAP = {
13
+ ok: { emoji: "✅", label: "SUKSES" },
14
+ warn: { emoji: "⚠️", label: "GAGAL" },
15
+ fail: { emoji: "❌", label: "ERROR" },
16
+ };
17
+ export const formatStatus = (type, text) => {
18
+ const { emoji, label } = STATUS_MAP[type];
19
+ const lines = Array.isArray(text) ? text : String(text).split("\n");
20
+ return `${emoji} ${toBoldSans(label)}\n\n${lines.map((l) => "> " + l).join("\n")}`;
21
+ };
@@ -0,0 +1,44 @@
1
+ import type { Readable } from "node:stream";
2
+ import type { WaDownloadMediaOptions, WaMediaUploadResult, WaMessagePublishResult, WaSendMessageContent, WaSendMessageOptions, WaUploadMediaOptions, WaUploadMediaSource } from "zapo-js";
3
+ import type { BuilderMessagePayload } from "./payloads.js";
4
+ export type ZapoSendOptions = {
5
+ quote?: unknown;
6
+ } & Record<string, unknown>;
7
+ export interface ZapoReactionContent {
8
+ type: "reaction";
9
+ target: unknown;
10
+ emoji: string;
11
+ }
12
+ export interface ZapoPollContent {
13
+ type: "poll";
14
+ name: string;
15
+ options: string[];
16
+ selectableCount?: number;
17
+ allowAddOption?: boolean;
18
+ hideParticipantName?: boolean;
19
+ }
20
+ export type ZapoMessageContent = WaSendMessageContent | BuilderMessagePayload | ZapoReactionContent | ZapoPollContent;
21
+ export interface ZapoMessageCoordinator {
22
+ send(to: string, content: ZapoMessageContent, options?: WaSendMessageOptions | ZapoSendOptions): Promise<WaMessagePublishResult>;
23
+ upload?(source: WaUploadMediaSource, options: WaUploadMediaOptions): Promise<WaMediaUploadResult>;
24
+ download?(source: unknown, options?: WaDownloadMediaOptions): Promise<Readable>;
25
+ downloadBytes?(source: unknown, options?: WaDownloadMediaOptions): Promise<Uint8Array>;
26
+ }
27
+ export interface ZapoAuthLike {
28
+ getCurrentCredentials?(): {
29
+ meJid?: string;
30
+ meLid?: string;
31
+ } | undefined | null;
32
+ }
33
+ export interface ZapoClient {
34
+ message: ZapoMessageCoordinator;
35
+ auth?: ZapoAuthLike;
36
+ }
37
+ export type ZapoDownloadCapableClient = ZapoClient & {
38
+ message: ZapoMessageCoordinator & {
39
+ download(source: unknown, options?: WaDownloadMediaOptions): Promise<Readable>;
40
+ downloadBytes(source: unknown, options?: WaDownloadMediaOptions): Promise<Uint8Array>;
41
+ };
42
+ };
43
+ export type MessageSendResult = WaMessagePublishResult;
44
+ export declare const isZapoMessageCoordinatorShape: (value: unknown) => value is ZapoClient;
@@ -0,0 +1 @@
1
+ export const isZapoMessageCoordinatorShape = (value) => typeof value?.message?.send === "function";
@@ -0,0 +1,59 @@
1
+ import type { ZapoClient } from "@kyyinfinite/zapo-message";
2
+
3
+ const client: ZapoClient = {
4
+ message: {
5
+ send: async (to, content, options) => {
6
+ console.log(
7
+ "send ->",
8
+ to,
9
+ "additionalAttributes:",
10
+ (options as { additionalAttributes?: unknown } | undefined)
11
+ ?.additionalAttributes,
12
+ );
13
+ return {
14
+ id: `RICH-${Date.now()}`,
15
+ attempts: 1,
16
+ ack: { refreshLid: false },
17
+ ackNode: undefined as never,
18
+ };
19
+ },
20
+ },
21
+ };
22
+
23
+ const { airich, decodeUnifiedResponse } =
24
+ await import("@kyyinfinite/zapo-message");
25
+
26
+ const builder = airich(client)
27
+ .text(
28
+ "Laporan singkat dengan [tautan](https://example.com) dan kutipan [](https://example.com/src)",
29
+ )
30
+ .code("javascript", 'const greeting = "halo dunia"\nconsole.log(greeting)')
31
+ .table([
32
+ ["Nama", "Nilai"],
33
+ ["zapo-message", "100"],
34
+ ["AIRich", "aktif"],
35
+ ])
36
+ .suggest(["ulangi", "lanjutkan"])
37
+ .footer("dibuat dengan zapo-message");
38
+
39
+ const placeholderSent = (await builder.send("6281@s.whatsapp.net")) as {
40
+ id: string;
41
+ };
42
+
43
+ console.log("placeholder message id:", placeholderSent.id);
44
+ console.log("lastId:", builder.lastId);
45
+
46
+ const direct = airich(client)
47
+ .text("kirim langsung tanpa placeholder")
48
+ .build({ submessages: false });
49
+
50
+ const decoded = decodeUnifiedResponse(
51
+ direct.botForwardedMessage.message.richResponseMessage.unifiedResponse.data,
52
+ ) as { sections: { view_model: { primitive?: { __typename?: string } } }[] };
53
+
54
+ console.log(
55
+ "direct sections:",
56
+ decoded.sections.length,
57
+ "first type:",
58
+ decoded.sections[0]?.view_model.primitive?.__typename,
59
+ );
@@ -0,0 +1,48 @@
1
+ import type { ZapoClient } from "@kyyinfinite/zapo-message";
2
+
3
+ const client: ZapoClient = {
4
+ message: {
5
+ send: async (to, content) => {
6
+ console.log("send ->", to, JSON.stringify(content).slice(0, 160));
7
+ return {
8
+ id: `EXAMPLE-${Date.now()}`,
9
+ attempts: 1,
10
+ ack: { refreshLid: false },
11
+ ackNode: undefined as never,
12
+ };
13
+ },
14
+ },
15
+ };
16
+
17
+ const card = await buttonDemo(client);
18
+ console.log(
19
+ "native flow buttons:",
20
+ card.interactiveMessage.nativeFlowMessage.buttons
21
+ .map((b) => b.name)
22
+ .join(", "),
23
+ );
24
+
25
+ async function buttonDemo(zapoClient: ZapoClient) {
26
+ const { button } = await import("@kyyinfinite/zapo-message");
27
+ const builder = button(zapoClient)
28
+ .title("Pilih tindakan")
29
+ .body("Ini contoh kartu tombol native flow")
30
+ .footer("zapo-message example")
31
+ .quick_reply("Mulai", "cmd start")
32
+ .cta_url("Buka Dokumentasi", "https://example.com/docs")
33
+ .cta_copy("Salin Kode", "ZAPO123")
34
+ .cta_call("Telepon", "+628123456789")
35
+ .send_location("Kirim Lokasi")
36
+ .single_select("Pilih Menu", [
37
+ {
38
+ title: "Utama",
39
+ rows: [
40
+ { id: "menu tools", title: "Tools" },
41
+ { id: "menu owner", title: "Owner" },
42
+ ],
43
+ },
44
+ ])
45
+ .bottom_sheet({ limit: 2, listTitle: "Daftar", buttonTitle: "Buka" });
46
+
47
+ return builder.build();
48
+ }
@@ -0,0 +1,58 @@
1
+ import { createStore, WaClient } from "zapo-js";
2
+ import "@kyyinfinite/zapo-message";
3
+
4
+ const client = new WaClient({ store: createStore({}), sessionId: "menu" });
5
+
6
+ const jid = "628123456789@s.whatsapp.net";
7
+
8
+ const run = async () => {
9
+ await client.text().body("Halo Dunia").send(jid);
10
+
11
+ await client
12
+ .button()
13
+ .body("Pilih salah satu")
14
+ .quick_reply("Klik saya", "menu klik")
15
+ .send(jid);
16
+
17
+ await client.legacyButton().body("Halo").button("b1", "Satu").send(jid);
18
+
19
+ await client
20
+ .listMessage()
21
+ .title("Menu")
22
+ .body("Pilih opsi")
23
+ .section("Utama", [{ id: "opsi-1", title: "Opsi 1" }])
24
+ .send(jid);
25
+
26
+ await client.airich().text("Halo dari AIRich").send(jid);
27
+
28
+ await client
29
+ .linkPreview()
30
+ .body("Baca dokumentasi di https://zapo.to ya")
31
+ .title("Dokumentasi")
32
+ .send(jid);
33
+
34
+ await client
35
+ .reaction()
36
+ .target({ key: { remoteJid: jid, id: "ID_PESAN", fromMe: false } })
37
+ .emoji("🔥")
38
+ .send();
39
+
40
+ await client.media().image(Buffer.alloc(0)).caption("Foto liburan").send(jid);
41
+
42
+ await client.sticker().source(Buffer.alloc(0)).send(jid);
43
+
44
+ await client.contact().name("Budi").phone("+628123456789").send(jid);
45
+
46
+ await client.poll().question("Pilih satu").options(["A", "B", "C"]).send(jid);
47
+
48
+ await client.album().image(Buffer.alloc(0)).image(Buffer.alloc(0)).send(jid);
49
+
50
+ await client
51
+ .forward()
52
+ .message({ message: { conversation: "pesan asli" } })
53
+ .send(jid);
54
+ };
55
+
56
+ void run();
57
+
58
+ await client.disconnect().catch(() => {});
@@ -0,0 +1,133 @@
1
+ import { createStore, WaClient } from "zapo-js";
2
+ import "@kyyinfinite/zapo-message";
3
+
4
+ const client = new WaClient({ store: createStore({}), sessionId: "hybrid" });
5
+
6
+ const jid = "628123456789@s.whatsapp.net";
7
+
8
+ const run = async () => {
9
+ await client.text(jid, { body: "Halo Dunia" });
10
+
11
+ await client.text().to(jid).body("Halo Dunia").send();
12
+
13
+ await client.button(jid, {
14
+ title: "Main Menu",
15
+ subtitle: "Welcome",
16
+ body: "Choose one",
17
+ footer: "Powered by Avelyna",
18
+ buttons: [
19
+ { type: "quick_reply", text: "Profile", id: "profile" },
20
+ { type: "cta_url", text: "Website", url: "https://example.com" },
21
+ { type: "cta_copy", text: "Copy Code", copyCode: "AVELYNA" },
22
+ { type: "cta_call", text: "Contact", phoneNumber: "+628123456789" },
23
+ ],
24
+ });
25
+
26
+ await client
27
+ .button()
28
+ .to(jid)
29
+ .title("Main Menu")
30
+ .body("Choose one")
31
+ .quick_reply("Profile", "profile")
32
+ .cta_url("Website", "https://example.com")
33
+ .send();
34
+
35
+ await client.legacyButton(jid, {
36
+ title: "Menu",
37
+ body: "Select an option",
38
+ footer: "Avelyna",
39
+ buttons: [{ id: "profile", text: "Profile" }],
40
+ });
41
+
42
+ await client.listMessage(jid, {
43
+ title: "Main Menu",
44
+ body: "Choose a menu",
45
+ footer: "Avelyna",
46
+ buttonText: "Open",
47
+ sections: [
48
+ {
49
+ title: "General",
50
+ rows: [
51
+ { id: "profile", title: "Profile", description: "Your profile" },
52
+ ],
53
+ },
54
+ ],
55
+ });
56
+
57
+ await client.airich(jid, {
58
+ sections: [
59
+ { type: "text", text: "Welcome" },
60
+ { type: "code", language: "javascript", code: "console.log('Hello')" },
61
+ { type: "tip", text: "Helpful information" },
62
+ { type: "suggest", items: ["ulangi pesanan", "lihat menu"] },
63
+ ],
64
+ footer: "Powered by Avelyna",
65
+ });
66
+
67
+ await client
68
+ .airich()
69
+ .text("Welcome")
70
+ .code("javascript", "console.log('Hello')")
71
+ .tip("Helpful information")
72
+ .send(jid);
73
+
74
+ await client.location(jid, {
75
+ latitude: -6.2,
76
+ longitude: 106.8,
77
+ name: "Jakarta",
78
+ address: "Indonesia",
79
+ });
80
+
81
+ await client
82
+ .location()
83
+ .to(jid)
84
+ .coordinates(-6.2, 106.8)
85
+ .name("Jakarta")
86
+ .address("Indonesia")
87
+ .send();
88
+
89
+ await client.poll(jid, {
90
+ question: "Siapa menang?",
91
+ options: ["Tim A", "Tim B"],
92
+ selectableCount: 1,
93
+ });
94
+
95
+ await client.contact(jid, {
96
+ name: "Budi",
97
+ phone: "+628123456789",
98
+ organization: "PT Contoh",
99
+ });
100
+
101
+ await client.image(jid, {
102
+ source: Buffer.from("png-bytes"),
103
+ mimetype: "image/png",
104
+ });
105
+
106
+ await client.media(jid, {
107
+ type: "document",
108
+ source: Buffer.from("pdf-bytes"),
109
+ fileName: "laporan.pdf",
110
+ });
111
+
112
+ await client.album(jid, {
113
+ media: [
114
+ {
115
+ type: "image",
116
+ source: Buffer.from("png-a"),
117
+ options: { mimetype: "image/png" },
118
+ },
119
+ {
120
+ type: "image",
121
+ source: Buffer.from("png-b"),
122
+ options: { mimetype: "image/png" },
123
+ },
124
+ ],
125
+ });
126
+
127
+ await client.disconnect();
128
+ };
129
+
130
+ run().catch((error) => {
131
+ console.error(error);
132
+ process.exitCode = 1;
133
+ });
@@ -0,0 +1,61 @@
1
+ import { mSerialize } from "@kyyinfinite/zapo-message/serialize.js";
2
+ import { extractInteractiveResponse } from "@kyyinfinite/zapo-message/interactive.js";
3
+ import { listMessage } from "@kyyinfinite/zapo-message";
4
+ import type { ZapoDownloadCapableClient } from "@kyyinfinite/zapo-message";
5
+
6
+ const client: ZapoDownloadCapableClient = {
7
+ message: {
8
+ send: async (to, content) => {
9
+ console.log(
10
+ "reply ->",
11
+ to,
12
+ typeof content === "string" ? content : "[payload]",
13
+ );
14
+ return {
15
+ id: `SER-${Date.now()}`,
16
+ attempts: 1,
17
+ ack: { refreshLid: false },
18
+ ackNode: undefined as never,
19
+ };
20
+ },
21
+ download: async () => {
22
+ const { Readable } = await import("node:stream");
23
+ return Readable.from([Buffer.alloc(8)]);
24
+ },
25
+ downloadBytes: async () => new Uint8Array([1, 2, 3]),
26
+ },
27
+ auth: {
28
+ getCurrentCredentials: () => ({ meLid: "6281@lid" }),
29
+ },
30
+ };
31
+
32
+ const event = {
33
+ key: {
34
+ remoteJid: "1203@g.us",
35
+ id: "MSG1",
36
+ fromMe: false,
37
+ participant: "6281@lid",
38
+ },
39
+ message: {
40
+ listResponseMessage: {
41
+ title: "Menu",
42
+ singleSelectReply: { selectedRowId: "menu tools" },
43
+ },
44
+ },
45
+ };
46
+
47
+ const m = mSerialize(event, client);
48
+ console.log("interactive id:", m.interactive?.id);
49
+ console.log("interactive content:", m.interactive?.content);
50
+ console.log("extracted:", extractInteractiveResponse(event.message)?.id);
51
+
52
+ const direct = listMessage({ message: client.message } as never)
53
+ .title("Menu")
54
+ .section("Utama", [{ id: "menu tools", title: "Tools" }])
55
+ .build();
56
+ console.log(
57
+ "list listType:",
58
+ direct.listMessage.listType,
59
+ "rows:",
60
+ (direct.listMessage.sections[0] as { rows?: unknown[] })?.rows?.length,
61
+ );