@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,98 @@
1
+ import { BaseBuilder } from "../core/base-builder.js";
2
+ import { sendConfigured } from "../core/async-send.js";
3
+ import { ValidationError, MessageError } from "../core/errors.js";
4
+ const QUESTION_MAX = 1024;
5
+ const OPTION_NAME_MAX = 100;
6
+ const POLL_OPTIONS_MIN = 1;
7
+ const POLL_OPTIONS_MAX = 12;
8
+ const SELECTABLE_MAX = 12;
9
+ const assertQuestion = (value) => {
10
+ if (typeof value !== "string" || !value.trim()) {
11
+ throw new ValidationError("poll.question wajib diisi (string non-kosong)");
12
+ }
13
+ if (value.length > QUESTION_MAX) {
14
+ throw new ValidationError(`poll.question melebihi batas ${QUESTION_MAX} karakter (${value.length})`);
15
+ }
16
+ return value;
17
+ };
18
+ export class PollBuilder extends BaseBuilder {
19
+ #question;
20
+ #options = [];
21
+ #selectableCount;
22
+ #allowAddOption = false;
23
+ #hideParticipantName = false;
24
+ question(value) {
25
+ this.#question = assertQuestion(value);
26
+ return this;
27
+ }
28
+ options(values) {
29
+ if (!Array.isArray(values)) {
30
+ throw new ValidationError(`poll.options butuh array string, diterima ${typeof values}`);
31
+ }
32
+ this.#options = values.map((value) => {
33
+ if (typeof value !== "string" || !value.trim()) {
34
+ throw new ValidationError("poll.options semua opsi harus string non-kosong");
35
+ }
36
+ if (value.length > OPTION_NAME_MAX) {
37
+ throw new ValidationError(`poll.options opsi melebihi batas ${OPTION_NAME_MAX} karakter (${value.length})`);
38
+ }
39
+ return value;
40
+ });
41
+ return this;
42
+ }
43
+ selectableCount(value) {
44
+ if (!Number.isInteger(value) || value < 1 || value > SELECTABLE_MAX) {
45
+ throw new ValidationError(`poll.selectableCount harus integer 1-${SELECTABLE_MAX}, diterima ${JSON.stringify(value)}`);
46
+ }
47
+ this.#selectableCount = value;
48
+ return this;
49
+ }
50
+ allowAddOption(flag = true) {
51
+ this.#allowAddOption = flag;
52
+ return this;
53
+ }
54
+ hideParticipantName(flag = true) {
55
+ this.#hideParticipantName = flag;
56
+ return this;
57
+ }
58
+ build() {
59
+ if (this.#question === undefined) {
60
+ throw new MessageError('poll.question belum diset — panggil question("Pilih satu")', "NO_QUESTION");
61
+ }
62
+ if (this.#options.length < POLL_OPTIONS_MIN ||
63
+ this.#options.length > POLL_OPTIONS_MAX) {
64
+ throw new ValidationError(`poll.options butuh ${POLL_OPTIONS_MIN}-${POLL_OPTIONS_MAX} opsi, diterima ${this.#options.length}`);
65
+ }
66
+ const selectable = this.#selectableCount ?? 1;
67
+ if (selectable > this.#options.length) {
68
+ throw new ValidationError(`poll.selectableCount (${selectable}) melebihi jumlah opsi (${this.#options.length})`);
69
+ }
70
+ return {
71
+ type: "poll",
72
+ name: this.#question,
73
+ options: [...this.#options],
74
+ selectableCount: selectable,
75
+ ...(this.#allowAddOption ? { allowAddOption: true } : {}),
76
+ ...(this.#hideParticipantName ? { hideParticipantName: true } : {}),
77
+ };
78
+ }
79
+ }
80
+ export function poll(client, jid, config, options) {
81
+ if (config === undefined)
82
+ return new PollBuilder(client);
83
+ return sendPoll(client, jid, config, options);
84
+ }
85
+ export const applyPollConfig = (builder, config) => {
86
+ builder.question(config.question).options(config.options);
87
+ if (config.selectableCount !== undefined)
88
+ builder.selectableCount(config.selectableCount);
89
+ if (config.allowAddOption !== undefined)
90
+ builder.allowAddOption(config.allowAddOption);
91
+ if (config.hideParticipantName !== undefined)
92
+ builder.hideParticipantName(config.hideParticipantName);
93
+ };
94
+ export const sendPoll = async (client, jid, config, options) => {
95
+ const builder = new PollBuilder(client);
96
+ applyPollConfig(builder, config);
97
+ return sendConfigured(builder, jid, options);
98
+ };
@@ -0,0 +1,20 @@
1
+ import { BaseBuilder, type SendResolutionArg } from "../core/base-builder.js";
2
+ import { type MessageSendOptions } from "../core/async-send.js";
3
+ import type { MessageSendResult } from "../zapo-client.js";
4
+ import type { ZapoReactionContent, ZapoClient } from "../zapo-client.js";
5
+ export interface ReactionConfig {
6
+ target: unknown;
7
+ emoji: string;
8
+ }
9
+ export declare class ReactionBuilder extends BaseBuilder<ZapoReactionContent> {
10
+ #private;
11
+ target(ref: unknown): this;
12
+ emoji(value: string): this;
13
+ build(): ZapoReactionContent;
14
+ send(jid?: string, arg?: SendResolutionArg): Promise<unknown>;
15
+ }
16
+ export declare function reaction(client?: ZapoClient): ReactionBuilder;
17
+ export declare function reaction(client: ZapoClient | undefined, config: ReactionConfig, options?: MessageSendOptions): Promise<MessageSendResult>;
18
+ export declare function reaction(client: ZapoClient | undefined, jid: string, config: ReactionConfig, options?: MessageSendOptions): Promise<MessageSendResult>;
19
+ export declare const applyReactionConfig: (builder: ReactionBuilder, config: ReactionConfig) => void;
20
+ export declare const sendReaction: (client: ZapoClient | undefined, jid: string | undefined, config: ReactionConfig, options?: MessageSendOptions) => Promise<MessageSendResult>;
@@ -0,0 +1,71 @@
1
+ import { BaseBuilder } from "../core/base-builder.js";
2
+ import { sendConfigured } from "../core/async-send.js";
3
+ import { ValidationError, MessageError } from "../core/errors.js";
4
+ import { targetChatJidOf, targetIdOf } from "./target.js";
5
+ const EMOJI_MAX = 64;
6
+ const assertEmoji = (value) => {
7
+ if (typeof value !== "string") {
8
+ throw new ValidationError(`reaction.emoji harus string, diterima ${typeof value}`);
9
+ }
10
+ if (value.length > EMOJI_MAX) {
11
+ throw new ValidationError(`reaction.emoji melebihi batas ${EMOJI_MAX} karakter (${value.length})`);
12
+ }
13
+ return value;
14
+ };
15
+ export class ReactionBuilder extends BaseBuilder {
16
+ #target;
17
+ #emoji;
18
+ target(ref) {
19
+ if (!targetIdOf(ref)) {
20
+ throw new ValidationError("reaction.target butuh event pesan masuk atau message key dengan id");
21
+ }
22
+ this.#target = ref;
23
+ return this;
24
+ }
25
+ emoji(value) {
26
+ this.#emoji = assertEmoji(value);
27
+ return this;
28
+ }
29
+ build() {
30
+ if (this.#emoji === undefined) {
31
+ throw new MessageError('reaction.emoji belum diset — panggil emoji("🔥") (string kosong untuk menghapus reaksi)', "NO_EMOJI");
32
+ }
33
+ if (!targetIdOf(this.#target)) {
34
+ throw new ValidationError("reaction.target butuh event pesan masuk atau message key dengan id");
35
+ }
36
+ return { type: "reaction", target: this.#target, emoji: this.#emoji };
37
+ }
38
+ async send(jid, arg) {
39
+ const { client, options } = this._resolve(arg);
40
+ const target = typeof jid === "string" && jid
41
+ ? jid
42
+ : (targetChatJidOf(this.#target) ?? this._defaultTarget());
43
+ if (!target) {
44
+ throw new MessageError("tujuan reaksi tidak diketahui — panggil send(jid), defaultTo(jid), atau berikan target pesan yang punya remoteJid", "NO_TARGET");
45
+ }
46
+ const content = this.build();
47
+ const send = client.message.send.bind(client.message);
48
+ return Object.keys(options).length
49
+ ? send(target, content, options)
50
+ : send(target, content);
51
+ }
52
+ }
53
+ const isReactionConfig = (value) => !!value && typeof value === "object" && "target" in value && "emoji" in value;
54
+ export function reaction(client, first, second, third) {
55
+ if (typeof first === "string") {
56
+ if (!isReactionConfig(second))
57
+ return new ReactionBuilder(client);
58
+ return sendReaction(client, first, second, third);
59
+ }
60
+ if (!isReactionConfig(first))
61
+ return new ReactionBuilder(client);
62
+ return sendReaction(client, undefined, first, second);
63
+ }
64
+ export const applyReactionConfig = (builder, config) => {
65
+ builder.target(config.target).emoji(config.emoji);
66
+ };
67
+ export const sendReaction = async (client, jid, config, options) => {
68
+ const builder = new ReactionBuilder(client);
69
+ applyReactionConfig(builder, config);
70
+ return sendConfigured(builder, jid, options);
71
+ };
@@ -0,0 +1,29 @@
1
+ import { BaseBuilder } from "../core/base-builder.js";
2
+ import { type MessageSendOptions } from "../core/async-send.js";
3
+ import type { MessageSendResult } from "../zapo-client.js";
4
+ import { type MediaSlotOptions } from "../btn/media-slot.js";
5
+ import type { MediaSource } from "../btn/media-source.js";
6
+ import { type MediaBuildResult, type MediaSlotResolution } from "../payloads.js";
7
+ import type { ZapoClient } from "../zapo-client.js";
8
+ export type { MediaSlotOptions } from "../btn/media-slot.js";
9
+ export interface StickerMediaOptions {
10
+ mimetype?: string;
11
+ isAnimated?: boolean;
12
+ pngThumbnail?: Uint8Array | false;
13
+ width?: number;
14
+ height?: number;
15
+ stickerSentTs?: number;
16
+ }
17
+ export interface StickerConfig extends StickerMediaOptions {
18
+ source: MediaSource;
19
+ }
20
+ export declare class StickerBuilder extends BaseBuilder<MediaBuildResult> {
21
+ #private;
22
+ source(source: MediaSource, options?: MediaSlotOptions): this;
23
+ slot(): Promise<MediaSlotResolution>;
24
+ build(): Promise<MediaBuildResult>;
25
+ }
26
+ export declare function sticker(client?: ZapoClient): StickerBuilder;
27
+ export declare function sticker(client: ZapoClient | undefined, jid: string, config: StickerConfig, options?: MessageSendOptions): Promise<MessageSendResult>;
28
+ export declare const applyStickerConfig: (builder: StickerBuilder, config: StickerConfig) => void;
29
+ export declare const sendSticker: (client: ZapoClient | undefined, jid: string | undefined, config: StickerConfig, options?: MessageSendOptions) => Promise<MessageSendResult>;
@@ -0,0 +1,44 @@
1
+ import { BaseBuilder } from "../core/base-builder.js";
2
+ import { MessageError } from "../core/errors.js";
3
+ import { sendConfigured } from "../core/async-send.js";
4
+ import { resolveMediaSlot, } from "../btn/media-slot.js";
5
+ import { mediaSlotToMessage, } from "../payloads.js";
6
+ export class StickerBuilder extends BaseBuilder {
7
+ #slot;
8
+ source(source, options) {
9
+ this.#slot = {
10
+ kind: "sticker",
11
+ source,
12
+ options: options ?? {},
13
+ label: "sticker",
14
+ };
15
+ return this;
16
+ }
17
+ async slot() {
18
+ return this.#resolveSlot();
19
+ }
20
+ async #resolveSlot() {
21
+ if (!this.#slot) {
22
+ throw new MessageError("sticker builder belum punya sumber — panggil source(bytesAtauPath)", "NO_SOURCE");
23
+ }
24
+ const { client } = this._resolve();
25
+ return resolveMediaSlot(client, this.#slot);
26
+ }
27
+ async build() {
28
+ return mediaSlotToMessage(await this.#resolveSlot());
29
+ }
30
+ }
31
+ export function sticker(client, jid, config, options) {
32
+ if (config === undefined)
33
+ return new StickerBuilder(client);
34
+ return sendSticker(client, jid, config, options);
35
+ }
36
+ export const applyStickerConfig = (builder, config) => {
37
+ const { source, ...options } = config;
38
+ builder.source(source, options);
39
+ };
40
+ export const sendSticker = async (client, jid, config, options) => {
41
+ const builder = new StickerBuilder(client);
42
+ applyStickerConfig(builder, config);
43
+ return sendConfigured(builder, jid, options);
44
+ };
@@ -0,0 +1,18 @@
1
+ export interface MessageKeyLike {
2
+ remoteJid?: string;
3
+ id?: string;
4
+ fromMe?: boolean;
5
+ participant?: string;
6
+ }
7
+ export interface MessageTargetLike {
8
+ key?: MessageKeyLike;
9
+ id?: string;
10
+ remoteJid?: string;
11
+ fromMe?: boolean;
12
+ participant?: string;
13
+ message?: unknown;
14
+ rawNode?: unknown;
15
+ }
16
+ export declare const targetKeyOf: (target: unknown) => MessageKeyLike | undefined;
17
+ export declare const targetChatJidOf: (target: unknown) => string | undefined;
18
+ export declare const targetIdOf: (target: unknown) => string | undefined;
@@ -0,0 +1,24 @@
1
+ export const targetKeyOf = (target) => {
2
+ if (!target || typeof target !== "object")
3
+ return undefined;
4
+ const ref = target;
5
+ if (ref.key && typeof ref.key === "object")
6
+ return ref.key;
7
+ if (typeof ref.id === "string")
8
+ return ref;
9
+ return undefined;
10
+ };
11
+ export const targetChatJidOf = (target) => {
12
+ const key = targetKeyOf(target);
13
+ const jid = key?.remoteJid;
14
+ if (typeof jid === "string" && jid)
15
+ return jid;
16
+ return undefined;
17
+ };
18
+ export const targetIdOf = (target) => {
19
+ const key = targetKeyOf(target);
20
+ const id = key?.id;
21
+ if (typeof id === "string" && id)
22
+ return id;
23
+ return undefined;
24
+ };
@@ -0,0 +1,17 @@
1
+ import { BaseBuilder } from "../core/base-builder.js";
2
+ import { type MessageSendOptions } from "../core/async-send.js";
3
+ import type { MessageSendResult } from "../zapo-client.js";
4
+ import type { TextBuildResult } from "../payloads.js";
5
+ import type { ZapoClient } from "../zapo-client.js";
6
+ export interface TextConfig {
7
+ body: string;
8
+ }
9
+ export declare class TextBuilder extends BaseBuilder<TextBuildResult> {
10
+ #private;
11
+ body(text: string): this;
12
+ build(): TextBuildResult;
13
+ }
14
+ export declare function text(client?: ZapoClient): TextBuilder;
15
+ export declare function text(client: ZapoClient | undefined, jid: string, config: TextConfig, options?: MessageSendOptions): Promise<MessageSendResult>;
16
+ export declare const applyTextConfig: (builder: TextBuilder, config: TextConfig) => void;
17
+ export declare const sendText: (client: ZapoClient | undefined, jid: string | undefined, config: TextConfig, options?: MessageSendOptions) => Promise<MessageSendResult>;
@@ -0,0 +1,29 @@
1
+ import { BaseBuilder } from "../core/base-builder.js";
2
+ import { sendConfigured } from "../core/async-send.js";
3
+ import { assertText } from "../btn/validators.js";
4
+ export class TextBuilder extends BaseBuilder {
5
+ #text;
6
+ body(text) {
7
+ this.#text = assertText(text, "text.body");
8
+ return this;
9
+ }
10
+ build() {
11
+ if (this.#text === undefined) {
12
+ this.#text = assertText(undefined, "text.body");
13
+ }
14
+ return { conversation: this.#text };
15
+ }
16
+ }
17
+ export function text(client, jid, config, options) {
18
+ if (config === undefined)
19
+ return new TextBuilder(client);
20
+ return sendText(client, jid, config, options);
21
+ }
22
+ export const applyTextConfig = (builder, config) => {
23
+ builder.body(config.body);
24
+ };
25
+ export const sendText = async (client, jid, config, options) => {
26
+ const builder = new TextBuilder(client);
27
+ applyTextConfig(builder, config);
28
+ return sendConfigured(builder, jid, options);
29
+ };
@@ -0,0 +1,9 @@
1
+ export interface VcardInput {
2
+ displayName: string;
3
+ phoneNumber?: string;
4
+ organization?: string;
5
+ email?: string;
6
+ url?: string;
7
+ note?: string;
8
+ }
9
+ export declare const buildVcard: (input: VcardInput) => string;
@@ -0,0 +1,23 @@
1
+ const escapeVcardValue = (value) => value.replace(/([\\,;])/g, "\\$1").replace(/\n/g, "\\n");
2
+ export const buildVcard = (input) => {
3
+ const lines = ["BEGIN:VCARD", "VERSION:3.0"];
4
+ lines.push(`FN:${escapeVcardValue(input.displayName)}`);
5
+ lines.push(`N:;${escapeVcardValue(input.displayName)};;;`);
6
+ if (input.phoneNumber !== undefined) {
7
+ lines.push(`TEL;type=CELL;type=VOICE:${escapeVcardValue(input.phoneNumber)}`);
8
+ }
9
+ if (input.organization !== undefined) {
10
+ lines.push(`ORG:${escapeVcardValue(input.organization)}`);
11
+ }
12
+ if (input.email !== undefined) {
13
+ lines.push(`EMAIL;type=INTERNET:${escapeVcardValue(input.email)}`);
14
+ }
15
+ if (input.url !== undefined) {
16
+ lines.push(`URL:${escapeVcardValue(input.url)}`);
17
+ }
18
+ if (input.note !== undefined) {
19
+ lines.push(`NOTE:${escapeVcardValue(input.note)}`);
20
+ }
21
+ lines.push("END:VCARD");
22
+ return lines.join("\n");
23
+ };
@@ -0,0 +1,6 @@
1
+ export interface WebpInfo {
2
+ width: number | undefined;
3
+ height: number | undefined;
4
+ isAnimated: boolean;
5
+ }
6
+ export declare const probeWebp: (bytes: Uint8Array) => WebpInfo | undefined;
@@ -0,0 +1,57 @@
1
+ const RIFF = 0x52494646;
2
+ const WEBP = 0x57454250;
3
+ const readUInt32BE = (bytes, offset) => (bytes[offset] * 0x1000000 +
4
+ (bytes[offset + 1] << 16) +
5
+ (bytes[offset + 2] << 8) +
6
+ bytes[offset + 3]) >>>
7
+ 0;
8
+ const readUInt32LE = (bytes, offset) => (bytes[offset] |
9
+ (bytes[offset + 1] << 8) |
10
+ (bytes[offset + 2] << 16) |
11
+ (bytes[offset + 3] << 24)) >>>
12
+ 0;
13
+ const readUInt24LE = (bytes, offset) => (bytes[offset] | (bytes[offset + 1] << 8) | (bytes[offset + 2] << 16)) >>>
14
+ 0;
15
+ const readUInt16LE = (bytes, offset) => bytes[offset] | (bytes[offset + 1] << 8);
16
+ const isWebpContainer = (bytes) => bytes.byteLength >= 12 &&
17
+ readUInt32BE(bytes, 0) === RIFF &&
18
+ readUInt32BE(bytes, 8) === WEBP;
19
+ export const probeWebp = (bytes) => {
20
+ if (!isWebpContainer(bytes))
21
+ return undefined;
22
+ const info = {
23
+ width: undefined,
24
+ height: undefined,
25
+ isAnimated: false,
26
+ };
27
+ let offset = 12;
28
+ while (offset + 8 <= bytes.byteLength) {
29
+ const chunkView = bytes.subarray(offset, offset + 4);
30
+ const chunk = String.fromCharCode(chunkView[0], chunkView[1], chunkView[2], chunkView[3]);
31
+ const size = readUInt32LE(bytes, offset + 4);
32
+ const payload = offset + 8;
33
+ if (payload + size > bytes.byteLength)
34
+ break;
35
+ if (chunk === "VP8X" && size >= 10) {
36
+ info.width = readUInt24LE(bytes, payload + 4) + 1;
37
+ info.height = readUInt24LE(bytes, payload + 7) + 1;
38
+ }
39
+ else if (chunk === "ANIM") {
40
+ info.isAnimated = true;
41
+ }
42
+ else if (chunk === "VP8 " && info.width === undefined && size >= 10) {
43
+ info.width = readUInt16LE(bytes, payload + 6) & 0x3fff;
44
+ info.height = readUInt16LE(bytes, payload + 8) & 0x3fff;
45
+ }
46
+ else if (chunk === "VP8L" && info.width === undefined && size >= 5) {
47
+ const bits = bytes[payload + 1] |
48
+ (bytes[payload + 2] << 8) |
49
+ (bytes[payload + 3] << 16) |
50
+ (bytes[payload + 4] << 24);
51
+ info.width = (bits & 0x3fff) + 1;
52
+ info.height = ((bits >>> 14) & 0x3fff) + 1;
53
+ }
54
+ offset = payload + size + (size % 2);
55
+ }
56
+ return info;
57
+ };
@@ -0,0 +1,180 @@
1
+ import type { Proto } from "zapo-js";
2
+ export type InteractiveHeaderPayload = Proto.Message.InteractiveMessage.Header.$Properties;
3
+ export type LocationMessagePayload = Proto.Message.LocationMessage.$Properties;
4
+ export type ContextInfoPayload = Proto.ContextInfo.$Properties;
5
+ export interface NativeFlowButtonPayload {
6
+ name: string;
7
+ buttonParamsJson: string;
8
+ }
9
+ export interface NativeFlowMessagePayload {
10
+ buttons: NativeFlowButtonPayload[];
11
+ messageVersion: number;
12
+ messageParamsJson?: string;
13
+ }
14
+ export interface InteractiveCardPayload {
15
+ body: {
16
+ text: string;
17
+ };
18
+ nativeFlowMessage: NativeFlowMessagePayload;
19
+ header?: InteractiveHeaderPayload;
20
+ footer?: {
21
+ text: string;
22
+ };
23
+ }
24
+ export interface ButtonsMessagePayload {
25
+ contentText: string;
26
+ buttons: Proto.Message.ButtonsMessage.Button.$Properties[];
27
+ headerType: Proto.Message.ButtonsMessage.HeaderType;
28
+ text?: string;
29
+ footerText?: string;
30
+ imageMessage?: Proto.Message.ImageMessage.$Properties;
31
+ videoMessage?: Proto.Message.VideoMessage.$Properties;
32
+ documentMessage?: Proto.Message.DocumentMessage.$Properties;
33
+ locationMessage?: LocationMessagePayload | null;
34
+ }
35
+ export interface ListMessagePayload {
36
+ title: string;
37
+ description: string;
38
+ buttonText: string;
39
+ listType: Proto.Message.ListMessage.ListType;
40
+ sections: Proto.Message.ListMessage.Section.$Properties[];
41
+ footerText?: string;
42
+ }
43
+ export interface ButtonBuildResult {
44
+ interactiveMessage: InteractiveCardPayload;
45
+ }
46
+ export interface LegacyButtonBuildResult {
47
+ buttonsMessage: ButtonsMessagePayload;
48
+ }
49
+ export interface ListBuildResult {
50
+ listMessage: ListMessagePayload;
51
+ }
52
+ export type MediaSlotResolution = {
53
+ field: "imageMessage";
54
+ message: Proto.Message.ImageMessage.$Properties;
55
+ } | {
56
+ field: "videoMessage";
57
+ message: Proto.Message.VideoMessage.$Properties;
58
+ } | {
59
+ field: "documentMessage";
60
+ message: Proto.Message.DocumentMessage.$Properties;
61
+ } | {
62
+ field: "audioMessage";
63
+ message: Proto.Message.AudioMessage.$Properties;
64
+ } | {
65
+ field: "stickerMessage";
66
+ message: Proto.Message.StickerMessage.$Properties;
67
+ };
68
+ export interface CodeMetadataPayload {
69
+ codeLanguage: string;
70
+ codeBlocks: {
71
+ codeContent: string;
72
+ highlightType: number;
73
+ }[];
74
+ }
75
+ export interface TableMetadataPayload {
76
+ title: string;
77
+ rows: {
78
+ items: string[];
79
+ isHeading?: boolean;
80
+ }[];
81
+ }
82
+ export type SubmessagePayload = {
83
+ messageType: Proto.AIRichResponseSubMessageType;
84
+ messageText: string;
85
+ } | {
86
+ messageType: Proto.AIRichResponseSubMessageType;
87
+ codeMetadata: CodeMetadataPayload;
88
+ } | {
89
+ messageType: Proto.AIRichResponseSubMessageType;
90
+ tableMetadata: TableMetadataPayload;
91
+ };
92
+ export interface RichResponseMessagePayload {
93
+ messageType: Proto.AIRichResponseMessageType;
94
+ submessages: SubmessagePayload[];
95
+ unifiedResponse: {
96
+ data: Uint8Array;
97
+ };
98
+ contextInfo: Record<string, unknown>;
99
+ messageText?: string | undefined;
100
+ }
101
+ export interface RichResponseBuildResult {
102
+ richResponseMessage: RichResponseMessagePayload;
103
+ }
104
+ export interface BotForwardedEnvelope {
105
+ message: RichResponseBuildResult;
106
+ }
107
+ export interface WrapBotForwardedResult {
108
+ botForwardedMessage: BotForwardedEnvelope;
109
+ }
110
+ export interface MessageContextInfoPayload {
111
+ deviceListMetadataVersion: number;
112
+ messageSecret: Uint8Array;
113
+ }
114
+ export interface PlaceholderBuildResult extends WrapBotForwardedResult {
115
+ messageContextInfo: MessageContextInfoPayload;
116
+ }
117
+ export interface EditBuildResult {
118
+ botForwardedMessage: {
119
+ message: {
120
+ protocolMessage: {
121
+ key: {
122
+ remoteJid: string;
123
+ fromMe: true;
124
+ id: string;
125
+ };
126
+ type: Proto.Message.ProtocolMessage.Type;
127
+ editedMessage: WrapBotForwardedResult;
128
+ };
129
+ };
130
+ };
131
+ }
132
+ export interface TextBuildResult {
133
+ conversation: string;
134
+ }
135
+ export interface ExtendedTextMessagePayload {
136
+ text: string;
137
+ matchedText: string;
138
+ previewType: Proto.Message.ExtendedTextMessage.PreviewType;
139
+ title?: string;
140
+ description?: string;
141
+ jpegThumbnail?: Uint8Array;
142
+ }
143
+ export interface LinkPreviewBuildResult {
144
+ extendedTextMessage: ExtendedTextMessagePayload;
145
+ }
146
+ export interface ContactMessagePayload {
147
+ displayName: string;
148
+ vcard: string;
149
+ }
150
+ export interface ContactBuildResult {
151
+ contactMessage: ContactMessagePayload;
152
+ }
153
+ export interface AlbumMessagePayload {
154
+ expectedImageCount: number;
155
+ expectedVideoCount: number;
156
+ }
157
+ export interface AlbumBuildResult {
158
+ albumMessage: AlbumMessagePayload;
159
+ }
160
+ export interface LocationBuildResult {
161
+ locationMessage: LocationMessagePayload;
162
+ }
163
+ export type AlbumChildPayload = {
164
+ field: string;
165
+ message: unknown;
166
+ };
167
+ export type MediaMessageKind = "image" | "video" | "audio" | "document";
168
+ export type MediaBuildResult = {
169
+ imageMessage: Proto.Message.ImageMessage.$Properties;
170
+ } | {
171
+ videoMessage: Proto.Message.VideoMessage.$Properties;
172
+ } | {
173
+ audioMessage: Proto.Message.AudioMessage.$Properties;
174
+ } | {
175
+ documentMessage: Proto.Message.DocumentMessage.$Properties;
176
+ } | {
177
+ stickerMessage: Proto.Message.StickerMessage.$Properties;
178
+ };
179
+ export declare const mediaSlotToMessage: (resolution: MediaSlotResolution) => MediaBuildResult;
180
+ export type BuilderMessagePayload = ButtonBuildResult | LegacyButtonBuildResult | ListBuildResult | WrapBotForwardedResult | PlaceholderBuildResult | EditBuildResult | TextBuildResult | LinkPreviewBuildResult | ContactBuildResult | AlbumBuildResult | LocationBuildResult | MediaBuildResult;
@@ -0,0 +1 @@
1
+ export const mediaSlotToMessage = (resolution) => ({ [resolution.field]: resolution.message });