@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,130 @@
|
|
|
1
|
+
// Vanz@Port (2.0.3) --- from @japofc/baileys 2.4.1 (MIT, author JAPofc / J.AP), lib/Utils/ffmpeg-path.js. See NOTICE.md.
|
|
2
|
+
/**
|
|
3
|
+
* JAP@Add --- one central ffmpeg binary resolver for the whole package.
|
|
4
|
+
*
|
|
5
|
+
* Nothing is bundled (an ffmpeg binary is ~80MB per platform and does not
|
|
6
|
+
* even exist for Termux/Android in ffmpeg-static) — instead the binary is
|
|
7
|
+
* AUTO-DETECTED, in priority order:
|
|
8
|
+
*
|
|
9
|
+
* 1. explicit override → setFfmpegPath('/path/to/ffmpeg') or
|
|
10
|
+
* the FFMPEG_PATH environment variable
|
|
11
|
+
* 2. `ffmpeg-static` → if the user installed it (optional peer)
|
|
12
|
+
* 3. `@ffmpeg-installer/ffmpeg` → same, alternative provider
|
|
13
|
+
* 4. system `ffmpeg` on PATH → Termux (pkg install ffmpeg), apt, brew, ...
|
|
14
|
+
*
|
|
15
|
+
* Every ffmpeg consumer in this package (video thumbs, voice-note/sticker
|
|
16
|
+
* conversion via fluent-ffmpeg, VoIP audio feeder) resolves through here, so
|
|
17
|
+
* `npm i ffmpeg-static` — or nothing at all on systems with ffmpeg installed —
|
|
18
|
+
* just works with zero configuration.
|
|
19
|
+
*
|
|
20
|
+
* @author J.AP
|
|
21
|
+
*/
|
|
22
|
+
import { spawnSync } from 'node:child_process';
|
|
23
|
+
import { existsSync } from 'node:fs';
|
|
24
|
+
|
|
25
|
+
let overridePath = null;
|
|
26
|
+
let cached; // undefined = not probed yet; null = probed, nothing found
|
|
27
|
+
|
|
28
|
+
const moduleProvidedPath = async () => {
|
|
29
|
+
// 2. ffmpeg-static: default export is the absolute binary path (or null
|
|
30
|
+
// on platforms it does not ship, e.g. android/Termux)
|
|
31
|
+
try {
|
|
32
|
+
const mod = await import('ffmpeg-static');
|
|
33
|
+
const p = mod?.default ?? mod;
|
|
34
|
+
if (typeof p === 'string' && existsSync(p)) {
|
|
35
|
+
return p;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch { /* not installed */ }
|
|
39
|
+
// 3. @ffmpeg-installer/ffmpeg: exports { path }
|
|
40
|
+
try {
|
|
41
|
+
const mod = await import('@ffmpeg-installer/ffmpeg');
|
|
42
|
+
const p = (mod?.default ?? mod)?.path;
|
|
43
|
+
if (typeof p === 'string' && existsSync(p)) {
|
|
44
|
+
return p;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch { /* not installed */ }
|
|
48
|
+
return null;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const systemHasFfmpeg = () => {
|
|
52
|
+
try {
|
|
53
|
+
const r = spawnSync('ffmpeg', ['-version'], { stdio: 'ignore' });
|
|
54
|
+
return !r.error && r.status === 0;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/** Pin the ffmpeg binary explicitly (wins over every auto-detection step). */
|
|
62
|
+
export const setFfmpegPath = (path) => {
|
|
63
|
+
overridePath = path || null;
|
|
64
|
+
cached = undefined; // re-resolve on next use
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Resolve the ffmpeg binary to use. Returns an absolute path (module-provided
|
|
69
|
+
* or override) or the bare string 'ffmpeg' when only the system binary is
|
|
70
|
+
* available. Returns null when nothing was found. Result is cached.
|
|
71
|
+
*/
|
|
72
|
+
export const resolveFfmpegPath = async () => {
|
|
73
|
+
if (overridePath) {
|
|
74
|
+
return overridePath;
|
|
75
|
+
}
|
|
76
|
+
if (process.env.FFMPEG_PATH && existsSync(process.env.FFMPEG_PATH)) {
|
|
77
|
+
return process.env.FFMPEG_PATH;
|
|
78
|
+
}
|
|
79
|
+
if (cached !== undefined) {
|
|
80
|
+
return cached;
|
|
81
|
+
}
|
|
82
|
+
cached = (await moduleProvidedPath()) ?? (systemHasFfmpeg() ? 'ffmpeg' : null);
|
|
83
|
+
return cached;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Like resolveFfmpegPath() but throws a platform-aware install guide instead
|
|
88
|
+
* of returning null — use at every "we need ffmpeg NOW" call site.
|
|
89
|
+
*/
|
|
90
|
+
export const requireFfmpegPath = async () => {
|
|
91
|
+
const path = await resolveFfmpegPath();
|
|
92
|
+
if (path) {
|
|
93
|
+
return path;
|
|
94
|
+
}
|
|
95
|
+
throw new Error(ffmpegInstallHint());
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/** Human install instructions for the current platform. */
|
|
99
|
+
export const ffmpegInstallHint = () => {
|
|
100
|
+
const lines = ['ffmpeg not found. Install one of:'];
|
|
101
|
+
const isAndroid = process.platform === 'android' ||
|
|
102
|
+
!!process.env.TERMUX_VERSION || existsSync('/data/data/com.termux');
|
|
103
|
+
if (isAndroid) {
|
|
104
|
+
lines.push(' - Termux: pkg install ffmpeg (recommended — npm ffmpeg bundles have no Android binary)');
|
|
105
|
+
}
|
|
106
|
+
else if (process.platform === 'linux') {
|
|
107
|
+
lines.push(' - npm: npm i ffmpeg-static (auto-detected, no config needed)');
|
|
108
|
+
lines.push(' - Debian/Ubuntu: sudo apt install ffmpeg');
|
|
109
|
+
}
|
|
110
|
+
else if (process.platform === 'darwin') {
|
|
111
|
+
lines.push(' - npm: npm i ffmpeg-static (auto-detected, no config needed)');
|
|
112
|
+
lines.push(' - Homebrew: brew install ffmpeg');
|
|
113
|
+
}
|
|
114
|
+
else if (process.platform === 'win32') {
|
|
115
|
+
lines.push(' - npm: npm i ffmpeg-static (auto-detected, no config needed)');
|
|
116
|
+
lines.push(' - winget: winget install ffmpeg (or choco/scoop install ffmpeg)');
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
lines.push(' - npm: npm i ffmpeg-static');
|
|
120
|
+
lines.push(' - or your system package manager');
|
|
121
|
+
}
|
|
122
|
+
lines.push(' - or pin a binary yourself: setFfmpegPath(\'/path/to/ffmpeg\') / FFMPEG_PATH env var');
|
|
123
|
+
return lines.join('\n');
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/** Test hook: forget the cached probe result. */
|
|
127
|
+
export const _resetFfmpegCache = () => {
|
|
128
|
+
cached = undefined;
|
|
129
|
+
overridePath = null;
|
|
130
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export function promiseTimeout(ms: any, promise: any): Promise<any>;
|
|
2
|
+
export function bindWaitForEvent(ev: any, event: any): (check: any, timeoutMs: any) => Promise<void>;
|
|
3
|
+
export function trimUndefined(obj: any): any;
|
|
4
|
+
export function bytesToCrockford(buffer: any): string;
|
|
5
|
+
export function encodeNewsletterMessage(message: any): any;
|
|
6
|
+
export namespace BufferJSON {
|
|
7
|
+
function replacer(k: any, value: any): any;
|
|
8
|
+
function reviver(_: any, value: any): any;
|
|
9
|
+
}
|
|
10
|
+
export function getKeyAuthor(key: any, meId?: string): any;
|
|
11
|
+
export function isStringNullOrEmpty(value: any): boolean;
|
|
12
|
+
export function writeRandomPadMax16(msg: any): any;
|
|
13
|
+
export function unpadRandomMax16(e: any): Uint8Array<any>;
|
|
14
|
+
export function generateParticipantHashV2(participants: any): string;
|
|
15
|
+
export function encodeWAMessage(message: any): any;
|
|
16
|
+
export function generateRegistrationId(): number;
|
|
17
|
+
export function encodeBigEndian(e: any, t?: number): Uint8Array<ArrayBuffer>;
|
|
18
|
+
export function toNumber(t: any): any;
|
|
19
|
+
export function unixTimestampSeconds(date: any): number;
|
|
20
|
+
export function debouncedTimeout(intervalMs: number, task: any): {
|
|
21
|
+
start: (newIntervalMs: any, newTask: any) => void;
|
|
22
|
+
cancel: () => void;
|
|
23
|
+
setTask: (newTask: any) => any;
|
|
24
|
+
setInterval: (newInterval: any) => any;
|
|
25
|
+
};
|
|
26
|
+
export function delay(ms: any): Promise<any>;
|
|
27
|
+
export function delayCancellable(ms: any): {
|
|
28
|
+
delay: Promise<any>;
|
|
29
|
+
cancel: () => void;
|
|
30
|
+
};
|
|
31
|
+
export function generateMessageIDV2(userId: any): string;
|
|
32
|
+
export function generateMessageID(): string;
|
|
33
|
+
export function bindWaitForConnectionUpdate(ev: any): (check: any, timeoutMs: any) => Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* utility that fetches latest baileys version from the master branch.
|
|
36
|
+
* Use to ensure your WA connection is always on the latest version
|
|
37
|
+
*/
|
|
38
|
+
export const DEFAULT_VERSION_SOURCE_URL: "https://raw.githubusercontent.com/vanzxysenpai/vanzxysenpai/main/lib/Defaults/version.js";
|
|
39
|
+
export function fetchLatestBaileysVersion(options?: {}): Promise<{
|
|
40
|
+
version: number[];
|
|
41
|
+
isLatest: boolean;
|
|
42
|
+
error?: undefined;
|
|
43
|
+
} | {
|
|
44
|
+
version: number[];
|
|
45
|
+
isLatest: boolean;
|
|
46
|
+
error: any;
|
|
47
|
+
}>;
|
|
48
|
+
export function fetchLatestWaWebVersion(options?: {}): Promise<{
|
|
49
|
+
version: number[];
|
|
50
|
+
isLatest: boolean;
|
|
51
|
+
error?: undefined;
|
|
52
|
+
} | {
|
|
53
|
+
version: number[];
|
|
54
|
+
isLatest: boolean;
|
|
55
|
+
error: any;
|
|
56
|
+
}>;
|
|
57
|
+
export function fetchBestWaVersion(options?: {}): Promise<{
|
|
58
|
+
source: string;
|
|
59
|
+
version: number[];
|
|
60
|
+
isLatest: boolean;
|
|
61
|
+
error?: undefined;
|
|
62
|
+
} | {
|
|
63
|
+
source: string;
|
|
64
|
+
version: number[];
|
|
65
|
+
isLatest: boolean;
|
|
66
|
+
error: any;
|
|
67
|
+
}>;
|
|
68
|
+
export function generateMdTagPrefix(): string;
|
|
69
|
+
export function getStatusFromReceiptType(type: any): any;
|
|
70
|
+
export function getErrorCodeFromStreamError(node: any): {
|
|
71
|
+
reason: any;
|
|
72
|
+
statusCode: number;
|
|
73
|
+
};
|
|
74
|
+
export function getCallStatusFromNode(opts1: { [key: string]: any;
|
|
75
|
+
tag: any;
|
|
76
|
+
attrs: any;
|
|
77
|
+
}): string;
|
|
78
|
+
export function getCodeFromWSError(error: any): number;
|
|
79
|
+
export function isWABusinessPlatform(platform: any): boolean;
|
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { createHash, randomBytes, randomFillSync } from 'crypto';
|
|
3
|
+
import { proto } from '../../WAProto/index.js';
|
|
4
|
+
import { DisconnectReason } from '../Types/index.js';
|
|
5
|
+
import { getAllBinaryNodeChildren, jidDecode } from '../WABinary/index.js';
|
|
6
|
+
import { sha256 } from './crypto.js';
|
|
7
|
+
import { DEFAULT_WA_VERSION } from '../Defaults/version.js';
|
|
8
|
+
const baileysVersion = DEFAULT_WA_VERSION;
|
|
9
|
+
export const BufferJSON = {
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
+
replacer: (k, value) => {
|
|
12
|
+
if (Buffer.isBuffer(value) || value instanceof Uint8Array || value?.type === 'Buffer') {
|
|
13
|
+
return { type: 'Buffer', data: Buffer.from(value?.data || value).toString('base64') };
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
},
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
reviver: (_, value) => {
|
|
19
|
+
if (typeof value === 'object' && value !== null && value.type === 'Buffer' && typeof value.data === 'string') {
|
|
20
|
+
return Buffer.from(value.data, 'base64');
|
|
21
|
+
}
|
|
22
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
23
|
+
const keys = Object.keys(value);
|
|
24
|
+
if (keys.length > 0 && keys.every(k => !isNaN(parseInt(k, 10)))) {
|
|
25
|
+
const values = Object.values(value);
|
|
26
|
+
if (values.every(v => typeof v === 'number')) {
|
|
27
|
+
return Buffer.from(values);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
export const getKeyAuthor = (key, meId = 'me') => (key?.fromMe ? meId : key?.participantAlt || key?.remoteJidAlt || key?.participant || key?.remoteJid) || '';
|
|
35
|
+
export const isStringNullOrEmpty = (value) =>
|
|
36
|
+
// eslint-disable-next-line eqeqeq
|
|
37
|
+
value == null || value === '';
|
|
38
|
+
export const writeRandomPadMax16 = (msg) => {
|
|
39
|
+
const pad = randomBytes(1);
|
|
40
|
+
const padLength = (pad[0] & 0x0f) + 1;
|
|
41
|
+
return Buffer.concat([msg, Buffer.alloc(padLength, padLength)]);
|
|
42
|
+
};
|
|
43
|
+
export const unpadRandomMax16 = (e) => {
|
|
44
|
+
const t = new Uint8Array(e);
|
|
45
|
+
if (0 === t.length) {
|
|
46
|
+
throw new Error('unpadPkcs7 given empty bytes');
|
|
47
|
+
}
|
|
48
|
+
var r = t[t.length - 1];
|
|
49
|
+
if (r > t.length) {
|
|
50
|
+
throw new Error(`unpad given ${t.length} bytes, but pad is ${r}`);
|
|
51
|
+
}
|
|
52
|
+
return new Uint8Array(t.buffer, t.byteOffset, t.length - r);
|
|
53
|
+
};
|
|
54
|
+
// code is inspired by whatsmeow
|
|
55
|
+
export const generateParticipantHashV2 = (participants) => {
|
|
56
|
+
participants.sort();
|
|
57
|
+
const sha256Hash = sha256(Buffer.from(participants.join(''))).toString('base64');
|
|
58
|
+
return '2:' + sha256Hash.slice(0, 6);
|
|
59
|
+
};
|
|
60
|
+
export const encodeWAMessage = (message) => writeRandomPadMax16(proto.Message.encode(message).finish());
|
|
61
|
+
export const generateRegistrationId = () => {
|
|
62
|
+
return Uint16Array.from(randomBytes(2))[0] & 16383;
|
|
63
|
+
};
|
|
64
|
+
export const encodeBigEndian = (e, t = 4) => {
|
|
65
|
+
let r = e;
|
|
66
|
+
const a = new Uint8Array(t);
|
|
67
|
+
for (let i = t - 1; i >= 0; i--) {
|
|
68
|
+
a[i] = 255 & r;
|
|
69
|
+
r >>>= 8;
|
|
70
|
+
}
|
|
71
|
+
return a;
|
|
72
|
+
};
|
|
73
|
+
export const toNumber = (t) => typeof t === 'object' && t ? ('toNumber' in t ? t.toNumber() : t.low) : t || 0;
|
|
74
|
+
/** unix timestamp of a date in seconds */
|
|
75
|
+
export const unixTimestampSeconds = (date) => {
|
|
76
|
+
if (date == null) date = new Date(); // null AND undefined both mean "now" (default params only catch undefined)
|
|
77
|
+
const d = date instanceof Date
|
|
78
|
+
? date
|
|
79
|
+
: new Date(typeof date === 'number' && date < 1e12 ? date * 1000 : date); // treat sub-1e12 numbers as already-seconds
|
|
80
|
+
if (Number.isNaN(d.getTime())) {
|
|
81
|
+
throw new TypeError(`unixTimestampSeconds: invalid timestamp input (${typeof date}): ${date}`);
|
|
82
|
+
}
|
|
83
|
+
return d.getTime() / 1000 | 0;
|
|
84
|
+
};
|
|
85
|
+
export const debouncedTimeout = (intervalMs = 1000, task) => {
|
|
86
|
+
let timeout;
|
|
87
|
+
return {
|
|
88
|
+
start: (newIntervalMs, newTask) => {
|
|
89
|
+
task = newTask || task;
|
|
90
|
+
intervalMs = newIntervalMs || intervalMs;
|
|
91
|
+
timeout && clearTimeout(timeout);
|
|
92
|
+
timeout = setTimeout(() => task?.(), intervalMs);
|
|
93
|
+
},
|
|
94
|
+
cancel: () => {
|
|
95
|
+
timeout && clearTimeout(timeout);
|
|
96
|
+
timeout = undefined;
|
|
97
|
+
},
|
|
98
|
+
setTask: (newTask) => (task = newTask),
|
|
99
|
+
setInterval: (newInterval) => (intervalMs = newInterval)
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
export const delay = (ms) => delayCancellable(ms).delay;
|
|
103
|
+
export const delayCancellable = (ms) => {
|
|
104
|
+
const stack = new Error().stack;
|
|
105
|
+
let timeout;
|
|
106
|
+
let reject;
|
|
107
|
+
const delay = new Promise((resolve, _reject) => {
|
|
108
|
+
timeout = setTimeout(resolve, ms);
|
|
109
|
+
reject = _reject;
|
|
110
|
+
});
|
|
111
|
+
const cancel = () => {
|
|
112
|
+
clearTimeout(timeout);
|
|
113
|
+
reject(new Boom('Cancelled', {
|
|
114
|
+
statusCode: 500,
|
|
115
|
+
data: {
|
|
116
|
+
stack
|
|
117
|
+
}
|
|
118
|
+
}));
|
|
119
|
+
};
|
|
120
|
+
return { delay, cancel };
|
|
121
|
+
};
|
|
122
|
+
export async function promiseTimeout(ms, promise) {
|
|
123
|
+
if (!ms) {
|
|
124
|
+
return new Promise(promise);
|
|
125
|
+
}
|
|
126
|
+
const stack = new Error().stack;
|
|
127
|
+
// Create a promise that rejects in <ms> milliseconds
|
|
128
|
+
const { delay, cancel } = delayCancellable(ms);
|
|
129
|
+
const p = new Promise((resolve, reject) => {
|
|
130
|
+
delay
|
|
131
|
+
.then(() => reject(new Boom('Timed Out', {
|
|
132
|
+
statusCode: DisconnectReason.timedOut,
|
|
133
|
+
data: {
|
|
134
|
+
stack
|
|
135
|
+
}
|
|
136
|
+
})))
|
|
137
|
+
.catch(err => reject(err));
|
|
138
|
+
promise(resolve, reject);
|
|
139
|
+
}).finally(cancel);
|
|
140
|
+
return p;
|
|
141
|
+
}
|
|
142
|
+
// inspired from whatsmeow code
|
|
143
|
+
// https://github.com/tulir/whatsmeow/blob/64bc969fbe78d31ae0dd443b8d4c80a5d026d07a/send.go#L42
|
|
144
|
+
export const generateMessageIDV2 = (userId) => {
|
|
145
|
+
const data = Buffer.allocUnsafe(44);
|
|
146
|
+
data.writeBigUInt64BE(BigInt(Date.now() / 1000 | 0), 0);
|
|
147
|
+
if (userId) {
|
|
148
|
+
const userStr = userId.split('@')[0].split(':')[0];
|
|
149
|
+
if (userStr) {
|
|
150
|
+
const len = data.write(userStr, 8);
|
|
151
|
+
data.write('@c.us', 8 + len);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
randomFillSync(data, 28, 16);
|
|
155
|
+
const hash = createHash('sha256').update(data).digest();
|
|
156
|
+
const hex = hash.toString('hex', 0, 9).toUpperCase();
|
|
157
|
+
return '3EB0' + hex;
|
|
158
|
+
};
|
|
159
|
+
// generate a random ID to attach to a message
|
|
160
|
+
export const generateMessageID = () => '3EB0' + randomBytes(18).toString('hex').toUpperCase();
|
|
161
|
+
export function bindWaitForEvent(ev, event) {
|
|
162
|
+
return async (check, timeoutMs) => {
|
|
163
|
+
let listener;
|
|
164
|
+
let closeListener;
|
|
165
|
+
await promiseTimeout(timeoutMs, (resolve, reject) => {
|
|
166
|
+
closeListener = ({ connection, lastDisconnect }) => {
|
|
167
|
+
if (connection === 'close') {
|
|
168
|
+
reject(lastDisconnect?.error || new Boom('Connection Closed', { statusCode: DisconnectReason.connectionClosed }));
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
ev.on('connection.update', closeListener);
|
|
172
|
+
listener = async (update) => {
|
|
173
|
+
if (await check(update)) {
|
|
174
|
+
resolve();
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
ev.on(event, listener);
|
|
178
|
+
}).finally(() => {
|
|
179
|
+
ev.off(event, listener);
|
|
180
|
+
ev.off('connection.update', closeListener);
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
export const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
|
|
185
|
+
/**
|
|
186
|
+
* utility that fetches latest baileys version from the master branch.
|
|
187
|
+
* Use to ensure your WA connection is always on the latest version
|
|
188
|
+
*/
|
|
189
|
+
export const DEFAULT_VERSION_SOURCE_URL = 'https://raw.githubusercontent.com/vanzxysenpai/vanzxysenpai/main/lib/Defaults/version.js';
|
|
190
|
+
export const fetchLatestBaileysVersion = async (options = {}) => {
|
|
191
|
+
const url = options.url || DEFAULT_VERSION_SOURCE_URL;
|
|
192
|
+
try {
|
|
193
|
+
const response = await fetch(url, {
|
|
194
|
+
dispatcher: options.dispatcher,
|
|
195
|
+
method: 'GET',
|
|
196
|
+
headers: options.headers,
|
|
197
|
+
signal: options.signal || AbortSignal.timeout(options.timeoutMs ?? 10_000)
|
|
198
|
+
});
|
|
199
|
+
if (!response.ok) {
|
|
200
|
+
throw new Boom(`Failed to fetch latest Baileys version: ${response.statusText}`, { statusCode: response.status });
|
|
201
|
+
}
|
|
202
|
+
const text = await response.text();
|
|
203
|
+
// Matches `const version = [a, b, c]` and `DEFAULT_WA_VERSION = [a, b, c]` anywhere in the file.
|
|
204
|
+
const versionMatch = text.match(/(?:const\s+version|DEFAULT_WA_VERSION)\s*=\s*\[(\d+),\s*(\d+),\s*(\d+)\]/);
|
|
205
|
+
if (!versionMatch) {
|
|
206
|
+
throw new Error('Could not parse version from Defaults/version.js');
|
|
207
|
+
}
|
|
208
|
+
const version = [parseInt(versionMatch[1]), parseInt(versionMatch[2]), parseInt(versionMatch[3])];
|
|
209
|
+
// WA Web is [2, 3000, <revision>]; reject anything that doesn't look like it, and
|
|
210
|
+
// never accept a version older than the built-in fallback.
|
|
211
|
+
if (version[0] !== 2 || version[1] < 3000 || version[2] < baileysVersion[2]) {
|
|
212
|
+
throw new Error(`Rejected implausible version ${version.join('.')}`);
|
|
213
|
+
}
|
|
214
|
+
return { version, isLatest: true };
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
return {
|
|
218
|
+
version: baileysVersion,
|
|
219
|
+
isLatest: false,
|
|
220
|
+
error
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* A utility that fetches the latest web version of whatsapp.
|
|
226
|
+
* Use to ensure your WA connection is always on the latest version
|
|
227
|
+
*/
|
|
228
|
+
export const fetchLatestWaWebVersion = async (options = {}) => {
|
|
229
|
+
try {
|
|
230
|
+
// Absolute minimal headers required to bypass anti-bot detection
|
|
231
|
+
const defaultHeaders = {
|
|
232
|
+
'sec-fetch-site': 'none',
|
|
233
|
+
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
|
|
234
|
+
};
|
|
235
|
+
const headers = { ...defaultHeaders, ...options.headers };
|
|
236
|
+
const response = await fetch('https://web.whatsapp.com/sw.js', {
|
|
237
|
+
...options,
|
|
238
|
+
method: 'GET',
|
|
239
|
+
headers
|
|
240
|
+
});
|
|
241
|
+
if (!response.ok) {
|
|
242
|
+
throw new Boom(`Failed to fetch sw.js: ${response.statusText}`, { statusCode: response.status });
|
|
243
|
+
}
|
|
244
|
+
const data = await response.text();
|
|
245
|
+
const regex = /\\?"client_revision\\?":\s*(\d+)/;
|
|
246
|
+
const match = data.match(regex);
|
|
247
|
+
if (!match?.[1]) {
|
|
248
|
+
return {
|
|
249
|
+
version: baileysVersion,
|
|
250
|
+
isLatest: false,
|
|
251
|
+
error: {
|
|
252
|
+
message: 'Could not find client revision in the fetched content'
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
const clientRevision = match[1];
|
|
257
|
+
return {
|
|
258
|
+
version: [2, 3000, +clientRevision],
|
|
259
|
+
isLatest: true
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
catch (error) {
|
|
263
|
+
return {
|
|
264
|
+
version: baileysVersion,
|
|
265
|
+
isLatest: false,
|
|
266
|
+
error
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
/**
|
|
271
|
+
* the comment on `version` in Defaults/index.js has long
|
|
272
|
+
* recommended calling `fetchLatestWaWebVersion()` first (parses WA's own
|
|
273
|
+
* sw.js — most accurate, and sidesteps the upstream `isLatest:true`-while-stale
|
|
274
|
+
* bug, WhiskeySockets#2679), falling back to `fetchLatestBaileysVersion()`,
|
|
275
|
+
* and only then the hardcoded constant — but nothing actually implemented
|
|
276
|
+
* that chain, so it was on every consumer to hand-roll it (or, more likely,
|
|
277
|
+
* skip it, which is how a bot ends up pinned to a stale `version` and starts
|
|
278
|
+
* getting rejected with 405 during pairing once WA bumps its minimum — see
|
|
279
|
+
* WhiskeySockets#2370 / #2485). This runs the documented chain for real.
|
|
280
|
+
* Never throws: worst case it resolves to the hardcoded fallback with
|
|
281
|
+
* isLatest:false, same as calling either function alone would.
|
|
282
|
+
*/
|
|
283
|
+
export const fetchBestWaVersion = async (options = {}) => {
|
|
284
|
+
const webResult = await fetchLatestWaWebVersion(options);
|
|
285
|
+
if (webResult.isLatest) {
|
|
286
|
+
return { ...webResult, source: 'wa-web' };
|
|
287
|
+
}
|
|
288
|
+
const baileysResult = await fetchLatestBaileysVersion(options);
|
|
289
|
+
if (baileysResult.isLatest) {
|
|
290
|
+
return { ...baileysResult, source: 'baileys-fork' };
|
|
291
|
+
}
|
|
292
|
+
return { ...baileysResult, source: 'hardcoded-fallback' };
|
|
293
|
+
};
|
|
294
|
+
/** unique message tag prefix for MD clients */
|
|
295
|
+
export const generateMdTagPrefix = () => {
|
|
296
|
+
const bytes = randomBytes(4);
|
|
297
|
+
return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`;
|
|
298
|
+
};
|
|
299
|
+
const STATUS_MAP = {
|
|
300
|
+
sender: proto.WebMessageInfo.Status.SERVER_ACK,
|
|
301
|
+
played: proto.WebMessageInfo.Status.PLAYED,
|
|
302
|
+
read: proto.WebMessageInfo.Status.READ,
|
|
303
|
+
'read-self': proto.WebMessageInfo.Status.READ
|
|
304
|
+
};
|
|
305
|
+
/**
|
|
306
|
+
* Given a type of receipt, returns what the new status of the message should be
|
|
307
|
+
* @param type type from receipt
|
|
308
|
+
*/
|
|
309
|
+
export const getStatusFromReceiptType = (type) => {
|
|
310
|
+
const status = STATUS_MAP[type];
|
|
311
|
+
if (typeof type === 'undefined') {
|
|
312
|
+
return proto.WebMessageInfo.Status.DELIVERY_ACK;
|
|
313
|
+
}
|
|
314
|
+
return status;
|
|
315
|
+
};
|
|
316
|
+
const CODE_MAP = {
|
|
317
|
+
conflict: DisconnectReason.connectionReplaced
|
|
318
|
+
};
|
|
319
|
+
/**
|
|
320
|
+
* Stream errors generally provide a reason, map that to a baileys DisconnectReason
|
|
321
|
+
* @param reason the string reason given, eg. "conflict"
|
|
322
|
+
*/
|
|
323
|
+
export const getErrorCodeFromStreamError = (node) => {
|
|
324
|
+
const [reasonNode] = getAllBinaryNodeChildren(node);
|
|
325
|
+
let reason = reasonNode?.tag || 'unknown';
|
|
326
|
+
const statusCode = +(node.attrs.code || CODE_MAP[reason] || DisconnectReason.badSession);
|
|
327
|
+
if (statusCode === DisconnectReason.restartRequired) {
|
|
328
|
+
reason = 'restart required';
|
|
329
|
+
}
|
|
330
|
+
return {
|
|
331
|
+
reason,
|
|
332
|
+
statusCode
|
|
333
|
+
};
|
|
334
|
+
};
|
|
335
|
+
export const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
336
|
+
let status;
|
|
337
|
+
switch (tag) {
|
|
338
|
+
case 'offer':
|
|
339
|
+
case 'offer_notice':
|
|
340
|
+
status = 'offer';
|
|
341
|
+
break;
|
|
342
|
+
case 'terminate':
|
|
343
|
+
if (attrs.reason === 'timeout') {
|
|
344
|
+
status = 'timeout';
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
//fired when accepted/rejected/timeout/caller hangs up
|
|
348
|
+
status = 'terminate';
|
|
349
|
+
}
|
|
350
|
+
break;
|
|
351
|
+
case 'preaccept':
|
|
352
|
+
status = 'preaccept';
|
|
353
|
+
break;
|
|
354
|
+
case 'transport':
|
|
355
|
+
status = 'transport';
|
|
356
|
+
break;
|
|
357
|
+
case 'relaylatency':
|
|
358
|
+
status = 'relaylatency';
|
|
359
|
+
break;
|
|
360
|
+
case 'reject':
|
|
361
|
+
status = 'reject';
|
|
362
|
+
break;
|
|
363
|
+
case 'accept':
|
|
364
|
+
status = 'accept';
|
|
365
|
+
break;
|
|
366
|
+
default:
|
|
367
|
+
status = 'ringing';
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
return status;
|
|
371
|
+
};
|
|
372
|
+
const UNEXPECTED_SERVER_CODE_TEXT = 'Unexpected server response: ';
|
|
373
|
+
export const getCodeFromWSError = (error) => {
|
|
374
|
+
let statusCode = 500;
|
|
375
|
+
if (error?.message?.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
|
|
376
|
+
const code = +error?.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length);
|
|
377
|
+
if (!Number.isNaN(code) && code >= 400) {
|
|
378
|
+
statusCode = code;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
else if (
|
|
382
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
383
|
+
error?.code?.startsWith('E') ||
|
|
384
|
+
error?.message?.includes('timed out')) {
|
|
385
|
+
// handle ETIMEOUT, ENOTFOUND etc
|
|
386
|
+
statusCode = 408;
|
|
387
|
+
}
|
|
388
|
+
return statusCode;
|
|
389
|
+
};
|
|
390
|
+
/**
|
|
391
|
+
* Is the given platform WA business
|
|
392
|
+
* @param platform AuthenticationCreds.platform
|
|
393
|
+
*/
|
|
394
|
+
export const isWABusinessPlatform = (platform) => {
|
|
395
|
+
return platform === 'smbi' || platform === 'smba';
|
|
396
|
+
};
|
|
397
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
398
|
+
export function trimUndefined(obj) {
|
|
399
|
+
for (const key in obj) {
|
|
400
|
+
if (typeof obj[key] === 'undefined') {
|
|
401
|
+
delete obj[key];
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return obj;
|
|
405
|
+
}
|
|
406
|
+
const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
|
|
407
|
+
export function bytesToCrockford(buffer) {
|
|
408
|
+
let value = 0;
|
|
409
|
+
let bitCount = 0;
|
|
410
|
+
const crockford = [];
|
|
411
|
+
for (const element of buffer) {
|
|
412
|
+
value = (value << 8) | (element & 0xff);
|
|
413
|
+
bitCount += 8;
|
|
414
|
+
while (bitCount >= 5) {
|
|
415
|
+
crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
|
|
416
|
+
bitCount -= 5;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
if (bitCount > 0) {
|
|
420
|
+
crockford.push(CROCKFORD_CHARACTERS.charAt((value << (5 - bitCount)) & 31));
|
|
421
|
+
}
|
|
422
|
+
return crockford.join('');
|
|
423
|
+
}
|
|
424
|
+
export function encodeNewsletterMessage(message) {
|
|
425
|
+
return proto.Message.encode(message).finish();
|
|
426
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Vanz@Port (2.0.3) --- from rexxhayanasi/elaina-baileys 1.3.10 (group-metadata-cache.js). Creator credits untouched. See NOTICE.md.
|
|
2
|
+
export const GROUP_ADDRESSING_MODES = Object.freeze(['pn', 'lid']);
|
|
3
|
+
/** A cached group metadata object is usable for fan-out only if it has a participant list AND a known addressing mode. */
|
|
4
|
+
export const isUsableGroupMetadata = (metadata) => {
|
|
5
|
+
if (!metadata || typeof metadata !== 'object') {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
if (!Array.isArray(metadata.participants)) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
return GROUP_ADDRESSING_MODES.includes(metadata.addressingMode);
|
|
12
|
+
};
|
|
13
|
+
/** Human-readable reason a cached group metadata object was rejected (for logs). */
|
|
14
|
+
export const describeUnusableGroupMetadata = (metadata) => {
|
|
15
|
+
if (!metadata || typeof metadata !== 'object') {
|
|
16
|
+
return 'nothing cached';
|
|
17
|
+
}
|
|
18
|
+
if (!Array.isArray(metadata.participants)) {
|
|
19
|
+
return 'no participants';
|
|
20
|
+
}
|
|
21
|
+
if (metadata.addressingMode === undefined || metadata.addressingMode === null) {
|
|
22
|
+
return 'no addressingMode';
|
|
23
|
+
}
|
|
24
|
+
return `addressingMode ${JSON.stringify(metadata.addressingMode)} is not pn or lid`;
|
|
25
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export function isGroupStatusValue(value: any): boolean;
|
|
2
|
+
export function hasGroupStatusFlag(value: any, depth?: number, seenObjects?: WeakSet<object>): boolean;
|
|
3
|
+
export function getCurrentMessageContentVariants(message: any, depth?: number, seenObjects?: WeakSet<object>): any[];
|
|
4
|
+
/** Verifica se a webMessage é uma marcação de status em grupo, inclusive em wrappers ou níveis profundos. */
|
|
5
|
+
export function hasGroupStatusMessage(webMessage: any): boolean;
|