@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,162 @@
|
|
|
1
|
+
import { getBinaryNodeChild, getBinaryNodeChildren, isHostedLidUser, isHostedPnUser, isJidMetaAI, isLidUser, isPnUser, jidNormalizedUser } from '../WABinary/index.js';
|
|
2
|
+
// Same phone-number pattern as WABinary's isJidBot, applied against the user
|
|
3
|
+
// part so the check is invariant to @c.us ↔ @s.whatsapp.net normalization.
|
|
4
|
+
const BOT_PHONE_REGEX = /^1313555\d{4}$|^131655500\d{2}$/;
|
|
5
|
+
/**
|
|
6
|
+
* Mirrors WA Web's `Wid.isRegularUser()` (user ∧ ¬PSA ∧ ¬Bot). Used to gate tctoken
|
|
7
|
+
* storage against malformed notifications — WA Web filters server-side but we
|
|
8
|
+
* defend here for parity with `WAWebSetTcTokenChatAction.handleIncomingTcToken`.
|
|
9
|
+
* Works for both pre- and post-normalized JIDs (`@c.us` vs `@s.whatsapp.net`).
|
|
10
|
+
*/
|
|
11
|
+
function isRegularUser(jid) {
|
|
12
|
+
if (!jid)
|
|
13
|
+
return false;
|
|
14
|
+
const user = jid.split('@')[0] ?? '';
|
|
15
|
+
if (user === '0')
|
|
16
|
+
return false; // PSA
|
|
17
|
+
if (BOT_PHONE_REGEX.test(user))
|
|
18
|
+
return false; // Bot by phone pattern
|
|
19
|
+
if (isJidMetaAI(jid))
|
|
20
|
+
return false; // MetaAI (@bot server)
|
|
21
|
+
return !!(isPnUser(jid) || isLidUser(jid) || isHostedPnUser(jid) || isHostedLidUser(jid) || jid.endsWith('@c.us'));
|
|
22
|
+
}
|
|
23
|
+
const TC_TOKEN_BUCKET_DURATION = 604800; // 7 days
|
|
24
|
+
const TC_TOKEN_NUM_BUCKETS = 4; // ~28-day rolling window
|
|
25
|
+
/** Sentinel key under `tctoken` store holding a JSON array of tracked storage JIDs for cross-session pruning. */
|
|
26
|
+
export const TC_TOKEN_INDEX_KEY = '__index';
|
|
27
|
+
/** Read the persisted tctoken JID index and return its entries (never contains the sentinel key itself). */
|
|
28
|
+
export async function readTcTokenIndex(keys) {
|
|
29
|
+
const data = await keys.get('tctoken', [TC_TOKEN_INDEX_KEY]);
|
|
30
|
+
const entry = data[TC_TOKEN_INDEX_KEY];
|
|
31
|
+
if (!entry?.token?.length)
|
|
32
|
+
return [];
|
|
33
|
+
try {
|
|
34
|
+
const parsed = JSON.parse(Buffer.from(entry.token).toString());
|
|
35
|
+
if (!Array.isArray(parsed))
|
|
36
|
+
return [];
|
|
37
|
+
return parsed.filter((j) => typeof j === 'string' && j.length > 0 && j !== TC_TOKEN_INDEX_KEY);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** Build a SignalDataSet fragment that writes the merged index (persisted ∪ added) under the sentinel key. */
|
|
44
|
+
export async function buildMergedTcTokenIndexWrite(keys, addedJids) {
|
|
45
|
+
const persisted = await readTcTokenIndex(keys);
|
|
46
|
+
const merged = new Set(persisted);
|
|
47
|
+
for (const jid of addedJids) {
|
|
48
|
+
if (jid && jid !== TC_TOKEN_INDEX_KEY)
|
|
49
|
+
merged.add(jid);
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
[TC_TOKEN_INDEX_KEY]: { token: Buffer.from(JSON.stringify([...merged])) }
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// WA Web has separate sender/receiver AB props for these but they're identical today
|
|
56
|
+
export function isTcTokenExpired(timestamp) {
|
|
57
|
+
if (timestamp === null || timestamp === undefined)
|
|
58
|
+
return true;
|
|
59
|
+
const ts = typeof timestamp === 'string' ? parseInt(timestamp) : timestamp;
|
|
60
|
+
if (isNaN(ts))
|
|
61
|
+
return true;
|
|
62
|
+
const now = Math.floor(Date.now() / 1000);
|
|
63
|
+
const currentBucket = Math.floor(now / TC_TOKEN_BUCKET_DURATION);
|
|
64
|
+
const cutoffBucket = currentBucket - (TC_TOKEN_NUM_BUCKETS - 1);
|
|
65
|
+
const cutoffTimestamp = cutoffBucket * TC_TOKEN_BUCKET_DURATION;
|
|
66
|
+
return ts < cutoffTimestamp;
|
|
67
|
+
}
|
|
68
|
+
export function shouldSendNewTcToken(senderTimestamp) {
|
|
69
|
+
if (senderTimestamp === undefined)
|
|
70
|
+
return true;
|
|
71
|
+
const now = Math.floor(Date.now() / 1000);
|
|
72
|
+
const currentBucket = Math.floor(now / TC_TOKEN_BUCKET_DURATION);
|
|
73
|
+
const senderBucket = Math.floor(senderTimestamp / TC_TOKEN_BUCKET_DURATION);
|
|
74
|
+
return currentBucket > senderBucket;
|
|
75
|
+
}
|
|
76
|
+
/** Resolve JID to LID for tctoken storage (WA Web stores under LID) */
|
|
77
|
+
export async function resolveTcTokenJid(jid, getLIDForPN) {
|
|
78
|
+
if (isLidUser(jid))
|
|
79
|
+
return jid;
|
|
80
|
+
const lid = await getLIDForPN(jid);
|
|
81
|
+
return lid ?? jid;
|
|
82
|
+
}
|
|
83
|
+
/** Resolve target JID for issuing privacy token based on AB prop 14303 */
|
|
84
|
+
export async function resolveIssuanceJid(jid, issueToLid, getLIDForPN, getPNForLID) {
|
|
85
|
+
if (issueToLid) {
|
|
86
|
+
if (isLidUser(jid))
|
|
87
|
+
return jid;
|
|
88
|
+
const lid = await getLIDForPN(jid);
|
|
89
|
+
return lid ?? jid;
|
|
90
|
+
}
|
|
91
|
+
if (!isLidUser(jid))
|
|
92
|
+
return jid;
|
|
93
|
+
if (getPNForLID) {
|
|
94
|
+
const pn = await getPNForLID(jid);
|
|
95
|
+
return pn ?? jid;
|
|
96
|
+
}
|
|
97
|
+
return jid;
|
|
98
|
+
}
|
|
99
|
+
export async function buildTcTokenFromJid({ authState, jid, baseContent = [], getLIDForPN }) {
|
|
100
|
+
try {
|
|
101
|
+
const storageJid = await resolveTcTokenJid(jid, getLIDForPN);
|
|
102
|
+
const tcTokenData = await authState.keys.get('tctoken', [storageJid]);
|
|
103
|
+
const entry = tcTokenData?.[storageJid];
|
|
104
|
+
const tcTokenBuffer = entry?.token;
|
|
105
|
+
if (!tcTokenBuffer?.length || isTcTokenExpired(entry?.timestamp)) {
|
|
106
|
+
if (tcTokenBuffer) {
|
|
107
|
+
// Preserve senderTimestamp so shouldSendNewTcToken() keeps its dedupe state
|
|
108
|
+
// after we drop the unusable peer token. Only wipe the record entirely when
|
|
109
|
+
// there's nothing worth keeping.
|
|
110
|
+
const cleared = entry?.senderTimestamp !== undefined
|
|
111
|
+
? { token: Buffer.alloc(0), senderTimestamp: entry.senderTimestamp }
|
|
112
|
+
: null;
|
|
113
|
+
await authState.keys.set({ tctoken: { [storageJid]: cleared } });
|
|
114
|
+
}
|
|
115
|
+
return baseContent.length > 0 ? baseContent : undefined;
|
|
116
|
+
}
|
|
117
|
+
baseContent.push({
|
|
118
|
+
tag: 'tctoken',
|
|
119
|
+
attrs: {},
|
|
120
|
+
content: tcTokenBuffer
|
|
121
|
+
});
|
|
122
|
+
return baseContent;
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
return baseContent.length > 0 ? baseContent : undefined;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
export async function storeTcTokensFromIqResult({ result, fallbackJid, keys, getLIDForPN, onNewJidStored }) {
|
|
129
|
+
const tokensNode = getBinaryNodeChild(result, 'tokens');
|
|
130
|
+
if (!tokensNode)
|
|
131
|
+
return;
|
|
132
|
+
const tokenNodes = getBinaryNodeChildren(tokensNode, 'token');
|
|
133
|
+
for (const tokenNode of tokenNodes) {
|
|
134
|
+
if (tokenNode.attrs.type !== 'trusted_contact' || !(tokenNode.content instanceof Uint8Array)) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
// In notifications tokenNode.attrs.jid is your own device JID, not the sender's
|
|
138
|
+
const rawJid = jidNormalizedUser(fallbackJid || tokenNode.attrs.jid);
|
|
139
|
+
if (!isRegularUser(rawJid))
|
|
140
|
+
continue;
|
|
141
|
+
const storageJid = await resolveTcTokenJid(rawJid, getLIDForPN);
|
|
142
|
+
const existingTcData = await keys.get('tctoken', [storageJid]);
|
|
143
|
+
const existingEntry = existingTcData[storageJid];
|
|
144
|
+
const existingTs = existingEntry?.timestamp ? Number(existingEntry.timestamp) : 0;
|
|
145
|
+
const incomingTs = tokenNode.attrs.t ? Number(tokenNode.attrs.t) : 0;
|
|
146
|
+
// timestamp-less tokens would be immediately expired
|
|
147
|
+
if (!incomingTs)
|
|
148
|
+
continue;
|
|
149
|
+
if (existingTs > 0 && existingTs > incomingTs)
|
|
150
|
+
continue;
|
|
151
|
+
await keys.set({
|
|
152
|
+
tctoken: {
|
|
153
|
+
[storageJid]: {
|
|
154
|
+
...existingEntry,
|
|
155
|
+
token: Buffer.from(tokenNode.content),
|
|
156
|
+
timestamp: tokenNode.attrs.t
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
onNewJidStored?.(storageJid);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export class TemplateManager {
|
|
2
|
+
templates: Map<any, any>;
|
|
3
|
+
generateId(): string;
|
|
4
|
+
extractVariables(content: any): {
|
|
5
|
+
name: string;
|
|
6
|
+
defaultValue: string;
|
|
7
|
+
required: boolean;
|
|
8
|
+
}[];
|
|
9
|
+
create(options: any): {
|
|
10
|
+
id: any;
|
|
11
|
+
name: any;
|
|
12
|
+
content: any;
|
|
13
|
+
description: any;
|
|
14
|
+
category: any;
|
|
15
|
+
variables: {
|
|
16
|
+
name: string;
|
|
17
|
+
defaultValue: string;
|
|
18
|
+
required: boolean;
|
|
19
|
+
}[];
|
|
20
|
+
createdAt: Date;
|
|
21
|
+
updatedAt: Date;
|
|
22
|
+
};
|
|
23
|
+
get(id: any): any;
|
|
24
|
+
getByName(name: any): any;
|
|
25
|
+
getAll(): any[];
|
|
26
|
+
getByCategory(category: any): any[];
|
|
27
|
+
update(id: any, updates: any): any;
|
|
28
|
+
delete(id: any): boolean;
|
|
29
|
+
renderContent(content: any, data?: {}): any;
|
|
30
|
+
render(id: any, data?: {}): any;
|
|
31
|
+
validate(id: any, data: any): {
|
|
32
|
+
valid: boolean;
|
|
33
|
+
missing: any;
|
|
34
|
+
};
|
|
35
|
+
export(): string;
|
|
36
|
+
import(json: any, overwrite?: boolean): number;
|
|
37
|
+
}
|
|
38
|
+
export namespace PRESET_TEMPLATES {
|
|
39
|
+
namespace ORDER_CONFIRMATION {
|
|
40
|
+
let name: string;
|
|
41
|
+
let category: string;
|
|
42
|
+
let content: string;
|
|
43
|
+
}
|
|
44
|
+
namespace WELCOME {
|
|
45
|
+
let name_1: string;
|
|
46
|
+
export { name_1 as name };
|
|
47
|
+
let category_1: string;
|
|
48
|
+
export { category_1 as category };
|
|
49
|
+
let content_1: string;
|
|
50
|
+
export { content_1 as content };
|
|
51
|
+
}
|
|
52
|
+
namespace REMINDER {
|
|
53
|
+
let name_2: string;
|
|
54
|
+
export { name_2 as name };
|
|
55
|
+
let category_2: string;
|
|
56
|
+
export { category_2 as category };
|
|
57
|
+
let content_2: string;
|
|
58
|
+
export { content_2 as content };
|
|
59
|
+
}
|
|
60
|
+
namespace SUPPORT_TICKET {
|
|
61
|
+
let name_3: string;
|
|
62
|
+
export { name_3 as name };
|
|
63
|
+
let category_3: string;
|
|
64
|
+
export { category_3 as category };
|
|
65
|
+
let content_3: string;
|
|
66
|
+
export { content_3 as content };
|
|
67
|
+
}
|
|
68
|
+
namespace BIRTHDAY {
|
|
69
|
+
let name_4: string;
|
|
70
|
+
export { name_4 as name };
|
|
71
|
+
let category_4: string;
|
|
72
|
+
export { category_4 as category };
|
|
73
|
+
let content_4: string;
|
|
74
|
+
export { content_4 as content };
|
|
75
|
+
}
|
|
76
|
+
namespace INVOICE {
|
|
77
|
+
let name_5: string;
|
|
78
|
+
export { name_5 as name };
|
|
79
|
+
let category_5: string;
|
|
80
|
+
export { category_5 as category };
|
|
81
|
+
let content_5: string;
|
|
82
|
+
export { content_5 as content };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export function createTemplateManager(includePresets?: boolean): TemplateManager;
|
|
86
|
+
export function renderTemplate(content: any, data?: {}): any;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
export class TemplateManager {
|
|
2
|
+
templates = new Map();
|
|
3
|
+
generateId() {
|
|
4
|
+
return `tpl_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
5
|
+
}
|
|
6
|
+
extractVariables(content) {
|
|
7
|
+
const regex = /\{\{(\w+)(?::([^}]*))?\}\}/g;
|
|
8
|
+
const variables = [];
|
|
9
|
+
const seen = new Set();
|
|
10
|
+
let match;
|
|
11
|
+
while ((match = regex.exec(content)) !== null) {
|
|
12
|
+
const name = match[1];
|
|
13
|
+
if (!name || seen.has(name))
|
|
14
|
+
continue;
|
|
15
|
+
seen.add(name);
|
|
16
|
+
variables.push({ name, defaultValue: match[2], required: !match[2] });
|
|
17
|
+
}
|
|
18
|
+
return variables;
|
|
19
|
+
}
|
|
20
|
+
create(options) {
|
|
21
|
+
const template = {
|
|
22
|
+
id: options.id ?? this.generateId(),
|
|
23
|
+
name: options.name,
|
|
24
|
+
content: options.content,
|
|
25
|
+
description: options.description,
|
|
26
|
+
category: options.category,
|
|
27
|
+
variables: this.extractVariables(options.content),
|
|
28
|
+
createdAt: new Date(),
|
|
29
|
+
updatedAt: new Date()
|
|
30
|
+
};
|
|
31
|
+
this.templates.set(template.id, template);
|
|
32
|
+
return template;
|
|
33
|
+
}
|
|
34
|
+
get(id) {
|
|
35
|
+
return this.templates.get(id);
|
|
36
|
+
}
|
|
37
|
+
getByName(name) {
|
|
38
|
+
return Array.from(this.templates.values()).find((t) => t.name === name);
|
|
39
|
+
}
|
|
40
|
+
getAll() {
|
|
41
|
+
return Array.from(this.templates.values());
|
|
42
|
+
}
|
|
43
|
+
getByCategory(category) {
|
|
44
|
+
return Array.from(this.templates.values()).filter((t) => t.category === category);
|
|
45
|
+
}
|
|
46
|
+
update(id, updates) {
|
|
47
|
+
const template = this.templates.get(id);
|
|
48
|
+
if (!template)
|
|
49
|
+
return undefined;
|
|
50
|
+
if (updates.content)
|
|
51
|
+
updates.variables = this.extractVariables(updates.content);
|
|
52
|
+
const updated = { ...template, ...updates, updatedAt: new Date() };
|
|
53
|
+
this.templates.set(id, updated);
|
|
54
|
+
return updated;
|
|
55
|
+
}
|
|
56
|
+
delete(id) {
|
|
57
|
+
return this.templates.delete(id);
|
|
58
|
+
}
|
|
59
|
+
renderContent(content, data = {}) {
|
|
60
|
+
return content.replace(/\{\{(\w+)(?::([^}]*))?\}\}/g, (match, name, defaultValue) => {
|
|
61
|
+
const value = data[name];
|
|
62
|
+
if (value !== undefined && value !== null)
|
|
63
|
+
return String(value);
|
|
64
|
+
if (defaultValue !== undefined)
|
|
65
|
+
return defaultValue;
|
|
66
|
+
return match;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
render(id, data = {}) {
|
|
70
|
+
const template = this.templates.get(id);
|
|
71
|
+
if (!template)
|
|
72
|
+
throw new Error(`Template not found: ${id}`);
|
|
73
|
+
return this.renderContent(template.content, data);
|
|
74
|
+
}
|
|
75
|
+
validate(id, data) {
|
|
76
|
+
const template = this.templates.get(id);
|
|
77
|
+
if (!template)
|
|
78
|
+
throw new Error(`Template not found: ${id}`);
|
|
79
|
+
const missing = template.variables.filter((v) => v.required && !(v.name in data)).map((v) => v.name);
|
|
80
|
+
return { valid: missing.length === 0, missing };
|
|
81
|
+
}
|
|
82
|
+
export() {
|
|
83
|
+
return JSON.stringify(Array.from(this.templates.values()), null, 2);
|
|
84
|
+
}
|
|
85
|
+
import(json, overwrite = false) {
|
|
86
|
+
const templates = JSON.parse(json);
|
|
87
|
+
let imported = 0;
|
|
88
|
+
for (const t of templates) {
|
|
89
|
+
if (!overwrite && this.templates.has(t.id))
|
|
90
|
+
continue;
|
|
91
|
+
this.templates.set(t.id, { ...t, createdAt: new Date(t.createdAt), updatedAt: new Date(t.updatedAt) });
|
|
92
|
+
imported++;
|
|
93
|
+
}
|
|
94
|
+
return imported;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** Ready-made templates covering common bot scenarios (order, welcome, reminder, etc). */
|
|
98
|
+
export const PRESET_TEMPLATES = {
|
|
99
|
+
ORDER_CONFIRMATION: {
|
|
100
|
+
name: 'Order Confirmation',
|
|
101
|
+
category: 'order',
|
|
102
|
+
content: `✅ *Order Confirmed!*\n\nOrder ID: #{{orderId}}\nCustomer: {{customerName}}\nDate: {{orderDate}}\n\n📦 *Items:*\n{{items}}\n\n💰 *Total: {{total}}*\n\nThank you! 🙏`
|
|
103
|
+
},
|
|
104
|
+
WELCOME: {
|
|
105
|
+
name: 'Welcome Message',
|
|
106
|
+
category: 'greeting',
|
|
107
|
+
content: `👋 *Welcome, {{name}}!*\n\nThank you for joining {{companyName:us}}!\nNeed help? Reply to this message!`
|
|
108
|
+
},
|
|
109
|
+
REMINDER: {
|
|
110
|
+
name: 'Reminder',
|
|
111
|
+
category: 'notification',
|
|
112
|
+
content: `⏰ *Reminder*\n\nHi {{name}},\n\n📋 {{subject}}\n📅 Date: {{date}}\n🕐 Time: {{time}}\n📍 Location: {{location:TBD}}`
|
|
113
|
+
},
|
|
114
|
+
SUPPORT_TICKET: {
|
|
115
|
+
name: 'Support Ticket',
|
|
116
|
+
category: 'support',
|
|
117
|
+
content: `🎫 *Support Ticket Created*\n\nTicket #: {{ticketId}}\nSubject: {{subject}}\n\nHi {{name}},\n\nWe received your request! Response time: {{responseTime:24 hours}} 🙏`
|
|
118
|
+
},
|
|
119
|
+
BIRTHDAY: {
|
|
120
|
+
name: 'Birthday Wishes',
|
|
121
|
+
category: 'greeting',
|
|
122
|
+
content: `🎂 *Happy Birthday, {{name}}!* 🎉\n\nWishing you a wonderful day!\n\n🎁 Use code: {{code}} for {{discount:10}}% off! 🥳`
|
|
123
|
+
},
|
|
124
|
+
INVOICE: {
|
|
125
|
+
name: 'Invoice',
|
|
126
|
+
category: 'invoice',
|
|
127
|
+
content: `🧾 *Invoice {{invoiceNumber}}*\n\nBilled to: {{customerName}}\nInvoice date: {{invoiceDate}}\nDue date: {{dueDate:on receipt}}\n\n📋 *Items:*\n{{items}}\n\nSubtotal: {{subtotal}}\n💰 *Total: {{total}}*\n\nThank you for your business! 🙏`
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
export const createTemplateManager = (includePresets = true) => {
|
|
131
|
+
const manager = new TemplateManager();
|
|
132
|
+
if (includePresets) {
|
|
133
|
+
for (const [key, template] of Object.entries(PRESET_TEMPLATES)) {
|
|
134
|
+
manager.create({ ...template, id: key.toLowerCase() });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return manager;
|
|
138
|
+
};
|
|
139
|
+
export const renderTemplate = (content, data = {}) => {
|
|
140
|
+
return content.replace(/\{\{(\w+)(?::([^}]*))?\}\}/g, (match, name, defaultValue) => {
|
|
141
|
+
const value = data[name];
|
|
142
|
+
if (value !== undefined && value !== null)
|
|
143
|
+
return String(value);
|
|
144
|
+
if (defaultValue !== undefined)
|
|
145
|
+
return defaultValue;
|
|
146
|
+
return match;
|
|
147
|
+
});
|
|
148
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Default part size. WhatsApp accepts far more, but long single bubbles render and quote badly; 4000 is a safe chunk. */
|
|
2
|
+
export const DEFAULT_TEXT_PART_LENGTH: 4000;
|
|
3
|
+
export function splitText(text: any, maxLen?: number): string[];
|
|
4
|
+
export function whatsappify(text: any): any;
|
|
5
|
+
export function sendLongText(sock: any, jid: any, text: any, opts1?: { [key: string]: any;
|
|
6
|
+
format?: boolean;
|
|
7
|
+
maxLen?: number;
|
|
8
|
+
delayMs?: number;
|
|
9
|
+
}): Promise<{
|
|
10
|
+
ok: boolean;
|
|
11
|
+
ids: string[];
|
|
12
|
+
error?: unknown;
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Vanz@Port (2.0.3) --- from xbibzlibrary/whatsbibz 1.4.0 (BibzWhats/send.js: splitText, whatsappify). See NOTICE.md.
|
|
2
|
+
// Changed vs donor: whatsappify leaves fenced/inline code untouched (the donor rewrote `**x**` inside code blocks), splitText never cuts
|
|
3
|
+
// an emoji/surrogate pair in half, and sendLongText does NOT retry a failed send (a retry after a partial relay can post duplicates).
|
|
4
|
+
/** Default part size. WhatsApp accepts far more, but long single bubbles render and quote badly; 4000 is a safe chunk. */
|
|
5
|
+
export const DEFAULT_TEXT_PART_LENGTH = 4000;
|
|
6
|
+
/** Split long text into parts <= maxLen, preferring a newline, then a space, then a hard cut (never inside a surrogate pair). */
|
|
7
|
+
export const splitText = (text, maxLen = DEFAULT_TEXT_PART_LENGTH) => {
|
|
8
|
+
const limit = Number.isFinite(maxLen) && maxLen >= 2 ? Math.floor(maxLen) : DEFAULT_TEXT_PART_LENGTH;
|
|
9
|
+
const out = [];
|
|
10
|
+
let rest = String(text ?? '');
|
|
11
|
+
while (rest.length > limit) {
|
|
12
|
+
let cut = rest.lastIndexOf('\n', limit);
|
|
13
|
+
if (cut < limit * 0.5) {
|
|
14
|
+
cut = rest.lastIndexOf(' ', limit);
|
|
15
|
+
}
|
|
16
|
+
if (cut < limit * 0.5) {
|
|
17
|
+
cut = limit;
|
|
18
|
+
const prev = rest.charCodeAt(cut - 1);
|
|
19
|
+
if (prev >= 0xd800 && prev <= 0xdbff) {
|
|
20
|
+
cut -= 1; // do not split a surrogate pair
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
out.push(rest.slice(0, cut).trim());
|
|
24
|
+
rest = rest.slice(cut).trim();
|
|
25
|
+
}
|
|
26
|
+
if (rest) {
|
|
27
|
+
out.push(rest);
|
|
28
|
+
}
|
|
29
|
+
return out.filter(Boolean);
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Normalise ChatGPT-style markdown to WhatsApp formatting: **bold** / __bold__ -> *bold*, ~~strike~~ -> ~strike~,
|
|
33
|
+
* "# heading" -> "heading", [text](url) -> "text (url)". Fenced (```...```) and inline (`...`) code is left exactly as written.
|
|
34
|
+
*/
|
|
35
|
+
export const whatsappify = (text) => {
|
|
36
|
+
if (typeof text !== 'string' || !text) {
|
|
37
|
+
return text;
|
|
38
|
+
}
|
|
39
|
+
const stash = [];
|
|
40
|
+
const hold = (m) => `\u0000${stash.push(m) - 1}\u0000`;
|
|
41
|
+
let t = text.replace(/```[\s\S]*?```/g, hold).replace(/`[^`\n]+`/g, hold);
|
|
42
|
+
for (let i = 0; i < 3; i++) {
|
|
43
|
+
t = t.replace(/\*\*\*([^*\n]+)\*\*\*/g, '*$1*');
|
|
44
|
+
t = t.replace(/\*\*([^*\n]+)\*\*/g, '*$1*');
|
|
45
|
+
t = t.replace(/__([^_\n]+)__/g, '*$1*');
|
|
46
|
+
}
|
|
47
|
+
t = t.replace(/_{2,}([^_\n]+)_{2,}/g, '_$1_');
|
|
48
|
+
t = t.replace(/~~([^~\n]+)~~/g, '~$1~');
|
|
49
|
+
t = t.replace(/^\s{0,3}#{1,6}\s+/gm, '');
|
|
50
|
+
t = t.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, '$1 ($2)');
|
|
51
|
+
t = t.replace(/\*{3,}/g, '*').replace(/_{3,}/g, '_');
|
|
52
|
+
t = t.replace(/\u0000(\d+)\u0000/g, (_, i) => stash[Number(i)]);
|
|
53
|
+
return t.trim();
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Send long text as several messages. Stops at the first failure (no automatic retry).
|
|
57
|
+
* @returns {Promise<{ ok: boolean, ids: string[], error?: unknown }>}
|
|
58
|
+
*/
|
|
59
|
+
export const sendLongText = async (sock, jid, text, { quoted, format = true, maxLen = DEFAULT_TEXT_PART_LENGTH, delayMs = 250 } = {}) => {
|
|
60
|
+
if (!sock || typeof sock.sendMessage !== 'function') {
|
|
61
|
+
throw new TypeError('sendLongText(sock, ...) requires a socket with sendMessage');
|
|
62
|
+
}
|
|
63
|
+
const body = format ? whatsappify(String(text ?? '')) : String(text ?? '');
|
|
64
|
+
const parts = splitText(body, maxLen);
|
|
65
|
+
const ids = [];
|
|
66
|
+
for (let i = 0; i < parts.length; i++) {
|
|
67
|
+
try {
|
|
68
|
+
const result = await sock.sendMessage(jid, { text: parts[i] }, quoted ? { quoted } : undefined);
|
|
69
|
+
if (result?.key?.id) {
|
|
70
|
+
ids.push(result.key.id);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
return { ok: false, ids, error };
|
|
75
|
+
}
|
|
76
|
+
if (delayMs > 0 && i < parts.length - 1) {
|
|
77
|
+
await new Promise((r) => setTimeout(r, delayMs));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return { ok: true, ids };
|
|
81
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Vanz@Port (2.0.3) --- from @japofc/baileys 2.4.1 (MIT, author JAPofc / J.AP), lib/Utils/text-tools.js. See NOTICE.md.
|
|
2
|
+
// sendBroadcast is NOT ported (bulk-send helper; pacing/anti-spam policy belongs in the bot, not the library).
|
|
3
|
+
// Fix vs donor: parseMentions ignored context, so an e-mail such as "foo@123456.com" yielded a bogus mention. A mention must
|
|
4
|
+
// now start the string or follow whitespace/punctuation, and must not be followed by more word characters or a domain dot.
|
|
5
|
+
const MENTION_RE = /(?<![\w.])@(\d{5,20})(?![\w]|\.\w)/g;
|
|
6
|
+
const INVITE_RE = /(?:https?:\/\/)?chat\.whatsapp\.com\/(?:invite\/)?([0-9A-Za-z]{16,32})/;
|
|
7
|
+
/** '@62812… halo @62813…' -> ['62812…@s.whatsapp.net', …] (de-duplicated, order of first appearance). */
|
|
8
|
+
export const parseMentions = (text) => {
|
|
9
|
+
if (typeof text !== 'string' || !text) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
const seen = new Set();
|
|
13
|
+
const out = [];
|
|
14
|
+
for (const m of text.matchAll(MENTION_RE)) {
|
|
15
|
+
const jid = `${m[1]}@s.whatsapp.net`;
|
|
16
|
+
if (!seen.has(jid)) {
|
|
17
|
+
seen.add(jid);
|
|
18
|
+
out.push(jid);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
};
|
|
23
|
+
/** Pull the invite code out of a chat.whatsapp.com link (or text containing one). Returns null when absent. */
|
|
24
|
+
export const extractGroupInviteCode = (link) => {
|
|
25
|
+
if (typeof link !== 'string' || !link) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const m = link.match(INVITE_RE);
|
|
29
|
+
return m ? m[1] : null;
|
|
30
|
+
};
|
|
31
|
+
/** Join a group from an invite link or bare code via sock.groupAcceptInvite. Throws when no code can be found. */
|
|
32
|
+
export const joinGroupViaLink = async (sock, linkOrCode) => {
|
|
33
|
+
const code = extractGroupInviteCode(linkOrCode) ?? (/^[0-9A-Za-z]{16,32}$/.test(String(linkOrCode ?? '')) ? String(linkOrCode) : null);
|
|
34
|
+
if (!code) {
|
|
35
|
+
throw new Error(`joinGroupViaLink: no invite code found in ${JSON.stringify(linkOrCode)}`);
|
|
36
|
+
}
|
|
37
|
+
return sock.groupAcceptInvite(code);
|
|
38
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* Elaina Baileys maintained distribution. Upstream notices and license are preserved in LICENSE and NOTICE.md. */
|
|
2
|
+
export declare class TTLCache<T = any> {
|
|
3
|
+
constructor(options?: {
|
|
4
|
+
/** lifetime in seconds, the same unit node-cache used; 0 or omitted means no expiry */
|
|
5
|
+
stdTTL?: number;
|
|
6
|
+
/** ceiling on entries, the oldest is evicted once it is reached */
|
|
7
|
+
maxKeys?: number;
|
|
8
|
+
/** alias for maxKeys */
|
|
9
|
+
max?: number;
|
|
10
|
+
/** lifetime in milliseconds, takes precedence over stdTTL */
|
|
11
|
+
ttl?: number;
|
|
12
|
+
});
|
|
13
|
+
get(key: string | number): T | undefined;
|
|
14
|
+
set(key: string | number, value: T, ttl?: number): boolean;
|
|
15
|
+
has(key: string | number): boolean;
|
|
16
|
+
del(keys: string | number | Array<string | number>): number;
|
|
17
|
+
take(key: string | number): T | undefined;
|
|
18
|
+
mget(keys: Array<string | number>): Record<string, T>;
|
|
19
|
+
mset(list: Array<{ key: string | number; value?: T; val?: T; ttl?: number }>): boolean;
|
|
20
|
+
keys(): string[];
|
|
21
|
+
flushAll(): void;
|
|
22
|
+
getStats(): { hits: number; misses: number; keys: number; ksize: number; vsize: number };
|
|
23
|
+
close(): void;
|
|
24
|
+
on(): this;
|
|
25
|
+
off(): this;
|
|
26
|
+
removeAllListeners(): this;
|
|
27
|
+
readonly size: number;
|
|
28
|
+
}
|
|
29
|
+
export default TTLCache;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// Ported into @vanzxysenpai/baileys 0.0.1 from @rexxhayanasi/elaina-baileys 1.4.7, MIT. See NOTICE.md.
|
|
2
|
+
/* Elaina Baileys maintained distribution. Upstream notices and license are preserved in LICENSE and NOTICE.md. */
|
|
3
|
+
import { LRUCache } from 'lru-cache';
|
|
4
|
+
// DEFAULT_CACHE_MAX_KEYS is not exported by this package's Defaults; same value as Elaina's Defaults.
|
|
5
|
+
const DEFAULT_CACHE_MAX_KEYS = 20_000;
|
|
6
|
+
|
|
7
|
+
const asKey = (key) => (typeof key === 'string' ? key : String(key));
|
|
8
|
+
|
|
9
|
+
const toMilliseconds = (seconds) => {
|
|
10
|
+
const value = Number(seconds);
|
|
11
|
+
return Number.isFinite(value) && value > 0 ? Math.round(value * 1000) : 0;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export class TTLCache {
|
|
15
|
+
#store;
|
|
16
|
+
|
|
17
|
+
#ttl;
|
|
18
|
+
|
|
19
|
+
#hits = 0;
|
|
20
|
+
|
|
21
|
+
#misses = 0;
|
|
22
|
+
|
|
23
|
+
constructor({ stdTTL = 0, maxKeys, max, ttl } = {}) {
|
|
24
|
+
this.#ttl = ttl !== undefined ? Number(ttl) || 0 : toMilliseconds(stdTTL);
|
|
25
|
+
const limit = Number(max ?? maxKeys);
|
|
26
|
+
this.#store = new LRUCache({
|
|
27
|
+
max: Number.isFinite(limit) && limit > 0 ? limit : DEFAULT_CACHE_MAX_KEYS,
|
|
28
|
+
...(this.#ttl ? { ttl: this.#ttl } : {})
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get(key) {
|
|
33
|
+
const value = this.#store.get(asKey(key));
|
|
34
|
+
if (value === undefined) {
|
|
35
|
+
this.#misses += 1;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
this.#hits += 1;
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
set(key, value, ttl) {
|
|
44
|
+
const override = toMilliseconds(ttl);
|
|
45
|
+
this.#store.set(asKey(key), value, override ? { ttl: override } : undefined);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
has(key) {
|
|
50
|
+
return this.#store.has(asKey(key));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
del(keys) {
|
|
54
|
+
const list = Array.isArray(keys) ? keys : [keys];
|
|
55
|
+
let removed = 0;
|
|
56
|
+
for (const key of list) {
|
|
57
|
+
if (this.#store.delete(asKey(key))) {
|
|
58
|
+
removed += 1;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return removed;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
take(key) {
|
|
65
|
+
const value = this.get(key);
|
|
66
|
+
this.del(key);
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
mget(keys) {
|
|
71
|
+
const found = {};
|
|
72
|
+
for (const key of Array.isArray(keys) ? keys : [keys]) {
|
|
73
|
+
const value = this.get(key);
|
|
74
|
+
if (value !== undefined) {
|
|
75
|
+
found[key] = value;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return found;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
mset(list) {
|
|
82
|
+
for (const item of list ?? []) {
|
|
83
|
+
this.set(item.key, item.value ?? item.val, item.ttl);
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
keys() {
|
|
89
|
+
return [...this.#store.keys()];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
flushAll() {
|
|
93
|
+
this.#store.clear();
|
|
94
|
+
this.#hits = 0;
|
|
95
|
+
this.#misses = 0;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
getStats() {
|
|
99
|
+
return { hits: this.#hits, misses: this.#misses, keys: this.#store.size, ksize: 0, vsize: 0 };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
close() {
|
|
103
|
+
this.#store.clear();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
on() {
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
off() {
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
removeAllListeners() {
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
get size() {
|
|
119
|
+
return this.#store.size;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export default TTLCache;
|