@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.
- package/CHANGELOG.md +159 -0
- package/LICENSE +20 -0
- package/README.md +532 -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 +38 -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
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
import { pathToFileURL } from "node:url";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
|
|
5
|
+
const avelynaArg = process.argv.find((arg) => arg.startsWith("--avelyna="));
|
|
6
|
+
if (!avelynaArg) {
|
|
7
|
+
console.error(
|
|
8
|
+
"usage: node scripts/compare-golden.mjs --avelyna=<path-to-avelyna-repo>",
|
|
9
|
+
);
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
const avelynaRoot = resolve(avelynaArg.replace("--avelyna=", ""));
|
|
13
|
+
const messageLib = resolve(avelynaRoot, "src/lib/message/index.js");
|
|
14
|
+
if (!existsSync(messageLib)) {
|
|
15
|
+
console.error(`avelyna message library not found at ${messageLib}`);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
process.chdir(avelynaRoot);
|
|
20
|
+
const legacy = await import(pathToFileURL(messageLib));
|
|
21
|
+
const legacyInteractive = await import(
|
|
22
|
+
pathToFileURL(resolve(avelynaRoot, "src/lib/message/interactive.js"))
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
process.chdir(new URL("..", import.meta.url).pathname);
|
|
26
|
+
const modern = await import("@kyyinfinite/zapo-message");
|
|
27
|
+
const modernInteractive =
|
|
28
|
+
await import("@kyyinfinite/zapo-message/interactive.js");
|
|
29
|
+
|
|
30
|
+
const results = [];
|
|
31
|
+
const record = (name, ok, detail) => {
|
|
32
|
+
results.push({ name, ok, detail: detail ?? "" });
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const compare = (name, a, b) => {
|
|
36
|
+
const sa = JSON.stringify(a);
|
|
37
|
+
const sb = JSON.stringify(b);
|
|
38
|
+
record(name, sa === sb, sa === sb ? "" : `legacy=${sa} modern=${sb}`);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const noopLegacy = {
|
|
42
|
+
message: {
|
|
43
|
+
async send() {
|
|
44
|
+
return { id: "X" };
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
const noopModern = {
|
|
49
|
+
message: {
|
|
50
|
+
async send() {
|
|
51
|
+
return { id: "X" };
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
{
|
|
57
|
+
const legacyPayload = await legacy
|
|
58
|
+
.button(noopLegacy)
|
|
59
|
+
.title("Judul")
|
|
60
|
+
.body("Isi")
|
|
61
|
+
.footer("Footer")
|
|
62
|
+
.quick_reply("QR", "cmd qr")
|
|
63
|
+
.cta_url("Buka", "https://example.com/path?x=1")
|
|
64
|
+
.cta_copy("Salin", "KODE123")
|
|
65
|
+
.cta_call("Telepon", "+628123456789")
|
|
66
|
+
.send_location("Kirim lokasi")
|
|
67
|
+
.single_select("Pilih", [
|
|
68
|
+
{
|
|
69
|
+
title: "Utama",
|
|
70
|
+
rows: [{ id: "row1", title: "Baris Satu", description: "desc" }],
|
|
71
|
+
},
|
|
72
|
+
])
|
|
73
|
+
.bottom_sheet({ limit: 2, listTitle: "Daftar", buttonTitle: "Buka" })
|
|
74
|
+
.limited_time_offer({ copyCode: "OFFER", expiresIn: 3600 })
|
|
75
|
+
.build();
|
|
76
|
+
|
|
77
|
+
const modernPayload = await modern
|
|
78
|
+
.button(noopModern)
|
|
79
|
+
.title("Judul")
|
|
80
|
+
.body("Isi")
|
|
81
|
+
.footer("Footer")
|
|
82
|
+
.quick_reply("QR", "cmd qr")
|
|
83
|
+
.cta_url("Buka", "https://example.com/path?x=1")
|
|
84
|
+
.cta_copy("Salin", "KODE123")
|
|
85
|
+
.cta_call("Telepon", "+628123456789")
|
|
86
|
+
.send_location("Kirim lokasi")
|
|
87
|
+
.single_select("Pilih", [
|
|
88
|
+
{
|
|
89
|
+
title: "Utama",
|
|
90
|
+
rows: [{ id: "row1", title: "Baris Satu", description: "desc" }],
|
|
91
|
+
},
|
|
92
|
+
])
|
|
93
|
+
.bottom_sheet({ limit: 2, listTitle: "Daftar", buttonTitle: "Buka" })
|
|
94
|
+
.limited_time_offer({ copyCode: "OFFER", expiresIn: 3600 })
|
|
95
|
+
.build();
|
|
96
|
+
|
|
97
|
+
const stripVolatile = (payload) => {
|
|
98
|
+
const flow = payload.interactiveMessage.nativeFlowMessage;
|
|
99
|
+
if (flow.messageParamsJson) {
|
|
100
|
+
const params = JSON.parse(flow.messageParamsJson);
|
|
101
|
+
if (params.limited_time_offer) {
|
|
102
|
+
delete params.limited_time_offer.expiration_time;
|
|
103
|
+
flow.messageParamsJson = JSON.stringify(params);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return payload;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
compare(
|
|
110
|
+
"button: interactiveMessage payload (buttons, params, messageParamsJson)",
|
|
111
|
+
stripVolatile(legacyPayload),
|
|
112
|
+
stripVolatile(modernPayload),
|
|
113
|
+
);
|
|
114
|
+
compare(
|
|
115
|
+
"button: buttonParamsJson string-for-string",
|
|
116
|
+
legacyPayload.interactiveMessage.nativeFlowMessage.buttons.map(
|
|
117
|
+
(b) => b.buttonParamsJson,
|
|
118
|
+
),
|
|
119
|
+
modernPayload.interactiveMessage.nativeFlowMessage.buttons.map(
|
|
120
|
+
(b) => b.buttonParamsJson,
|
|
121
|
+
),
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
{
|
|
126
|
+
const legacyLegacy = await legacy
|
|
127
|
+
.legacyButton(noopLegacy)
|
|
128
|
+
.title("Judul Legacy")
|
|
129
|
+
.body("Konten")
|
|
130
|
+
.footer("Footer")
|
|
131
|
+
.button("b1", "Satu")
|
|
132
|
+
.button("b2", "Dua")
|
|
133
|
+
.build();
|
|
134
|
+
|
|
135
|
+
const modernLegacy = await modern
|
|
136
|
+
.legacyButton(noopModern)
|
|
137
|
+
.title("Judul Legacy")
|
|
138
|
+
.body("Konten")
|
|
139
|
+
.footer("Footer")
|
|
140
|
+
.button("b1", "Satu")
|
|
141
|
+
.button("b2", "Dua")
|
|
142
|
+
.build();
|
|
143
|
+
|
|
144
|
+
compare("legacyButton: buttonsMessage payload", legacyLegacy, modernLegacy);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
{
|
|
148
|
+
const legacyList = legacy
|
|
149
|
+
.listMessage(noopLegacy)
|
|
150
|
+
.title("Menu")
|
|
151
|
+
.body("Deskripsi")
|
|
152
|
+
.buttonText("Pilih")
|
|
153
|
+
.footer("Footer")
|
|
154
|
+
.section("Utama", [{ id: "r1", title: "Baris", description: "deskripsi" }])
|
|
155
|
+
.build();
|
|
156
|
+
|
|
157
|
+
const modernList = modern
|
|
158
|
+
.listMessage(noopModern)
|
|
159
|
+
.title("Menu")
|
|
160
|
+
.body("Deskripsi")
|
|
161
|
+
.buttonText("Pilih")
|
|
162
|
+
.footer("Footer")
|
|
163
|
+
.section("Utama", [{ id: "r1", title: "Baris", description: "deskripsi" }])
|
|
164
|
+
.build();
|
|
165
|
+
|
|
166
|
+
compare("listMessage: classic payload", legacyList, modernList);
|
|
167
|
+
|
|
168
|
+
const legacyNative = legacy
|
|
169
|
+
.listMessage(noopLegacy)
|
|
170
|
+
.title("Menu")
|
|
171
|
+
.body("Deskripsi")
|
|
172
|
+
.buttonText("Pilih")
|
|
173
|
+
.footer("Footer")
|
|
174
|
+
.section("Utama", [{ id: "r1", title: "Baris", description: "deskripsi" }])
|
|
175
|
+
.toNativeFlow();
|
|
176
|
+
|
|
177
|
+
const modernNative = modern
|
|
178
|
+
.listMessage(noopModern)
|
|
179
|
+
.title("Menu")
|
|
180
|
+
.body("Deskripsi")
|
|
181
|
+
.buttonText("Pilih")
|
|
182
|
+
.footer("Footer")
|
|
183
|
+
.section("Utama", [{ id: "r1", title: "Baris", description: "deskripsi" }])
|
|
184
|
+
.toNativeFlow();
|
|
185
|
+
|
|
186
|
+
compare("listMessage: native flow payload", legacyNative, modernNative);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
{
|
|
190
|
+
const buildRich = (impl, client) =>
|
|
191
|
+
impl
|
|
192
|
+
.airich(client)
|
|
193
|
+
.text("unicode ☕ café — [link](https://example.com)")
|
|
194
|
+
.code("javascript", 'const x = "☕"')
|
|
195
|
+
.table([
|
|
196
|
+
["H1", "H2"],
|
|
197
|
+
["a", "b"],
|
|
198
|
+
])
|
|
199
|
+
.suggest(["satu", "dua"])
|
|
200
|
+
.footer("catatan")
|
|
201
|
+
.build({ submessages: false });
|
|
202
|
+
|
|
203
|
+
const legacyRich = buildRich(legacy, noopLegacy);
|
|
204
|
+
const modernRich = buildRich(modern, noopModern);
|
|
205
|
+
|
|
206
|
+
const decode = (payload) =>
|
|
207
|
+
JSON.parse(
|
|
208
|
+
Buffer.from(
|
|
209
|
+
payload.botForwardedMessage.message.richResponseMessage.unifiedResponse
|
|
210
|
+
.data,
|
|
211
|
+
).toString("utf8"),
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
const legacyDecoded = decode(legacyRich);
|
|
215
|
+
const modernDecoded = decode(modernRich);
|
|
216
|
+
|
|
217
|
+
delete legacyDecoded.response_id;
|
|
218
|
+
delete modernDecoded.response_id;
|
|
219
|
+
compare(
|
|
220
|
+
"airich: unified response sections (text/code/table/suggest/footer)",
|
|
221
|
+
legacyDecoded,
|
|
222
|
+
modernDecoded,
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
compare(
|
|
226
|
+
"airich: submessages",
|
|
227
|
+
legacyRich.botForwardedMessage.message.richResponseMessage.submessages,
|
|
228
|
+
modernRich.botForwardedMessage.message.richResponseMessage.submessages,
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
compare(
|
|
232
|
+
"airich: contextInfo",
|
|
233
|
+
legacyRich.botForwardedMessage.message.richResponseMessage.contextInfo,
|
|
234
|
+
modernRich.botForwardedMessage.message.richResponseMessage.contextInfo,
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
const legacyBytes =
|
|
238
|
+
legacyRich.botForwardedMessage.message.richResponseMessage.unifiedResponse
|
|
239
|
+
.data;
|
|
240
|
+
const modernBytes =
|
|
241
|
+
modernRich.botForwardedMessage.message.richResponseMessage.unifiedResponse
|
|
242
|
+
.data;
|
|
243
|
+
const legacyText = Buffer.from(legacyBytes).toString("utf8");
|
|
244
|
+
const modernText = Buffer.from(modernBytes).toString("utf8");
|
|
245
|
+
const legacyPatched = legacyText.replace(
|
|
246
|
+
/"response_id":"[0-9a-f-]{36}"/,
|
|
247
|
+
'"response_id":"FIXED"',
|
|
248
|
+
);
|
|
249
|
+
const modernPatched = modernText.replace(
|
|
250
|
+
/"response_id":"[0-9a-f-]{36}"/,
|
|
251
|
+
'"response_id":"FIXED"',
|
|
252
|
+
);
|
|
253
|
+
record(
|
|
254
|
+
"airich: unified response bytes byte-for-byte (response_id fixed)",
|
|
255
|
+
legacyPatched === modernPatched,
|
|
256
|
+
legacyPatched === modernPatched
|
|
257
|
+
? ""
|
|
258
|
+
: `legacy=${legacyPatched} modern=${modernPatched}`,
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
{
|
|
263
|
+
const legacyPlaceholder = new legacy.AIRich(noopLegacy, {
|
|
264
|
+
botJid: "123@bot",
|
|
265
|
+
});
|
|
266
|
+
legacyPlaceholder.context({
|
|
267
|
+
mentionedJid: ["6281@s.whatsapp.net"],
|
|
268
|
+
expiration: 7776000,
|
|
269
|
+
});
|
|
270
|
+
const legacyP = legacyPlaceholder.buildPlaceholder();
|
|
271
|
+
|
|
272
|
+
const modernPlaceholder = new modern.AIRich(noopModern, {
|
|
273
|
+
botJid: "123@bot",
|
|
274
|
+
});
|
|
275
|
+
modernPlaceholder.context({
|
|
276
|
+
mentionedJid: ["6281@s.whatsapp.net"],
|
|
277
|
+
expiration: 7776000,
|
|
278
|
+
});
|
|
279
|
+
const modernP = modernPlaceholder.buildPlaceholder();
|
|
280
|
+
|
|
281
|
+
const stripSecret = (p) => {
|
|
282
|
+
const copy = JSON.parse(
|
|
283
|
+
JSON.stringify(p, (k, v) => (k === "messageSecret" ? "RANDOM" : v)),
|
|
284
|
+
);
|
|
285
|
+
const rich = copy.botForwardedMessage.message.richResponseMessage;
|
|
286
|
+
const text = Buffer.from(rich.unifiedResponse.data).toString("utf8");
|
|
287
|
+
rich.unifiedResponse.data = Buffer.from(
|
|
288
|
+
text.replace(/"response_id":"[0-9a-f-]{36}"/, '"response_id":"FIXED"'),
|
|
289
|
+
);
|
|
290
|
+
return copy;
|
|
291
|
+
};
|
|
292
|
+
compare(
|
|
293
|
+
"airich: placeholder payload (messageSecret + response_id masked)",
|
|
294
|
+
stripSecret(legacyP),
|
|
295
|
+
stripSecret(modernP),
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
{
|
|
300
|
+
const legacyEdit = legacy
|
|
301
|
+
.airich(noopLegacy)
|
|
302
|
+
.text("edit ini")
|
|
303
|
+
.buildEdit("6281@s.whatsapp.net", "PLACEHOLDER", { submessages: false });
|
|
304
|
+
const modernEdit = modern
|
|
305
|
+
.airich(noopModern)
|
|
306
|
+
.text("edit ini")
|
|
307
|
+
.buildEdit("6281@s.whatsapp.net", "PLACEHOLDER", { submessages: false });
|
|
308
|
+
|
|
309
|
+
const stripRichId = (payload) => {
|
|
310
|
+
const copy = JSON.parse(JSON.stringify(payload));
|
|
311
|
+
const rich =
|
|
312
|
+
copy.botForwardedMessage.message.protocolMessage.editedMessage
|
|
313
|
+
.botForwardedMessage.message.richResponseMessage;
|
|
314
|
+
const text = Buffer.from(rich.unifiedResponse.data).toString("utf8");
|
|
315
|
+
rich.unifiedResponse.data = Buffer.from(
|
|
316
|
+
text.replace(/"response_id":"[0-9a-f-]{36}"/, '"response_id":"FIXED"'),
|
|
317
|
+
);
|
|
318
|
+
return copy;
|
|
319
|
+
};
|
|
320
|
+
compare(
|
|
321
|
+
"airich: protocol edit payload (type 14, key, editedMessage)",
|
|
322
|
+
stripRichId(legacyEdit),
|
|
323
|
+
stripRichId(modernEdit),
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
{
|
|
328
|
+
const legacyTable = legacy.toTable([["A", "B"], ["c"]]);
|
|
329
|
+
const modernTable = modern.toTable([["A", "B"], ["c"]]);
|
|
330
|
+
compare("toTable: unified + legacy rows", legacyTable, modernTable);
|
|
331
|
+
|
|
332
|
+
const legacyInline = legacy.parseInline(
|
|
333
|
+
"lihat [web](https://a.com) ref [](https://b.com) [E|10]<https://c.com/i.png>",
|
|
334
|
+
);
|
|
335
|
+
const modernInline = modern.parseInline(
|
|
336
|
+
"lihat [web](https://a.com) ref [](https://b.com) [E|10]<https://c.com/i.png>",
|
|
337
|
+
);
|
|
338
|
+
compare("parseInline: entities + tags", legacyInline, modernInline);
|
|
339
|
+
|
|
340
|
+
const legacyTokens = legacy.tokenizeCode(
|
|
341
|
+
'=> conn.relayMessage(m.chat, { extendedTextMessage: { text: "x" } }, {})\nconst a = 1 // note',
|
|
342
|
+
"javascript",
|
|
343
|
+
);
|
|
344
|
+
const modernTokens = modern.tokenizeCode(
|
|
345
|
+
'=> conn.relayMessage(m.chat, { extendedTextMessage: { text: "x" } }, {})\nconst a = 1 // note',
|
|
346
|
+
"javascript",
|
|
347
|
+
);
|
|
348
|
+
compare("tokenizeCode: tokens", legacyTokens, modernTokens);
|
|
349
|
+
|
|
350
|
+
compare(
|
|
351
|
+
"layout: Single",
|
|
352
|
+
legacy.layout("Single", { text: "x" }),
|
|
353
|
+
modern.layout("Single", { text: "x" }),
|
|
354
|
+
);
|
|
355
|
+
compare(
|
|
356
|
+
"layout: HScroll + extra",
|
|
357
|
+
legacy.layout("HScroll", [{ a: 1 }], {
|
|
358
|
+
__typename: "GenAIUnifiedResponseSection",
|
|
359
|
+
}),
|
|
360
|
+
modern.layout("HScroll", [{ a: 1 }], {
|
|
361
|
+
__typename: "GenAIUnifiedResponseSection",
|
|
362
|
+
}),
|
|
363
|
+
);
|
|
364
|
+
compare(
|
|
365
|
+
"forwardInfo",
|
|
366
|
+
legacy.forwardInfo("1@bot"),
|
|
367
|
+
modern.forwardInfo("1@bot"),
|
|
368
|
+
);
|
|
369
|
+
compare(
|
|
370
|
+
"buildContextInfo",
|
|
371
|
+
legacy.buildContextInfo({
|
|
372
|
+
botJid: "1@bot",
|
|
373
|
+
quote: null,
|
|
374
|
+
contextInfo: { expiration: 1 },
|
|
375
|
+
}),
|
|
376
|
+
modern.buildContextInfo({
|
|
377
|
+
botJid: "1@bot",
|
|
378
|
+
quote: null,
|
|
379
|
+
contextInfo: { expiration: 1 },
|
|
380
|
+
}),
|
|
381
|
+
);
|
|
382
|
+
compare(
|
|
383
|
+
"sendAttributes",
|
|
384
|
+
legacy.sendAttributes({
|
|
385
|
+
additionalAttributes: { ephemerality: "ephemeral" },
|
|
386
|
+
}),
|
|
387
|
+
modern.sendAttributes({
|
|
388
|
+
additionalAttributes: { ephemerality: "ephemeral" },
|
|
389
|
+
}),
|
|
390
|
+
);
|
|
391
|
+
compare(
|
|
392
|
+
"stringifyEscaped",
|
|
393
|
+
legacy.stringifyEscaped({ k: "café ☕" }),
|
|
394
|
+
modern.stringifyEscaped({ k: "café ☕" }),
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
{
|
|
399
|
+
const buttonsResponse = {
|
|
400
|
+
buttonsResponseMessage: {
|
|
401
|
+
selectedButtonId: "menu tools",
|
|
402
|
+
selectedDisplayText: "Tools",
|
|
403
|
+
},
|
|
404
|
+
};
|
|
405
|
+
const listResponse = {
|
|
406
|
+
listResponseMessage: {
|
|
407
|
+
title: "T",
|
|
408
|
+
singleSelectReply: { selectedRowId: "menu owner" },
|
|
409
|
+
},
|
|
410
|
+
};
|
|
411
|
+
const nativeFlow = {
|
|
412
|
+
interactiveResponseMessage: {
|
|
413
|
+
nativeFlowResponseMessage: {
|
|
414
|
+
name: "quick_reply",
|
|
415
|
+
paramsJson: JSON.stringify({ display_text: "OK", id: "menu ok" }),
|
|
416
|
+
},
|
|
417
|
+
},
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
const legacyExtract = (message) =>
|
|
421
|
+
legacyInteractive.extractInteractiveResponse(message);
|
|
422
|
+
const modernExtract = (message) =>
|
|
423
|
+
modernInteractive.extractInteractiveResponse(message);
|
|
424
|
+
|
|
425
|
+
compare(
|
|
426
|
+
"interactive: buttonsResponseMessage",
|
|
427
|
+
legacyExtract(buttonsResponse),
|
|
428
|
+
modernExtract(buttonsResponse),
|
|
429
|
+
);
|
|
430
|
+
compare(
|
|
431
|
+
"interactive: listResponseMessage",
|
|
432
|
+
legacyExtract(listResponse),
|
|
433
|
+
modernExtract(listResponse),
|
|
434
|
+
);
|
|
435
|
+
compare(
|
|
436
|
+
"interactive: nativeFlow",
|
|
437
|
+
legacyExtract(nativeFlow),
|
|
438
|
+
modernExtract(nativeFlow),
|
|
439
|
+
);
|
|
440
|
+
compare(
|
|
441
|
+
"interactive: plain message",
|
|
442
|
+
legacyExtract({ conversation: "halo" }),
|
|
443
|
+
modernExtract({ conversation: "halo" }),
|
|
444
|
+
);
|
|
445
|
+
compare(
|
|
446
|
+
"interactive: envelope",
|
|
447
|
+
legacyExtract({ ephemeralMessage: { message: buttonsResponse } }),
|
|
448
|
+
modernExtract({ ephemeralMessage: { message: buttonsResponse } }),
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
const failures = results.filter((r) => !r.ok);
|
|
453
|
+
for (const result of results) {
|
|
454
|
+
console.log(
|
|
455
|
+
`${result.ok ? "MATCH" : "DIFF "} ${result.name}${result.ok ? "" : ` :: ${result.detail}`}`,
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
console.log(
|
|
459
|
+
`\ngolden comparison: ${results.length - failures.length}/${results.length} match, ${failures.length} differ`,
|
|
460
|
+
);
|
|
461
|
+
if (failures.length > 0) process.exit(1);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { createStore, WaClient } from "zapo-js";
|
|
2
|
+
import "../dist/index.js";
|
|
3
|
+
|
|
4
|
+
const store = createStore({});
|
|
5
|
+
const client = new WaClient({ store, sessionId: "smoke" });
|
|
6
|
+
|
|
7
|
+
const checks = [];
|
|
8
|
+
checks.push(["button", typeof client.button]);
|
|
9
|
+
checks.push(["legacyButton", typeof client.legacyButton]);
|
|
10
|
+
checks.push(["listMessage", typeof client.listMessage]);
|
|
11
|
+
checks.push(["airich", typeof client.airich]);
|
|
12
|
+
checks.push(["text", typeof client.text]);
|
|
13
|
+
checks.push(["reaction", typeof client.reaction]);
|
|
14
|
+
checks.push(["media", typeof client.media]);
|
|
15
|
+
checks.push(["sticker", typeof client.sticker]);
|
|
16
|
+
checks.push(["contact", typeof client.contact]);
|
|
17
|
+
checks.push(["poll", typeof client.poll]);
|
|
18
|
+
checks.push(["album", typeof client.album]);
|
|
19
|
+
checks.push(["linkPreview", typeof client.linkPreview]);
|
|
20
|
+
checks.push(["forward", typeof client.forward]);
|
|
21
|
+
|
|
22
|
+
for (const [name, kind] of checks) {
|
|
23
|
+
console.log(name, "=", kind);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const b = client.text().body("halo");
|
|
27
|
+
const payload = b.build();
|
|
28
|
+
console.log("text payload:", JSON.stringify(payload));
|
|
29
|
+
|
|
30
|
+
const second = new WaClient({ store, sessionId: "smoke2" });
|
|
31
|
+
console.log("second client text:", typeof second.text);
|
|
32
|
+
|
|
33
|
+
const enumerated = Object.getOwnPropertyNames(Object.getPrototypeOf(client))
|
|
34
|
+
.filter((n) => n !== "constructor")
|
|
35
|
+
.sort();
|
|
36
|
+
console.log(
|
|
37
|
+
"prototype methods sample:",
|
|
38
|
+
enumerated.filter((n) => ["button", "text", "poll", "forward"].includes(n)),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const reactionPayload = client
|
|
42
|
+
.reaction()
|
|
43
|
+
.target({
|
|
44
|
+
key: { remoteJid: "6281@s.whatsapp.net", id: "ABC", fromMe: false },
|
|
45
|
+
})
|
|
46
|
+
.emoji("🔥")
|
|
47
|
+
.build();
|
|
48
|
+
console.log("reaction payload:", JSON.stringify(reactionPayload));
|
|
49
|
+
|
|
50
|
+
const pollPayload = client.poll().question("Pilih").options(["A", "B"]).build();
|
|
51
|
+
console.log("poll payload:", JSON.stringify(pollPayload));
|
|
52
|
+
|
|
53
|
+
const contactPayload = client
|
|
54
|
+
.contact()
|
|
55
|
+
.name("Budi")
|
|
56
|
+
.phone("+628123456789")
|
|
57
|
+
.build();
|
|
58
|
+
console.log("contact payload:", JSON.stringify(contactPayload));
|
|
59
|
+
|
|
60
|
+
const forwardPayload = client
|
|
61
|
+
.forward()
|
|
62
|
+
.message({ message: { conversation: "hai" } })
|
|
63
|
+
.build();
|
|
64
|
+
console.log("forward payload:", JSON.stringify(forwardPayload));
|
|
65
|
+
|
|
66
|
+
const linkPayload = client
|
|
67
|
+
.linkPreview()
|
|
68
|
+
.body("kunjungi https://example.com ya")
|
|
69
|
+
.title("Contoh")
|
|
70
|
+
.build();
|
|
71
|
+
console.log("linkPreview payload:", JSON.stringify(linkPayload));
|
|
72
|
+
|
|
73
|
+
await client.disconnect().catch(() => {});
|
|
74
|
+
await second.disconnect().catch(() => {});
|
|
75
|
+
console.log("SMOKE OK");
|