@vanzxysenpai/baileys 0.0.0-stage → 0.0.2
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 +30 -0
- package/LICENSE +25 -0
- package/NOTICE.md +158 -0
- package/README.md +5294 -2
- package/VanzxyBanner.js +134 -0
- package/WAProto/index.d.ts +13317 -0
- package/WAProto/index.js +147553 -0
- package/lib/Builders/A2UI.d.ts +131 -0
- package/lib/Builders/A2UI.js +343 -0
- package/lib/Builders/AIRich.d.ts +1021 -0
- package/lib/Builders/AIRich.js +2889 -0
- package/lib/Builders/Album.d.ts +51 -0
- package/lib/Builders/Album.js +99 -0
- package/lib/Builders/Button.d.ts +137449 -0
- package/lib/Builders/Button.js +1054 -0
- package/lib/Builders/ButtonV2.d.ts +43 -0
- package/lib/Builders/ButtonV2.js +175 -0
- package/lib/Builders/ButtonV3.d.ts +35 -0
- package/lib/Builders/ButtonV3.js +189 -0
- package/lib/Builders/Carousel.d.ts +68 -0
- package/lib/Builders/Carousel.js +161 -0
- package/lib/Builders/Event.d.ts +61 -0
- package/lib/Builders/Event.js +118 -0
- package/lib/Builders/Expiring.d.ts +17 -0
- package/lib/Builders/Expiring.js +27 -0
- package/lib/Builders/Poll.d.ts +63 -0
- package/lib/Builders/Poll.js +139 -0
- package/lib/Builders/VanzxyBaileys.d.ts +42 -0
- package/lib/Builders/VanzxyBaileys.js +110 -0
- package/lib/Builders/errors.d.ts +25 -0
- package/lib/Builders/errors.js +29 -0
- package/lib/Builders/index.d.ts +14 -0
- package/lib/Builders/index.js +23 -0
- package/lib/Builders/shared.d.ts +395 -0
- package/lib/Builders/shared.js +738 -0
- package/lib/Defaults/bot-jid.d.ts +1 -0
- package/lib/Defaults/bot-jid.js +1 -0
- package/lib/Defaults/index.d.ts +161 -0
- package/lib/Defaults/index.js +165 -0
- package/lib/Defaults/version.d.ts +1 -0
- package/lib/Defaults/version.js +1 -0
- package/lib/Framework/Bot.d.ts +865 -0
- package/lib/Framework/Bot.js +230 -0
- package/lib/Framework/Context.d.ts +17 -0
- package/lib/Framework/Context.js +90 -0
- package/lib/Framework/MediaManager.d.ts +15 -0
- package/lib/Framework/MediaManager.js +154 -0
- package/lib/Framework/SessionManager.d.ts +10 -0
- package/lib/Framework/SessionManager.js +34 -0
- package/lib/Framework/StatsManager.d.ts +20 -0
- package/lib/Framework/StatsManager.js +117 -0
- package/lib/Framework/Store/SQLiteStore.d.ts +13 -0
- package/lib/Framework/Store/SQLiteStore.js +68 -0
- package/lib/Framework/index.d.ts +6 -0
- package/lib/Framework/index.js +11 -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 +58 -0
- package/lib/Signal/libsignal.js +436 -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 +674 -0
- package/lib/Socket/business.js +379 -0
- package/lib/Socket/chats.d.ts +137 -0
- package/lib/Socket/chats.js +1299 -0
- package/lib/Socket/communities.d.ts +805 -0
- package/lib/Socket/communities.js +454 -0
- package/lib/Socket/dugong.d.ts +118 -0
- package/lib/Socket/dugong.js +810 -0
- package/lib/Socket/groups.d.ts +287 -0
- package/lib/Socket/groups.js +386 -0
- package/lib/Socket/index.d.ts +826 -0
- package/lib/Socket/index.js +35 -0
- package/lib/Socket/messages-recv.d.ts +613 -0
- package/lib/Socket/messages-recv.js +1851 -0
- package/lib/Socket/messages-send.d.ts +608 -0
- package/lib/Socket/messages-send.js +1574 -0
- package/lib/Socket/mex-fallback.d.ts +51 -0
- package/lib/Socket/mex-fallback.js +97 -0
- package/lib/Socket/mex.d.ts +1 -0
- package/lib/Socket/mex.js +41 -0
- package/lib/Socket/newsletter-ext.d.ts +47 -0
- package/lib/Socket/newsletter-ext.js +262 -0
- package/lib/Socket/newsletter.d.ts +285 -0
- package/lib/Socket/newsletter.js +223 -0
- package/lib/Socket/socket.d.ts +60 -0
- package/lib/Socket/socket.js +1001 -0
- package/lib/Socket/username.d.ts +842 -0
- package/lib/Socket/username.js +156 -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 +425 -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 +1 -0
- package/lib/Types/Auth.js +1 -0
- package/lib/Types/Bussines.d.ts +1 -0
- package/lib/Types/Bussines.js +1 -0
- package/lib/Types/Call.d.ts +1 -0
- package/lib/Types/Call.js +1 -0
- package/lib/Types/Chat.d.ts +1 -0
- package/lib/Types/Chat.js +7 -0
- package/lib/Types/Contact.d.ts +1 -0
- package/lib/Types/Contact.js +1 -0
- package/lib/Types/Events.d.ts +1 -0
- package/lib/Types/Events.js +1 -0
- package/lib/Types/GroupMetadata.d.ts +1 -0
- package/lib/Types/GroupMetadata.js +1 -0
- package/lib/Types/Label.d.ts +2 -0
- package/lib/Types/Label.js +24 -0
- package/lib/Types/LabelAssociation.d.ts +2 -0
- package/lib/Types/LabelAssociation.js +6 -0
- package/lib/Types/Message.d.ts +11 -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 +1 -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 +1 -0
- package/lib/Types/Signal.js +1 -0
- package/lib/Types/Socket.d.ts +1 -0
- package/lib/Types/Socket.js +1 -0
- package/lib/Types/State.d.ts +5 -0
- package/lib/Types/State.js +55 -0
- package/lib/Types/USync.d.ts +1 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.d.ts +15 -0
- package/lib/Types/index.js +27 -0
- package/lib/Utils/PersistentStore.d.ts +83 -0
- package/lib/Utils/PersistentStore.js +592 -0
- package/lib/Utils/anchor-guard.d.ts +31 -0
- package/lib/Utils/anchor-guard.js +329 -0
- package/lib/Utils/android-stanza-id.d.ts +4 -0
- package/lib/Utils/android-stanza-id.js +21 -0
- package/lib/Utils/anti-delete.d.ts +62 -0
- package/lib/Utils/anti-delete.js +212 -0
- package/lib/Utils/auth-secure.d.ts +180 -0
- package/lib/Utils/auth-secure.js +791 -0
- package/lib/Utils/auth-utils.d.ts +59 -0
- package/lib/Utils/auth-utils.js +326 -0
- package/lib/Utils/auto-reconnect.d.ts +8 -0
- package/lib/Utils/auto-reconnect.js +204 -0
- package/lib/Utils/auto-reply.d.ts +35 -0
- package/lib/Utils/auto-reply.js +152 -0
- package/lib/Utils/bad-mac-handler.d.ts +59 -0
- package/lib/Utils/bad-mac-handler.js +119 -0
- package/lib/Utils/baileys-event-stream.d.ts +5 -0
- package/lib/Utils/baileys-event-stream.js +62 -0
- package/lib/Utils/browser-utils.d.ts +9 -0
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/business.d.ts +49 -0
- package/lib/Utils/business.js +236 -0
- package/lib/Utils/button-helper-utils.d.ts +59 -0
- package/lib/Utils/button-helper-utils.js +266 -0
- package/lib/Utils/button-sender.d.ts +164 -0
- package/lib/Utils/button-sender.js +845 -0
- package/lib/Utils/chat-control.d.ts +98 -0
- package/lib/Utils/chat-control.js +231 -0
- package/lib/Utils/chat-history-helpers.d.ts +4 -0
- package/lib/Utils/chat-history-helpers.js +70 -0
- package/lib/Utils/chat-utils.d.ts +408 -0
- package/lib/Utils/chat-utils.js +879 -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/connection-watchdog.d.ts +10 -0
- package/lib/Utils/connection-watchdog.js +74 -0
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/crypto.js +145 -0
- package/lib/Utils/decode-wa-message.d.ts +83 -0
- package/lib/Utils/decode-wa-message.js +315 -0
- package/lib/Utils/disconnect-reason.d.ts +13 -0
- package/lib/Utils/disconnect-reason.js +36 -0
- package/lib/Utils/event-buffer.d.ts +12 -0
- package/lib/Utils/event-buffer.js +640 -0
- package/lib/Utils/fetch-timeout.d.ts +4 -0
- package/lib/Utils/fetch-timeout.js +14 -0
- package/lib/Utils/ffmpeg-path.d.ts +5 -0
- package/lib/Utils/ffmpeg-path.js +130 -0
- package/lib/Utils/generics.d.ts +79 -0
- package/lib/Utils/generics.js +426 -0
- package/lib/Utils/group-metadata-cache.d.ts +3 -0
- package/lib/Utils/group-metadata-cache.js +25 -0
- package/lib/Utils/group-status-detection.d.ts +5 -0
- package/lib/Utils/group-status-detection.js +114 -0
- package/lib/Utils/history.d.ts +91 -0
- package/lib/Utils/history.js +144 -0
- package/lib/Utils/html-app.d.ts +14 -0
- package/lib/Utils/html-app.js +97 -0
- package/lib/Utils/html-multiplayer.d.ts +8 -0
- package/lib/Utils/html-multiplayer.js +90 -0
- package/lib/Utils/humanizer.d.ts +8 -0
- package/lib/Utils/humanizer.js +74 -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 +88 -0
- package/lib/Utils/index.js +93 -0
- package/lib/Utils/jid-tools.d.ts +3 -0
- package/lib/Utils/jid-tools.js +78 -0
- package/lib/Utils/link-preview-metadata.d.ts +47 -0
- package/lib/Utils/link-preview-metadata.js +90 -0
- package/lib/Utils/link-preview.d.ts +12 -0
- package/lib/Utils/link-preview.js +84 -0
- package/lib/Utils/lock-manager.d.ts +5 -0
- package/lib/Utils/lock-manager.js +50 -0
- package/lib/Utils/logger.d.ts +2 -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 +35 -0
- package/lib/Utils/media-messages.js +70 -0
- package/lib/Utils/media-processor.d.ts +6 -0
- package/lib/Utils/media-processor.js +174 -0
- package/lib/Utils/media-set.d.ts +6 -0
- package/lib/Utils/media-set.js +169 -0
- package/lib/Utils/message-kind.d.ts +26 -0
- package/lib/Utils/message-kind.js +138 -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 +40 -0
- package/lib/Utils/message-search.js +181 -0
- package/lib/Utils/messages-media.d.ts +136 -0
- package/lib/Utils/messages-media.js +867 -0
- package/lib/Utils/messages.d.ts +66 -0
- package/lib/Utils/messages.js +2271 -0
- package/lib/Utils/meta-ai-msmsg.d.ts +3 -0
- package/lib/Utils/meta-ai-msmsg.js +132 -0
- package/lib/Utils/meta-ai.d.ts +4 -0
- package/lib/Utils/meta-ai.js +75 -0
- package/lib/Utils/migrate-auth-state.d.ts +23 -0
- package/lib/Utils/migrate-auth-state.js +126 -0
- package/lib/Utils/mini-app.d.ts +20 -0
- package/lib/Utils/mini-app.js +215 -0
- package/lib/Utils/mock-socket.d.ts +67 -0
- package/lib/Utils/mock-socket.js +254 -0
- package/lib/Utils/modern-messages.d.ts +64 -0
- package/lib/Utils/modern-messages.js +497 -0
- package/lib/Utils/native-flow.d.ts +19 -0
- package/lib/Utils/native-flow.js +112 -0
- package/lib/Utils/newsletter-status.d.ts +157 -0
- package/lib/Utils/newsletter-status.js +652 -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/pairing-utils.d.ts +5 -0
- package/lib/Utils/pairing-utils.js +29 -0
- package/lib/Utils/passkey.d.ts +4 -0
- package/lib/Utils/passkey.js +11 -0
- package/lib/Utils/past-participants.d.ts +2 -0
- package/lib/Utils/past-participants.js +40 -0
- package/lib/Utils/payment-detection.d.ts +40 -0
- package/lib/Utils/payment-detection.js +213 -0
- package/lib/Utils/payment-guard.d.ts +28 -0
- package/lib/Utils/payment-guard.js +143 -0
- package/lib/Utils/payment-messages.d.ts +42 -0
- package/lib/Utils/payment-messages.js +161 -0
- package/lib/Utils/payment-utils.d.ts +75 -0
- package/lib/Utils/payment-utils.js +145 -0
- package/lib/Utils/phone-utils.d.ts +3 -0
- package/lib/Utils/phone-utils.js +29 -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 +103 -0
- package/lib/Utils/process-message.js +868 -0
- package/lib/Utils/qr-terminal.d.ts +1 -0
- package/lib/Utils/qr-terminal.js +16 -0
- package/lib/Utils/reconnect-backoff.d.ts +25 -0
- package/lib/Utils/reconnect-backoff.js +47 -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 +54 -0
- package/lib/Utils/rich-message-utils.js +435 -0
- package/lib/Utils/rich-messages.d.ts +298 -0
- package/lib/Utils/rich-messages.js +1145 -0
- package/lib/Utils/scheduled-message.d.ts +81 -0
- package/lib/Utils/scheduled-message.js +101 -0
- package/lib/Utils/scheduling.d.ts +59 -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-stickers.d.ts +79 -0
- package/lib/Utils/status-stickers.js +261 -0
- package/lib/Utils/status.d.ts +107 -0
- package/lib/Utils/status.js +131 -0
- package/lib/Utils/sticker-pack-maker.d.ts +20 -0
- package/lib/Utils/sticker-pack-maker.js +112 -0
- package/lib/Utils/stickerpack.d.ts +18 -0
- package/lib/Utils/stickerpack.js +316 -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 +8 -0
- package/lib/Utils/tag.js +45 -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 +86 -0
- package/lib/Utils/templates.js +148 -0
- package/lib/Utils/text-format.d.ts +13 -0
- package/lib/Utils/text-format.js +81 -0
- package/lib/Utils/text-tools.d.ts +3 -0
- package/lib/Utils/text-tools.js +38 -0
- package/lib/Utils/ttl-cache.d.ts +29 -0
- package/lib/Utils/ttl-cache.js +123 -0
- package/lib/Utils/use-cache-manager-auth-state.d.ts +22 -0
- package/lib/Utils/use-cache-manager-auth-state.js +86 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +20 -0
- package/lib/Utils/use-multi-file-auth-state.js +201 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +10 -0
- package/lib/Utils/use-single-file-auth-state.js +111 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +13 -0
- package/lib/Utils/use-sqlite-auth-state.js +171 -0
- package/lib/Utils/username.d.ts +22 -0
- package/lib/Utils/username.js +59 -0
- package/lib/Utils/validate-connection.d.ts +43 -0
- package/lib/Utils/validate-connection.js +197 -0
- package/lib/Utils/vcard.d.ts +40 -0
- package/lib/Utils/vcard.js +92 -0
- package/lib/Utils/voice-note.d.ts +13 -0
- package/lib/Utils/voice-note.js +47 -0
- package/lib/VoIP/audio-feeder.d.ts +15 -0
- package/lib/VoIP/audio-feeder.js +132 -0
- package/lib/VoIP/index.d.ts +22 -0
- package/lib/VoIP/index.js +277 -0
- package/lib/VoIP/relay-transport.d.ts +16 -0
- package/lib/VoIP/relay-transport.js +559 -0
- package/lib/VoIP/signaling.d.ts +16 -0
- package/lib/VoIP/signaling.js +624 -0
- package/lib/VoIP/types.d.ts +11 -0
- package/lib/VoIP/types.js +17 -0
- package/lib/VoIP/wasm-engine.d.ts +28 -0
- package/lib/VoIP/wasm-engine.js +1214 -0
- package/lib/VoIP/worker-bootstrap.d.ts +1 -0
- package/lib/VoIP/worker-bootstrap.js +1042 -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 +45 -0
- package/lib/WABinary/generic-utils.js +285 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +5 -0
- package/lib/WABinary/jid-utils.d.ts +32 -0
- package/lib/WABinary/jid-utils.js +102 -0
- package/lib/WABinary/types.d.ts +1 -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/USyncBusinessProtocol.d.ts +43 -0
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +32 -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 +60 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +28 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +28 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.d.ts +20 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +23 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.d.ts +14 -0
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +24 -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 +49 -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 +12 -0
- package/lib/WAUSync/Protocols/index.js +12 -0
- package/lib/WAUSync/USyncQuery.d.ts +25 -0
- package/lib/WAUSync/USyncQuery.js +140 -0
- package/lib/WAUSync/USyncUser.d.ts +24 -0
- package/lib/WAUSync/USyncUser.js +47 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +3 -0
- package/lib/assets/wasm/loader.js +5 -0
- package/lib/assets/wasm/whatsapp.wasm +0 -0
- package/lib/assets/wasm/worker-modules.js +273 -0
- package/lib/exports-extra.d.ts +45 -0
- package/lib/exports-extra.js +47 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +24 -0
- package/package.json +161 -4
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `buttonsMessage` builder (nativeFlowInfo-based buttons under a media/location header, or
|
|
3
|
+
* a raw pre-built header via `setMedia()`). Distinct from `Button` (interactiveMessage/nativeFlow)
|
|
4
|
+
* and `ButtonV3` (legacy templateMessage) — see those classes for the other two button protocols.
|
|
5
|
+
*/
|
|
6
|
+
export class ButtonV2 extends BaseBuilder {
|
|
7
|
+
/** @param {import('../../WAProto/index.js').WASocket} client Active Baileys socket. */
|
|
8
|
+
constructor(client: any);
|
|
9
|
+
_image: any;
|
|
10
|
+
_data: any;
|
|
11
|
+
_buttons: any[];
|
|
12
|
+
/**
|
|
13
|
+
* Reconstruct this builder's state from an already-built/sent buttonsMessage.
|
|
14
|
+
* @param {object} msg A raw message object containing `buttonsMessage` (e.g. `oldMsg.message`).
|
|
15
|
+
*/
|
|
16
|
+
loadFrom(msg: object): this;
|
|
17
|
+
/** Add a simple quick-reply button. @param {string} displayText Label. @param {string} [buttonId] Defaults to a random uuid. */
|
|
18
|
+
addButton(displayText?: string, buttonId?: string): this;
|
|
19
|
+
/** Push a raw pre-built button object, bypassing the `addButton()` shorthand. */
|
|
20
|
+
addRawButton(obj: any): this;
|
|
21
|
+
/** Set the header thumbnail (used as a fallback location-header image when no `setMedia()` header is given). */
|
|
22
|
+
setThumbnail(path: any): this;
|
|
23
|
+
/** Set a raw pre-built header media object for the buttons message. */
|
|
24
|
+
setMedia(obj: any): this;
|
|
25
|
+
/** Alias for addButton() — shorthand parity with RowBuilder#button(). */
|
|
26
|
+
button(displayText: any, buttonId: any): this;
|
|
27
|
+
/**
|
|
28
|
+
* Fluent row helper ported from the RowBuilder class (already
|
|
29
|
+
* present but previously unwired into ButtonV2). Lets callers group buttons via a
|
|
30
|
+
* callback instead of chaining addButton() calls one at a time.
|
|
31
|
+
* @param {(row: RowBuilder) => void} cb
|
|
32
|
+
*/
|
|
33
|
+
row(cb: (row: RowBuilder) => void): this;
|
|
34
|
+
/** @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. */
|
|
35
|
+
build(jid: any, opts1?: { [key: string]: any;
|
|
36
|
+
viewOnce?: boolean;
|
|
37
|
+
}): Promise<Record<string, any>>;
|
|
38
|
+
/** Build and send this buttons message. @param {string} jid Destination chat/group jid. */
|
|
39
|
+
send(jid: string, opts2?: { [key: string]: any; }): Promise<Record<string, any>>;
|
|
40
|
+
#private;
|
|
41
|
+
}
|
|
42
|
+
import { BaseBuilder } from './shared.js';
|
|
43
|
+
import { RowBuilder } from './shared.js';
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { BaseBuilder, Toolkit, RowBuilder, generateWAMessageFromContent, prepareWAMessageMedia, generateMessageIDV2, getBizBinaryNode, crypto } from './shared.js';
|
|
2
|
+
/**
|
|
3
|
+
* `buttonsMessage` builder (nativeFlowInfo-based buttons under a media/location header, or
|
|
4
|
+
* a raw pre-built header via `setMedia()`). Distinct from `Button` (interactiveMessage/nativeFlow)
|
|
5
|
+
* and `ButtonV3` (legacy templateMessage) — see those classes for the other two button protocols.
|
|
6
|
+
*/
|
|
7
|
+
class ButtonV2 extends BaseBuilder {
|
|
8
|
+
#client;
|
|
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._image = null;
|
|
19
|
+
this._data = null;
|
|
20
|
+
this._buttons = [];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Reconstruct this builder's state from an already-built/sent buttonsMessage.
|
|
25
|
+
* @param {object} msg A raw message object containing `buttonsMessage` (e.g. `oldMsg.message`).
|
|
26
|
+
*/
|
|
27
|
+
loadFrom(msg) {
|
|
28
|
+
if (!msg) throw new Error('loadFrom(msg): buttonsMessage needed');
|
|
29
|
+
if (!msg.buttonsMessage) throw new Error('loadFrom(msg): buttonsMessage not found');
|
|
30
|
+
|
|
31
|
+
const { buttonsMessage, ...extraPayload } = msg;
|
|
32
|
+
const bM = buttonsMessage;
|
|
33
|
+
const location = bM.locationMessage || {};
|
|
34
|
+
|
|
35
|
+
this._title = location.name || '';
|
|
36
|
+
this._subtitle = location.address || '';
|
|
37
|
+
this._body = bM.contentText || '';
|
|
38
|
+
this._footer = bM.footerText || '';
|
|
39
|
+
this._contextInfo = bM.contextInfo || {};
|
|
40
|
+
this._extraPayload = extraPayload;
|
|
41
|
+
|
|
42
|
+
this._buttons = Array.isArray(bM.buttons)
|
|
43
|
+
? bM.buttons.map((button) => ({
|
|
44
|
+
...button,
|
|
45
|
+
...(button.nativeFlowInfo
|
|
46
|
+
? {
|
|
47
|
+
nativeFlowInfo: {
|
|
48
|
+
...button.nativeFlowInfo,
|
|
49
|
+
paramsJson: typeof button.nativeFlowInfo.paramsJson === 'string' ? button.nativeFlowInfo.paramsJson : JSON.stringify(button.nativeFlowInfo.paramsJson || {}),
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
: {}),
|
|
53
|
+
}))
|
|
54
|
+
: [];
|
|
55
|
+
|
|
56
|
+
this._image = location.jpegThumbnail || null;
|
|
57
|
+
|
|
58
|
+
this._data = Object.keys(bM).reduce((data, key) => {
|
|
59
|
+
if (!['contentText', 'footerText', 'contextInfo', 'buttons', 'headerType', 'locationMessage', 'viewOnce'].includes(key)) {
|
|
60
|
+
data[key] = bM[key];
|
|
61
|
+
}
|
|
62
|
+
return data;
|
|
63
|
+
}, {});
|
|
64
|
+
|
|
65
|
+
if (!Object.keys(this._data).length) {
|
|
66
|
+
this._data = null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Add a simple quick-reply button. @param {string} displayText Label. @param {string} [buttonId] Defaults to a random uuid. */
|
|
73
|
+
addButton(displayText = '', buttonId = crypto.randomUUID()) {
|
|
74
|
+
if (!displayText) throw new TypeError('addButton(displayText) requires a non-empty label');
|
|
75
|
+
this._buttons.push({
|
|
76
|
+
buttonId,
|
|
77
|
+
buttonText: { displayText },
|
|
78
|
+
type: 1,
|
|
79
|
+
});
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Push a raw pre-built button object, bypassing the `addButton()` shorthand. */
|
|
84
|
+
addRawButton(obj) {
|
|
85
|
+
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
|
|
86
|
+
throw new TypeError('Buttons must be a plain object');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
this._buttons.push(obj);
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Set the header thumbnail (used as a fallback location-header image when no `setMedia()` header is given). */
|
|
94
|
+
setThumbnail(path) {
|
|
95
|
+
if (!path) throw new Error('Url or buffer needed');
|
|
96
|
+
this._image = path;
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Set a raw pre-built header media object for the buttons message. */
|
|
101
|
+
setMedia(obj) {
|
|
102
|
+
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
|
|
103
|
+
throw new TypeError('Media must be a plain object');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
this._data = obj;
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Alias for addButton() — shorthand parity with RowBuilder#button(). */
|
|
111
|
+
button(displayText, buttonId) {
|
|
112
|
+
return this.addButton(displayText, buttonId);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Fluent row helper ported from the RowBuilder class (already
|
|
117
|
+
* present but previously unwired into ButtonV2). Lets callers group buttons via a
|
|
118
|
+
* callback instead of chaining addButton() calls one at a time.
|
|
119
|
+
* @param {(row: RowBuilder) => void} cb
|
|
120
|
+
*/
|
|
121
|
+
row(cb) {
|
|
122
|
+
const r = new RowBuilder();
|
|
123
|
+
cb(r);
|
|
124
|
+
r.buttons.forEach((b) => this._buttons.push(b));
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** @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. */
|
|
129
|
+
async build(jid, { viewOnce = true, ...options } = {}) {
|
|
130
|
+
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;
|
|
131
|
+
const msg = generateWAMessageFromContent(
|
|
132
|
+
jid,
|
|
133
|
+
{
|
|
134
|
+
...this._extraPayload,
|
|
135
|
+
buttonsMessage: {
|
|
136
|
+
contentText: this._body,
|
|
137
|
+
footerText: this._footer,
|
|
138
|
+
...(this._data
|
|
139
|
+
? this._data
|
|
140
|
+
: {
|
|
141
|
+
headerType: 6,
|
|
142
|
+
locationMessage: {
|
|
143
|
+
degreesLatitude: 0,
|
|
144
|
+
degreesLongitude: 0,
|
|
145
|
+
name: this._title,
|
|
146
|
+
address: this._subtitle,
|
|
147
|
+
jpegThumbnail: _thumbnail,
|
|
148
|
+
},
|
|
149
|
+
}),
|
|
150
|
+
viewOnce,
|
|
151
|
+
contextInfo: this._contextInfo,
|
|
152
|
+
buttons: [...this._buttons],
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
{ ...options }
|
|
156
|
+
);
|
|
157
|
+
return msg;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Build and send this buttons message. @param {string} jid Destination chat/group jid. */
|
|
161
|
+
async send(jid, { ...options } = {}) {
|
|
162
|
+
if (this._buttons.length < 1) throw new Error('ButtonV2 requires at least one button');
|
|
163
|
+
const msg = await this.build(jid, options);
|
|
164
|
+
const bizNode = getBizBinaryNode(msg.message);
|
|
165
|
+
|
|
166
|
+
await this.#client.relayMessage(msg.key.remoteJid, msg.message, {
|
|
167
|
+
messageId: msg.key.id,
|
|
168
|
+
additionalNodes: [bizNode],
|
|
169
|
+
...options,
|
|
170
|
+
});
|
|
171
|
+
return msg;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export { ButtonV2 };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Legacy `templateMessage` / `hydratedFourRowTemplate` builder — WA's Generation-1
|
|
3
|
+
* button protocol (predates the nativeFlow format that Button/ButtonV2 use).
|
|
4
|
+
* Capped at 3 buttons (quickReply/url/call only), no interactive list/flow support.
|
|
5
|
+
* Ported from MessageBuilderV4.7.
|
|
6
|
+
*/
|
|
7
|
+
export class ButtonV3 extends BaseBuilder {
|
|
8
|
+
/** @param {import('../../WAProto/index.js').WASocket} client Active Baileys socket. */
|
|
9
|
+
constructor(client: any);
|
|
10
|
+
_data: any;
|
|
11
|
+
_mediaHeaderType: string;
|
|
12
|
+
_buttons: any[];
|
|
13
|
+
/** Load an existing templateMessage (e.g. from a fetched/quoted message) for editing. */
|
|
14
|
+
loadFrom(msg: any): this;
|
|
15
|
+
setImage(path: any, options?: {}): this;
|
|
16
|
+
setVideo(path: any, options?: {}): this;
|
|
17
|
+
setDocument(path: any, options?: {}): this;
|
|
18
|
+
setMedia(obj: any): this;
|
|
19
|
+
clearButtons(): this;
|
|
20
|
+
addButton(hydratedButton: any): this;
|
|
21
|
+
addReply(display_text?: string, id?: string): this;
|
|
22
|
+
addUrl(display_text?: string, url?: string, options?: {}): this;
|
|
23
|
+
addCall(display_text?: string, phone_number?: string): this;
|
|
24
|
+
toTemplate(): Promise<{
|
|
25
|
+
hydratedContentText: string;
|
|
26
|
+
hydratedFooterText: string;
|
|
27
|
+
hydratedButtons: any[];
|
|
28
|
+
}>;
|
|
29
|
+
build(jid: any, opts1?: { [key: string]: any; }): Promise<import("../../WAProto/index.js").proto.WebMessageInfo>;
|
|
30
|
+
send(jid: any, opts2?: { [key: string]: any;
|
|
31
|
+
additionalNodes?: any[];
|
|
32
|
+
}): Promise<import("../../WAProto/index.js").proto.WebMessageInfo>;
|
|
33
|
+
#private;
|
|
34
|
+
}
|
|
35
|
+
import { BaseBuilder } from './shared.js';
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { BaseBuilder, generateWAMessageFromContent, prepareWAMessageMedia, generateMessageIDV2, crypto } from './shared.js';
|
|
2
|
+
/**
|
|
3
|
+
* Legacy `templateMessage` / `hydratedFourRowTemplate` builder — WA's Generation-1
|
|
4
|
+
* button protocol (predates the nativeFlow format that Button/ButtonV2 use).
|
|
5
|
+
* Capped at 3 buttons (quickReply/url/call only), no interactive list/flow support.
|
|
6
|
+
* Ported from MessageBuilderV4.7.
|
|
7
|
+
*/
|
|
8
|
+
class ButtonV3 extends BaseBuilder {
|
|
9
|
+
#client;
|
|
10
|
+
|
|
11
|
+
/** @param {import('../../WAProto/index.js').WASocket} client Active Baileys socket. */
|
|
12
|
+
constructor(client) {
|
|
13
|
+
super();
|
|
14
|
+
if (!client) {
|
|
15
|
+
throw new Error('Socket is required');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
this.#client = client;
|
|
19
|
+
this._data = null;
|
|
20
|
+
this._mediaHeaderType = null;
|
|
21
|
+
this._buttons = [];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Load an existing templateMessage (e.g. from a fetched/quoted message) for editing. */
|
|
25
|
+
loadFrom(msg) {
|
|
26
|
+
if (!msg) throw new Error('templateMessage needed');
|
|
27
|
+
if (!msg.templateMessage) throw new Error('templateMessage not found');
|
|
28
|
+
|
|
29
|
+
const { templateMessage, ...extraPayload } = msg;
|
|
30
|
+
const hft = templateMessage.hydratedFourRowTemplate || {};
|
|
31
|
+
|
|
32
|
+
this._title = hft.hydratedTitleText || '';
|
|
33
|
+
this._body = hft.hydratedContentText || '';
|
|
34
|
+
this._footer = hft.hydratedFooterText || '';
|
|
35
|
+
this._contextInfo = templateMessage.contextInfo || {};
|
|
36
|
+
this._extraPayload = extraPayload;
|
|
37
|
+
|
|
38
|
+
this._buttons = Array.isArray(hft.hydratedButtons)
|
|
39
|
+
? hft.hydratedButtons.map((button) => ({ ...button }))
|
|
40
|
+
: [];
|
|
41
|
+
|
|
42
|
+
if (hft.imageMessage) {
|
|
43
|
+
this._data = { imageMessage: hft.imageMessage };
|
|
44
|
+
this._mediaHeaderType = 'imageMessage';
|
|
45
|
+
} else if (hft.videoMessage) {
|
|
46
|
+
this._data = { videoMessage: hft.videoMessage };
|
|
47
|
+
this._mediaHeaderType = 'videoMessage';
|
|
48
|
+
} else if (hft.documentMessage) {
|
|
49
|
+
this._data = { documentMessage: hft.documentMessage };
|
|
50
|
+
this._mediaHeaderType = 'documentMessage';
|
|
51
|
+
} else if (hft.locationMessage) {
|
|
52
|
+
this._data = { locationMessage: hft.locationMessage };
|
|
53
|
+
this._mediaHeaderType = 'locationMessage';
|
|
54
|
+
} else {
|
|
55
|
+
this._data = undefined;
|
|
56
|
+
this._mediaHeaderType = null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
setImage(path, options = {}) {
|
|
63
|
+
if (!path) throw new Error('Url or buffer needed');
|
|
64
|
+
this._data = Buffer.isBuffer(path)
|
|
65
|
+
? { image: path, ...options }
|
|
66
|
+
: { image: { url: path }, ...options };
|
|
67
|
+
this._mediaHeaderType = 'imageMessage';
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
setVideo(path, options = {}) {
|
|
72
|
+
if (!path) throw new Error('Url or buffer needed');
|
|
73
|
+
this._data = Buffer.isBuffer(path)
|
|
74
|
+
? { video: path, ...options }
|
|
75
|
+
: { video: { url: path }, ...options };
|
|
76
|
+
this._mediaHeaderType = 'videoMessage';
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
setDocument(path, options = {}) {
|
|
81
|
+
if (!path) throw new Error('Url or buffer needed');
|
|
82
|
+
this._data = Buffer.isBuffer(path)
|
|
83
|
+
? { document: path, ...options }
|
|
84
|
+
: { document: { url: path }, ...options };
|
|
85
|
+
this._mediaHeaderType = 'documentMessage';
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
setMedia(obj) {
|
|
90
|
+
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
|
|
91
|
+
throw new TypeError('Media must be a plain object');
|
|
92
|
+
}
|
|
93
|
+
this._data = obj;
|
|
94
|
+
this._mediaHeaderType = null; // caller is expected to pass an already-resolved shape
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
clearButtons() {
|
|
99
|
+
this._buttons = [];
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
addButton(hydratedButton) {
|
|
104
|
+
if (this._buttons.length >= 3) {
|
|
105
|
+
throw new Error('ButtonV3 (TemplateMessage) supports a maximum of 3 buttons');
|
|
106
|
+
}
|
|
107
|
+
this._buttons.push({ index: this._buttons.length + 1, ...hydratedButton });
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
addReply(display_text = '', id = '') {
|
|
112
|
+
return this.addButton({
|
|
113
|
+
quickReplyButton: { displayText: display_text, id },
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
addUrl(display_text = '', url = '', options = {}) {
|
|
118
|
+
return this.addButton({
|
|
119
|
+
urlButton: { displayText: display_text, url, ...options },
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
addCall(display_text = '', phone_number = '') {
|
|
124
|
+
return this.addButton({
|
|
125
|
+
callButton: { displayText: display_text, phoneNumber: phone_number },
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async toTemplate() {
|
|
130
|
+
let mediaFields = {};
|
|
131
|
+
|
|
132
|
+
if (this._data) {
|
|
133
|
+
const alreadyResolved =
|
|
134
|
+
this._data.imageMessage || this._data.videoMessage ||
|
|
135
|
+
this._data.documentMessage || this._data.locationMessage;
|
|
136
|
+
|
|
137
|
+
mediaFields = alreadyResolved
|
|
138
|
+
? this._data
|
|
139
|
+
: await prepareWAMessageMedia(this._data, {
|
|
140
|
+
upload: this.#client.waUploadToServer,
|
|
141
|
+
}).catch((e) => {
|
|
142
|
+
if (String(e).includes('Invalid media type')) return this._data;
|
|
143
|
+
throw e;
|
|
144
|
+
});
|
|
145
|
+
} else if (this._title) {
|
|
146
|
+
mediaFields = { hydratedTitleText: this._title };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
hydratedContentText: this._body,
|
|
151
|
+
hydratedFooterText: this._footer,
|
|
152
|
+
hydratedButtons: this._buttons,
|
|
153
|
+
...mediaFields,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async build(jid, { messageId, ...options } = {}) {
|
|
158
|
+
const hydratedFourRowTemplate = await this.toTemplate();
|
|
159
|
+
|
|
160
|
+
return generateWAMessageFromContent(
|
|
161
|
+
jid,
|
|
162
|
+
{
|
|
163
|
+
...this._extraPayload,
|
|
164
|
+
templateMessage: {
|
|
165
|
+
hydratedFourRowTemplate,
|
|
166
|
+
contextInfo: this._contextInfo,
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
{ messageId: messageId || generateMessageIDV2(), ...options },
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async send(jid, { messageId, additionalNodes = [], ...options } = {}) {
|
|
174
|
+
if (this._buttons.length < 1)
|
|
175
|
+
throw new Error('ButtonV3 requires at least one button');
|
|
176
|
+
const msg = await this.build(jid, { messageId, ...options });
|
|
177
|
+
|
|
178
|
+
// TemplateMessage predates the nativeFlow protocol and does not need the
|
|
179
|
+
// "biz"/"native_flow" additionalNodes hack that Button/ButtonV2 use.
|
|
180
|
+
await this.#client.relayMessage(msg.key.remoteJid, msg.message, {
|
|
181
|
+
messageId: msg.key.id,
|
|
182
|
+
additionalNodes,
|
|
183
|
+
...options,
|
|
184
|
+
});
|
|
185
|
+
return msg;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export { ButtonV3 };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** Carousel of interactive cards (each with its own header media + optional buttons), scrollable horizontally in-chat. */
|
|
2
|
+
export class Carousel extends BaseBuilder {
|
|
3
|
+
static MAX_CARDS: number;
|
|
4
|
+
/** @param {import('../../WAProto/index.js').WASocket} client Active Baileys socket. */
|
|
5
|
+
constructor(client: any);
|
|
6
|
+
_cards: any[];
|
|
7
|
+
/**
|
|
8
|
+
* Reconstruct this builder's state from an already-built/sent carousel interactiveMessage.
|
|
9
|
+
* @param {object} msg A raw message object containing `interactiveMessage` (e.g. `oldMsg.message`).
|
|
10
|
+
*/
|
|
11
|
+
loadFrom(msg: object): this;
|
|
12
|
+
/**
|
|
13
|
+
* Add one card, or an array of cards, to the carousel.
|
|
14
|
+
* @param {Record<string, any>|Record<string, any>[]} card A card (or array of cards) with `header.hasMediaAttachment: true`
|
|
15
|
+
* — typically built via `new Button(client).setImage(...).addUrl(...).toCard()`.
|
|
16
|
+
*/
|
|
17
|
+
addCard(card: Record<string, any> | Record<string, any>[]): this;
|
|
18
|
+
/** Remove every card added so far. */
|
|
19
|
+
clearCards(): this;
|
|
20
|
+
/** Number of cards currently in the carousel. */
|
|
21
|
+
get cardCount(): number;
|
|
22
|
+
/**
|
|
23
|
+
* Build one card straight from an image/video url or Buffer (media uploaded here) -- no `Button` instance needed.
|
|
24
|
+
* Pass the result to `addCard()`.
|
|
25
|
+
* @param {{image?: string|Buffer, video?: string|Buffer, gifPlayback?: boolean, body?: string, footer?: string, title?: string, subtitle?: string,
|
|
26
|
+
* buttons?: Array<{name: string, params?: any, buttonParamsJson?: string}>, params?: string|object}} card
|
|
27
|
+
*/
|
|
28
|
+
makeCard(opts3?: { [key: string]: any;
|
|
29
|
+
image?: string | Buffer;
|
|
30
|
+
video?: string | Buffer;
|
|
31
|
+
gifPlayback?: boolean;
|
|
32
|
+
body?: string;
|
|
33
|
+
footer?: string;
|
|
34
|
+
title?: string;
|
|
35
|
+
subtitle?: string;
|
|
36
|
+
buttons?: Array<{
|
|
37
|
+
name: string;
|
|
38
|
+
params?: any;
|
|
39
|
+
buttonParamsJson?: string;
|
|
40
|
+
}>;
|
|
41
|
+
params?: string | object;
|
|
42
|
+
}): Promise<{
|
|
43
|
+
header: {
|
|
44
|
+
hasMediaAttachment: boolean;
|
|
45
|
+
title: string;
|
|
46
|
+
subtitle: string;
|
|
47
|
+
};
|
|
48
|
+
body: {
|
|
49
|
+
text: string;
|
|
50
|
+
};
|
|
51
|
+
footer: {
|
|
52
|
+
text: string;
|
|
53
|
+
};
|
|
54
|
+
nativeFlowMessage: {
|
|
55
|
+
buttons: {
|
|
56
|
+
name: string;
|
|
57
|
+
buttonParamsJson: string;
|
|
58
|
+
}[];
|
|
59
|
+
messageParamsJson?: string;
|
|
60
|
+
};
|
|
61
|
+
}>;
|
|
62
|
+
/** @returns {Record<string, any>} The generated WAMessage (without sending). */
|
|
63
|
+
build(jid: any, opts1?: { [key: string]: any; }): Record<string, any>;
|
|
64
|
+
/** Build and send this carousel. @param {string} jid Destination chat/group jid. */
|
|
65
|
+
send(jid: string, opts2?: { [key: string]: any; }): Promise<Record<string, any>>;
|
|
66
|
+
#private;
|
|
67
|
+
}
|
|
68
|
+
import { BaseBuilder } from './shared.js';
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { BaseBuilder, generateWAMessageFromContent, prepareWAMessageMedia, generateMessageIDV2, getBizBinaryNode, crypto } from './shared.js';
|
|
2
|
+
/** Carousel of interactive cards (each with its own header media + optional buttons), scrollable horizontally in-chat. */
|
|
3
|
+
class Carousel extends BaseBuilder {
|
|
4
|
+
#client;
|
|
5
|
+
|
|
6
|
+
static MAX_CARDS = 10;
|
|
7
|
+
|
|
8
|
+
/** @param {import('../../WAProto/index.js').WASocket} client Active Baileys socket. */
|
|
9
|
+
constructor(client) {
|
|
10
|
+
super();
|
|
11
|
+
if (!client) {
|
|
12
|
+
throw new Error('Socket is required');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
this.#client = client;
|
|
16
|
+
this._cards = [];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Reconstruct this builder's state from an already-built/sent carousel interactiveMessage.
|
|
21
|
+
* @param {object} msg A raw message object containing `interactiveMessage` (e.g. `oldMsg.message`).
|
|
22
|
+
*/
|
|
23
|
+
loadFrom(msg) {
|
|
24
|
+
if (!msg) throw new Error('loadFrom(msg): interactiveMessage needed');
|
|
25
|
+
if (!msg.interactiveMessage) throw new Error('loadFrom(msg): interactiveMessage not found');
|
|
26
|
+
|
|
27
|
+
const { interactiveMessage, ...extraPayload } = msg;
|
|
28
|
+
const iM = interactiveMessage;
|
|
29
|
+
const carousel = iM.carouselMessage || {};
|
|
30
|
+
|
|
31
|
+
this._body = iM.body?.text || '';
|
|
32
|
+
this._footer = iM.footer?.text || '';
|
|
33
|
+
this._contextInfo = iM.contextInfo || {};
|
|
34
|
+
this._extraPayload = extraPayload;
|
|
35
|
+
|
|
36
|
+
this._cards = Array.isArray(carousel.cards)
|
|
37
|
+
? carousel.cards.map((card) => ({
|
|
38
|
+
...card,
|
|
39
|
+
header: {
|
|
40
|
+
...(card.header || {}),
|
|
41
|
+
hasMediaAttachment: !!card.header?.hasMediaAttachment,
|
|
42
|
+
...(card.header?.imageMessage ? { imageMessage: card.header.imageMessage } : {}),
|
|
43
|
+
...(card.header?.videoMessage ? { videoMessage: card.header.videoMessage } : {}),
|
|
44
|
+
},
|
|
45
|
+
body: { text: card.body?.text || '' },
|
|
46
|
+
footer: { text: card.footer?.text || '' },
|
|
47
|
+
nativeFlowMessage: {
|
|
48
|
+
...(card.nativeFlowMessage || {}),
|
|
49
|
+
buttons: Array.isArray(card.nativeFlowMessage?.buttons)
|
|
50
|
+
? card.nativeFlowMessage.buttons.map((button) => ({
|
|
51
|
+
...button,
|
|
52
|
+
buttonParamsJson: typeof button.buttonParamsJson === 'string' ? button.buttonParamsJson : JSON.stringify(button.buttonParamsJson || {}),
|
|
53
|
+
}))
|
|
54
|
+
: [],
|
|
55
|
+
messageParamsJson:
|
|
56
|
+
typeof card.nativeFlowMessage?.messageParamsJson === 'string' ? card.nativeFlowMessage.messageParamsJson : JSON.stringify(card.nativeFlowMessage?.messageParamsJson || {}),
|
|
57
|
+
},
|
|
58
|
+
}))
|
|
59
|
+
: [];
|
|
60
|
+
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Add one card, or an array of cards, to the carousel.
|
|
66
|
+
* @param {Record<string, any>|Record<string, any>[]} card A card (or array of cards) with `header.hasMediaAttachment: true`
|
|
67
|
+
* — typically built via `new Button(client).setImage(...).addUrl(...).toCard()`.
|
|
68
|
+
*/
|
|
69
|
+
addCard(card) {
|
|
70
|
+
const cards = Array.isArray(card) ? card : [card];
|
|
71
|
+
const baseIndex = this._cards.length;
|
|
72
|
+
|
|
73
|
+
for (const [index, c] of cards.entries()) {
|
|
74
|
+
if (!c?.header?.hasMediaAttachment) {
|
|
75
|
+
throw new Error(`Card [${baseIndex + index}] must include an image or video in header`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (this._cards.length + cards.length > Carousel.MAX_CARDS) {
|
|
80
|
+
throw new Error(`Carousel supports at most ${Carousel.MAX_CARDS} cards (got ${this._cards.length + cards.length})`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
this._cards.push(...cards);
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Remove every card added so far. */
|
|
88
|
+
clearCards() {
|
|
89
|
+
this._cards = [];
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Number of cards currently in the carousel. */
|
|
94
|
+
get cardCount() {
|
|
95
|
+
return this._cards.length;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Build one card straight from an image/video url or Buffer (media uploaded here) -- no `Button` instance needed.
|
|
100
|
+
* Pass the result to `addCard()`.
|
|
101
|
+
* @param {{image?: string|Buffer, video?: string|Buffer, gifPlayback?: boolean, body?: string, footer?: string, title?: string, subtitle?: string,
|
|
102
|
+
* buttons?: Array<{name: string, params?: any, buttonParamsJson?: string}>, params?: string|object}} card
|
|
103
|
+
*/
|
|
104
|
+
async makeCard({ image, video, gifPlayback = false, body = '', footer = '', title = '', subtitle = '', buttons = [], params } = {}) {
|
|
105
|
+
if (!image && !video) throw new Error('makeCard needs an image or video');
|
|
106
|
+
const source = image ? { image: Buffer.isBuffer(image) ? image : { url: image } } : { video: Buffer.isBuffer(video) ? video : { url: video } };
|
|
107
|
+
let media = await prepareWAMessageMedia(source, { upload: this.#client.waUploadToServer });
|
|
108
|
+
if (gifPlayback && media.videoMessage) media = { ...media, videoMessage: { ...media.videoMessage, gifPlayback: true } };
|
|
109
|
+
return {
|
|
110
|
+
header: { hasMediaAttachment: true, title, subtitle, ...media },
|
|
111
|
+
body: { text: body },
|
|
112
|
+
footer: { text: footer },
|
|
113
|
+
nativeFlowMessage: {
|
|
114
|
+
...(params ? { messageParamsJson: typeof params === 'string' ? params : JSON.stringify(params) } : {}),
|
|
115
|
+
buttons: buttons.map((b) => ({ name: b.name, buttonParamsJson: b.buttonParamsJson ?? (typeof b.params === 'string' ? b.params : JSON.stringify(b.params ?? {})) })),
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** @returns {Record<string, any>} The generated WAMessage (without sending). */
|
|
121
|
+
build(jid, { ...options } = {}) {
|
|
122
|
+
return generateWAMessageFromContent(
|
|
123
|
+
jid,
|
|
124
|
+
{
|
|
125
|
+
...this._extraPayload,
|
|
126
|
+
interactiveMessage: {
|
|
127
|
+
header: {
|
|
128
|
+
hasMediaAttachment: false,
|
|
129
|
+
...(this._title ? { title: this._title } : {}),
|
|
130
|
+
...(this._subtitle ? { subtitle: this._subtitle } : {}),
|
|
131
|
+
},
|
|
132
|
+
body: { text: this._body },
|
|
133
|
+
footer: { text: this._footer },
|
|
134
|
+
contextInfo: this._contextInfo,
|
|
135
|
+
carouselMessage: {
|
|
136
|
+
...(this._params && Object.keys(this._params).length ? { messageParamsJson: JSON.stringify(this._params) } : {}),
|
|
137
|
+
cards: this._cards,
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
{ ...options }
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Build and send this carousel. @param {string} jid Destination chat/group jid. */
|
|
146
|
+
async send(jid, { ...options } = {}) {
|
|
147
|
+
if (this._cards.length === 0) throw new Error('Carousel requires at least one card (use addCard())');
|
|
148
|
+
|
|
149
|
+
const msg = this.build(jid, options);
|
|
150
|
+
const bizNode = getBizBinaryNode(msg.message);
|
|
151
|
+
|
|
152
|
+
await this.#client.relayMessage(msg.key.remoteJid, msg.message, {
|
|
153
|
+
messageId: msg.key.id,
|
|
154
|
+
additionalNodes: [bizNode],
|
|
155
|
+
...options,
|
|
156
|
+
});
|
|
157
|
+
return msg;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export { Carousel };
|