@kyyinfinite/zapo-message 1.0.0 → 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 +1220 -328
- 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/media-source.d.ts +1 -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/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, {
|
|
@@ -21,8 +21,7 @@ export type NormalizedMediaSource = NormalizedBytesSource | NormalizedPathSource
|
|
|
21
21
|
export interface NormalizedMediaSourceOptions {
|
|
22
22
|
label?: string;
|
|
23
23
|
}
|
|
24
|
-
declare const
|
|
25
|
-
export declare const isReadableStreamSource: typeof isReadableStream;
|
|
24
|
+
export declare const isReadableStreamSource: (value: unknown) => value is Readable;
|
|
26
25
|
export declare const bufferFromBytes: (bytes: Uint8Array) => Buffer;
|
|
27
26
|
export declare const sniffBytes: (bytes: Uint8Array) => Promise<{
|
|
28
27
|
ext: string;
|
|
@@ -35,4 +34,3 @@ export declare const sniffFile: (path: string) => Promise<{
|
|
|
35
34
|
export declare const readBoundedBytes: (stream: Readable, maxBytes: number, label: string) => Promise<Buffer>;
|
|
36
35
|
export declare const readPathBounded: (path: string, maxBytes: number, label: string) => Promise<Buffer>;
|
|
37
36
|
export declare const normalizeMediaSource: (source: MediaSource | unknown, { label }?: NormalizedMediaSourceOptions) => Promise<NormalizedMediaSource>;
|
|
38
|
-
export {};
|
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
|
}
|