@eduh_dev021/baileys 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +1843 -2
- package/WAProto/index.d.ts +22220 -0
- package/WAProto/index.js +5 -0
- package/cjs/WAProto/index.d.ts +22220 -0
- package/cjs/WAProto/index.js +60125 -0
- package/cjs/engine-requirements.js +12 -0
- package/cjs/lib/Addon/cache.js +179 -0
- package/cjs/lib/Addon/crc32.js +41 -0
- package/cjs/lib/Addon/file-type.js +217 -0
- package/cjs/lib/Addon/get-file.js +99 -0
- package/cjs/lib/Addon/http-error.d.ts +18 -0
- package/cjs/lib/Addon/http-error.js +66 -0
- package/cjs/lib/Addon/index.d.ts +96 -0
- package/cjs/lib/Addon/index.js +58 -0
- package/cjs/lib/Addon/keyed-db.d.ts +14 -0
- package/cjs/lib/Addon/keyed-db.js +264 -0
- package/cjs/lib/Addon/link-preview.d.ts +15 -0
- package/cjs/lib/Addon/link-preview.js +104 -0
- package/cjs/lib/Addon/media-info.js +98 -0
- package/cjs/lib/Addon/mutex.js +78 -0
- package/cjs/lib/Addon/qr.js +464 -0
- package/cjs/lib/Addon/queue.js +54 -0
- package/cjs/lib/Addon/waveform.js +130 -0
- package/cjs/lib/Addon/zip.js +136 -0
- package/cjs/lib/Defaults/index.d.ts +184 -0
- package/cjs/lib/Defaults/index.js +292 -0
- package/cjs/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/cjs/lib/Signal/Group/ciphertext-message.js +37 -0
- package/cjs/lib/Signal/Group/group-cipher.d.ts +10 -0
- package/cjs/lib/Signal/Group/group-cipher.js +105 -0
- package/cjs/lib/Signal/Group/group-session-builder.d.ts +7 -0
- package/cjs/lib/Signal/Group/group-session-builder.js +65 -0
- package/cjs/lib/Signal/Group/index.d.ts +11 -0
- package/cjs/lib/Signal/Group/index.js +67 -0
- package/cjs/lib/Signal/Group/keyhelper.d.ts +6 -0
- package/cjs/lib/Signal/Group/keyhelper.js +47 -0
- package/cjs/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/cjs/lib/Signal/Group/sender-chain-key.js +51 -0
- package/cjs/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/cjs/lib/Signal/Group/sender-key-distribution-message.js +80 -0
- package/cjs/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/cjs/lib/Signal/Group/sender-key-message.js +87 -0
- package/cjs/lib/Signal/Group/sender-key-name.d.ts +11 -0
- package/cjs/lib/Signal/Group/sender-key-name.js +73 -0
- package/cjs/lib/Signal/Group/sender-key-record.d.ts +12 -0
- package/cjs/lib/Signal/Group/sender-key-record.js +66 -0
- package/cjs/lib/Signal/Group/sender-key-state.d.ts +16 -0
- package/cjs/lib/Signal/Group/sender-key-state.js +106 -0
- package/cjs/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/cjs/lib/Signal/Group/sender-message-key.js +51 -0
- package/cjs/lib/Signal/libsignal.d.ts +54 -0
- package/cjs/lib/Signal/libsignal.js +421 -0
- package/cjs/lib/Signal/lid-mapping.d.ts +20 -0
- package/cjs/lib/Signal/lid-mapping.js +292 -0
- package/cjs/lib/Socket/Client/index.d.ts +2 -0
- package/cjs/lib/Socket/Client/index.js +23 -0
- package/cjs/lib/Socket/Client/types.d.ts +5 -0
- package/cjs/lib/Socket/Client/types.js +36 -0
- package/cjs/lib/Socket/Client/websocket.d.ts +12 -0
- package/cjs/lib/Socket/Client/websocket.js +143 -0
- package/cjs/lib/Socket/business.d.ts +387 -0
- package/cjs/lib/Socket/business.js +402 -0
- package/cjs/lib/Socket/chats.d.ts +144 -0
- package/cjs/lib/Socket/chats.js +1118 -0
- package/cjs/lib/Socket/communities.d.ts +554 -0
- package/cjs/lib/Socket/communities.js +456 -0
- package/cjs/lib/Socket/groups.d.ts +286 -0
- package/cjs/lib/Socket/groups.js +366 -0
- package/cjs/lib/Socket/index.d.ts +522 -0
- package/cjs/lib/Socket/index.js +32 -0
- package/cjs/lib/Socket/messages-recv.d.ts +326 -0
- package/cjs/lib/Socket/messages-recv.js +1670 -0
- package/cjs/lib/Socket/messages-send.d.ts +321 -0
- package/cjs/lib/Socket/messages-send.js +1252 -0
- package/cjs/lib/Socket/mex.d.ts +1 -0
- package/cjs/lib/Socket/mex.js +65 -0
- package/cjs/lib/Socket/newsletter.d.ts +283 -0
- package/cjs/lib/Socket/newsletter.js +243 -0
- package/cjs/lib/Socket/socket.d.ts +61 -0
- package/cjs/lib/Socket/socket.js +908 -0
- package/cjs/lib/Store/index.d.ts +3 -0
- package/cjs/lib/Store/index.js +25 -0
- package/cjs/lib/Store/make-in-memory-store.d.ts +63 -0
- package/cjs/lib/Store/make-in-memory-store.js +431 -0
- package/cjs/lib/Store/make-ordered-dictionary.d.ts +12 -0
- package/cjs/lib/Store/make-ordered-dictionary.js +101 -0
- package/cjs/lib/Store/object-repository.d.ts +10 -0
- package/cjs/lib/Store/object-repository.js +49 -0
- package/cjs/lib/Transport/crypto.d.ts +6 -0
- package/cjs/lib/Transport/crypto.js +107 -0
- package/cjs/lib/Transport/curve.d.ts +8 -0
- package/cjs/lib/Transport/curve.js +94 -0
- package/cjs/lib/Transport/index.d.ts +16 -0
- package/cjs/lib/Transport/index.js +67 -0
- package/cjs/lib/Transport/internals.d.ts +57 -0
- package/cjs/lib/Transport/internals.js +203 -0
- package/cjs/lib/Transport/session-builder.d.ts +40 -0
- package/cjs/lib/Transport/session-builder.js +169 -0
- package/cjs/lib/Transport/session-cipher.d.ts +26 -0
- package/cjs/lib/Transport/session-cipher.js +328 -0
- package/cjs/lib/Transport/session-record.d.ts +55 -0
- package/cjs/lib/Transport/session-record.js +289 -0
- package/cjs/lib/Types/Auth.d.ts +1 -0
- package/cjs/lib/Types/Auth.js +15 -0
- package/cjs/lib/Types/Bussines.d.ts +1 -0
- package/cjs/lib/Types/Bussines.js +15 -0
- package/cjs/lib/Types/Call.d.ts +1 -0
- package/cjs/lib/Types/Call.js +15 -0
- package/cjs/lib/Types/Chat.d.ts +1 -0
- package/cjs/lib/Types/Chat.js +33 -0
- package/cjs/lib/Types/Contact.d.ts +1 -0
- package/cjs/lib/Types/Contact.js +15 -0
- package/cjs/lib/Types/Events.d.ts +1 -0
- package/cjs/lib/Types/Events.js +1 -0
- package/cjs/lib/Types/GroupMetadata.d.ts +1 -0
- package/cjs/lib/Types/GroupMetadata.js +15 -0
- package/cjs/lib/Types/Label.d.ts +2 -0
- package/cjs/lib/Types/Label.js +49 -0
- package/cjs/lib/Types/LabelAssociation.d.ts +2 -0
- package/cjs/lib/Types/LabelAssociation.js +31 -0
- package/cjs/lib/Types/Message.d.ts +11 -0
- package/cjs/lib/Types/Message.js +58 -0
- package/cjs/lib/Types/Mex.d.ts +2 -0
- package/cjs/lib/Types/Mex.js +66 -0
- package/cjs/lib/Types/Product.d.ts +1 -0
- package/cjs/lib/Types/Product.js +15 -0
- package/cjs/lib/Types/RichType.d.ts +2 -0
- package/cjs/lib/Types/RichType.js +50 -0
- package/cjs/lib/Types/Signal.d.ts +1 -0
- package/cjs/lib/Types/Signal.js +1 -0
- package/cjs/lib/Types/Socket.d.ts +1 -0
- package/cjs/lib/Types/Socket.js +1 -0
- package/cjs/lib/Types/State.d.ts +5 -0
- package/cjs/lib/Types/State.js +83 -0
- package/cjs/lib/Types/USync.d.ts +1 -0
- package/cjs/lib/Types/USync.js +1 -0
- package/cjs/lib/Types/index.d.ts +13 -0
- package/cjs/lib/Types/index.js +64 -0
- package/cjs/lib/Utils/auth-utils.d.ts +58 -0
- package/cjs/lib/Utils/auth-utils.js +275 -0
- package/cjs/lib/Utils/browser-utils.d.ts +9 -0
- package/cjs/lib/Utils/browser-utils.js +56 -0
- package/cjs/lib/Utils/business.d.ts +49 -0
- package/cjs/lib/Utils/business.js +259 -0
- package/cjs/lib/Utils/chat-utils.d.ts +408 -0
- package/cjs/lib/Utils/chat-utils.js +821 -0
- package/cjs/lib/Utils/companion-reg-client-utils.d.ts +4 -0
- package/cjs/lib/Utils/companion-reg-client-utils.js +71 -0
- package/cjs/lib/Utils/crypto.d.ts +39 -0
- package/cjs/lib/Utils/crypto.js +155 -0
- package/cjs/lib/Utils/decode-wa-message.d.ts +83 -0
- package/cjs/lib/Utils/decode-wa-message.js +316 -0
- package/cjs/lib/Utils/event-buffer.d.ts +12 -0
- package/cjs/lib/Utils/event-buffer.js +605 -0
- package/cjs/lib/Utils/generics.d.ts +63 -0
- package/cjs/lib/Utils/generics.js +440 -0
- package/cjs/lib/Utils/history.d.ts +75 -0
- package/cjs/lib/Utils/history.js +153 -0
- package/cjs/lib/Utils/identity-change-handler.d.ts +13 -0
- package/cjs/lib/Utils/identity-change-handler.js +73 -0
- package/cjs/lib/Utils/index.d.ts +24 -0
- package/cjs/lib/Utils/index.js +67 -0
- package/cjs/lib/Utils/link-preview.d.ts +13 -0
- package/cjs/lib/Utils/link-preview.js +87 -0
- package/cjs/lib/Utils/logger.d.ts +12 -0
- package/cjs/lib/Utils/logger.js +40 -0
- package/cjs/lib/Utils/lt-hash.d.ts +6 -0
- package/cjs/lib/Utils/lt-hash.js +28 -0
- package/cjs/lib/Utils/make-mutex.d.ts +6 -0
- package/cjs/lib/Utils/make-mutex.js +58 -0
- package/cjs/lib/Utils/message-retry-manager.d.ts +79 -0
- package/cjs/lib/Utils/message-retry-manager.js +274 -0
- package/cjs/lib/Utils/messages-media.d.ts +134 -0
- package/cjs/lib/Utils/messages-media.js +799 -0
- package/cjs/lib/Utils/messages.d.ts +47 -0
- package/cjs/lib/Utils/messages.js +1667 -0
- package/cjs/lib/Utils/noise-handler.d.ts +20 -0
- package/cjs/lib/Utils/noise-handler.js +223 -0
- package/cjs/lib/Utils/offline-node-processor.d.ts +10 -0
- package/cjs/lib/Utils/offline-node-processor.js +60 -0
- package/cjs/lib/Utils/pre-key-manager.d.ts +25 -0
- package/cjs/lib/Utils/pre-key-manager.js +116 -0
- package/cjs/lib/Utils/process-message.d.ts +83 -0
- package/cjs/lib/Utils/process-message.js +607 -0
- package/cjs/lib/Utils/reporting-utils.d.ts +12 -0
- package/cjs/lib/Utils/reporting-utils.js +282 -0
- package/cjs/lib/Utils/rich-message-utils.d.ts +48 -0
- package/cjs/lib/Utils/rich-message-utils.js +381 -0
- package/cjs/lib/Utils/signal.d.ts +82 -0
- package/cjs/lib/Utils/signal.js +232 -0
- package/cjs/lib/Utils/stanza-ack.d.ts +16 -0
- package/cjs/lib/Utils/stanza-ack.js +53 -0
- package/cjs/lib/Utils/sync-action-utils.d.ts +2 -0
- package/cjs/lib/Utils/sync-action-utils.js +68 -0
- package/cjs/lib/Utils/tc-token-utils.d.ts +29 -0
- package/cjs/lib/Utils/tc-token-utils.js +182 -0
- package/cjs/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
- package/cjs/lib/Utils/use-multi-file-auth-state.js +135 -0
- package/cjs/lib/Utils/use-single-file-auth-state.d.ts +11 -0
- package/cjs/lib/Utils/use-single-file-auth-state.js +115 -0
- package/cjs/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/cjs/lib/Utils/use-sqlite-auth-state.js +140 -0
- package/cjs/lib/Utils/validate-connection.d.ts +44 -0
- package/cjs/lib/Utils/validate-connection.js +229 -0
- package/cjs/lib/WABinary/constants.d.ts +61 -0
- package/cjs/lib/WABinary/constants.js +1992 -0
- package/cjs/lib/WABinary/decode.d.ts +9 -0
- package/cjs/lib/WABinary/decode.js +292 -0
- package/cjs/lib/WABinary/encode.d.ts +2 -0
- package/cjs/lib/WABinary/encode.js +240 -0
- package/cjs/lib/WABinary/generic-utils.d.ts +79 -0
- package/cjs/lib/WABinary/generic-utils.js +252 -0
- package/cjs/lib/WABinary/index.d.ts +5 -0
- package/cjs/lib/WABinary/index.js +29 -0
- package/cjs/lib/WABinary/jid-utils.d.ts +28 -0
- package/cjs/lib/WABinary/jid-utils.js +151 -0
- package/cjs/lib/WABinary/types.d.ts +1 -0
- package/cjs/lib/WABinary/types.js +23 -0
- package/cjs/lib/WACrypto/appstate-keys.js +39 -0
- package/cjs/lib/WACrypto/curves/constants.js +37 -0
- package/cjs/lib/WACrypto/hkdf.js +38 -0
- package/cjs/lib/WACrypto/index.js +51 -0
- package/cjs/lib/WACrypto/lthash.js +59 -0
- package/cjs/lib/WACrypto/math/constants.js +53 -0
- package/cjs/lib/WACrypto/math/edwards.js +206 -0
- package/cjs/lib/WACrypto/math/fe.js +449 -0
- package/cjs/lib/WACrypto/math/le.js +44 -0
- package/cjs/lib/WACrypto/math/mod.js +36 -0
- package/cjs/lib/WACrypto/util/bytes.js +348 -0
- package/cjs/lib/WACrypto/x25519.js +157 -0
- package/cjs/lib/WACrypto/xeddsa.js +134 -0
- package/cjs/lib/WAM/BinaryInfo.d.ts +7 -0
- package/cjs/lib/WAM/BinaryInfo.js +35 -0
- package/cjs/lib/WAM/constants.d.ts +34926 -0
- package/cjs/lib/WAM/constants.js +22890 -0
- package/cjs/lib/WAM/encode.d.ts +1 -0
- package/cjs/lib/WAM/encode.js +162 -0
- package/cjs/lib/WAM/index.d.ts +3 -0
- package/cjs/lib/WAM/index.js +25 -0
- package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
- package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.js +77 -0
- package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.js +76 -0
- package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +52 -0
- package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.js +61 -0
- package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
- package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.js +50 -0
- package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
- package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +76 -0
- package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
- package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.js +53 -0
- package/cjs/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/cjs/lib/WAUSync/Protocols/index.js +29 -0
- package/cjs/lib/WAUSync/USyncQuery.d.ts +20 -0
- package/cjs/lib/WAUSync/USyncQuery.js +113 -0
- package/cjs/lib/WAUSync/USyncUser.d.ts +16 -0
- package/cjs/lib/WAUSync/USyncUser.js +56 -0
- package/cjs/lib/WAUSync/index.d.ts +3 -0
- package/cjs/lib/WAUSync/index.js +25 -0
- package/cjs/lib/index.d.ts +11 -0
- package/cjs/lib/index.js +56 -0
- package/cjs/package.json +3 -0
- package/engine-requirements.js +12 -0
- package/lib/Addon/cache.js +201 -0
- package/lib/Addon/crc32.js +21 -0
- package/lib/Addon/file-type.js +198 -0
- package/lib/Addon/get-file.js +98 -0
- package/lib/Addon/http-error.d.ts +18 -0
- package/lib/Addon/http-error.js +40 -0
- package/lib/Addon/index.d.ts +96 -0
- package/lib/Addon/index.js +26 -0
- package/lib/Addon/keyed-db.d.ts +14 -0
- package/lib/Addon/keyed-db.js +241 -0
- package/lib/Addon/link-preview.d.ts +15 -0
- package/lib/Addon/link-preview.js +79 -0
- package/lib/Addon/media-info.js +96 -0
- package/lib/Addon/mutex.js +76 -0
- package/lib/Addon/qr.js +531 -0
- package/lib/Addon/queue.js +44 -0
- package/lib/Addon/waveform.js +135 -0
- package/lib/Addon/zip.js +144 -0
- package/lib/Defaults/index.d.ts +184 -0
- package/lib/Defaults/index.js +181 -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-cipher.d.ts +10 -0
- package/lib/Signal/Group/group-cipher.js +81 -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/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +11 -0
- package/lib/Signal/Group/keyhelper.d.ts +6 -0
- package/lib/Signal/Group/keyhelper.js +17 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +25 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +65 -0
- package/lib/Signal/Group/sender-key-name.d.ts +11 -0
- package/lib/Signal/Group/sender-key-name.js +47 -0
- package/lib/Signal/Group/sender-key-record.d.ts +12 -0
- package/lib/Signal/Group/sender-key-record.js +40 -0
- package/lib/Signal/Group/sender-key-state.d.ts +16 -0
- package/lib/Signal/Group/sender-key-state.js +83 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/Group/sender-message-key.js +25 -0
- package/lib/Signal/libsignal.d.ts +54 -0
- package/lib/Signal/libsignal.js +426 -0
- package/lib/Signal/lid-mapping.d.ts +20 -0
- package/lib/Signal/lid-mapping.js +274 -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 +119 -0
- package/lib/Socket/business.d.ts +387 -0
- package/lib/Socket/business.js +379 -0
- package/lib/Socket/chats.d.ts +144 -0
- package/lib/Socket/chats.js +1216 -0
- package/lib/Socket/communities.d.ts +554 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/groups.d.ts +286 -0
- package/lib/Socket/groups.js +347 -0
- package/lib/Socket/index.d.ts +522 -0
- package/lib/Socket/index.js +11 -0
- package/lib/Socket/messages-recv.d.ts +326 -0
- package/lib/Socket/messages-recv.js +1822 -0
- package/lib/Socket/messages-send.d.ts +321 -0
- package/lib/Socket/messages-send.js +1378 -0
- package/lib/Socket/mex.d.ts +1 -0
- package/lib/Socket/mex.js +41 -0
- package/lib/Socket/newsletter.d.ts +283 -0
- package/lib/Socket/newsletter.js +225 -0
- package/lib/Socket/socket.d.ts +61 -0
- package/lib/Socket/socket.js +992 -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 +63 -0
- package/lib/Store/make-in-memory-store.js +419 -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/Transport/crypto.d.ts +6 -0
- package/lib/Transport/crypto.js +61 -0
- package/lib/Transport/curve.d.ts +8 -0
- package/lib/Transport/curve.js +66 -0
- package/lib/Transport/index.d.ts +16 -0
- package/lib/Transport/index.js +9 -0
- package/lib/Transport/internals.d.ts +57 -0
- package/lib/Transport/internals.js +155 -0
- package/lib/Transport/session-builder.d.ts +40 -0
- package/lib/Transport/session-builder.js +143 -0
- package/lib/Transport/session-cipher.d.ts +26 -0
- package/lib/Transport/session-cipher.js +301 -0
- package/lib/Transport/session-record.d.ts +55 -0
- package/lib/Transport/session-record.js +272 -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 +54 -0
- package/lib/Types/USync.d.ts +1 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.d.ts +13 -0
- package/lib/Types/index.js +25 -0
- package/lib/Utils/auth-utils.d.ts +58 -0
- package/lib/Utils/auth-utils.js +316 -0
- package/lib/Utils/browser-utils.d.ts +9 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/business.d.ts +49 -0
- package/lib/Utils/business.js +230 -0
- package/lib/Utils/chat-utils.d.ts +408 -0
- package/lib/Utils/chat-utils.js +871 -0
- package/lib/Utils/companion-reg-client-utils.d.ts +4 -0
- package/lib/Utils/companion-reg-client-utils.js +39 -0
- package/lib/Utils/crypto.d.ts +39 -0
- package/lib/Utils/crypto.js +117 -0
- package/lib/Utils/decode-wa-message.d.ts +83 -0
- package/lib/Utils/decode-wa-message.js +316 -0
- package/lib/Utils/event-buffer.d.ts +12 -0
- package/lib/Utils/event-buffer.js +621 -0
- package/lib/Utils/generics.d.ts +63 -0
- package/lib/Utils/generics.js +394 -0
- package/lib/Utils/history.d.ts +75 -0
- package/lib/Utils/history.js +133 -0
- package/lib/Utils/identity-change-handler.d.ts +13 -0
- package/lib/Utils/identity-change-handler.js +48 -0
- package/lib/Utils/index.d.ts +24 -0
- package/lib/Utils/index.js +24 -0
- package/lib/Utils/link-preview.d.ts +13 -0
- package/lib/Utils/link-preview.js +73 -0
- package/lib/Utils/logger.d.ts +12 -0
- package/lib/Utils/logger.js +12 -0
- package/lib/Utils/lt-hash.d.ts +6 -0
- package/lib/Utils/lt-hash.js +7 -0
- package/lib/Utils/make-mutex.d.ts +6 -0
- package/lib/Utils/make-mutex.js +32 -0
- package/lib/Utils/message-retry-manager.d.ts +79 -0
- package/lib/Utils/message-retry-manager.js +259 -0
- package/lib/Utils/messages-media.d.ts +134 -0
- package/lib/Utils/messages-media.js +802 -0
- package/lib/Utils/messages.d.ts +47 -0
- package/lib/Utils/messages.js +1907 -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 +10 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/pre-key-manager.d.ts +25 -0
- package/lib/Utils/pre-key-manager.js +105 -0
- package/lib/Utils/process-message.d.ts +83 -0
- package/lib/Utils/process-message.js +748 -0
- package/lib/Utils/reporting-utils.d.ts +12 -0
- package/lib/Utils/reporting-utils.js +257 -0
- package/lib/Utils/rich-message-utils.d.ts +48 -0
- package/lib/Utils/rich-message-utils.js +366 -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/sync-action-utils.d.ts +2 -0
- package/lib/Utils/sync-action-utils.js +48 -0
- package/lib/Utils/tc-token-utils.d.ts +29 -0
- package/lib/Utils/tc-token-utils.js +163 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
- package/lib/Utils/use-multi-file-auth-state.js +116 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-single-file-auth-state.js +94 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/lib/Utils/use-sqlite-auth-state.js +109 -0
- package/lib/Utils/validate-connection.d.ts +44 -0
- package/lib/Utils/validate-connection.js +210 -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 +79 -0
- package/lib/WABinary/generic-utils.js +226 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +5 -0
- package/lib/WABinary/jid-utils.d.ts +28 -0
- package/lib/WABinary/jid-utils.js +95 -0
- package/lib/WABinary/types.d.ts +1 -0
- package/lib/WABinary/types.js +1 -0
- package/lib/WACrypto/appstate-keys.js +26 -0
- package/lib/WACrypto/curves/constants.js +12 -0
- package/lib/WACrypto/hkdf.js +27 -0
- package/lib/WACrypto/index.js +20 -0
- package/lib/WACrypto/lthash.js +54 -0
- package/lib/WACrypto/math/constants.js +24 -0
- package/lib/WACrypto/math/edwards.js +194 -0
- package/lib/WACrypto/math/fe.js +698 -0
- package/lib/WACrypto/math/le.js +23 -0
- package/lib/WACrypto/math/mod.js +15 -0
- package/lib/WACrypto/util/bytes.js +339 -0
- package/lib/WACrypto/x25519.js +145 -0
- package/lib/WACrypto/xeddsa.js +92 -0
- package/lib/WAM/BinaryInfo.d.ts +7 -0
- package/lib/WAM/BinaryInfo.js +9 -0
- package/lib/WAM/constants.d.ts +34926 -0
- package/lib/WAM/constants.js +22852 -0
- package/lib/WAM/encode.d.ts +1 -0
- package/lib/WAM/encode.js +149 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +3 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +51 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
- package/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/lib/WAUSync/Protocols/index.js +5 -0
- package/lib/WAUSync/USyncQuery.d.ts +20 -0
- package/lib/WAUSync/USyncQuery.js +97 -0
- package/lib/WAUSync/USyncUser.d.ts +16 -0
- package/lib/WAUSync/USyncUser.js +30 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +3 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +11 -0
- package/package.json +74 -5
- package/tests/addon-test.mjs +162 -0
- package/tests/differential-test.mjs +90 -0
|
@@ -0,0 +1,1252 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var messages_send_exports = {};
|
|
19
|
+
__export(messages_send_exports, {
|
|
20
|
+
makeMessagesSocket: () => makeMessagesSocket
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(messages_send_exports);
|
|
23
|
+
var import_node_crypto = require("node:crypto");
|
|
24
|
+
var import_WAProto = require("../../WAProto/index.js");
|
|
25
|
+
var import_Addon = require("../Addon/index.js");
|
|
26
|
+
var import_Defaults = require("../Defaults/index.js");
|
|
27
|
+
var import_Utils = require("../Utils/index.js");
|
|
28
|
+
var import_Types = require("../Types/index.js");
|
|
29
|
+
var import_link_preview = require("../Utils/link-preview.js");
|
|
30
|
+
var import_make_mutex = require("../Utils/make-mutex.js");
|
|
31
|
+
var import_reporting_utils = require("../Utils/reporting-utils.js");
|
|
32
|
+
var import_tc_token_utils = require("../Utils/tc-token-utils.js");
|
|
33
|
+
var import_WABinary = require("../WABinary/index.js");
|
|
34
|
+
var import_WAUSync = require("../WAUSync/index.js");
|
|
35
|
+
var import_newsletter = require("./newsletter.js");
|
|
36
|
+
const makeMessagesSocket = (config) => {
|
|
37
|
+
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: httpRequestOptions, patchMessageBeforeSending, cachedGroupMetadata, enableRecentMessageCache, maxMsgRetryCount } = config;
|
|
38
|
+
const sock = (0, import_newsletter.makeNewsletterSocket)(config);
|
|
39
|
+
const { ev, authState, messageMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral, registerSocketEndHandler } = sock;
|
|
40
|
+
const getLIDForPN = signalRepository.lidMapping.getLIDForPN.bind(signalRepository.lidMapping);
|
|
41
|
+
const inFlightTcTokenIssuance = /* @__PURE__ */ new Set();
|
|
42
|
+
const userDevicesCache = config.userDevicesCache || (0, import_Addon.createCache)({
|
|
43
|
+
ttl: import_Defaults.DEFAULT_CACHE_TTLS.USER_DEVICES
|
|
44
|
+
// 5 minutes
|
|
45
|
+
});
|
|
46
|
+
const devicesMutex = (0, import_make_mutex.makeMutex)();
|
|
47
|
+
const messageRetryManager = enableRecentMessageCache ? new import_Utils.MessageRetryManager(logger, maxMsgRetryCount) : null;
|
|
48
|
+
const encryptionMutex = (0, import_make_mutex.makeKeyedMutex)();
|
|
49
|
+
const mediaConnMutex = (0, import_make_mutex.makeKeyedMutex)();
|
|
50
|
+
let mediaConn;
|
|
51
|
+
let mediaHost = import_Utils.DEF_MEDIA_HOST;
|
|
52
|
+
const refreshMediaConn = async (forceGet = false) => {
|
|
53
|
+
return mediaConnMutex.mutex("media-conn", async () => {
|
|
54
|
+
const media = await mediaConn;
|
|
55
|
+
if (!media || forceGet || (/* @__PURE__ */ new Date()).getTime() - media.fetchDate.getTime() > media.ttl * 1e3) {
|
|
56
|
+
mediaConn = (async () => {
|
|
57
|
+
const result = await query({
|
|
58
|
+
tag: "iq",
|
|
59
|
+
attrs: {
|
|
60
|
+
type: "set",
|
|
61
|
+
xmlns: "w:m",
|
|
62
|
+
to: import_WABinary.S_WHATSAPP_NET
|
|
63
|
+
},
|
|
64
|
+
content: [{ tag: "media_conn", attrs: {} }]
|
|
65
|
+
});
|
|
66
|
+
const mediaConnNode = (0, import_WABinary.getBinaryNodeChild)(result, "media_conn");
|
|
67
|
+
const node = {
|
|
68
|
+
hosts: (0, import_WABinary.getBinaryNodeChildren)(mediaConnNode, "host").map(({ attrs }) => ({
|
|
69
|
+
hostname: attrs.hostname,
|
|
70
|
+
maxContentLengthBytes: +attrs.maxContentLengthBytes
|
|
71
|
+
})),
|
|
72
|
+
auth: mediaConnNode.attrs.auth,
|
|
73
|
+
ttl: +mediaConnNode.attrs.ttl,
|
|
74
|
+
fetchDate: /* @__PURE__ */ new Date()
|
|
75
|
+
};
|
|
76
|
+
logger.debug("fetched media conn");
|
|
77
|
+
if (node.hosts[0]) {
|
|
78
|
+
mediaHost = node.hosts[0].hostname;
|
|
79
|
+
}
|
|
80
|
+
return node;
|
|
81
|
+
})();
|
|
82
|
+
}
|
|
83
|
+
return mediaConn;
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
const sendReceipt = async (jid, participant, messageIds, type) => {
|
|
87
|
+
if (!messageIds || messageIds.length === 0) {
|
|
88
|
+
throw new import_Addon.HttpError("missing ids in receipt");
|
|
89
|
+
}
|
|
90
|
+
const node = {
|
|
91
|
+
tag: "receipt",
|
|
92
|
+
attrs: {
|
|
93
|
+
id: messageIds[0]
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const isReadReceipt = type === "read" || type === "read-self";
|
|
97
|
+
if (isReadReceipt) {
|
|
98
|
+
node.attrs.t = (0, import_Utils.unixTimestampSeconds)().toString();
|
|
99
|
+
}
|
|
100
|
+
if (type === "sender" && ((0, import_WABinary.isPnUser)(jid) || (0, import_WABinary.isLidUser)(jid))) {
|
|
101
|
+
node.attrs.recipient = jid;
|
|
102
|
+
node.attrs.to = participant;
|
|
103
|
+
} else {
|
|
104
|
+
node.attrs.to = jid;
|
|
105
|
+
if (participant) {
|
|
106
|
+
node.attrs.participant = participant;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (type) {
|
|
110
|
+
node.attrs.type = type;
|
|
111
|
+
}
|
|
112
|
+
const remainingMessageIds = messageIds.slice(1);
|
|
113
|
+
if (remainingMessageIds.length) {
|
|
114
|
+
node.content = [
|
|
115
|
+
{
|
|
116
|
+
tag: "list",
|
|
117
|
+
attrs: {},
|
|
118
|
+
content: remainingMessageIds.map((id) => ({
|
|
119
|
+
tag: "item",
|
|
120
|
+
attrs: { id }
|
|
121
|
+
}))
|
|
122
|
+
}
|
|
123
|
+
];
|
|
124
|
+
}
|
|
125
|
+
logger.debug({ attrs: node.attrs, messageIds }, "sending receipt for messages");
|
|
126
|
+
await sendNode(node);
|
|
127
|
+
};
|
|
128
|
+
const sendReceipts = async (keys, type) => {
|
|
129
|
+
const recps = (0, import_Utils.aggregateMessageKeysNotFromMe)(keys);
|
|
130
|
+
for (const { jid, participant, messageIds } of recps) {
|
|
131
|
+
await sendReceipt(jid, participant, messageIds, type);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
const readMessages = async (keys) => {
|
|
135
|
+
const privacySettings = await fetchPrivacySettings();
|
|
136
|
+
const readType = privacySettings.readreceipts === "all" ? "read" : "read-self";
|
|
137
|
+
await sendReceipts(keys, readType);
|
|
138
|
+
};
|
|
139
|
+
const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
|
|
140
|
+
const deviceResults = [];
|
|
141
|
+
if (!useCache) {
|
|
142
|
+
logger.debug("not using cache for devices");
|
|
143
|
+
}
|
|
144
|
+
const toFetch = [];
|
|
145
|
+
const jidsWithUser = jids.map((jid) => {
|
|
146
|
+
const decoded = (0, import_WABinary.jidDecode)(jid);
|
|
147
|
+
const user = decoded?.user;
|
|
148
|
+
const device = decoded?.device;
|
|
149
|
+
const isExplicitDevice = typeof device === "number" && device >= 0;
|
|
150
|
+
if (isExplicitDevice && user) {
|
|
151
|
+
deviceResults.push({
|
|
152
|
+
user,
|
|
153
|
+
device,
|
|
154
|
+
jid
|
|
155
|
+
});
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
jid = (0, import_WABinary.jidNormalizedUser)(jid);
|
|
159
|
+
return { jid, user };
|
|
160
|
+
}).filter((jid) => jid !== null);
|
|
161
|
+
let mgetDevices;
|
|
162
|
+
if (useCache && userDevicesCache.mget) {
|
|
163
|
+
const usersToFetch = jidsWithUser.map((j) => j?.user).filter(Boolean);
|
|
164
|
+
mgetDevices = await userDevicesCache.mget(usersToFetch);
|
|
165
|
+
}
|
|
166
|
+
for (const { jid, user } of jidsWithUser) {
|
|
167
|
+
if (useCache) {
|
|
168
|
+
const devices = mgetDevices?.[user] || (userDevicesCache.mget ? void 0 : await userDevicesCache.get(user));
|
|
169
|
+
if (devices) {
|
|
170
|
+
const devicesWithJid = devices.map((d) => ({
|
|
171
|
+
...d,
|
|
172
|
+
jid: (0, import_WABinary.jidEncode)(d.user, d.server, d.device)
|
|
173
|
+
}));
|
|
174
|
+
deviceResults.push(...devicesWithJid);
|
|
175
|
+
logger.trace({ user }, "using cache for devices");
|
|
176
|
+
} else {
|
|
177
|
+
toFetch.push(jid);
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
toFetch.push(jid);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (!toFetch.length) {
|
|
184
|
+
return deviceResults;
|
|
185
|
+
}
|
|
186
|
+
const requestedLidUsers = /* @__PURE__ */ new Set();
|
|
187
|
+
for (const jid of toFetch) {
|
|
188
|
+
if ((0, import_WABinary.isLidUser)(jid) || (0, import_WABinary.isHostedLidUser)(jid)) {
|
|
189
|
+
const user = (0, import_WABinary.jidDecode)(jid)?.user;
|
|
190
|
+
if (user)
|
|
191
|
+
requestedLidUsers.add(user);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
const query2 = new import_WAUSync.USyncQuery().withContext("message").withDeviceProtocol().withLIDProtocol();
|
|
195
|
+
for (const jid of toFetch) {
|
|
196
|
+
query2.withUser(new import_WAUSync.USyncUser().withId(jid));
|
|
197
|
+
}
|
|
198
|
+
const result = await sock.executeUSyncQuery(query2);
|
|
199
|
+
if (result) {
|
|
200
|
+
const lidResults = result.list.filter((a) => !!a.lid);
|
|
201
|
+
if (lidResults.length > 0) {
|
|
202
|
+
logger.trace("Storing LID maps from device call");
|
|
203
|
+
await signalRepository.lidMapping.storeLIDPNMappings(lidResults.map((a) => ({ lid: a.lid, pn: a.id })));
|
|
204
|
+
try {
|
|
205
|
+
const lids = lidResults.map((a) => a.lid);
|
|
206
|
+
if (lids.length) {
|
|
207
|
+
await assertSessions(lids, true);
|
|
208
|
+
}
|
|
209
|
+
} catch (e) {
|
|
210
|
+
logger.warn({ e, count: lidResults.length }, "failed to assert sessions for newly mapped LIDs");
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
const extracted = (0, import_Utils.extractDeviceJids)(result?.list, authState.creds.me.id, authState.creds.me.lid, ignoreZeroDevices);
|
|
214
|
+
const deviceMap = {};
|
|
215
|
+
for (const item of extracted) {
|
|
216
|
+
deviceMap[item.user] = deviceMap[item.user] || [];
|
|
217
|
+
deviceMap[item.user]?.push(item);
|
|
218
|
+
}
|
|
219
|
+
for (const [user, userDevices] of Object.entries(deviceMap)) {
|
|
220
|
+
const isLidUser2 = requestedLidUsers.has(user);
|
|
221
|
+
for (const item of userDevices) {
|
|
222
|
+
const finalJid = isLidUser2 ? (0, import_WABinary.jidEncode)(user, item.server, item.device) : (0, import_WABinary.jidEncode)(item.user, item.server, item.device);
|
|
223
|
+
deviceResults.push({
|
|
224
|
+
...item,
|
|
225
|
+
jid: finalJid
|
|
226
|
+
});
|
|
227
|
+
logger.debug({
|
|
228
|
+
user: item.user,
|
|
229
|
+
device: item.device,
|
|
230
|
+
finalJid,
|
|
231
|
+
usedLid: isLidUser2
|
|
232
|
+
}, "Processed device with LID priority");
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
await devicesMutex.mutex(async () => {
|
|
236
|
+
if (userDevicesCache.mset) {
|
|
237
|
+
await userDevicesCache.mset(Object.entries(deviceMap).map(([key, value]) => ({ key, value })));
|
|
238
|
+
} else {
|
|
239
|
+
for (const key in deviceMap) {
|
|
240
|
+
if (deviceMap[key])
|
|
241
|
+
await userDevicesCache.set(key, deviceMap[key]);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
const userDeviceUpdates = {};
|
|
246
|
+
for (const [userId, devices] of Object.entries(deviceMap)) {
|
|
247
|
+
if (devices && devices.length > 0) {
|
|
248
|
+
userDeviceUpdates[userId] = devices.map((d) => d.device?.toString() || "0");
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (Object.keys(userDeviceUpdates).length > 0) {
|
|
252
|
+
try {
|
|
253
|
+
await authState.keys.set({ "device-list": userDeviceUpdates });
|
|
254
|
+
logger.debug({ userCount: Object.keys(userDeviceUpdates).length }, "stored user device lists for bulk migration");
|
|
255
|
+
} catch (error) {
|
|
256
|
+
logger.warn({ error }, "failed to store user device lists");
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return deviceResults;
|
|
261
|
+
};
|
|
262
|
+
const updateMemberLabel = (jid, memberLabel) => {
|
|
263
|
+
return relayMessage(jid, {
|
|
264
|
+
protocolMessage: {
|
|
265
|
+
type: import_WAProto.proto.Message.ProtocolMessage.Type.GROUP_MEMBER_LABEL_CHANGE,
|
|
266
|
+
memberLabel: {
|
|
267
|
+
label: memberLabel?.slice(0, 30),
|
|
268
|
+
labelTimestamp: import_Utils.unixTimestampSeconds
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}, {
|
|
272
|
+
additionalNodes: [
|
|
273
|
+
{
|
|
274
|
+
tag: "meta",
|
|
275
|
+
attrs: {
|
|
276
|
+
tag_reason: "user_update",
|
|
277
|
+
appdata: "member_tag"
|
|
278
|
+
},
|
|
279
|
+
content: void 0
|
|
280
|
+
}
|
|
281
|
+
]
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
const assertSessions = async (jids, force) => {
|
|
285
|
+
let didFetchNewSession = false;
|
|
286
|
+
const uniqueJids = [...new Set(jids)];
|
|
287
|
+
const jidsRequiringFetch = [];
|
|
288
|
+
logger.debug({ jids }, "assertSessions call with jids");
|
|
289
|
+
for (const jid of uniqueJids) {
|
|
290
|
+
if (!force) {
|
|
291
|
+
const sessionValidation = await signalRepository.validateSession(jid);
|
|
292
|
+
if (sessionValidation.exists) {
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
jidsRequiringFetch.push(jid);
|
|
297
|
+
}
|
|
298
|
+
if (jidsRequiringFetch.length) {
|
|
299
|
+
const wireJids = [
|
|
300
|
+
...jidsRequiringFetch.filter((jid) => !!(0, import_WABinary.isLidUser)(jid) || !!(0, import_WABinary.isHostedLidUser)(jid)),
|
|
301
|
+
...(await signalRepository.lidMapping.getLIDsForPNs(jidsRequiringFetch.filter((jid) => !!(0, import_WABinary.isPnUser)(jid) || !!(0, import_WABinary.isHostedPnUser)(jid))) || []).map((a) => a.lid)
|
|
302
|
+
];
|
|
303
|
+
logger.debug({ jidsRequiringFetch, wireJids }, "fetching sessions");
|
|
304
|
+
const result = await query({
|
|
305
|
+
tag: "iq",
|
|
306
|
+
attrs: {
|
|
307
|
+
xmlns: "encrypt",
|
|
308
|
+
type: "get",
|
|
309
|
+
to: import_WABinary.S_WHATSAPP_NET
|
|
310
|
+
},
|
|
311
|
+
content: [
|
|
312
|
+
{
|
|
313
|
+
tag: "key",
|
|
314
|
+
attrs: {},
|
|
315
|
+
content: wireJids.map((jid) => {
|
|
316
|
+
const attrs = { jid };
|
|
317
|
+
if (force)
|
|
318
|
+
attrs.reason = "identity";
|
|
319
|
+
return { tag: "user", attrs };
|
|
320
|
+
})
|
|
321
|
+
}
|
|
322
|
+
]
|
|
323
|
+
});
|
|
324
|
+
await (0, import_Utils.parseAndInjectE2ESessions)(result, signalRepository);
|
|
325
|
+
didFetchNewSession = true;
|
|
326
|
+
}
|
|
327
|
+
return didFetchNewSession;
|
|
328
|
+
};
|
|
329
|
+
const sendPeerDataOperationMessage = async (pdoMessage) => {
|
|
330
|
+
if (!authState.creds.me?.id) {
|
|
331
|
+
throw new import_Addon.HttpError("Not authenticated");
|
|
332
|
+
}
|
|
333
|
+
const protocolMessage = {
|
|
334
|
+
protocolMessage: {
|
|
335
|
+
peerDataOperationRequestMessage: pdoMessage,
|
|
336
|
+
type: import_WAProto.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
const meJid = (0, import_WABinary.jidNormalizedUser)(authState.creds.me.id);
|
|
340
|
+
const msgId = await relayMessage(meJid, protocolMessage, {
|
|
341
|
+
additionalAttributes: {
|
|
342
|
+
category: "peer",
|
|
343
|
+
push_priority: "high_force"
|
|
344
|
+
},
|
|
345
|
+
additionalNodes: [
|
|
346
|
+
{
|
|
347
|
+
tag: "meta",
|
|
348
|
+
attrs: { appdata: "default" }
|
|
349
|
+
}
|
|
350
|
+
]
|
|
351
|
+
});
|
|
352
|
+
return msgId;
|
|
353
|
+
};
|
|
354
|
+
const createParticipantNodes = async (recipientJids, message, extraAttrs, dsmMessage) => {
|
|
355
|
+
if (!recipientJids.length) {
|
|
356
|
+
return { nodes: [], shouldIncludeDeviceIdentity: false };
|
|
357
|
+
}
|
|
358
|
+
const patched = await patchMessageBeforeSending(message, recipientJids);
|
|
359
|
+
const patchedMessages = Array.isArray(patched) ? patched : recipientJids.map((jid) => ({ recipientJid: jid, message: patched }));
|
|
360
|
+
let shouldIncludeDeviceIdentity = false;
|
|
361
|
+
const meId = authState.creds.me.id;
|
|
362
|
+
const meLid = authState.creds.me?.lid;
|
|
363
|
+
const meLidUser = meLid ? (0, import_WABinary.jidDecode)(meLid)?.user : null;
|
|
364
|
+
const encryptionPromises = patchedMessages.map(async ({ recipientJid: jid, message: patchedMessage }) => {
|
|
365
|
+
try {
|
|
366
|
+
if (!jid)
|
|
367
|
+
return null;
|
|
368
|
+
let msgToEncrypt = patchedMessage;
|
|
369
|
+
if (dsmMessage) {
|
|
370
|
+
const { user: targetUser } = (0, import_WABinary.jidDecode)(jid);
|
|
371
|
+
const { user: ownPnUser } = (0, import_WABinary.jidDecode)(meId);
|
|
372
|
+
const ownLidUser = meLidUser;
|
|
373
|
+
const isOwnUser = targetUser === ownPnUser || ownLidUser && targetUser === ownLidUser;
|
|
374
|
+
const isExactSenderDevice = jid === meId || meLid && jid === meLid;
|
|
375
|
+
if (isOwnUser && !isExactSenderDevice) {
|
|
376
|
+
msgToEncrypt = dsmMessage;
|
|
377
|
+
logger.debug({ jid, targetUser }, "Using DSM for own device");
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
const bytes = (0, import_Utils.encodeWAMessage)(msgToEncrypt);
|
|
381
|
+
const mutexKey = jid;
|
|
382
|
+
const node = await encryptionMutex.mutex(mutexKey, async () => {
|
|
383
|
+
const { type, ciphertext } = await signalRepository.encryptMessage({ jid, data: bytes });
|
|
384
|
+
if (type === "pkmsg") {
|
|
385
|
+
shouldIncludeDeviceIdentity = true;
|
|
386
|
+
}
|
|
387
|
+
return {
|
|
388
|
+
tag: "to",
|
|
389
|
+
attrs: { jid },
|
|
390
|
+
content: [
|
|
391
|
+
{
|
|
392
|
+
tag: "enc",
|
|
393
|
+
attrs: { v: "2", type, ...extraAttrs || {} },
|
|
394
|
+
content: ciphertext
|
|
395
|
+
}
|
|
396
|
+
]
|
|
397
|
+
};
|
|
398
|
+
});
|
|
399
|
+
return node;
|
|
400
|
+
} catch (err) {
|
|
401
|
+
logger.error({ jid, err }, "Failed to encrypt for recipient");
|
|
402
|
+
return null;
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
const nodes = (await Promise.all(encryptionPromises)).filter((node) => node !== null);
|
|
406
|
+
if (recipientJids.length > 0 && nodes.length === 0) {
|
|
407
|
+
throw new import_Addon.HttpError("All encryptions failed", { statusCode: 500 });
|
|
408
|
+
}
|
|
409
|
+
return { nodes, shouldIncludeDeviceIdentity };
|
|
410
|
+
};
|
|
411
|
+
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, addBizAttributes, statusJidList } = {}) => {
|
|
412
|
+
const meId = (0, import_Utils.assertMeId)(authState.creds);
|
|
413
|
+
const meLid = authState.creds.me?.lid;
|
|
414
|
+
const isRetryResend = Boolean(participant?.jid);
|
|
415
|
+
let shouldIncludeDeviceIdentity = isRetryResend;
|
|
416
|
+
const statusJid = "status@broadcast";
|
|
417
|
+
const { user, server } = (0, import_WABinary.jidDecode)(jid);
|
|
418
|
+
const isGroup = server === "g.us";
|
|
419
|
+
const isStatus = jid === statusJid;
|
|
420
|
+
const isLid = server === "lid";
|
|
421
|
+
const isNewsletter = server === "newsletter";
|
|
422
|
+
const isGroupOrStatus = isGroup || isStatus;
|
|
423
|
+
const finalJid = jid;
|
|
424
|
+
msgId = msgId || (0, import_Utils.generateMessageIDV2)(meId);
|
|
425
|
+
useUserDevicesCache = useUserDevicesCache !== false;
|
|
426
|
+
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
|
|
427
|
+
const participants = [];
|
|
428
|
+
const destinationJid = !isStatus ? finalJid : statusJid;
|
|
429
|
+
const binaryNodeContent = [];
|
|
430
|
+
const devices = [];
|
|
431
|
+
let reportingMessage;
|
|
432
|
+
const meMsg = {
|
|
433
|
+
deviceSentMessage: {
|
|
434
|
+
destinationJid,
|
|
435
|
+
message
|
|
436
|
+
},
|
|
437
|
+
messageContextInfo: message.messageContextInfo
|
|
438
|
+
};
|
|
439
|
+
const extraAttrs = {};
|
|
440
|
+
if (participant) {
|
|
441
|
+
if (participant && !isGroup && !isStatus) {
|
|
442
|
+
additionalAttributes = { ...additionalAttributes, device_fanout: "false" };
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
await authState.keys.transaction(async () => {
|
|
446
|
+
const innerMessage = (0, import_Utils.normalizeMessageContent)(message);
|
|
447
|
+
const mediaType = getMediaType(innerMessage);
|
|
448
|
+
if (mediaType) {
|
|
449
|
+
extraAttrs["mediatype"] = mediaType;
|
|
450
|
+
}
|
|
451
|
+
if (isNewsletter) {
|
|
452
|
+
const patched = patchMessageBeforeSending ? await patchMessageBeforeSending(message, []) : message;
|
|
453
|
+
const bytes = (0, import_Utils.encodeNewsletterMessage)(patched);
|
|
454
|
+
if (additionalNodes && additionalNodes.length > 0) {
|
|
455
|
+
;
|
|
456
|
+
binaryNodeContent.push(...additionalNodes);
|
|
457
|
+
}
|
|
458
|
+
binaryNodeContent.push({
|
|
459
|
+
tag: "plaintext",
|
|
460
|
+
attrs: extraAttrs,
|
|
461
|
+
// Add extraAttrs to fix media being rejected when sending to newsletter (◠‿◕)
|
|
462
|
+
content: bytes
|
|
463
|
+
});
|
|
464
|
+
const stanza2 = {
|
|
465
|
+
tag: "message",
|
|
466
|
+
attrs: {
|
|
467
|
+
to: jid,
|
|
468
|
+
id: msgId,
|
|
469
|
+
type: getMessageType(innerMessage),
|
|
470
|
+
...additionalAttributes || {}
|
|
471
|
+
},
|
|
472
|
+
content: binaryNodeContent
|
|
473
|
+
};
|
|
474
|
+
logger.debug({ msgId }, `sending newsletter message to ${jid}`);
|
|
475
|
+
await sendNode(stanza2);
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
const isNeedMetaAttrs = innerMessage?.pinInChatMessage || innerMessage?.keepInChatMessage || innerMessage?.reactionMessage;
|
|
479
|
+
const isGroupStatus = message?.groupStatusMessage || message?.groupStatusMessageV2;
|
|
480
|
+
const isPollUpdate = innerMessage?.pollUpdateMessage;
|
|
481
|
+
const isViewOnce = (0, import_Utils.isViewOnceMessage)(message);
|
|
482
|
+
if (isNeedMetaAttrs || isGroupStatus || isPollUpdate || isViewOnce) {
|
|
483
|
+
const metaAttrs = {};
|
|
484
|
+
if (isNeedMetaAttrs) {
|
|
485
|
+
metaAttrs.content_type = "add_on";
|
|
486
|
+
}
|
|
487
|
+
if (isPollUpdate && !isGroupStatus) {
|
|
488
|
+
metaAttrs.polltype = "vote";
|
|
489
|
+
}
|
|
490
|
+
if (isGroupStatus) {
|
|
491
|
+
metaAttrs.is_group_status = "true";
|
|
492
|
+
}
|
|
493
|
+
if (isViewOnce) {
|
|
494
|
+
metaAttrs.view_once = "true";
|
|
495
|
+
}
|
|
496
|
+
binaryNodeContent.push({
|
|
497
|
+
tag: "meta",
|
|
498
|
+
attrs: metaAttrs,
|
|
499
|
+
content: void 0
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
if (isNeedMetaAttrs || innerMessage?.protocolMessage?.memberLabel || innerMessage?.protocolMessage?.editedMessage || innerMessage?.protocolMessage?.mediaNotifyMessage) {
|
|
503
|
+
extraAttrs["decrypt-fail"] = "hide";
|
|
504
|
+
}
|
|
505
|
+
if (innerMessage?.interactiveResponseMessage?.nativeFlowResponseMessage) {
|
|
506
|
+
extraAttrs["native_flow_name"] = innerMessage.interactiveResponseMessage.nativeFlowResponseMessage.name;
|
|
507
|
+
}
|
|
508
|
+
if (isGroupOrStatus && !isRetryResend) {
|
|
509
|
+
const [groupData, senderKeyMap] = await Promise.all([
|
|
510
|
+
(async () => {
|
|
511
|
+
let groupData2 = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : void 0;
|
|
512
|
+
if (groupData2 && Array.isArray(groupData2?.participants)) {
|
|
513
|
+
logger.trace({ jid, participants: groupData2.participants.length }, "using cached group metadata");
|
|
514
|
+
} else if (!isStatus) {
|
|
515
|
+
groupData2 = await groupMetadata(jid);
|
|
516
|
+
}
|
|
517
|
+
return groupData2;
|
|
518
|
+
})(),
|
|
519
|
+
(async () => {
|
|
520
|
+
if (!participant && !isStatus) {
|
|
521
|
+
const result = await authState.keys.get("sender-key-memory", [jid]);
|
|
522
|
+
return result[jid] || {};
|
|
523
|
+
}
|
|
524
|
+
return {};
|
|
525
|
+
})
|
|
526
|
+
]);
|
|
527
|
+
const participantsList = groupData ? groupData.participants.map((p) => p.id) : [];
|
|
528
|
+
if (groupData?.ephemeralDuration && groupData.ephemeralDuration > 0) {
|
|
529
|
+
additionalAttributes = {
|
|
530
|
+
...additionalAttributes,
|
|
531
|
+
expiration: groupData.ephemeralDuration.toString
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
if (isStatus && statusJidList) {
|
|
535
|
+
participantsList.push(...statusJidList);
|
|
536
|
+
}
|
|
537
|
+
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
|
|
538
|
+
devices.push(...additionalDevices);
|
|
539
|
+
if (isGroup) {
|
|
540
|
+
additionalAttributes = {
|
|
541
|
+
...additionalAttributes,
|
|
542
|
+
addressing_mode: groupData?.addressingMode || "lid"
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
const patched = await patchMessageBeforeSending(message);
|
|
546
|
+
if (Array.isArray(patched)) {
|
|
547
|
+
throw new import_Addon.HttpError("Per-jid patching is not supported in groups");
|
|
548
|
+
}
|
|
549
|
+
const bytes = (0, import_Utils.encodeWAMessage)(patched);
|
|
550
|
+
reportingMessage = patched;
|
|
551
|
+
const groupAddressingMode = additionalAttributes?.["addressing_mode"] || groupData?.addressingMode || "lid";
|
|
552
|
+
const groupSenderIdentity = groupAddressingMode === "lid" && meLid ? meLid : meId;
|
|
553
|
+
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
|
|
554
|
+
group: destinationJid,
|
|
555
|
+
data: bytes,
|
|
556
|
+
meId: groupSenderIdentity
|
|
557
|
+
});
|
|
558
|
+
const senderKeyRecipients = [];
|
|
559
|
+
for (const device of devices) {
|
|
560
|
+
const deviceJid = device.jid;
|
|
561
|
+
const hasKey = !!senderKeyMap[deviceJid];
|
|
562
|
+
if ((!hasKey || !!participant) && !(0, import_WABinary.isHostedLidUser)(deviceJid) && !(0, import_WABinary.isHostedPnUser)(deviceJid) && device.device !== 99) {
|
|
563
|
+
senderKeyRecipients.push(deviceJid);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
if (senderKeyRecipients.length) {
|
|
567
|
+
logger.debug({ senderKeyJids: senderKeyRecipients }, "sending new sender key");
|
|
568
|
+
const senderKeyMsg = {
|
|
569
|
+
senderKeyDistributionMessage: {
|
|
570
|
+
axolotlSenderKeyDistributionMessage: senderKeyDistributionMessage,
|
|
571
|
+
groupId: destinationJid
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
const senderKeySessionTargets = senderKeyRecipients;
|
|
575
|
+
await assertSessions(senderKeySessionTargets);
|
|
576
|
+
const result = await createParticipantNodes(senderKeyRecipients, senderKeyMsg, extraAttrs);
|
|
577
|
+
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
|
|
578
|
+
participants.push(...result.nodes);
|
|
579
|
+
for (const { attrs } of result.nodes) {
|
|
580
|
+
if (attrs.jid) {
|
|
581
|
+
senderKeyMap[attrs.jid] = true;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
binaryNodeContent.push({
|
|
586
|
+
tag: "enc",
|
|
587
|
+
attrs: { v: "2", type: "skmsg", ...extraAttrs },
|
|
588
|
+
content: ciphertext
|
|
589
|
+
});
|
|
590
|
+
await authState.keys.set({ "sender-key-memory": { [jid]: senderKeyMap } });
|
|
591
|
+
} else {
|
|
592
|
+
let ownId = meId;
|
|
593
|
+
if (isLid && meLid) {
|
|
594
|
+
ownId = meLid;
|
|
595
|
+
logger.debug({ to: jid, ownId }, "Using LID identity for @lid conversation");
|
|
596
|
+
} else {
|
|
597
|
+
logger.debug({ to: jid, ownId }, "Using PN identity for @s.whatsapp.net conversation");
|
|
598
|
+
}
|
|
599
|
+
const { user: ownUser } = (0, import_WABinary.jidDecode)(ownId);
|
|
600
|
+
if (!participant) {
|
|
601
|
+
const patchedForReporting = await patchMessageBeforeSending(message, [jid]);
|
|
602
|
+
reportingMessage = Array.isArray(patchedForReporting) ? patchedForReporting.find((item) => item.recipientJid === jid) || patchedForReporting[0] : patchedForReporting;
|
|
603
|
+
}
|
|
604
|
+
if (!isRetryResend) {
|
|
605
|
+
const targetUserServer = isLid ? "lid" : "s.whatsapp.net";
|
|
606
|
+
devices.push({
|
|
607
|
+
user,
|
|
608
|
+
device: 0,
|
|
609
|
+
jid: (0, import_WABinary.jidEncode)(user, targetUserServer, 0)
|
|
610
|
+
// rajeh, todo: this entire logic is convoluted and weird.
|
|
611
|
+
});
|
|
612
|
+
if (user !== ownUser) {
|
|
613
|
+
const ownUserServer = isLid ? "lid" : "s.whatsapp.net";
|
|
614
|
+
const ownUserForAddressing = isLid && meLid ? (0, import_WABinary.jidDecode)(meLid).user : (0, import_WABinary.jidDecode)(meId).user;
|
|
615
|
+
devices.push({
|
|
616
|
+
user: ownUserForAddressing,
|
|
617
|
+
device: 0,
|
|
618
|
+
jid: (0, import_WABinary.jidEncode)(ownUserForAddressing, ownUserServer, 0)
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
if (additionalAttributes?.["category"] !== "peer") {
|
|
622
|
+
devices.length = 0;
|
|
623
|
+
const senderIdentity = isLid && meLid ? (0, import_WABinary.jidEncode)((0, import_WABinary.jidDecode)(meLid)?.user, "lid", void 0) : (0, import_WABinary.jidEncode)((0, import_WABinary.jidDecode)(meId)?.user, "s.whatsapp.net", void 0);
|
|
624
|
+
const sessionDevices = await getUSyncDevices([senderIdentity, jid], true, false);
|
|
625
|
+
devices.push(...sessionDevices);
|
|
626
|
+
logger.debug({
|
|
627
|
+
deviceCount: devices.length,
|
|
628
|
+
devices: devices.map((d) => `${d.user}:${d.device}@${(0, import_WABinary.jidDecode)(d.jid)?.server}`)
|
|
629
|
+
}, "Device enumeration complete with unified addressing");
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
const allRecipients = [];
|
|
633
|
+
const meRecipients = [];
|
|
634
|
+
const otherRecipients = [];
|
|
635
|
+
const { user: mePnUser } = (0, import_WABinary.jidDecode)(meId);
|
|
636
|
+
const { user: meLidUser } = meLid ? (0, import_WABinary.jidDecode)(meLid) : { user: null };
|
|
637
|
+
for (const { user: user2, jid: jid2 } of devices) {
|
|
638
|
+
const isExactSenderDevice = jid2 === meId || meLid && jid2 === meLid;
|
|
639
|
+
if (isExactSenderDevice) {
|
|
640
|
+
logger.debug({ jid: jid2, meId, meLid }, "Skipping exact sender device (whatsmeow pattern)");
|
|
641
|
+
continue;
|
|
642
|
+
}
|
|
643
|
+
const isMe = user2 === mePnUser || user2 === meLidUser;
|
|
644
|
+
if (isMe) {
|
|
645
|
+
meRecipients.push(jid2);
|
|
646
|
+
} else {
|
|
647
|
+
otherRecipients.push(jid2);
|
|
648
|
+
}
|
|
649
|
+
allRecipients.push(jid2);
|
|
650
|
+
}
|
|
651
|
+
await assertSessions(allRecipients);
|
|
652
|
+
const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
|
|
653
|
+
// For own devices: use DSM if available (1:1 chats only)
|
|
654
|
+
createParticipantNodes(meRecipients, meMsg || message, extraAttrs),
|
|
655
|
+
createParticipantNodes(otherRecipients, message, extraAttrs, meMsg)
|
|
656
|
+
]);
|
|
657
|
+
participants.push(...meNodes);
|
|
658
|
+
participants.push(...otherNodes);
|
|
659
|
+
if (meRecipients.length > 0 || otherRecipients.length > 0) {
|
|
660
|
+
extraAttrs["phash"] = (0, import_Utils.generateParticipantHashV2)([...meRecipients, ...otherRecipients]);
|
|
661
|
+
}
|
|
662
|
+
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
|
|
663
|
+
}
|
|
664
|
+
if (isRetryResend) {
|
|
665
|
+
const isParticipantLid = (0, import_WABinary.isLidUser)(participant.jid);
|
|
666
|
+
const isMe = (0, import_WABinary.areJidsSameUser)(participant.jid, isParticipantLid ? meLid : meId);
|
|
667
|
+
let messageToSend = message;
|
|
668
|
+
if (isGroupOrStatus) {
|
|
669
|
+
let groupSenderIdentity;
|
|
670
|
+
if (meLid && await signalRepository.hasSenderKey({ group: destinationJid, meId: meLid })) {
|
|
671
|
+
groupSenderIdentity = meLid;
|
|
672
|
+
} else if (await signalRepository.hasSenderKey({ group: destinationJid, meId })) {
|
|
673
|
+
groupSenderIdentity = meId;
|
|
674
|
+
}
|
|
675
|
+
if (groupSenderIdentity) {
|
|
676
|
+
try {
|
|
677
|
+
const skdm = await signalRepository.getSenderKeyDistributionMessage({
|
|
678
|
+
group: destinationJid,
|
|
679
|
+
meId: groupSenderIdentity
|
|
680
|
+
});
|
|
681
|
+
messageToSend = {
|
|
682
|
+
...message,
|
|
683
|
+
senderKeyDistributionMessage: {
|
|
684
|
+
groupId: destinationJid,
|
|
685
|
+
axolotlSenderKeyDistributionMessage: skdm
|
|
686
|
+
}
|
|
687
|
+
};
|
|
688
|
+
} catch (err) {
|
|
689
|
+
logger.warn({ err, jid: destinationJid }, "failed to build SKDM for retry, sending without it");
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
const encodedMessageToSend = isMe ? (0, import_Utils.encodeWAMessage)({
|
|
694
|
+
deviceSentMessage: {
|
|
695
|
+
destinationJid,
|
|
696
|
+
message: messageToSend
|
|
697
|
+
}
|
|
698
|
+
}) : (0, import_Utils.encodeWAMessage)(messageToSend);
|
|
699
|
+
await assertSessions([participant.jid]);
|
|
700
|
+
const { type, ciphertext: encryptedContent } = await signalRepository.encryptMessage({
|
|
701
|
+
data: encodedMessageToSend,
|
|
702
|
+
jid: participant.jid
|
|
703
|
+
});
|
|
704
|
+
binaryNodeContent.push({
|
|
705
|
+
tag: "enc",
|
|
706
|
+
attrs: {
|
|
707
|
+
v: "2",
|
|
708
|
+
type,
|
|
709
|
+
count: (participant.count || 0).toString
|
|
710
|
+
},
|
|
711
|
+
content: encryptedContent
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
if (participants.length) {
|
|
715
|
+
if (additionalAttributes?.["category"] === "peer") {
|
|
716
|
+
const peerNode = participants[0]?.content?.[0];
|
|
717
|
+
if (peerNode) {
|
|
718
|
+
binaryNodeContent.push(peerNode);
|
|
719
|
+
}
|
|
720
|
+
} else {
|
|
721
|
+
binaryNodeContent.push({
|
|
722
|
+
tag: "participants",
|
|
723
|
+
attrs: {},
|
|
724
|
+
content: participants
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
const stanza = {
|
|
729
|
+
tag: "message",
|
|
730
|
+
attrs: {
|
|
731
|
+
id: msgId,
|
|
732
|
+
to: destinationJid,
|
|
733
|
+
type: getMessageType(innerMessage),
|
|
734
|
+
...additionalAttributes || {}
|
|
735
|
+
},
|
|
736
|
+
content: binaryNodeContent
|
|
737
|
+
};
|
|
738
|
+
if (participant) {
|
|
739
|
+
if ((0, import_WABinary.isJidGroup)(destinationJid)) {
|
|
740
|
+
stanza.attrs.to = destinationJid;
|
|
741
|
+
stanza.attrs.participant = participant.jid;
|
|
742
|
+
} else if ((0, import_WABinary.areJidsSameUser)(participant.jid, meId)) {
|
|
743
|
+
stanza.attrs.to = participant.jid;
|
|
744
|
+
stanza.attrs.recipient = destinationJid;
|
|
745
|
+
} else {
|
|
746
|
+
stanza.attrs.to = participant.jid;
|
|
747
|
+
}
|
|
748
|
+
} else {
|
|
749
|
+
stanza.attrs.to = destinationJid;
|
|
750
|
+
}
|
|
751
|
+
if (shouldIncludeDeviceIdentity) {
|
|
752
|
+
;
|
|
753
|
+
stanza.content.push({
|
|
754
|
+
tag: "device-identity",
|
|
755
|
+
attrs: {},
|
|
756
|
+
content: (0, import_Utils.encodeSignedDeviceIdentity)(authState.creds.account, true)
|
|
757
|
+
});
|
|
758
|
+
logger.debug({ jid }, "adding device identity");
|
|
759
|
+
}
|
|
760
|
+
if (!isNewsletter && !isRetryResend && reportingMessage?.messageContextInfo?.messageSecret && (0, import_reporting_utils.shouldIncludeReportingToken)(reportingMessage)) {
|
|
761
|
+
try {
|
|
762
|
+
const encoded = (0, import_Utils.encodeWAMessage)(reportingMessage);
|
|
763
|
+
const reportingKey = {
|
|
764
|
+
id: msgId,
|
|
765
|
+
fromMe: true,
|
|
766
|
+
remoteJid: destinationJid,
|
|
767
|
+
participant: participant?.jid
|
|
768
|
+
};
|
|
769
|
+
const reportingNode = await (0, import_reporting_utils.getMessageReportingToken)(encoded, reportingMessage, reportingKey);
|
|
770
|
+
if (reportingNode) {
|
|
771
|
+
;
|
|
772
|
+
stanza.content.push(reportingNode);
|
|
773
|
+
logger.trace({ jid }, "added reporting token to message");
|
|
774
|
+
}
|
|
775
|
+
} catch (error) {
|
|
776
|
+
logger.warn({ jid, trace: error?.stack }, "failed to attach reporting token");
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
const isPeerMessage = additionalAttributes?.["category"] === "peer";
|
|
780
|
+
const is1on1Send = !isGroup && !isRetryResend && !isStatus && !isNewsletter && !isPeerMessage;
|
|
781
|
+
const tcTokenJid = is1on1Send ? await (0, import_tc_token_utils.resolveTcTokenJid)(destinationJid, getLIDForPN) : destinationJid;
|
|
782
|
+
const contactTcTokenData = is1on1Send ? await authState.keys.get("tctoken", [tcTokenJid]) : {};
|
|
783
|
+
const existingTokenEntry = contactTcTokenData[tcTokenJid];
|
|
784
|
+
let tcTokenBuffer = existingTokenEntry?.token;
|
|
785
|
+
if (tcTokenBuffer?.length && (0, import_tc_token_utils.isTcTokenExpired)(existingTokenEntry?.timestamp)) {
|
|
786
|
+
logger.debug({ jid: destinationJid, timestamp: existingTokenEntry?.timestamp }, "tctoken expired, clearing");
|
|
787
|
+
tcTokenBuffer = void 0;
|
|
788
|
+
const cleared = existingTokenEntry?.senderTimestamp !== void 0 ? { token: Buffer.alloc(0), senderTimestamp: existingTokenEntry.senderTimestamp } : null;
|
|
789
|
+
try {
|
|
790
|
+
await authState.keys.set({ tctoken: { [tcTokenJid]: cleared } });
|
|
791
|
+
} catch (err) {
|
|
792
|
+
logger.debug({ jid: destinationJid, err: err?.message }, "failed to persist tctoken expiry cleanup");
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
if (tcTokenBuffer?.length && sock.serverProps.privacyTokenOn1to1) {
|
|
796
|
+
;
|
|
797
|
+
stanza.content.push({
|
|
798
|
+
tag: "tctoken",
|
|
799
|
+
attrs: {},
|
|
800
|
+
content: tcTokenBuffer
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
let alreadyHasBizNode = false;
|
|
804
|
+
if (additionalNodes && additionalNodes.length > 0) {
|
|
805
|
+
;
|
|
806
|
+
stanza.content.push(...additionalNodes);
|
|
807
|
+
alreadyHasBizNode = !addBizAttributes && additionalNodes.some((node) => node.tag === "biz");
|
|
808
|
+
}
|
|
809
|
+
if (!alreadyHasBizNode && (0, import_Utils.shouldIncludeBizBinaryNode)(innerMessage) || addBizAttributes) {
|
|
810
|
+
const bizNode = (0, import_WABinary.getBizBinaryNode)(innerMessage);
|
|
811
|
+
stanza.content.push(bizNode);
|
|
812
|
+
}
|
|
813
|
+
logger.debug({ msgId }, `sending message to ${participants.length} devices`);
|
|
814
|
+
await sendNode(stanza);
|
|
815
|
+
const isProtocolMsg = !!innerMessage?.protocolMessage;
|
|
816
|
+
const isBotOrPSA = destinationJid === import_WABinary.PSA_WID || (0, import_WABinary.isJidBot)(destinationJid) || (0, import_WABinary.isJidMetaAI)(destinationJid);
|
|
817
|
+
if (is1on1Send && !isProtocolMsg && !isBotOrPSA && (0, import_tc_token_utils.shouldSendNewTcToken)(existingTokenEntry?.senderTimestamp) && !inFlightTcTokenIssuance.has(tcTokenJid)) {
|
|
818
|
+
inFlightTcTokenIssuance.add(tcTokenJid);
|
|
819
|
+
const issueTimestamp = (0, import_Utils.unixTimestampSeconds)();
|
|
820
|
+
const getPNForLID = signalRepository.lidMapping.getPNForLID.bind(signalRepository.lidMapping);
|
|
821
|
+
(0, import_tc_token_utils.resolveIssuanceJid)(destinationJid, sock.serverProps.lidTrustedTokenIssueToLid, getLIDForPN, getPNForLID).then((issueJid) => issuePrivacyTokens([issueJid], issueTimestamp)).then(async (result) => {
|
|
822
|
+
await (0, import_tc_token_utils.storeTcTokensFromIqResult)({
|
|
823
|
+
result,
|
|
824
|
+
fallbackJid: tcTokenJid,
|
|
825
|
+
keys: authState.keys,
|
|
826
|
+
getLIDForPN
|
|
827
|
+
});
|
|
828
|
+
const currentData = await authState.keys.get("tctoken", [tcTokenJid]);
|
|
829
|
+
const currentEntry = currentData[tcTokenJid];
|
|
830
|
+
const indexWrite = await (0, import_tc_token_utils.buildMergedTcTokenIndexWrite)(authState.keys, [tcTokenJid]);
|
|
831
|
+
await authState.keys.set({
|
|
832
|
+
tctoken: {
|
|
833
|
+
[tcTokenJid]: {
|
|
834
|
+
token: Buffer.alloc(0),
|
|
835
|
+
...currentEntry,
|
|
836
|
+
senderTimestamp: issueTimestamp
|
|
837
|
+
},
|
|
838
|
+
...indexWrite
|
|
839
|
+
}
|
|
840
|
+
});
|
|
841
|
+
}).catch((err) => {
|
|
842
|
+
logger.debug({ jid: destinationJid, err: err?.message }, "fire-and-forget tctoken issuance failed");
|
|
843
|
+
}).finally(() => {
|
|
844
|
+
inFlightTcTokenIssuance.delete(tcTokenJid);
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
if (messageRetryManager && !participant) {
|
|
848
|
+
messageRetryManager.addRecentMessage(destinationJid, msgId, message);
|
|
849
|
+
}
|
|
850
|
+
}, meId);
|
|
851
|
+
return msgId;
|
|
852
|
+
};
|
|
853
|
+
const getMessageType = (message) => {
|
|
854
|
+
if (!message)
|
|
855
|
+
return "text";
|
|
856
|
+
if (message.reactionMessage || message.encReactionMessage) {
|
|
857
|
+
return "reaction";
|
|
858
|
+
}
|
|
859
|
+
if (message.pollCreationMessage || message.pollCreationMessageV2 || message.pollCreationMessageV3 || message.pollCreationMessageV5 || message.pollCreationMessageV6 || message.pollUpdateMessage) {
|
|
860
|
+
return "poll";
|
|
861
|
+
}
|
|
862
|
+
if (message.eventMessage) {
|
|
863
|
+
return "event";
|
|
864
|
+
}
|
|
865
|
+
if (getMediaType(message) !== "") {
|
|
866
|
+
return "media";
|
|
867
|
+
}
|
|
868
|
+
return "text";
|
|
869
|
+
};
|
|
870
|
+
const getMediaType = (message) => {
|
|
871
|
+
if (message.imageMessage) {
|
|
872
|
+
return "image";
|
|
873
|
+
} else if (message.videoMessage) {
|
|
874
|
+
return message.videoMessage.gifPlayback ? "gif" : "video";
|
|
875
|
+
} else if (message.stickerMessage) {
|
|
876
|
+
const sticker = message.stickerMessage;
|
|
877
|
+
if (sticker.isLottie)
|
|
878
|
+
return "1p_sticker";
|
|
879
|
+
if (sticker.isAvatar)
|
|
880
|
+
return "avatar_sticker";
|
|
881
|
+
if (sticker.isAiSticker)
|
|
882
|
+
return "genai_sticker";
|
|
883
|
+
return "sticker";
|
|
884
|
+
} else if (message.audioMessage) {
|
|
885
|
+
return message.audioMessage.ptt ? "ptt" : "audio";
|
|
886
|
+
} else if (message.albumMessage) {
|
|
887
|
+
return "collection";
|
|
888
|
+
} else if (message.contactMessage) {
|
|
889
|
+
return "vcard";
|
|
890
|
+
} else if (message.documentMessage) {
|
|
891
|
+
return "document";
|
|
892
|
+
} else if (message.contactsArrayMessage) {
|
|
893
|
+
return "contact_array";
|
|
894
|
+
} else if (message.liveLocationMessage) {
|
|
895
|
+
return "livelocation";
|
|
896
|
+
} else if (message.stickerPackMessage) {
|
|
897
|
+
return "sticker_pack";
|
|
898
|
+
} else if (message.listMessage) {
|
|
899
|
+
return "list";
|
|
900
|
+
} else if (message.listResponseMessage) {
|
|
901
|
+
return "list_response";
|
|
902
|
+
} else if (message.buttonsResponseMessage) {
|
|
903
|
+
return "buttons_response";
|
|
904
|
+
} else if (message.orderMessage) {
|
|
905
|
+
return "order";
|
|
906
|
+
} else if (message.productMessage) {
|
|
907
|
+
return "product";
|
|
908
|
+
} else if (message.interactiveResponseMessage) {
|
|
909
|
+
return "native_flow_response";
|
|
910
|
+
} else if (message.extendedTextMessage?.matchedText || message.groupInviteMessage) {
|
|
911
|
+
return "url";
|
|
912
|
+
} else if ((message.extendedTextMessage?.text || message.conversation || "").includes("://wa.me/c/")) {
|
|
913
|
+
return "cataloglink";
|
|
914
|
+
} else if ((message.extendedTextMessage?.text || message.conversation || "").includes("://wa.me/p/")) {
|
|
915
|
+
return "productlink";
|
|
916
|
+
}
|
|
917
|
+
return "";
|
|
918
|
+
};
|
|
919
|
+
const issuePrivacyTokens = async (jids, timestamp) => {
|
|
920
|
+
const t = (timestamp ?? (0, import_Utils.unixTimestampSeconds)()).toString();
|
|
921
|
+
const result = await query({
|
|
922
|
+
tag: "iq",
|
|
923
|
+
attrs: {
|
|
924
|
+
to: import_WABinary.S_WHATSAPP_NET,
|
|
925
|
+
type: "set",
|
|
926
|
+
xmlns: "privacy"
|
|
927
|
+
},
|
|
928
|
+
content: [
|
|
929
|
+
{
|
|
930
|
+
tag: "tokens",
|
|
931
|
+
attrs: {},
|
|
932
|
+
content: jids.map((jid) => ({
|
|
933
|
+
tag: "token",
|
|
934
|
+
attrs: {
|
|
935
|
+
jid: (0, import_WABinary.jidNormalizedUser)(jid),
|
|
936
|
+
t,
|
|
937
|
+
type: "trusted_contact"
|
|
938
|
+
}
|
|
939
|
+
}))
|
|
940
|
+
}
|
|
941
|
+
]
|
|
942
|
+
});
|
|
943
|
+
return result;
|
|
944
|
+
};
|
|
945
|
+
const waUploadToServer = (0, import_Utils.getWAUploadToServer)(config, refreshMediaConn);
|
|
946
|
+
const waitForMsgMediaUpdate = (0, import_Utils.bindWaitForEvent)(ev, "messages.media-update");
|
|
947
|
+
registerSocketEndHandler(() => {
|
|
948
|
+
if (!config.userDevicesCache && userDevicesCache.close) {
|
|
949
|
+
userDevicesCache.close();
|
|
950
|
+
}
|
|
951
|
+
mediaConn = void 0;
|
|
952
|
+
if (messageRetryManager) {
|
|
953
|
+
messageRetryManager.flushAll();
|
|
954
|
+
}
|
|
955
|
+
});
|
|
956
|
+
return {
|
|
957
|
+
...sock,
|
|
958
|
+
userDevicesCache,
|
|
959
|
+
devicesMutex,
|
|
960
|
+
issuePrivacyTokens,
|
|
961
|
+
assertSessions,
|
|
962
|
+
relayMessage,
|
|
963
|
+
sendReceipt,
|
|
964
|
+
sendReceipts,
|
|
965
|
+
readMessages,
|
|
966
|
+
refreshMediaConn,
|
|
967
|
+
// Function (not getter) so the spread in chats.ts preserves the live closure binding.
|
|
968
|
+
getMediaHost: () => mediaHost,
|
|
969
|
+
waUploadToServer,
|
|
970
|
+
fetchPrivacySettings,
|
|
971
|
+
sendPeerDataOperationMessage,
|
|
972
|
+
createParticipantNodes,
|
|
973
|
+
getUSyncDevices,
|
|
974
|
+
messageRetryManager,
|
|
975
|
+
updateMemberLabel,
|
|
976
|
+
updateMediaMessage: async (message) => {
|
|
977
|
+
const content = (0, import_Utils.assertMediaContent)(message.message);
|
|
978
|
+
const mediaKey = content.mediaKey;
|
|
979
|
+
const meId = authState.creds.me.id;
|
|
980
|
+
const node = (0, import_Utils.encryptMediaRetryRequest)(message.key, mediaKey, meId);
|
|
981
|
+
let error = void 0;
|
|
982
|
+
await Promise.all([
|
|
983
|
+
sendNode(node),
|
|
984
|
+
waitForMsgMediaUpdate(async (update) => {
|
|
985
|
+
const result = update.find((c) => c.key.id === message.key.id);
|
|
986
|
+
if (result) {
|
|
987
|
+
if (result.error) {
|
|
988
|
+
error = result.error;
|
|
989
|
+
} else {
|
|
990
|
+
try {
|
|
991
|
+
const media = (0, import_Utils.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
|
|
992
|
+
if (media.result !== import_WAProto.proto.MediaRetryNotification.ResultType.SUCCESS) {
|
|
993
|
+
const resultStr = import_WAProto.proto.MediaRetryNotification.ResultType[media.result];
|
|
994
|
+
throw new import_Addon.HttpError(`Media re-upload failed by device (${resultStr})`, {
|
|
995
|
+
data: media,
|
|
996
|
+
statusCode: (0, import_Utils.getStatusCodeForMediaRetry)(media.result) || 404
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
content.directPath = media.directPath;
|
|
1000
|
+
content.url = (0, import_Utils.getUrlFromDirectPath)(content.directPath, mediaHost);
|
|
1001
|
+
logger.debug({ directPath: media.directPath, key: result.key }, "media update successful");
|
|
1002
|
+
} catch (err) {
|
|
1003
|
+
error = err;
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
return true;
|
|
1007
|
+
}
|
|
1008
|
+
})
|
|
1009
|
+
]);
|
|
1010
|
+
if (error) {
|
|
1011
|
+
throw error;
|
|
1012
|
+
}
|
|
1013
|
+
ev.emit("messages.update", [{ key: message.key, update: { message: message.message } }]);
|
|
1014
|
+
return message;
|
|
1015
|
+
},
|
|
1016
|
+
// Add support for modifying additionalNodes and additionalAttributes using "options" in sendMessage
|
|
1017
|
+
sendMessage: async (jid, content, options = {}) => {
|
|
1018
|
+
var _a;
|
|
1019
|
+
const userJid = authState.creds.me.id;
|
|
1020
|
+
if (Array.isArray(jid)) {
|
|
1021
|
+
const { delayMs = 1500 } = options;
|
|
1022
|
+
const allUsers = /* @__PURE__ */ new Set();
|
|
1023
|
+
const fullMsg = await (0, import_Utils.generateWAMessage)("status@broadcast", content, {
|
|
1024
|
+
logger,
|
|
1025
|
+
userJid,
|
|
1026
|
+
upload: waUploadToServer,
|
|
1027
|
+
mediaCache: config.mediaCache,
|
|
1028
|
+
options: config.options,
|
|
1029
|
+
...options,
|
|
1030
|
+
messageId: (0, import_Utils.generateMessageIDV2)(userJid)
|
|
1031
|
+
});
|
|
1032
|
+
for (const id of jid) {
|
|
1033
|
+
if ((0, import_WABinary.isJidGroup)(id)) {
|
|
1034
|
+
try {
|
|
1035
|
+
const groupData = (cachedGroupMetadata ? await cachedGroupMetadata(id) : null) || await groupMetadata(id);
|
|
1036
|
+
for (const participant of groupData.participants) {
|
|
1037
|
+
if (allUsers.has(participant.id))
|
|
1038
|
+
continue;
|
|
1039
|
+
allUsers.add(participant.id);
|
|
1040
|
+
}
|
|
1041
|
+
} catch (error) {
|
|
1042
|
+
logger.error(`Error getting metadata group from ${id}: ${error}`);
|
|
1043
|
+
}
|
|
1044
|
+
} else if (!allUsers.has(id)) {
|
|
1045
|
+
allUsers.add(id);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
await relayMessage("status@broadcast", fullMsg.message, {
|
|
1049
|
+
messageId: fullMsg.key.id,
|
|
1050
|
+
statusJidList: Array.from(allUsers),
|
|
1051
|
+
additionalNodes: [
|
|
1052
|
+
{
|
|
1053
|
+
tag: "meta",
|
|
1054
|
+
attrs: {},
|
|
1055
|
+
content: [
|
|
1056
|
+
{
|
|
1057
|
+
tag: "mentioned_users",
|
|
1058
|
+
attrs: {},
|
|
1059
|
+
content: jid.map((id) => ({
|
|
1060
|
+
tag: "to",
|
|
1061
|
+
attrs: { jid: id },
|
|
1062
|
+
content: void 0
|
|
1063
|
+
}))
|
|
1064
|
+
}
|
|
1065
|
+
]
|
|
1066
|
+
}
|
|
1067
|
+
]
|
|
1068
|
+
});
|
|
1069
|
+
if (config.emitOwnEvents) {
|
|
1070
|
+
process.nextTick(async () => {
|
|
1071
|
+
await messageMutex.mutex(() => upsertMessage(fullMsg, "append"));
|
|
1072
|
+
});
|
|
1073
|
+
}
|
|
1074
|
+
for (const id of jid) {
|
|
1075
|
+
const isGroup = (0, import_WABinary.isJidGroup)(id);
|
|
1076
|
+
const sendType = isGroup ? "groupStatusMentionMessage" : "statusMentionMessage";
|
|
1077
|
+
const mentionMsg = (0, import_Utils.generateWAMessageFromContent)(id, {
|
|
1078
|
+
messageContextInfo: {
|
|
1079
|
+
messageSecret: (0, import_node_crypto.randomBytes)(32)
|
|
1080
|
+
},
|
|
1081
|
+
[sendType]: {
|
|
1082
|
+
message: {
|
|
1083
|
+
protocolMessage: {
|
|
1084
|
+
key: fullMsg.key,
|
|
1085
|
+
type: 25
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
}, {
|
|
1090
|
+
userJid
|
|
1091
|
+
});
|
|
1092
|
+
await relayMessage(id, mentionMsg.message, {
|
|
1093
|
+
additionalNodes: [
|
|
1094
|
+
{
|
|
1095
|
+
tag: "meta",
|
|
1096
|
+
attrs: isGroup ? { is_group_status_mention: "true" } : { is_status_mention: "true" },
|
|
1097
|
+
content: void 0
|
|
1098
|
+
}
|
|
1099
|
+
]
|
|
1100
|
+
});
|
|
1101
|
+
if (config.emitOwnEvents) {
|
|
1102
|
+
process.nextTick(async () => {
|
|
1103
|
+
await messageMutex.mutex(() => upsertMessage(mentionMsg, "append"));
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
await (0, import_Utils.delay)(delayMs);
|
|
1107
|
+
}
|
|
1108
|
+
return fullMsg;
|
|
1109
|
+
} else if ("disappearingMessagesInChat" in content && (0, import_WABinary.isJidGroup)(jid)) {
|
|
1110
|
+
const { disappearingMessagesInChat } = content;
|
|
1111
|
+
const value = typeof disappearingMessagesInChat === "boolean" ? disappearingMessagesInChat ? import_Defaults.WA_DEFAULT_EPHEMERAL : 0 : disappearingMessagesInChat;
|
|
1112
|
+
await groupToggleEphemeral(jid, value);
|
|
1113
|
+
} else {
|
|
1114
|
+
const fullMsg = await (0, import_Utils.generateWAMessage)(jid, content, {
|
|
1115
|
+
logger,
|
|
1116
|
+
userJid,
|
|
1117
|
+
getUrlInfo: (text) => (0, import_link_preview.getUrlInfo)(text, {
|
|
1118
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
1119
|
+
fetchOpts: {
|
|
1120
|
+
timeout: 3e3,
|
|
1121
|
+
...httpRequestOptions || {}
|
|
1122
|
+
},
|
|
1123
|
+
logger,
|
|
1124
|
+
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : void 0
|
|
1125
|
+
}),
|
|
1126
|
+
//TODO: CACHE
|
|
1127
|
+
getProfilePicUrl: sock.profilePictureUrl,
|
|
1128
|
+
getCallLink: sock.createCallLink,
|
|
1129
|
+
upload: waUploadToServer,
|
|
1130
|
+
mediaCache: config.mediaCache,
|
|
1131
|
+
options: config.options,
|
|
1132
|
+
...options,
|
|
1133
|
+
messageId: (0, import_Utils.generateMessageIDV2)(userJid)
|
|
1134
|
+
});
|
|
1135
|
+
const isNewsletter = (0, import_WABinary.isJidNewsletter)(jid);
|
|
1136
|
+
const isEventMsg = "event" in content && !!content.event;
|
|
1137
|
+
const isDeleteMsg = "delete" in content && !!content.delete;
|
|
1138
|
+
const isEditMsg = "edit" in content && !!content.edit;
|
|
1139
|
+
const isPinMsg = "pin" in content && !!content.pin;
|
|
1140
|
+
const isKeepMsg = "keep" in content && !!content.keep;
|
|
1141
|
+
const isPollMsg = "poll" in content && !!content.poll;
|
|
1142
|
+
const isQuizMsg = "poll" in content && !!content.poll.pollType;
|
|
1143
|
+
const isAiMsg = "ai" in content && !!content.ai;
|
|
1144
|
+
const isNeedBizAttrs = "secureMetaServiceLabel" in content && !!content.secureMetaServiceLabel;
|
|
1145
|
+
const additionalAttributes = options.additionalAttributes || {};
|
|
1146
|
+
const additionalNodes = options.additionalNodes || [];
|
|
1147
|
+
if (isDeleteMsg || isKeepMsg) {
|
|
1148
|
+
if ((0, import_WABinary.isJidGroup)(content.delete?.remoteJid) && !content.delete?.fromMe) {
|
|
1149
|
+
additionalAttributes.edit = "8";
|
|
1150
|
+
} else {
|
|
1151
|
+
additionalAttributes.edit = "7";
|
|
1152
|
+
}
|
|
1153
|
+
} else if (isEditMsg) {
|
|
1154
|
+
additionalAttributes.edit = isNewsletter ? "3" : "1";
|
|
1155
|
+
} else if (isPinMsg) {
|
|
1156
|
+
additionalAttributes.edit = "2";
|
|
1157
|
+
} else if (isPollMsg) {
|
|
1158
|
+
if (!isNewsletter && isQuizMsg) {
|
|
1159
|
+
throw new import_Addon.HttpError("Quiz are only allowed for newsletter", { statusCode: 400 });
|
|
1160
|
+
}
|
|
1161
|
+
additionalNodes.push({
|
|
1162
|
+
tag: "meta",
|
|
1163
|
+
attrs: {
|
|
1164
|
+
// Still a hypothesis regarding PollResult ༎ຶ‿༎ຶ
|
|
1165
|
+
polltype: isQuizMsg ? "quiz_creation" : "creation",
|
|
1166
|
+
contenttype: isPollMsg && isNewsletter ? "text" : void 0
|
|
1167
|
+
},
|
|
1168
|
+
content: void 0
|
|
1169
|
+
});
|
|
1170
|
+
} else if (isEventMsg) {
|
|
1171
|
+
additionalNodes.push({
|
|
1172
|
+
tag: "meta",
|
|
1173
|
+
attrs: {
|
|
1174
|
+
event_type: "creation"
|
|
1175
|
+
},
|
|
1176
|
+
content: void 0
|
|
1177
|
+
});
|
|
1178
|
+
} else if (isAiMsg) {
|
|
1179
|
+
if (!((0, import_WABinary.isPnUser)(jid) || (0, import_WABinary.isLidUser)(jid))) {
|
|
1180
|
+
throw new import_Addon.HttpError("AI icon on message are only allowed in private chat", { statusCode: 400 });
|
|
1181
|
+
}
|
|
1182
|
+
if ("messageContextInfo" in fullMsg.message && !!fullMsg.message.messageContextInfo) {
|
|
1183
|
+
fullMsg.message.messageContextInfo.supportPayload = import_Defaults.BIZ_BOT_SUPPORT_PAYLOAD;
|
|
1184
|
+
}
|
|
1185
|
+
;
|
|
1186
|
+
additionalNodes.push({
|
|
1187
|
+
tag: "bot",
|
|
1188
|
+
attrs: {
|
|
1189
|
+
biz_bot: "1"
|
|
1190
|
+
},
|
|
1191
|
+
content: void 0
|
|
1192
|
+
});
|
|
1193
|
+
delete content.ai;
|
|
1194
|
+
}
|
|
1195
|
+
await relayMessage(jid, fullMsg.message, {
|
|
1196
|
+
messageId: fullMsg.key.id,
|
|
1197
|
+
useCachedGroupMetadata: options.useCachedGroupMetadata,
|
|
1198
|
+
addBizAttributes: isNeedBizAttrs,
|
|
1199
|
+
statusJidList: options.statusJidList,
|
|
1200
|
+
additionalAttributes,
|
|
1201
|
+
additionalNodes
|
|
1202
|
+
});
|
|
1203
|
+
if (config.emitOwnEvents) {
|
|
1204
|
+
process.nextTick(async () => {
|
|
1205
|
+
await messageMutex.mutex(() => upsertMessage(fullMsg, "append"));
|
|
1206
|
+
});
|
|
1207
|
+
}
|
|
1208
|
+
if ("album" in content) {
|
|
1209
|
+
const { delayMs = 1500 } = options;
|
|
1210
|
+
for (const albumMedia of content.album) {
|
|
1211
|
+
const albumMsg = await (0, import_Utils.generateWAMessage)(jid, albumMedia, {
|
|
1212
|
+
logger,
|
|
1213
|
+
userJid,
|
|
1214
|
+
upload: waUploadToServer,
|
|
1215
|
+
mediaCache: config.mediaCache,
|
|
1216
|
+
options: config.options,
|
|
1217
|
+
...options,
|
|
1218
|
+
messageId: (0, import_Utils.generateMessageIDV2)(userJid)
|
|
1219
|
+
});
|
|
1220
|
+
if (!(0, import_Utils.hasValidAlbumMedia)((0, import_Utils.normalizeMessageContent)(albumMsg.message))) {
|
|
1221
|
+
throw new import_Addon.HttpError("Invalid message type for album", { statusCode: 400 });
|
|
1222
|
+
}
|
|
1223
|
+
(_a = albumMsg.message).messageContextInfo || (_a.messageContextInfo = {});
|
|
1224
|
+
albumMsg.message.messageContextInfo.messageAssociation = {
|
|
1225
|
+
parentMessageKey: fullMsg.key,
|
|
1226
|
+
associationType: import_Types.AssociationType.MEDIA_ALBUM
|
|
1227
|
+
};
|
|
1228
|
+
await relayMessage(jid, albumMsg.message, {
|
|
1229
|
+
messageId: albumMsg.key.id,
|
|
1230
|
+
useCachedGroupMetadata: options.useCachedGroupMetadata,
|
|
1231
|
+
addBizAttributes: isNeedBizAttrs,
|
|
1232
|
+
statusJidList: options.statusJidList,
|
|
1233
|
+
additionalAttributes,
|
|
1234
|
+
additionalNodes
|
|
1235
|
+
});
|
|
1236
|
+
if (config.emitOwnEvents) {
|
|
1237
|
+
process.nextTick(async () => {
|
|
1238
|
+
await messageMutex.mutex(() => upsertMessage(albumMsg, "append"));
|
|
1239
|
+
});
|
|
1240
|
+
}
|
|
1241
|
+
await (0, import_Utils.delay)(delayMs);
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
return fullMsg;
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
};
|
|
1248
|
+
};
|
|
1249
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1250
|
+
0 && (module.exports = {
|
|
1251
|
+
makeMessagesSocket
|
|
1252
|
+
});
|