@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,406 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
AIRich,
|
|
6
|
+
airich,
|
|
7
|
+
decodeUnifiedResponse,
|
|
8
|
+
ZWSP,
|
|
9
|
+
} from "@kyyinfinite/zapo-message";
|
|
10
|
+
import { asClient, L, A } from "./helpers.js";
|
|
11
|
+
|
|
12
|
+
const makeClient = () => {
|
|
13
|
+
const sends: { jid?: unknown; content?: unknown; options?: unknown }[] = [];
|
|
14
|
+
return {
|
|
15
|
+
sends,
|
|
16
|
+
client: asClient({
|
|
17
|
+
message: {
|
|
18
|
+
send: async (jid: unknown, content: unknown, options: unknown) => {
|
|
19
|
+
sends.push({ jid, content, options });
|
|
20
|
+
return { id: `GOLDEN_${sends.length}`, attempts: 1, ack: {} };
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const richOf = (payload: unknown): Record<string, unknown> =>
|
|
28
|
+
L(L(L(payload).botForwardedMessage).message).richResponseMessage as Record<
|
|
29
|
+
string,
|
|
30
|
+
unknown
|
|
31
|
+
>;
|
|
32
|
+
|
|
33
|
+
const dataOf = (payload: unknown): Uint8Array =>
|
|
34
|
+
L(L(richOf(payload)).unifiedResponse).data as unknown as Uint8Array;
|
|
35
|
+
|
|
36
|
+
const FIXTURE_PLACEHOLDER = {
|
|
37
|
+
response_id: "dc8a253b-c1ad-47bc-bb14-3670489f418c",
|
|
38
|
+
sections: [
|
|
39
|
+
{
|
|
40
|
+
view_model: {
|
|
41
|
+
primitive: { text: "", __typename: "GenAIMarkdownTextUXPrimitive" },
|
|
42
|
+
__typename: "GenAISingleLayoutViewModel",
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const FIXTURE_PLACEHOLDER_CONTEXT = {
|
|
49
|
+
mentionedJid: [],
|
|
50
|
+
groupMentions: [],
|
|
51
|
+
statusAttributions: [],
|
|
52
|
+
forwardingScore: 1,
|
|
53
|
+
isForwarded: true,
|
|
54
|
+
expiration: 7776000,
|
|
55
|
+
ephemeralSettingTimestamp: 1773527159,
|
|
56
|
+
disappearingMode: { initiator: 1, trigger: 2, initiatedByMe: true },
|
|
57
|
+
forwardedAiBotMessageInfo: { botJid: "123456789012345@bot" },
|
|
58
|
+
forwardOrigin: 4,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const FIXTURE_EDIT_SECTIONS = [
|
|
62
|
+
{
|
|
63
|
+
view_model: {
|
|
64
|
+
primitive: {
|
|
65
|
+
text: "ini tabel rekomendasi film 3 kolom x 3 baris:",
|
|
66
|
+
__typename: "GenAIMarkdownTextUXPrimitive",
|
|
67
|
+
},
|
|
68
|
+
__typename: "GenAISingleLayoutViewModel",
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
view_model: {
|
|
73
|
+
primitive: {
|
|
74
|
+
rows: [
|
|
75
|
+
{
|
|
76
|
+
is_header: true,
|
|
77
|
+
cells: ["**Judul Film**", "**Genre**", "**Rating**"],
|
|
78
|
+
markdown_cells: [
|
|
79
|
+
{ text: "**Judul Film**" },
|
|
80
|
+
{ text: "**Genre**" },
|
|
81
|
+
{ text: "**Rating**" },
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
is_header: false,
|
|
86
|
+
cells: ["Interstellar", "Sci-Fi", "9.0/10"],
|
|
87
|
+
markdown_cells: [
|
|
88
|
+
{ text: "Interstellar" },
|
|
89
|
+
{ text: "Sci-Fi" },
|
|
90
|
+
{ text: "9.0/10" },
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
is_header: false,
|
|
95
|
+
cells: ["Inception", "Thriller", "8.8/10"],
|
|
96
|
+
markdown_cells: [
|
|
97
|
+
{ text: "Inception" },
|
|
98
|
+
{ text: "Thriller" },
|
|
99
|
+
{ text: "8.8/10" },
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
is_header: false,
|
|
104
|
+
cells: ["The Martian", "Adventure", "8.5/10"],
|
|
105
|
+
markdown_cells: [
|
|
106
|
+
{ text: "The Martian" },
|
|
107
|
+
{ text: "Adventure" },
|
|
108
|
+
{ text: "8.5/10" },
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
__typename: "GenATableUXPrimitive",
|
|
113
|
+
},
|
|
114
|
+
__typename: "GenAISingleLayoutViewModel",
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
view_model: {
|
|
119
|
+
primitive: {
|
|
120
|
+
text: "Tabel ini berisi beberapa film dengan genre dan rating masing-masing.",
|
|
121
|
+
__typename: "GenAIMarkdownTextUXPrimitive",
|
|
122
|
+
},
|
|
123
|
+
__typename: "GenAISingleLayoutViewModel",
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
];
|
|
127
|
+
|
|
128
|
+
const FIXTURE_EDIT_CONTEXT = {
|
|
129
|
+
forwardingScore: 1,
|
|
130
|
+
isForwarded: true,
|
|
131
|
+
forwardOrigin: 4,
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const UUID_RE =
|
|
135
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
136
|
+
|
|
137
|
+
test("golden: placeholder mengikuti payload botf.js msg1 (outer wrapper + nested structure)", () => {
|
|
138
|
+
const { client } = makeClient();
|
|
139
|
+
const builder = new AIRich(client, { botJid: "123456789012345@bot" });
|
|
140
|
+
builder.context({
|
|
141
|
+
mentionedJid: [],
|
|
142
|
+
groupMentions: [],
|
|
143
|
+
statusAttributions: [],
|
|
144
|
+
expiration: 7776000,
|
|
145
|
+
ephemeralSettingTimestamp: 1773527159,
|
|
146
|
+
disappearingMode: {
|
|
147
|
+
initiator: 1,
|
|
148
|
+
trigger: 2,
|
|
149
|
+
initiatedByMe: true,
|
|
150
|
+
} as never,
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const payload = builder.buildPlaceholder();
|
|
154
|
+
|
|
155
|
+
assert.deepEqual(
|
|
156
|
+
Object.keys(payload).sort(),
|
|
157
|
+
["botForwardedMessage", "messageContextInfo"],
|
|
158
|
+
"outer wrapper: messageContextInfo + botForwardedMessage",
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const message = L(L(payload).botForwardedMessage).message as Record<
|
|
162
|
+
string,
|
|
163
|
+
unknown
|
|
164
|
+
>;
|
|
165
|
+
assert.deepEqual(Object.keys(message), ["richResponseMessage"]);
|
|
166
|
+
const rr = L(message).richResponseMessage;
|
|
167
|
+
|
|
168
|
+
assert.deepEqual(Object.keys(L(rr)).sort(), [
|
|
169
|
+
"contextInfo",
|
|
170
|
+
"messageType",
|
|
171
|
+
"submessages",
|
|
172
|
+
"unifiedResponse",
|
|
173
|
+
]);
|
|
174
|
+
assert.equal(L(rr).messageType, 1);
|
|
175
|
+
assert.deepEqual(L(rr).submessages, [{ messageType: 2, messageText: ZWSP }]);
|
|
176
|
+
assert.deepEqual(L(rr).contextInfo, FIXTURE_PLACEHOLDER_CONTEXT);
|
|
177
|
+
|
|
178
|
+
assert.ok(L(L(rr).unifiedResponse).data instanceof Uint8Array);
|
|
179
|
+
const decoded = decodeUnifiedResponse(dataOf(payload)) as {
|
|
180
|
+
response_id: string;
|
|
181
|
+
sections: unknown[];
|
|
182
|
+
};
|
|
183
|
+
assert.match(decoded.response_id, UUID_RE);
|
|
184
|
+
assert.deepEqual(decoded.sections, FIXTURE_PLACEHOLDER.sections);
|
|
185
|
+
|
|
186
|
+
assert.equal(payload.messageContextInfo.deviceListMetadataVersion, 2);
|
|
187
|
+
assert.ok(payload.messageContextInfo.messageSecret instanceof Uint8Array);
|
|
188
|
+
assert.equal(payload.messageContextInfo.messageSecret.length, 32);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test("golden: protocol edit mengikuti payload botf.js (key + type 14 + editedMessage)", () => {
|
|
192
|
+
const { client } = makeClient();
|
|
193
|
+
const builder = airich(client)
|
|
194
|
+
.text("ini tabel rekomendasi film 3 kolom x 3 baris:")
|
|
195
|
+
.table([
|
|
196
|
+
["**Judul Film**", "**Genre**", "**Rating**"],
|
|
197
|
+
["Interstellar", "Sci-Fi", "9.0/10"],
|
|
198
|
+
["Inception", "Thriller", "8.8/10"],
|
|
199
|
+
["The Martian", "Adventure", "8.5/10"],
|
|
200
|
+
])
|
|
201
|
+
.text(
|
|
202
|
+
"Tabel ini berisi beberapa film dengan genre dan rating masing-masing.",
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
const payload = builder.buildEdit(
|
|
206
|
+
"62812036341183@g.us",
|
|
207
|
+
"GOLDEN_PLACEHOLDER_ID",
|
|
208
|
+
{ submessages: false },
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
const message = L(L(payload).botForwardedMessage).message as Record<
|
|
212
|
+
string,
|
|
213
|
+
unknown
|
|
214
|
+
>;
|
|
215
|
+
assert.deepEqual(Object.keys(message), ["protocolMessage"]);
|
|
216
|
+
|
|
217
|
+
const protoMessage = L(message).protocolMessage;
|
|
218
|
+
assert.deepEqual(L(protoMessage).key, {
|
|
219
|
+
remoteJid: "62812036341183@g.us",
|
|
220
|
+
fromMe: true,
|
|
221
|
+
id: "GOLDEN_PLACEHOLDER_ID",
|
|
222
|
+
});
|
|
223
|
+
assert.equal(L(protoMessage).type, 14);
|
|
224
|
+
|
|
225
|
+
const editedMessage = L(L(protoMessage).editedMessage).botForwardedMessage;
|
|
226
|
+
const editedRich = L(L(editedMessage).message).richResponseMessage;
|
|
227
|
+
assert.deepEqual(Object.keys(L(editedRich)).sort(), [
|
|
228
|
+
"contextInfo",
|
|
229
|
+
"messageType",
|
|
230
|
+
"submessages",
|
|
231
|
+
"unifiedResponse",
|
|
232
|
+
]);
|
|
233
|
+
assert.equal(L(editedRich).messageType, 1);
|
|
234
|
+
assert.deepEqual(
|
|
235
|
+
L(editedRich).submessages,
|
|
236
|
+
[],
|
|
237
|
+
"eksperimen botf memakai submessages kosong untuk edit",
|
|
238
|
+
);
|
|
239
|
+
assert.deepEqual(L(editedRich).contextInfo, FIXTURE_EDIT_CONTEXT);
|
|
240
|
+
|
|
241
|
+
const decoded = decodeUnifiedResponse(
|
|
242
|
+
L(L(editedRich).unifiedResponse).data as unknown as Uint8Array,
|
|
243
|
+
) as { response_id: string; sections: unknown[] };
|
|
244
|
+
assert.match(decoded.response_id, UUID_RE);
|
|
245
|
+
assert.deepEqual(decoded.sections, FIXTURE_EDIT_SECTIONS);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
test("golden: table markdown_cells selalu {text} tanpa inline entity untuk sel polos", () => {
|
|
249
|
+
const { client } = makeClient();
|
|
250
|
+
const payload = airich(client)
|
|
251
|
+
.table([
|
|
252
|
+
["A", "B"],
|
|
253
|
+
["c", "d"],
|
|
254
|
+
])
|
|
255
|
+
.build({ submessages: false });
|
|
256
|
+
const decoded = decodeUnifiedResponse(dataOf(payload)) as {
|
|
257
|
+
sections: { view_model: { primitive: { rows: unknown[] } } }[];
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
const rows = decoded.sections[0]?.view_model.primitive.rows;
|
|
261
|
+
assert.deepEqual(rows, [
|
|
262
|
+
{
|
|
263
|
+
is_header: true,
|
|
264
|
+
cells: ["A", "B"],
|
|
265
|
+
markdown_cells: [{ text: "A" }, { text: "B" }],
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
is_header: false,
|
|
269
|
+
cells: ["c", "d"],
|
|
270
|
+
markdown_cells: [{ text: "c" }, { text: "d" }],
|
|
271
|
+
},
|
|
272
|
+
]);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
test("golden: representasi Buffer/Uint8Array stabil untuk transport Zapo", () => {
|
|
276
|
+
const { client } = makeClient();
|
|
277
|
+
const payload = airich(client).text("x").buildPlaceholder();
|
|
278
|
+
|
|
279
|
+
const jsonDump = JSON.stringify(L(L(richOf(payload)).unifiedResponse));
|
|
280
|
+
assert.ok(
|
|
281
|
+
jsonDump.includes('"type":"Buffer"'),
|
|
282
|
+
"bytes harus JSON-serializable sebagai Buffer (Uint8Array)",
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
const secret = payload.messageContextInfo.messageSecret;
|
|
286
|
+
assert.ok(secret instanceof Uint8Array);
|
|
287
|
+
assert.equal(secret.length, 32);
|
|
288
|
+
assert.ok(JSON.stringify(secret).includes('"type":"Buffer"'));
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
test("golden: tidak ada certificate, signature, atau metadata verifikasi palsu di seluruh payload", () => {
|
|
292
|
+
const { client } = makeClient();
|
|
293
|
+
const builder = new AIRich(client, { botJid: "123456789012345@bot" });
|
|
294
|
+
builder
|
|
295
|
+
.text("a")
|
|
296
|
+
.code("js", "b")
|
|
297
|
+
.table([["1"], ["2"]]);
|
|
298
|
+
|
|
299
|
+
const dumps = [
|
|
300
|
+
JSON.stringify(builder.build()),
|
|
301
|
+
JSON.stringify(builder.buildPlaceholder()),
|
|
302
|
+
JSON.stringify(builder.buildEdit("jid@s.whatsapp.net", "ID123")),
|
|
303
|
+
];
|
|
304
|
+
|
|
305
|
+
for (const dump of dumps) {
|
|
306
|
+
assert.equal(dump.includes('"certificateChain"'), false);
|
|
307
|
+
assert.equal(dump.includes('"signature"'), false);
|
|
308
|
+
assert.equal(dump.includes('"verificationMetadata"'), false);
|
|
309
|
+
assert.equal(dump.includes('"botMetadata"'), false);
|
|
310
|
+
assert.equal(dump.includes('"deviceListMetadata"'), false);
|
|
311
|
+
assert.equal(dump.includes("0@bot"), false);
|
|
312
|
+
assert.equal(dump.includes("867051314767696@bot"), false);
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
test("golden: suggestion HScroll dari payload alternatif botf ter-replikasi builder", () => {
|
|
317
|
+
const { client } = makeClient();
|
|
318
|
+
const payload = airich(client)
|
|
319
|
+
.suggest([
|
|
320
|
+
"extendedTextMessage",
|
|
321
|
+
"120363411834515372@g.us",
|
|
322
|
+
"ACCD293BB8DE4DA98AF01BA0E9E7582",
|
|
323
|
+
])
|
|
324
|
+
.build({ submessages: false });
|
|
325
|
+
const decoded = decodeUnifiedResponse(dataOf(payload)) as {
|
|
326
|
+
sections: {
|
|
327
|
+
__typename?: string;
|
|
328
|
+
view_model: { __typename: string; primitives: Record<string, unknown>[] };
|
|
329
|
+
}[];
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
const section = decoded.sections[0];
|
|
333
|
+
assert.equal(section?.__typename, "GenAIUnifiedResponseSection");
|
|
334
|
+
assert.equal(section?.view_model.__typename, "GenAIHScrollLayoutViewModel");
|
|
335
|
+
assert.equal(Array.isArray(section?.view_model.primitives), true);
|
|
336
|
+
assert.deepEqual(
|
|
337
|
+
(section?.view_model.primitives ?? []).map((p) => ({
|
|
338
|
+
prompt_text: p.prompt_text,
|
|
339
|
+
prompt_type: p.prompt_type,
|
|
340
|
+
__typename: p.__typename,
|
|
341
|
+
})),
|
|
342
|
+
[
|
|
343
|
+
{
|
|
344
|
+
prompt_text: "extendedTextMessage",
|
|
345
|
+
prompt_type: "SUGGESTED_PROMPT",
|
|
346
|
+
__typename: "GenAIFollowUpSuggestionPillPrimitive",
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
prompt_text: "120363411834515372@g.us",
|
|
350
|
+
prompt_type: "SUGGESTED_PROMPT",
|
|
351
|
+
__typename: "GenAIFollowUpSuggestionPillPrimitive",
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
prompt_text: "ACCD293BB8DE4DA98AF01BA0E9E7582",
|
|
355
|
+
prompt_type: "SUGGESTED_PROMPT",
|
|
356
|
+
__typename: "GenAIFollowUpSuggestionPillPrimitive",
|
|
357
|
+
},
|
|
358
|
+
],
|
|
359
|
+
);
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
test("golden: code primitive dari payload alternatif botf (language + code_blocks + token types)", () => {
|
|
363
|
+
const { client } = makeClient();
|
|
364
|
+
const snippet =
|
|
365
|
+
'=> conn.\n relayMessage(\n m.chat,\n {\n extendedTextMessage: {\n text: "testtt",\n previewType: 0,\n contextInfo: {\n expiration: 7776000,\n disappearingMode: {\n initiator: 0,\n trigger: 0\n }\n },\n inviteLinkGroupTypeV2: 0\n }\n },\n {}\n)';
|
|
366
|
+
|
|
367
|
+
const payload = airich(client)
|
|
368
|
+
.code("javascript", snippet)
|
|
369
|
+
.build({ submessages: false });
|
|
370
|
+
const decoded = decodeUnifiedResponse(dataOf(payload)) as {
|
|
371
|
+
sections: {
|
|
372
|
+
view_model: {
|
|
373
|
+
primitive: {
|
|
374
|
+
__typename: string;
|
|
375
|
+
language: string;
|
|
376
|
+
code_blocks: { content: string; type: string }[];
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
}[];
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
const primitive = decoded.sections[0]?.view_model.primitive;
|
|
383
|
+
assert.equal(primitive?.__typename, "GenAICodeUXPrimitive");
|
|
384
|
+
assert.equal(primitive?.language, "javascript");
|
|
385
|
+
|
|
386
|
+
assert.deepEqual(
|
|
387
|
+
(primitive?.code_blocks ?? []).map((t) => t.type),
|
|
388
|
+
[
|
|
389
|
+
"DEFAULT",
|
|
390
|
+
"METHOD",
|
|
391
|
+
"DEFAULT",
|
|
392
|
+
"STR",
|
|
393
|
+
"DEFAULT",
|
|
394
|
+
"NUMBER",
|
|
395
|
+
"DEFAULT",
|
|
396
|
+
"NUMBER",
|
|
397
|
+
"DEFAULT",
|
|
398
|
+
"NUMBER",
|
|
399
|
+
"DEFAULT",
|
|
400
|
+
"NUMBER",
|
|
401
|
+
"DEFAULT",
|
|
402
|
+
"NUMBER",
|
|
403
|
+
"DEFAULT",
|
|
404
|
+
],
|
|
405
|
+
);
|
|
406
|
+
});
|