@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,51 @@
|
|
|
1
|
+
/** op name -> { alternates, readOnly, extraVariables (added only when an alternate id is used) } */
|
|
2
|
+
export const NEWSLETTER_ID_ALTERNATES: Readonly<{
|
|
3
|
+
METADATA: {
|
|
4
|
+
alternates: string[];
|
|
5
|
+
readOnly: boolean;
|
|
6
|
+
extraVariables: {
|
|
7
|
+
fetch_pinned_messages: boolean;
|
|
8
|
+
fetch_status_metadata: boolean;
|
|
9
|
+
fetch_wamo_sub: boolean;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
SUBSCRIBED: {
|
|
13
|
+
alternates: string[];
|
|
14
|
+
readOnly: boolean;
|
|
15
|
+
};
|
|
16
|
+
ADMIN_COUNT: {
|
|
17
|
+
alternates: string[];
|
|
18
|
+
readOnly: boolean;
|
|
19
|
+
};
|
|
20
|
+
CREATE: {
|
|
21
|
+
alternates: string[];
|
|
22
|
+
readOnly: boolean;
|
|
23
|
+
};
|
|
24
|
+
CHANGE_OWNER: {
|
|
25
|
+
alternates: string[];
|
|
26
|
+
readOnly: boolean;
|
|
27
|
+
};
|
|
28
|
+
DEMOTE: {
|
|
29
|
+
alternates: string[];
|
|
30
|
+
readOnly: boolean;
|
|
31
|
+
};
|
|
32
|
+
FOLLOW: {
|
|
33
|
+
alternates: string[];
|
|
34
|
+
readOnly: boolean;
|
|
35
|
+
};
|
|
36
|
+
UNFOLLOW: {
|
|
37
|
+
alternates: string[];
|
|
38
|
+
readOnly: boolean;
|
|
39
|
+
};
|
|
40
|
+
}>;
|
|
41
|
+
export function isStaleQueryError(e: any): boolean;
|
|
42
|
+
export function makeMexWithFallback(opts1: { [key: string]: any;
|
|
43
|
+
query: Function;
|
|
44
|
+
generateMessageTag: Function;
|
|
45
|
+
logger?: any;
|
|
46
|
+
overrides?: Record<string, string>;
|
|
47
|
+
}): {
|
|
48
|
+
executeWMexQuery: Function;
|
|
49
|
+
probeQueryIds: Function;
|
|
50
|
+
preferred: Map<string, string>;
|
|
51
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { QueryIds } from '../Types/index.js';
|
|
2
|
+
import { executeWMexQuery as genericExecuteWMexQuery } from './mex.js';
|
|
3
|
+
|
|
4
|
+
/** op name -> { alternates, readOnly, extraVariables (added only when an alternate id is used) } */
|
|
5
|
+
export const NEWSLETTER_ID_ALTERNATES = Object.freeze({
|
|
6
|
+
METADATA: { alternates: ['27456920720571478'], readOnly: true, extraVariables: { fetch_pinned_messages: false, fetch_status_metadata: false, fetch_wamo_sub: false } },
|
|
7
|
+
SUBSCRIBED: { alternates: ['25399611239711790'], readOnly: true },
|
|
8
|
+
ADMIN_COUNT: { alternates: ['26278439461859188'], readOnly: true },
|
|
9
|
+
CREATE: { alternates: ['25149874324715067'], readOnly: false },
|
|
10
|
+
CHANGE_OWNER: { alternates: ['9546742745432473'], readOnly: false },
|
|
11
|
+
DEMOTE: { alternates: ['9880997548630971'], readOnly: false },
|
|
12
|
+
FOLLOW: { alternates: ['7871414976211147'], readOnly: false },
|
|
13
|
+
UNFOLLOW: { alternates: ['7238632346214362'], readOnly: false },
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const STALE_QUERY_RE = /persisted|not[ _-]?found|unknown (query|doc|operation)|doc[_ -]?id|invalid (query|document|operation)|no such (query|operation)|unsupported (query|operation)|deprecated/i;
|
|
17
|
+
const AUTH_CODES = new Set([401, 403, 419]);
|
|
18
|
+
|
|
19
|
+
const errorText = (e) => [e?.message, e?.data?.message, e?.data?.extensions?.error_code, e?.data?.extensions?.severity, JSON.stringify(e?.data?.attrs ?? '')].filter(Boolean).join(' ');
|
|
20
|
+
export const isStaleQueryError = (e) => STALE_QUERY_RE.test(errorText(e));
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {{ query: Function, generateMessageTag: Function, logger?: any, overrides?: Record<string,string> }} o
|
|
24
|
+
* @returns {{ executeWMexQuery: Function, probeQueryIds: Function, preferred: Map<string,string> }}
|
|
25
|
+
*/
|
|
26
|
+
export const makeMexWithFallback = ({ query, generateMessageTag, logger, overrides = {} }) => {
|
|
27
|
+
const nameById = new Map(Object.entries(QueryIds).map(([name, id]) => [String(id), name]));
|
|
28
|
+
const preferred = new Map(); // primary id -> id that last worked
|
|
29
|
+
const raw = (variables, id, path) => genericExecuteWMexQuery(variables, id, path, query, generateMessageTag);
|
|
30
|
+
|
|
31
|
+
const candidatesFor = (id) => {
|
|
32
|
+
const name = nameById.get(String(id));
|
|
33
|
+
const spec = name ? NEWSLETTER_ID_ALTERNATES[name] : undefined;
|
|
34
|
+
const list = [];
|
|
35
|
+
if (name && overrides[name]) list.push(String(overrides[name]));
|
|
36
|
+
if (preferred.has(String(id))) list.push(preferred.get(String(id)));
|
|
37
|
+
list.push(String(id));
|
|
38
|
+
if (spec) list.push(...spec.alternates);
|
|
39
|
+
return { name, spec, list: [...new Set(list)] };
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const executeWMexQuery = async (variables, queryId, dataPath) => {
|
|
43
|
+
const { name, spec, list } = candidatesFor(queryId);
|
|
44
|
+
if (list.length === 1) return raw(variables, list[0], dataPath);
|
|
45
|
+
let firstError;
|
|
46
|
+
for (let i = 0; i < list.length; i++) {
|
|
47
|
+
const id = list[i];
|
|
48
|
+
const vars = spec?.extraVariables && id !== String(queryId) ? { ...spec.extraVariables, ...variables } : variables;
|
|
49
|
+
try {
|
|
50
|
+
const res = await raw(vars, id, dataPath);
|
|
51
|
+
if (id !== String(queryId) && preferred.get(String(queryId)) !== id) {
|
|
52
|
+
preferred.set(String(queryId), id);
|
|
53
|
+
logger?.info?.({ op: name, primary: queryId, using: id }, 'newsletter mex: primary doc id failed, alternate id worked (remembered for this process)');
|
|
54
|
+
}
|
|
55
|
+
return res;
|
|
56
|
+
} catch (e) {
|
|
57
|
+
firstError ??= e;
|
|
58
|
+
const status = e?.output?.statusCode ?? e?.data?.statusCode;
|
|
59
|
+
const retry = i < list.length - 1 && !AUTH_CODES.has(status) && (spec?.readOnly || isStaleQueryError(e));
|
|
60
|
+
if (!retry) throw firstError;
|
|
61
|
+
logger?.debug?.({ op: name, id, err: e?.message }, 'newsletter mex: trying next candidate doc id');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
throw firstError;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Diagnostic: run each READ-ONLY op against every candidate id and report which respond.
|
|
69
|
+
* @param {string} [jid] a newsletter jid you can read (enables METADATA / ADMIN_COUNT)
|
|
70
|
+
* @returns {Promise<Record<string, Array<{ id: string, primary: boolean, ok: boolean, error?: string }>>>}
|
|
71
|
+
*/
|
|
72
|
+
const probeQueryIds = async (jid) => {
|
|
73
|
+
const inputFor = {
|
|
74
|
+
SUBSCRIBED: [{}, 'xwa2_newsletter_subscribed'],
|
|
75
|
+
ADMIN_COUNT: jid ? [{ newsletter_id: jid }, 'xwa2_newsletter_admin_count'] : null,
|
|
76
|
+
METADATA: jid ? [{ fetch_creation_time: true, fetch_full_image: true, fetch_viewer_metadata: true, input: { key: jid, type: 'JID' } }, 'xwa2_newsletter'] : null,
|
|
77
|
+
};
|
|
78
|
+
const report = {};
|
|
79
|
+
for (const [name, spec] of Object.entries(NEWSLETTER_ID_ALTERNATES)) {
|
|
80
|
+
if (!spec.readOnly || !inputFor[name]) continue;
|
|
81
|
+
const [vars, path] = inputFor[name];
|
|
82
|
+
report[name] = [];
|
|
83
|
+
for (const id of [String(QueryIds[name]), ...spec.alternates]) {
|
|
84
|
+
const isPrimary = id === String(QueryIds[name]);
|
|
85
|
+
try {
|
|
86
|
+
await raw(spec.extraVariables && !isPrimary ? { ...spec.extraVariables, ...vars } : vars, id, path);
|
|
87
|
+
report[name].push({ id, primary: isPrimary, ok: true });
|
|
88
|
+
} catch (e) {
|
|
89
|
+
report[name].push({ id, primary: isPrimary, ok: false, error: String(e?.message ?? e).slice(0, 160) });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return report;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
return { executeWMexQuery, probeQueryIds, preferred };
|
|
97
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function executeWMexQuery(variables: any, queryId: any, dataPath: any, query: any, generateMessageTag: any): Promise<any>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { getBinaryNodeChild, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
3
|
+
const wMexQuery = (variables, queryId, query, generateMessageTag) => {
|
|
4
|
+
return query({
|
|
5
|
+
tag: 'iq',
|
|
6
|
+
attrs: {
|
|
7
|
+
id: generateMessageTag(),
|
|
8
|
+
type: 'get',
|
|
9
|
+
to: S_WHATSAPP_NET,
|
|
10
|
+
xmlns: 'w:mex'
|
|
11
|
+
},
|
|
12
|
+
content: [
|
|
13
|
+
{
|
|
14
|
+
tag: 'query',
|
|
15
|
+
attrs: { query_id: queryId },
|
|
16
|
+
content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
export const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
|
|
22
|
+
const result = await wMexQuery(variables, queryId, query, generateMessageTag);
|
|
23
|
+
const child = getBinaryNodeChild(result, 'result');
|
|
24
|
+
if (child?.content) {
|
|
25
|
+
const data = JSON.parse(child.content.toString());
|
|
26
|
+
if (data.errors && data.errors.length > 0) {
|
|
27
|
+
const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ');
|
|
28
|
+
const firstError = data.errors[0];
|
|
29
|
+
const errorCode = firstError.extensions?.error_code || 400;
|
|
30
|
+
throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError });
|
|
31
|
+
}
|
|
32
|
+
const response = dataPath ? data?.data?.[dataPath] : data?.data;
|
|
33
|
+
if (typeof response !== 'undefined') {
|
|
34
|
+
return response;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const action = (dataPath || '').startsWith('xwa2_')
|
|
38
|
+
? dataPath.substring(5).replace(/_/g, ' ')
|
|
39
|
+
: dataPath?.replace(/_/g, ' ');
|
|
40
|
+
throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result });
|
|
41
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export const EXT_QUERY_IDS: Readonly<{
|
|
2
|
+
UPDATE_USER_SETTING: "31938993655691868";
|
|
3
|
+
ADMIN_CAPABILITIES: "9801384413216421";
|
|
4
|
+
ENFORCEMENTS: "27835373536068060";
|
|
5
|
+
CHANNEL_REPORTS: "35936238352686172";
|
|
6
|
+
CREATE_REPORT_APPEAL: "27103316329328467";
|
|
7
|
+
POLL_VOTERS: "9407762219322536";
|
|
8
|
+
REACTION_SENDER_LIST: "29575462448733991";
|
|
9
|
+
PIN_MESSAGES: "27165709459706559";
|
|
10
|
+
UNPIN_MESSAGES: "28007176042216937";
|
|
11
|
+
LABEL_AI_CONTENT: "27909718265289596";
|
|
12
|
+
PAID_PARTNERSHIP_LABEL: "26102375079404865";
|
|
13
|
+
CREATE_ADMIN_INVITE: "9387141988078609";
|
|
14
|
+
REVOKE_ADMIN_INVITE: "9656078347839416";
|
|
15
|
+
ACCEPT_ADMIN_INVITE: "9580828702035549";
|
|
16
|
+
DIRECTORY_LIST: "26125047313831973";
|
|
17
|
+
DIRECTORY_SEARCH: "26301059626252132";
|
|
18
|
+
DIRECTORY_CATEGORIES: "35266481849605779";
|
|
19
|
+
INSIGHTS: "9853618868050977";
|
|
20
|
+
FOLLOWERS: "27472091235714801";
|
|
21
|
+
QUESTION_RESPONSE_STATE: "24636260219323456";
|
|
22
|
+
RECOMMENDED: "25806748772361516";
|
|
23
|
+
SIMILAR: "26217043484590756";
|
|
24
|
+
UPDATE_TEXT_STATUS: "9152604461510864";
|
|
25
|
+
TEXT_STATUS_LIST: "24072923595647473";
|
|
26
|
+
ABOUT_STATUS: "24535500086059408";
|
|
27
|
+
}>;
|
|
28
|
+
export const NEWSLETTER_SERVER_ID_MIN: 99;
|
|
29
|
+
export const NEWSLETTER_SERVER_ID_MAX: 2147476647;
|
|
30
|
+
export function toNewsletterServerId(value: any, label: any): string;
|
|
31
|
+
export function toNewsletterServerIds(serverIds: any): string[];
|
|
32
|
+
export function extractNewsletterMessageMeta(stanza: any): {
|
|
33
|
+
adminProfile: {
|
|
34
|
+
id: any;
|
|
35
|
+
name: any;
|
|
36
|
+
pictureId: any;
|
|
37
|
+
pictureDirectPath: any;
|
|
38
|
+
};
|
|
39
|
+
paidPartnership: boolean;
|
|
40
|
+
aiContent: boolean;
|
|
41
|
+
editTimestamp: number;
|
|
42
|
+
originalTimestamp: number;
|
|
43
|
+
};
|
|
44
|
+
export function makeNewsletterExtMethods(sock: {
|
|
45
|
+
query: Function;
|
|
46
|
+
generateMessageTag: Function;
|
|
47
|
+
}): Record<string, Function>;
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { createHash } from 'crypto';
|
|
3
|
+
import { proto } from '../../WAProto/index.js';
|
|
4
|
+
import { S_WHATSAPP_NET, getBinaryNodeChild, getBinaryNodeChildren, jidDecode, jidNormalizedUser } from '../WABinary/index.js';
|
|
5
|
+
import { executeWMexQuery as genericExecuteWMexQuery } from './mex.js';
|
|
6
|
+
|
|
7
|
+
export const EXT_QUERY_IDS = Object.freeze({
|
|
8
|
+
UPDATE_USER_SETTING: '31938993655691868',
|
|
9
|
+
ADMIN_CAPABILITIES: '9801384413216421',
|
|
10
|
+
ENFORCEMENTS: '27835373536068060',
|
|
11
|
+
CHANNEL_REPORTS: '35936238352686172',
|
|
12
|
+
CREATE_REPORT_APPEAL: '27103316329328467',
|
|
13
|
+
POLL_VOTERS: '9407762219322536',
|
|
14
|
+
REACTION_SENDER_LIST: '29575462448733991',
|
|
15
|
+
PIN_MESSAGES: '27165709459706559',
|
|
16
|
+
UNPIN_MESSAGES: '28007176042216937',
|
|
17
|
+
LABEL_AI_CONTENT: '27909718265289596',
|
|
18
|
+
PAID_PARTNERSHIP_LABEL: '26102375079404865',
|
|
19
|
+
CREATE_ADMIN_INVITE: '9387141988078609',
|
|
20
|
+
REVOKE_ADMIN_INVITE: '9656078347839416',
|
|
21
|
+
ACCEPT_ADMIN_INVITE: '9580828702035549',
|
|
22
|
+
DIRECTORY_LIST: '26125047313831973',
|
|
23
|
+
DIRECTORY_SEARCH: '26301059626252132',
|
|
24
|
+
DIRECTORY_CATEGORIES: '35266481849605779',
|
|
25
|
+
INSIGHTS: '9853618868050977',
|
|
26
|
+
FOLLOWERS: '27472091235714801',
|
|
27
|
+
QUESTION_RESPONSE_STATE: '24636260219323456',
|
|
28
|
+
RECOMMENDED: '25806748772361516',
|
|
29
|
+
SIMILAR: '26217043484590756',
|
|
30
|
+
UPDATE_TEXT_STATUS: '9152604461510864',
|
|
31
|
+
TEXT_STATUS_LIST: '24072923595647473',
|
|
32
|
+
ABOUT_STATUS: '24535500086059408',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export const NEWSLETTER_SERVER_ID_MIN = 99;
|
|
36
|
+
export const NEWSLETTER_SERVER_ID_MAX = 2147476647;
|
|
37
|
+
|
|
38
|
+
/** Validate + stringify a newsletter server id (the server accepts 99..2147476647). */
|
|
39
|
+
export const toNewsletterServerId = (value, label) => {
|
|
40
|
+
const parsed = typeof value === 'number' ? value : Number(String(value).trim());
|
|
41
|
+
if (!Number.isInteger(parsed) || parsed < NEWSLETTER_SERVER_ID_MIN || parsed > NEWSLETTER_SERVER_ID_MAX) {
|
|
42
|
+
throw new TypeError(`${JSON.stringify(value)} is not a newsletter server id${label ? ` for ${label}` : ''}; expected an integer in ${NEWSLETTER_SERVER_ID_MIN}..${NEWSLETTER_SERVER_ID_MAX} (get one from newsletterFetchMessages or a sent message)`);
|
|
43
|
+
}
|
|
44
|
+
return String(parsed);
|
|
45
|
+
};
|
|
46
|
+
export const toNewsletterServerIds = (serverIds) => {
|
|
47
|
+
const list = Array.isArray(serverIds) ? serverIds : [serverIds];
|
|
48
|
+
if (!list.length) throw new TypeError('a newsletter server id is required');
|
|
49
|
+
return list.map((id) => toNewsletterServerId(id));
|
|
50
|
+
};
|
|
51
|
+
const assertNewsletterJid = (jid) => {
|
|
52
|
+
if (typeof jid !== 'string' || !jid.endsWith('@newsletter')) throw new TypeError(`${JSON.stringify(jid)} is not a newsletter jid`);
|
|
53
|
+
return jid;
|
|
54
|
+
};
|
|
55
|
+
const REACTION_SETTINGS = new Set(['ALL', 'BASIC', 'NONE', 'BLOCKLIST']);
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
// ── binary (non-MEX) helpers, ported from elaina-baileys ─────────────────────────────────────
|
|
59
|
+
const readInt = (attrs, key) => {
|
|
60
|
+
const raw = attrs?.[key];
|
|
61
|
+
if (raw === undefined || raw === null || raw === '') return undefined;
|
|
62
|
+
const n = Number.parseInt(String(raw), 10);
|
|
63
|
+
return Number.isFinite(n) ? n : undefined;
|
|
64
|
+
};
|
|
65
|
+
/** Parse the <meta> child of a newsletter <message> stanza (admin profile, AI / paid-partnership labels, edit times). */
|
|
66
|
+
export const extractNewsletterMessageMeta = (stanza) => {
|
|
67
|
+
const meta = getBinaryNodeChild(stanza, 'meta');
|
|
68
|
+
if (!meta) return undefined;
|
|
69
|
+
const result = {};
|
|
70
|
+
const adminProfile = getBinaryNodeChild(meta, 'admin_profile');
|
|
71
|
+
if (adminProfile) {
|
|
72
|
+
const name = getBinaryNodeChild(adminProfile, 'name');
|
|
73
|
+
const picture = getBinaryNodeChild(adminProfile, 'picture');
|
|
74
|
+
const content = name?.content;
|
|
75
|
+
result.adminProfile = {
|
|
76
|
+
id: adminProfile.attrs?.id,
|
|
77
|
+
name: typeof content === 'string' ? content : content instanceof Uint8Array ? Buffer.from(content).toString('utf-8') : undefined,
|
|
78
|
+
pictureId: picture?.attrs?.id,
|
|
79
|
+
pictureDirectPath: picture?.attrs?.direct_path,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
if (getBinaryNodeChild(meta, 'paid_partnership')) result.paidPartnership = true;
|
|
83
|
+
if (getBinaryNodeChild(meta, 'ai_content')) result.aiContent = true;
|
|
84
|
+
const editTimestamp = readInt(meta.attrs, 'msg_edit_t');
|
|
85
|
+
if (editTimestamp !== undefined) result.editTimestamp = editTimestamp;
|
|
86
|
+
const originalTimestamp = readInt(meta.attrs, 'original_msg_t');
|
|
87
|
+
if (originalTimestamp !== undefined) result.originalTimestamp = originalTimestamp;
|
|
88
|
+
return Object.keys(result).length ? result : undefined;
|
|
89
|
+
};
|
|
90
|
+
const decodePlaintext = (node) => {
|
|
91
|
+
if (!node?.content) return undefined;
|
|
92
|
+
const buf = typeof node.content === 'string' ? Buffer.from(node.content, 'binary') : Buffer.from(node.content);
|
|
93
|
+
return proto.Message.decode(buf).toJSON();
|
|
94
|
+
};
|
|
95
|
+
const decodeMessageNodes = (parent, newsletterJid, logger) => {
|
|
96
|
+
const out = [];
|
|
97
|
+
for (const child of getBinaryNodeChildren(parent, 'message')) {
|
|
98
|
+
const plaintext = getBinaryNodeChild(child, 'plaintext');
|
|
99
|
+
if (!plaintext?.content) continue;
|
|
100
|
+
try {
|
|
101
|
+
const full = proto.WebMessageInfo.fromObject({
|
|
102
|
+
key: { remoteJid: newsletterJid, id: child.attrs.id || child.attrs.server_id, fromMe: child.attrs.is_sender === 'true' },
|
|
103
|
+
message: decodePlaintext(plaintext),
|
|
104
|
+
messageTimestamp: child.attrs.t ? +child.attrs.t : undefined,
|
|
105
|
+
}).toJSON();
|
|
106
|
+
if (child.attrs.server_id) full.key.server_id = child.attrs.server_id;
|
|
107
|
+
const meta = extractNewsletterMessageMeta(child);
|
|
108
|
+
if (meta) {
|
|
109
|
+
full.newsletterMeta = meta;
|
|
110
|
+
if (meta.adminProfile?.name) full.pushName = meta.adminProfile.name;
|
|
111
|
+
}
|
|
112
|
+
out.push(full);
|
|
113
|
+
} catch (error) {
|
|
114
|
+
logger?.error?.({ error }, 'Failed to decode newsletter message');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return out;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @param {{ query: Function, generateMessageTag: Function }} sock
|
|
122
|
+
* @returns {Record<string, Function>} methods to spread into the socket
|
|
123
|
+
*/
|
|
124
|
+
export const makeNewsletterExtMethods = (sock) => {
|
|
125
|
+
const { query, generateMessageTag, logger } = sock;
|
|
126
|
+
const nl = (to, type, content) => query({ tag: 'iq', attrs: { id: generateMessageTag(), type, xmlns: 'newsletter', to }, content });
|
|
127
|
+
const fetchMyAddOns = async (options, type) => {
|
|
128
|
+
const attrs = { limit: String(options.limit ?? 100) };
|
|
129
|
+
if (type) attrs.type = type;
|
|
130
|
+
if (options.jid) attrs.jid = options.jid;
|
|
131
|
+
const result = await nl(S_WHATSAPP_NET, 'get', [{ tag: 'my_addons', attrs, content: undefined }]);
|
|
132
|
+
const addOns = getBinaryNodeChild(result, 'my_addons');
|
|
133
|
+
if (!addOns) return [];
|
|
134
|
+
return getBinaryNodeChildren(addOns, 'messages').map((group) => ({
|
|
135
|
+
jid: group.attrs?.jid,
|
|
136
|
+
messages: getBinaryNodeChildren(group, 'message').map((entry) => {
|
|
137
|
+
const reaction = getBinaryNodeChild(entry, 'reaction');
|
|
138
|
+
const votes = getBinaryNodeChild(entry, 'votes');
|
|
139
|
+
return {
|
|
140
|
+
serverId: entry.attrs?.server_id ? Number(entry.attrs.server_id) : undefined,
|
|
141
|
+
reaction: reaction ? { code: reaction.attrs?.code, t: reaction.attrs?.t ? Number(reaction.attrs.t) : undefined } : undefined,
|
|
142
|
+
pollVote: votes ? { t: votes.attrs?.t ? Number(votes.attrs.t) : undefined, hashes: getBinaryNodeChildren(votes, 'vote').map((v) => Buffer.from(v.content ?? []).toString('hex')) } : undefined,
|
|
143
|
+
};
|
|
144
|
+
}),
|
|
145
|
+
}));
|
|
146
|
+
};
|
|
147
|
+
const mex = (variables, id, path) => genericExecuteWMexQuery(variables, id, path, query, generateMessageTag);
|
|
148
|
+
const Q = EXT_QUERY_IDS;
|
|
149
|
+
const base = (jid, extra = {}) => ({ newsletter_id: assertNewsletterJid(jid), ...extra });
|
|
150
|
+
const labelOp = (id, path) => (jid, serverId, messageType = 'MESSAGE') =>
|
|
151
|
+
mex(base(jid, { server_id: toNewsletterServerId(serverId), message_type: messageType }), id, path);
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
newsletterUpdateUserSetting: async (jid, type, muted) => {
|
|
155
|
+
const input = { newsletter_id: assertNewsletterJid(jid), type: type === 'FOLLOWER_NOTIFICATIONS' ? 'MUTE_FOLLOWER_ACTIVITY' : 'MUTE_ADMIN_ACTIVITY', value: muted ? 'ON' : 'OFF' };
|
|
156
|
+
const r = await mex({ input }, Q.UPDATE_USER_SETTING, 'xwa2_newsletter_update_user_setting');
|
|
157
|
+
return r;
|
|
158
|
+
},
|
|
159
|
+
newsletterAdminCapabilities: async (jid) => (await mex(base(jid), Q.ADMIN_CAPABILITIES, 'xwa2_newsletter_admin_capabilities'))?.capabilities ?? [],
|
|
160
|
+
newsletterEnforcements: (jid, locale = 'en_US') => mex(base(jid, { locale }), Q.ENFORCEMENTS, 'xwa2_channel_enforcements'),
|
|
161
|
+
newsletterReports: async (locale = 'en_US') => (await mex({ locale }, Q.CHANNEL_REPORTS, 'xwa2_channels_reports'))?.channels_reports ?? [],
|
|
162
|
+
newsletterAppealReport: (reportId, reason) => mex({ report_id: String(reportId), reason }, Q.CREATE_REPORT_APPEAL, 'xwa2_create_channel_report_appeal_v2'),
|
|
163
|
+
newsletterPollVoters: (jid, serverId, options = {}) => mex({ input: { newsletter_id: assertNewsletterJid(jid), server_id: toNewsletterServerId(serverId), limit: options.limit ?? 100, vote_hash: options.voteHash } }, Q.POLL_VOTERS, 'voter_list'),
|
|
164
|
+
newsletterReactionSenders: (jid, serverId) => mex({ input: { id: assertNewsletterJid(jid), server_id: toNewsletterServerId(serverId) } }, Q.REACTION_SENDER_LIST, 'xwa2_newsletters_reaction_sender_list'),
|
|
165
|
+
newsletterPinMessages: (jid, serverIds) => mex(base(jid, { input: { message_ids: toNewsletterServerIds(serverIds) } }), Q.PIN_MESSAGES, 'xwa2_newsletter_pin_messages'),
|
|
166
|
+
newsletterUnpinMessages: (jid, serverIds) => mex(base(jid, { input: { message_ids: toNewsletterServerIds(serverIds) } }), Q.UNPIN_MESSAGES, 'xwa2_newsletter_unpin_messages'),
|
|
167
|
+
newsletterLabelAiContent: labelOp(Q.LABEL_AI_CONTENT, 'xwa2_newsletter_label_ai_content'),
|
|
168
|
+
newsletterLabelPaidPartnership: labelOp(Q.PAID_PARTNERSHIP_LABEL, 'xwa2_newsletter_label_paid_partnership'),
|
|
169
|
+
newsletterCreateAdminInvite: (jid, userJid) => mex(base(jid, { user_id: userJid }), Q.CREATE_ADMIN_INVITE, 'xwa2_newsletter_admin_invite_create'),
|
|
170
|
+
newsletterRevokeAdminInvite: (jid, userJid) => mex(base(jid, { user_id: userJid }), Q.REVOKE_ADMIN_INVITE, 'xwa2_newsletter_admin_invite_revoke'),
|
|
171
|
+
newsletterAcceptAdminInvite: (jid) => mex(base(jid), Q.ACCEPT_ADMIN_INVITE, 'xwa2_newsletter_admin_invite_accept'),
|
|
172
|
+
newsletterDirectoryList: (o = {}) => mex({ fetch_status_metadata: o.fetchStatusMetadata ?? false, input: { view: o.view ?? 'RECOMMENDED', filters: { country_codes: o.countryCodes ?? [], categories: o.categories ?? [] }, limit: o.limit ?? 20, start_cursor: o.cursorToken } }, Q.DIRECTORY_LIST, 'xwa2_newsletters_directory_list'),
|
|
173
|
+
newsletterDirectorySearch: (text, o = {}) => mex({ fetch_status_metadata: o.fetchStatusMetadata ?? false, input: { search_text: text, categories: o.categories ?? [], limit: o.limit ?? 20, start_cursor: o.cursorToken } }, Q.DIRECTORY_SEARCH, 'xwa2_newsletters_directory_search'),
|
|
174
|
+
newsletterDirectoryCategories: (o = {}) => mex({ fetch_status_metadata: o.fetchStatusMetadata ?? false, input: { categories: o.categories ?? [], country_code: o.countryCode || undefined, per_category_limit: o.perCategoryLimit ?? 10 } }, Q.DIRECTORY_CATEGORIES, 'xwa2_newsletters_directory_category_preview'),
|
|
175
|
+
newsletterInsights: (jid, o = {}) => mex({ input: { newsletter_id: assertNewsletterJid(jid), metrics: o.metrics ?? ['NET_FOLLOWS', 'UNFOLLOWS'] } }, Q.INSIGHTS, 'xwa2_newsletter_admin_insights'),
|
|
176
|
+
newsletterFollowers: (jid, o = {}) => mex({ input: { newsletter_id: assertNewsletterJid(jid), count: o.count ?? 100 } }, Q.FOLLOWERS, 'xwa2_newsletter_followers'),
|
|
177
|
+
newsletterQuestionResponseState: (jid, serverId, responseServerId, state) => mex(base(jid, { server_id: toNewsletterServerId(serverId), response_server_id: toNewsletterServerId(responseServerId), state }), Q.QUESTION_RESPONSE_STATE, 'xwa2_newsletter_question_response_state_update'),
|
|
178
|
+
newsletterRecommended: (o = {}) => mex({ fetch_status_metadata: o.fetchStatusMetadata ?? false, input: { limit: o.limit ?? 20, country_codes: o.countryCodes ?? [] } }, Q.RECOMMENDED, 'xwa2_newsletters_recommended'),
|
|
179
|
+
newsletterSimilar: (jid, o = {}) => mex({ fetch_status_metadata: o.fetchStatusMetadata ?? false, input: { newsletter_id: assertNewsletterJid(jid), limit: o.limit ?? 20, country_codes: o.countryCodes ?? [] } }, Q.SIMILAR, 'xwa2_newsletters_similar'),
|
|
180
|
+
// ── binary newsletter ops (iq xmlns=newsletter) ──────────────────────────────
|
|
181
|
+
/** Messages edited/updated since a timestamp or before/after a server id. */
|
|
182
|
+
newsletterFetchMessageUpdates: async (jid, options = {}) => {
|
|
183
|
+
assertNewsletterJid(jid);
|
|
184
|
+
const { count = 20, since, before, after } = options;
|
|
185
|
+
const attrs = { count: String(count) };
|
|
186
|
+
if (since !== undefined) attrs.since = String(since);
|
|
187
|
+
if (before !== undefined) attrs.before = String(before);
|
|
188
|
+
else if (after !== undefined) attrs.after = String(after);
|
|
189
|
+
const result = await nl(jid, 'get', [{ tag: 'message_updates', attrs, content: undefined }]);
|
|
190
|
+
const updates = getBinaryNodeChild(result, 'message_updates');
|
|
191
|
+
const messages = updates && getBinaryNodeChild(updates, 'messages');
|
|
192
|
+
return { jid: messages?.attrs?.jid ?? jid, messages: messages ? decodeMessageNodes(messages, messages.attrs?.jid ?? jid, logger) : [] };
|
|
193
|
+
},
|
|
194
|
+
/** Responses to a channel "question" message. `filter`: e.g. 'replied' | 'starred' (server-defined). */
|
|
195
|
+
newsletterQuestionResponses: async (jid, serverId, options = {}) => {
|
|
196
|
+
assertNewsletterJid(jid);
|
|
197
|
+
const id = toNewsletterServerId(serverId);
|
|
198
|
+
const { count = 20, before, filter, searchText } = options;
|
|
199
|
+
const attrs = { server_id: id, count: String(count) };
|
|
200
|
+
if (before !== undefined) attrs.before = String(before);
|
|
201
|
+
const content = [];
|
|
202
|
+
if (filter) content.push({ tag: 'filters', attrs: {}, content: [{ tag: filter, attrs: {}, content: undefined }] });
|
|
203
|
+
if (searchText) content.push({ tag: 'search', attrs: { text: searchText }, content: undefined });
|
|
204
|
+
const result = await nl(jid, 'get', [{ tag: 'question_responses', attrs, content: content.length ? content : undefined }]);
|
|
205
|
+
const responses = getBinaryNodeChild(result, 'question_responses');
|
|
206
|
+
if (!responses) return { jid, serverId: Number(id), responses: [] };
|
|
207
|
+
return {
|
|
208
|
+
jid: result.attrs?.from ?? jid,
|
|
209
|
+
serverId: responses.attrs?.server_id ? Number(responses.attrs.server_id) : Number(id),
|
|
210
|
+
responses: getBinaryNodeChildren(responses, 'question_response').map((entry) => {
|
|
211
|
+
const messageNode = getBinaryNodeChild(entry, 'message');
|
|
212
|
+
const sender = getBinaryNodeChild(entry, 'sender');
|
|
213
|
+
const picture = sender && getBinaryNodeChild(sender, 'picture');
|
|
214
|
+
const flags = getBinaryNodeChild(entry, 'flags');
|
|
215
|
+
const plaintext = messageNode && getBinaryNodeChild(messageNode, 'plaintext');
|
|
216
|
+
return {
|
|
217
|
+
id: messageNode?.attrs?.id,
|
|
218
|
+
t: messageNode?.attrs?.t ? Number(messageNode.attrs.t) : undefined,
|
|
219
|
+
isSender: messageNode?.attrs?.is_sender === 'true',
|
|
220
|
+
responseServerId: messageNode?.attrs?.response_server_id,
|
|
221
|
+
sender: { lid: sender?.attrs?.lid, notifyName: sender?.attrs?.notify_name, pictureDirectPath: picture?.attrs?.direct_path },
|
|
222
|
+
replied: flags ? !!getBinaryNodeChild(flags, 'replied') : false,
|
|
223
|
+
starred: flags ? !!getBinaryNodeChild(flags, 'starred') : false,
|
|
224
|
+
message: decodePlaintext(plaintext),
|
|
225
|
+
};
|
|
226
|
+
}),
|
|
227
|
+
};
|
|
228
|
+
},
|
|
229
|
+
/** My own reactions / poll votes across channels ({ limit, jid }). */
|
|
230
|
+
newsletterMyAddOns: (options = {}) => fetchMyAddOns(options, undefined),
|
|
231
|
+
/** Same, restricted to channel status updates. */
|
|
232
|
+
newsletterStatusMyAddOns: (options = {}) => fetchMyAddOns(options, 'status'),
|
|
233
|
+
/** Vote on a channel poll: `options` = option name(s); each is sent as its sha256 hash. */
|
|
234
|
+
newsletterSendPollVote: async (jid, parentServerId, options) => {
|
|
235
|
+
const names = Array.isArray(options) ? options : [options];
|
|
236
|
+
const votes = names.map((name) => ({ tag: 'vote', attrs: {}, content: createHash('sha256').update(String(name), 'utf-8').digest() }));
|
|
237
|
+
const id = generateMessageTag();
|
|
238
|
+
await query({ tag: 'message', attrs: { to: assertNewsletterJid(jid), id, type: 'poll', server_id: toNewsletterServerId(parentServerId) }, content: [{ tag: 'meta', attrs: { polltype: 'vote' } }, { tag: 'votes', attrs: {}, content: votes }] });
|
|
239
|
+
return { id };
|
|
240
|
+
},
|
|
241
|
+
newsletterUpdateReactions: async (jid, setting) => {
|
|
242
|
+
const s = String(setting || '').toUpperCase();
|
|
243
|
+
if (!REACTION_SETTINGS.has(s)) throw new TypeError(`reaction setting must be one of ${[...REACTION_SETTINGS].join(', ')}`);
|
|
244
|
+
return mex({ newsletter_id: assertNewsletterJid(jid), updates: { settings: { reaction_codes: { value: s } } } }, '24250201037901610', 'xwa2_newsletter_update');
|
|
245
|
+
},
|
|
246
|
+
|
|
247
|
+
// ── profile: text status / about ─────────────────────────────────────────────
|
|
248
|
+
updateTextStatus: (text, o = {}) => {
|
|
249
|
+
const input = { text: text === '' ? null : text ?? null, ephemeral_duration_sec: o.ephemeralDurationSec ?? 0 };
|
|
250
|
+
if (o.emoji) input.emoji = { content: o.emoji };
|
|
251
|
+
return mex({ input }, Q.UPDATE_TEXT_STATUS, 'xwa2_update_text_status');
|
|
252
|
+
},
|
|
253
|
+
fetchTextStatus: (jids) => mex({ input: (Array.isArray(jids) ? jids : [jids]).map((jid) => ({ jid: jidNormalizedUser(jid) })) }, Q.TEXT_STATUS_LIST, 'xwa2_text_status_list'),
|
|
254
|
+
fetchAbout: async (jid) => {
|
|
255
|
+
const { user } = jidDecode(jidNormalizedUser(jid)) || {};
|
|
256
|
+
if (!user) throw new Boom('Invalid user jid', { statusCode: 400 });
|
|
257
|
+
const response = await mex({ user: { user_id: user } }, Q.ABOUT_STATUS, 'xwa2_users_updates_since');
|
|
258
|
+
const updates = Array.isArray(response) ? response[0]?.updates : undefined;
|
|
259
|
+
return { jid: jidNormalizedUser(jid), status: updates?.[0]?.text ?? null, response };
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
};
|