@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,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chat Control Utilities
|
|
3
|
+
*
|
|
4
|
+
* Part of @japofc/baileys chat utilities.
|
|
5
|
+
* Rewritten as clean TypeScript with full types and JSDoc.
|
|
6
|
+
*
|
|
7
|
+
* Three components:
|
|
8
|
+
* - TypingIndicator — composing / recording presence helpers
|
|
9
|
+
* - PinnedMessagesManager — client-side pin tracking
|
|
10
|
+
* - ReadReceiptController — configurable automatic read receipts
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Standard disappearing-message duration constants (in seconds).
|
|
14
|
+
* Pass to `sock.sendMessage(jid, { disappearingMessagesInChat: DISAPPEARING_DURATIONS.DAYS_7 })`.
|
|
15
|
+
*/
|
|
16
|
+
export declare const DISAPPEARING_DURATIONS: {
|
|
17
|
+
/** Disable disappearing messages */
|
|
18
|
+
readonly OFF: 0;
|
|
19
|
+
/** 24 hours */
|
|
20
|
+
readonly HOURS_24: 86400;
|
|
21
|
+
/** 7 days */
|
|
22
|
+
readonly DAYS_7: 604800;
|
|
23
|
+
/** 90 days */
|
|
24
|
+
readonly DAYS_90: 7776000;
|
|
25
|
+
};
|
|
26
|
+
export type DisappearingDuration = (typeof DISAPPEARING_DURATIONS)[keyof typeof DISAPPEARING_DURATIONS];
|
|
27
|
+
type PresenceType = 'composing' | 'recording' | 'paused' | 'available' | 'unavailable';
|
|
28
|
+
type SendPresence = (jid: string, presence: PresenceType) => Promise<void>;
|
|
29
|
+
type TypingOptions = {
|
|
30
|
+
/** Auto-stop after this many ms (default: no auto-stop) */
|
|
31
|
+
duration?: number;
|
|
32
|
+
/** Whether to auto-pause on timeout — default `true` */
|
|
33
|
+
autoPause?: boolean;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Manages composing ("typing...") and recording ("recording...") presence
|
|
37
|
+
* indicators with per-JID timer tracking.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* const typing = createTypingIndicator(
|
|
41
|
+
* (jid, presence) => sock.sendPresenceUpdate(presence, jid)
|
|
42
|
+
* )
|
|
43
|
+
*
|
|
44
|
+
* // Simulate typing then send a message
|
|
45
|
+
* const result = await typing.simulateTyping(jid, 1500, () =>
|
|
46
|
+
* sock.sendMessage(jid, { text: 'Hello!' })
|
|
47
|
+
* )
|
|
48
|
+
*/
|
|
49
|
+
export declare class TypingIndicator {
|
|
50
|
+
private readonly sendPresence;
|
|
51
|
+
private readonly timers;
|
|
52
|
+
constructor(sendPresence: SendPresence);
|
|
53
|
+
/** Show the "typing..." (composing) indicator for a JID. */
|
|
54
|
+
startTyping(jid: string, options?: TypingOptions): Promise<void>;
|
|
55
|
+
/** Show the "recording..." (audio/video) indicator for a JID. */
|
|
56
|
+
startRecording(jid: string, options?: TypingOptions): Promise<void>;
|
|
57
|
+
/** Stop any active composing/recording indicator for a JID. */
|
|
58
|
+
stopTyping(jid: string): Promise<void>;
|
|
59
|
+
/** Stop all active indicators. */
|
|
60
|
+
stopAll(): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Show typing for `durationMs`, run `callback`, then stop the indicator.
|
|
63
|
+
*
|
|
64
|
+
* @template T
|
|
65
|
+
* @returns The return value of `callback`
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* await typing.simulateTyping(jid, 2000, async () => {
|
|
69
|
+
* await sock.sendMessage(jid, { text: 'Here is your answer' })
|
|
70
|
+
* })
|
|
71
|
+
*/
|
|
72
|
+
simulateTyping<T>(jid: string, durationMs: number, callback: () => Promise<T> | T): Promise<T>;
|
|
73
|
+
private clearTimer;
|
|
74
|
+
}
|
|
75
|
+
/** Factory — create a TypingIndicator. */
|
|
76
|
+
export declare const createTypingIndicator: (sendPresence: SendPresence) => TypingIndicator;
|
|
77
|
+
export type PinnedMessage = {
|
|
78
|
+
messageId: string;
|
|
79
|
+
jid: string;
|
|
80
|
+
pinnedAt: Date;
|
|
81
|
+
pinnedBy?: string;
|
|
82
|
+
expiresAt?: Date;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Client-side tracker for pinned messages.
|
|
86
|
+
* Listen to `messages.update` for `pinInChatMessage` protocol messages and call
|
|
87
|
+
* `manager.pin(jid, msgId, pinnedBy)` / `manager.unpin(jid, msgId)` accordingly.
|
|
88
|
+
*/
|
|
89
|
+
export declare class PinnedMessagesManager {
|
|
90
|
+
private readonly store;
|
|
91
|
+
/**
|
|
92
|
+
* Record a newly pinned message.
|
|
93
|
+
* @returns The created pin entry
|
|
94
|
+
*/
|
|
95
|
+
pin(jid: string, messageId: string, pinnedBy?: string, expiresAt?: Date): PinnedMessage;
|
|
96
|
+
/**
|
|
97
|
+
* Remove a pinned message.
|
|
98
|
+
* @returns `true` if the pin was found and removed, `false` otherwise
|
|
99
|
+
*/
|
|
100
|
+
unpin(jid: string, messageId: string): boolean;
|
|
101
|
+
/** Get all pinned messages for a chat. */
|
|
102
|
+
getPinned(jid: string): PinnedMessage[];
|
|
103
|
+
/** Check if a message is pinned in a chat. */
|
|
104
|
+
isPinned(jid: string, messageId: string): boolean;
|
|
105
|
+
/** Remove all pins for a chat. */
|
|
106
|
+
clearPins(jid: string): void;
|
|
107
|
+
/**
|
|
108
|
+
* Evict pins whose `expiresAt` is in the past.
|
|
109
|
+
* @returns Number of expired pins removed
|
|
110
|
+
*/
|
|
111
|
+
clearExpired(): number;
|
|
112
|
+
/** Total pin count across all chats. */
|
|
113
|
+
get totalPins(): number;
|
|
114
|
+
}
|
|
115
|
+
/** Factory — create a PinnedMessagesManager. */
|
|
116
|
+
export declare const createPinnedMessagesManager: () => PinnedMessagesManager;
|
|
117
|
+
export type ReadReceiptConfig = {
|
|
118
|
+
/** Whether to send read receipts at all (default: `true`) */
|
|
119
|
+
enabled?: boolean;
|
|
120
|
+
/** JIDs to never send receipts for */
|
|
121
|
+
excludeJids?: string[];
|
|
122
|
+
/** Delay before marking as read in ms (default: `0`) */
|
|
123
|
+
readDelay?: number;
|
|
124
|
+
};
|
|
125
|
+
export type ReadReceiptController = {
|
|
126
|
+
setConfig(config: Partial<ReadReceiptConfig>): void;
|
|
127
|
+
getConfig(): Required<ReadReceiptConfig>;
|
|
128
|
+
enable(): void;
|
|
129
|
+
disable(): void;
|
|
130
|
+
isEnabled(): boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Mark messages as read, respecting the current config.
|
|
133
|
+
* No-op if disabled or JID is excluded.
|
|
134
|
+
*/
|
|
135
|
+
markRead(jid: string, participant: string | null | undefined, messageIds: string[]): Promise<void>;
|
|
136
|
+
/** Mark messages as read regardless of config. */
|
|
137
|
+
forceMarkRead(jid: string, participant: string | null | undefined, messageIds: string[]): Promise<void>;
|
|
138
|
+
};
|
|
139
|
+
type SendReadReceipt = (jid: string, participant: string | null | undefined, messageIds: string[]) => Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Create a read-receipt controller with optional auto-delay and per-JID exclusions.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* const readCtrl = createReadReceiptController(
|
|
145
|
+
* (jid, participant, ids) => sock.readMessages(ids.map(id => ({ remoteJid: jid, id, participant }))),
|
|
146
|
+
* { enabled: true, readDelay: 500, excludeJids: [spamJid] }
|
|
147
|
+
* )
|
|
148
|
+
*
|
|
149
|
+
* sock.ev.on('messages.upsert', ({ messages }) => {
|
|
150
|
+
* for (const msg of messages) {
|
|
151
|
+
* const { key } = msg
|
|
152
|
+
* if (!key.fromMe)
|
|
153
|
+
* readCtrl.markRead(key.remoteJid!, key.participant, [key.id!])
|
|
154
|
+
* }
|
|
155
|
+
* })
|
|
156
|
+
*/
|
|
157
|
+
export declare const createReadReceiptController: (sendReadReceipt: SendReadReceipt, config?: ReadReceiptConfig) => ReadReceiptController;
|
|
158
|
+
export {};
|
|
159
|
+
//# sourceMappingURL=chat-control.d.ts.map
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chat Control Utilities
|
|
3
|
+
*
|
|
4
|
+
* Part of @japofc/baileys chat utilities.
|
|
5
|
+
*
|
|
6
|
+
* Three components:
|
|
7
|
+
* - TypingIndicator — composing / recording presence helpers
|
|
8
|
+
* - PinnedMessagesManager — client-side pin tracking
|
|
9
|
+
* - ReadReceiptController — configurable automatic read receipts
|
|
10
|
+
*/
|
|
11
|
+
// ─── Constants ─────────────────────────────────────────────────────────────────
|
|
12
|
+
/**
|
|
13
|
+
* Standard disappearing-message duration constants (in seconds).
|
|
14
|
+
* Pass to `sock.sendMessage(jid, { disappearingMessagesInChat: DISAPPEARING_DURATIONS.DAYS_7 })`.
|
|
15
|
+
*/
|
|
16
|
+
export const DISAPPEARING_DURATIONS = {
|
|
17
|
+
/** Disable disappearing messages */
|
|
18
|
+
OFF: 0,
|
|
19
|
+
/** 24 hours */
|
|
20
|
+
HOURS_24: 86400,
|
|
21
|
+
/** 7 days */
|
|
22
|
+
DAYS_7: 604800,
|
|
23
|
+
/** 90 days */
|
|
24
|
+
DAYS_90: 7776000
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Manages composing ("typing...") and recording ("recording...") presence
|
|
28
|
+
* indicators with per-JID timer tracking.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const typing = createTypingIndicator(
|
|
32
|
+
* (jid, presence) => sock.sendPresenceUpdate(presence, jid)
|
|
33
|
+
* )
|
|
34
|
+
*
|
|
35
|
+
* // Simulate typing then send a message
|
|
36
|
+
* const result = await typing.simulateTyping(jid, 1500, () =>
|
|
37
|
+
* sock.sendMessage(jid, { text: 'Hello!' })
|
|
38
|
+
* )
|
|
39
|
+
*/
|
|
40
|
+
export class TypingIndicator {
|
|
41
|
+
constructor(sendPresence) {
|
|
42
|
+
this.sendPresence = sendPresence;
|
|
43
|
+
this.timers = new Map();
|
|
44
|
+
}
|
|
45
|
+
/** Show the "typing..." (composing) indicator for a JID. */
|
|
46
|
+
async startTyping(jid, options = {}) {
|
|
47
|
+
this.clearTimer(jid);
|
|
48
|
+
await this.sendPresence(jid, 'composing');
|
|
49
|
+
if (options.autoPause !== false && options.duration) {
|
|
50
|
+
const t = setTimeout(() => void this.stopTyping(jid), options.duration);
|
|
51
|
+
this.timers.set(jid, t);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Show the "recording..." (audio/video) indicator for a JID. */
|
|
55
|
+
async startRecording(jid, options = {}) {
|
|
56
|
+
this.clearTimer(jid);
|
|
57
|
+
await this.sendPresence(jid, 'recording');
|
|
58
|
+
if (options.autoPause !== false && options.duration) {
|
|
59
|
+
const t = setTimeout(() => void this.stopTyping(jid), options.duration);
|
|
60
|
+
this.timers.set(jid, t);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** Stop any active composing/recording indicator for a JID. */
|
|
64
|
+
async stopTyping(jid) {
|
|
65
|
+
this.clearTimer(jid);
|
|
66
|
+
try {
|
|
67
|
+
await this.sendPresence(jid, 'paused');
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// Ignore errors when stopping presence (connection may be closed)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** Stop all active indicators. */
|
|
74
|
+
async stopAll() {
|
|
75
|
+
const jids = Array.from(this.timers.keys());
|
|
76
|
+
await Promise.all(jids.map(jid => this.stopTyping(jid)));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Show typing for `durationMs`, run `callback`, then stop the indicator.
|
|
80
|
+
*
|
|
81
|
+
* @template T
|
|
82
|
+
* @returns The return value of `callback`
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* await typing.simulateTyping(jid, 2000, async () => {
|
|
86
|
+
* await sock.sendMessage(jid, { text: 'Here is your answer' })
|
|
87
|
+
* })
|
|
88
|
+
*/
|
|
89
|
+
async simulateTyping(jid, durationMs, callback) {
|
|
90
|
+
await this.startTyping(jid);
|
|
91
|
+
await new Promise(resolve => setTimeout(resolve, durationMs));
|
|
92
|
+
await this.stopTyping(jid);
|
|
93
|
+
return callback();
|
|
94
|
+
}
|
|
95
|
+
clearTimer(jid) {
|
|
96
|
+
const existing = this.timers.get(jid);
|
|
97
|
+
if (existing) {
|
|
98
|
+
clearTimeout(existing);
|
|
99
|
+
this.timers.delete(jid);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** Factory — create a TypingIndicator. */
|
|
104
|
+
export const createTypingIndicator = (sendPresence) => new TypingIndicator(sendPresence);
|
|
105
|
+
/**
|
|
106
|
+
* Client-side tracker for pinned messages.
|
|
107
|
+
* Listen to `messages.update` for `pinInChatMessage` protocol messages and call
|
|
108
|
+
* `manager.pin(jid, msgId, pinnedBy)` / `manager.unpin(jid, msgId)` accordingly.
|
|
109
|
+
*/
|
|
110
|
+
export class PinnedMessagesManager {
|
|
111
|
+
constructor() {
|
|
112
|
+
this.store = new Map();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Record a newly pinned message.
|
|
116
|
+
* @returns The created pin entry
|
|
117
|
+
*/
|
|
118
|
+
pin(jid, messageId, pinnedBy, expiresAt) {
|
|
119
|
+
const entry = { messageId, jid, pinnedAt: new Date(), pinnedBy, expiresAt };
|
|
120
|
+
const existing = this.store.get(jid) ?? [];
|
|
121
|
+
// Remove any previous pin with the same message ID before re-adding
|
|
122
|
+
const filtered = existing.filter(p => p.messageId !== messageId);
|
|
123
|
+
filtered.push(entry);
|
|
124
|
+
this.store.set(jid, filtered);
|
|
125
|
+
return entry;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Remove a pinned message.
|
|
129
|
+
* @returns `true` if the pin was found and removed, `false` otherwise
|
|
130
|
+
*/
|
|
131
|
+
unpin(jid, messageId) {
|
|
132
|
+
const existing = this.store.get(jid);
|
|
133
|
+
if (!existing)
|
|
134
|
+
return false;
|
|
135
|
+
const filtered = existing.filter(p => p.messageId !== messageId);
|
|
136
|
+
if (filtered.length === existing.length)
|
|
137
|
+
return false;
|
|
138
|
+
this.store.set(jid, filtered);
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
/** Get all pinned messages for a chat. */
|
|
142
|
+
getPinned(jid) {
|
|
143
|
+
return this.store.get(jid) ?? [];
|
|
144
|
+
}
|
|
145
|
+
/** Check if a message is pinned in a chat. */
|
|
146
|
+
isPinned(jid, messageId) {
|
|
147
|
+
return (this.store.get(jid) ?? []).some(p => p.messageId === messageId);
|
|
148
|
+
}
|
|
149
|
+
/** Remove all pins for a chat. */
|
|
150
|
+
clearPins(jid) {
|
|
151
|
+
this.store.delete(jid);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Evict pins whose `expiresAt` is in the past.
|
|
155
|
+
* @returns Number of expired pins removed
|
|
156
|
+
*/
|
|
157
|
+
clearExpired() {
|
|
158
|
+
let cleared = 0;
|
|
159
|
+
const now = Date.now();
|
|
160
|
+
for (const [jid, pins] of this.store) {
|
|
161
|
+
const valid = pins.filter(p => !p.expiresAt || p.expiresAt.getTime() > now);
|
|
162
|
+
cleared += pins.length - valid.length;
|
|
163
|
+
this.store.set(jid, valid);
|
|
164
|
+
}
|
|
165
|
+
return cleared;
|
|
166
|
+
}
|
|
167
|
+
/** Total pin count across all chats. */
|
|
168
|
+
get totalPins() {
|
|
169
|
+
let total = 0;
|
|
170
|
+
for (const pins of this.store.values())
|
|
171
|
+
total += pins.length;
|
|
172
|
+
return total;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/** Factory — create a PinnedMessagesManager. */
|
|
176
|
+
export const createPinnedMessagesManager = () => new PinnedMessagesManager();
|
|
177
|
+
/**
|
|
178
|
+
* Create a read-receipt controller with optional auto-delay and per-JID exclusions.
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* const readCtrl = createReadReceiptController(
|
|
182
|
+
* (jid, participant, ids) => sock.readMessages(ids.map(id => ({ remoteJid: jid, id, participant }))),
|
|
183
|
+
* { enabled: true, readDelay: 500, excludeJids: [spamJid] }
|
|
184
|
+
* )
|
|
185
|
+
*
|
|
186
|
+
* sock.ev.on('messages.upsert', ({ messages }) => {
|
|
187
|
+
* for (const msg of messages) {
|
|
188
|
+
* const { key } = msg
|
|
189
|
+
* if (!key.fromMe)
|
|
190
|
+
* readCtrl.markRead(key.remoteJid!, key.participant, [key.id!])
|
|
191
|
+
* }
|
|
192
|
+
* })
|
|
193
|
+
*/
|
|
194
|
+
export const createReadReceiptController = (sendReadReceipt, config = {}) => {
|
|
195
|
+
let currentConfig = {
|
|
196
|
+
enabled: config.enabled ?? true,
|
|
197
|
+
excludeJids: config.excludeJids ?? [],
|
|
198
|
+
readDelay: config.readDelay ?? 0
|
|
199
|
+
};
|
|
200
|
+
return {
|
|
201
|
+
setConfig(newConfig) {
|
|
202
|
+
currentConfig = { ...currentConfig, ...newConfig };
|
|
203
|
+
},
|
|
204
|
+
getConfig() {
|
|
205
|
+
return { ...currentConfig };
|
|
206
|
+
},
|
|
207
|
+
enable() {
|
|
208
|
+
currentConfig.enabled = true;
|
|
209
|
+
},
|
|
210
|
+
disable() {
|
|
211
|
+
currentConfig.enabled = false;
|
|
212
|
+
},
|
|
213
|
+
isEnabled() {
|
|
214
|
+
return currentConfig.enabled;
|
|
215
|
+
},
|
|
216
|
+
async markRead(jid, participant, messageIds) {
|
|
217
|
+
if (!currentConfig.enabled)
|
|
218
|
+
return;
|
|
219
|
+
if (currentConfig.excludeJids.includes(jid))
|
|
220
|
+
return;
|
|
221
|
+
if (currentConfig.readDelay > 0) {
|
|
222
|
+
await new Promise(r => setTimeout(r, currentConfig.readDelay));
|
|
223
|
+
}
|
|
224
|
+
await sendReadReceipt(jid, participant, messageIds);
|
|
225
|
+
},
|
|
226
|
+
async forceMarkRead(jid, participant, messageIds) {
|
|
227
|
+
await sendReadReceipt(jid, participant, messageIds);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { WAMessage } from '../Types/index.js';
|
|
2
|
+
import type { AnyMediaMessageContent, WAMediaUploadFunction } from '../Types/Message.js';
|
|
3
|
+
import type { ILogger } from './logger.js';
|
|
4
|
+
import type { MediaType } from '../Defaults/index.js';
|
|
5
|
+
/** The object returned by `makeInMemoryStore()` (see lib/Store/make-in-memory-store.js). */
|
|
6
|
+
export interface InMemoryStoreLike {
|
|
7
|
+
messages?: Record<string, {
|
|
8
|
+
array: WAMessage[];
|
|
9
|
+
} | undefined>;
|
|
10
|
+
}
|
|
11
|
+
export declare const getLastMessageInChat: (store: InMemoryStoreLike, jid: string) => WAMessage | undefined;
|
|
12
|
+
export declare const getOldestMessageInChat: (store: InMemoryStoreLike, jid: string) => WAMessage | undefined;
|
|
13
|
+
export declare const copyNForward: (sock: {
|
|
14
|
+
sendMessage: (jid: string, content: unknown) => Promise<WAMessage | undefined>;
|
|
15
|
+
}, jid: string, message: WAMessage, forceForward?: boolean) => Promise<WAMessage | undefined>;
|
|
16
|
+
export declare const uploadMediaToWhatsApp: (sock: {
|
|
17
|
+
waUploadToServer: WAMediaUploadFunction;
|
|
18
|
+
}, message: AnyMediaMessageContent, opts?: {
|
|
19
|
+
logger?: ILogger;
|
|
20
|
+
mediaTypeOverride?: MediaType;
|
|
21
|
+
}) => Promise<any>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JAP@Add --- part of the @japofc/baileys utils (chat-history-helpers.ts.)
|
|
3
|
+
*
|
|
4
|
+
* NOTE: this was written against this package's own
|
|
5
|
+
* `in-memory-store.ts` addon (a plain `Map<jid, WAMessage[]>`), which this fork
|
|
6
|
+
* does not have. `@japofc/baileys` already ships a full `makeInMemoryStore`
|
|
7
|
+
* (see lib/Store/make-in-memory-store.js), whose `store.messages[jid]` is a
|
|
8
|
+
* KeyedDB-backed ordered dictionary exposing `.array` — NOT a plain array or
|
|
9
|
+
* Map. getLastMessageInChat / getOldestMessageInChat below are rewritten
|
|
10
|
+
* against that shape so they work with this fork's real store out of the box.
|
|
11
|
+
* copyNForward and uploadMediaToWhatsApp are store-independent and ported as-is.
|
|
12
|
+
*/
|
|
13
|
+
import { generateForwardMessageContent, prepareWAMessageMedia } from './messages.js';
|
|
14
|
+
/**
|
|
15
|
+
* Get the most recently stored message in a chat.
|
|
16
|
+
* `store` is the object returned by `makeInMemoryStore()`, kept in sync via
|
|
17
|
+
* `store.bind(sock.ev)`.
|
|
18
|
+
*/
|
|
19
|
+
export const getLastMessageInChat = (store, jid) => {
|
|
20
|
+
const list = store.messages?.[jid];
|
|
21
|
+
const arr = list?.array;
|
|
22
|
+
if (!arr || arr.length === 0)
|
|
23
|
+
return undefined;
|
|
24
|
+
return arr[arr.length - 1];
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Get the oldest stored message in a chat (useful as the `oldestMsgKey`
|
|
28
|
+
* cursor for `sock.fetchMessageHistory(...)`, which pages backwards from it).
|
|
29
|
+
*/
|
|
30
|
+
export const getOldestMessageInChat = (store, jid) => {
|
|
31
|
+
const list = store.messages?.[jid];
|
|
32
|
+
const arr = list?.array;
|
|
33
|
+
if (!arr || arr.length === 0)
|
|
34
|
+
return undefined;
|
|
35
|
+
return arr[0];
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Re-send ("copy-forward") an existing message to a (possibly different) jid.
|
|
39
|
+
* Thin wrapper around generateForwardMessageContent + sock.sendMessage —
|
|
40
|
+
* strips the original sender's quoting/context the same way WhatsApp's own
|
|
41
|
+
* "Forward" action does, and marks the copy as forwarded.
|
|
42
|
+
*
|
|
43
|
+
* Usage: await copyNForward(sock, targetJid, originalMessage)
|
|
44
|
+
*/
|
|
45
|
+
export const copyNForward = async (sock, jid, message, forceForward = false) => {
|
|
46
|
+
const content = generateForwardMessageContent(message, forceForward);
|
|
47
|
+
return sock.sendMessage(jid, content);
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Upload media directly to WhatsApp's own encrypted media CDN and get back
|
|
51
|
+
* a ready-to-send message-content object (with mediaKey, url/directPath,
|
|
52
|
+
* fileEncSha256, etc).
|
|
53
|
+
*
|
|
54
|
+
* IMPORTANT: WhatsApp clients only accept media that lives on WhatsApp's own
|
|
55
|
+
* CDN, encrypted with a mediaKey the recipient can derive — there is no way
|
|
56
|
+
* to point a WAMessage at an arbitrary third-party URL and have it render.
|
|
57
|
+
* This wrapper does the real, official upload (same path prepareWAMessageMedia
|
|
58
|
+
* / sock.waUploadToServer use internally) — it does not accept or return an
|
|
59
|
+
* arbitrary external URL.
|
|
60
|
+
*
|
|
61
|
+
* Usage: const media = await uploadMediaToWhatsApp(sock, { image: buffer })
|
|
62
|
+
* await sock.sendMessage(jid, media)
|
|
63
|
+
*/
|
|
64
|
+
export const uploadMediaToWhatsApp = async (sock, message, opts) => {
|
|
65
|
+
return prepareWAMessageMedia(message, {
|
|
66
|
+
upload: sock.waUploadToServer,
|
|
67
|
+
logger: opts?.logger,
|
|
68
|
+
mediaTypeOverride: opts?.mediaTypeOverride
|
|
69
|
+
});
|
|
70
|
+
};
|