@japofc/baileys 2.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/NOTICE.md +111 -0
- package/README.md +1254 -0
- package/WAProto/index.d.ts +9 -0
- package/WAProto/index.js +142276 -0
- package/engine-requirements.js +13 -0
- package/lib/Builders/A2UI.d.ts +242 -0
- package/lib/Builders/A2UI.js +308 -0
- package/lib/Builders/AIRich.d.ts +105 -0
- package/lib/Builders/AIRich.js +2286 -0
- package/lib/Builders/Button.d.ts +103 -0
- package/lib/Builders/Button.js +883 -0
- package/lib/Builders/ButtonV2.d.ts +28 -0
- package/lib/Builders/ButtonV2.js +144 -0
- package/lib/Builders/ButtonV3.d.ts +25 -0
- package/lib/Builders/ButtonV3.js +184 -0
- package/lib/Builders/Carousel.d.ts +22 -0
- package/lib/Builders/Carousel.js +111 -0
- package/lib/Builders/JapBaileys.d.ts +34 -0
- package/lib/Builders/JapBaileys.js +108 -0
- package/lib/Builders/Poll.d.ts +25 -0
- package/lib/Builders/Poll.js +128 -0
- package/lib/Builders/index.d.ts +17 -0
- package/lib/Builders/index.js +11 -0
- package/lib/Builders/shared.d.ts +67 -0
- package/lib/Builders/shared.js +652 -0
- package/lib/Defaults/index.d.ts +154 -0
- package/lib/Defaults/index.js +178 -0
- package/lib/Framework/Bot.d.ts +61 -0
- package/lib/Framework/Bot.js +248 -0
- package/lib/Framework/Context.d.ts +21 -0
- package/lib/Framework/Context.js +89 -0
- package/lib/Framework/MediaManager.d.ts +17 -0
- package/lib/Framework/MediaManager.js +151 -0
- package/lib/Framework/SessionManager.d.ts +13 -0
- package/lib/Framework/SessionManager.js +33 -0
- package/lib/Framework/StatsManager.d.ts +26 -0
- package/lib/Framework/StatsManager.js +119 -0
- package/lib/Framework/Store/SQLiteStore.d.ts +11 -0
- package/lib/Framework/Store/SQLiteStore.js +73 -0
- package/lib/Framework/index.d.ts +9 -0
- package/lib/Framework/index.js +10 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +11 -0
- package/lib/Signal/Group/group-session-builder.d.ts +7 -0
- package/lib/Signal/Group/group-session-builder.js +29 -0
- package/lib/Signal/Group/group_cipher.d.ts +10 -0
- package/lib/Signal/Group/group_cipher.js +81 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +11 -0
- package/lib/Signal/Group/keyhelper.d.ts +6 -0
- package/lib/Signal/Group/keyhelper.js +17 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +25 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +65 -0
- package/lib/Signal/Group/sender-key-name.d.ts +11 -0
- package/lib/Signal/Group/sender-key-name.js +47 -0
- package/lib/Signal/Group/sender-key-record.d.ts +12 -0
- package/lib/Signal/Group/sender-key-record.js +40 -0
- package/lib/Signal/Group/sender-key-state.d.ts +16 -0
- package/lib/Signal/Group/sender-key-state.js +83 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/Group/sender-message-key.js +25 -0
- package/lib/Signal/libsignal.d.ts +54 -0
- package/lib/Signal/libsignal.js +430 -0
- package/lib/Signal/lid-mapping.d.ts +20 -0
- package/lib/Signal/lid-mapping.js +276 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/lib/Socket/Client/index.js +2 -0
- package/lib/Socket/Client/types.d.ts +5 -0
- package/lib/Socket/Client/types.js +10 -0
- package/lib/Socket/Client/websocket.d.ts +12 -0
- package/lib/Socket/Client/websocket.js +53 -0
- package/lib/Socket/business.d.ts +395 -0
- package/lib/Socket/business.js +379 -0
- package/lib/Socket/chats.d.ts +136 -0
- package/lib/Socket/chats.js +1327 -0
- package/lib/Socket/communities.d.ts +562 -0
- package/lib/Socket/communities.js +439 -0
- package/lib/Socket/dugong.d.ts +117 -0
- package/lib/Socket/dugong.js +798 -0
- package/lib/Socket/groups.d.ts +285 -0
- package/lib/Socket/groups.js +354 -0
- package/lib/Socket/index.d.ts +585 -0
- package/lib/Socket/index.js +52 -0
- package/lib/Socket/messages-recv.d.ts +333 -0
- package/lib/Socket/messages-recv.js +1781 -0
- package/lib/Socket/messages-send.d.ts +353 -0
- package/lib/Socket/messages-send.js +1524 -0
- package/lib/Socket/mex.d.ts +1 -0
- package/lib/Socket/mex.js +41 -0
- package/lib/Socket/newsletter.d.ts +286 -0
- package/lib/Socket/newsletter.js +364 -0
- package/lib/Socket/socket.d.ts +60 -0
- package/lib/Socket/socket.js +1012 -0
- package/lib/Socket/username.d.ts +82 -0
- package/lib/Socket/username.js +159 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +3 -0
- package/lib/Store/make-in-memory-store.d.ts +62 -0
- package/lib/Store/make-in-memory-store.js +428 -0
- package/lib/Store/make-ordered-dictionary.d.ts +12 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +23 -0
- package/lib/Types/Auth.d.ts +117 -0
- package/lib/Types/Auth.js +1 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Call.js +1 -0
- package/lib/Types/Chat.d.ts +124 -0
- package/lib/Types/Chat.js +7 -0
- package/lib/Types/Contact.d.ts +26 -0
- package/lib/Types/Contact.js +1 -0
- package/lib/Types/Events.d.ts +256 -0
- package/lib/Types/Events.js +1 -0
- package/lib/Types/GroupMetadata.d.ts +71 -0
- package/lib/Types/GroupMetadata.js +1 -0
- package/lib/Types/Label.d.ts +5 -0
- package/lib/Types/Label.js +24 -0
- package/lib/Types/LabelAssociation.d.ts +6 -0
- package/lib/Types/LabelAssociation.js +6 -0
- package/lib/Types/Message.d.ts +62 -0
- package/lib/Types/Message.js +17 -0
- package/lib/Types/Mex.d.ts +2 -0
- package/lib/Types/Mex.js +38 -0
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Product.js +1 -0
- package/lib/Types/RichType.d.ts +2 -0
- package/lib/Types/RichType.js +22 -0
- package/lib/Types/Signal.d.ts +87 -0
- package/lib/Types/Signal.js +1 -0
- package/lib/Types/Socket.d.ts +138 -0
- package/lib/Types/Socket.js +1 -0
- package/lib/Types/State.d.ts +8 -0
- package/lib/Types/State.js +55 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/index.d.ts +68 -0
- package/lib/Types/index.js +27 -0
- package/lib/Utils/MessageBuilder.d.ts +2 -0
- package/lib/Utils/MessageBuilder.js +2 -0
- package/lib/Utils/PersistentStore.d.ts +60 -0
- package/lib/Utils/PersistentStore.js +592 -0
- package/lib/Utils/anti-delete.d.ts +74 -0
- package/lib/Utils/anti-delete.js +221 -0
- package/lib/Utils/auth-secure.d.ts +86 -0
- package/lib/Utils/auth-secure.js +764 -0
- package/lib/Utils/auth-utils.d.ts +57 -0
- package/lib/Utils/auth-utils.js +306 -0
- package/lib/Utils/auto-reply.d.ts +47 -0
- package/lib/Utils/auto-reply.js +157 -0
- package/lib/Utils/baileys-event-stream.d.ts +8 -0
- package/lib/Utils/baileys-event-stream.js +62 -0
- package/lib/Utils/browser-utils.d.ts +8 -0
- package/lib/Utils/browser-utils.js +27 -0
- package/lib/Utils/business.d.ts +49 -0
- package/lib/Utils/business.js +239 -0
- package/lib/Utils/button-helper-utils.d.ts +53 -0
- package/lib/Utils/button-helper-utils.js +312 -0
- package/lib/Utils/button-sender.d.ts +54 -0
- package/lib/Utils/button-sender.js +822 -0
- package/lib/Utils/chat-control.d.ts +159 -0
- package/lib/Utils/chat-control.js +230 -0
- package/lib/Utils/chat-history-helpers.d.ts +21 -0
- package/lib/Utils/chat-history-helpers.js +70 -0
- package/lib/Utils/chat-utils.d.ts +407 -0
- package/lib/Utils/chat-utils.js +885 -0
- package/lib/Utils/companion-reg-client-utils.d.ts +4 -0
- package/lib/Utils/companion-reg-client-utils.js +39 -0
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/crypto.js +147 -0
- package/lib/Utils/decode-wa-message.d.ts +83 -0
- package/lib/Utils/decode-wa-message.js +316 -0
- package/lib/Utils/event-buffer.d.ts +12 -0
- package/lib/Utils/event-buffer.js +635 -0
- package/lib/Utils/generics.d.ts +69 -0
- package/lib/Utils/generics.js +438 -0
- package/lib/Utils/history-share.d.ts +11 -0
- package/lib/Utils/history-share.js +70 -0
- package/lib/Utils/history.d.ts +90 -0
- package/lib/Utils/history.js +146 -0
- package/lib/Utils/humanizer.d.ts +12 -0
- package/lib/Utils/humanizer.js +73 -0
- package/lib/Utils/identity-change-handler.d.ts +13 -0
- package/lib/Utils/identity-change-handler.js +49 -0
- package/lib/Utils/index.d.ts +57 -0
- package/lib/Utils/index.js +56 -0
- package/lib/Utils/jid-tools.d.ts +6 -0
- package/lib/Utils/jid-tools.js +77 -0
- package/lib/Utils/link-preview.d.ts +12 -0
- package/lib/Utils/link-preview.js +84 -0
- package/lib/Utils/logger.d.ts +4 -0
- package/lib/Utils/logger.js +2 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +26 -0
- package/lib/Utils/make-mutex.d.ts +6 -0
- package/lib/Utils/make-mutex.js +32 -0
- package/lib/Utils/media-messages.d.ts +18 -0
- package/lib/Utils/media-messages.js +70 -0
- package/lib/Utils/media-set.d.ts +13 -0
- package/lib/Utils/media-set.js +171 -0
- package/lib/Utils/message-kind.d.ts +32 -0
- package/lib/Utils/message-kind.js +136 -0
- package/lib/Utils/message-retry-manager.d.ts +79 -0
- package/lib/Utils/message-retry-manager.js +264 -0
- package/lib/Utils/message-search.d.ts +44 -0
- package/lib/Utils/message-search.js +188 -0
- package/lib/Utils/messages-media.d.ts +135 -0
- package/lib/Utils/messages-media.js +868 -0
- package/lib/Utils/messages.d.ts +44 -0
- package/lib/Utils/messages.js +2326 -0
- package/lib/Utils/meta-ai.d.ts +13 -0
- package/lib/Utils/meta-ai.js +74 -0
- package/lib/Utils/mini-app.d.ts +35 -0
- package/lib/Utils/mini-app.js +213 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +200 -0
- package/lib/Utils/offline-node-processor.d.ts +9 -0
- package/lib/Utils/offline-node-processor.js +39 -0
- package/lib/Utils/past-participants.d.ts +14 -0
- package/lib/Utils/past-participants.js +40 -0
- package/lib/Utils/pre-key-manager.d.ts +25 -0
- package/lib/Utils/pre-key-manager.js +105 -0
- package/lib/Utils/process-message.d.ts +82 -0
- package/lib/Utils/process-message.js +808 -0
- package/lib/Utils/qr-render.d.ts +59 -0
- package/lib/Utils/qr-render.js +179 -0
- package/lib/Utils/qrcodegen.d.ts +79 -0
- package/lib/Utils/qrcodegen.js +848 -0
- package/lib/Utils/reporting-utils.d.ts +12 -0
- package/lib/Utils/reporting-utils.js +257 -0
- package/lib/Utils/rich-message-utils.d.ts +48 -0
- package/lib/Utils/rich-message-utils.js +444 -0
- package/lib/Utils/router.d.ts +37 -0
- package/lib/Utils/router.js +165 -0
- package/lib/Utils/scheduled-posts.d.ts +30 -0
- package/lib/Utils/scheduled-posts.js +110 -0
- package/lib/Utils/scheduling.d.ts +42 -0
- package/lib/Utils/scheduling.js +139 -0
- package/lib/Utils/signal.d.ts +82 -0
- package/lib/Utils/signal.js +200 -0
- package/lib/Utils/stanza-ack.d.ts +16 -0
- package/lib/Utils/stanza-ack.js +37 -0
- package/lib/Utils/status.d.ts +50 -0
- package/lib/Utils/status.js +107 -0
- package/lib/Utils/stickerpack.d.ts +51 -0
- package/lib/Utils/stickerpack.js +274 -0
- package/lib/Utils/sync-action-utils.d.ts +2 -0
- package/lib/Utils/sync-action-utils.js +48 -0
- package/lib/Utils/tag.d.ts +12 -0
- package/lib/Utils/tag.js +44 -0
- package/lib/Utils/tc-token-utils.d.ts +29 -0
- package/lib/Utils/tc-token-utils.js +162 -0
- package/lib/Utils/templates.d.ts +76 -0
- package/lib/Utils/templates.js +150 -0
- package/lib/Utils/transcribe.d.ts +12 -0
- package/lib/Utils/transcribe.js +107 -0
- package/lib/Utils/use-cache-manager-auth-state.d.ts +13 -0
- package/lib/Utils/use-cache-manager-auth-state.js +81 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
- package/lib/Utils/use-multi-file-auth-state.js +166 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +10 -0
- package/lib/Utils/use-single-file-auth-state.js +113 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/lib/Utils/use-sqlite-auth-state.js +169 -0
- package/lib/Utils/validate-connection.d.ts +42 -0
- package/lib/Utils/validate-connection.js +198 -0
- package/lib/Utils/vcard.d.ts +58 -0
- package/lib/Utils/vcard.js +104 -0
- package/lib/Utils/voice-note.d.ts +15 -0
- package/lib/Utils/voice-note.js +63 -0
- package/lib/VoIP/audio-feeder.d.ts +18 -0
- package/lib/VoIP/audio-feeder.js +160 -0
- package/lib/VoIP/call-recorder.d.ts +13 -0
- package/lib/VoIP/call-recorder.js +73 -0
- package/lib/VoIP/index.d.ts +86 -0
- package/lib/VoIP/index.js +611 -0
- package/lib/VoIP/relay-transport.d.ts +43 -0
- package/lib/VoIP/relay-transport.js +563 -0
- package/lib/VoIP/signaling.d.ts +26 -0
- package/lib/VoIP/signaling.js +662 -0
- package/lib/VoIP/types.d.ts +69 -0
- package/lib/VoIP/types.js +17 -0
- package/lib/VoIP/wasm-engine.d.ts +120 -0
- package/lib/VoIP/wasm-engine.js +1358 -0
- package/lib/VoIP/worker-bootstrap.d.ts +4 -0
- package/lib/VoIP/worker-bootstrap.js +1046 -0
- package/lib/WABinary/constants.d.ts +61 -0
- package/lib/WABinary/constants.js +1466 -0
- package/lib/WABinary/decode.d.ts +9 -0
- package/lib/WABinary/decode.js +261 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +219 -0
- package/lib/WABinary/generic-utils.d.ts +74 -0
- package/lib/WABinary/generic-utils.js +276 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +5 -0
- package/lib/WABinary/jid-utils.d.ts +28 -0
- package/lib/WABinary/jid-utils.js +95 -0
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.js +1 -0
- package/lib/WAM/BinaryInfo.d.ts +7 -0
- package/lib/WAM/BinaryInfo.js +9 -0
- package/lib/WAM/constants.d.ts +34926 -0
- package/lib/WAM/constants.js +22852 -0
- package/lib/WAM/encode.d.ts +1 -0
- package/lib/WAM/encode.js +149 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +3 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +51 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +29 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +62 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
- package/lib/WAUSync/Protocols/index.d.ts +7 -0
- package/lib/WAUSync/Protocols/index.js +7 -0
- package/lib/WAUSync/USyncQuery.d.ts +20 -0
- package/lib/WAUSync/USyncQuery.js +121 -0
- package/lib/WAUSync/USyncUser.d.ts +16 -0
- package/lib/WAUSync/USyncUser.js +30 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +3 -0
- package/lib/assets/wasm/loader.d.ts +5 -0
- package/lib/assets/wasm/loader.js +5 -0
- package/lib/assets/wasm/whatsapp.wasm +0 -0
- package/lib/assets/wasm/worker-modules.d.ts +5 -0
- package/lib/assets/wasm/worker-modules.js +273 -0
- package/lib/index.d.ts +18 -0
- package/lib/index.js +23 -0
- package/package.json +180 -0
- package/postinstall-banner.js +82 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { BaseBuilder, RowBuilder } from './shared.js';
|
|
2
|
+
|
|
3
|
+
export interface ButtonV2BuildOptions {
|
|
4
|
+
/** Default true — some clients need it to render legacy buttonsMessage. */
|
|
5
|
+
viewOnce?: boolean;
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Legacy `buttonsMessage` builder (quick-reply buttons + location-fallback header). */
|
|
10
|
+
export class ButtonV2 extends BaseBuilder {
|
|
11
|
+
constructor(client: any);
|
|
12
|
+
/** Add a simple quick-reply button. buttonId defaults to a random uuid. */
|
|
13
|
+
addButton(displayText?: string, buttonId?: string): this;
|
|
14
|
+
/** Push a raw pre-built button object. */
|
|
15
|
+
addRawButton(obj: Record<string, any>): this;
|
|
16
|
+
/** Header thumbnail (fallback location-header image). */
|
|
17
|
+
setThumbnail(path: string | Buffer): this;
|
|
18
|
+
/** Raw pre-built header media object. */
|
|
19
|
+
setMedia(obj: Record<string, any>): this;
|
|
20
|
+
/** Alias for addButton(). */
|
|
21
|
+
button(displayText?: string, buttonId?: string): this;
|
|
22
|
+
/** Group buttons via a RowBuilder callback. */
|
|
23
|
+
row(cb: (row: RowBuilder) => void): this;
|
|
24
|
+
/** Build the WAMessage without sending. */
|
|
25
|
+
build(jid: string, options?: ButtonV2BuildOptions): Promise<any>;
|
|
26
|
+
/** Build and send. Requires at least one button. */
|
|
27
|
+
send(jid: string, options?: Record<string, any>): Promise<any>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { BaseBuilder, Toolkit, RowBuilder, generateWAMessageFromContent, prepareWAMessageMedia, generateMessageIDV2, crypto } from './shared.js';
|
|
2
|
+
class ButtonV2 extends BaseBuilder {
|
|
3
|
+
#client;
|
|
4
|
+
|
|
5
|
+
/** @param {import('../../WAProto/index.js').WASocket} client Active Baileys socket. */
|
|
6
|
+
constructor(client) {
|
|
7
|
+
super();
|
|
8
|
+
if (!client) {
|
|
9
|
+
throw new Error('Socket is required');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
this.#client = client;
|
|
13
|
+
this._image;
|
|
14
|
+
this._data;
|
|
15
|
+
this._buttons = [];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Add a simple quick-reply button. @param {string} displayText Label. @param {string} [buttonId] Defaults to a random uuid. */
|
|
19
|
+
addButton(displayText = '', buttonId = crypto.randomUUID()) {
|
|
20
|
+
if (!displayText) throw new TypeError('addButton(displayText) requires a non-empty label');
|
|
21
|
+
this._buttons.push({
|
|
22
|
+
buttonId,
|
|
23
|
+
buttonText: { displayText },
|
|
24
|
+
type: 1,
|
|
25
|
+
});
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Push a raw pre-built button object, bypassing the `addButton()` shorthand. */
|
|
30
|
+
addRawButton(obj) {
|
|
31
|
+
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
|
|
32
|
+
throw new TypeError('Buttons must be a plain object');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
this._buttons.push(obj);
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Set the header thumbnail (used as a fallback location-header image when no `setMedia()` header is given). */
|
|
40
|
+
setThumbnail(path) {
|
|
41
|
+
if (!path) throw new Error('Url or buffer needed');
|
|
42
|
+
this._image = path;
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Set a raw pre-built header media object for the buttons message. */
|
|
47
|
+
setMedia(obj) {
|
|
48
|
+
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
|
|
49
|
+
throw new TypeError('Media must be a plain object');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this._data = obj;
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Alias for addButton() — shorthand parity with RowBuilder#button(). */
|
|
57
|
+
button(displayText, buttonId) {
|
|
58
|
+
return this.addButton(displayText, buttonId);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* JAP@Add 29-08-26 --- Fluent row helper ported from the RowBuilder class (already
|
|
63
|
+
* present but previously unwired into ButtonV2). Lets callers group buttons via a
|
|
64
|
+
* callback instead of chaining addButton() calls one at a time.
|
|
65
|
+
* @param {(row: RowBuilder) => void} cb
|
|
66
|
+
*/
|
|
67
|
+
row(cb) {
|
|
68
|
+
const r = new RowBuilder();
|
|
69
|
+
cb(r);
|
|
70
|
+
r.buttons.forEach((b) => this._buttons.push(b));
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// JAP@Fix 22-08-26 (v4.7) --- _thumbnail was computed unconditionally (fetch + resize) even
|
|
75
|
+
// when setMedia() is used, in which case the location-fallback header (the only place
|
|
76
|
+
// _thumbnail is used) never runs at all — wasted network/CPU work on every build() call.
|
|
77
|
+
// Now only computed when it'll actually be used. Also: `viewOnce` was hardcoded true with no
|
|
78
|
+
// way to opt out (kept as the default — some clients need it to render legacy buttonsMessage
|
|
79
|
+
// at all — but it's now a `{ viewOnce = true }` option instead of a hardcoded literal).
|
|
80
|
+
/** @returns {Promise<Record<string, any>>} The generated WAMessage (without sending). @param {boolean} [viewOnce] Default true — some clients require this for legacy buttonsMessage to render; pass false to send it as a normal (non-disappearing) message. */
|
|
81
|
+
async build(jid, { viewOnce = true, ...options } = {}) {
|
|
82
|
+
const _thumbnail = !this._data && this._image ? await Toolkit.resize(Buffer.isBuffer(this._image) ? this._image : await Toolkit.fetchBuffer(this._image, {}, { silent: true }), 300, 300) : null;
|
|
83
|
+
const msg = generateWAMessageFromContent(
|
|
84
|
+
jid,
|
|
85
|
+
{
|
|
86
|
+
...this._extraPayload,
|
|
87
|
+
buttonsMessage: {
|
|
88
|
+
contentText: this._body,
|
|
89
|
+
footerText: this._footer,
|
|
90
|
+
...(this._data
|
|
91
|
+
? this._data
|
|
92
|
+
: {
|
|
93
|
+
headerType: 6,
|
|
94
|
+
locationMessage: {
|
|
95
|
+
degreesLatitude: 0,
|
|
96
|
+
degreesLongitude: 0,
|
|
97
|
+
name: this._title,
|
|
98
|
+
address: this._subtitle,
|
|
99
|
+
jpegThumbnail: _thumbnail,
|
|
100
|
+
},
|
|
101
|
+
}),
|
|
102
|
+
viewOnce,
|
|
103
|
+
contextInfo: this._contextInfo,
|
|
104
|
+
buttons: [...this._buttons],
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
{ ...options }
|
|
108
|
+
);
|
|
109
|
+
return msg;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Build and send this buttons message. @param {string} jid Destination chat/group jid. */
|
|
113
|
+
async send(jid, { ...options } = {}) {
|
|
114
|
+
if (this._buttons.length < 1) throw new Error('ButtonV2 requires at least one button');
|
|
115
|
+
const msg = await this.build(jid, options);
|
|
116
|
+
|
|
117
|
+
await this.#client.relayMessage(msg.key.remoteJid, msg.message, {
|
|
118
|
+
messageId: msg.key.id,
|
|
119
|
+
additionalNodes: [
|
|
120
|
+
{
|
|
121
|
+
tag: 'biz',
|
|
122
|
+
attrs: {},
|
|
123
|
+
content: [
|
|
124
|
+
{
|
|
125
|
+
tag: 'interactive',
|
|
126
|
+
attrs: { type: 'native_flow', v: '1' },
|
|
127
|
+
content: [{ tag: 'native_flow', attrs: { v: '9', name: 'mixed' } }],
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
...options,
|
|
133
|
+
});
|
|
134
|
+
return msg;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Legacy `templateMessage` / `hydratedFourRowTemplate` builder — WA's Generation-1
|
|
140
|
+
* button protocol (predates the nativeFlow format that Button/ButtonV2 use).
|
|
141
|
+
* Capped at 3 buttons (quickReply/url/call only), no interactive list/flow support.
|
|
142
|
+
* Ported from MessageBuilderV4.7.
|
|
143
|
+
*/
|
|
144
|
+
export { ButtonV2 };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { BaseBuilder } from './shared.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Legacy `templateMessage` / `hydratedFourRowTemplate` builder — WA's Generation-1
|
|
5
|
+
* button protocol (predates the nativeFlow format Button/ButtonV2 use). Capped at
|
|
6
|
+
* 3 buttons (quickReply/url/call only), no interactive list/flow support.
|
|
7
|
+
*/
|
|
8
|
+
export class ButtonV3 extends BaseBuilder {
|
|
9
|
+
constructor(client: any);
|
|
10
|
+
/** Load an existing templateMessage (e.g. from a fetched/quoted message) for editing. */
|
|
11
|
+
loadFrom(msg: Record<string, any>): this;
|
|
12
|
+
setImage(path: string | Buffer, options?: Record<string, any>): this;
|
|
13
|
+
setVideo(path: string | Buffer, options?: Record<string, any>): this;
|
|
14
|
+
setDocument(path: string | Buffer, options?: Record<string, any>): this;
|
|
15
|
+
setMedia(obj: Record<string, any>): this;
|
|
16
|
+
clearButtons(): this;
|
|
17
|
+
/** Max 3 buttons — throws past the limit. */
|
|
18
|
+
addButton(hydratedButton: Record<string, any>): this;
|
|
19
|
+
addReply(display_text?: string, id?: string): this;
|
|
20
|
+
addUrl(display_text?: string, url?: string, options?: Record<string, any>): this;
|
|
21
|
+
addCall(display_text?: string, phone_number?: string): this;
|
|
22
|
+
toTemplate(): Promise<Record<string, any>>;
|
|
23
|
+
build(jid: string, options?: Record<string, any>): Promise<Record<string, any>>;
|
|
24
|
+
send(jid: string, options?: Record<string, any>): Promise<any>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { BaseBuilder, generateWAMessageFromContent, prepareWAMessageMedia, generateMessageIDV2, crypto } from './shared.js';
|
|
2
|
+
class ButtonV3 extends BaseBuilder {
|
|
3
|
+
#client;
|
|
4
|
+
|
|
5
|
+
/** @param {import('../../WAProto/index.js').WASocket} client Active Baileys socket. */
|
|
6
|
+
constructor(client) {
|
|
7
|
+
super();
|
|
8
|
+
if (!client) {
|
|
9
|
+
throw new Error('Socket is required');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
this.#client = client;
|
|
13
|
+
this._data;
|
|
14
|
+
this._mediaHeaderType = null;
|
|
15
|
+
this._buttons = [];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Load an existing templateMessage (e.g. from a fetched/quoted message) for editing. */
|
|
19
|
+
loadFrom(msg) {
|
|
20
|
+
if (!msg) throw new Error('templateMessage needed');
|
|
21
|
+
if (!msg.templateMessage) throw new Error('templateMessage not found');
|
|
22
|
+
|
|
23
|
+
const { templateMessage, ...extraPayload } = msg;
|
|
24
|
+
const hft = templateMessage.hydratedFourRowTemplate || {};
|
|
25
|
+
|
|
26
|
+
this._title = hft.hydratedTitleText || '';
|
|
27
|
+
this._body = hft.hydratedContentText || '';
|
|
28
|
+
this._footer = hft.hydratedFooterText || '';
|
|
29
|
+
this._contextInfo = templateMessage.contextInfo || {};
|
|
30
|
+
this._extraPayload = extraPayload;
|
|
31
|
+
|
|
32
|
+
this._buttons = Array.isArray(hft.hydratedButtons)
|
|
33
|
+
? hft.hydratedButtons.map((button) => ({ ...button }))
|
|
34
|
+
: [];
|
|
35
|
+
|
|
36
|
+
if (hft.imageMessage) {
|
|
37
|
+
this._data = { imageMessage: hft.imageMessage };
|
|
38
|
+
this._mediaHeaderType = 'imageMessage';
|
|
39
|
+
} else if (hft.videoMessage) {
|
|
40
|
+
this._data = { videoMessage: hft.videoMessage };
|
|
41
|
+
this._mediaHeaderType = 'videoMessage';
|
|
42
|
+
} else if (hft.documentMessage) {
|
|
43
|
+
this._data = { documentMessage: hft.documentMessage };
|
|
44
|
+
this._mediaHeaderType = 'documentMessage';
|
|
45
|
+
} else if (hft.locationMessage) {
|
|
46
|
+
this._data = { locationMessage: hft.locationMessage };
|
|
47
|
+
this._mediaHeaderType = 'locationMessage';
|
|
48
|
+
} else {
|
|
49
|
+
this._data = undefined;
|
|
50
|
+
this._mediaHeaderType = null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
setImage(path, options = {}) {
|
|
57
|
+
if (!path) throw new Error('Url or buffer needed');
|
|
58
|
+
this._data = Buffer.isBuffer(path)
|
|
59
|
+
? { image: path, ...options }
|
|
60
|
+
: { image: { url: path }, ...options };
|
|
61
|
+
this._mediaHeaderType = 'imageMessage';
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
setVideo(path, options = {}) {
|
|
66
|
+
if (!path) throw new Error('Url or buffer needed');
|
|
67
|
+
this._data = Buffer.isBuffer(path)
|
|
68
|
+
? { video: path, ...options }
|
|
69
|
+
: { video: { url: path }, ...options };
|
|
70
|
+
this._mediaHeaderType = 'videoMessage';
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
setDocument(path, options = {}) {
|
|
75
|
+
if (!path) throw new Error('Url or buffer needed');
|
|
76
|
+
this._data = Buffer.isBuffer(path)
|
|
77
|
+
? { document: path, ...options }
|
|
78
|
+
: { document: { url: path }, ...options };
|
|
79
|
+
this._mediaHeaderType = 'documentMessage';
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
setMedia(obj) {
|
|
84
|
+
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
|
|
85
|
+
throw new TypeError('Media must be a plain object');
|
|
86
|
+
}
|
|
87
|
+
this._data = obj;
|
|
88
|
+
this._mediaHeaderType = null; // caller is expected to pass an already-resolved shape
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
clearButtons() {
|
|
93
|
+
this._buttons = [];
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
addButton(hydratedButton) {
|
|
98
|
+
if (this._buttons.length >= 3) {
|
|
99
|
+
throw new Error('ButtonV3 (TemplateMessage) supports a maximum of 3 buttons');
|
|
100
|
+
}
|
|
101
|
+
this._buttons.push({ index: this._buttons.length + 1, ...hydratedButton });
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
addReply(display_text = '', id = '') {
|
|
106
|
+
return this.addButton({
|
|
107
|
+
quickReplyButton: { displayText: display_text, id },
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
addUrl(display_text = '', url = '', options = {}) {
|
|
112
|
+
return this.addButton({
|
|
113
|
+
urlButton: { displayText: display_text, url, ...options },
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
addCall(display_text = '', phone_number = '') {
|
|
118
|
+
return this.addButton({
|
|
119
|
+
callButton: { displayText: display_text, phoneNumber: phone_number },
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async toTemplate() {
|
|
124
|
+
let mediaFields = {};
|
|
125
|
+
|
|
126
|
+
if (this._data) {
|
|
127
|
+
const alreadyResolved =
|
|
128
|
+
this._data.imageMessage || this._data.videoMessage ||
|
|
129
|
+
this._data.documentMessage || this._data.locationMessage;
|
|
130
|
+
|
|
131
|
+
mediaFields = alreadyResolved
|
|
132
|
+
? this._data
|
|
133
|
+
: await prepareWAMessageMedia(this._data, {
|
|
134
|
+
upload: this.#client.waUploadToServer,
|
|
135
|
+
}).catch((e) => {
|
|
136
|
+
if (String(e).includes('Invalid media type')) return this._data;
|
|
137
|
+
throw e;
|
|
138
|
+
});
|
|
139
|
+
} else if (this._title) {
|
|
140
|
+
mediaFields = { hydratedTitleText: this._title };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
hydratedContentText: this._body,
|
|
145
|
+
hydratedFooterText: this._footer,
|
|
146
|
+
hydratedButtons: this._buttons,
|
|
147
|
+
...mediaFields,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async build(jid, { messageId, ...options } = {}) {
|
|
152
|
+
const hydratedFourRowTemplate = await this.toTemplate();
|
|
153
|
+
|
|
154
|
+
return generateWAMessageFromContent(
|
|
155
|
+
jid,
|
|
156
|
+
{
|
|
157
|
+
...this._extraPayload,
|
|
158
|
+
templateMessage: {
|
|
159
|
+
hydratedFourRowTemplate,
|
|
160
|
+
contextInfo: this._contextInfo,
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
{ messageId: messageId || generateMessageIDV2(), ...options },
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async send(jid, { messageId, additionalNodes = [], ...options } = {}) {
|
|
168
|
+
if (this._buttons.length < 1)
|
|
169
|
+
throw new Error('ButtonV3 requires at least one button');
|
|
170
|
+
const msg = await this.build(jid, { messageId, ...options });
|
|
171
|
+
|
|
172
|
+
// TemplateMessage predates the nativeFlow protocol and does not need the
|
|
173
|
+
// "biz"/"native_flow" additionalNodes hack that Button/ButtonV2 use.
|
|
174
|
+
await this.#client.relayMessage(msg.key.remoteJid, msg.message, {
|
|
175
|
+
messageId: msg.key.id,
|
|
176
|
+
additionalNodes,
|
|
177
|
+
...options,
|
|
178
|
+
});
|
|
179
|
+
return msg;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Carousel of interactive cards (each with its own header media + optional buttons), scrollable horizontally in-chat. */
|
|
184
|
+
export { ButtonV3 };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { BaseBuilder } from './shared.js';
|
|
2
|
+
|
|
3
|
+
/** One carousel card — typically built via `new Button(client).setImage(…).addUrl(…).toCard()`. */
|
|
4
|
+
export interface CarouselCard {
|
|
5
|
+
header: {
|
|
6
|
+
hasMediaAttachment: boolean;
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
};
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Chainable carousel builder (max 10 cards — enforced, WA truncates beyond that). */
|
|
13
|
+
export class Carousel extends BaseBuilder {
|
|
14
|
+
static MAX_CARDS: number;
|
|
15
|
+
constructor(client: any);
|
|
16
|
+
/** Add one card, or an array of cards. Each must carry header media. */
|
|
17
|
+
addCard(card: CarouselCard | CarouselCard[]): this;
|
|
18
|
+
/** Build the WAMessage without sending. */
|
|
19
|
+
build(jid: string, options?: Record<string, any>): any;
|
|
20
|
+
/** Build and send. Requires at least one card. */
|
|
21
|
+
send(jid: string, options?: Record<string, any>): Promise<any>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { BaseBuilder, generateWAMessageFromContent, prepareWAMessageMedia, generateMessageIDV2, crypto } from './shared.js';
|
|
2
|
+
class Carousel extends BaseBuilder {
|
|
3
|
+
#client;
|
|
4
|
+
|
|
5
|
+
// JAP@Add 22-08-26 (v4.7) --- WhatsApp caps carousels at 10 cards; anything beyond
|
|
6
|
+
// that is silently truncated client-side, so failing fast here is more useful than
|
|
7
|
+
// shipping a carousel that quietly loses cards.
|
|
8
|
+
static MAX_CARDS = 10;
|
|
9
|
+
|
|
10
|
+
/** @param {import('../../WAProto/index.js').WASocket} client Active Baileys socket. */
|
|
11
|
+
constructor(client) {
|
|
12
|
+
super();
|
|
13
|
+
if (!client) {
|
|
14
|
+
throw new Error('Socket is required');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
this.#client = client;
|
|
18
|
+
this._cards = [];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Add one card, or an array of cards, to the carousel.
|
|
23
|
+
* @param {Record<string, any>|Record<string, any>[]} card A card (or array of cards) with `header.hasMediaAttachment: true`
|
|
24
|
+
* — typically built via `new Button(client).setImage(...).addUrl(...).toCard()`.
|
|
25
|
+
*/
|
|
26
|
+
addCard(card) {
|
|
27
|
+
const cards = Array.isArray(card) ? card : [card];
|
|
28
|
+
const baseIndex = this._cards.length;
|
|
29
|
+
|
|
30
|
+
for (const [index, c] of cards.entries()) {
|
|
31
|
+
if (!c?.header?.hasMediaAttachment) {
|
|
32
|
+
throw new Error(`Card [${baseIndex + index}] must include an image or video in header`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (this._cards.length + cards.length > Carousel.MAX_CARDS) {
|
|
37
|
+
throw new Error(`Carousel supports at most ${Carousel.MAX_CARDS} cards (got ${this._cards.length + cards.length})`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
this._cards.push(...cards);
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** @returns {Record<string, any>} The generated WAMessage (without sending). */
|
|
45
|
+
build(jid, { ...options } = {}) {
|
|
46
|
+
return generateWAMessageFromContent(
|
|
47
|
+
jid,
|
|
48
|
+
{
|
|
49
|
+
...this._extraPayload,
|
|
50
|
+
interactiveMessage: {
|
|
51
|
+
header: {
|
|
52
|
+
hasMediaAttachment: false,
|
|
53
|
+
},
|
|
54
|
+
body: { text: this._body },
|
|
55
|
+
footer: { text: this._footer },
|
|
56
|
+
contextInfo: this._contextInfo,
|
|
57
|
+
carouselMessage: {
|
|
58
|
+
cards: this._cards,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
{ ...options }
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Build and send this carousel. @param {string} jid Destination chat/group jid. */
|
|
67
|
+
async send(jid, { ...options } = {}) {
|
|
68
|
+
if (this._cards.length === 0) throw new Error('Carousel requires at least one card (use addCard())');
|
|
69
|
+
|
|
70
|
+
const msg = this.build(jid, options);
|
|
71
|
+
|
|
72
|
+
await this.#client.relayMessage(msg.key.remoteJid, msg.message, {
|
|
73
|
+
messageId: msg.key.id,
|
|
74
|
+
additionalNodes: [
|
|
75
|
+
{
|
|
76
|
+
tag: 'biz',
|
|
77
|
+
attrs: {},
|
|
78
|
+
content: [
|
|
79
|
+
{
|
|
80
|
+
tag: 'interactive',
|
|
81
|
+
attrs: { type: 'native_flow', v: '1' },
|
|
82
|
+
content: [{ tag: 'native_flow', attrs: { v: '9', name: 'mixed' } }],
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
...options,
|
|
88
|
+
});
|
|
89
|
+
return msg;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* JAP@Add (v4.8) --- Chainable poll builder, wrapping the socket's own well-tested
|
|
95
|
+
* `sendMessage({ poll })` path (see messages.js) instead of hand-building
|
|
96
|
+
* pollCreationMessageV3/V5 over relayMessage. Two things from the traffic you sent were
|
|
97
|
+
* deliberately NOT implemented here because they can't be built with confidence:
|
|
98
|
+
* 1. Per-option poll images (`values: [{ name, image }]`) — the proto this fork ships
|
|
99
|
+
* only has a plain `optionName` string per option; an image-poll option isn't a named
|
|
100
|
+
* field anywhere in it. The one place an image-poll concept even appears
|
|
101
|
+
* (`pollCreationOptionImageMessage`) is typed as an opaque `FutureProofMessage` (a
|
|
102
|
+
* forward-compat envelope with no documented inner layout) — there's no field list to
|
|
103
|
+
* target, so adding "support" for it would just be silently dropping the image and
|
|
104
|
+
* guessing at a shape. Flagging instead of faking it.
|
|
105
|
+
* 2. Quiz-mode `correctAnswer.optionHash` built by hand — the one working example you
|
|
106
|
+
* captured had a 65-character hex string where a sha256 digest should be 64, and this
|
|
107
|
+
* builder's target `sendMessage({poll})` path (pollCreationMessageV5) already computes
|
|
108
|
+
* quiz mode correctly from a plain `correctAnswer` string, so `setQuiz()` below defers to
|
|
109
|
+
* that existing, already-tested logic rather than reimplementing the hash.
|
|
110
|
+
*/
|
|
111
|
+
export { Carousel };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { AIRich } from './AIRich.js';
|
|
2
|
+
import type { Button } from './Button.js';
|
|
3
|
+
import type { ButtonV2 } from './ButtonV2.js';
|
|
4
|
+
import type { ButtonV3 } from './ButtonV3.js';
|
|
5
|
+
import type { Carousel } from './Carousel.js';
|
|
6
|
+
import type { Poll } from './Poll.js';
|
|
7
|
+
import type { A2UI } from './A2UI.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* JapBaileys — unified builder hub. Every builder stays in its own
|
|
11
|
+
* class/file; this is a single entry point to instantiate them.
|
|
12
|
+
*/
|
|
13
|
+
export class JapBaileys {
|
|
14
|
+
constructor(client: any);
|
|
15
|
+
client: any;
|
|
16
|
+
airich(): AIRich;
|
|
17
|
+
japAI(): AIRich;
|
|
18
|
+
aiJap(): AIRich;
|
|
19
|
+
leafRich(): AIRich;
|
|
20
|
+
japRich(): AIRich;
|
|
21
|
+
richJap(): AIRich;
|
|
22
|
+
button(): Button;
|
|
23
|
+
buttonV2(): ButtonV2;
|
|
24
|
+
buttonV3(): ButtonV3;
|
|
25
|
+
carousel(): Carousel;
|
|
26
|
+
poll(): Poll;
|
|
27
|
+
a2ui(): A2UI;
|
|
28
|
+
/** PascalCase aliases. */
|
|
29
|
+
AIRich(): AIRich;
|
|
30
|
+
Button(): Button;
|
|
31
|
+
Carousel(): Carousel;
|
|
32
|
+
Poll(): Poll;
|
|
33
|
+
A2UI(): A2UI;
|
|
34
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { AIRich } from './AIRich.js'
|
|
2
|
+
import { Button } from './Button.js'
|
|
3
|
+
import { ButtonV2 } from './ButtonV2.js'
|
|
4
|
+
import { ButtonV3 } from './ButtonV3.js'
|
|
5
|
+
import { Carousel } from './Carousel.js'
|
|
6
|
+
import { Poll } from './Poll.js'
|
|
7
|
+
import { A2UI } from './A2UI.js'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* JapBaileys — unified builder hub.
|
|
11
|
+
*
|
|
12
|
+
* Semua builder tetap berada di class/file masing-masing.
|
|
13
|
+
* Class ini hanya menyediakan satu pintu masuk.
|
|
14
|
+
*/
|
|
15
|
+
class JapBaileys {
|
|
16
|
+
constructor(client) {
|
|
17
|
+
if (!client) {
|
|
18
|
+
throw new TypeError(
|
|
19
|
+
'JapBaileys(client) requires an active Baileys socket/client'
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
this.client = client
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// ===== AIRICH =====
|
|
27
|
+
|
|
28
|
+
airich() {
|
|
29
|
+
return new AIRich(this.client)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
japAI() {
|
|
33
|
+
return new AIRich(this.client)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
aiJap() {
|
|
37
|
+
return new AIRich(this.client)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
leafRich() {
|
|
41
|
+
return new AIRich(this.client)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
japRich() {
|
|
45
|
+
return new AIRich(this.client)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
richJap() {
|
|
49
|
+
return new AIRich(this.client)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ===== BUTTON =====
|
|
53
|
+
|
|
54
|
+
button() {
|
|
55
|
+
return new Button(this.client)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
buttonV2() {
|
|
59
|
+
return new ButtonV2(this.client)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
buttonV3() {
|
|
63
|
+
return new ButtonV3(this.client)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ===== CAROUSEL =====
|
|
67
|
+
|
|
68
|
+
carousel() {
|
|
69
|
+
return new Carousel(this.client)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ===== POLL =====
|
|
73
|
+
|
|
74
|
+
poll() {
|
|
75
|
+
return new Poll(this.client)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// ===== A2UI / BLOKS =====
|
|
79
|
+
|
|
80
|
+
a2ui() {
|
|
81
|
+
return new A2UI()
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Alias PascalCase untuk developer yang suka naming class.
|
|
86
|
+
*/
|
|
87
|
+
AIRich() {
|
|
88
|
+
return this.airich()
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
Button() {
|
|
92
|
+
return this.button()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
Carousel() {
|
|
96
|
+
return this.carousel()
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
Poll() {
|
|
100
|
+
return this.poll()
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
A2UI() {
|
|
104
|
+
return this.a2ui()
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export { JapBaileys }
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { BaseBuilder } from './shared.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Chainable poll builder wrapping the socket's own `sendMessage({ poll })` path.
|
|
5
|
+
* Per-option images and hand-built quiz hashes are deliberately NOT supported
|
|
6
|
+
* (see the .js docblock) — quiz mode defers to the socket's tested logic.
|
|
7
|
+
*/
|
|
8
|
+
export class Poll extends BaseBuilder {
|
|
9
|
+
constructor(client: any);
|
|
10
|
+
setName(name: string): this;
|
|
11
|
+
addOption(name: string): this;
|
|
12
|
+
addOptions(names: string[]): this;
|
|
13
|
+
setSelectable(count: number): this;
|
|
14
|
+
setMultiSelect(canSelectMultiple?: boolean): this;
|
|
15
|
+
setHideVoter(hide?: boolean): this;
|
|
16
|
+
setCanAddOption(allow?: boolean): this;
|
|
17
|
+
setAnnouncementGroup(isAnnouncement?: boolean): this;
|
|
18
|
+
setEndDate(date: Date | string | number): this;
|
|
19
|
+
/** Quiz mode — must match one of the added options exactly. */
|
|
20
|
+
setQuiz(correctOptionName: string): this;
|
|
21
|
+
/** Requires a name + at least 2 options. */
|
|
22
|
+
build(): { poll: Record<string, any> };
|
|
23
|
+
/** Build and send via the socket's `sendMessage()`. */
|
|
24
|
+
send(jid: string, options?: Record<string, any>): Promise<any>;
|
|
25
|
+
}
|