xspacesocket 0.0.0-stage → 1.3.1
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 +32 -0
- package/README.md +199 -2
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +5488 -0
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.d.ts +14043 -0
- package/WAProto/index.js +107198 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/index.d.ts +81 -0
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +146 -0
- package/lib/Defaults/index.js.map +1 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/ciphertext-message.js.map +1 -0
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/lib/Signal/Group/group-session-builder.js.map +1 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
- package/lib/Signal/Group/group_cipher.js +82 -0
- package/lib/Signal/Group/group_cipher.js.map +1 -0
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.d.ts.map +1 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/index.js.map +1 -0
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
- package/lib/Signal/Group/keyhelper.js +18 -0
- package/lib/Signal/Group/keyhelper.js.map +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-chain-key.js +26 -0
- package/lib/Signal/Group/sender-chain-key.js.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-name.js +48 -0
- package/lib/Signal/Group/sender-key-name.js.map +1 -0
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-record.js +41 -0
- package/lib/Signal/Group/sender-key-record.js.map +1 -0
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-state.js +84 -0
- package/lib/Signal/Group/sender-key-state.js.map +1 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-message-key.js +26 -0
- package/lib/Signal/Group/sender-message-key.js.map +1 -0
- package/lib/Signal/libsignal.d.ts +5 -0
- package/lib/Signal/libsignal.d.ts.map +1 -0
- package/lib/Signal/libsignal.js +431 -0
- package/lib/Signal/libsignal.js.map +1 -0
- package/lib/Signal/lid-mapping.d.ts +23 -0
- package/lib/Signal/lid-mapping.d.ts.map +1 -0
- package/lib/Signal/lid-mapping.js +277 -0
- package/lib/Signal/lid-mapping.js.map +1 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.d.ts.map +1 -0
- package/lib/Socket/Client/index.js +3 -0
- package/lib/Socket/Client/index.js.map +1 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.d.ts.map +1 -0
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/types.js.map +1 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +54 -0
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +387 -0
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +379 -0
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/channelPollVote.d.ts +44 -0
- package/lib/Socket/channelPollVote.d.ts.map +1 -0
- package/lib/Socket/channelPollVote.js +65 -0
- package/lib/Socket/channelPollVote.js.map +1 -0
- package/lib/Socket/channelSchedule.d.ts +229 -0
- package/lib/Socket/channelSchedule.d.ts.map +1 -0
- package/lib/Socket/channelSchedule.js +465 -0
- package/lib/Socket/channelSchedule.js.map +1 -0
- package/lib/Socket/channelStatus.d.ts +317 -0
- package/lib/Socket/channelStatus.d.ts.map +1 -0
- package/lib/Socket/channelStatus.js +479 -0
- package/lib/Socket/channelStatus.js.map +1 -0
- package/lib/Socket/chats.d.ts +150 -0
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +1313 -0
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +444 -0
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +447 -0
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/groupHistory.d.ts +38 -0
- package/lib/Socket/groupHistory.d.ts.map +1 -0
- package/lib/Socket/groupHistory.js +88 -0
- package/lib/Socket/groupHistory.js.map +1 -0
- package/lib/Socket/groupStatus.d.ts +28 -0
- package/lib/Socket/groupStatus.d.ts.map +1 -0
- package/lib/Socket/groupStatus.js +47 -0
- package/lib/Socket/groupStatus.js.map +1 -0
- package/lib/Socket/groups.d.ts +167 -0
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +354 -0
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +430 -0
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +12 -0
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +373 -0
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +1897 -0
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +404 -0
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +1528 -0
- package/lib/Socket/messages-send.js.map +1 -0
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.d.ts.map +1 -0
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/mex.js.map +1 -0
- package/lib/Socket/newsletter.d.ts +176 -0
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +181 -0
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/newsletterDirectory.d.ts +201 -0
- package/lib/Socket/newsletterDirectory.d.ts.map +1 -0
- package/lib/Socket/newsletterDirectory.js +291 -0
- package/lib/Socket/newsletterDirectory.js.map +1 -0
- package/lib/Socket/payment.d.ts +37 -0
- package/lib/Socket/payment.d.ts.map +1 -0
- package/lib/Socket/payment.js +124 -0
- package/lib/Socket/payment.js.map +1 -0
- package/lib/Socket/report.d.ts +70 -0
- package/lib/Socket/report.d.ts.map +1 -0
- package/lib/Socket/report.js +265 -0
- package/lib/Socket/report.js.map +1 -0
- package/lib/Socket/socket.d.ts +59 -0
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +982 -0
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Socket/stickerPack.d.ts +29 -0
- package/lib/Socket/stickerPack.d.ts.map +1 -0
- package/lib/Socket/stickerPack.js +130 -0
- package/lib/Socket/stickerPack.js.map +1 -0
- package/lib/Socket/username.d.ts +55 -0
- package/lib/Socket/username.d.ts.map +1 -0
- package/lib/Socket/username.js +114 -0
- package/lib/Socket/username.js.map +1 -0
- package/lib/Types/Auth.d.ts +117 -0
- package/lib/Types/Auth.d.ts.map +1 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Auth.js.map +1 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.d.ts.map +1 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Bussines.js.map +1 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Call.d.ts.map +1 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Call.js.map +1 -0
- package/lib/Types/ChannelStatus.d.ts +34 -0
- package/lib/Types/ChannelStatus.d.ts.map +1 -0
- package/lib/Types/ChannelStatus.js +2 -0
- package/lib/Types/ChannelStatus.js.map +1 -0
- package/lib/Types/Chat.d.ts +141 -0
- package/lib/Types/Chat.d.ts.map +1 -0
- package/lib/Types/Chat.js +8 -0
- package/lib/Types/Chat.js.map +1 -0
- package/lib/Types/Contact.d.ts +26 -0
- package/lib/Types/Contact.d.ts.map +1 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Contact.js.map +1 -0
- package/lib/Types/Events.d.ts +260 -0
- package/lib/Types/Events.d.ts.map +1 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/Events.js.map +1 -0
- package/lib/Types/GroupMetadata.d.ts +73 -0
- package/lib/Types/GroupMetadata.d.ts.map +1 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/GroupMetadata.js.map +1 -0
- package/lib/Types/Label.d.ts +47 -0
- package/lib/Types/Label.d.ts.map +1 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/Label.js.map +1 -0
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/LabelAssociation.d.ts.map +1 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/LabelAssociation.js.map +1 -0
- package/lib/Types/Message.d.ts +466 -0
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +11 -0
- package/lib/Types/Message.js.map +1 -0
- package/lib/Types/Mex.d.ts +141 -0
- package/lib/Types/Mex.d.ts.map +1 -0
- package/lib/Types/Mex.js +37 -0
- package/lib/Types/Mex.js.map +1 -0
- package/lib/Types/Payment.d.ts +47 -0
- package/lib/Types/Payment.d.ts.map +1 -0
- package/lib/Types/Payment.js +2 -0
- package/lib/Types/Payment.js.map +1 -0
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Product.d.ts.map +1 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Product.js.map +1 -0
- package/lib/Types/Report.d.ts +219 -0
- package/lib/Types/Report.d.ts.map +1 -0
- package/lib/Types/Report.js +166 -0
- package/lib/Types/Report.js.map +1 -0
- package/lib/Types/Signal.d.ts +87 -0
- package/lib/Types/Signal.d.ts.map +1 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Signal.js.map +1 -0
- package/lib/Types/Socket.d.ts +136 -0
- package/lib/Types/Socket.d.ts.map +1 -0
- package/lib/Types/Socket.js +3 -0
- package/lib/Types/Socket.js.map +1 -0
- package/lib/Types/State.d.ts +97 -0
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +56 -0
- package/lib/Types/State.js.map +1 -0
- package/lib/Types/StickerPack.d.ts +52 -0
- package/lib/Types/StickerPack.d.ts.map +1 -0
- package/lib/Types/StickerPack.js +2 -0
- package/lib/Types/StickerPack.js.map +1 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.d.ts.map +1 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/USync.js.map +1 -0
- package/lib/Types/Username.d.ts +19 -0
- package/lib/Types/Username.d.ts.map +1 -0
- package/lib/Types/Username.js +2 -0
- package/lib/Types/Username.js.map +1 -0
- package/lib/Types/index.d.ts +71 -0
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +31 -0
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/auth-utils.d.ts +24 -0
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +302 -0
- package/lib/Utils/auth-utils.js.map +1 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.d.ts.map +1 -0
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/browser-utils.js.map +1 -0
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +231 -0
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +100 -0
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +890 -0
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
- package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/companion-reg-client-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +37 -0
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +118 -0
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +66 -0
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +317 -0
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +36 -0
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +642 -0
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +92 -0
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +393 -0
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/group-history.d.ts +37 -0
- package/lib/Utils/group-history.d.ts.map +1 -0
- package/lib/Utils/group-history.js +55 -0
- package/lib/Utils/group-history.js.map +1 -0
- package/lib/Utils/history.d.ts +24 -0
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +134 -0
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/identity-change-handler.d.ts +44 -0
- package/lib/Utils/identity-change-handler.d.ts.map +1 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/identity-change-handler.js.map +1 -0
- package/lib/Utils/index.d.ts +26 -0
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +26 -0
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +99 -0
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +13 -0
- package/lib/Utils/logger.d.ts.map +1 -0
- package/lib/Utils/logger.js +3 -0
- package/lib/Utils/logger.js.map +1 -0
- package/lib/Utils/lt-hash.d.ts +8 -0
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +8 -0
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts +9 -0
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +33 -0
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/message-retry-manager.d.ts +119 -0
- package/lib/Utils/message-retry-manager.d.ts.map +1 -0
- package/lib/Utils/message-retry-manager.js +276 -0
- package/lib/Utils/message-retry-manager.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +149 -0
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +875 -0
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +178 -0
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +1325 -0
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +201 -0
- package/lib/Utils/noise-handler.js.map +1 -0
- package/lib/Utils/offline-node-processor.d.ts +17 -0
- package/lib/Utils/offline-node-processor.d.ts.map +1 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/offline-node-processor.js.map +1 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.d.ts.map +1 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/pre-key-manager.js.map +1 -0
- package/lib/Utils/process-message.d.ts +85 -0
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +688 -0
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/reporting-utils.d.ts +18 -0
- package/lib/Utils/reporting-utils.d.ts.map +1 -0
- package/lib/Utils/reporting-utils.js +265 -0
- package/lib/Utils/reporting-utils.js.map +1 -0
- package/lib/Utils/rich-response.d.ts +12 -0
- package/lib/Utils/rich-response.d.ts.map +1 -0
- package/lib/Utils/rich-response.js +97 -0
- package/lib/Utils/rich-response.js.map +1 -0
- package/lib/Utils/signal.d.ts +47 -0
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +201 -0
- package/lib/Utils/signal.js.map +1 -0
- package/lib/Utils/stanza-ack.d.ts +11 -0
- package/lib/Utils/stanza-ack.d.ts.map +1 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/stanza-ack.js.map +1 -0
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.d.ts.map +1 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/sync-action-utils.js.map +1 -0
- package/lib/Utils/sync-key-auto-resolve.d.ts +10 -0
- package/lib/Utils/sync-key-auto-resolve.d.ts.map +1 -0
- package/lib/Utils/sync-key-auto-resolve.js +33 -0
- package/lib/Utils/sync-key-auto-resolve.js.map +1 -0
- package/lib/Utils/tc-token-utils.d.ts +37 -0
- package/lib/Utils/tc-token-utils.d.ts.map +1 -0
- package/lib/Utils/tc-token-utils.js +164 -0
- package/lib/Utils/tc-token-utils.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +153 -0
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +211 -0
- package/lib/Utils/validate-connection.js.map +1 -0
- package/lib/Utils/zip.d.ts +11 -0
- package/lib/Utils/zip.d.ts.map +1 -0
- package/lib/Utils/zip.js +88 -0
- package/lib/Utils/zip.js.map +1 -0
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/constants.d.ts.map +1 -0
- package/lib/WABinary/constants.js +1301 -0
- package/lib/WABinary/constants.js.map +1 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.d.ts.map +1 -0
- package/lib/WABinary/decode.js +262 -0
- package/lib/WABinary/decode.js.map +1 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.d.ts.map +1 -0
- package/lib/WABinary/encode.js +220 -0
- package/lib/WABinary/encode.js.map +1 -0
- package/lib/WABinary/generic-utils.d.ts +22 -0
- package/lib/WABinary/generic-utils.d.ts.map +1 -0
- package/lib/WABinary/generic-utils.js +201 -0
- package/lib/WABinary/generic-utils.js.map +1 -0
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.d.ts.map +1 -0
- package/lib/WABinary/index.js +6 -0
- package/lib/WABinary/index.js.map +1 -0
- package/lib/WABinary/jid-utils.d.ts +48 -0
- package/lib/WABinary/jid-utils.d.ts.map +1 -0
- package/lib/WABinary/jid-utils.js +96 -0
- package/lib/WABinary/jid-utils.js.map +1 -0
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.d.ts.map +1 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WABinary/types.js.map +1 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/BinaryInfo.d.ts.map +1 -0
- package/lib/WAM/BinaryInfo.js +10 -0
- package/lib/WAM/BinaryInfo.js.map +1 -0
- package/lib/WAM/constants.d.ts +40 -0
- package/lib/WAM/constants.d.ts.map +1 -0
- package/lib/WAM/constants.js +22853 -0
- package/lib/WAM/constants.js.map +1 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.d.ts.map +1 -0
- package/lib/WAM/encode.js +150 -0
- package/lib/WAM/encode.js.map +1 -0
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.d.ts.map +1 -0
- package/lib/WAM/index.js +4 -0
- package/lib/WAM/index.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +52 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/index.d.ts +6 -0
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/index.js +6 -0
- package/lib/WAUSync/Protocols/index.js.map +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +30 -0
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
- package/lib/WAUSync/USyncQuery.js +98 -0
- package/lib/WAUSync/USyncQuery.js.map +1 -0
- package/lib/WAUSync/USyncUser.d.ts +17 -0
- package/lib/WAUSync/USyncUser.d.ts.map +1 -0
- package/lib/WAUSync/USyncUser.js +31 -0
- package/lib/WAUSync/USyncUser.js.map +1 -0
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.d.ts.map +1 -0
- package/lib/WAUSync/index.js +4 -0
- package/lib/WAUSync/index.js.map +1 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -0
- package/lib/index.js.map +1 -0
- package/package.json +136 -4
|
@@ -0,0 +1,1528 @@
|
|
|
1
|
+
import NodeCache from '@cacheable/node-cache';
|
|
2
|
+
import { Boom } from '@hapi/boom';
|
|
3
|
+
import { proto } from '../../WAProto/index.js';
|
|
4
|
+
import { DEFAULT_CACHE_TTLS, WA_DEFAULT_EPHEMERAL } from '../Defaults/index.js';
|
|
5
|
+
import { SPAM_FLOWS, SPAM_REPORT_REASONS } from '../Types/Report.js';
|
|
6
|
+
import { aggregateMessageKeysNotFromMe, assertMediaContent, assertMeId, bindWaitForEvent, decryptMediaRetryData, DEF_MEDIA_HOST, encodeNewsletterMessage, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, encryptPollVote, extractDeviceJids, generateMessageIDV2, generateParticipantHashV2, generateWAMessage, getKeyAuthor, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, isViewOnceMessage, MessageRetryManager, normalizeMessageContent, parseAndInjectE2ESessions, sha256, shouldIncludeBizBinaryNode, unixTimestampSeconds } from '../Utils/index.js';
|
|
7
|
+
import { getUrlInfo } from '../Utils/link-preview.js';
|
|
8
|
+
import { makeKeyedMutex, makeMutex } from '../Utils/make-mutex.js';
|
|
9
|
+
import { getMessageReportingToken, shouldIncludeReportingToken } from '../Utils/reporting-utils.js';
|
|
10
|
+
import { buildMergedTcTokenIndexWrite, isTcTokenExpired, resolveIssuanceJid, resolveTcTokenJid, shouldSendNewTcToken, storeTcTokensFromIqResult } from '../Utils/tc-token-utils.js';
|
|
11
|
+
import { areJidsSameUser, getBinaryNodeChild, getBinaryNodeChildren, getBizBinaryNode, isHostedLidUser, isHostedPnUser, isJidBot, isJidGroup, isJidMetaAI, isLidUser, isPnUser, jidDecode, jidEncode, jidNormalizedUser, PSA_WID, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
12
|
+
import { USyncQuery, USyncUser } from '../WAUSync/index.js';
|
|
13
|
+
import { CHANNEL_STATUS_ECHO_TIMEOUT_MS, fetchChannelStatusResponses, fetchChannelStatuses, reactChannelStatus, revokeChannelStatus, sendChannelStatus, sendChannelStatusViewReceipt } from './channelStatus.js';
|
|
14
|
+
import { newsletterSendPollVote as sendNewsletterPollVote } from './channelPollVote.js';
|
|
15
|
+
import { cancelChannelPost, fetchChannelScheduledPosts, rescheduleChannelPost, scheduleChannelPost, sendChannelPostNow } from './channelSchedule.js';
|
|
16
|
+
import { newsletterDirectoryList as listNewsletterDirectory, newsletterDirectorySearch as searchNewsletterDirectory } from './newsletterDirectory.js';
|
|
17
|
+
import { sendGroupHistory } from './groupHistory.js';
|
|
18
|
+
import { sendGroupStatus } from './groupStatus.js';
|
|
19
|
+
import { makeNewsletterSocket } from './newsletter.js';
|
|
20
|
+
import { cancelPaymentRequest, declinePaymentRequest, requestPayment, sendPayment, sendPaymentInvite } from './payment.js';
|
|
21
|
+
import { reportAndBlock, reportChannelStatus, reportContact, reportEvent, reportGroup, reportNewsletter, reportSpam, reportStatus, reportTarget } from './report.js';
|
|
22
|
+
import { sendStickerPack } from './stickerPack.js';
|
|
23
|
+
import { checkUsername, checkUsernameMulti, deleteUsername, fetchContactUsernames, findUserByUsername, getMyUsername, getUsernameRecommendations, setUsername, setUsernamePin, setUsernameQueryIds, USERNAME_CHECK_RESULT, USERNAME_QUERY_IDS, USERNAME_SOURCE } from './username.js';
|
|
24
|
+
/**
|
|
25
|
+
* Whether a device JID is one of our own devices. A LID device is compared with
|
|
26
|
+
* our LID and any other device with our PN: areJidsSameUser compares only the
|
|
27
|
+
* user part, and a PN can share its digits with our LID.
|
|
28
|
+
*/
|
|
29
|
+
export const isOwnDeviceJid = (jid, meId, meLid) => isLidUser(jid) || isHostedLidUser(jid) ? !!meLid && areJidsSameUser(jid, meLid) : areJidsSameUser(jid, meId);
|
|
30
|
+
/**
|
|
31
|
+
* Stanza addressing for a resend to a single device (a retry). A resend to one
|
|
32
|
+
* of our own devices must name the chat as `recipient`; that device is
|
|
33
|
+
* addressed by LID as well as by PN, as handleReceipt already assumes.
|
|
34
|
+
*/
|
|
35
|
+
export const buildRetryResendAddressing = (destinationJid, participantJid, meId, meLid) => {
|
|
36
|
+
if (isJidGroup(destinationJid)) {
|
|
37
|
+
return { to: destinationJid, participant: participantJid };
|
|
38
|
+
}
|
|
39
|
+
if (isOwnDeviceJid(participantJid, meId, meLid)) {
|
|
40
|
+
return { to: participantJid, recipient: destinationJid };
|
|
41
|
+
}
|
|
42
|
+
return { to: participantJid };
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Add the close-friends audience marker to status content.
|
|
46
|
+
* Any contextInfo already on the content (e.g. mentions) is kept.
|
|
47
|
+
* Exported for testing; the socket wrapper is
|
|
48
|
+
* sendCloseFriendsStatus.
|
|
49
|
+
*/
|
|
50
|
+
export const closeFriendsStatusContent = (content) => {
|
|
51
|
+
const existing = 'contextInfo' in content ? content.contextInfo : undefined;
|
|
52
|
+
return {
|
|
53
|
+
...content,
|
|
54
|
+
contextInfo: {
|
|
55
|
+
...existing,
|
|
56
|
+
statusAudienceMetadata: {
|
|
57
|
+
audienceType: proto.ContextInfo.StatusAudienceMetadata.AudienceType.CLOSE_FRIENDS
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Build the receipt key used to mark a status as viewed.
|
|
64
|
+
* The key is read as someone else's message (fromMe: false) with
|
|
65
|
+
* the status author as participant.
|
|
66
|
+
* Exported for testing; the socket wrapper is markStatusViewed.
|
|
67
|
+
*/
|
|
68
|
+
export const buildStatusViewKey = (key, participant) => ({
|
|
69
|
+
...key,
|
|
70
|
+
fromMe: false,
|
|
71
|
+
participant
|
|
72
|
+
});
|
|
73
|
+
export const makeMessagesSocket = (config) => {
|
|
74
|
+
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: httpRequestOptions, patchMessageBeforeSending, cachedGroupMetadata, enableRecentMessageCache, maxMsgRetryCount, getMessage } = config;
|
|
75
|
+
const sock = makeNewsletterSocket(config);
|
|
76
|
+
const { ev, authState, messageMutex, signalRepository, upsertMessage, query, generateMessageTag, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral, registerSocketEndHandler } = sock;
|
|
77
|
+
const getLIDForPN = signalRepository.lidMapping.getLIDForPN.bind(signalRepository.lidMapping);
|
|
78
|
+
/**
|
|
79
|
+
* Set of tctoken storage JIDs with a fire-and-forget `issuePrivacyTokens` IQ in flight.
|
|
80
|
+
* Prevents duplicate IQs from rapid back-to-back sends before `senderTimestamp` persists.
|
|
81
|
+
* Entries are always removed in `.finally()`, so the set is bounded by concurrency.
|
|
82
|
+
*/
|
|
83
|
+
const inFlightTcTokenIssuance = new Set();
|
|
84
|
+
const userDevicesCache = config.userDevicesCache ||
|
|
85
|
+
new NodeCache({
|
|
86
|
+
stdTTL: DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
|
|
87
|
+
useClones: false
|
|
88
|
+
});
|
|
89
|
+
/** Serializes writes to userDevicesCache across USync refresh and device-notification handling. */
|
|
90
|
+
const devicesMutex = makeMutex();
|
|
91
|
+
// Initialize message retry manager if enabled
|
|
92
|
+
const messageRetryManager = enableRecentMessageCache ? new MessageRetryManager(logger, maxMsgRetryCount) : null;
|
|
93
|
+
// Prevent race conditions in Signal session encryption by user
|
|
94
|
+
const encryptionMutex = makeKeyedMutex();
|
|
95
|
+
let mediaConn;
|
|
96
|
+
/** Per-socket media host; updated whenever media_conn is fetched. Defaults to the public WhatsApp host. */
|
|
97
|
+
let mediaHost = DEF_MEDIA_HOST;
|
|
98
|
+
const refreshMediaConn = async (forceGet = false) => {
|
|
99
|
+
const media = await mediaConn;
|
|
100
|
+
if (!media || forceGet || new Date().getTime() - media.fetchDate.getTime() > media.ttl * 1000) {
|
|
101
|
+
mediaConn = (async () => {
|
|
102
|
+
const result = await query({
|
|
103
|
+
tag: 'iq',
|
|
104
|
+
attrs: {
|
|
105
|
+
type: 'set',
|
|
106
|
+
xmlns: 'w:m',
|
|
107
|
+
to: S_WHATSAPP_NET
|
|
108
|
+
},
|
|
109
|
+
content: [{ tag: 'media_conn', attrs: {} }]
|
|
110
|
+
});
|
|
111
|
+
const mediaConnNode = getBinaryNodeChild(result, 'media_conn');
|
|
112
|
+
// TODO: explore full length of data that whatsapp provides
|
|
113
|
+
const node = {
|
|
114
|
+
hosts: getBinaryNodeChildren(mediaConnNode, 'host').map(({ attrs }) => ({
|
|
115
|
+
hostname: attrs.hostname,
|
|
116
|
+
maxContentLengthBytes: +attrs.maxContentLengthBytes
|
|
117
|
+
})),
|
|
118
|
+
auth: mediaConnNode.attrs.auth,
|
|
119
|
+
ttl: +mediaConnNode.attrs.ttl,
|
|
120
|
+
fetchDate: new Date()
|
|
121
|
+
};
|
|
122
|
+
logger.debug('fetched media conn');
|
|
123
|
+
if (node.hosts[0]) {
|
|
124
|
+
mediaHost = node.hosts[0].hostname;
|
|
125
|
+
}
|
|
126
|
+
return node;
|
|
127
|
+
})();
|
|
128
|
+
}
|
|
129
|
+
return mediaConn;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* generic send receipt function
|
|
133
|
+
* used for receipts of phone call, read, delivery etc.
|
|
134
|
+
* */
|
|
135
|
+
const sendReceipt = async (jid, participant, messageIds, type) => {
|
|
136
|
+
if (!messageIds || messageIds.length === 0) {
|
|
137
|
+
throw new Boom('missing ids in receipt');
|
|
138
|
+
}
|
|
139
|
+
const node = {
|
|
140
|
+
tag: 'receipt',
|
|
141
|
+
attrs: {
|
|
142
|
+
id: messageIds[0]
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const isReadReceipt = type === 'read' || type === 'read-self';
|
|
146
|
+
if (isReadReceipt) {
|
|
147
|
+
node.attrs.t = unixTimestampSeconds().toString();
|
|
148
|
+
}
|
|
149
|
+
if (type === 'sender' && (isPnUser(jid) || isLidUser(jid))) {
|
|
150
|
+
node.attrs.recipient = jid;
|
|
151
|
+
node.attrs.to = participant;
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
node.attrs.to = jid;
|
|
155
|
+
if (participant) {
|
|
156
|
+
node.attrs.participant = participant;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (type) {
|
|
160
|
+
node.attrs.type = type;
|
|
161
|
+
}
|
|
162
|
+
const remainingMessageIds = messageIds.slice(1);
|
|
163
|
+
if (remainingMessageIds.length) {
|
|
164
|
+
node.content = [
|
|
165
|
+
{
|
|
166
|
+
tag: 'list',
|
|
167
|
+
attrs: {},
|
|
168
|
+
content: remainingMessageIds.map(id => ({
|
|
169
|
+
tag: 'item',
|
|
170
|
+
attrs: { id }
|
|
171
|
+
}))
|
|
172
|
+
}
|
|
173
|
+
];
|
|
174
|
+
}
|
|
175
|
+
logger.debug({ attrs: node.attrs, messageIds }, 'sending receipt for messages');
|
|
176
|
+
await sendNode(node);
|
|
177
|
+
};
|
|
178
|
+
/** Correctly bulk send receipts to multiple chats, participants */
|
|
179
|
+
const sendReceipts = async (keys, type) => {
|
|
180
|
+
const recps = aggregateMessageKeysNotFromMe(keys);
|
|
181
|
+
for (const { jid, participant, messageIds } of recps) {
|
|
182
|
+
await sendReceipt(jid, participant, messageIds, type);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
/** Bulk read messages. Keys can be from different chats & participants */
|
|
186
|
+
const readMessages = async (keys) => {
|
|
187
|
+
const privacySettings = await fetchPrivacySettings();
|
|
188
|
+
// based on privacy settings, we have to change the read type
|
|
189
|
+
const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self';
|
|
190
|
+
await sendReceipts(keys, readType);
|
|
191
|
+
};
|
|
192
|
+
/** Fetch all the devices we've to send a message to */
|
|
193
|
+
const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
|
|
194
|
+
const deviceResults = [];
|
|
195
|
+
if (!useCache) {
|
|
196
|
+
logger.debug('not using cache for devices');
|
|
197
|
+
}
|
|
198
|
+
const toFetch = [];
|
|
199
|
+
const jidsWithUser = jids
|
|
200
|
+
.map(jid => {
|
|
201
|
+
const decoded = jidDecode(jid);
|
|
202
|
+
const user = decoded?.user;
|
|
203
|
+
const device = decoded?.device;
|
|
204
|
+
const isExplicitDevice = typeof device === 'number' && device >= 0;
|
|
205
|
+
if (isExplicitDevice && user) {
|
|
206
|
+
deviceResults.push({
|
|
207
|
+
user,
|
|
208
|
+
device,
|
|
209
|
+
jid
|
|
210
|
+
});
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
jid = jidNormalizedUser(jid);
|
|
214
|
+
return { jid, user };
|
|
215
|
+
})
|
|
216
|
+
.filter(jid => jid !== null);
|
|
217
|
+
let mgetDevices;
|
|
218
|
+
if (useCache && userDevicesCache.mget) {
|
|
219
|
+
const usersToFetch = jidsWithUser.map(j => j?.user).filter(Boolean);
|
|
220
|
+
mgetDevices = await userDevicesCache.mget(usersToFetch);
|
|
221
|
+
}
|
|
222
|
+
for (const { jid, user } of jidsWithUser) {
|
|
223
|
+
if (useCache) {
|
|
224
|
+
const devices = mgetDevices?.[user] ||
|
|
225
|
+
(userDevicesCache.mget ? undefined : (await userDevicesCache.get(user)));
|
|
226
|
+
if (devices) {
|
|
227
|
+
const devicesWithJid = devices.map(d => ({
|
|
228
|
+
...d,
|
|
229
|
+
jid: jidEncode(d.user, d.server, d.device)
|
|
230
|
+
}));
|
|
231
|
+
deviceResults.push(...devicesWithJid);
|
|
232
|
+
logger.trace({ user }, 'using cache for devices');
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
toFetch.push(jid);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
toFetch.push(jid);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (!toFetch.length) {
|
|
243
|
+
return deviceResults;
|
|
244
|
+
}
|
|
245
|
+
const requestedLidUsers = new Set();
|
|
246
|
+
for (const jid of toFetch) {
|
|
247
|
+
if (isLidUser(jid) || isHostedLidUser(jid)) {
|
|
248
|
+
const user = jidDecode(jid)?.user;
|
|
249
|
+
if (user)
|
|
250
|
+
requestedLidUsers.add(user);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const query = new USyncQuery().withContext('message').withDeviceProtocol().withLIDProtocol();
|
|
254
|
+
for (const jid of toFetch) {
|
|
255
|
+
query.withUser(new USyncUser().withId(jid)); // todo: investigate - the idea here is that <user> should have an inline lid field with the lid being the pn equivalent
|
|
256
|
+
}
|
|
257
|
+
const result = await sock.executeUSyncQuery(query);
|
|
258
|
+
if (result) {
|
|
259
|
+
// TODO: LID MAP this stuff (lid protocol will now return lid with devices)
|
|
260
|
+
const lidResults = result.list.filter(a => !!a.lid);
|
|
261
|
+
if (lidResults.length > 0) {
|
|
262
|
+
logger.trace('Storing LID maps from device call');
|
|
263
|
+
await signalRepository.lidMapping.storeLIDPNMappings(lidResults.map(a => ({ lid: a.lid, pn: a.id })));
|
|
264
|
+
// Force-refresh sessions for newly mapped LIDs to align identity addressing
|
|
265
|
+
try {
|
|
266
|
+
const lids = lidResults.map(a => a.lid);
|
|
267
|
+
if (lids.length) {
|
|
268
|
+
await assertSessions(lids, true);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
catch (e) {
|
|
272
|
+
logger.warn({ e, count: lidResults.length }, 'failed to assert sessions for newly mapped LIDs');
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
const extracted = extractDeviceJids(result?.list, authState.creds.me.id, authState.creds.me.lid, ignoreZeroDevices);
|
|
276
|
+
const deviceMap = {};
|
|
277
|
+
for (const item of extracted) {
|
|
278
|
+
deviceMap[item.user] = deviceMap[item.user] || [];
|
|
279
|
+
deviceMap[item.user]?.push(item);
|
|
280
|
+
}
|
|
281
|
+
// Process each user's devices as a group for bulk LID migration
|
|
282
|
+
for (const [user, userDevices] of Object.entries(deviceMap)) {
|
|
283
|
+
const isLidUser = requestedLidUsers.has(user);
|
|
284
|
+
// Process all devices for this user
|
|
285
|
+
for (const item of userDevices) {
|
|
286
|
+
const finalJid = isLidUser
|
|
287
|
+
? jidEncode(user, item.server, item.device)
|
|
288
|
+
: jidEncode(item.user, item.server, item.device);
|
|
289
|
+
deviceResults.push({
|
|
290
|
+
...item,
|
|
291
|
+
jid: finalJid
|
|
292
|
+
});
|
|
293
|
+
logger.debug({
|
|
294
|
+
user: item.user,
|
|
295
|
+
device: item.device,
|
|
296
|
+
finalJid,
|
|
297
|
+
usedLid: isLidUser
|
|
298
|
+
}, 'Processed device with LID priority');
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
await devicesMutex.mutex(async () => {
|
|
302
|
+
if (userDevicesCache.mset) {
|
|
303
|
+
// if the cache supports mset, we can set all devices in one go
|
|
304
|
+
await userDevicesCache.mset(Object.entries(deviceMap).map(([key, value]) => ({ key, value })));
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
for (const key in deviceMap) {
|
|
308
|
+
if (deviceMap[key])
|
|
309
|
+
await userDevicesCache.set(key, deviceMap[key]);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
const userDeviceUpdates = {};
|
|
314
|
+
for (const [userId, devices] of Object.entries(deviceMap)) {
|
|
315
|
+
if (devices && devices.length > 0) {
|
|
316
|
+
userDeviceUpdates[userId] = devices.map(d => d.device?.toString() || '0');
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (Object.keys(userDeviceUpdates).length > 0) {
|
|
320
|
+
try {
|
|
321
|
+
await authState.keys.set({ 'device-list': userDeviceUpdates });
|
|
322
|
+
logger.debug({ userCount: Object.keys(userDeviceUpdates).length }, 'stored user device lists for bulk migration');
|
|
323
|
+
}
|
|
324
|
+
catch (error) {
|
|
325
|
+
logger.warn({ error }, 'failed to store user device lists');
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return deviceResults;
|
|
330
|
+
};
|
|
331
|
+
/**
|
|
332
|
+
* Update Member Label
|
|
333
|
+
*/
|
|
334
|
+
const updateMemberLabel = (jid, memberLabel) => {
|
|
335
|
+
return relayMessage(jid, {
|
|
336
|
+
protocolMessage: {
|
|
337
|
+
type: proto.Message.ProtocolMessage.Type.GROUP_MEMBER_LABEL_CHANGE,
|
|
338
|
+
memberLabel: {
|
|
339
|
+
label: memberLabel?.slice(0, 30),
|
|
340
|
+
labelTimestamp: unixTimestampSeconds()
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}, {
|
|
344
|
+
additionalNodes: [
|
|
345
|
+
{
|
|
346
|
+
tag: 'meta',
|
|
347
|
+
attrs: {
|
|
348
|
+
tag_reason: 'user_update',
|
|
349
|
+
appdata: 'member_tag'
|
|
350
|
+
},
|
|
351
|
+
content: undefined
|
|
352
|
+
}
|
|
353
|
+
]
|
|
354
|
+
});
|
|
355
|
+
};
|
|
356
|
+
const assertSessions = async (jids, force) => {
|
|
357
|
+
let didFetchNewSession = false;
|
|
358
|
+
const uniqueJids = [...new Set(jids)];
|
|
359
|
+
const jidsRequiringFetch = [];
|
|
360
|
+
logger.debug({ jids }, 'assertSessions call with jids');
|
|
361
|
+
for (const jid of uniqueJids) {
|
|
362
|
+
if (!force) {
|
|
363
|
+
const sessionValidation = await signalRepository.validateSession(jid);
|
|
364
|
+
if (sessionValidation.exists) {
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
jidsRequiringFetch.push(jid);
|
|
369
|
+
}
|
|
370
|
+
if (jidsRequiringFetch.length) {
|
|
371
|
+
// LID if mapped, otherwise original
|
|
372
|
+
const wireJids = [
|
|
373
|
+
...jidsRequiringFetch.filter(jid => !!isLidUser(jid) || !!isHostedLidUser(jid)),
|
|
374
|
+
...((await signalRepository.lidMapping.getLIDsForPNs(jidsRequiringFetch.filter(jid => !!isPnUser(jid) || !!isHostedPnUser(jid)))) || []).map(a => a.lid)
|
|
375
|
+
];
|
|
376
|
+
logger.debug({ jidsRequiringFetch, wireJids }, 'fetching sessions');
|
|
377
|
+
const result = await query({
|
|
378
|
+
tag: 'iq',
|
|
379
|
+
attrs: {
|
|
380
|
+
xmlns: 'encrypt',
|
|
381
|
+
type: 'get',
|
|
382
|
+
to: S_WHATSAPP_NET
|
|
383
|
+
},
|
|
384
|
+
content: [
|
|
385
|
+
{
|
|
386
|
+
tag: 'key',
|
|
387
|
+
attrs: {},
|
|
388
|
+
content: wireJids.map(jid => {
|
|
389
|
+
const attrs = { jid };
|
|
390
|
+
if (force)
|
|
391
|
+
attrs.reason = 'identity';
|
|
392
|
+
return { tag: 'user', attrs };
|
|
393
|
+
})
|
|
394
|
+
}
|
|
395
|
+
]
|
|
396
|
+
});
|
|
397
|
+
await parseAndInjectE2ESessions(result, signalRepository);
|
|
398
|
+
didFetchNewSession = true;
|
|
399
|
+
}
|
|
400
|
+
return didFetchNewSession;
|
|
401
|
+
};
|
|
402
|
+
const sendPeerMessage = async (protocolMessage) => {
|
|
403
|
+
if (!authState.creds.me?.id) {
|
|
404
|
+
throw new Boom('Not authenticated');
|
|
405
|
+
}
|
|
406
|
+
const meJid = jidNormalizedUser(authState.creds.me.id);
|
|
407
|
+
// On-demand history sync must carry privacy_sensitive: '1' or the
|
|
408
|
+
// server drops the request silently (upstream #2853).
|
|
409
|
+
const isHistorySync = protocolMessage?.peerDataOperationRequestMessage?.peerDataOperationRequestType ===
|
|
410
|
+
proto.Message.PeerDataOperationRequestType.HISTORY_SYNC_ON_DEMAND;
|
|
411
|
+
const msgId = await relayMessage(meJid, { protocolMessage }, {
|
|
412
|
+
additionalAttributes: {
|
|
413
|
+
category: 'peer',
|
|
414
|
+
push_priority: 'high_force',
|
|
415
|
+
...(isHistorySync ? { privacy_sensitive: '1' } : {})
|
|
416
|
+
},
|
|
417
|
+
additionalNodes: [
|
|
418
|
+
{
|
|
419
|
+
tag: 'meta',
|
|
420
|
+
attrs: { appdata: 'default' }
|
|
421
|
+
}
|
|
422
|
+
]
|
|
423
|
+
});
|
|
424
|
+
return msgId;
|
|
425
|
+
};
|
|
426
|
+
const sendPeerDataOperationMessage = async (pdoMessage) => {
|
|
427
|
+
return sendPeerMessage({
|
|
428
|
+
peerDataOperationRequestMessage: pdoMessage,
|
|
429
|
+
type: proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
|
|
430
|
+
});
|
|
431
|
+
};
|
|
432
|
+
// Ask the phone (primary device) to share app-state sync keys we are
|
|
433
|
+
// missing, e.g. the rotated key the server now encrypts chat state with.
|
|
434
|
+
// Mirrors whatsmeow's requestAppStateKeys: a peer protocol message of
|
|
435
|
+
// type APP_STATE_SYNC_KEY_REQUEST, sent to our own JID. The phone is
|
|
436
|
+
// expected to answer with an APP_STATE_SYNC_KEY_SHARE, which Baileys
|
|
437
|
+
// already handles in process-message.ts (stores the key, emits
|
|
438
|
+
// creds.update with myAppStateKeyId). Whatsmeow throttles this to one
|
|
439
|
+
// request per key per 24h; callers should do the same. Unproven whether
|
|
440
|
+
// the phone answers for a rotated key on an imported (non-linked) session.
|
|
441
|
+
const requestAppStateSyncKey = async (keyIds) => {
|
|
442
|
+
if (!keyIds?.length) {
|
|
443
|
+
throw new Boom('At least one app state sync key ID is required', { statusCode: 400 });
|
|
444
|
+
}
|
|
445
|
+
const msgId = await sendPeerMessage({
|
|
446
|
+
type: proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_REQUEST,
|
|
447
|
+
appStateSyncKeyRequest: {
|
|
448
|
+
keyIds: keyIds.map(keyId => ({ keyId: Buffer.from(keyId, 'base64') }))
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
logger.info({ keyIds, msgId }, 'requested app state sync keys from phone');
|
|
452
|
+
return msgId;
|
|
453
|
+
};
|
|
454
|
+
const createParticipantNodes = async (recipientJids, message, extraAttrs, dsmMessage) => {
|
|
455
|
+
if (!recipientJids.length) {
|
|
456
|
+
return { nodes: [], shouldIncludeDeviceIdentity: false };
|
|
457
|
+
}
|
|
458
|
+
const patched = await patchMessageBeforeSending(message, recipientJids);
|
|
459
|
+
const patchedMessages = Array.isArray(patched)
|
|
460
|
+
? patched
|
|
461
|
+
: recipientJids.map(jid => ({ recipientJid: jid, message: patched }));
|
|
462
|
+
let shouldIncludeDeviceIdentity = false;
|
|
463
|
+
const meId = authState.creds.me.id;
|
|
464
|
+
const meLid = authState.creds.me?.lid;
|
|
465
|
+
const meLidUser = meLid ? jidDecode(meLid)?.user : null;
|
|
466
|
+
const encryptionPromises = patchedMessages.map(async ({ recipientJid: jid, message: patchedMessage }) => {
|
|
467
|
+
try {
|
|
468
|
+
if (!jid)
|
|
469
|
+
return null;
|
|
470
|
+
let msgToEncrypt = patchedMessage;
|
|
471
|
+
if (dsmMessage) {
|
|
472
|
+
const { user: targetUser } = jidDecode(jid);
|
|
473
|
+
const { user: ownPnUser } = jidDecode(meId);
|
|
474
|
+
const ownLidUser = meLidUser;
|
|
475
|
+
const isOwnUser = targetUser === ownPnUser || (ownLidUser && targetUser === ownLidUser);
|
|
476
|
+
const isExactSenderDevice = jid === meId || (meLid && jid === meLid);
|
|
477
|
+
if (isOwnUser && !isExactSenderDevice) {
|
|
478
|
+
msgToEncrypt = dsmMessage;
|
|
479
|
+
logger.debug({ jid, targetUser }, 'Using DSM for own device');
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
const bytes = encodeWAMessage(msgToEncrypt);
|
|
483
|
+
const mutexKey = jid;
|
|
484
|
+
const node = await encryptionMutex.mutex(mutexKey, async () => {
|
|
485
|
+
const { type, ciphertext } = await signalRepository.encryptMessage({ jid, data: bytes });
|
|
486
|
+
if (type === 'pkmsg') {
|
|
487
|
+
shouldIncludeDeviceIdentity = true;
|
|
488
|
+
}
|
|
489
|
+
return {
|
|
490
|
+
tag: 'to',
|
|
491
|
+
attrs: { jid },
|
|
492
|
+
content: [
|
|
493
|
+
{
|
|
494
|
+
tag: 'enc',
|
|
495
|
+
attrs: { v: '2', type, ...(extraAttrs || {}) },
|
|
496
|
+
content: ciphertext
|
|
497
|
+
}
|
|
498
|
+
]
|
|
499
|
+
};
|
|
500
|
+
});
|
|
501
|
+
return node;
|
|
502
|
+
}
|
|
503
|
+
catch (err) {
|
|
504
|
+
logger.error({ jid, err }, 'Failed to encrypt for recipient');
|
|
505
|
+
return null;
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
const nodes = (await Promise.all(encryptionPromises)).filter(node => node !== null);
|
|
509
|
+
if (recipientJids.length > 0 && nodes.length === 0) {
|
|
510
|
+
throw new Boom('All encryptions failed', { statusCode: 500 });
|
|
511
|
+
}
|
|
512
|
+
return { nodes, shouldIncludeDeviceIdentity };
|
|
513
|
+
};
|
|
514
|
+
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList, addBizAttributes }) => {
|
|
515
|
+
const meId = assertMeId(authState.creds);
|
|
516
|
+
const meLid = authState.creds.me?.lid;
|
|
517
|
+
const isRetryResend = Boolean(participant?.jid);
|
|
518
|
+
let shouldIncludeDeviceIdentity = isRetryResend;
|
|
519
|
+
const statusJid = 'status@broadcast';
|
|
520
|
+
const { user, server } = jidDecode(jid);
|
|
521
|
+
const isGroup = server === 'g.us';
|
|
522
|
+
const isStatus = jid === statusJid;
|
|
523
|
+
const isLid = server === 'lid';
|
|
524
|
+
const isNewsletter = server === 'newsletter';
|
|
525
|
+
const isGroupOrStatus = isGroup || isStatus;
|
|
526
|
+
const finalJid = jid;
|
|
527
|
+
msgId = msgId || generateMessageIDV2(meId);
|
|
528
|
+
useUserDevicesCache = useUserDevicesCache !== false;
|
|
529
|
+
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
|
|
530
|
+
const participants = [];
|
|
531
|
+
const destinationJid = !isStatus ? finalJid : statusJid;
|
|
532
|
+
const binaryNodeContent = [];
|
|
533
|
+
const devices = [];
|
|
534
|
+
let reportingMessage;
|
|
535
|
+
const meMsg = {
|
|
536
|
+
deviceSentMessage: {
|
|
537
|
+
destinationJid,
|
|
538
|
+
message
|
|
539
|
+
},
|
|
540
|
+
messageContextInfo: message.messageContextInfo
|
|
541
|
+
};
|
|
542
|
+
const extraAttrs = {};
|
|
543
|
+
// a retry resend is encrypted once, in the dedicated retry block below;
|
|
544
|
+
// adding the participant to the regular fan-out would encrypt it twice (479)
|
|
545
|
+
if (participant && !isGroup && !isStatus) {
|
|
546
|
+
additionalAttributes = { ...additionalAttributes, device_fanout: 'false' };
|
|
547
|
+
}
|
|
548
|
+
await authState.keys.transaction(async () => {
|
|
549
|
+
const mediaType = getMediaType(normalizeMessageContent(message) || message);
|
|
550
|
+
if (mediaType) {
|
|
551
|
+
extraAttrs['mediatype'] = mediaType;
|
|
552
|
+
}
|
|
553
|
+
if (isNewsletter) {
|
|
554
|
+
const patched = patchMessageBeforeSending ? await patchMessageBeforeSending(message, []) : message;
|
|
555
|
+
const bytes = encodeNewsletterMessage(patched);
|
|
556
|
+
binaryNodeContent.push({
|
|
557
|
+
tag: 'plaintext',
|
|
558
|
+
attrs: mediaType ? { mediatype: mediaType } : {},
|
|
559
|
+
content: bytes
|
|
560
|
+
});
|
|
561
|
+
const stanza = {
|
|
562
|
+
tag: 'message',
|
|
563
|
+
attrs: {
|
|
564
|
+
to: jid,
|
|
565
|
+
id: msgId,
|
|
566
|
+
type: getMessageType(message),
|
|
567
|
+
...(additionalAttributes || {})
|
|
568
|
+
},
|
|
569
|
+
content: binaryNodeContent
|
|
570
|
+
};
|
|
571
|
+
logger.debug({ msgId }, `sending newsletter message to ${jid}`);
|
|
572
|
+
await sendNode(stanza);
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
if (normalizeMessageContent(message)?.pinInChatMessage || normalizeMessageContent(message)?.reactionMessage) {
|
|
576
|
+
extraAttrs['decrypt-fail'] = 'hide'; // todo: expand for reactions and other types
|
|
577
|
+
}
|
|
578
|
+
if (isGroupOrStatus && !isRetryResend) {
|
|
579
|
+
const [groupData, senderKeyMap] = await Promise.all([
|
|
580
|
+
(async () => {
|
|
581
|
+
let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined; // todo: should we rely on the cache specially if the cache is outdated and the metadata has new fields?
|
|
582
|
+
if (groupData && Array.isArray(groupData?.participants)) {
|
|
583
|
+
logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
|
|
584
|
+
}
|
|
585
|
+
else if (!isStatus) {
|
|
586
|
+
groupData = await groupMetadata(jid); // TODO: start storing group participant list + addr mode in Signal & stop relying on this
|
|
587
|
+
}
|
|
588
|
+
return groupData;
|
|
589
|
+
})(),
|
|
590
|
+
(async () => {
|
|
591
|
+
if (!participant && !isStatus) {
|
|
592
|
+
// what if sender memory is less accurate than the cached metadata
|
|
593
|
+
// on participant change in group, we should do sender memory manipulation
|
|
594
|
+
const result = await authState.keys.get('sender-key-memory', [jid]); // TODO: check out what if the sender key memory doesn't include the LID stuff now?
|
|
595
|
+
return result[jid] || {};
|
|
596
|
+
}
|
|
597
|
+
return {};
|
|
598
|
+
})()
|
|
599
|
+
]);
|
|
600
|
+
const participantsList = groupData ? groupData.participants.map(p => p.id) : [];
|
|
601
|
+
if (groupData?.ephemeralDuration && groupData.ephemeralDuration > 0) {
|
|
602
|
+
additionalAttributes = {
|
|
603
|
+
...additionalAttributes,
|
|
604
|
+
expiration: groupData.ephemeralDuration.toString()
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
if (isStatus && statusJidList) {
|
|
608
|
+
participantsList.push(...statusJidList);
|
|
609
|
+
}
|
|
610
|
+
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
|
|
611
|
+
devices.push(...additionalDevices);
|
|
612
|
+
if (isGroup) {
|
|
613
|
+
additionalAttributes = {
|
|
614
|
+
...additionalAttributes,
|
|
615
|
+
addressing_mode: groupData?.addressingMode || 'lid'
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
const patched = await patchMessageBeforeSending(message);
|
|
619
|
+
if (Array.isArray(patched)) {
|
|
620
|
+
throw new Boom('Per-jid patching is not supported in groups');
|
|
621
|
+
}
|
|
622
|
+
const bytes = encodeWAMessage(patched);
|
|
623
|
+
reportingMessage = patched;
|
|
624
|
+
const groupAddressingMode = additionalAttributes?.['addressing_mode'] || groupData?.addressingMode || 'lid';
|
|
625
|
+
const groupSenderIdentity = groupAddressingMode === 'lid' && meLid ? meLid : meId;
|
|
626
|
+
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
|
|
627
|
+
group: destinationJid,
|
|
628
|
+
data: bytes,
|
|
629
|
+
meId: groupSenderIdentity
|
|
630
|
+
});
|
|
631
|
+
const senderKeyRecipients = [];
|
|
632
|
+
for (const device of devices) {
|
|
633
|
+
const deviceJid = device.jid;
|
|
634
|
+
const hasKey = !!senderKeyMap[deviceJid];
|
|
635
|
+
if ((!hasKey || !!participant) &&
|
|
636
|
+
!isHostedLidUser(deviceJid) &&
|
|
637
|
+
!isHostedPnUser(deviceJid) &&
|
|
638
|
+
device.device !== 99) {
|
|
639
|
+
//todo: revamp all this logic
|
|
640
|
+
// the goal is to follow with what I said above for each group, and instead of a true false map of ids, we can set an array full of those the app has already sent pkmsgs
|
|
641
|
+
senderKeyRecipients.push(deviceJid);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
if (senderKeyRecipients.length) {
|
|
645
|
+
logger.debug({ senderKeyJids: senderKeyRecipients }, 'sending new sender key');
|
|
646
|
+
const senderKeyMsg = {
|
|
647
|
+
senderKeyDistributionMessage: {
|
|
648
|
+
axolotlSenderKeyDistributionMessage: senderKeyDistributionMessage,
|
|
649
|
+
groupId: destinationJid
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
const senderKeySessionTargets = senderKeyRecipients;
|
|
653
|
+
await assertSessions(senderKeySessionTargets);
|
|
654
|
+
const result = await createParticipantNodes(senderKeyRecipients, senderKeyMsg, extraAttrs);
|
|
655
|
+
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
|
|
656
|
+
participants.push(...result.nodes);
|
|
657
|
+
// A prepared SKDM is tracked per device; failed encryptions must be retried on the next send.
|
|
658
|
+
for (const { attrs } of result.nodes) {
|
|
659
|
+
if (attrs.jid) {
|
|
660
|
+
senderKeyMap[attrs.jid] = true;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
binaryNodeContent.push({
|
|
665
|
+
tag: 'enc',
|
|
666
|
+
attrs: { v: '2', type: 'skmsg', ...extraAttrs },
|
|
667
|
+
content: ciphertext
|
|
668
|
+
});
|
|
669
|
+
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
|
|
670
|
+
}
|
|
671
|
+
else {
|
|
672
|
+
// ADDRESSING CONSISTENCY: Match own identity to conversation context
|
|
673
|
+
// TODO: investigate if this is true
|
|
674
|
+
let ownId = meId;
|
|
675
|
+
if (isLid && meLid) {
|
|
676
|
+
ownId = meLid;
|
|
677
|
+
logger.debug({ to: jid, ownId }, 'Using LID identity for @lid conversation');
|
|
678
|
+
}
|
|
679
|
+
else {
|
|
680
|
+
logger.debug({ to: jid, ownId }, 'Using PN identity for @s.whatsapp.net conversation');
|
|
681
|
+
}
|
|
682
|
+
const { user: ownUser } = jidDecode(ownId);
|
|
683
|
+
if (!participant) {
|
|
684
|
+
const patchedForReporting = await patchMessageBeforeSending(message, [jid]);
|
|
685
|
+
reportingMessage = Array.isArray(patchedForReporting)
|
|
686
|
+
? patchedForReporting.find(item => item.recipientJid === jid) || patchedForReporting[0]
|
|
687
|
+
: patchedForReporting;
|
|
688
|
+
}
|
|
689
|
+
if (!isRetryResend) {
|
|
690
|
+
const targetUserServer = isLid ? 'lid' : 's.whatsapp.net';
|
|
691
|
+
devices.push({
|
|
692
|
+
user,
|
|
693
|
+
device: 0,
|
|
694
|
+
jid: jidEncode(user, targetUserServer, 0) // rajeh, todo: this entire logic is convoluted and weird.
|
|
695
|
+
});
|
|
696
|
+
if (user !== ownUser) {
|
|
697
|
+
const ownUserServer = isLid ? 'lid' : 's.whatsapp.net';
|
|
698
|
+
const ownUserForAddressing = isLid && meLid ? jidDecode(meLid).user : jidDecode(meId).user;
|
|
699
|
+
devices.push({
|
|
700
|
+
user: ownUserForAddressing,
|
|
701
|
+
device: 0,
|
|
702
|
+
jid: jidEncode(ownUserForAddressing, ownUserServer, 0)
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
if (additionalAttributes?.['category'] !== 'peer') {
|
|
706
|
+
// Clear placeholders and enumerate actual devices
|
|
707
|
+
devices.length = 0;
|
|
708
|
+
// Use conversation-appropriate sender identity
|
|
709
|
+
const senderIdentity = isLid && meLid
|
|
710
|
+
? jidEncode(jidDecode(meLid)?.user, 'lid', undefined)
|
|
711
|
+
: jidEncode(jidDecode(meId)?.user, 's.whatsapp.net', undefined);
|
|
712
|
+
// Enumerate devices for sender and target with consistent addressing
|
|
713
|
+
const sessionDevices = await getUSyncDevices([senderIdentity, jid], true, false);
|
|
714
|
+
devices.push(...sessionDevices);
|
|
715
|
+
logger.debug({
|
|
716
|
+
deviceCount: devices.length,
|
|
717
|
+
devices: devices.map(d => `${d.user}:${d.device}@${jidDecode(d.jid)?.server}`)
|
|
718
|
+
}, 'Device enumeration complete with unified addressing');
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
const allRecipients = [];
|
|
722
|
+
const meRecipients = [];
|
|
723
|
+
const otherRecipients = [];
|
|
724
|
+
const { user: mePnUser } = jidDecode(meId);
|
|
725
|
+
const { user: meLidUser } = meLid ? jidDecode(meLid) : { user: null };
|
|
726
|
+
for (const { user, jid } of devices) {
|
|
727
|
+
const isExactSenderDevice = jid === meId || (meLid && jid === meLid);
|
|
728
|
+
if (isExactSenderDevice) {
|
|
729
|
+
logger.debug({ jid, meId, meLid }, 'Skipping exact sender device (whatsmeow pattern)');
|
|
730
|
+
continue;
|
|
731
|
+
}
|
|
732
|
+
// Check if this is our device (could match either PN or LID user)
|
|
733
|
+
const isMe = user === mePnUser || user === meLidUser;
|
|
734
|
+
if (isMe) {
|
|
735
|
+
meRecipients.push(jid);
|
|
736
|
+
}
|
|
737
|
+
else {
|
|
738
|
+
otherRecipients.push(jid);
|
|
739
|
+
}
|
|
740
|
+
allRecipients.push(jid);
|
|
741
|
+
}
|
|
742
|
+
await assertSessions(allRecipients);
|
|
743
|
+
const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
|
|
744
|
+
// For own devices: use DSM if available (1:1 chats only)
|
|
745
|
+
createParticipantNodes(meRecipients, meMsg || message, extraAttrs),
|
|
746
|
+
createParticipantNodes(otherRecipients, message, extraAttrs, meMsg)
|
|
747
|
+
]);
|
|
748
|
+
participants.push(...meNodes);
|
|
749
|
+
participants.push(...otherNodes);
|
|
750
|
+
if (meRecipients.length > 0 || otherRecipients.length > 0) {
|
|
751
|
+
extraAttrs['phash'] = generateParticipantHashV2([...meRecipients, ...otherRecipients]);
|
|
752
|
+
}
|
|
753
|
+
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
|
|
754
|
+
}
|
|
755
|
+
if (isRetryResend) {
|
|
756
|
+
const isMe = isOwnDeviceJid(participant.jid, meId, meLid);
|
|
757
|
+
let messageToSend = message;
|
|
758
|
+
if (isGroupOrStatus) {
|
|
759
|
+
let groupSenderIdentity;
|
|
760
|
+
if (meLid && (await signalRepository.hasSenderKey({ group: destinationJid, meId: meLid }))) {
|
|
761
|
+
groupSenderIdentity = meLid;
|
|
762
|
+
}
|
|
763
|
+
else if (await signalRepository.hasSenderKey({ group: destinationJid, meId })) {
|
|
764
|
+
groupSenderIdentity = meId;
|
|
765
|
+
}
|
|
766
|
+
if (groupSenderIdentity) {
|
|
767
|
+
try {
|
|
768
|
+
const skdm = await signalRepository.getSenderKeyDistributionMessage({
|
|
769
|
+
group: destinationJid,
|
|
770
|
+
meId: groupSenderIdentity
|
|
771
|
+
});
|
|
772
|
+
messageToSend = {
|
|
773
|
+
...message,
|
|
774
|
+
senderKeyDistributionMessage: {
|
|
775
|
+
groupId: destinationJid,
|
|
776
|
+
axolotlSenderKeyDistributionMessage: skdm
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
catch (err) {
|
|
781
|
+
logger.warn({ err, jid: destinationJid }, 'failed to build SKDM for retry, sending without it');
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
const encodedMessageToSend = isMe
|
|
786
|
+
? encodeWAMessage({
|
|
787
|
+
deviceSentMessage: {
|
|
788
|
+
destinationJid,
|
|
789
|
+
message: messageToSend
|
|
790
|
+
}
|
|
791
|
+
})
|
|
792
|
+
: encodeWAMessage(messageToSend);
|
|
793
|
+
await assertSessions([participant.jid]);
|
|
794
|
+
const { type, ciphertext: encryptedContent } = await signalRepository.encryptMessage({
|
|
795
|
+
data: encodedMessageToSend,
|
|
796
|
+
jid: participant.jid
|
|
797
|
+
});
|
|
798
|
+
binaryNodeContent.push({
|
|
799
|
+
tag: 'enc',
|
|
800
|
+
attrs: {
|
|
801
|
+
v: '2',
|
|
802
|
+
type,
|
|
803
|
+
count: participant.count.toString()
|
|
804
|
+
},
|
|
805
|
+
content: encryptedContent
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
if (participants.length) {
|
|
809
|
+
if (additionalAttributes?.['category'] === 'peer') {
|
|
810
|
+
const peerNode = participants[0]?.content?.[0];
|
|
811
|
+
if (peerNode) {
|
|
812
|
+
binaryNodeContent.push(peerNode); // push only enc
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
else {
|
|
816
|
+
binaryNodeContent.push({
|
|
817
|
+
tag: 'participants',
|
|
818
|
+
attrs: {},
|
|
819
|
+
content: participants
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
const stanza = {
|
|
824
|
+
tag: 'message',
|
|
825
|
+
attrs: {
|
|
826
|
+
id: msgId,
|
|
827
|
+
to: destinationJid,
|
|
828
|
+
type: getMessageType(message),
|
|
829
|
+
...(additionalAttributes || {})
|
|
830
|
+
},
|
|
831
|
+
content: binaryNodeContent
|
|
832
|
+
};
|
|
833
|
+
// if the participant to send to is explicitly specified (generally retry recp)
|
|
834
|
+
// ensure the message is only sent to that person
|
|
835
|
+
// if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
|
|
836
|
+
if (participant) {
|
|
837
|
+
Object.assign(stanza.attrs, buildRetryResendAddressing(destinationJid, participant.jid, meId, meLid));
|
|
838
|
+
}
|
|
839
|
+
else {
|
|
840
|
+
stanza.attrs.to = destinationJid;
|
|
841
|
+
}
|
|
842
|
+
if (shouldIncludeDeviceIdentity) {
|
|
843
|
+
;
|
|
844
|
+
stanza.content.push({
|
|
845
|
+
tag: 'device-identity',
|
|
846
|
+
attrs: {},
|
|
847
|
+
content: encodeSignedDeviceIdentity(authState.creds.account, true)
|
|
848
|
+
});
|
|
849
|
+
logger.debug({ jid }, 'adding device identity');
|
|
850
|
+
}
|
|
851
|
+
// WA Web marks view once sends at the stanza level too, not just in the
|
|
852
|
+
// protobuf wrapper. Adding it here also covers retry resends.
|
|
853
|
+
if (isViewOnceMessage(message)) {
|
|
854
|
+
;
|
|
855
|
+
stanza.content.push({ tag: 'meta', attrs: { view_once: 'true' } });
|
|
856
|
+
}
|
|
857
|
+
if (!isNewsletter &&
|
|
858
|
+
!isRetryResend &&
|
|
859
|
+
reportingMessage?.messageContextInfo?.messageSecret &&
|
|
860
|
+
shouldIncludeReportingToken(reportingMessage)) {
|
|
861
|
+
try {
|
|
862
|
+
const encoded = encodeWAMessage(reportingMessage);
|
|
863
|
+
const reportingKey = {
|
|
864
|
+
id: msgId,
|
|
865
|
+
fromMe: true,
|
|
866
|
+
remoteJid: destinationJid,
|
|
867
|
+
participant: participant?.jid
|
|
868
|
+
};
|
|
869
|
+
const reportingNode = await getMessageReportingToken(encoded, reportingMessage, reportingKey);
|
|
870
|
+
if (reportingNode) {
|
|
871
|
+
;
|
|
872
|
+
stanza.content.push(reportingNode);
|
|
873
|
+
logger.trace({ jid }, 'added reporting token to message');
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
catch (error) {
|
|
877
|
+
logger.warn({ jid, trace: error?.stack }, 'failed to attach reporting token');
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
// WA Web never attaches tctoken to peer (AppStateSync) messages — server rejects with 479
|
|
881
|
+
const isPeerMessage = additionalAttributes?.['category'] === 'peer';
|
|
882
|
+
const is1on1Send = !isGroup && !isRetryResend && !isStatus && !isNewsletter && !isPeerMessage;
|
|
883
|
+
// Resolve destination to LID for tctoken storage — matches Signal session key pattern
|
|
884
|
+
const tcTokenJid = is1on1Send ? await resolveTcTokenJid(destinationJid, getLIDForPN) : destinationJid;
|
|
885
|
+
const contactTcTokenData = is1on1Send ? await authState.keys.get('tctoken', [tcTokenJid]) : {};
|
|
886
|
+
const existingTokenEntry = contactTcTokenData[tcTokenJid];
|
|
887
|
+
let tcTokenBuffer = existingTokenEntry?.token;
|
|
888
|
+
// Treat expired tokens the same as missing — clear from cache
|
|
889
|
+
if (tcTokenBuffer?.length && isTcTokenExpired(existingTokenEntry?.timestamp)) {
|
|
890
|
+
logger.debug({ jid: destinationJid, timestamp: existingTokenEntry?.timestamp }, 'tctoken expired, clearing');
|
|
891
|
+
tcTokenBuffer = undefined;
|
|
892
|
+
// Preserve senderTimestamp so the fire-and-forget issuance dedupe survives cleanup.
|
|
893
|
+
const cleared = existingTokenEntry?.senderTimestamp !== undefined
|
|
894
|
+
? { token: Buffer.alloc(0), senderTimestamp: existingTokenEntry.senderTimestamp }
|
|
895
|
+
: null;
|
|
896
|
+
try {
|
|
897
|
+
await authState.keys.set({ tctoken: { [tcTokenJid]: cleared } });
|
|
898
|
+
}
|
|
899
|
+
catch (err) {
|
|
900
|
+
logger.debug({ jid: destinationJid, err: err?.message }, 'failed to persist tctoken expiry cleanup');
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
if (tcTokenBuffer?.length && sock.serverProps.privacyTokenOn1to1) {
|
|
904
|
+
;
|
|
905
|
+
stanza.content.push({
|
|
906
|
+
tag: 'tctoken',
|
|
907
|
+
attrs: {},
|
|
908
|
+
content: tcTokenBuffer
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
let alreadyHasBizNode = false;
|
|
912
|
+
if (additionalNodes && additionalNodes.length > 0) {
|
|
913
|
+
;
|
|
914
|
+
stanza.content.push(...additionalNodes);
|
|
915
|
+
alreadyHasBizNode = !addBizAttributes && additionalNodes.some(node => node.tag === 'biz');
|
|
916
|
+
}
|
|
917
|
+
const normalizedMsg = normalizeMessageContent(message);
|
|
918
|
+
// Biz binary node: required for buttons/list/template/native-flow
|
|
919
|
+
// messages to render (and for the secureMetaServiceLabel biz shelf).
|
|
920
|
+
if (normalizedMsg &&
|
|
921
|
+
((!alreadyHasBizNode && shouldIncludeBizBinaryNode(normalizedMsg)) || addBizAttributes)) {
|
|
922
|
+
;
|
|
923
|
+
stanza.content.push(getBizBinaryNode(normalizedMsg));
|
|
924
|
+
}
|
|
925
|
+
logger.debug({ msgId }, `sending message to ${participants.length} devices`);
|
|
926
|
+
await sendNode(stanza);
|
|
927
|
+
// Fire-and-forget: issue our token to the contact AFTER message send.
|
|
928
|
+
// WA Web skips protocol messages and PSA/bot contacts (TcTokenChatAction: isRegularUser)
|
|
929
|
+
const isProtocolMsg = !!normalizeMessageContent(message)?.protocolMessage;
|
|
930
|
+
const isBotOrPSA = destinationJid === PSA_WID || isJidBot(destinationJid) || isJidMetaAI(destinationJid);
|
|
931
|
+
if (is1on1Send &&
|
|
932
|
+
!isProtocolMsg &&
|
|
933
|
+
!isBotOrPSA &&
|
|
934
|
+
shouldSendNewTcToken(existingTokenEntry?.senderTimestamp) &&
|
|
935
|
+
!inFlightTcTokenIssuance.has(tcTokenJid)) {
|
|
936
|
+
inFlightTcTokenIssuance.add(tcTokenJid);
|
|
937
|
+
const issueTimestamp = unixTimestampSeconds();
|
|
938
|
+
const getPNForLID = signalRepository.lidMapping.getPNForLID.bind(signalRepository.lidMapping);
|
|
939
|
+
resolveIssuanceJid(destinationJid, sock.serverProps.lidTrustedTokenIssueToLid, getLIDForPN, getPNForLID)
|
|
940
|
+
.then(issueJid => issuePrivacyTokens([issueJid], issueTimestamp))
|
|
941
|
+
.then(async (result) => {
|
|
942
|
+
await storeTcTokensFromIqResult({
|
|
943
|
+
result,
|
|
944
|
+
fallbackJid: tcTokenJid,
|
|
945
|
+
keys: authState.keys,
|
|
946
|
+
getLIDForPN
|
|
947
|
+
});
|
|
948
|
+
const currentData = await authState.keys.get('tctoken', [tcTokenJid]);
|
|
949
|
+
const currentEntry = currentData[tcTokenJid];
|
|
950
|
+
const indexWrite = await buildMergedTcTokenIndexWrite(authState.keys, [tcTokenJid]);
|
|
951
|
+
await authState.keys.set({
|
|
952
|
+
tctoken: {
|
|
953
|
+
[tcTokenJid]: {
|
|
954
|
+
token: Buffer.alloc(0),
|
|
955
|
+
...currentEntry,
|
|
956
|
+
senderTimestamp: issueTimestamp
|
|
957
|
+
},
|
|
958
|
+
...indexWrite
|
|
959
|
+
}
|
|
960
|
+
});
|
|
961
|
+
})
|
|
962
|
+
.catch(err => {
|
|
963
|
+
logger.debug({ jid: destinationJid, err: err?.message }, 'fire-and-forget tctoken issuance failed');
|
|
964
|
+
})
|
|
965
|
+
.finally(() => {
|
|
966
|
+
inFlightTcTokenIssuance.delete(tcTokenJid);
|
|
967
|
+
});
|
|
968
|
+
}
|
|
969
|
+
// Add message to retry cache if enabled
|
|
970
|
+
if (messageRetryManager && !participant) {
|
|
971
|
+
messageRetryManager.addRecentMessage(destinationJid, msgId, message);
|
|
972
|
+
}
|
|
973
|
+
}, meId);
|
|
974
|
+
return msgId;
|
|
975
|
+
};
|
|
976
|
+
const getMessageType = (message) => {
|
|
977
|
+
const normalizedMessage = normalizeMessageContent(message);
|
|
978
|
+
if (!normalizedMessage)
|
|
979
|
+
return 'text';
|
|
980
|
+
if (normalizedMessage.reactionMessage || normalizedMessage.encReactionMessage) {
|
|
981
|
+
return 'reaction';
|
|
982
|
+
}
|
|
983
|
+
if (normalizedMessage.pollCreationMessage ||
|
|
984
|
+
normalizedMessage.pollCreationMessageV2 ||
|
|
985
|
+
normalizedMessage.pollCreationMessageV3 ||
|
|
986
|
+
normalizedMessage.pollUpdateMessage ||
|
|
987
|
+
normalizedMessage.pollAddOptionMessage) {
|
|
988
|
+
return 'poll';
|
|
989
|
+
}
|
|
990
|
+
if (normalizedMessage.eventMessage) {
|
|
991
|
+
return 'event';
|
|
992
|
+
}
|
|
993
|
+
if (getMediaType(normalizedMessage) !== '') {
|
|
994
|
+
return 'media';
|
|
995
|
+
}
|
|
996
|
+
return 'text';
|
|
997
|
+
};
|
|
998
|
+
const getMediaType = (message) => {
|
|
999
|
+
if (message.imageMessage) {
|
|
1000
|
+
return 'image';
|
|
1001
|
+
}
|
|
1002
|
+
else if (message.videoMessage) {
|
|
1003
|
+
return message.videoMessage.gifPlayback ? 'gif' : 'video';
|
|
1004
|
+
}
|
|
1005
|
+
else if (message.audioMessage) {
|
|
1006
|
+
return message.audioMessage.ptt ? 'ptt' : 'audio';
|
|
1007
|
+
}
|
|
1008
|
+
else if (message.contactMessage) {
|
|
1009
|
+
return 'vcard';
|
|
1010
|
+
}
|
|
1011
|
+
else if (message.documentMessage) {
|
|
1012
|
+
return 'document';
|
|
1013
|
+
}
|
|
1014
|
+
else if (message.contactsArrayMessage) {
|
|
1015
|
+
return 'contact_array';
|
|
1016
|
+
}
|
|
1017
|
+
else if (message.liveLocationMessage) {
|
|
1018
|
+
return 'livelocation';
|
|
1019
|
+
}
|
|
1020
|
+
else if (message.stickerMessage) {
|
|
1021
|
+
return 'sticker';
|
|
1022
|
+
}
|
|
1023
|
+
else if (message.listMessage) {
|
|
1024
|
+
return 'list';
|
|
1025
|
+
}
|
|
1026
|
+
else if (message.listResponseMessage) {
|
|
1027
|
+
return 'list_response';
|
|
1028
|
+
}
|
|
1029
|
+
else if (message.buttonsResponseMessage) {
|
|
1030
|
+
return 'buttons_response';
|
|
1031
|
+
}
|
|
1032
|
+
else if (message.orderMessage) {
|
|
1033
|
+
return 'order';
|
|
1034
|
+
}
|
|
1035
|
+
else if (message.productMessage) {
|
|
1036
|
+
return 'product';
|
|
1037
|
+
}
|
|
1038
|
+
else if (message.interactiveResponseMessage) {
|
|
1039
|
+
return 'native_flow_response';
|
|
1040
|
+
}
|
|
1041
|
+
else if (message.groupInviteMessage) {
|
|
1042
|
+
return 'url';
|
|
1043
|
+
}
|
|
1044
|
+
return '';
|
|
1045
|
+
};
|
|
1046
|
+
const issuePrivacyTokens = async (jids, timestamp) => {
|
|
1047
|
+
const t = (timestamp ?? unixTimestampSeconds()).toString();
|
|
1048
|
+
const result = await query({
|
|
1049
|
+
tag: 'iq',
|
|
1050
|
+
attrs: {
|
|
1051
|
+
to: S_WHATSAPP_NET,
|
|
1052
|
+
type: 'set',
|
|
1053
|
+
xmlns: 'privacy'
|
|
1054
|
+
},
|
|
1055
|
+
content: [
|
|
1056
|
+
{
|
|
1057
|
+
tag: 'tokens',
|
|
1058
|
+
attrs: {},
|
|
1059
|
+
content: jids.map(jid => ({
|
|
1060
|
+
tag: 'token',
|
|
1061
|
+
attrs: {
|
|
1062
|
+
jid: jidNormalizedUser(jid),
|
|
1063
|
+
t,
|
|
1064
|
+
type: 'trusted_contact'
|
|
1065
|
+
}
|
|
1066
|
+
}))
|
|
1067
|
+
}
|
|
1068
|
+
]
|
|
1069
|
+
});
|
|
1070
|
+
return result;
|
|
1071
|
+
};
|
|
1072
|
+
const waUploadToServer = getWAUploadToServer(config, refreshMediaConn);
|
|
1073
|
+
const waitForMsgMediaUpdate = bindWaitForEvent(ev, 'messages.media-update');
|
|
1074
|
+
registerSocketEndHandler(() => {
|
|
1075
|
+
if (!config.userDevicesCache && userDevicesCache.close) {
|
|
1076
|
+
userDevicesCache.close();
|
|
1077
|
+
}
|
|
1078
|
+
mediaConn = undefined;
|
|
1079
|
+
if (messageRetryManager) {
|
|
1080
|
+
messageRetryManager.clear();
|
|
1081
|
+
}
|
|
1082
|
+
});
|
|
1083
|
+
const usernameDeps = {
|
|
1084
|
+
query,
|
|
1085
|
+
generateMessageTag,
|
|
1086
|
+
executeUSyncQuery: sock.executeUSyncQuery
|
|
1087
|
+
};
|
|
1088
|
+
const reportDeps = {
|
|
1089
|
+
query,
|
|
1090
|
+
meJid: authState.creds.me?.id,
|
|
1091
|
+
updateBlockStatus: sock.updateBlockStatus
|
|
1092
|
+
};
|
|
1093
|
+
const stickerPackDeps = {
|
|
1094
|
+
relayMessage,
|
|
1095
|
+
upload: waUploadToServer,
|
|
1096
|
+
userJid: authState.creds.me?.id,
|
|
1097
|
+
logger
|
|
1098
|
+
};
|
|
1099
|
+
const paymentDeps = {
|
|
1100
|
+
relayMessage,
|
|
1101
|
+
userJid: authState.creds.me?.id,
|
|
1102
|
+
meJid: authState.creds.me?.id
|
|
1103
|
+
};
|
|
1104
|
+
/**
|
|
1105
|
+
* Delete a message for everyone (revoke) — it is removed for all
|
|
1106
|
+
* participants. In a group, an admin can delete someone else's message.
|
|
1107
|
+
*/
|
|
1108
|
+
const deleteMessage = async (jid, key) => {
|
|
1109
|
+
const fullMsg = await generateWAMessage(jid, { delete: key }, {
|
|
1110
|
+
logger,
|
|
1111
|
+
userJid: authState.creds.me.id,
|
|
1112
|
+
upload: waUploadToServer,
|
|
1113
|
+
messageId: generateMessageIDV2(sock.user?.id)
|
|
1114
|
+
});
|
|
1115
|
+
await relayMessage(jid, fullMsg.message, {
|
|
1116
|
+
messageId: fullMsg.key.id,
|
|
1117
|
+
additionalAttributes: {
|
|
1118
|
+
// group + not the author => delete as an admin
|
|
1119
|
+
edit: isJidGroup(key.remoteJid) && !key.fromMe ? '8' : '7'
|
|
1120
|
+
}
|
|
1121
|
+
});
|
|
1122
|
+
if (config.emitOwnEvents) {
|
|
1123
|
+
process.nextTick(async () => {
|
|
1124
|
+
await messageMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
return fullMsg;
|
|
1128
|
+
};
|
|
1129
|
+
const sendMessage = async (jid, content, options = {}) => {
|
|
1130
|
+
const userJid = authState.creds.me.id;
|
|
1131
|
+
if (typeof content === 'object' &&
|
|
1132
|
+
'disappearingMessagesInChat' in content &&
|
|
1133
|
+
typeof content['disappearingMessagesInChat'] !== 'undefined' &&
|
|
1134
|
+
isJidGroup(jid)) {
|
|
1135
|
+
const { disappearingMessagesInChat } = content;
|
|
1136
|
+
const value = typeof disappearingMessagesInChat === 'boolean'
|
|
1137
|
+
? disappearingMessagesInChat
|
|
1138
|
+
? WA_DEFAULT_EPHEMERAL
|
|
1139
|
+
: 0
|
|
1140
|
+
: disappearingMessagesInChat;
|
|
1141
|
+
await groupToggleEphemeral(jid, value);
|
|
1142
|
+
}
|
|
1143
|
+
else {
|
|
1144
|
+
const fullMsg = await generateWAMessage(jid, content, {
|
|
1145
|
+
logger,
|
|
1146
|
+
userJid,
|
|
1147
|
+
getUrlInfo: text => getUrlInfo(text, {
|
|
1148
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
1149
|
+
fetchOpts: {
|
|
1150
|
+
timeout: 3000,
|
|
1151
|
+
...(httpRequestOptions || {})
|
|
1152
|
+
},
|
|
1153
|
+
logger,
|
|
1154
|
+
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
1155
|
+
}),
|
|
1156
|
+
//TODO: CACHE
|
|
1157
|
+
getProfilePicUrl: sock.profilePictureUrl,
|
|
1158
|
+
getCallLink: sock.createCallLink,
|
|
1159
|
+
upload: waUploadToServer,
|
|
1160
|
+
mediaCache: config.mediaCache,
|
|
1161
|
+
options: config.options,
|
|
1162
|
+
messageId: generateMessageIDV2(sock.user?.id),
|
|
1163
|
+
...options
|
|
1164
|
+
});
|
|
1165
|
+
const isEventMsg = 'event' in content && !!content.event;
|
|
1166
|
+
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
1167
|
+
const isEditMsg = 'edit' in content && !!content.edit;
|
|
1168
|
+
const isPinMsg = 'pin' in content && !!content.pin;
|
|
1169
|
+
const isPollMessage = 'poll' in content && !!content.poll;
|
|
1170
|
+
const additionalAttributes = {};
|
|
1171
|
+
const additionalNodes = [];
|
|
1172
|
+
// required for delete
|
|
1173
|
+
if (isDeleteMsg) {
|
|
1174
|
+
// if the chat is a group, and I am not the author, then delete the message as an admin
|
|
1175
|
+
if (isJidGroup(content.delete?.remoteJid) && !content.delete?.fromMe) {
|
|
1176
|
+
additionalAttributes.edit = '8';
|
|
1177
|
+
}
|
|
1178
|
+
else {
|
|
1179
|
+
additionalAttributes.edit = '7';
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
else if (isEditMsg) {
|
|
1183
|
+
additionalAttributes.edit = '1';
|
|
1184
|
+
}
|
|
1185
|
+
else if (isPinMsg) {
|
|
1186
|
+
additionalAttributes.edit = '2';
|
|
1187
|
+
}
|
|
1188
|
+
else if (isPollMessage) {
|
|
1189
|
+
additionalNodes.push({
|
|
1190
|
+
tag: 'meta',
|
|
1191
|
+
attrs: {
|
|
1192
|
+
polltype: 'creation'
|
|
1193
|
+
}
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
else if (isEventMsg) {
|
|
1197
|
+
additionalNodes.push({
|
|
1198
|
+
tag: 'meta',
|
|
1199
|
+
attrs: {
|
|
1200
|
+
event_type: 'creation'
|
|
1201
|
+
}
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
// Interactive messages in 1:1 chats also carry the `bot` node
|
|
1205
|
+
// (gifted-btns does the same for private chats).
|
|
1206
|
+
if (!isJidGroup(jid) &&
|
|
1207
|
+
('nativeFlow' in content || 'interactiveButtons' in content)) {
|
|
1208
|
+
additionalNodes.push({ tag: 'bot', attrs: { biz_bot: '1' } });
|
|
1209
|
+
}
|
|
1210
|
+
await relayMessage(jid, fullMsg.message, {
|
|
1211
|
+
messageId: fullMsg.key.id,
|
|
1212
|
+
useCachedGroupMetadata: options.useCachedGroupMetadata,
|
|
1213
|
+
additionalAttributes,
|
|
1214
|
+
statusJidList: options.statusJidList,
|
|
1215
|
+
additionalNodes
|
|
1216
|
+
});
|
|
1217
|
+
if (config.emitOwnEvents) {
|
|
1218
|
+
process.nextTick(async () => {
|
|
1219
|
+
await messageMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
return fullMsg;
|
|
1223
|
+
}
|
|
1224
|
+
};
|
|
1225
|
+
/**
|
|
1226
|
+
* Pin a message in a chat for everyone, for `duration` seconds.
|
|
1227
|
+
* The server accepts 24 hours (86400), 7 days (604800) or
|
|
1228
|
+
* 30 days (2592000); defaults to 24 hours.
|
|
1229
|
+
*
|
|
1230
|
+
* Safety: the message must exist in the chat first. Pinning a
|
|
1231
|
+
* message that is not there gets the account flagged, so the pin
|
|
1232
|
+
* is only sent after the message is found in the store. A missing
|
|
1233
|
+
* message is refused here instead of sent.
|
|
1234
|
+
*/
|
|
1235
|
+
const pinMessage = async (jid, key, duration = 86400) => {
|
|
1236
|
+
if (key.remoteJid && key.remoteJid !== jid) {
|
|
1237
|
+
throw new Error(`refusing to pin message ${key.id}: it belongs to ${key.remoteJid}, not ${jid}`);
|
|
1238
|
+
}
|
|
1239
|
+
const found = typeof getMessage === 'function' ? await getMessage({ ...key, remoteJid: jid }) : undefined;
|
|
1240
|
+
if (!found) {
|
|
1241
|
+
throw new Error(`refusing to pin message ${key.id} in ${jid}: message not found in this chat`);
|
|
1242
|
+
}
|
|
1243
|
+
return sendMessage(jid, { pin: key, type: proto.PinInChat.Type.PIN_FOR_ALL, time: duration });
|
|
1244
|
+
};
|
|
1245
|
+
/** Remove a pin from a message in a chat. */
|
|
1246
|
+
const unpinMessage = async (jid, key) => {
|
|
1247
|
+
return sendMessage(jid, { pin: key, type: proto.PinInChat.Type.UNPIN_FOR_ALL });
|
|
1248
|
+
};
|
|
1249
|
+
/**
|
|
1250
|
+
* Post a personal status (story) visible to your contacts.
|
|
1251
|
+
* Same content shapes as sendMessage: { text }, { image, caption },
|
|
1252
|
+
* { video, caption }, { audio, ptt }, { sticker }, etc.
|
|
1253
|
+
*/
|
|
1254
|
+
const sendPersonalStatus = async (content, options = {}) => {
|
|
1255
|
+
return sendMessage('status@broadcast', content, options);
|
|
1256
|
+
};
|
|
1257
|
+
/**
|
|
1258
|
+
* Post a personal status visible only to the given close friends.
|
|
1259
|
+
* The status carries the close-friends audience marker and is
|
|
1260
|
+
* fanned out only to `closeFriendJids`.
|
|
1261
|
+
*/
|
|
1262
|
+
const sendCloseFriendsStatus = async (content, closeFriendJids, options = {}) => {
|
|
1263
|
+
return sendMessage('status@broadcast', closeFriendsStatusContent(content), {
|
|
1264
|
+
...options,
|
|
1265
|
+
statusJidList: closeFriendJids
|
|
1266
|
+
});
|
|
1267
|
+
};
|
|
1268
|
+
/**
|
|
1269
|
+
* Mark a status as viewed. `key` is the status message key —
|
|
1270
|
+
* group status keys carry the group JID, personal status keys
|
|
1271
|
+
* carry 'status@broadcast'. `participant` is the status author
|
|
1272
|
+
* and defaults to your own JID.
|
|
1273
|
+
*/
|
|
1274
|
+
const markStatusViewed = async (key, participant) => {
|
|
1275
|
+
await readMessages([buildStatusViewKey(key, participant ?? authState.creds.me?.id)]);
|
|
1276
|
+
};
|
|
1277
|
+
/**
|
|
1278
|
+
* React to a status (group or personal). `jid` is the group JID
|
|
1279
|
+
* for a group status, or 'status@broadcast' for a personal status
|
|
1280
|
+
* (pass your own JID in `statusJidList` for personal statuses,
|
|
1281
|
+
* as the reaction is fanned out to that list).
|
|
1282
|
+
*/
|
|
1283
|
+
const reactToStatus = async (jid, key, emoji, statusJidList) => {
|
|
1284
|
+
return sendMessage(jid, { react: { key, text: emoji } }, statusJidList ? { statusJidList } : {});
|
|
1285
|
+
};
|
|
1286
|
+
/**
|
|
1287
|
+
* Report spam two ways: by target JID (`sock.reportSpam(jid, options?)`,
|
|
1288
|
+
* one IQ, one summary) or by messages (`sock.reportSpam(messages,
|
|
1289
|
+
* options?)`, one IQ per message, one result per message).
|
|
1290
|
+
*/
|
|
1291
|
+
const reportSpamSocket = ((targetOrMessages, options = {}) => typeof targetOrMessages === 'string'
|
|
1292
|
+
? reportTarget(targetOrMessages, reportDeps, options)
|
|
1293
|
+
: reportSpam(targetOrMessages, reportDeps, options));
|
|
1294
|
+
/**
|
|
1295
|
+
* Vote on a poll by option name. The vote is encrypted with the poll
|
|
1296
|
+
* creation message's secret, so pass it in `pollInfo` — the fork does
|
|
1297
|
+
* not look the creation message up in any store. `creatorJid` defaults
|
|
1298
|
+
* to the author of `pollCreationMessageKey` (the same derivation the
|
|
1299
|
+
* vote decryption uses). The voter JID is the bot's LID when the poll
|
|
1300
|
+
* is LID-addressed, else its phone JID — receivers decrypt with the
|
|
1301
|
+
* voter JID from the vote message's key, so the wrong form makes the
|
|
1302
|
+
* vote undecryptable and it never counts. The vote is sent through the
|
|
1303
|
+
* raw pollUpdateMessage passthrough, so no new send plumbing was needed.
|
|
1304
|
+
*/
|
|
1305
|
+
const sendPollVote = async (jid, pollCreationMessageKey, options, pollInfo) => {
|
|
1306
|
+
const meIdNormalised = jidNormalizedUser(assertMeId(authState.creds));
|
|
1307
|
+
const meLidNormalised = authState.creds.me?.lid ? jidNormalizedUser(authState.creds.me.lid) : null;
|
|
1308
|
+
const pollMsgId = pollCreationMessageKey.id;
|
|
1309
|
+
if (!pollMsgId) {
|
|
1310
|
+
throw new Boom('pollCreationMessageKey needs an id', { statusCode: 400 });
|
|
1311
|
+
}
|
|
1312
|
+
const optionNames = Array.isArray(options) ? options : [options];
|
|
1313
|
+
if (!optionNames.length) {
|
|
1314
|
+
throw new Boom('sendPollVote needs at least one option', { statusCode: 400 });
|
|
1315
|
+
}
|
|
1316
|
+
// The vote is decrypted by other clients with the voter JID from the
|
|
1317
|
+
// vote message's key. In a LID-addressed group that is the voter's
|
|
1318
|
+
// LID, but meIdNormalised is the phone JID — encrypting with it makes
|
|
1319
|
+
// the vote fail AES-GCM auth on every client so it never counts, even
|
|
1320
|
+
// though the send succeeds (2026-11-21, "Alice" poll: vote reported
|
|
1321
|
+
// sent with an ID but the poll stayed 0/0). Use the LID when the poll
|
|
1322
|
+
// is LID-addressed.
|
|
1323
|
+
const creatorJid = pollInfo.creatorJid || getKeyAuthor(pollCreationMessageKey, meIdNormalised);
|
|
1324
|
+
const voterJid = (creatorJid.endsWith('@lid') || pollCreationMessageKey.participant?.endsWith('@lid') || pollCreationMessageKey.addressingMode === 'lid') && meLidNormalised
|
|
1325
|
+
? meLidNormalised
|
|
1326
|
+
: meIdNormalised;
|
|
1327
|
+
const vote = encryptPollVote({ selectedOptions: optionNames.map(name => sha256(Buffer.from(name))) }, {
|
|
1328
|
+
pollCreatorJid: creatorJid,
|
|
1329
|
+
pollMsgId,
|
|
1330
|
+
pollEncKey: pollInfo.messageSecret,
|
|
1331
|
+
voterJid
|
|
1332
|
+
});
|
|
1333
|
+
return sendMessage(jid, {
|
|
1334
|
+
pollUpdateMessage: {
|
|
1335
|
+
pollCreationMessageKey,
|
|
1336
|
+
vote,
|
|
1337
|
+
senderTimestampMs: Date.now()
|
|
1338
|
+
}
|
|
1339
|
+
});
|
|
1340
|
+
};
|
|
1341
|
+
return {
|
|
1342
|
+
...sock,
|
|
1343
|
+
userDevicesCache,
|
|
1344
|
+
devicesMutex,
|
|
1345
|
+
issuePrivacyTokens,
|
|
1346
|
+
assertSessions,
|
|
1347
|
+
relayMessage,
|
|
1348
|
+
sendGroupStatus: (jid, content, options = {}) => sendGroupStatus(jid, content, {
|
|
1349
|
+
relayMessage,
|
|
1350
|
+
waUploadToServer,
|
|
1351
|
+
userJid: authState.creds.me?.id,
|
|
1352
|
+
linkPreviewImageThumbnailWidth,
|
|
1353
|
+
generateHighQualityLinkPreview,
|
|
1354
|
+
httpRequestOptions,
|
|
1355
|
+
logger
|
|
1356
|
+
}, options),
|
|
1357
|
+
sendChannelStatus: (jid, content, options = {}) => sendChannelStatus(jid, content, {
|
|
1358
|
+
sendNode,
|
|
1359
|
+
waUploadToServer,
|
|
1360
|
+
userJid: authState.creds.me?.id
|
|
1361
|
+
}, options),
|
|
1362
|
+
newsletterSendStatus: async (jid, content, options = {}) => {
|
|
1363
|
+
const sent = await sendChannelStatus(jid, content, {
|
|
1364
|
+
sendNode,
|
|
1365
|
+
waUploadToServer,
|
|
1366
|
+
userJid: authState.creds.me?.id
|
|
1367
|
+
}, options);
|
|
1368
|
+
// The server-assigned id of a posted status only arrives in the
|
|
1369
|
+
// server echo of that status (an incoming <status> stanza,
|
|
1370
|
+
// surfaced as 'newsletter.status'). The echo is a network round
|
|
1371
|
+
// trip away, so attaching the listener right after the send
|
|
1372
|
+
// cannot miss it. It is matched by the stanza id from the send.
|
|
1373
|
+
// If the echo does not arrive in time (or the server rejected
|
|
1374
|
+
// the post), the server id stays undefined — the send itself
|
|
1375
|
+
// already went out.
|
|
1376
|
+
const newsletterStatusServerId = await new Promise(resolve => {
|
|
1377
|
+
const onStatus = (status) => {
|
|
1378
|
+
if (status.channelJid === jid && status.id === sent.id) {
|
|
1379
|
+
clearTimeout(timer);
|
|
1380
|
+
ev.off('newsletter.status', onStatus);
|
|
1381
|
+
resolve(status.serverId);
|
|
1382
|
+
}
|
|
1383
|
+
};
|
|
1384
|
+
const timer = setTimeout(() => {
|
|
1385
|
+
ev.off('newsletter.status', onStatus);
|
|
1386
|
+
resolve(undefined);
|
|
1387
|
+
}, CHANNEL_STATUS_ECHO_TIMEOUT_MS);
|
|
1388
|
+
ev.on('newsletter.status', onStatus);
|
|
1389
|
+
});
|
|
1390
|
+
return { ...sent, newsletterStatusServerId };
|
|
1391
|
+
},
|
|
1392
|
+
newsletterReactStatus: (jid, serverId, reaction) => reactChannelStatus(jid, serverId, reaction, { query, generateMessageTag }),
|
|
1393
|
+
newsletterRevokeStatus: (jid, statusId) => revokeChannelStatus(jid, statusId, { query, generateMessageTag }),
|
|
1394
|
+
newsletterFetchStatus: (jid, options) => fetchChannelStatuses(jid, options, { query, generateMessageTag }),
|
|
1395
|
+
newsletterFetchStatusResponses: (jid, serverId, options) => fetchChannelStatusResponses(jid, serverId, options, { query, generateMessageTag }),
|
|
1396
|
+
newsletterSendStatusViewReceipt: (jid, receiptStanzaId, sortId) => sendChannelStatusViewReceipt(jid, receiptStanzaId, sortId, { sendNode }),
|
|
1397
|
+
newsletterScheduleChannelPost: (jid, content, publishAtMs, options = {}) => scheduleChannelPost(jid, content, publishAtMs, {
|
|
1398
|
+
sendNode,
|
|
1399
|
+
waUploadToServer,
|
|
1400
|
+
userJid: authState.creds.me?.id
|
|
1401
|
+
}, options),
|
|
1402
|
+
newsletterRescheduleChannelPost: (jid, clientId, content, publishAtMs, options = {}) => rescheduleChannelPost(jid, clientId, content, publishAtMs, {
|
|
1403
|
+
sendNode,
|
|
1404
|
+
waUploadToServer,
|
|
1405
|
+
userJid: authState.creds.me?.id,
|
|
1406
|
+
query,
|
|
1407
|
+
generateMessageTag
|
|
1408
|
+
}, options),
|
|
1409
|
+
newsletterSendChannelPostNow: (jid, clientId, content, options = {}) => sendChannelPostNow(jid, clientId, content, {
|
|
1410
|
+
sendNode,
|
|
1411
|
+
waUploadToServer,
|
|
1412
|
+
userJid: authState.creds.me?.id,
|
|
1413
|
+
query,
|
|
1414
|
+
generateMessageTag
|
|
1415
|
+
}, options),
|
|
1416
|
+
newsletterCancelChannelPost: (jid, clientId) => cancelChannelPost(jid, clientId, { query, generateMessageTag }),
|
|
1417
|
+
newsletterFetchChannelScheduledPosts: (jid, options) => fetchChannelScheduledPosts(jid, options, { query, generateMessageTag }),
|
|
1418
|
+
newsletterDirectorySearch: (searchText, options = {}) => searchNewsletterDirectory(searchText, options, { query, generateMessageTag }),
|
|
1419
|
+
newsletterDirectoryList: (options = {}) => listNewsletterDirectory(options, { query, generateMessageTag }),
|
|
1420
|
+
pinMessage,
|
|
1421
|
+
unpinMessage,
|
|
1422
|
+
sendPersonalStatus,
|
|
1423
|
+
sendCloseFriendsStatus,
|
|
1424
|
+
markStatusViewed,
|
|
1425
|
+
reactToStatus,
|
|
1426
|
+
sendGroupHistory: (jid, receivers, messages, options = {}) => sendGroupHistory(jid, receivers, messages, {
|
|
1427
|
+
relayMessage,
|
|
1428
|
+
waUploadToServer,
|
|
1429
|
+
userJid: authState.creds.me?.id,
|
|
1430
|
+
logger
|
|
1431
|
+
}, options),
|
|
1432
|
+
checkUsername: (username, includeSuggestions = true, sessionId) => checkUsername(username, usernameDeps, includeSuggestions, sessionId),
|
|
1433
|
+
checkUsernameMulti: (usernames) => checkUsernameMulti(usernames, usernameDeps),
|
|
1434
|
+
setUsername: (username, options = {}) => setUsername(username, usernameDeps, options),
|
|
1435
|
+
deleteUsername: () => deleteUsername(usernameDeps),
|
|
1436
|
+
getMyUsername: () => getMyUsername(usernameDeps),
|
|
1437
|
+
getUsernameRecommendations: (source = null) => getUsernameRecommendations(usernameDeps, source),
|
|
1438
|
+
setUsernamePin: (pin) => setUsernamePin(pin, usernameDeps),
|
|
1439
|
+
findUserByUsername: (username, pin) => findUserByUsername(username, usernameDeps, pin),
|
|
1440
|
+
fetchContactUsernames: (...jids) => fetchContactUsernames(jids, usernameDeps),
|
|
1441
|
+
setUsernameQueryIds: (ids) => setUsernameQueryIds(ids),
|
|
1442
|
+
USERNAME_QUERY_IDS,
|
|
1443
|
+
USERNAME_CHECK_RESULT,
|
|
1444
|
+
USERNAME_SOURCE,
|
|
1445
|
+
reportSpam: reportSpamSocket,
|
|
1446
|
+
reportContact: (jid, messages, options = {}) => reportContact(jid, messages, reportDeps, options),
|
|
1447
|
+
reportGroup: (jid, messages, options = {}) => reportGroup(jid, messages, reportDeps, options),
|
|
1448
|
+
reportStatus: (jid, messages, options = {}) => reportStatus(jid, messages, reportDeps, options),
|
|
1449
|
+
reportNewsletter: (jid, messages, options = {}) => reportNewsletter(jid, messages, reportDeps, options),
|
|
1450
|
+
reportChannelStatus: (jid, messages, options = {}) => reportChannelStatus(jid, messages, reportDeps, options),
|
|
1451
|
+
reportEvent: (jid, messages, options = {}) => reportEvent(jid, messages, reportDeps, options),
|
|
1452
|
+
reportAndBlock: (jid, messages, options = {}) => reportAndBlock(jid, messages, reportDeps, options),
|
|
1453
|
+
SPAM_FLOWS,
|
|
1454
|
+
SPAM_REPORT_REASONS,
|
|
1455
|
+
getPNForLID: (lid) => signalRepository.lidMapping.getPNForLID(lid),
|
|
1456
|
+
getPNsForLIDs: (lids) => signalRepository.lidMapping.getPNsForLIDs(lids),
|
|
1457
|
+
getLIDForPN: (pn) => signalRepository.lidMapping.getLIDForPN(pn),
|
|
1458
|
+
getLIDsForPNs: (pns) => signalRepository.lidMapping.getLIDsForPNs(pns),
|
|
1459
|
+
sendStickerPack: (jid, pack) => sendStickerPack(jid, pack, stickerPackDeps),
|
|
1460
|
+
requestPayment: (jid, options) => requestPayment(jid, options, paymentDeps),
|
|
1461
|
+
sendPayment: (jid, options) => sendPayment(jid, options, paymentDeps),
|
|
1462
|
+
declinePaymentRequest: (jid, key) => declinePaymentRequest(jid, key, paymentDeps),
|
|
1463
|
+
cancelPaymentRequest: (jid, key) => cancelPaymentRequest(jid, key, paymentDeps),
|
|
1464
|
+
sendPaymentInvite: (jid, options = {}) => sendPaymentInvite(jid, options, paymentDeps),
|
|
1465
|
+
deleteMessage,
|
|
1466
|
+
sendReceipt,
|
|
1467
|
+
sendReceipts,
|
|
1468
|
+
readMessages,
|
|
1469
|
+
refreshMediaConn,
|
|
1470
|
+
// Function (not getter) so the spread in chats.ts preserves the live closure binding.
|
|
1471
|
+
getMediaHost: () => mediaHost,
|
|
1472
|
+
waUploadToServer,
|
|
1473
|
+
fetchPrivacySettings,
|
|
1474
|
+
sendPeerDataOperationMessage,
|
|
1475
|
+
sendPeerMessage,
|
|
1476
|
+
requestAppStateSyncKey,
|
|
1477
|
+
createParticipantNodes,
|
|
1478
|
+
getUSyncDevices,
|
|
1479
|
+
messageRetryManager,
|
|
1480
|
+
updateMemberLabel,
|
|
1481
|
+
updateMediaMessage: async (message) => {
|
|
1482
|
+
const content = assertMediaContent(message.message);
|
|
1483
|
+
const mediaKey = content.mediaKey;
|
|
1484
|
+
const meId = authState.creds.me.id;
|
|
1485
|
+
const node = encryptMediaRetryRequest(message.key, mediaKey, meId);
|
|
1486
|
+
let error = undefined;
|
|
1487
|
+
await Promise.all([
|
|
1488
|
+
sendNode(node),
|
|
1489
|
+
waitForMsgMediaUpdate(async (update) => {
|
|
1490
|
+
const result = update.find(c => c.key.id === message.key.id);
|
|
1491
|
+
if (result) {
|
|
1492
|
+
if (result.error) {
|
|
1493
|
+
error = result.error;
|
|
1494
|
+
}
|
|
1495
|
+
else {
|
|
1496
|
+
try {
|
|
1497
|
+
const media = decryptMediaRetryData(result.media, mediaKey, result.key.id);
|
|
1498
|
+
if (media.result !== proto.MediaRetryNotification.ResultType.SUCCESS) {
|
|
1499
|
+
const resultStr = proto.MediaRetryNotification.ResultType[media.result];
|
|
1500
|
+
throw new Boom(`Media re-upload failed by device (${resultStr})`, {
|
|
1501
|
+
data: media,
|
|
1502
|
+
statusCode: getStatusCodeForMediaRetry(media.result) || 404
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
content.directPath = media.directPath;
|
|
1506
|
+
content.url = getUrlFromDirectPath(content.directPath, mediaHost);
|
|
1507
|
+
logger.debug({ directPath: media.directPath, key: result.key }, 'media update successful');
|
|
1508
|
+
}
|
|
1509
|
+
catch (err) {
|
|
1510
|
+
error = err;
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
return true;
|
|
1514
|
+
}
|
|
1515
|
+
})
|
|
1516
|
+
]);
|
|
1517
|
+
if (error) {
|
|
1518
|
+
throw error;
|
|
1519
|
+
}
|
|
1520
|
+
ev.emit('messages.update', [{ key: message.key, update: { message: message.message } }]);
|
|
1521
|
+
return message;
|
|
1522
|
+
},
|
|
1523
|
+
sendMessage,
|
|
1524
|
+
sendPollVote,
|
|
1525
|
+
newsletterSendPollVote: (jid, parentServerId, options) => sendNewsletterPollVote(jid, parentServerId, options, { query, generateMessageTag }),
|
|
1526
|
+
};
|
|
1527
|
+
};
|
|
1528
|
+
//# sourceMappingURL=messages-send.js.map
|