@kyyinfinite/zapo-message 1.0.1 → 1.1.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 +46 -0
- package/README.md +24 -1
- package/dist/airich/airich.js +13 -8
- package/dist/btn/builders.js +8 -2
- package/dist/btn/media-slot.js +12 -3
- package/dist/btn/thumbnail.js +18 -0
- package/dist/core/base-builder.d.ts +1 -0
- package/dist/core/base-builder.js +5 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/message/album.js +3 -2
- package/dist/message/forward.js +3 -2
- package/dist/message/index.d.ts +2 -0
- package/dist/message/index.js +1 -0
- package/dist/message/operations.d.ts +22 -0
- package/dist/message/operations.js +176 -0
- package/dist/message/reaction.js +3 -2
- package/package.json +111 -107
- package/src/airich/airich.ts +16 -7
- package/src/btn/builders.ts +12 -2
- package/src/btn/media-slot.ts +11 -3
- package/src/btn/thumbnail.ts +22 -0
- package/src/core/base-builder.ts +8 -0
- package/src/index.ts +13 -0
- package/src/message/album.ts +3 -2
- package/src/message/forward.ts +3 -2
- package/src/message/index.ts +13 -0
- package/src/message/operations.ts +325 -0
- package/src/message/reaction.ts +3 -2
- package/test/message-operations.test.ts +298 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,51 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.1.0 — API Consistency, Type Safety, Feature Expansion & Reliability
|
|
4
|
+
|
|
5
|
+
Versi minor: tidak ada breaking change terhadap API publik 1.0.1. Seluruh
|
|
6
|
+
hybrid async + chain tetap memakai fondasi eksekusi internal yang sama.
|
|
7
|
+
|
|
8
|
+
### Hybrid API consistency
|
|
9
|
+
|
|
10
|
+
- `defaultQuote()` kini diproses seragam oleh seluruh builder. Sebelumnya
|
|
11
|
+
`ListMessage`, `ReactionBuilder`, `ForwardBuilder`, `AlbumBuilder`, dan
|
|
12
|
+
`AIRich` melewatinya diam-diam; kini keduanya mengikuti kontrak
|
|
13
|
+
`BaseBuilder`: quote eksplisit pada `send()` menimpa default quote.
|
|
14
|
+
- `AIRich.send()` kini mengikuti resolusi target `BaseBuilder`
|
|
15
|
+
(`send(jid)` > `defaultTo()`/`to()` > error `NO_TARGET`); sebelumnya
|
|
16
|
+
`defaultTo()` diabaikan dan menghasilkan error validasi jid.
|
|
17
|
+
- `BaseBuilder` mengekspos `_mergedOptions()` sebagai satu titik penggabungan
|
|
18
|
+
default quote — async API dan chain API kini identik untuk quote.
|
|
19
|
+
|
|
20
|
+
### Message operations (baru, `message/operations.js` + root export)
|
|
21
|
+
|
|
22
|
+
- `editMessage(client, target, content)` — edit pesan terkirim via opsi
|
|
23
|
+
native `editKey` zapo-js.
|
|
24
|
+
- `revokeMessage`, `pinMessage(durationSecs?)`, `unpinMessage`, `keepMessage`,
|
|
25
|
+
`unkeepMessage` — wrapper konten terketik `type: "revoke" | "pin" | "unpin"
|
|
26
|
+
| "keep" | "unkeep"` native zapo-js.
|
|
27
|
+
- `votePoll(client, { poll, selectedOptionNames })` — vote poll dengan
|
|
28
|
+
validasi parent (`id`, `fromMe`, `authorJid`, `messageSecret`).
|
|
29
|
+
- `sendEvent(client, jid, config)` / `respondEvent(client, event, response)`
|
|
30
|
+
— event creation + response (`going` | `not_going` | `maybe`) native.
|
|
31
|
+
- Semua operasi memvalidasi input sebelum kirim dan melempar `MessageError`
|
|
32
|
+
terstruktur (`VALIDATION` / `INVALID_TARGET` / `NO_CLIENT`).
|
|
33
|
+
|
|
34
|
+
### Media handling
|
|
35
|
+
|
|
36
|
+
- Thumbnail JPEG yang sudah kecil (≤ 240px) kini lolos tanpa re-encode —
|
|
37
|
+
byte payload identik dengan input pengguna; yang lebih besar tetap di-resize.
|
|
38
|
+
- Thumbnail otomatis untuk image yang tidak bisa diproses sharp kini
|
|
39
|
+
didegradasi menjadi tanpa-thumbnail, bukan gagal kirim (upload tetap
|
|
40
|
+
berjalan; pesan tetap terkirim).
|
|
41
|
+
- Header `document()` tanpa `fileName` pada sumber non-path kini ditolak
|
|
42
|
+
lebih awal dengan `ValidationError` yang jelas.
|
|
43
|
+
|
|
44
|
+
### Testing
|
|
45
|
+
|
|
46
|
+
- 390 test existing tetap hijau (perbaikan baseline di atas), ditambah suite
|
|
47
|
+
`message-operations` dan `quote-parity` untuk kontrak default quote/target.
|
|
48
|
+
|
|
3
49
|
## 1.2.0 — Complete Hybrid API
|
|
4
50
|
|
|
5
51
|
Versi minor: hanya tambahan aditif; seluruh API 1.1.0 dipertahankan
|
package/README.md
CHANGED
|
@@ -1059,7 +1059,30 @@ await customClient.text().body("Hello").send(jid);
|
|
|
1059
1059
|
|
|
1060
1060
|
`installZapoMessage()` checks for a callable `message.send` method and returns the client. This does not make an arbitrary transport fully ZapoJS-compatible; message content and options still need to be supported by the transport.
|
|
1061
1061
|
|
|
1062
|
-
###
|
|
1062
|
+
### Message operations
|
|
1063
|
+
|
|
1064
|
+
Operasi pesan native zapo-js dibungkus dengan validasi dan error terstruktur
|
|
1065
|
+
(semua diekspor dari root dan `@kyyinfinite/zapo-message/message/operations.js`):
|
|
1066
|
+
|
|
1067
|
+
```ts
|
|
1068
|
+
import {
|
|
1069
|
+
editMessage, revokeMessage, pinMessage, unpinMessage,
|
|
1070
|
+
keepMessage, unkeepMessage, votePoll, sendEvent, respondEvent,
|
|
1071
|
+
} from "@kyyinfinite/zapo-message";
|
|
1072
|
+
|
|
1073
|
+
await editMessage(client, incoming, { conversation: "teks baru" });
|
|
1074
|
+
await revokeMessage(client, incoming);
|
|
1075
|
+
await pinMessage(client, incoming, 604_800);
|
|
1076
|
+
await keepMessage(client, incoming);
|
|
1077
|
+
await votePoll(client, { poll: pollParent, selectedOptionNames: ["A"] });
|
|
1078
|
+
await sendEvent(client, jid, { name: "Rapat", startTime: 1730000000 });
|
|
1079
|
+
await respondEvent(client, eventParent, "going");
|
|
1080
|
+
```
|
|
1081
|
+
|
|
1082
|
+
Target dapat berupa event pesan masuk atau message key; resolusi, validasi,
|
|
1083
|
+
dan bentuk payload mengikuti tipe native zapo-js 1.11.0.
|
|
1084
|
+
|
|
1085
|
+
## Serialization and interactive replies
|
|
1063
1086
|
|
|
1064
1087
|
```ts
|
|
1065
1088
|
import {
|
package/dist/airich/airich.js
CHANGED
|
@@ -2,7 +2,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { proto } from "zapo-js";
|
|
3
3
|
import { BaseBuilder } from "../core/base-builder.js";
|
|
4
4
|
import { sendConfigured } from "../core/async-send.js";
|
|
5
|
-
import { ValidationError, ItemNotFoundError, InvalidTargetError, } from "../core/errors.js";
|
|
5
|
+
import { MessageError, ValidationError, ItemNotFoundError, InvalidTargetError, } from "../core/errors.js";
|
|
6
6
|
import { parseInline } from "./inline.js";
|
|
7
7
|
import { toTable } from "./table.js";
|
|
8
8
|
import { tokenizeCode } from "./tokenizer.js";
|
|
@@ -363,31 +363,36 @@ export class AIRich extends BaseBuilder {
|
|
|
363
363
|
}
|
|
364
364
|
async send(jid, arg) {
|
|
365
365
|
const { client, options } = this._resolve(arg);
|
|
366
|
-
const
|
|
366
|
+
const target = typeof jid === "string" && jid ? jid : this._defaultTarget();
|
|
367
|
+
if (!target) {
|
|
368
|
+
throw new MessageError("tujuan airich tidak diketahui. panggil send(jid) atau .defaultTo(jid)", "NO_TARGET");
|
|
369
|
+
}
|
|
370
|
+
const { twoStep = true, submessages = true, ...restOptions } = options;
|
|
371
|
+
const sendOptions = this._mergedOptions(restOptions);
|
|
367
372
|
if (!twoStep) {
|
|
368
373
|
const direct = wrapBotForwarded(this.#rich({
|
|
369
374
|
sections: this.#sections(),
|
|
370
375
|
submessages: this.#submessages(Boolean(submessages)),
|
|
371
376
|
withContext: true,
|
|
372
377
|
}));
|
|
373
|
-
const result = await sendViaZapo(client,
|
|
378
|
+
const result = await sendViaZapo(client, target, direct, sendOptions);
|
|
374
379
|
this.#lastId = result?.id ?? null;
|
|
375
380
|
return result;
|
|
376
381
|
}
|
|
377
382
|
const sent = await sendPlaceholderThenEdit({
|
|
378
383
|
client,
|
|
379
|
-
jid:
|
|
384
|
+
jid: target,
|
|
380
385
|
placeholder: this.buildPlaceholder(),
|
|
381
|
-
buildEdit: (messageId) => this.buildEdit(
|
|
386
|
+
buildEdit: (messageId) => this.buildEdit(target, messageId, {
|
|
382
387
|
submessages: Boolean(submessages),
|
|
383
388
|
}),
|
|
384
389
|
options: sendOptions,
|
|
385
|
-
onPlaceholderSent: (
|
|
390
|
+
onPlaceholderSent: (sentTarget, messageId) => {
|
|
386
391
|
this.#lastId = messageId;
|
|
387
|
-
this.#pendingEdits.set(
|
|
392
|
+
this.#pendingEdits.set(sentTarget, messageId);
|
|
388
393
|
},
|
|
389
394
|
});
|
|
390
|
-
this.#pendingEdits.delete(
|
|
395
|
+
this.#pendingEdits.delete(target);
|
|
391
396
|
return sent;
|
|
392
397
|
}
|
|
393
398
|
async edit(jid, id = this.#lastId, arg) {
|
package/dist/btn/builders.js
CHANGED
|
@@ -126,6 +126,11 @@ class HeaderMessage extends BaseMessage {
|
|
|
126
126
|
if (this._headerThumbnail) {
|
|
127
127
|
throw new ValidationError(`.${kind}() tidak bisa dipakai bareng .headerThumbnail() — thumbnail gambar header pakai .${kind}(source, { thumbnail })`);
|
|
128
128
|
}
|
|
129
|
+
if (kind === "document" &&
|
|
130
|
+
options.fileName === undefined &&
|
|
131
|
+
typeof source !== "string") {
|
|
132
|
+
throw new ValidationError(`header ${kind} butuh fileName — berikan options.fileName (sumber bukan path tidak bisa menebak nama file)`);
|
|
133
|
+
}
|
|
129
134
|
this._mediaSlot = {
|
|
130
135
|
kind,
|
|
131
136
|
source,
|
|
@@ -578,9 +583,10 @@ export class ListMessage extends BaseMessage {
|
|
|
578
583
|
const isGroup = this._inGroupOverride ?? isGroupJid(target);
|
|
579
584
|
const useNativeFlow = this._fallback === "native" || (this._fallback === "auto" && isGroup);
|
|
580
585
|
const content = useNativeFlow ? this.toNativeFlow() : this.build();
|
|
586
|
+
const merged = this._mergedOptions(options);
|
|
581
587
|
const send = client.message.send.bind(client.message);
|
|
582
|
-
return Object.keys(
|
|
583
|
-
? send(target, content,
|
|
588
|
+
return Object.keys(merged).length
|
|
589
|
+
? send(target, content, merged)
|
|
584
590
|
: send(target, content);
|
|
585
591
|
}
|
|
586
592
|
}
|
package/dist/btn/media-slot.js
CHANGED
|
@@ -85,9 +85,18 @@ const resolveThumbnail = async (bytes, kind, options, label) => {
|
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
87
|
if (kind === "image" && bytes) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
try {
|
|
89
|
+
return await generateImageThumbnail(bytes, {
|
|
90
|
+
label: `${label} (thumbnail otomatis)`,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
const meta = error;
|
|
95
|
+
if (error instanceof MediaError && meta.kind === "thumbnail_failed") {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
91
100
|
}
|
|
92
101
|
if (kind === "sticker" && bytes) {
|
|
93
102
|
return generatePngThumbnail(bytes, {
|
package/dist/btn/thumbnail.js
CHANGED
|
@@ -47,6 +47,11 @@ export const validateJpegThumbnail = (bytes, { label = "thumbnail" } = {}) => {
|
|
|
47
47
|
};
|
|
48
48
|
export const generateImageThumbnail = async (bytes, { label = "thumbnail", maxDimension = THUMBNAIL_MAX_DIMENSION, quality = THUMBNAIL_JPEG_QUALITY, } = {}) => {
|
|
49
49
|
const input = asThumbnailBytes(bytes);
|
|
50
|
+
if (isJpegBytes(input)) {
|
|
51
|
+
const withinLimit = await isWithinThumbnailLimit(input, maxDimension);
|
|
52
|
+
if (withinLimit)
|
|
53
|
+
return bufferFromBytes(input);
|
|
54
|
+
}
|
|
50
55
|
const sharp = await loadSharp();
|
|
51
56
|
if (!sharp) {
|
|
52
57
|
throw new MediaError(`generasi thumbnail otomatis ${label} gagal — ${SHARP_INSTALL_HINT}`, { kind: "thumbnail_failed" });
|
|
@@ -122,3 +127,16 @@ const describeBytes = (bytes) => {
|
|
|
122
127
|
.join(" ");
|
|
123
128
|
return `bytes dengan magic ${hex}`;
|
|
124
129
|
};
|
|
130
|
+
const isWithinThumbnailLimit = async (bytes, maxDimension) => {
|
|
131
|
+
const sharp = await loadSharp();
|
|
132
|
+
if (!sharp)
|
|
133
|
+
return true;
|
|
134
|
+
const metadata = await sharp(bytes).metadata().catch(() => undefined);
|
|
135
|
+
if (metadata?.width === undefined ||
|
|
136
|
+
metadata?.height === undefined ||
|
|
137
|
+
!Number.isFinite(metadata.width) ||
|
|
138
|
+
!Number.isFinite(metadata.height)) {
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
return metadata.width <= maxDimension && metadata.height <= maxDimension;
|
|
142
|
+
};
|
|
@@ -11,6 +11,7 @@ export declare class BaseBuilder<TBuild extends ZapoMessageContent = BuilderMess
|
|
|
11
11
|
to(jid: string | undefined): this;
|
|
12
12
|
defaultQuote(ref: unknown): this;
|
|
13
13
|
protected _defaultTarget(): string | undefined;
|
|
14
|
+
protected _mergedOptions(options: Record<string, unknown>): Record<string, unknown>;
|
|
14
15
|
build(): TBuild | Promise<TBuild>;
|
|
15
16
|
protected _resolve(arg?: SendResolutionArg): {
|
|
16
17
|
client: ZapoClient;
|
|
@@ -34,6 +34,11 @@ export class BaseBuilder {
|
|
|
34
34
|
_defaultTarget() {
|
|
35
35
|
return this.#defaultJid;
|
|
36
36
|
}
|
|
37
|
+
_mergedOptions(options) {
|
|
38
|
+
return this.#defaultQuote !== undefined && options.quote === undefined
|
|
39
|
+
? { quote: this.#defaultQuote, ...options }
|
|
40
|
+
: options;
|
|
41
|
+
}
|
|
37
42
|
build() {
|
|
38
43
|
throw new MessageError(`${this.constructor.name}.build() belum diimplementasi`, "NOT_IMPLEMENTED");
|
|
39
44
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -36,3 +36,5 @@ export declare const messageKit: (client?: ZapoClient) => {
|
|
|
36
36
|
listMessage: () => import("./btn.js").ListMessage;
|
|
37
37
|
airich: (options?: AIRichConstructorOptions) => import("./airich/airich.js").AIRich;
|
|
38
38
|
};
|
|
39
|
+
export { editMessage, revokeMessage, pinMessage, unpinMessage, keepMessage, unkeepMessage, votePoll, sendEvent, respondEvent, resolveMessageTargetKey, } from "./message/operations.js";
|
|
40
|
+
export type { PollVoteInput, MessageOperationTargetInput } from "./message/operations.js";
|
package/dist/index.js
CHANGED
|
@@ -20,3 +20,4 @@ export const messageKit = (client) => ({
|
|
|
20
20
|
listMessage: () => listMessage(client),
|
|
21
21
|
airich: (options) => airich(client, options),
|
|
22
22
|
});
|
|
23
|
+
export { editMessage, revokeMessage, pinMessage, unpinMessage, keepMessage, unkeepMessage, votePoll, sendEvent, respondEvent, resolveMessageTargetKey, } from "./message/operations.js";
|
package/dist/message/album.js
CHANGED
|
@@ -56,7 +56,8 @@ export class AlbumBuilder extends BaseBuilder {
|
|
|
56
56
|
}
|
|
57
57
|
const children = await this.resolveChildren();
|
|
58
58
|
const album = this.build();
|
|
59
|
-
const
|
|
59
|
+
const mergedOptions = this._mergedOptions(options);
|
|
60
|
+
const albumOptions = { ...mergedOptions };
|
|
60
61
|
const albumSend = client.message.send.bind(client.message);
|
|
61
62
|
const albumResult = (await (Object.keys(albumOptions).length
|
|
62
63
|
? albumSend(target, album, albumOptions)
|
|
@@ -68,7 +69,7 @@ export class AlbumBuilder extends BaseBuilder {
|
|
|
68
69
|
const selfJid = resolveSelfJid(client);
|
|
69
70
|
for (const child of children) {
|
|
70
71
|
const childOptions = {
|
|
71
|
-
...
|
|
72
|
+
...mergedOptions,
|
|
72
73
|
quote: {
|
|
73
74
|
id: albumId,
|
|
74
75
|
remoteJid: target,
|
package/dist/message/forward.js
CHANGED
|
@@ -51,9 +51,10 @@ export class ForwardBuilder extends BaseBuilder {
|
|
|
51
51
|
if (!this.#message) {
|
|
52
52
|
throw new MessageError("forward.message belum diset — berikan pesan sumber yang mau diteruskan", "NO_SOURCE");
|
|
53
53
|
}
|
|
54
|
+
const merged = this._mergedOptions(options);
|
|
54
55
|
const sendOptions = {
|
|
55
|
-
...
|
|
56
|
-
forward:
|
|
56
|
+
...merged,
|
|
57
|
+
forward: merged.forward ??
|
|
57
58
|
(this.#score !== undefined ? { score: this.#score } : true),
|
|
58
59
|
};
|
|
59
60
|
return client.message.send(target, this.build(), sendOptions);
|
package/dist/message/index.d.ts
CHANGED
|
@@ -24,3 +24,5 @@ export { buildVcard } from "./vcard.js";
|
|
|
24
24
|
export type { VcardInput } from "./vcard.js";
|
|
25
25
|
export { targetKeyOf, targetChatJidOf, targetIdOf } from "./target.js";
|
|
26
26
|
export type { MessageKeyLike, MessageTargetLike } from "./target.js";
|
|
27
|
+
export { editMessage, revokeMessage, pinMessage, unpinMessage, keepMessage, unkeepMessage, votePoll, sendEvent, respondEvent, resolveMessageTargetKey, } from "./operations.js";
|
|
28
|
+
export type { PollVoteInput, MessageOperationTargetInput } from "./operations.js";
|
package/dist/message/index.js
CHANGED
|
@@ -11,3 +11,4 @@ export { LocationBuilder, location, applyLocationConfig, sendLocation, } from ".
|
|
|
11
11
|
export { probeWebp } from "./webp.js";
|
|
12
12
|
export { buildVcard } from "./vcard.js";
|
|
13
13
|
export { targetKeyOf, targetChatJidOf, targetIdOf } from "./target.js";
|
|
14
|
+
export { editMessage, revokeMessage, pinMessage, unpinMessage, keepMessage, unkeepMessage, votePoll, sendEvent, respondEvent, resolveMessageTargetKey, } from "./operations.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { WaMessageTargetInput, WaSendPollParent, WaSendEventResponseType } from "zapo-js";
|
|
2
|
+
import type { ZapoClient } from "../zapo-client.js";
|
|
3
|
+
export type MessageOperationTargetInput = WaMessageTargetInput;
|
|
4
|
+
export declare const resolveMessageTargetKey: (target: unknown) => {
|
|
5
|
+
remoteJid: string;
|
|
6
|
+
id: string;
|
|
7
|
+
fromMe: boolean;
|
|
8
|
+
participant?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const editMessage: (client: ZapoClient | undefined, target: unknown, content: unknown) => Promise<unknown>;
|
|
11
|
+
export declare const revokeMessage: (client: ZapoClient | undefined, target: unknown) => Promise<unknown>;
|
|
12
|
+
export declare const pinMessage: (client: ZapoClient | undefined, target: unknown, durationSecs?: number) => Promise<unknown>;
|
|
13
|
+
export declare const unpinMessage: (client: ZapoClient | undefined, target: unknown) => Promise<unknown>;
|
|
14
|
+
export declare const keepMessage: (client: ZapoClient | undefined, target: unknown) => Promise<unknown>;
|
|
15
|
+
export declare const unkeepMessage: (client: ZapoClient | undefined, target: unknown) => Promise<unknown>;
|
|
16
|
+
export interface PollVoteInput {
|
|
17
|
+
poll: WaSendPollParent;
|
|
18
|
+
selectedOptionNames: readonly string[];
|
|
19
|
+
}
|
|
20
|
+
export declare const votePoll: (client: ZapoClient | undefined, input: PollVoteInput) => Promise<unknown>;
|
|
21
|
+
export declare const sendEvent: (client: ZapoClient | undefined, jid: string | undefined, input: unknown) => Promise<unknown>;
|
|
22
|
+
export declare const respondEvent: (client: ZapoClient | undefined, event: unknown, response: WaSendEventResponseType) => Promise<unknown>;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { MessageError } from "../core/errors.js";
|
|
2
|
+
import { targetChatJidOf, targetIdOf, targetKeyOf } from "../message/target.js";
|
|
3
|
+
const asTargetRecord = (target) => {
|
|
4
|
+
if (!target || typeof target !== "object")
|
|
5
|
+
return undefined;
|
|
6
|
+
const ref = target;
|
|
7
|
+
if (ref.rawNode !== undefined)
|
|
8
|
+
return ref;
|
|
9
|
+
if (ref.key && typeof ref.key === "object")
|
|
10
|
+
return ref;
|
|
11
|
+
return { key: ref };
|
|
12
|
+
};
|
|
13
|
+
const resolveTargetKey = (target) => {
|
|
14
|
+
const record = asTargetRecord(target);
|
|
15
|
+
const key = record?.key ?? target;
|
|
16
|
+
const keyRecord = (key ?? {});
|
|
17
|
+
const remoteJid = keyRecord.remoteJid ?? targetChatJidOf(target);
|
|
18
|
+
const id = keyRecord.id ?? targetIdOf(target);
|
|
19
|
+
if (typeof remoteJid !== "string" || !remoteJid) {
|
|
20
|
+
throw new MessageError("target tidak punya remoteJid — berikan message key atau event pesan masuk", "INVALID_TARGET");
|
|
21
|
+
}
|
|
22
|
+
if (typeof id !== "string" || !id) {
|
|
23
|
+
throw new MessageError("target tidak punya id — berikan message key atau event pesan masuk", "INVALID_TARGET");
|
|
24
|
+
}
|
|
25
|
+
const resolved = {
|
|
26
|
+
remoteJid,
|
|
27
|
+
id,
|
|
28
|
+
fromMe: keyRecord.fromMe === true,
|
|
29
|
+
};
|
|
30
|
+
if (typeof keyRecord.participant === "string" && keyRecord.participant) {
|
|
31
|
+
resolved.participant = keyRecord.participant;
|
|
32
|
+
}
|
|
33
|
+
return resolved;
|
|
34
|
+
};
|
|
35
|
+
const assertClient = (client) => {
|
|
36
|
+
if (!client)
|
|
37
|
+
throw new MessageError("client belum diset", "NO_CLIENT");
|
|
38
|
+
return client;
|
|
39
|
+
};
|
|
40
|
+
export const resolveMessageTargetKey = resolveTargetKey;
|
|
41
|
+
export const editMessage = async (client, target, content) => assertClient(client).message.send(resolveTargetKey(target).remoteJid, content, { editKey: resolveTargetKey(target) });
|
|
42
|
+
export const revokeMessage = async (client, target) => {
|
|
43
|
+
const key = resolveTargetKey(target);
|
|
44
|
+
return assertClient(client).message.send(key.remoteJid, {
|
|
45
|
+
type: "revoke",
|
|
46
|
+
target: { key },
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
export const pinMessage = async (client, target, durationSecs) => {
|
|
50
|
+
const key = resolveTargetKey(target);
|
|
51
|
+
const payload = {
|
|
52
|
+
type: "pin",
|
|
53
|
+
target: { key },
|
|
54
|
+
};
|
|
55
|
+
if (durationSecs !== undefined) {
|
|
56
|
+
if (!Number.isFinite(durationSecs) || durationSecs < 0) {
|
|
57
|
+
throw new MessageError("pin durationSecs harus number >= 0", "VALIDATION");
|
|
58
|
+
}
|
|
59
|
+
payload.durationSecs = durationSecs;
|
|
60
|
+
}
|
|
61
|
+
return assertClient(client).message.send(key.remoteJid, payload);
|
|
62
|
+
};
|
|
63
|
+
export const unpinMessage = async (client, target) => {
|
|
64
|
+
const key = resolveTargetKey(target);
|
|
65
|
+
return assertClient(client).message.send(key.remoteJid, {
|
|
66
|
+
type: "unpin",
|
|
67
|
+
target: { key },
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
export const keepMessage = async (client, target) => {
|
|
71
|
+
const key = resolveTargetKey(target);
|
|
72
|
+
return assertClient(client).message.send(key.remoteJid, {
|
|
73
|
+
type: "keep",
|
|
74
|
+
target: { key },
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
export const unkeepMessage = async (client, target) => {
|
|
78
|
+
const key = resolveTargetKey(target);
|
|
79
|
+
return assertClient(client).message.send(key.remoteJid, {
|
|
80
|
+
type: "unkeep",
|
|
81
|
+
target: { key },
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
export const votePoll = async (client, input) => {
|
|
85
|
+
if (!input || typeof input !== "object") {
|
|
86
|
+
throw new MessageError("poll vote butuh { poll, selectedOptionNames }", "VALIDATION");
|
|
87
|
+
}
|
|
88
|
+
if (!input.poll || typeof input.poll !== "object") {
|
|
89
|
+
throw new MessageError("poll vote butuh poll parent (id, fromMe, authorJid, messageSecret)", "VALIDATION");
|
|
90
|
+
}
|
|
91
|
+
if (typeof input.poll.id !== "string" ||
|
|
92
|
+
!input.poll.id ||
|
|
93
|
+
typeof input.poll.authorJid !== "string" ||
|
|
94
|
+
!input.poll.authorJid ||
|
|
95
|
+
!(input.poll.messageSecret instanceof Uint8Array)) {
|
|
96
|
+
throw new MessageError("poll vote butuh poll parent (id, fromMe, authorJid, messageSecret)", "VALIDATION");
|
|
97
|
+
}
|
|
98
|
+
if (!Array.isArray(input.selectedOptionNames) ||
|
|
99
|
+
!input.selectedOptionNames.length ||
|
|
100
|
+
!input.selectedOptionNames.every((name) => typeof name === "string" && !!name)) {
|
|
101
|
+
throw new MessageError("poll vote selectedOptionNames butuh array string non-kosong", "VALIDATION");
|
|
102
|
+
}
|
|
103
|
+
const remoteJid = targetChatJidOf(input.poll) ?? undefined;
|
|
104
|
+
if (!remoteJid) {
|
|
105
|
+
throw new MessageError("poll vote butuh remoteJid pada poll parent", "INVALID_TARGET");
|
|
106
|
+
}
|
|
107
|
+
return assertClient(client).message.send(remoteJid, {
|
|
108
|
+
type: "poll-vote",
|
|
109
|
+
poll: input.poll,
|
|
110
|
+
selectedOptionNames: [...input.selectedOptionNames],
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
export const sendEvent = async (client, jid, input) => {
|
|
114
|
+
const config = (input ?? {});
|
|
115
|
+
if (typeof jid !== "string" || !jid) {
|
|
116
|
+
throw new MessageError("event butuh jid tujuan — panggil send(jid) atau .defaultTo(jid)", "NO_TARGET");
|
|
117
|
+
}
|
|
118
|
+
if (typeof config.name !== "string" || !config.name.trim()) {
|
|
119
|
+
throw new MessageError("event.name wajib diisi (string non-kosong)", "VALIDATION");
|
|
120
|
+
}
|
|
121
|
+
if (typeof config.startTime !== "number" ||
|
|
122
|
+
!Number.isFinite(config.startTime)) {
|
|
123
|
+
throw new MessageError("event.startTime harus unix seconds (number)", "VALIDATION");
|
|
124
|
+
}
|
|
125
|
+
const payload = {
|
|
126
|
+
type: "event",
|
|
127
|
+
name: config.name,
|
|
128
|
+
startTime: config.startTime,
|
|
129
|
+
};
|
|
130
|
+
if (config.endTime !== undefined) {
|
|
131
|
+
if (typeof config.endTime !== "number" ||
|
|
132
|
+
!Number.isFinite(config.endTime)) {
|
|
133
|
+
throw new MessageError("event.endTime harus unix seconds (number)", "VALIDATION");
|
|
134
|
+
}
|
|
135
|
+
payload.endTime = config.endTime;
|
|
136
|
+
}
|
|
137
|
+
if (config.description !== undefined)
|
|
138
|
+
payload.description = config.description;
|
|
139
|
+
if (config.location !== undefined)
|
|
140
|
+
payload.location = config.location;
|
|
141
|
+
if (config.joinLink !== undefined)
|
|
142
|
+
payload.joinLink = config.joinLink;
|
|
143
|
+
if (config.extraGuestsAllowed !== undefined)
|
|
144
|
+
payload.extraGuestsAllowed = config.extraGuestsAllowed;
|
|
145
|
+
if (config.isScheduleCall !== undefined)
|
|
146
|
+
payload.isScheduleCall = config.isScheduleCall;
|
|
147
|
+
if (config.isCanceled !== undefined)
|
|
148
|
+
payload.isCanceled = config.isCanceled;
|
|
149
|
+
if (config.hasReminder !== undefined)
|
|
150
|
+
payload.hasReminder = config.hasReminder;
|
|
151
|
+
if (config.reminderOffsetSec !== undefined)
|
|
152
|
+
payload.reminderOffsetSec = config.reminderOffsetSec;
|
|
153
|
+
return assertClient(client).message.send(jid, payload);
|
|
154
|
+
};
|
|
155
|
+
export const respondEvent = async (client, event, response) => {
|
|
156
|
+
if (response !== "going" && response !== "not_going" && response !== "maybe") {
|
|
157
|
+
throw new MessageError('event response harus "going" | "not_going" | "maybe"', "VALIDATION");
|
|
158
|
+
}
|
|
159
|
+
const parent = (event ?? {});
|
|
160
|
+
if (typeof parent.id !== "string" ||
|
|
161
|
+
!parent.id ||
|
|
162
|
+
typeof parent.authorJid !== "string" ||
|
|
163
|
+
!parent.authorJid ||
|
|
164
|
+
!(parent.messageSecret instanceof Uint8Array)) {
|
|
165
|
+
throw new MessageError("event response butuh parent event (id, fromMe, authorJid, messageSecret)", "VALIDATION");
|
|
166
|
+
}
|
|
167
|
+
const remoteJid = targetChatJidOf(event) ?? undefined;
|
|
168
|
+
if (!remoteJid) {
|
|
169
|
+
throw new MessageError("event response butuh remoteJid pada parent event", "INVALID_TARGET");
|
|
170
|
+
}
|
|
171
|
+
return assertClient(client).message.send(remoteJid, {
|
|
172
|
+
type: "event-response",
|
|
173
|
+
event: parent,
|
|
174
|
+
response,
|
|
175
|
+
});
|
|
176
|
+
};
|
package/dist/message/reaction.js
CHANGED
|
@@ -44,9 +44,10 @@ export class ReactionBuilder extends BaseBuilder {
|
|
|
44
44
|
throw new MessageError("tujuan reaksi tidak diketahui — panggil send(jid), defaultTo(jid), atau berikan target pesan yang punya remoteJid", "NO_TARGET");
|
|
45
45
|
}
|
|
46
46
|
const content = this.build();
|
|
47
|
+
const merged = this._mergedOptions(options);
|
|
47
48
|
const send = client.message.send.bind(client.message);
|
|
48
|
-
return Object.keys(
|
|
49
|
-
? send(target, content,
|
|
49
|
+
return Object.keys(merged).length
|
|
50
|
+
? send(target, content, merged)
|
|
50
51
|
: send(target, content);
|
|
51
52
|
}
|
|
52
53
|
}
|