@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,349 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import sharp from "sharp";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
text,
|
|
7
|
+
linkPreview,
|
|
8
|
+
reaction,
|
|
9
|
+
forward,
|
|
10
|
+
contact,
|
|
11
|
+
poll,
|
|
12
|
+
media,
|
|
13
|
+
sticker,
|
|
14
|
+
album,
|
|
15
|
+
location,
|
|
16
|
+
button,
|
|
17
|
+
legacyButton,
|
|
18
|
+
listMessage,
|
|
19
|
+
airich,
|
|
20
|
+
} from "@kyyinfinite/zapo-message";
|
|
21
|
+
import { asClient } from "./helpers.js";
|
|
22
|
+
|
|
23
|
+
const GOLDEN_UPLOAD = {
|
|
24
|
+
url: "https://mmg.whatsapp.net/v/t62.7118-24/golden",
|
|
25
|
+
directPath: "/v/t62.7118-24/golden",
|
|
26
|
+
mediaKey: new Uint8Array(32).fill(1),
|
|
27
|
+
fileSha256: new Uint8Array(32).fill(2),
|
|
28
|
+
fileEncSha256: new Uint8Array(32).fill(3),
|
|
29
|
+
fileLength: 1000,
|
|
30
|
+
mediaKeyTimestamp: 1730000000,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const PNG_BYTES = await sharp({
|
|
34
|
+
create: { width: 120, height: 90, channels: 3, background: "#3060ff" },
|
|
35
|
+
})
|
|
36
|
+
.png()
|
|
37
|
+
.toBuffer();
|
|
38
|
+
|
|
39
|
+
const WEBP_BYTES = await sharp({
|
|
40
|
+
create: { width: 512, height: 512, channels: 4, background: "#ff9030" },
|
|
41
|
+
})
|
|
42
|
+
.webp({ effort: 0 })
|
|
43
|
+
.toBuffer();
|
|
44
|
+
|
|
45
|
+
const capture = () => {
|
|
46
|
+
const sends: { to: unknown; content: unknown; options: unknown }[] = [];
|
|
47
|
+
const client = asClient({
|
|
48
|
+
message: {
|
|
49
|
+
upload: async () => GOLDEN_UPLOAD,
|
|
50
|
+
send: async (to: unknown, content: unknown, options: unknown) => {
|
|
51
|
+
sends.push({ to, content, options });
|
|
52
|
+
return { id: `ID-${sends.length}`, attempts: 1, ack: {} };
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
return { client, sends };
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const plain = (value: unknown): unknown =>
|
|
60
|
+
JSON.parse(
|
|
61
|
+
JSON.stringify(value, (_key, raw) => {
|
|
62
|
+
if (raw instanceof Uint8Array) return { $bytes: raw.byteLength };
|
|
63
|
+
if (
|
|
64
|
+
raw &&
|
|
65
|
+
typeof raw === "object" &&
|
|
66
|
+
!Array.isArray(raw) &&
|
|
67
|
+
(raw as { type?: unknown }).type === "Buffer" &&
|
|
68
|
+
Array.isArray((raw as { data?: unknown }).data)
|
|
69
|
+
) {
|
|
70
|
+
return { $bytes: (raw as { data: number[] }).data.length };
|
|
71
|
+
}
|
|
72
|
+
return raw;
|
|
73
|
+
}),
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
test("golden async: text", async () => {
|
|
77
|
+
const { client, sends } = capture();
|
|
78
|
+
await text(client, "6281@s.whatsapp.net", { body: "Halo Dunia" });
|
|
79
|
+
assert.deepEqual(plain(sends[0]?.content), { conversation: "Halo Dunia" });
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("golden async: linkPreview", async () => {
|
|
83
|
+
const { client, sends } = capture();
|
|
84
|
+
await linkPreview(client, "6281@s.whatsapp.net", {
|
|
85
|
+
body: "Dokumentasi ada di https://example.com/docs",
|
|
86
|
+
title: "Dokumentasi",
|
|
87
|
+
description: "Semua yang perlu diketahui",
|
|
88
|
+
});
|
|
89
|
+
const payload = plain(sends[0]?.content) as {
|
|
90
|
+
extendedTextMessage: Record<string, unknown>;
|
|
91
|
+
};
|
|
92
|
+
assert.equal(
|
|
93
|
+
payload.extendedTextMessage.text,
|
|
94
|
+
"Dokumentasi ada di https://example.com/docs",
|
|
95
|
+
);
|
|
96
|
+
assert.equal(
|
|
97
|
+
payload.extendedTextMessage.matchedText,
|
|
98
|
+
"https://example.com/docs",
|
|
99
|
+
);
|
|
100
|
+
assert.equal(payload.extendedTextMessage.previewType, 5);
|
|
101
|
+
assert.equal(payload.extendedTextMessage.title, "Dokumentasi");
|
|
102
|
+
assert.equal(
|
|
103
|
+
payload.extendedTextMessage.description,
|
|
104
|
+
"Semua yang perlu diketahui",
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("golden async: reaction", async () => {
|
|
109
|
+
const { client, sends } = capture();
|
|
110
|
+
const target = {
|
|
111
|
+
key: { remoteJid: "6281@s.whatsapp.net", id: "MSG-G", fromMe: false },
|
|
112
|
+
};
|
|
113
|
+
await reaction(client, { target, emoji: "🔥" });
|
|
114
|
+
assert.deepEqual(plain(sends[0]?.content), {
|
|
115
|
+
type: "reaction",
|
|
116
|
+
target,
|
|
117
|
+
emoji: "🔥",
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("golden async: forward", async () => {
|
|
122
|
+
const { client, sends } = capture();
|
|
123
|
+
await forward(client, "6282@s.whatsapp.net", {
|
|
124
|
+
message: {
|
|
125
|
+
key: { remoteJid: "6281@s.whatsapp.net", id: "MSG-F", fromMe: false },
|
|
126
|
+
message: { conversation: "pesan asal" },
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
assert.deepEqual(plain(sends[0]?.content), { conversation: "pesan asal" });
|
|
130
|
+
assert.deepEqual(
|
|
131
|
+
(sends[0]?.options as Record<string, unknown>).forward,
|
|
132
|
+
true,
|
|
133
|
+
);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("golden async: contact", async () => {
|
|
137
|
+
const { client, sends } = capture();
|
|
138
|
+
await contact(client, "6281@s.whatsapp.net", {
|
|
139
|
+
name: "Budi",
|
|
140
|
+
phone: "+628123456789",
|
|
141
|
+
});
|
|
142
|
+
const payload = plain(sends[0]?.content) as {
|
|
143
|
+
contactMessage: { displayName: string; vcard: string };
|
|
144
|
+
};
|
|
145
|
+
assert.equal(payload.contactMessage.displayName, "Budi");
|
|
146
|
+
assert.match(payload.contactMessage.vcard, /^BEGIN:VCARD/);
|
|
147
|
+
assert.match(payload.contactMessage.vcard, /FN:Budi/);
|
|
148
|
+
assert.match(
|
|
149
|
+
payload.contactMessage.vcard,
|
|
150
|
+
/TEL;type=CELL;type=VOICE:\+628123456789/,
|
|
151
|
+
);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("golden async: poll", async () => {
|
|
155
|
+
const { client, sends } = capture();
|
|
156
|
+
await poll(client, "6281@s.whatsapp.net", {
|
|
157
|
+
question: "Makan apa?",
|
|
158
|
+
options: ["Nasi goreng", "Mie ayam"],
|
|
159
|
+
});
|
|
160
|
+
assert.deepEqual(plain(sends[0]?.content), {
|
|
161
|
+
type: "poll",
|
|
162
|
+
name: "Makan apa?",
|
|
163
|
+
options: ["Nasi goreng", "Mie ayam"],
|
|
164
|
+
selectableCount: 1,
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test("golden async: media image", async () => {
|
|
169
|
+
const { client, sends } = capture();
|
|
170
|
+
await media(client, "6281@s.whatsapp.net", {
|
|
171
|
+
type: "image",
|
|
172
|
+
source: PNG_BYTES,
|
|
173
|
+
caption: "Foto",
|
|
174
|
+
});
|
|
175
|
+
const payload = plain(sends[0]?.content) as {
|
|
176
|
+
imageMessage: Record<string, unknown>;
|
|
177
|
+
};
|
|
178
|
+
assert.equal(payload.imageMessage.url, GOLDEN_UPLOAD.url);
|
|
179
|
+
assert.equal(payload.imageMessage.mimetype, "image/png");
|
|
180
|
+
assert.equal(payload.imageMessage.caption, "Foto");
|
|
181
|
+
assert.equal(payload.imageMessage.width, 120);
|
|
182
|
+
assert.equal(payload.imageMessage.height, 90);
|
|
183
|
+
const thumb = payload.imageMessage.jpegThumbnail as { $bytes: number };
|
|
184
|
+
assert.equal(typeof thumb.$bytes, "number");
|
|
185
|
+
assert.ok(thumb.$bytes > 0, "thumbnail tergenerate");
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test("golden async: sticker", async () => {
|
|
189
|
+
const { client, sends } = capture();
|
|
190
|
+
await sticker(client, "6281@s.whatsapp.net", { source: WEBP_BYTES });
|
|
191
|
+
const payload = plain(sends[0]?.content) as {
|
|
192
|
+
stickerMessage: Record<string, unknown>;
|
|
193
|
+
};
|
|
194
|
+
assert.equal(payload.stickerMessage.mimetype, "image/webp");
|
|
195
|
+
assert.equal(payload.stickerMessage.isAnimated, false);
|
|
196
|
+
assert.equal(payload.stickerMessage.width, 512);
|
|
197
|
+
assert.equal(payload.stickerMessage.height, 512);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test("golden async: album", async () => {
|
|
201
|
+
const { client, sends } = capture();
|
|
202
|
+
await album(client, "6281@s.whatsapp.net", {
|
|
203
|
+
media: [
|
|
204
|
+
{ type: "image", source: PNG_BYTES },
|
|
205
|
+
{ type: "image", source: PNG_BYTES, options: { caption: "kedua" } },
|
|
206
|
+
],
|
|
207
|
+
});
|
|
208
|
+
assert.deepEqual(plain(sends[0]?.content), {
|
|
209
|
+
albumMessage: { expectedImageCount: 2, expectedVideoCount: 0 },
|
|
210
|
+
});
|
|
211
|
+
const second = plain(sends[2]?.content) as {
|
|
212
|
+
imageMessage: Record<string, unknown>;
|
|
213
|
+
};
|
|
214
|
+
assert.equal(second.imageMessage.caption, "kedua");
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test("golden async: location", async () => {
|
|
218
|
+
const { client, sends } = capture();
|
|
219
|
+
await location(client, "6281@s.whatsapp.net", {
|
|
220
|
+
latitude: -6.175,
|
|
221
|
+
longitude: 106.827,
|
|
222
|
+
name: "Monas",
|
|
223
|
+
address: "Jakarta",
|
|
224
|
+
});
|
|
225
|
+
assert.deepEqual(plain(sends[0]?.content), {
|
|
226
|
+
locationMessage: {
|
|
227
|
+
degreesLatitude: -6.175,
|
|
228
|
+
degreesLongitude: 106.827,
|
|
229
|
+
name: "Monas",
|
|
230
|
+
address: "Jakarta",
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
test("golden async: button", async () => {
|
|
236
|
+
const { client, sends } = capture();
|
|
237
|
+
await button(client, "6281@s.whatsapp.net", {
|
|
238
|
+
title: "Menu",
|
|
239
|
+
body: "Pilih",
|
|
240
|
+
footer: "Avelyna",
|
|
241
|
+
buttons: [
|
|
242
|
+
{ type: "quick_reply", text: "OK", id: "cmd-ok" },
|
|
243
|
+
{ type: "cta_url", text: "Web", url: "https://example.com" },
|
|
244
|
+
],
|
|
245
|
+
});
|
|
246
|
+
const payload = plain(sends[0]?.content) as {
|
|
247
|
+
interactiveMessage: {
|
|
248
|
+
header: Record<string, unknown>;
|
|
249
|
+
body: { text: string };
|
|
250
|
+
footer: { text: string };
|
|
251
|
+
nativeFlowMessage: {
|
|
252
|
+
buttons: { name: string; buttonParamsJson: string }[];
|
|
253
|
+
messageVersion: number;
|
|
254
|
+
};
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
assert.deepEqual(payload.interactiveMessage.header, {
|
|
258
|
+
hasMediaAttachment: false,
|
|
259
|
+
title: "Menu",
|
|
260
|
+
});
|
|
261
|
+
assert.equal(payload.interactiveMessage.body.text, "Pilih");
|
|
262
|
+
assert.equal(payload.interactiveMessage.footer.text, "Avelyna");
|
|
263
|
+
assert.equal(payload.interactiveMessage.nativeFlowMessage.messageVersion, 1);
|
|
264
|
+
const goldenButtons = payload.interactiveMessage.nativeFlowMessage.buttons;
|
|
265
|
+
assert.deepEqual(JSON.parse(goldenButtons[0]!.buttonParamsJson), {
|
|
266
|
+
display_text: "OK",
|
|
267
|
+
id: "cmd-ok",
|
|
268
|
+
});
|
|
269
|
+
assert.deepEqual(JSON.parse(goldenButtons[1]!.buttonParamsJson), {
|
|
270
|
+
display_text: "Web",
|
|
271
|
+
url: "https://example.com",
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
test("golden async: legacyButton", async () => {
|
|
276
|
+
const { client, sends } = capture();
|
|
277
|
+
await legacyButton(client, "6281@s.whatsapp.net", {
|
|
278
|
+
title: "Menu",
|
|
279
|
+
body: "Halo",
|
|
280
|
+
footer: "Avelyna",
|
|
281
|
+
buttons: [{ id: "b1", text: "Satu" }],
|
|
282
|
+
});
|
|
283
|
+
assert.deepEqual(plain(sends[0]?.content), {
|
|
284
|
+
buttonsMessage: {
|
|
285
|
+
contentText: "Halo",
|
|
286
|
+
buttons: [
|
|
287
|
+
{
|
|
288
|
+
buttonId: "b1",
|
|
289
|
+
buttonText: { displayText: "Satu" },
|
|
290
|
+
type: 1,
|
|
291
|
+
},
|
|
292
|
+
],
|
|
293
|
+
headerType: 2,
|
|
294
|
+
text: "Menu",
|
|
295
|
+
footerText: "Avelyna",
|
|
296
|
+
},
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
test("golden async: listMessage", async () => {
|
|
301
|
+
const { client, sends } = capture();
|
|
302
|
+
await listMessage(client, "6281@s.whatsapp.net", {
|
|
303
|
+
title: "Menu",
|
|
304
|
+
body: "Pilih",
|
|
305
|
+
footer: "Avelyna",
|
|
306
|
+
buttonText: "Buka",
|
|
307
|
+
sections: [
|
|
308
|
+
{
|
|
309
|
+
title: "Utama",
|
|
310
|
+
rows: [{ id: "a", title: "Opsi A", description: "deskripsi" }],
|
|
311
|
+
},
|
|
312
|
+
],
|
|
313
|
+
});
|
|
314
|
+
assert.deepEqual(plain(sends[0]?.content), {
|
|
315
|
+
listMessage: {
|
|
316
|
+
title: "Menu",
|
|
317
|
+
description: "Pilih",
|
|
318
|
+
buttonText: "Buka",
|
|
319
|
+
listType: 1,
|
|
320
|
+
sections: [
|
|
321
|
+
{
|
|
322
|
+
title: "Utama",
|
|
323
|
+
rows: [{ rowId: "a", title: "Opsi A", description: "deskripsi" }],
|
|
324
|
+
},
|
|
325
|
+
],
|
|
326
|
+
footerText: "Avelyna",
|
|
327
|
+
},
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
test("golden async: airich dua-langkah", async () => {
|
|
332
|
+
const { client, sends } = capture();
|
|
333
|
+
await airich(client, "6281@s.whatsapp.net", {
|
|
334
|
+
sections: [{ type: "text", text: "Halo dari AIRich" }],
|
|
335
|
+
footer: "Powered by Avelyna",
|
|
336
|
+
});
|
|
337
|
+
assert.equal(sends.length, 2);
|
|
338
|
+
const placeholder = plain(sends[0]?.content) as Record<string, unknown>;
|
|
339
|
+
assert.ok(placeholder.messageContextInfo);
|
|
340
|
+
const edit = sends[1]?.content as Record<string, unknown>;
|
|
341
|
+
const protocol = (edit.botForwardedMessage as Record<string, unknown>)
|
|
342
|
+
.message as Record<string, unknown>;
|
|
343
|
+
const protocolMessage = protocol.protocolMessage as Record<string, unknown>;
|
|
344
|
+
assert.equal(protocolMessage.type, 14);
|
|
345
|
+
const key = protocolMessage.key as Record<string, unknown>;
|
|
346
|
+
assert.equal(key.remoteJid, "6281@s.whatsapp.net");
|
|
347
|
+
assert.equal(key.fromMe, true);
|
|
348
|
+
assert.equal(key.id, "ID-1");
|
|
349
|
+
});
|