@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.
- package/CHANGELOG.md +159 -0
- package/LICENSE +20 -0
- package/README.md +1401 -2
- package/build.config.json +28 -0
- package/dist/airich/airich.d.ts +180 -0
- package/dist/airich/airich.js +548 -0
- package/dist/airich/context.d.ts +24 -0
- package/dist/airich/context.js +48 -0
- package/dist/airich/encode.d.ts +3 -0
- package/dist/airich/encode.js +16 -0
- package/dist/airich/index.d.ts +20 -0
- package/dist/airich/index.js +11 -0
- package/dist/airich/inline.d.ts +45 -0
- package/dist/airich/inline.js +152 -0
- package/dist/airich/nodes.d.ts +30 -0
- package/dist/airich/nodes.js +121 -0
- package/dist/airich/primitives.d.ts +144 -0
- package/dist/airich/primitives.js +230 -0
- package/dist/airich/protocol.d.ts +35 -0
- package/dist/airich/protocol.js +65 -0
- package/dist/airich/table.d.ts +22 -0
- package/dist/airich/table.js +35 -0
- package/dist/airich/tokenizer.d.ts +13 -0
- package/dist/airich/tokenizer.js +717 -0
- package/dist/airich/transport.d.ts +15 -0
- package/dist/airich/transport.js +56 -0
- package/dist/branding.d.ts +5 -0
- package/dist/branding.js +9 -0
- package/dist/btn/builders.d.ts +246 -0
- package/dist/btn/builders.js +710 -0
- package/dist/btn/media-slot.d.ts +28 -0
- package/dist/btn/media-slot.js +323 -0
- package/dist/btn/media-source.d.ts +36 -0
- package/dist/btn/media-source.js +116 -0
- package/dist/btn/sharp-loader.d.ts +5 -0
- package/dist/btn/sharp-loader.js +18 -0
- package/dist/btn/thumbnail.d.ts +21 -0
- package/dist/btn/thumbnail.js +124 -0
- package/dist/btn/validators.d.ts +40 -0
- package/dist/btn/validators.js +135 -0
- package/dist/btn.d.ts +1 -0
- package/dist/btn.js +1 -0
- package/dist/core/async-send.d.ts +20 -0
- package/dist/core/async-send.js +1 -0
- package/dist/core/base-builder.d.ts +20 -0
- package/dist/core/base-builder.js +67 -0
- package/dist/core/errors.d.ts +30 -0
- package/dist/core/errors.js +61 -0
- package/dist/download.d.ts +24 -0
- package/dist/download.js +123 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +22 -0
- package/dist/integration/augment.d.ts +97 -0
- package/dist/integration/augment.js +1 -0
- package/dist/integration/auto.d.ts +8 -0
- package/dist/integration/auto.js +79 -0
- package/dist/integration/index.d.ts +4 -0
- package/dist/integration/index.js +2 -0
- package/dist/integration/methods.d.ts +25 -0
- package/dist/integration/methods.js +24 -0
- package/dist/interactive.d.ts +24 -0
- package/dist/interactive.js +121 -0
- package/dist/media-gate.d.ts +99 -0
- package/dist/media-gate.js +322 -0
- package/dist/message/album.d.ts +33 -0
- package/dist/message/album.js +107 -0
- package/dist/message/contact.d.ts +29 -0
- package/dist/message/contact.js +123 -0
- package/dist/message/forward.d.ts +23 -0
- package/dist/message/forward.js +77 -0
- package/dist/message/index.d.ts +26 -0
- package/dist/message/index.js +13 -0
- package/dist/message/link-preview.d.ts +28 -0
- package/dist/message/link-preview.js +98 -0
- package/dist/message/location.d.ts +24 -0
- package/dist/message/location.js +94 -0
- package/dist/message/media.d.ts +90 -0
- package/dist/message/media.js +123 -0
- package/dist/message/poll.d.ts +24 -0
- package/dist/message/poll.js +98 -0
- package/dist/message/reaction.d.ts +20 -0
- package/dist/message/reaction.js +71 -0
- package/dist/message/sticker.d.ts +29 -0
- package/dist/message/sticker.js +44 -0
- package/dist/message/target.d.ts +18 -0
- package/dist/message/target.js +24 -0
- package/dist/message/text.d.ts +17 -0
- package/dist/message/text.js +29 -0
- package/dist/message/vcard.d.ts +9 -0
- package/dist/message/vcard.js +23 -0
- package/dist/message/webp.d.ts +6 -0
- package/dist/message/webp.js +57 -0
- package/dist/payloads.d.ts +180 -0
- package/dist/payloads.js +1 -0
- package/dist/serialize.d.ts +41 -0
- package/dist/serialize.js +93 -0
- package/dist/status.d.ts +3 -0
- package/dist/status.js +21 -0
- package/dist/zapo-client.d.ts +44 -0
- package/dist/zapo-client.js +1 -0
- package/examples/airich.ts +59 -0
- package/examples/buttons.ts +48 -0
- package/examples/client-methods.ts +58 -0
- package/examples/hybrid.ts +133 -0
- package/examples/serialize.ts +61 -0
- package/package.json +271 -4
- package/scripts/check-no-comments.mjs +101 -0
- package/scripts/compare-golden.mjs +461 -0
- package/scripts/lib-config.mjs +9 -0
- package/scripts/smoke-auto.mjs +75 -0
- package/scripts/test-external-consumer.mjs +316 -0
- package/scripts/verify-package.mjs +78 -0
- package/src/airich/airich.ts +970 -0
- package/src/airich/context.ts +96 -0
- package/src/airich/encode.ts +25 -0
- package/src/airich/index.ts +98 -0
- package/src/airich/inline.ts +272 -0
- package/src/airich/nodes.ts +174 -0
- package/src/airich/primitives.ts +474 -0
- package/src/airich/protocol.ts +133 -0
- package/src/airich/table.ts +70 -0
- package/src/airich/tokenizer.ts +799 -0
- package/src/airich/transport.ts +106 -0
- package/src/branding.ts +23 -0
- package/src/btn/builders.ts +1073 -0
- package/src/btn/media-slot.ts +486 -0
- package/src/btn/media-source.ts +189 -0
- package/src/btn/sharp-loader.ts +23 -0
- package/src/btn/thumbnail.ts +182 -0
- package/src/btn/validators.ts +237 -0
- package/src/btn.ts +8 -0
- package/src/core/async-send.ts +28 -0
- package/src/core/base-builder.ts +104 -0
- package/src/core/errors.ts +82 -0
- package/src/download.ts +212 -0
- package/src/index.ts +229 -0
- package/src/integration/augment.ts +262 -0
- package/src/integration/auto.ts +103 -0
- package/src/integration/index.ts +8 -0
- package/src/integration/methods.ts +45 -0
- package/src/interactive.ts +188 -0
- package/src/media-gate.ts +499 -0
- package/src/message/album.ts +187 -0
- package/src/message/contact.ts +170 -0
- package/src/message/forward.ts +123 -0
- package/src/message/index.ts +83 -0
- package/src/message/link-preview.ts +148 -0
- package/src/message/location.ts +150 -0
- package/src/message/media.ts +323 -0
- package/src/message/poll.ts +158 -0
- package/src/message/reaction.ts +133 -0
- package/src/message/sticker.ts +100 -0
- package/src/message/target.ts +38 -0
- package/src/message/text.ts +61 -0
- package/src/message/vcard.ts +36 -0
- package/src/message/webp.ts +78 -0
- package/src/payloads.ts +204 -0
- package/src/serialize.ts +180 -0
- package/src/status.ts +29 -0
- package/src/zapo-client.ts +84 -0
- package/test/airich-inline.test.ts +200 -0
- package/test/airich-primitives.test.ts +226 -0
- package/test/airich-tokenizer.test.ts +145 -0
- package/test/airich.golden.test.ts +406 -0
- package/test/airich.test.ts +1006 -0
- package/test/btn-button.test.ts +416 -0
- package/test/btn-header.test.ts +646 -0
- package/test/btn-legacy.test.ts +342 -0
- package/test/btn-lifecycle.test.ts +295 -0
- package/test/btn-list.test.ts +261 -0
- package/test/btn-media-source.test.ts +150 -0
- package/test/btn-thumbnail.test.ts +160 -0
- package/test/builder-compat.test.ts +264 -0
- package/test/helpers.ts +27 -0
- package/test/hybrid-airich.test.ts +345 -0
- package/test/hybrid-client.test.ts +239 -0
- package/test/hybrid-errors.test.ts +557 -0
- package/test/hybrid-interactive.test.ts +455 -0
- package/test/hybrid.golden.test.ts +349 -0
- package/test/hybrid.test.ts +479 -0
- package/test/integration-auto.test.ts +159 -0
- package/test/integration.fakeserver.test.ts +440 -0
- package/test/media-gate.test.ts +215 -0
- package/test/message-album.test.ts +145 -0
- package/test/message-builders.test.ts +401 -0
- package/test/message-media.test.ts +303 -0
- package/test/message.fakeserver.test.ts +284 -0
- package/test/message.golden.test.ts +254 -0
- package/test/serializer.test.ts +448 -0
- package/tsconfig.json +26 -0
- package/tsconfig.test.json +10 -0
package/src/download.ts
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { WaMediaTransferClient } from "zapo-js";
|
|
2
|
+
import type { WaMediaTransferClient as WaMediaTransferClientType } from "zapo-js";
|
|
3
|
+
import { Readable } from "node:stream";
|
|
4
|
+
import {
|
|
5
|
+
getSharedMediaQueue,
|
|
6
|
+
limitStreamBytes,
|
|
7
|
+
type LimitedStream,
|
|
8
|
+
} from "./media-gate.js";
|
|
9
|
+
import type { ZapoClient, ZapoDownloadCapableClient } from "./zapo-client.js";
|
|
10
|
+
|
|
11
|
+
const waMediaTransfer: WaMediaTransferClientType = new WaMediaTransferClient();
|
|
12
|
+
|
|
13
|
+
type MediaGateMode = "buffer" | "stream";
|
|
14
|
+
|
|
15
|
+
const throughMediaGate = async (
|
|
16
|
+
label: string,
|
|
17
|
+
mode: MediaGateMode,
|
|
18
|
+
work: () => Promise<unknown>,
|
|
19
|
+
): Promise<unknown> => {
|
|
20
|
+
const queue = getSharedMediaQueue();
|
|
21
|
+
|
|
22
|
+
return queue.run(
|
|
23
|
+
async ({ signal, maxBytes, noteBytes }) => {
|
|
24
|
+
const result = await work();
|
|
25
|
+
|
|
26
|
+
if (mode === "buffer") {
|
|
27
|
+
const bytes =
|
|
28
|
+
result instanceof Uint8Array
|
|
29
|
+
? result
|
|
30
|
+
: new Uint8Array((result ?? []) as number[]);
|
|
31
|
+
noteBytes(bytes.byteLength);
|
|
32
|
+
if (bytes.byteLength > maxBytes) {
|
|
33
|
+
queue.markOversized();
|
|
34
|
+
throw new Error(
|
|
35
|
+
`media melebihi batas ukuran (${bytes.byteLength} > ${maxBytes} byte)`,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
if (signal.aborted) {
|
|
39
|
+
throw new Error(`media job dibatalkan (signal)`);
|
|
40
|
+
}
|
|
41
|
+
return Buffer.from(bytes);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (signal.aborted) {
|
|
45
|
+
throw new Error(`media job dibatalkan (signal)`);
|
|
46
|
+
}
|
|
47
|
+
const stream = result;
|
|
48
|
+
if (stream && typeof (stream as Readable).pipe === "function") {
|
|
49
|
+
return limitStreamBytes(stream as Readable, maxBytes, () =>
|
|
50
|
+
queue.markOversized(),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
return stream;
|
|
54
|
+
},
|
|
55
|
+
{ label: `wa-media:${label}` },
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
type MediaDecryptRequest = Parameters<
|
|
60
|
+
WaMediaTransferClientType["downloadAndDecrypt"]
|
|
61
|
+
>[0];
|
|
62
|
+
type MediaDecryptStreamRequest = Parameters<
|
|
63
|
+
WaMediaTransferClientType["downloadAndDecryptStream"]
|
|
64
|
+
>[0];
|
|
65
|
+
|
|
66
|
+
interface ThumbnailMediaRecord {
|
|
67
|
+
mediaKey?: Uint8Array;
|
|
68
|
+
thumbnailDirectPath?: string;
|
|
69
|
+
thumbnailEncSha256?: Uint8Array;
|
|
70
|
+
thumbnailSha256?: Uint8Array;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const thumbnailRequest = (etm: ThumbnailMediaRecord) => ({
|
|
74
|
+
mediaType: "thumbnail-link" as const,
|
|
75
|
+
mediaKey: etm.mediaKey,
|
|
76
|
+
directPath: etm.thumbnailDirectPath,
|
|
77
|
+
fileEncSha256: etm.thumbnailEncSha256,
|
|
78
|
+
fileSha256: etm.thumbnailSha256,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const downloadThumbnail = async (
|
|
82
|
+
mode: "bytes" | "stream",
|
|
83
|
+
etm: ThumbnailMediaRecord,
|
|
84
|
+
): Promise<unknown> => {
|
|
85
|
+
if (mode === "bytes") {
|
|
86
|
+
return throughMediaGate("thumbnail", "buffer", async () => {
|
|
87
|
+
try {
|
|
88
|
+
return await waMediaTransfer.downloadAndDecrypt(
|
|
89
|
+
thumbnailRequest(etm) as MediaDecryptRequest,
|
|
90
|
+
);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
if ((error as Error).message === "media MAC mismatch") {
|
|
93
|
+
return await waMediaTransfer.downloadAndDecrypt({
|
|
94
|
+
...thumbnailRequest(etm),
|
|
95
|
+
mediaType: "image",
|
|
96
|
+
} as MediaDecryptRequest);
|
|
97
|
+
}
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return throughMediaGate("thumbnail", "stream", async () => {
|
|
104
|
+
try {
|
|
105
|
+
const { plaintext } = await waMediaTransfer.downloadAndDecryptStream(
|
|
106
|
+
thumbnailRequest(etm) as MediaDecryptStreamRequest,
|
|
107
|
+
);
|
|
108
|
+
return plaintext;
|
|
109
|
+
} catch (error) {
|
|
110
|
+
if ((error as Error).message === "media MAC mismatch") {
|
|
111
|
+
const { plaintext } = await waMediaTransfer.downloadAndDecryptStream({
|
|
112
|
+
...thumbnailRequest(etm),
|
|
113
|
+
mediaType: "image",
|
|
114
|
+
} as MediaDecryptStreamRequest);
|
|
115
|
+
return plaintext;
|
|
116
|
+
}
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export interface DownloadReceiver {
|
|
123
|
+
content?: string | undefined;
|
|
124
|
+
message?: Record<string, unknown> | undefined;
|
|
125
|
+
client: ZapoDownloadCapableClient;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function mDownload(
|
|
129
|
+
this: DownloadReceiver,
|
|
130
|
+
dataType: "buffer" | "stream",
|
|
131
|
+
): Promise<unknown> {
|
|
132
|
+
const etm = (this?.message as Record<string, unknown> | undefined)
|
|
133
|
+
?.extendedTextMessage as ThumbnailMediaRecord | undefined;
|
|
134
|
+
if (this?.content === "extendedTextMessage" && etm?.mediaKey) {
|
|
135
|
+
if (dataType === "buffer") {
|
|
136
|
+
return throughMediaGate("m-etm", "buffer", async () => {
|
|
137
|
+
const bytes = await waMediaTransfer.downloadAndDecrypt(
|
|
138
|
+
thumbnailRequest(etm) as MediaDecryptRequest,
|
|
139
|
+
);
|
|
140
|
+
return Buffer.from(bytes);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return downloadThumbnail("stream", etm);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (dataType === "buffer") {
|
|
147
|
+
return throughMediaGate("m-message", "buffer", async () => {
|
|
148
|
+
const bytes = await this.client.message.downloadBytes(this);
|
|
149
|
+
return Buffer.from(bytes);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return throughMediaGate("m-message", "stream", async () =>
|
|
153
|
+
this.client.message.download(this),
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface QuotedDownloadReceiver {
|
|
158
|
+
content?: string | undefined;
|
|
159
|
+
message?: Record<string, unknown> | undefined;
|
|
160
|
+
key?: Record<string, unknown>;
|
|
161
|
+
client: ZapoDownloadCapableClient;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function qDownload(
|
|
165
|
+
this: QuotedDownloadReceiver,
|
|
166
|
+
dataType: "bytes" | "stream",
|
|
167
|
+
): Promise<unknown> {
|
|
168
|
+
const isExtendedText = this?.content === "extendedTextMessage";
|
|
169
|
+
const etm = (this?.message as Record<string, unknown> | undefined)
|
|
170
|
+
?.extendedTextMessage as
|
|
171
|
+
(ThumbnailMediaRecord & { jpegThumbnail?: Uint8Array }) | undefined;
|
|
172
|
+
|
|
173
|
+
if (isExtendedText && etm?.mediaKey) {
|
|
174
|
+
return downloadThumbnail(dataType === "bytes" ? "bytes" : "stream", etm);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (isExtendedText && etm?.jpegThumbnail) {
|
|
178
|
+
const bytes = etm.jpegThumbnail;
|
|
179
|
+
return dataType === "bytes" ? Buffer.from(bytes) : Readable.from([bytes]);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (isExtendedText) {
|
|
183
|
+
const message = this.message as Record<string, unknown>;
|
|
184
|
+
if (dataType === "bytes") {
|
|
185
|
+
return throughMediaGate("q-etm", "buffer", async () =>
|
|
186
|
+
this.client.message.downloadBytes(message),
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
return throughMediaGate("q-etm", "stream", async () =>
|
|
190
|
+
this.client.message.download(message),
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (this?.content === "groupStatusMessageV2") {
|
|
195
|
+
const groupStatusMessageV2 = (this.message as Record<string, unknown>)
|
|
196
|
+
.groupStatusMessageV2 as { message?: unknown };
|
|
197
|
+
return this.client.message.download(groupStatusMessageV2.message);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const message = this.message as Record<string, unknown>;
|
|
201
|
+
if (dataType === "bytes") {
|
|
202
|
+
return throughMediaGate("q-message", "buffer", async () =>
|
|
203
|
+
this.client.message.downloadBytes(message),
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
return throughMediaGate("q-message", "stream", async () =>
|
|
207
|
+
this.client.message.download(message),
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export { mDownload, qDownload, downloadThumbnail };
|
|
212
|
+
export type { LimitedStream };
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import "./integration/auto.js";
|
|
2
|
+
import { button, legacyButton, listMessage } from "./btn.js";
|
|
3
|
+
import { airich } from "./airich/index.js";
|
|
4
|
+
import type { ZapoClient } from "./zapo-client.js";
|
|
5
|
+
import type { AIRichConstructorOptions } from "./airich/airich.js";
|
|
6
|
+
|
|
7
|
+
export { BaseBuilder, isClient } from "./core/base-builder.js";
|
|
8
|
+
export type { SendResolutionArg } from "./core/base-builder.js";
|
|
9
|
+
export type { MessageSendOptions } from "./core/async-send.js";
|
|
10
|
+
export {
|
|
11
|
+
MessageError,
|
|
12
|
+
ValidationError,
|
|
13
|
+
ItemNotFoundError,
|
|
14
|
+
DuplicateIdError,
|
|
15
|
+
InvalidTargetError,
|
|
16
|
+
ProtocolSendError,
|
|
17
|
+
MediaError,
|
|
18
|
+
} from "./core/errors.js";
|
|
19
|
+
export {
|
|
20
|
+
Button,
|
|
21
|
+
LegacyButton,
|
|
22
|
+
ListMessage,
|
|
23
|
+
button,
|
|
24
|
+
legacyButton,
|
|
25
|
+
listMessage,
|
|
26
|
+
} from "./btn.js";
|
|
27
|
+
export type {
|
|
28
|
+
ImageHeaderOptions,
|
|
29
|
+
VideoHeaderOptions,
|
|
30
|
+
DocumentHeaderOptions,
|
|
31
|
+
LocationHeaderOptions,
|
|
32
|
+
ListRowInput,
|
|
33
|
+
ListFallbackMode,
|
|
34
|
+
ButtonConfig,
|
|
35
|
+
LegacyButtonConfig,
|
|
36
|
+
ListMessageConfig,
|
|
37
|
+
ListSectionConfig,
|
|
38
|
+
InteractiveHeaderConfig,
|
|
39
|
+
LegacyButtonHeaderConfig,
|
|
40
|
+
ButtonItemConfig,
|
|
41
|
+
BottomSheetConfig,
|
|
42
|
+
LimitedTimeOfferConfig,
|
|
43
|
+
} from "./btn/builders.js";
|
|
44
|
+
export type { NativeSection, NativeSectionRow } from "./btn/validators.js";
|
|
45
|
+
export {
|
|
46
|
+
AIRich,
|
|
47
|
+
airich,
|
|
48
|
+
parseInline,
|
|
49
|
+
toTable,
|
|
50
|
+
tokenizeCode,
|
|
51
|
+
} from "./airich/index.js";
|
|
52
|
+
export type {
|
|
53
|
+
AIRichConstructorOptions,
|
|
54
|
+
AIRichConfig,
|
|
55
|
+
AIRichSectionConfig,
|
|
56
|
+
AIRichSendOptions,
|
|
57
|
+
RawNodeOptions,
|
|
58
|
+
InsertNodeOptions,
|
|
59
|
+
QuotableMessage,
|
|
60
|
+
RichTarget,
|
|
61
|
+
} from "./airich/index.js";
|
|
62
|
+
export type {
|
|
63
|
+
InlineEntity,
|
|
64
|
+
ParsedInline,
|
|
65
|
+
ParseInlineOptions,
|
|
66
|
+
} from "./airich/index.js";
|
|
67
|
+
export type {
|
|
68
|
+
TokenizeResult,
|
|
69
|
+
CodeBlockToken,
|
|
70
|
+
UnifiedCodeToken,
|
|
71
|
+
} from "./airich/index.js";
|
|
72
|
+
export {
|
|
73
|
+
encodeUnifiedResponse,
|
|
74
|
+
decodeUnifiedResponse,
|
|
75
|
+
stringifyEscaped,
|
|
76
|
+
} from "./airich/encode.js";
|
|
77
|
+
export {
|
|
78
|
+
buildRichResponse,
|
|
79
|
+
wrapBotForwarded,
|
|
80
|
+
buildPlaceholderContent,
|
|
81
|
+
buildEditContent,
|
|
82
|
+
layout,
|
|
83
|
+
ZWSP,
|
|
84
|
+
} from "./airich/protocol.js";
|
|
85
|
+
export type {
|
|
86
|
+
UnifiedResponseSection,
|
|
87
|
+
UnifiedViewModel,
|
|
88
|
+
RichResponseInput,
|
|
89
|
+
PlaceholderInput,
|
|
90
|
+
EditInput,
|
|
91
|
+
} from "./airich/protocol.js";
|
|
92
|
+
export {
|
|
93
|
+
forwardInfo,
|
|
94
|
+
buildContextInfo,
|
|
95
|
+
filterContextInfo,
|
|
96
|
+
ALLOWED_CONTEXT_FIELDS,
|
|
97
|
+
BUILDER_CONTROLLED_CONTEXT_FIELDS,
|
|
98
|
+
} from "./airich/context.js";
|
|
99
|
+
export type { QuoteInfo, AllowedContextInfo } from "./airich/context.js";
|
|
100
|
+
export {
|
|
101
|
+
sendViaZapo,
|
|
102
|
+
sendPlaceholderThenEdit,
|
|
103
|
+
sendAttributes,
|
|
104
|
+
isZapoClient,
|
|
105
|
+
} from "./airich/transport.js";
|
|
106
|
+
export { EXPERIMENTAL_PRIMITIVES } from "./airich/primitives.js";
|
|
107
|
+
export type {
|
|
108
|
+
SourceInput,
|
|
109
|
+
FooterActionItem,
|
|
110
|
+
WidgetItem,
|
|
111
|
+
ProductItem,
|
|
112
|
+
PostItem,
|
|
113
|
+
ReelsItem,
|
|
114
|
+
} from "./airich/primitives.js";
|
|
115
|
+
export type {
|
|
116
|
+
ButtonBuildResult,
|
|
117
|
+
LegacyButtonBuildResult,
|
|
118
|
+
ListBuildResult,
|
|
119
|
+
WrapBotForwardedResult,
|
|
120
|
+
PlaceholderBuildResult,
|
|
121
|
+
EditBuildResult,
|
|
122
|
+
MediaSlotResolution,
|
|
123
|
+
} from "./payloads.js";
|
|
124
|
+
export type {
|
|
125
|
+
ZapoClient,
|
|
126
|
+
ZapoSendOptions,
|
|
127
|
+
ZapoMessageContent,
|
|
128
|
+
ZapoMessageCoordinator,
|
|
129
|
+
ZapoAuthLike,
|
|
130
|
+
ZapoDownloadCapableClient,
|
|
131
|
+
ZapoReactionContent,
|
|
132
|
+
ZapoPollContent,
|
|
133
|
+
MessageSendResult,
|
|
134
|
+
} from "./zapo-client.js";
|
|
135
|
+
export type {
|
|
136
|
+
TextBuildResult,
|
|
137
|
+
LinkPreviewBuildResult,
|
|
138
|
+
ExtendedTextMessagePayload,
|
|
139
|
+
ContactBuildResult,
|
|
140
|
+
ContactMessagePayload,
|
|
141
|
+
AlbumBuildResult,
|
|
142
|
+
AlbumMessagePayload,
|
|
143
|
+
LocationBuildResult,
|
|
144
|
+
LocationMessagePayload,
|
|
145
|
+
MediaBuildResult,
|
|
146
|
+
MediaMessageKind,
|
|
147
|
+
} from "./payloads.js";
|
|
148
|
+
export { mediaSlotToMessage } from "./payloads.js";
|
|
149
|
+
export {
|
|
150
|
+
TextBuilder,
|
|
151
|
+
text,
|
|
152
|
+
LinkPreviewBuilder,
|
|
153
|
+
linkPreview,
|
|
154
|
+
ReactionBuilder,
|
|
155
|
+
reaction,
|
|
156
|
+
ForwardBuilder,
|
|
157
|
+
forward,
|
|
158
|
+
ContactBuilder,
|
|
159
|
+
contact,
|
|
160
|
+
PollBuilder,
|
|
161
|
+
poll,
|
|
162
|
+
MediaBuilder,
|
|
163
|
+
media,
|
|
164
|
+
image,
|
|
165
|
+
video,
|
|
166
|
+
audio,
|
|
167
|
+
document,
|
|
168
|
+
StickerBuilder,
|
|
169
|
+
sticker,
|
|
170
|
+
AlbumBuilder,
|
|
171
|
+
album,
|
|
172
|
+
LocationBuilder,
|
|
173
|
+
location,
|
|
174
|
+
probeWebp,
|
|
175
|
+
buildVcard,
|
|
176
|
+
targetKeyOf,
|
|
177
|
+
targetChatJidOf,
|
|
178
|
+
targetIdOf,
|
|
179
|
+
} from "./message/index.js";
|
|
180
|
+
export type {
|
|
181
|
+
TextConfig,
|
|
182
|
+
LinkPreviewConfig,
|
|
183
|
+
ReactionConfig,
|
|
184
|
+
ForwardConfig,
|
|
185
|
+
ContactConfig,
|
|
186
|
+
PollConfig,
|
|
187
|
+
MediaConfig,
|
|
188
|
+
MediaImageConfig,
|
|
189
|
+
MediaVideoConfig,
|
|
190
|
+
MediaAudioConfig,
|
|
191
|
+
MediaDocumentConfig,
|
|
192
|
+
ImageMediaOptions,
|
|
193
|
+
VideoMediaOptions,
|
|
194
|
+
AudioMediaOptions,
|
|
195
|
+
DocumentMediaOptions,
|
|
196
|
+
ImageMessageConfig,
|
|
197
|
+
VideoMessageConfig,
|
|
198
|
+
AudioMessageConfig,
|
|
199
|
+
DocumentMessageConfig,
|
|
200
|
+
StickerConfig,
|
|
201
|
+
StickerMediaOptions,
|
|
202
|
+
AlbumConfig,
|
|
203
|
+
AlbumMediaItem,
|
|
204
|
+
LocationConfig,
|
|
205
|
+
LinkPreviewKind,
|
|
206
|
+
AlbumChild,
|
|
207
|
+
WebpInfo,
|
|
208
|
+
VcardInput,
|
|
209
|
+
MessageKeyLike,
|
|
210
|
+
MessageTargetLike,
|
|
211
|
+
} from "./message/index.js";
|
|
212
|
+
export {
|
|
213
|
+
installZapoMessage,
|
|
214
|
+
installOnPrototype,
|
|
215
|
+
autoInstallStatus,
|
|
216
|
+
} from "./integration/auto.js";
|
|
217
|
+
export {
|
|
218
|
+
zapoMessageMethods,
|
|
219
|
+
ZAPO_MESSAGE_METHOD_NAMES,
|
|
220
|
+
} from "./integration/methods.js";
|
|
221
|
+
export type { ZapoMessageMethodName } from "./integration/methods.js";
|
|
222
|
+
export type { ZapoMessageClientMethods } from "./integration/augment.js";
|
|
223
|
+
|
|
224
|
+
export const messageKit = (client?: ZapoClient) => ({
|
|
225
|
+
button: () => button(client),
|
|
226
|
+
legacyButton: () => legacyButton(client),
|
|
227
|
+
listMessage: () => listMessage(client),
|
|
228
|
+
airich: (options?: AIRichConstructorOptions) => airich(client, options),
|
|
229
|
+
});
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import type { Button, LegacyButton, ListMessage } from "../btn/builders.js";
|
|
2
|
+
import type {
|
|
3
|
+
ButtonConfig,
|
|
4
|
+
LegacyButtonConfig,
|
|
5
|
+
ListMessageConfig,
|
|
6
|
+
} from "../btn/builders.js";
|
|
7
|
+
import type {
|
|
8
|
+
AIRich,
|
|
9
|
+
AIRichConfig,
|
|
10
|
+
AIRichConstructorOptions,
|
|
11
|
+
AIRichSendOptions,
|
|
12
|
+
} from "../airich/airich.js";
|
|
13
|
+
import type { MessageSendOptions } from "../core/async-send.js";
|
|
14
|
+
import type { MessageSendResult } from "../zapo-client.js";
|
|
15
|
+
import type { TextBuilder, TextConfig } from "../message/text.js";
|
|
16
|
+
import type {
|
|
17
|
+
LinkPreviewBuilder,
|
|
18
|
+
LinkPreviewConfig,
|
|
19
|
+
} from "../message/link-preview.js";
|
|
20
|
+
import type { ReactionBuilder, ReactionConfig } from "../message/reaction.js";
|
|
21
|
+
import type { ForwardBuilder, ForwardConfig } from "../message/forward.js";
|
|
22
|
+
import type { ContactBuilder, ContactConfig } from "../message/contact.js";
|
|
23
|
+
import type { PollBuilder, PollConfig } from "../message/poll.js";
|
|
24
|
+
import type {
|
|
25
|
+
MediaBuilder,
|
|
26
|
+
MediaConfig,
|
|
27
|
+
ImageMessageConfig,
|
|
28
|
+
VideoMessageConfig,
|
|
29
|
+
AudioMessageConfig,
|
|
30
|
+
DocumentMessageConfig,
|
|
31
|
+
} from "../message/media.js";
|
|
32
|
+
import type { StickerBuilder, StickerConfig } from "../message/sticker.js";
|
|
33
|
+
import type { AlbumBuilder, AlbumConfig } from "../message/album.js";
|
|
34
|
+
import type { LocationBuilder, LocationConfig } from "../message/location.js";
|
|
35
|
+
|
|
36
|
+
type SendPromise = Promise<MessageSendResult>;
|
|
37
|
+
|
|
38
|
+
declare module "zapo-js" {
|
|
39
|
+
interface WaClient {
|
|
40
|
+
button(): Button;
|
|
41
|
+
button(
|
|
42
|
+
jid: string,
|
|
43
|
+
config: ButtonConfig,
|
|
44
|
+
options?: MessageSendOptions,
|
|
45
|
+
): SendPromise;
|
|
46
|
+
legacyButton(): LegacyButton;
|
|
47
|
+
legacyButton(
|
|
48
|
+
jid: string,
|
|
49
|
+
config: LegacyButtonConfig,
|
|
50
|
+
options?: MessageSendOptions,
|
|
51
|
+
): SendPromise;
|
|
52
|
+
listMessage(): ListMessage;
|
|
53
|
+
listMessage(
|
|
54
|
+
jid: string,
|
|
55
|
+
config: ListMessageConfig,
|
|
56
|
+
options?: MessageSendOptions,
|
|
57
|
+
): SendPromise;
|
|
58
|
+
airich(options?: AIRichConstructorOptions): AIRich;
|
|
59
|
+
airich(
|
|
60
|
+
jid: string,
|
|
61
|
+
config: AIRichConfig,
|
|
62
|
+
options?: AIRichSendOptions,
|
|
63
|
+
): SendPromise;
|
|
64
|
+
text(): TextBuilder;
|
|
65
|
+
text(
|
|
66
|
+
jid: string,
|
|
67
|
+
config: TextConfig,
|
|
68
|
+
options?: MessageSendOptions,
|
|
69
|
+
): SendPromise;
|
|
70
|
+
reaction(): ReactionBuilder;
|
|
71
|
+
reaction(config: ReactionConfig, options?: MessageSendOptions): SendPromise;
|
|
72
|
+
reaction(
|
|
73
|
+
jid: string,
|
|
74
|
+
config: ReactionConfig,
|
|
75
|
+
options?: MessageSendOptions,
|
|
76
|
+
): SendPromise;
|
|
77
|
+
media(): MediaBuilder;
|
|
78
|
+
media(
|
|
79
|
+
jid: string,
|
|
80
|
+
config: MediaConfig,
|
|
81
|
+
options?: MessageSendOptions,
|
|
82
|
+
): SendPromise;
|
|
83
|
+
image(): MediaBuilder;
|
|
84
|
+
image(
|
|
85
|
+
jid: string,
|
|
86
|
+
config: ImageMessageConfig,
|
|
87
|
+
options?: MessageSendOptions,
|
|
88
|
+
): SendPromise;
|
|
89
|
+
video(): MediaBuilder;
|
|
90
|
+
video(
|
|
91
|
+
jid: string,
|
|
92
|
+
config: VideoMessageConfig,
|
|
93
|
+
options?: MessageSendOptions,
|
|
94
|
+
): SendPromise;
|
|
95
|
+
audio(): MediaBuilder;
|
|
96
|
+
audio(
|
|
97
|
+
jid: string,
|
|
98
|
+
config: AudioMessageConfig,
|
|
99
|
+
options?: MessageSendOptions,
|
|
100
|
+
): SendPromise;
|
|
101
|
+
document(): MediaBuilder;
|
|
102
|
+
document(
|
|
103
|
+
jid: string,
|
|
104
|
+
config: DocumentMessageConfig,
|
|
105
|
+
options?: MessageSendOptions,
|
|
106
|
+
): SendPromise;
|
|
107
|
+
sticker(): StickerBuilder;
|
|
108
|
+
sticker(
|
|
109
|
+
jid: string,
|
|
110
|
+
config: StickerConfig,
|
|
111
|
+
options?: MessageSendOptions,
|
|
112
|
+
): SendPromise;
|
|
113
|
+
contact(): ContactBuilder;
|
|
114
|
+
contact(
|
|
115
|
+
jid: string,
|
|
116
|
+
config: ContactConfig,
|
|
117
|
+
options?: MessageSendOptions,
|
|
118
|
+
): SendPromise;
|
|
119
|
+
poll(): PollBuilder;
|
|
120
|
+
poll(
|
|
121
|
+
jid: string,
|
|
122
|
+
config: PollConfig,
|
|
123
|
+
options?: MessageSendOptions,
|
|
124
|
+
): SendPromise;
|
|
125
|
+
album(): AlbumBuilder;
|
|
126
|
+
album(
|
|
127
|
+
jid: string,
|
|
128
|
+
config: AlbumConfig,
|
|
129
|
+
options?: MessageSendOptions,
|
|
130
|
+
): SendPromise;
|
|
131
|
+
linkPreview(): LinkPreviewBuilder;
|
|
132
|
+
linkPreview(
|
|
133
|
+
jid: string,
|
|
134
|
+
config: LinkPreviewConfig,
|
|
135
|
+
options?: MessageSendOptions,
|
|
136
|
+
): SendPromise;
|
|
137
|
+
forward(): ForwardBuilder;
|
|
138
|
+
forward(
|
|
139
|
+
jid: string,
|
|
140
|
+
config: ForwardConfig,
|
|
141
|
+
options?: MessageSendOptions,
|
|
142
|
+
): SendPromise;
|
|
143
|
+
location(): LocationBuilder;
|
|
144
|
+
location(
|
|
145
|
+
jid: string,
|
|
146
|
+
config: LocationConfig,
|
|
147
|
+
options?: MessageSendOptions,
|
|
148
|
+
): SendPromise;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface ZapoMessageClientMethods {
|
|
153
|
+
button(): Button;
|
|
154
|
+
button(
|
|
155
|
+
jid: string,
|
|
156
|
+
config: ButtonConfig,
|
|
157
|
+
options?: MessageSendOptions,
|
|
158
|
+
): SendPromise;
|
|
159
|
+
legacyButton(): LegacyButton;
|
|
160
|
+
legacyButton(
|
|
161
|
+
jid: string,
|
|
162
|
+
config: LegacyButtonConfig,
|
|
163
|
+
options?: MessageSendOptions,
|
|
164
|
+
): SendPromise;
|
|
165
|
+
listMessage(): ListMessage;
|
|
166
|
+
listMessage(
|
|
167
|
+
jid: string,
|
|
168
|
+
config: ListMessageConfig,
|
|
169
|
+
options?: MessageSendOptions,
|
|
170
|
+
): SendPromise;
|
|
171
|
+
airich(options?: AIRichConstructorOptions): AIRich;
|
|
172
|
+
airich(
|
|
173
|
+
jid: string,
|
|
174
|
+
config: AIRichConfig,
|
|
175
|
+
options?: AIRichSendOptions,
|
|
176
|
+
): SendPromise;
|
|
177
|
+
text(): TextBuilder;
|
|
178
|
+
text(
|
|
179
|
+
jid: string,
|
|
180
|
+
config: TextConfig,
|
|
181
|
+
options?: MessageSendOptions,
|
|
182
|
+
): SendPromise;
|
|
183
|
+
reaction(): ReactionBuilder;
|
|
184
|
+
reaction(config: ReactionConfig, options?: MessageSendOptions): SendPromise;
|
|
185
|
+
reaction(
|
|
186
|
+
jid: string,
|
|
187
|
+
config: ReactionConfig,
|
|
188
|
+
options?: MessageSendOptions,
|
|
189
|
+
): SendPromise;
|
|
190
|
+
media(): MediaBuilder;
|
|
191
|
+
media(
|
|
192
|
+
jid: string,
|
|
193
|
+
config: MediaConfig,
|
|
194
|
+
options?: MessageSendOptions,
|
|
195
|
+
): SendPromise;
|
|
196
|
+
image(): MediaBuilder;
|
|
197
|
+
image(
|
|
198
|
+
jid: string,
|
|
199
|
+
config: ImageMessageConfig,
|
|
200
|
+
options?: MessageSendOptions,
|
|
201
|
+
): SendPromise;
|
|
202
|
+
video(): MediaBuilder;
|
|
203
|
+
video(
|
|
204
|
+
jid: string,
|
|
205
|
+
config: VideoMessageConfig,
|
|
206
|
+
options?: MessageSendOptions,
|
|
207
|
+
): SendPromise;
|
|
208
|
+
audio(): MediaBuilder;
|
|
209
|
+
audio(
|
|
210
|
+
jid: string,
|
|
211
|
+
config: AudioMessageConfig,
|
|
212
|
+
options?: MessageSendOptions,
|
|
213
|
+
): SendPromise;
|
|
214
|
+
document(): MediaBuilder;
|
|
215
|
+
document(
|
|
216
|
+
jid: string,
|
|
217
|
+
config: DocumentMessageConfig,
|
|
218
|
+
options?: MessageSendOptions,
|
|
219
|
+
): SendPromise;
|
|
220
|
+
sticker(): StickerBuilder;
|
|
221
|
+
sticker(
|
|
222
|
+
jid: string,
|
|
223
|
+
config: StickerConfig,
|
|
224
|
+
options?: MessageSendOptions,
|
|
225
|
+
): SendPromise;
|
|
226
|
+
contact(): ContactBuilder;
|
|
227
|
+
contact(
|
|
228
|
+
jid: string,
|
|
229
|
+
config: ContactConfig,
|
|
230
|
+
options?: MessageSendOptions,
|
|
231
|
+
): SendPromise;
|
|
232
|
+
poll(): PollBuilder;
|
|
233
|
+
poll(
|
|
234
|
+
jid: string,
|
|
235
|
+
config: PollConfig,
|
|
236
|
+
options?: MessageSendOptions,
|
|
237
|
+
): SendPromise;
|
|
238
|
+
album(): AlbumBuilder;
|
|
239
|
+
album(
|
|
240
|
+
jid: string,
|
|
241
|
+
config: AlbumConfig,
|
|
242
|
+
options?: MessageSendOptions,
|
|
243
|
+
): SendPromise;
|
|
244
|
+
linkPreview(): LinkPreviewBuilder;
|
|
245
|
+
linkPreview(
|
|
246
|
+
jid: string,
|
|
247
|
+
config: LinkPreviewConfig,
|
|
248
|
+
options?: MessageSendOptions,
|
|
249
|
+
): SendPromise;
|
|
250
|
+
forward(): ForwardBuilder;
|
|
251
|
+
forward(
|
|
252
|
+
jid: string,
|
|
253
|
+
config: ForwardConfig,
|
|
254
|
+
options?: MessageSendOptions,
|
|
255
|
+
): SendPromise;
|
|
256
|
+
location(): LocationBuilder;
|
|
257
|
+
location(
|
|
258
|
+
jid: string,
|
|
259
|
+
config: LocationConfig,
|
|
260
|
+
options?: MessageSendOptions,
|
|
261
|
+
): SendPromise;
|
|
262
|
+
}
|