@neelegirl/baileys 1.5.6 → 1.5.7
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/README.md +21 -27
- package/WAProto/WAProto.proto +665 -291
- package/WAProto/index.d.ts +48037 -2294
- package/WAProto/index.js +139804 -45203
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +64 -58
- package/lib/Defaults/index.js +96 -74
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/WASignalGroup/GroupProtocol.js +1909 -0
- package/lib/Signal/WASignalGroup/ciphertext_message.js +16 -0
- package/lib/Signal/WASignalGroup/generate-proto.sh +1 -0
- package/lib/Signal/WASignalGroup/group.proto +42 -0
- package/lib/Signal/WASignalGroup/group_cipher.js +120 -0
- package/lib/Signal/WASignalGroup/group_session_builder.js +46 -0
- package/lib/Signal/WASignalGroup/index.js +6 -0
- package/lib/Signal/WASignalGroup/keyhelper.js +21 -0
- package/lib/Signal/WASignalGroup/protobufs.js +3 -0
- package/lib/Signal/WASignalGroup/queue_job.js +69 -0
- package/lib/Signal/WASignalGroup/readme.md +6 -0
- package/lib/Signal/WASignalGroup/sender_chain_key.js +50 -0
- package/lib/Signal/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/lib/Signal/WASignalGroup/sender_key_message.js +92 -0
- package/lib/Signal/WASignalGroup/sender_key_name.js +70 -0
- package/lib/Signal/WASignalGroup/sender_key_record.js +56 -0
- package/lib/Signal/WASignalGroup/sender_key_state.js +129 -0
- package/lib/Signal/{Group/sender-message-key.js → WASignalGroup/sender_message_key.js} +16 -3
- package/lib/Signal/libsignal.d.ts +4 -5
- package/lib/Signal/libsignal.js +112 -292
- package/lib/Socket/Client/abstract-socket-client.d.ts +15 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +22 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +12 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/types.d.ts +15 -15
- package/lib/Socket/Client/types.js +15 -8
- package/lib/Socket/Client/websocket.d.ts +12 -12
- package/lib/Socket/Client/websocket.js +36 -24
- package/lib/Socket/business.d.ts +177 -178
- package/lib/Socket/business.js +71 -179
- package/lib/Socket/chats.d.ts +93 -93
- package/lib/Socket/chats.js +625 -474
- package/lib/Socket/communities.d.ts +62 -83
- package/lib/Socket/communities.js +414 -412
- package/lib/Socket/groups.d.ts +112 -118
- package/lib/Socket/groups.js +171 -146
- package/lib/Socket/index.d.ts +182 -222
- package/lib/Socket/index.js +17 -12
- package/lib/Socket/messages-recv.d.ts +169 -165
- package/lib/Socket/messages-recv.js +1721 -1185
- package/lib/Socket/messages-send.d.ts +160 -161
- package/lib/Socket/messages-send.js +992 -642
- package/lib/Socket/mex.d.ts +0 -1
- package/lib/Socket/mex.js +9 -4
- package/lib/Socket/newsletter.d.ts +139 -139
- package/lib/Socket/newsletter.js +258 -153
- package/lib/Socket/registration.d.ts +266 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +36 -42
- package/lib/Socket/socket.js +525 -623
- package/lib/Socket/usync.d.ts +37 -0
- package/lib/Socket/usync.js +83 -0
- package/lib/Store/index.d.ts +4 -0
- package/lib/Store/index.js +24 -0
- package/lib/Store/make-cache-manager-store.d.ts +14 -0
- package/lib/Store/make-cache-manager-store.js +90 -0
- package/lib/Store/make-in-memory-store.d.ts +123 -0
- package/lib/Store/make-in-memory-store.js +429 -0
- package/lib/Store/make-ordered-dictionary.d.ts +12 -0
- package/lib/Store/make-ordered-dictionary.js +86 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +31 -0
- package/lib/Types/Auth.d.ts +96 -87
- package/lib/Types/Auth.js +3 -2
- package/lib/Types/Call.d.ts +13 -13
- package/lib/Types/Call.js +3 -2
- package/lib/Types/Chat.d.ts +94 -79
- package/lib/Types/Chat.js +9 -8
- package/lib/Types/Contact.d.ts +9 -13
- package/lib/Types/Contact.js +3 -2
- package/lib/Types/Events.d.ts +179 -152
- package/lib/Types/Events.js +3 -2
- package/lib/Types/GroupMetadata.d.ts +48 -49
- package/lib/Types/GroupMetadata.js +3 -2
- package/lib/Types/Label.d.ts +14 -13
- package/lib/Types/Label.js +30 -24
- package/lib/Types/LabelAssociation.d.ts +20 -15
- package/lib/Types/LabelAssociation.js +12 -6
- package/lib/Types/Message.d.ts +404 -234
- package/lib/Types/Message.js +13 -11
- package/lib/Types/MexUpdates.d.ts +9 -0
- package/lib/Types/MexUpdates.js +18 -0
- package/lib/Types/Newsletter.d.ts +104 -130
- package/lib/Types/Newsletter.js +40 -31
- package/lib/Types/Product.d.ts +71 -58
- package/lib/Types/Product.js +3 -2
- package/lib/Types/Signal.d.ts +55 -63
- package/lib/Types/Signal.js +3 -2
- package/lib/Types/Socket.d.ts +66 -77
- package/lib/Types/Socket.js +3 -3
- package/lib/Types/State.d.ts +19 -17
- package/lib/Types/State.js +14 -13
- package/lib/Types/USync.d.ts +8 -8
- package/lib/Types/USync.js +3 -2
- package/lib/Types/index.d.ts +61 -47
- package/lib/Types/index.js +48 -26
- package/lib/Utils/auth-utils.d.ts +10 -8
- package/lib/Utils/auth-utils.js +154 -206
- package/lib/Utils/baileys-event-stream.d.ts +7 -6
- package/lib/Utils/baileys-event-stream.js +43 -29
- package/lib/Utils/business.d.ts +20 -14
- package/lib/Utils/business.js +134 -110
- package/lib/Utils/chat-utils.d.ts +69 -57
- package/lib/Utils/chat-utils.js +380 -362
- package/lib/Utils/check-npm-version.d.ts +15 -0
- package/lib/Utils/check-npm-version.js +52 -0
- package/lib/Utils/crypto.d.ts +45 -30
- package/lib/Utils/crypto.js +178 -141
- package/lib/Utils/decode-wa-message.d.ts +35 -42
- package/lib/Utils/decode-wa-message.js +150 -176
- package/lib/Utils/event-buffer.d.ts +17 -12
- package/lib/Utils/event-buffer.js +286 -269
- package/lib/Utils/generics.d.ts +99 -60
- package/lib/Utils/generics.js +481 -244
- package/lib/Utils/history.d.ts +22 -18
- package/lib/Utils/history.js +80 -54
- package/lib/Utils/index.d.ts +19 -20
- package/lib/Utils/index.js +41 -19
- package/lib/Utils/link-preview.d.ts +14 -12
- package/lib/Utils/link-preview.js +75 -40
- package/lib/Utils/logger.d.ts +11 -10
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.d.ts +13 -12
- package/lib/Utils/lt-hash.js +37 -27
- package/lib/Utils/make-mutex.d.ts +7 -6
- package/lib/Utils/make-mutex.js +29 -20
- package/lib/Utils/message-retry-manager.d.ts +6 -6
- package/lib/Utils/message-retry-manager.js +36 -8
- package/lib/Utils/messages-media.d.ts +102 -87
- package/lib/Utils/messages-media.js +570 -427
- package/lib/Utils/messages.d.ts +64 -37
- package/lib/Utils/messages.js +1270 -511
- package/lib/Utils/noise-handler.d.ts +18 -18
- package/lib/Utils/noise-handler.js +109 -101
- package/lib/Utils/process-message.d.ts +32 -25
- package/lib/Utils/process-message.js +281 -266
- package/lib/Utils/signal.d.ts +32 -24
- package/lib/Utils/signal.js +105 -98
- package/lib/Utils/use-mongo-file-auth-state.d.ts +6 -0
- package/lib/Utils/use-mongo-file-auth-state.js +84 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +10 -5
- package/lib/Utils/use-multi-file-auth-state.js +186 -69
- package/lib/Utils/use-single-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-single-file-auth-state.js +80 -0
- package/lib/Utils/validate-connection.d.ts +13 -11
- package/lib/Utils/validate-connection.js +116 -124
- package/lib/WABinary/constants.d.ts +27 -25
- package/lib/WABinary/constants.js +1292 -1277
- package/lib/WABinary/decode.d.ts +9 -7
- package/lib/WABinary/decode.js +189 -139
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.js +154 -105
- package/lib/WABinary/generic-utils.d.ts +27 -14
- package/lib/WABinary/generic-utils.js +102 -62
- package/lib/WABinary/index.d.ts +5 -6
- package/lib/WABinary/index.js +25 -6
- package/lib/WABinary/jid-utils.d.ts +46 -41
- package/lib/WABinary/jid-utils.js +80 -84
- package/lib/WABinary/types.d.ts +13 -10
- package/lib/WABinary/types.js +3 -2
- package/lib/WAM/BinaryInfo.d.ts +15 -8
- package/lib/WAM/BinaryInfo.js +14 -7
- package/lib/WAM/constants.d.ts +37 -30
- package/lib/WAM/constants.js +11983 -19465
- package/lib/WAM/encode.d.ts +3 -3
- package/lib/WAM/encode.js +110 -95
- package/lib/WAM/index.d.ts +3 -4
- package/lib/WAM/index.js +23 -4
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +28 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +69 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +19 -12
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -19
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +26 -18
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +20 -12
- package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -11
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +24 -16
- package/lib/WAUSync/Protocols/index.d.ts +6 -5
- package/lib/WAUSync/Protocols/index.js +26 -5
- package/lib/WAUSync/USyncQuery.d.ts +28 -26
- package/lib/WAUSync/USyncQuery.js +62 -64
- package/lib/WAUSync/USyncUser.d.ts +10 -11
- package/lib/WAUSync/USyncUser.js +19 -12
- package/lib/WAUSync/index.d.ts +3 -4
- package/lib/WAUSync/index.js +23 -4
- package/lib/index.d.ts +11 -10
- package/lib/index.js +33 -11
- package/package.json +43 -48
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/fix-imports.js +0 -29
- package/engine-requirements.js +0 -10
- package/lib/Defaults/index.d.ts.map +0 -1
- package/lib/Defaults/index.js.map +0 -1
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -10
- package/lib/Signal/Group/ciphertext-message.d.ts.map +0 -1
- package/lib/Signal/Group/ciphertext-message.js +0 -12
- package/lib/Signal/Group/ciphertext-message.js.map +0 -1
- package/lib/Signal/Group/group-session-builder.d.ts +0 -15
- package/lib/Signal/Group/group-session-builder.d.ts.map +0 -1
- package/lib/Signal/Group/group-session-builder.js +0 -30
- package/lib/Signal/Group/group-session-builder.js.map +0 -1
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/group_cipher.d.ts.map +0 -1
- package/lib/Signal/Group/group_cipher.js +0 -82
- package/lib/Signal/Group/group_cipher.js.map +0 -1
- package/lib/Signal/Group/index.d.ts +0 -12
- package/lib/Signal/Group/index.d.ts.map +0 -1
- package/lib/Signal/Group/index.js +0 -12
- package/lib/Signal/Group/index.js.map +0 -1
- package/lib/Signal/Group/keyhelper.d.ts +0 -11
- package/lib/Signal/Group/keyhelper.d.ts.map +0 -1
- package/lib/Signal/Group/keyhelper.js +0 -18
- package/lib/Signal/Group/keyhelper.js.map +0 -1
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
- package/lib/Signal/Group/sender-chain-key.d.ts.map +0 -1
- package/lib/Signal/Group/sender-chain-key.js +0 -26
- package/lib/Signal/Group/sender-chain-key.js.map +0 -1
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
- package/lib/Signal/Group/sender-key-distribution-message.js.map +0 -1
- package/lib/Signal/Group/sender-key-message.d.ts +0 -19
- package/lib/Signal/Group/sender-key-message.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-message.js +0 -66
- package/lib/Signal/Group/sender-key-message.js.map +0 -1
- package/lib/Signal/Group/sender-key-name.d.ts +0 -18
- package/lib/Signal/Group/sender-key-name.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-name.js +0 -48
- package/lib/Signal/Group/sender-key-name.js.map +0 -1
- package/lib/Signal/Group/sender-key-record.d.ts +0 -31
- package/lib/Signal/Group/sender-key-record.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-record.js +0 -41
- package/lib/Signal/Group/sender-key-record.js.map +0 -1
- package/lib/Signal/Group/sender-key-state.d.ts +0 -39
- package/lib/Signal/Group/sender-key-state.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-state.js +0 -84
- package/lib/Signal/Group/sender-key-state.js.map +0 -1
- package/lib/Signal/Group/sender-message-key.d.ts +0 -12
- package/lib/Signal/Group/sender-message-key.d.ts.map +0 -1
- package/lib/Signal/Group/sender-message-key.js.map +0 -1
- package/lib/Signal/libsignal.d.ts.map +0 -1
- package/lib/Signal/libsignal.js.map +0 -1
- package/lib/Signal/lid-mapping.d.ts +0 -23
- package/lib/Signal/lid-mapping.d.ts.map +0 -1
- package/lib/Signal/lid-mapping.js +0 -171
- package/lib/Signal/lid-mapping.js.map +0 -1
- package/lib/Socket/Client/index.d.ts.map +0 -1
- package/lib/Socket/Client/index.js.map +0 -1
- package/lib/Socket/Client/types.d.ts.map +0 -1
- package/lib/Socket/Client/types.js.map +0 -1
- package/lib/Socket/Client/websocket.d.ts.map +0 -1
- package/lib/Socket/Client/websocket.js.map +0 -1
- package/lib/Socket/business.d.ts.map +0 -1
- package/lib/Socket/business.js.map +0 -1
- package/lib/Socket/chats.d.ts.map +0 -1
- package/lib/Socket/chats.js.map +0 -1
- package/lib/Socket/communities.d.ts.map +0 -1
- package/lib/Socket/communities.js.map +0 -1
- package/lib/Socket/groups.d.ts.map +0 -1
- package/lib/Socket/groups.js.map +0 -1
- package/lib/Socket/index.d.ts.map +0 -1
- package/lib/Socket/index.js.map +0 -1
- package/lib/Socket/messages-recv.d.ts.map +0 -1
- package/lib/Socket/messages-recv.js.map +0 -1
- package/lib/Socket/messages-send.d.ts.map +0 -1
- package/lib/Socket/messages-send.js.map +0 -1
- package/lib/Socket/mex.d.ts.map +0 -1
- package/lib/Socket/mex.js.map +0 -1
- package/lib/Socket/newsletter.d.ts.map +0 -1
- package/lib/Socket/newsletter.js.map +0 -1
- package/lib/Socket/socket.d.ts.map +0 -1
- package/lib/Socket/socket.js.map +0 -1
- package/lib/Types/Auth.d.ts.map +0 -1
- package/lib/Types/Auth.js.map +0 -1
- package/lib/Types/Bussines.d.ts +0 -25
- package/lib/Types/Bussines.d.ts.map +0 -1
- package/lib/Types/Bussines.js +0 -2
- package/lib/Types/Bussines.js.map +0 -1
- package/lib/Types/Call.d.ts.map +0 -1
- package/lib/Types/Call.js.map +0 -1
- package/lib/Types/Chat.d.ts.map +0 -1
- package/lib/Types/Chat.js.map +0 -1
- package/lib/Types/Contact.d.ts.map +0 -1
- package/lib/Types/Contact.js.map +0 -1
- package/lib/Types/Events.d.ts.map +0 -1
- package/lib/Types/Events.js.map +0 -1
- package/lib/Types/GroupMetadata.d.ts.map +0 -1
- package/lib/Types/GroupMetadata.js.map +0 -1
- package/lib/Types/Label.d.ts.map +0 -1
- package/lib/Types/Label.js.map +0 -1
- package/lib/Types/LabelAssociation.d.ts.map +0 -1
- package/lib/Types/LabelAssociation.js.map +0 -1
- package/lib/Types/Message.d.ts.map +0 -1
- package/lib/Types/Message.js.map +0 -1
- package/lib/Types/Newsletter.d.ts.map +0 -1
- package/lib/Types/Newsletter.js.map +0 -1
- package/lib/Types/Product.d.ts.map +0 -1
- package/lib/Types/Product.js.map +0 -1
- package/lib/Types/Signal.d.ts.map +0 -1
- package/lib/Types/Signal.js.map +0 -1
- package/lib/Types/Socket.d.ts.map +0 -1
- package/lib/Types/Socket.js.map +0 -1
- package/lib/Types/State.d.ts.map +0 -1
- package/lib/Types/State.js.map +0 -1
- package/lib/Types/USync.d.ts.map +0 -1
- package/lib/Types/USync.js.map +0 -1
- package/lib/Types/index.d.ts.map +0 -1
- package/lib/Types/index.js.map +0 -1
- package/lib/Utils/auth-utils.d.ts.map +0 -1
- package/lib/Utils/auth-utils.js.map +0 -1
- package/lib/Utils/baileys-event-stream.d.ts.map +0 -1
- package/lib/Utils/baileys-event-stream.js.map +0 -1
- package/lib/Utils/browser-utils.d.ts +0 -4
- package/lib/Utils/browser-utils.d.ts.map +0 -1
- package/lib/Utils/browser-utils.js +0 -28
- package/lib/Utils/browser-utils.js.map +0 -1
- package/lib/Utils/business.d.ts.map +0 -1
- package/lib/Utils/business.js.map +0 -1
- package/lib/Utils/chat-utils.d.ts.map +0 -1
- package/lib/Utils/chat-utils.js.map +0 -1
- package/lib/Utils/crypto.d.ts.map +0 -1
- package/lib/Utils/crypto.js.map +0 -1
- package/lib/Utils/decode-wa-message.d.ts.map +0 -1
- package/lib/Utils/decode-wa-message.js.map +0 -1
- package/lib/Utils/event-buffer.d.ts.map +0 -1
- package/lib/Utils/event-buffer.js.map +0 -1
- package/lib/Utils/generics.d.ts.map +0 -1
- package/lib/Utils/generics.js.map +0 -1
- package/lib/Utils/history.d.ts.map +0 -1
- package/lib/Utils/history.js.map +0 -1
- package/lib/Utils/index.d.ts.map +0 -1
- package/lib/Utils/index.js.map +0 -1
- package/lib/Utils/link-preview.d.ts.map +0 -1
- package/lib/Utils/link-preview.js.map +0 -1
- package/lib/Utils/logger.d.ts.map +0 -1
- package/lib/Utils/logger.js.map +0 -1
- package/lib/Utils/lt-hash.d.ts.map +0 -1
- package/lib/Utils/lt-hash.js.map +0 -1
- package/lib/Utils/make-mutex.d.ts.map +0 -1
- package/lib/Utils/make-mutex.js.map +0 -1
- package/lib/Utils/message-retry-manager.d.ts.map +0 -1
- package/lib/Utils/message-retry-manager.js.map +0 -1
- package/lib/Utils/messages-media.d.ts.map +0 -1
- package/lib/Utils/messages-media.js.map +0 -1
- package/lib/Utils/messages.d.ts.map +0 -1
- package/lib/Utils/messages.js.map +0 -1
- package/lib/Utils/noise-handler.d.ts.map +0 -1
- package/lib/Utils/noise-handler.js.map +0 -1
- package/lib/Utils/pre-key-manager.d.ts +0 -28
- package/lib/Utils/pre-key-manager.d.ts.map +0 -1
- package/lib/Utils/pre-key-manager.js +0 -106
- package/lib/Utils/pre-key-manager.js.map +0 -1
- package/lib/Utils/process-message.d.ts.map +0 -1
- package/lib/Utils/process-message.js.map +0 -1
- package/lib/Utils/signal.d.ts.map +0 -1
- package/lib/Utils/signal.js.map +0 -1
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +0 -1
- package/lib/Utils/use-multi-file-auth-state.js.map +0 -1
- package/lib/Utils/validate-connection.d.ts.map +0 -1
- package/lib/Utils/validate-connection.js.map +0 -1
- package/lib/WABinary/constants.d.ts.map +0 -1
- package/lib/WABinary/constants.js.map +0 -1
- package/lib/WABinary/decode.d.ts.map +0 -1
- package/lib/WABinary/decode.js.map +0 -1
- package/lib/WABinary/encode.d.ts.map +0 -1
- package/lib/WABinary/encode.js.map +0 -1
- package/lib/WABinary/generic-utils.d.ts.map +0 -1
- package/lib/WABinary/generic-utils.js.map +0 -1
- package/lib/WABinary/index.d.ts.map +0 -1
- package/lib/WABinary/index.js.map +0 -1
- package/lib/WABinary/jid-utils.d.ts.map +0 -1
- package/lib/WABinary/jid-utils.js.map +0 -1
- package/lib/WABinary/types.d.ts.map +0 -1
- package/lib/WABinary/types.js.map +0 -1
- package/lib/WAM/BinaryInfo.d.ts.map +0 -1
- package/lib/WAM/BinaryInfo.js.map +0 -1
- package/lib/WAM/constants.d.ts.map +0 -1
- package/lib/WAM/constants.js.map +0 -1
- package/lib/WAM/encode.d.ts.map +0 -1
- package/lib/WAM/encode.js.map +0 -1
- package/lib/WAM/index.d.ts.map +0 -1
- package/lib/WAM/index.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -26
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -51
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -29
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/index.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/index.js.map +0 -1
- package/lib/WAUSync/USyncQuery.d.ts.map +0 -1
- package/lib/WAUSync/USyncQuery.js.map +0 -1
- package/lib/WAUSync/USyncUser.d.ts.map +0 -1
- package/lib/WAUSync/USyncUser.js.map +0 -1
- package/lib/WAUSync/index.d.ts.map +0 -1
- package/lib/WAUSync/index.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
|
@@ -1,93 +1,111 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod }
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
8
|
+
|
|
9
|
+
const node_cache_1 = __importDefault(require("@cacheable/node-cache"))
|
|
10
|
+
const boom_1 = require("@hapi/boom")
|
|
11
|
+
const crypto_1 = require("crypto")
|
|
12
|
+
const WAProto_1 = require("../../WAProto")
|
|
13
|
+
const Defaults_1 = require("../Defaults")
|
|
14
|
+
const Utils_1 = require("../Utils")
|
|
15
|
+
const Types_1 = require("../Types")
|
|
16
|
+
const WABinary_1 = require("../WABinary")
|
|
17
|
+
const WAUSync_1 = require("../WAUSync")
|
|
18
|
+
const newsletter_1 = require("./newsletter")
|
|
19
|
+
const link_preview_1 = require("../Utils/link-preview")
|
|
20
|
+
|
|
21
|
+
const makeMessagesSocket = (config) => {
|
|
22
|
+
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, cachedGroupMetadata, enableRecentMessageCache, maxMsgRetryCount } = config
|
|
23
|
+
const baron = newsletter_1.makeNewsletterSocket(config)
|
|
24
|
+
const { ev, authState, processingMutex, signalRepository, upsertMessage, createCallLink, query, fetchPrivacySettings, sendNode, groupQuery, groupMetadata, groupToggleEphemeral, newsletterWMexQuery, executeUSyncQuery } = baron
|
|
25
|
+
|
|
26
|
+
const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
|
|
27
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
|
|
22
28
|
useClones: false
|
|
23
|
-
})
|
|
29
|
+
})
|
|
30
|
+
|
|
24
31
|
// Initialize message retry manager if enabled
|
|
25
|
-
const messageRetryManager = enableRecentMessageCache ? new MessageRetryManager(logger, maxMsgRetryCount) : null
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
const messageRetryManager = enableRecentMessageCache ? new Utils_1.MessageRetryManager(logger, maxMsgRetryCount) : null
|
|
33
|
+
|
|
34
|
+
let mediaConn
|
|
35
|
+
|
|
29
36
|
const refreshMediaConn = async (forceGet = false) => {
|
|
30
|
-
const media = await mediaConn
|
|
31
|
-
|
|
37
|
+
const media = await mediaConn
|
|
38
|
+
|
|
39
|
+
if (!media || forceGet || (new Date().getTime() - media.fetchDate.getTime()) > media.ttl * 1000) {
|
|
32
40
|
mediaConn = (async () => {
|
|
41
|
+
|
|
33
42
|
const result = await query({
|
|
34
43
|
tag: 'iq',
|
|
35
44
|
attrs: {
|
|
36
45
|
type: 'set',
|
|
37
46
|
xmlns: 'w:m',
|
|
38
|
-
to: S_WHATSAPP_NET
|
|
47
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
39
48
|
},
|
|
40
49
|
content: [{ tag: 'media_conn', attrs: {} }]
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
const mediaConnNode = WABinary_1.getBinaryNodeChild(result, 'media_conn')
|
|
53
|
+
|
|
44
54
|
const node = {
|
|
45
|
-
hosts: getBinaryNodeChildren(mediaConnNode, 'host').map(({ attrs }) => ({
|
|
55
|
+
hosts: WABinary_1.getBinaryNodeChildren(mediaConnNode, 'host').map(({ attrs }) => ({
|
|
46
56
|
hostname: attrs.hostname,
|
|
47
|
-
maxContentLengthBytes: +attrs.maxContentLengthBytes
|
|
57
|
+
maxContentLengthBytes: +attrs.maxContentLengthBytes,
|
|
48
58
|
})),
|
|
49
59
|
auth: mediaConnNode.attrs.auth,
|
|
50
60
|
ttl: +mediaConnNode.attrs.ttl,
|
|
51
61
|
fetchDate: new Date()
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
logger.debug('fetched media conn')
|
|
65
|
+
|
|
66
|
+
return node
|
|
67
|
+
})()
|
|
56
68
|
}
|
|
57
|
-
|
|
58
|
-
|
|
69
|
+
|
|
70
|
+
return mediaConn
|
|
71
|
+
}
|
|
72
|
+
|
|
59
73
|
/**
|
|
60
74
|
* generic send receipt function
|
|
61
75
|
* used for receipts of phone call, read, delivery etc.
|
|
62
76
|
* */
|
|
63
77
|
const sendReceipt = async (jid, participant, messageIds, type) => {
|
|
64
|
-
if (!messageIds || messageIds.length === 0) {
|
|
65
|
-
throw new Boom('missing ids in receipt');
|
|
66
|
-
}
|
|
67
78
|
const node = {
|
|
68
79
|
tag: 'receipt',
|
|
69
80
|
attrs: {
|
|
70
|
-
id: messageIds[0]
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
81
|
+
id: messageIds[0],
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const isReadReceipt = type === 'read' || type === 'read-self'
|
|
86
|
+
|
|
74
87
|
if (isReadReceipt) {
|
|
75
|
-
node.attrs.t = unixTimestampSeconds().toString()
|
|
88
|
+
node.attrs.t = Utils_1.unixTimestampSeconds().toString()
|
|
76
89
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
node.attrs.
|
|
90
|
+
|
|
91
|
+
if (type === 'sender' && WABinary_1.isJidUser(jid)) {
|
|
92
|
+
node.attrs.recipient = jid
|
|
93
|
+
node.attrs.to = participant
|
|
80
94
|
}
|
|
95
|
+
|
|
81
96
|
else {
|
|
82
|
-
node.attrs.to = jid
|
|
97
|
+
node.attrs.to = jid
|
|
83
98
|
if (participant) {
|
|
84
|
-
node.attrs.participant = participant
|
|
99
|
+
node.attrs.participant = participant
|
|
85
100
|
}
|
|
86
101
|
}
|
|
102
|
+
|
|
87
103
|
if (type) {
|
|
88
|
-
node.attrs.type = type
|
|
104
|
+
node.attrs.type = WABinary_1.isJidNewsletter(jid) ? 'read-self' : type
|
|
89
105
|
}
|
|
90
|
-
|
|
106
|
+
|
|
107
|
+
const remainingMessageIds = messageIds.slice(1)
|
|
108
|
+
|
|
91
109
|
if (remainingMessageIds.length) {
|
|
92
110
|
node.content = [
|
|
93
111
|
{
|
|
@@ -98,687 +116,811 @@ export const makeMessagesSocket = (config) => {
|
|
|
98
116
|
attrs: { id }
|
|
99
117
|
}))
|
|
100
118
|
}
|
|
101
|
-
]
|
|
119
|
+
]
|
|
102
120
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
121
|
+
|
|
122
|
+
logger.debug({ attrs: node.attrs, messageIds }, 'sending receipt for messages')
|
|
123
|
+
|
|
124
|
+
await sendNode(node)
|
|
125
|
+
}
|
|
126
|
+
|
|
106
127
|
/** Correctly bulk send receipts to multiple chats, participants */
|
|
107
128
|
const sendReceipts = async (keys, type) => {
|
|
108
|
-
const recps = aggregateMessageKeysNotFromMe(keys)
|
|
129
|
+
const recps = Utils_1.aggregateMessageKeysNotFromMe(keys)
|
|
130
|
+
|
|
109
131
|
for (const { jid, participant, messageIds } of recps) {
|
|
110
|
-
await sendReceipt(jid, participant, messageIds, type)
|
|
132
|
+
await sendReceipt(jid, participant, messageIds, type)
|
|
111
133
|
}
|
|
112
|
-
}
|
|
134
|
+
}
|
|
135
|
+
|
|
113
136
|
/** Bulk read messages. Keys can be from different chats & participants */
|
|
114
137
|
const readMessages = async (keys) => {
|
|
115
|
-
const privacySettings = await fetchPrivacySettings()
|
|
138
|
+
const privacySettings = await fetchPrivacySettings()
|
|
139
|
+
|
|
116
140
|
// based on privacy settings, we have to change the read type
|
|
117
|
-
const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self'
|
|
118
|
-
|
|
119
|
-
|
|
141
|
+
const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self'
|
|
142
|
+
|
|
143
|
+
await sendReceipts(keys, readType)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Fetch image for groups, user, and newsletter **/
|
|
147
|
+
const profilePictureUrl = async (jid) => {
|
|
148
|
+
if (WABinary_1.isJidNewsletter(jid)) {
|
|
149
|
+
|
|
150
|
+
let node = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
151
|
+
input: {
|
|
152
|
+
key: jid,
|
|
153
|
+
type: 'JID',
|
|
154
|
+
view_role: 'GUEST'
|
|
155
|
+
},
|
|
156
|
+
fetch_viewer_metadata: true,
|
|
157
|
+
fetch_full_image: true,
|
|
158
|
+
fetch_creation_time: true
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
let result = WABinary_1.getBinaryNodeChild(node, 'result')?.content?.toString()
|
|
162
|
+
|
|
163
|
+
let metadata = JSON.parse(result).data[Types_1.XWAPaths.NEWSLETTER]
|
|
164
|
+
|
|
165
|
+
return Utils_1.getUrlFromDirectPath(metadata.thread_metadata.picture?.direct_path || '')
|
|
166
|
+
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
else {
|
|
170
|
+
const result = await query({
|
|
171
|
+
tag: 'iq',
|
|
172
|
+
attrs: {
|
|
173
|
+
target: WABinary_1.jidNormalizedUser(jid),
|
|
174
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
175
|
+
type: 'get',
|
|
176
|
+
xmlns: 'w:profile:picture'
|
|
177
|
+
},
|
|
178
|
+
content: [{
|
|
179
|
+
tag: 'picture',
|
|
180
|
+
attrs: {
|
|
181
|
+
type: 'image',
|
|
182
|
+
query: 'url'
|
|
183
|
+
}
|
|
184
|
+
}]
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
const child = WABinary_1.getBinaryNodeChild(result, 'picture')
|
|
188
|
+
|
|
189
|
+
return child?.attrs?.url || null
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
120
193
|
/** Fetch all the devices we've to send a message to */
|
|
121
194
|
const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
|
|
122
|
-
const deviceResults = []
|
|
195
|
+
const deviceResults = []
|
|
196
|
+
|
|
123
197
|
if (!useCache) {
|
|
124
|
-
logger.debug('not using cache for devices')
|
|
125
|
-
}
|
|
126
|
-
const toFetch = [];
|
|
127
|
-
const jidsWithUser = jids
|
|
128
|
-
.map(jid => {
|
|
129
|
-
const decoded = jidDecode(jid);
|
|
130
|
-
const user = decoded?.user;
|
|
131
|
-
const device = decoded?.device;
|
|
132
|
-
const isExplicitDevice = typeof device === 'number' && device >= 0;
|
|
133
|
-
if (isExplicitDevice && user) {
|
|
134
|
-
deviceResults.push({
|
|
135
|
-
user,
|
|
136
|
-
device,
|
|
137
|
-
jid
|
|
138
|
-
});
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
jid = jidNormalizedUser(jid);
|
|
142
|
-
return { jid, user };
|
|
143
|
-
})
|
|
144
|
-
.filter(jid => jid !== null);
|
|
145
|
-
let mgetDevices;
|
|
146
|
-
if (useCache && userDevicesCache.mget) {
|
|
147
|
-
const usersToFetch = jidsWithUser.map(j => j?.user).filter(Boolean);
|
|
148
|
-
mgetDevices = await userDevicesCache.mget(usersToFetch);
|
|
198
|
+
logger.debug('not using cache for devices')
|
|
149
199
|
}
|
|
150
|
-
|
|
200
|
+
|
|
201
|
+
const toFetch = []
|
|
202
|
+
|
|
203
|
+
jids = Array.from(new Set(jids))
|
|
204
|
+
|
|
205
|
+
for (let jid of jids) {
|
|
206
|
+
const user = WABinary_1.jidDecode(jid)?.user
|
|
207
|
+
|
|
208
|
+
jid = WABinary_1.jidNormalizedUser(jid)
|
|
209
|
+
|
|
151
210
|
if (useCache) {
|
|
152
|
-
const devices =
|
|
153
|
-
|
|
211
|
+
const devices = userDevicesCache.get(user)
|
|
212
|
+
|
|
154
213
|
if (devices) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
jid: jidEncode(d.user, d.server, d.device)
|
|
158
|
-
}));
|
|
159
|
-
deviceResults.push(...devicesWithJid);
|
|
160
|
-
logger.trace({ user }, 'using cache for devices');
|
|
214
|
+
deviceResults.push(...devices)
|
|
215
|
+
logger.trace({ user }, 'using cache for devices')
|
|
161
216
|
}
|
|
217
|
+
|
|
162
218
|
else {
|
|
163
|
-
toFetch.push(jid)
|
|
219
|
+
toFetch.push(jid)
|
|
164
220
|
}
|
|
165
221
|
}
|
|
222
|
+
|
|
166
223
|
else {
|
|
167
|
-
toFetch.push(jid)
|
|
224
|
+
toFetch.push(jid)
|
|
168
225
|
}
|
|
169
226
|
}
|
|
227
|
+
|
|
170
228
|
if (!toFetch.length) {
|
|
171
|
-
return deviceResults
|
|
229
|
+
return deviceResults
|
|
172
230
|
}
|
|
173
|
-
|
|
231
|
+
|
|
232
|
+
const query = new WAUSync_1.USyncQuery()
|
|
233
|
+
.withContext('message')
|
|
234
|
+
.withDeviceProtocol()
|
|
235
|
+
|
|
174
236
|
for (const jid of toFetch) {
|
|
175
|
-
|
|
176
|
-
const user = jidDecode(jid)?.user;
|
|
177
|
-
if (user)
|
|
178
|
-
requestedLidUsers.add(user);
|
|
179
|
-
}
|
|
237
|
+
query.withUser(new WAUSync_1.USyncUser().withId(jid))
|
|
180
238
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
const result = await sock.executeUSyncQuery(query);
|
|
239
|
+
|
|
240
|
+
const result = await executeUSyncQuery(query)
|
|
241
|
+
|
|
186
242
|
if (result) {
|
|
187
|
-
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
logger.trace('Storing LID maps from device call');
|
|
191
|
-
await signalRepository.lidMapping.storeLIDPNMappings(lidResults.map(a => ({ lid: a.lid, pn: a.id })));
|
|
192
|
-
}
|
|
193
|
-
const extracted = extractDeviceJids(result?.list, authState.creds.me.id, authState.creds.me.lid, ignoreZeroDevices);
|
|
194
|
-
const deviceMap = {};
|
|
243
|
+
const extracted = Utils_1.extractDeviceJids(result?.list, authState.creds.me.id, ignoreZeroDevices)
|
|
244
|
+
const deviceMap = {}
|
|
245
|
+
|
|
195
246
|
for (const item of extracted) {
|
|
196
|
-
deviceMap[item.user] = deviceMap[item.user] || []
|
|
197
|
-
deviceMap[item.user]
|
|
198
|
-
|
|
199
|
-
// Process each user's devices as a group for bulk LID migration
|
|
200
|
-
for (const [user, userDevices] of Object.entries(deviceMap)) {
|
|
201
|
-
const isLidUser = requestedLidUsers.has(user);
|
|
202
|
-
// Process all devices for this user
|
|
203
|
-
for (const item of userDevices) {
|
|
204
|
-
const finalJid = isLidUser
|
|
205
|
-
? jidEncode(user, item.server, item.device)
|
|
206
|
-
: jidEncode(item.user, item.server, item.device);
|
|
207
|
-
deviceResults.push({
|
|
208
|
-
...item,
|
|
209
|
-
jid: finalJid
|
|
210
|
-
});
|
|
211
|
-
logger.debug({
|
|
212
|
-
user: item.user,
|
|
213
|
-
device: item.device,
|
|
214
|
-
finalJid,
|
|
215
|
-
usedLid: isLidUser
|
|
216
|
-
}, 'Processed device with LID priority');
|
|
217
|
-
}
|
|
247
|
+
deviceMap[item.user] = deviceMap[item.user] || []
|
|
248
|
+
deviceMap[item.user].push(item)
|
|
249
|
+
deviceResults.push(item)
|
|
218
250
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
for (const key in deviceMap) {
|
|
225
|
-
if (deviceMap[key])
|
|
226
|
-
await userDevicesCache.set(key, deviceMap[key]);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
const userDeviceUpdates = {};
|
|
230
|
-
for (const [userId, devices] of Object.entries(deviceMap)) {
|
|
231
|
-
if (devices && devices.length > 0) {
|
|
232
|
-
userDeviceUpdates[userId] = devices.map(d => d.device?.toString() || '0');
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
if (Object.keys(userDeviceUpdates).length > 0) {
|
|
236
|
-
try {
|
|
237
|
-
await authState.keys.set({ 'device-list': userDeviceUpdates });
|
|
238
|
-
logger.debug({ userCount: Object.keys(userDeviceUpdates).length }, 'stored user device lists for bulk migration');
|
|
239
|
-
}
|
|
240
|
-
catch (error) {
|
|
241
|
-
logger.warn({ error }, 'failed to store user device lists');
|
|
242
|
-
}
|
|
251
|
+
|
|
252
|
+
for (const key in deviceMap) {
|
|
253
|
+
userDevicesCache.set(key, deviceMap[key])
|
|
243
254
|
}
|
|
244
255
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
256
|
+
|
|
257
|
+
return deviceResults
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** Assert Sessions */
|
|
261
|
+
const assertSessions = async (jids, force) => {
|
|
262
|
+
let didFetchNewSession = false
|
|
263
|
+
let jidsRequiringFetch = []
|
|
264
|
+
|
|
265
|
+
if (force) {
|
|
266
|
+
jidsRequiringFetch = jids
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
else {
|
|
270
|
+
const addrs = jids.map(jid => (signalRepository.jidToSignalProtocolAddress(jid)))
|
|
271
|
+
|
|
272
|
+
const sessions = await authState.keys.get('session', addrs)
|
|
273
|
+
|
|
274
|
+
for (const jid of jids) {
|
|
275
|
+
const signalId = signalRepository
|
|
276
|
+
.jidToSignalProtocolAddress(jid)
|
|
277
|
+
|
|
278
|
+
if (!sessions[signalId]) {
|
|
279
|
+
jidsRequiringFetch.push(jid)
|
|
267
280
|
}
|
|
268
281
|
}
|
|
269
|
-
jidsRequiringFetch.push(jid);
|
|
270
282
|
}
|
|
283
|
+
|
|
271
284
|
if (jidsRequiringFetch.length) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
...jidsRequiringFetch.filter(jid => !!isLidUser(jid) || !!isHostedLidUser(jid)),
|
|
275
|
-
...((await signalRepository.lidMapping.getLIDsForPNs(jidsRequiringFetch.filter(jid => !!isPnUser(jid) || !!isHostedPnUser(jid)))) || []).map(a => a.lid)
|
|
276
|
-
];
|
|
277
|
-
logger.debug({ jidsRequiringFetch, wireJids }, 'fetching sessions');
|
|
285
|
+
logger.debug({ jidsRequiringFetch }, 'fetching sessions')
|
|
286
|
+
|
|
278
287
|
const result = await query({
|
|
279
288
|
tag: 'iq',
|
|
280
289
|
attrs: {
|
|
281
290
|
xmlns: 'encrypt',
|
|
282
291
|
type: 'get',
|
|
283
|
-
to: S_WHATSAPP_NET
|
|
292
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
284
293
|
},
|
|
285
294
|
content: [
|
|
286
295
|
{
|
|
287
296
|
tag: 'key',
|
|
288
297
|
attrs: {},
|
|
289
|
-
content:
|
|
298
|
+
content: jidsRequiringFetch.map(jid => ({
|
|
290
299
|
tag: 'user',
|
|
291
|
-
attrs: { jid }
|
|
300
|
+
attrs: { jid },
|
|
292
301
|
}))
|
|
293
302
|
}
|
|
294
303
|
]
|
|
295
|
-
})
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
const signalId = signalRepository.jidToSignalProtocolAddress(wireJid);
|
|
301
|
-
peerSessionsCache.set(signalId, true);
|
|
302
|
-
}
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
await Utils_1.parseAndInjectE2ESessions(result, signalRepository)
|
|
307
|
+
|
|
308
|
+
didFetchNewSession = true
|
|
303
309
|
}
|
|
304
|
-
|
|
305
|
-
|
|
310
|
+
|
|
311
|
+
return didFetchNewSession
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** Send Peer Operation */
|
|
306
315
|
const sendPeerDataOperationMessage = async (pdoMessage) => {
|
|
307
316
|
//TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
|
|
308
317
|
if (!authState.creds.me?.id) {
|
|
309
|
-
throw new Boom('Not authenticated')
|
|
318
|
+
throw new boom_1.Boom('Not authenticated')
|
|
310
319
|
}
|
|
320
|
+
|
|
311
321
|
const protocolMessage = {
|
|
312
322
|
protocolMessage: {
|
|
313
323
|
peerDataOperationRequestMessage: pdoMessage,
|
|
314
|
-
type: proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
|
|
324
|
+
type: WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
|
|
315
325
|
}
|
|
316
|
-
}
|
|
317
|
-
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const meJid = WABinary_1.jidNormalizedUser(authState.creds.me.id)
|
|
329
|
+
|
|
318
330
|
const msgId = await relayMessage(meJid, protocolMessage, {
|
|
319
331
|
additionalAttributes: {
|
|
320
332
|
category: 'peer',
|
|
321
|
-
|
|
333
|
+
// eslint-disable-next-line camelcase
|
|
334
|
+
push_priority: 'high_force',
|
|
322
335
|
},
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
: recipientJids.map(jid => ({ recipientJid: jid, message: patched }));
|
|
340
|
-
let shouldIncludeDeviceIdentity = false;
|
|
341
|
-
const meId = authState.creds.me.id;
|
|
342
|
-
const meLid = authState.creds.me?.lid;
|
|
343
|
-
const meLidUser = meLid ? jidDecode(meLid)?.user : null;
|
|
344
|
-
const encryptionPromises = patchedMessages.map(async ({ recipientJid: jid, message: patchedMessage }) => {
|
|
345
|
-
if (!jid)
|
|
346
|
-
return null;
|
|
347
|
-
let msgToEncrypt = patchedMessage;
|
|
348
|
-
if (dsmMessage) {
|
|
349
|
-
const { user: targetUser } = jidDecode(jid);
|
|
350
|
-
const { user: ownPnUser } = jidDecode(meId);
|
|
351
|
-
const ownLidUser = meLidUser;
|
|
352
|
-
const isOwnUser = targetUser === ownPnUser || (ownLidUser && targetUser === ownLidUser);
|
|
353
|
-
const isExactSenderDevice = jid === meId || (meLid && jid === meLid);
|
|
354
|
-
if (isOwnUser && !isExactSenderDevice) {
|
|
355
|
-
msgToEncrypt = dsmMessage;
|
|
356
|
-
logger.debug({ jid, targetUser }, 'Using DSM for own device');
|
|
357
|
-
}
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
return msgId
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const createParticipantNodes = async (jids, message, extraAttrs) => {
|
|
342
|
+
const patched = await patchMessageBeforeSending(message, jids)
|
|
343
|
+
const bytes = Utils_1.encodeWAMessage(patched)
|
|
344
|
+
|
|
345
|
+
let shouldIncludeDeviceIdentity = false
|
|
346
|
+
|
|
347
|
+
const nodes = await Promise.all(jids.map(async (jid) => {
|
|
348
|
+
const { type, ciphertext } = await signalRepository.encryptMessage({ jid, data: bytes })
|
|
349
|
+
|
|
350
|
+
if (type === 'pkmsg') {
|
|
351
|
+
shouldIncludeDeviceIdentity = true
|
|
358
352
|
}
|
|
359
|
-
|
|
360
|
-
const
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
const
|
|
392
|
-
const
|
|
393
|
-
const
|
|
394
|
-
|
|
395
|
-
const
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
const
|
|
406
|
-
|
|
407
|
-
const binaryNodeContent = [];
|
|
408
|
-
const devices = [];
|
|
353
|
+
|
|
354
|
+
const node = {
|
|
355
|
+
tag: 'to',
|
|
356
|
+
attrs: { jid },
|
|
357
|
+
content: [{
|
|
358
|
+
tag: 'enc',
|
|
359
|
+
attrs: {
|
|
360
|
+
v: '2',
|
|
361
|
+
type,
|
|
362
|
+
...extraAttrs || {}
|
|
363
|
+
},
|
|
364
|
+
content: ciphertext
|
|
365
|
+
}]
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
return node
|
|
369
|
+
}))
|
|
370
|
+
|
|
371
|
+
return {
|
|
372
|
+
nodes,
|
|
373
|
+
shouldIncludeDeviceIdentity
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, useCachedGroupMetadata, statusJidList, additionalNodes, AI = true }) => {
|
|
378
|
+
const meId = authState.creds.me.id
|
|
379
|
+
|
|
380
|
+
let didPushAdditional = false
|
|
381
|
+
let shouldIncludeDeviceIdentity = false
|
|
382
|
+
|
|
383
|
+
const { user, server } = WABinary_1.jidDecode(jid)
|
|
384
|
+
|
|
385
|
+
const statusJid = 'status@broadcast'
|
|
386
|
+
const isGroup = server === 'g.us'
|
|
387
|
+
const isPrivate = server === 's.whatsapp.net'
|
|
388
|
+
const isNewsletter = server == 'newsletter'
|
|
389
|
+
const isStatus = jid === statusJid
|
|
390
|
+
const isLid = server === 'lid'
|
|
391
|
+
|
|
392
|
+
msgId = msgId || Utils_1.generateMessageID(authState.creds.me.id)
|
|
393
|
+
useUserDevicesCache = useUserDevicesCache !== false
|
|
394
|
+
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus
|
|
395
|
+
|
|
396
|
+
const participants = []
|
|
397
|
+
const destinationJid = (!isStatus) ? WABinary_1.jidEncode(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid
|
|
398
|
+
const binaryNodeContent = []
|
|
399
|
+
const devices = []
|
|
400
|
+
|
|
409
401
|
const meMsg = {
|
|
410
402
|
deviceSentMessage: {
|
|
411
403
|
destinationJid,
|
|
412
404
|
message
|
|
413
|
-
},
|
|
414
|
-
messageContextInfo: message.messageContextInfo
|
|
415
|
-
}
|
|
416
|
-
|
|
405
|
+
},
|
|
406
|
+
messageContextInfo: message.messageContextInfo || {}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const extraAttrs = {}
|
|
410
|
+
|
|
411
|
+
const regexGroupOld = /^(\d{1,15})-(\d+)@g\.us$/
|
|
412
|
+
|
|
413
|
+
const messages = Utils_1.normalizeMessageContent(message)
|
|
414
|
+
|
|
415
|
+
const buttonType = getButtonType(messages)
|
|
416
|
+
const pollMessage = messages.pollCreationMessage || messages.pollCreationMessageV2 || messages.pollCreationMessageV3
|
|
417
|
+
|
|
418
|
+
|
|
417
419
|
if (participant) {
|
|
420
|
+
// when the retry request is not for a group
|
|
421
|
+
// only send to the specific device that asked for a retry
|
|
422
|
+
// otherwise the message is sent out to every device that should be a recipient
|
|
418
423
|
if (!isGroup && !isStatus) {
|
|
419
|
-
additionalAttributes = { ...additionalAttributes, device_fanout: 'false' }
|
|
424
|
+
additionalAttributes = { ...additionalAttributes, 'device_fanout': 'false' }
|
|
420
425
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
jid: participant.jid
|
|
426
|
-
});
|
|
426
|
+
|
|
427
|
+
const { user, device } = WABinary_1.jidDecode(participant.jid)
|
|
428
|
+
|
|
429
|
+
devices.push({ user, device })
|
|
427
430
|
}
|
|
431
|
+
|
|
428
432
|
await authState.keys.transaction(async () => {
|
|
429
|
-
const mediaType = getMediaType(message)
|
|
433
|
+
const mediaType = getMediaType(message)
|
|
434
|
+
|
|
430
435
|
if (mediaType) {
|
|
431
|
-
extraAttrs['mediatype'] = mediaType
|
|
436
|
+
extraAttrs['mediatype'] = mediaType
|
|
432
437
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
});
|
|
441
|
-
const stanza = {
|
|
442
|
-
tag: 'message',
|
|
443
|
-
attrs: {
|
|
444
|
-
to: jid,
|
|
445
|
-
id: msgId,
|
|
446
|
-
type: getMessageType(message),
|
|
447
|
-
...(additionalAttributes || {})
|
|
448
|
-
},
|
|
449
|
-
content: binaryNodeContent
|
|
450
|
-
};
|
|
451
|
-
logger.debug({ msgId }, `sending newsletter message to ${jid}`);
|
|
452
|
-
await sendNode(stanza);
|
|
453
|
-
return;
|
|
454
|
-
}
|
|
455
|
-
if (normalizeMessageContent(message)?.pinInChatMessage) {
|
|
456
|
-
extraAttrs['decrypt-fail'] = 'hide'; // todo: expand for reactions and other types
|
|
438
|
+
|
|
439
|
+
if (messages.pinInChatMessage || messages.keepInChatMessage || message.reactionMessage || message.protocolMessage?.editedMessage) {
|
|
440
|
+
extraAttrs['decrypt-fail'] = 'hide'
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (messages.interactiveResponseMessage?.nativeFlowResponseMessage) {
|
|
444
|
+
extraAttrs['native_flow_name'] = messages.interactiveResponseMessage.nativeFlowResponseMessage?.name || 'menu_options'
|
|
457
445
|
}
|
|
446
|
+
|
|
458
447
|
if (isGroup || isStatus) {
|
|
459
448
|
const [groupData, senderKeyMap] = await Promise.all([
|
|
460
449
|
(async () => {
|
|
461
|
-
let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined
|
|
450
|
+
let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined
|
|
451
|
+
|
|
462
452
|
if (groupData && Array.isArray(groupData?.participants)) {
|
|
463
|
-
logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata')
|
|
453
|
+
logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata')
|
|
464
454
|
}
|
|
455
|
+
|
|
465
456
|
else if (!isStatus) {
|
|
466
|
-
groupData = await groupMetadata(jid)
|
|
457
|
+
groupData = await groupMetadata(jid)
|
|
467
458
|
}
|
|
468
|
-
|
|
459
|
+
|
|
460
|
+
return groupData
|
|
469
461
|
})(),
|
|
462
|
+
|
|
470
463
|
(async () => {
|
|
471
464
|
if (!participant && !isStatus) {
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
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?
|
|
475
|
-
return result[jid] || {};
|
|
465
|
+
const result = await authState.keys.get('sender-key-memory', [jid])
|
|
466
|
+
return result[jid] || {}
|
|
476
467
|
}
|
|
477
|
-
|
|
468
|
+
|
|
469
|
+
return {}
|
|
470
|
+
|
|
478
471
|
})()
|
|
479
|
-
])
|
|
472
|
+
])
|
|
473
|
+
|
|
480
474
|
if (!participant) {
|
|
481
|
-
const participantsList = []
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
475
|
+
const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : []
|
|
476
|
+
|
|
477
|
+
if (isStatus && statusJidList) {
|
|
478
|
+
participantsList.push(...statusJidList)
|
|
485
479
|
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
groupAddressingMode = groupData?.addressingMode || groupAddressingMode;
|
|
480
|
+
|
|
481
|
+
if (!isStatus) {
|
|
482
|
+
additionalAttributes = {
|
|
483
|
+
...additionalAttributes,
|
|
484
|
+
addressing_mode: groupData.addressingMode
|
|
492
485
|
}
|
|
493
|
-
// default to lid addressing mode in a group
|
|
494
|
-
additionalAttributes = {
|
|
495
|
-
...additionalAttributes,
|
|
496
|
-
addressing_mode: groupAddressingMode
|
|
497
|
-
};
|
|
498
486
|
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
if (groupData?.ephemeralDuration && groupData.ephemeralDuration > 0) {
|
|
503
|
-
additionalAttributes = {
|
|
504
|
-
...additionalAttributes,
|
|
505
|
-
expiration: groupData.ephemeralDuration.toString()
|
|
506
|
-
};
|
|
507
|
-
}
|
|
508
|
-
const patched = await patchMessageBeforeSending(message);
|
|
509
|
-
if (Array.isArray(patched)) {
|
|
510
|
-
throw new Boom('Per-jid patching is not supported in groups');
|
|
487
|
+
|
|
488
|
+
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false)
|
|
489
|
+
devices.push(...additionalDevices)
|
|
511
490
|
}
|
|
512
|
-
|
|
513
|
-
const
|
|
514
|
-
const
|
|
491
|
+
|
|
492
|
+
const patched = await patchMessageBeforeSending(message, devices.map(d => WABinary_1.jidEncode(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device)))
|
|
493
|
+
const bytes = Utils_1.encodeWAMessage(patched)
|
|
494
|
+
|
|
515
495
|
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
|
|
516
496
|
group: destinationJid,
|
|
517
497
|
data: bytes,
|
|
518
|
-
meId
|
|
519
|
-
})
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
//
|
|
529
|
-
|
|
530
|
-
senderKeyRecipients.push(deviceJid);
|
|
531
|
-
senderKeyMap[deviceJid] = true;
|
|
498
|
+
meId,
|
|
499
|
+
})
|
|
500
|
+
|
|
501
|
+
const senderKeyJids = []
|
|
502
|
+
|
|
503
|
+
// ensure a connection is established with every device
|
|
504
|
+
for (const { user, device } of devices) {
|
|
505
|
+
const jid = WABinary_1.jidEncode(user, 's.whatsapp.net', device)
|
|
506
|
+
if (!senderKeyMap[jid] || !!participant) {
|
|
507
|
+
senderKeyJids.push(jid)
|
|
508
|
+
// store that this person has had the sender keys sent to them
|
|
509
|
+
senderKeyMap[jid] = true
|
|
532
510
|
}
|
|
533
511
|
}
|
|
534
|
-
|
|
535
|
-
|
|
512
|
+
|
|
513
|
+
// if there are some participants with whom the session has not been established
|
|
514
|
+
// if there are, we re-send the senderkey
|
|
515
|
+
if (senderKeyJids.length) {
|
|
516
|
+
logger.debug({ senderKeyJids }, 'sending new sender key')
|
|
536
517
|
const senderKeyMsg = {
|
|
537
518
|
senderKeyDistributionMessage: {
|
|
538
519
|
axolotlSenderKeyDistributionMessage: senderKeyDistributionMessage,
|
|
539
520
|
groupId: destinationJid
|
|
540
521
|
}
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
await assertSessions(
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
await assertSessions(senderKeyJids, false)
|
|
525
|
+
|
|
526
|
+
const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, extraAttrs)
|
|
527
|
+
|
|
528
|
+
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity
|
|
529
|
+
|
|
530
|
+
participants.push(...result.nodes)
|
|
547
531
|
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
532
|
+
|
|
533
|
+
binaryNodeContent.push({
|
|
534
|
+
tag: 'enc',
|
|
535
|
+
attrs: { v: '2', type: 'skmsg', ...extraAttrs },
|
|
536
|
+
content: ciphertext
|
|
537
|
+
})
|
|
538
|
+
|
|
539
|
+
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } })
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
else if (isNewsletter) {
|
|
543
|
+
// Message edit
|
|
544
|
+
if (message.protocolMessage?.editedMessage) {
|
|
545
|
+
msgId = message.protocolMessage.key?.id
|
|
546
|
+
message = message.protocolMessage.editedMessage
|
|
562
547
|
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
});
|
|
569
|
-
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
|
|
548
|
+
|
|
549
|
+
// Message delete
|
|
550
|
+
if (message.protocolMessage?.type === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
|
|
551
|
+
msgId = message.protocolMessage.key?.id
|
|
552
|
+
message = {}
|
|
570
553
|
}
|
|
554
|
+
|
|
555
|
+
const patched = await patchMessageBeforeSending(message, [])
|
|
556
|
+
const bytes = Utils_1.encodeNewsletterMessage(patched)
|
|
557
|
+
|
|
558
|
+
binaryNodeContent.push({
|
|
559
|
+
tag: 'plaintext',
|
|
560
|
+
attrs: extraAttrs ? extraAttrs : {},
|
|
561
|
+
content: bytes
|
|
562
|
+
})
|
|
571
563
|
}
|
|
564
|
+
|
|
572
565
|
else {
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
let ownId = meId;
|
|
576
|
-
if (isLid && meLid) {
|
|
577
|
-
ownId = meLid;
|
|
578
|
-
logger.debug({ to: jid, ownId }, 'Using LID identity for @lid conversation');
|
|
579
|
-
}
|
|
580
|
-
else {
|
|
581
|
-
logger.debug({ to: jid, ownId }, 'Using PN identity for @s.whatsapp.net conversation');
|
|
582
|
-
}
|
|
583
|
-
const { user: ownUser } = jidDecode(ownId);
|
|
566
|
+
const { user: meUser } = WABinary_1.jidDecode(meId)
|
|
567
|
+
|
|
584
568
|
if (!participant) {
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
user
|
|
588
|
-
device: 0,
|
|
589
|
-
jid: jidEncode(user, targetUserServer, 0) // rajeh, todo: this entire logic is convoluted and weird.
|
|
590
|
-
});
|
|
591
|
-
if (user !== ownUser) {
|
|
592
|
-
const ownUserServer = isLid ? 'lid' : 's.whatsapp.net';
|
|
593
|
-
const ownUserForAddressing = isLid && meLid ? jidDecode(meLid).user : jidDecode(meId).user;
|
|
594
|
-
devices.push({
|
|
595
|
-
user: ownUserForAddressing,
|
|
596
|
-
device: 0,
|
|
597
|
-
jid: jidEncode(ownUserForAddressing, ownUserServer, 0)
|
|
598
|
-
});
|
|
569
|
+
devices.push({ user })
|
|
570
|
+
if (user !== meUser) {
|
|
571
|
+
devices.push({ user: meUser })
|
|
599
572
|
}
|
|
573
|
+
|
|
600
574
|
if (additionalAttributes?.['category'] !== 'peer') {
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
const senderIdentity = isLid && meLid
|
|
605
|
-
? jidEncode(jidDecode(meLid)?.user, 'lid', undefined)
|
|
606
|
-
: jidEncode(jidDecode(meId)?.user, 's.whatsapp.net', undefined);
|
|
607
|
-
// Enumerate devices for sender and target with consistent addressing
|
|
608
|
-
const sessionDevices = await getUSyncDevices([senderIdentity, jid], true, false);
|
|
609
|
-
devices.push(...sessionDevices);
|
|
610
|
-
logger.debug({
|
|
611
|
-
deviceCount: devices.length,
|
|
612
|
-
devices: devices.map(d => `${d.user}:${d.device}@${jidDecode(d.jid)?.server}`)
|
|
613
|
-
}, 'Device enumeration complete with unified addressing');
|
|
575
|
+
const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true)
|
|
576
|
+
|
|
577
|
+
devices.push(...additionalDevices)
|
|
614
578
|
}
|
|
615
579
|
}
|
|
616
|
-
|
|
617
|
-
const
|
|
618
|
-
const
|
|
619
|
-
const
|
|
620
|
-
|
|
621
|
-
for (const { user,
|
|
622
|
-
const
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
continue;
|
|
626
|
-
}
|
|
627
|
-
// Check if this is our device (could match either PN or LID user)
|
|
628
|
-
const isMe = user === mePnUser || user === meLidUser;
|
|
580
|
+
|
|
581
|
+
const allJids = []
|
|
582
|
+
const meJids = []
|
|
583
|
+
const otherJids = []
|
|
584
|
+
|
|
585
|
+
for (const { user, device } of devices) {
|
|
586
|
+
const isMe = user === meUser
|
|
587
|
+
const jid = WABinary_1.jidEncode(isMe && isLid ? authState.creds?.me?.lid?.split(':')[0] || user : user, isLid ? 'lid' : 's.whatsapp.net', device)
|
|
588
|
+
|
|
629
589
|
if (isMe) {
|
|
630
|
-
|
|
590
|
+
meJids.push(jid)
|
|
631
591
|
}
|
|
592
|
+
|
|
632
593
|
else {
|
|
633
|
-
|
|
594
|
+
otherJids.push(jid)
|
|
634
595
|
}
|
|
635
|
-
|
|
596
|
+
|
|
597
|
+
allJids.push(jid)
|
|
636
598
|
}
|
|
637
|
-
|
|
599
|
+
|
|
600
|
+
await assertSessions(allJids, false)
|
|
601
|
+
|
|
638
602
|
const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
|
|
639
|
-
|
|
640
|
-
createParticipantNodes(
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
participants.push(...meNodes)
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
|
|
603
|
+
createParticipantNodes(meJids, meMsg, extraAttrs),
|
|
604
|
+
createParticipantNodes(otherJids, message, extraAttrs)
|
|
605
|
+
])
|
|
606
|
+
|
|
607
|
+
participants.push(...meNodes)
|
|
608
|
+
|
|
609
|
+
participants.push(...otherNodes)
|
|
610
|
+
|
|
611
|
+
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2
|
|
649
612
|
}
|
|
613
|
+
|
|
650
614
|
if (participants.length) {
|
|
651
615
|
if (additionalAttributes?.['category'] === 'peer') {
|
|
652
|
-
const peerNode = participants[0]?.content?.[0]
|
|
616
|
+
const peerNode = participants[0]?.content?.[0]
|
|
617
|
+
|
|
653
618
|
if (peerNode) {
|
|
654
|
-
binaryNodeContent.push(peerNode)
|
|
619
|
+
binaryNodeContent.push(peerNode) // push only enc
|
|
655
620
|
}
|
|
656
621
|
}
|
|
622
|
+
|
|
657
623
|
else {
|
|
658
624
|
binaryNodeContent.push({
|
|
659
625
|
tag: 'participants',
|
|
660
626
|
attrs: {},
|
|
661
627
|
content: participants
|
|
662
|
-
})
|
|
628
|
+
})
|
|
663
629
|
}
|
|
664
630
|
}
|
|
631
|
+
|
|
665
632
|
const stanza = {
|
|
666
633
|
tag: 'message',
|
|
667
634
|
attrs: {
|
|
668
635
|
id: msgId,
|
|
669
|
-
|
|
670
|
-
type: getMessageType(message),
|
|
636
|
+
type: getTypeMessage(message),
|
|
671
637
|
...(additionalAttributes || {})
|
|
672
638
|
},
|
|
673
639
|
content: binaryNodeContent
|
|
674
|
-
}
|
|
640
|
+
}
|
|
641
|
+
|
|
675
642
|
// if the participant to send to is explicitly specified (generally retry recp)
|
|
676
643
|
// ensure the message is only sent to that person
|
|
677
644
|
// if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
|
|
678
645
|
if (participant) {
|
|
679
|
-
if (isJidGroup(destinationJid)) {
|
|
680
|
-
stanza.attrs.to = destinationJid
|
|
681
|
-
stanza.attrs.participant = participant.jid
|
|
646
|
+
if (WABinary_1.isJidGroup(destinationJid)) {
|
|
647
|
+
stanza.attrs.to = destinationJid
|
|
648
|
+
stanza.attrs.participant = participant.jid
|
|
682
649
|
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
stanza.attrs.
|
|
650
|
+
|
|
651
|
+
else if (WABinary_1.areJidsSameUser(participant.jid, meId)) {
|
|
652
|
+
stanza.attrs.to = participant.jid
|
|
653
|
+
stanza.attrs.recipient = destinationJid
|
|
686
654
|
}
|
|
655
|
+
|
|
687
656
|
else {
|
|
688
|
-
stanza.attrs.to = participant.jid
|
|
657
|
+
stanza.attrs.to = participant.jid
|
|
689
658
|
}
|
|
690
659
|
}
|
|
660
|
+
|
|
691
661
|
else {
|
|
692
|
-
stanza.attrs.to = destinationJid
|
|
662
|
+
stanza.attrs.to = destinationJid
|
|
693
663
|
}
|
|
664
|
+
|
|
694
665
|
if (shouldIncludeDeviceIdentity) {
|
|
695
|
-
;
|
|
696
666
|
stanza.content.push({
|
|
697
667
|
tag: 'device-identity',
|
|
698
668
|
attrs: {},
|
|
699
|
-
content: encodeSignedDeviceIdentity(authState.creds.account, true)
|
|
700
|
-
})
|
|
701
|
-
|
|
669
|
+
content: Utils_1.encodeSignedDeviceIdentity(authState.creds.account, true)
|
|
670
|
+
})
|
|
671
|
+
|
|
672
|
+
logger.debug({ jid }, 'adding device identity')
|
|
702
673
|
}
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
stanza.content.push(
|
|
674
|
+
|
|
675
|
+
if (isGroup && regexGroupOld.test(jid) && !message.reactionMessage) {
|
|
676
|
+
stanza.content.push({
|
|
677
|
+
tag: 'multicast',
|
|
678
|
+
attrs: {}
|
|
679
|
+
})
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
if (pollMessage || messages.eventMessage) {
|
|
683
|
+
stanza.content.push({
|
|
684
|
+
tag: 'meta',
|
|
685
|
+
attrs: messages.eventMessage ? {
|
|
686
|
+
event_type: 'creation'
|
|
687
|
+
} : isNewsletter ? {
|
|
688
|
+
polltype: 'creation',
|
|
689
|
+
contenttype: pollMessage?.pollContentType === 2 ? 'image' : 'text'
|
|
690
|
+
} : {
|
|
691
|
+
polltype: 'creation'
|
|
692
|
+
}
|
|
693
|
+
})
|
|
706
694
|
}
|
|
707
|
-
|
|
708
|
-
|
|
695
|
+
|
|
696
|
+
if (!isNewsletter && buttonType) {
|
|
697
|
+
const buttonsNode = getButtonArgs(messages)
|
|
698
|
+
const filteredButtons = WABinary_1.getBinaryFilteredButtons(additionalNodes ? additionalNodes : [])
|
|
699
|
+
|
|
700
|
+
if (filteredButtons) {
|
|
701
|
+
stanza.content.push(...additionalNodes)
|
|
702
|
+
didPushAdditional = true
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
else {
|
|
706
|
+
stanza.content.push(buttonsNode)
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
if (AI && isPrivate) {
|
|
711
|
+
const botNode = {
|
|
712
|
+
tag: 'bot',
|
|
713
|
+
attrs: {
|
|
714
|
+
biz_bot: '1'
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
const filteredBizBot = WABinary_1.getBinaryFilteredBizBot(additionalNodes ? additionalNodes : [])
|
|
719
|
+
|
|
720
|
+
if (filteredBizBot) {
|
|
721
|
+
stanza.content.push(...additionalNodes)
|
|
722
|
+
didPushAdditional = true
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
else {
|
|
726
|
+
stanza.content.push(botNode)
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
if (!didPushAdditional && additionalNodes && additionalNodes.length > 0) {
|
|
731
|
+
stanza.content.push(...additionalNodes)
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
logger.debug({ msgId }, `sending message to ${participants.length} devices`)
|
|
735
|
+
|
|
736
|
+
await sendNode(stanza)
|
|
737
|
+
|
|
709
738
|
// Add message to retry cache if enabled
|
|
710
739
|
if (messageRetryManager && !participant) {
|
|
711
|
-
messageRetryManager.addRecentMessage(destinationJid, msgId, message)
|
|
740
|
+
messageRetryManager.addRecentMessage(destinationJid, msgId, message)
|
|
712
741
|
}
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
742
|
+
})
|
|
743
|
+
|
|
744
|
+
return msgId
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
const getTypeMessage = (msg) => {
|
|
748
|
+
const message = Utils_1.normalizeMessageContent(msg)
|
|
717
749
|
if (message.pollCreationMessage || message.pollCreationMessageV2 || message.pollCreationMessageV3) {
|
|
718
|
-
return 'poll'
|
|
719
|
-
}
|
|
720
|
-
if (message.
|
|
721
|
-
return '
|
|
722
|
-
}
|
|
723
|
-
if (
|
|
724
|
-
return '
|
|
750
|
+
return 'poll'
|
|
751
|
+
}
|
|
752
|
+
else if (message.reactionMessage) {
|
|
753
|
+
return 'reaction'
|
|
754
|
+
}
|
|
755
|
+
else if (message.eventMessage) {
|
|
756
|
+
return 'event'
|
|
757
|
+
}
|
|
758
|
+
else if (getMediaType(message)) {
|
|
759
|
+
return 'media'
|
|
760
|
+
}
|
|
761
|
+
else {
|
|
762
|
+
return 'text'
|
|
725
763
|
}
|
|
726
|
-
|
|
727
|
-
|
|
764
|
+
}
|
|
765
|
+
|
|
728
766
|
const getMediaType = (message) => {
|
|
729
767
|
if (message.imageMessage) {
|
|
730
|
-
return 'image'
|
|
768
|
+
return 'image'
|
|
769
|
+
}
|
|
770
|
+
else if (message.stickerMessage) {
|
|
771
|
+
return message.stickerMessage.isLottie ? '1p_sticker' : message.stickerMessage.isAvatar ? 'avatar_sticker' : 'sticker'
|
|
731
772
|
}
|
|
732
773
|
else if (message.videoMessage) {
|
|
733
|
-
return message.videoMessage.gifPlayback ? 'gif' : 'video'
|
|
774
|
+
return message.videoMessage.gifPlayback ? 'gif' : 'video'
|
|
734
775
|
}
|
|
735
776
|
else if (message.audioMessage) {
|
|
736
|
-
return message.audioMessage.ptt ? 'ptt' : 'audio'
|
|
777
|
+
return message.audioMessage.ptt ? 'ptt' : 'audio'
|
|
778
|
+
}
|
|
779
|
+
else if (message.ptvMessage) {
|
|
780
|
+
return 'ptv'
|
|
737
781
|
}
|
|
738
782
|
else if (message.contactMessage) {
|
|
739
|
-
return 'vcard'
|
|
783
|
+
return 'vcard'
|
|
740
784
|
}
|
|
741
785
|
else if (message.documentMessage) {
|
|
742
|
-
return 'document'
|
|
786
|
+
return 'document'
|
|
787
|
+
}
|
|
788
|
+
else if (message.stickerPackMessage) {
|
|
789
|
+
return 'sticker_pack'
|
|
743
790
|
}
|
|
744
791
|
else if (message.contactsArrayMessage) {
|
|
745
|
-
return 'contact_array'
|
|
792
|
+
return 'contact_array'
|
|
746
793
|
}
|
|
747
|
-
else if (message.
|
|
748
|
-
return '
|
|
794
|
+
else if (message.locationMessage) {
|
|
795
|
+
return 'location'
|
|
749
796
|
}
|
|
750
|
-
else if (message.
|
|
751
|
-
return '
|
|
797
|
+
else if (message.liveLocationMessage) {
|
|
798
|
+
return 'livelocation'
|
|
752
799
|
}
|
|
753
800
|
else if (message.listMessage) {
|
|
754
|
-
return 'list'
|
|
801
|
+
return 'list'
|
|
755
802
|
}
|
|
756
803
|
else if (message.listResponseMessage) {
|
|
757
|
-
return 'list_response'
|
|
804
|
+
return 'list_response'
|
|
758
805
|
}
|
|
759
806
|
else if (message.buttonsResponseMessage) {
|
|
760
|
-
return 'buttons_response'
|
|
807
|
+
return 'buttons_response'
|
|
761
808
|
}
|
|
762
809
|
else if (message.orderMessage) {
|
|
763
|
-
return 'order'
|
|
810
|
+
return 'order'
|
|
764
811
|
}
|
|
765
812
|
else if (message.productMessage) {
|
|
766
|
-
return 'product'
|
|
813
|
+
return 'product'
|
|
767
814
|
}
|
|
768
815
|
else if (message.interactiveResponseMessage) {
|
|
769
|
-
return 'native_flow_response'
|
|
816
|
+
return 'native_flow_response'
|
|
770
817
|
}
|
|
771
|
-
else if (message.
|
|
772
|
-
return '
|
|
818
|
+
else if (/https:\/\/wa\.me\/c\/\d+/.test(message.extendedTextMessage?.text)) {
|
|
819
|
+
return 'cataloglink'
|
|
773
820
|
}
|
|
774
|
-
|
|
775
|
-
|
|
821
|
+
else if (/https:\/\/wa\.me\/p\/\d+\/\d+/.test(message.extendedTextMessage?.text)) {
|
|
822
|
+
return 'productlink'
|
|
823
|
+
}
|
|
824
|
+
else if (message.extendedTextMessage?.matchedText || message.groupInviteMessage) {
|
|
825
|
+
return 'url'
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
const getButtonType = (message) => {
|
|
830
|
+
if (message.listMessage) {
|
|
831
|
+
return 'list'
|
|
832
|
+
}
|
|
833
|
+
else if (message.buttonsMessage) {
|
|
834
|
+
return 'buttons'
|
|
835
|
+
}
|
|
836
|
+
else if(message.interactiveMessage?.nativeFlowMessage) {
|
|
837
|
+
return 'native_flow'
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
const getButtonArgs = (message) => {
|
|
842
|
+
const nativeFlow = message.interactiveMessage?.nativeFlowMessage
|
|
843
|
+
const firstButtonName = nativeFlow?.buttons?.[0]?.name
|
|
844
|
+
const nativeFlowSpecials = [
|
|
845
|
+
'mpm', 'cta_catalog', 'send_location',
|
|
846
|
+
'call_permission_request', 'wa_payment_transaction_details',
|
|
847
|
+
'automated_greeting_message_view_catalog'
|
|
848
|
+
]
|
|
849
|
+
|
|
850
|
+
if (nativeFlow && (firstButtonName === 'review_and_pay' || firstButtonName === 'payment_info')) {
|
|
851
|
+
return {
|
|
852
|
+
tag: 'biz',
|
|
853
|
+
attrs: {
|
|
854
|
+
native_flow_name: firstButtonName === 'review_and_pay' ? 'order_details' : firstButtonName
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
} else if (nativeFlow && nativeFlowSpecials.includes(firstButtonName)) {
|
|
858
|
+
// Only works for WhatsApp Original, not WhatsApp Business
|
|
859
|
+
return {
|
|
860
|
+
tag: 'biz',
|
|
861
|
+
attrs: {},
|
|
862
|
+
content: [{
|
|
863
|
+
tag: 'interactive',
|
|
864
|
+
attrs: {
|
|
865
|
+
type: 'native_flow',
|
|
866
|
+
v: '1'
|
|
867
|
+
},
|
|
868
|
+
content: [{
|
|
869
|
+
tag: 'native_flow',
|
|
870
|
+
attrs: {
|
|
871
|
+
v: '2',
|
|
872
|
+
name: firstButtonName
|
|
873
|
+
}
|
|
874
|
+
}]
|
|
875
|
+
}]
|
|
876
|
+
}
|
|
877
|
+
} else if (nativeFlow || message.buttonsMessage) {
|
|
878
|
+
// It works for whatsapp original and whatsapp business
|
|
879
|
+
return {
|
|
880
|
+
tag: 'biz',
|
|
881
|
+
attrs: {},
|
|
882
|
+
content: [{
|
|
883
|
+
tag: 'interactive',
|
|
884
|
+
attrs: {
|
|
885
|
+
type: 'native_flow',
|
|
886
|
+
v: '1'
|
|
887
|
+
},
|
|
888
|
+
content: [{
|
|
889
|
+
tag: 'native_flow',
|
|
890
|
+
attrs: {
|
|
891
|
+
v: '9',
|
|
892
|
+
name: 'mixed'
|
|
893
|
+
}
|
|
894
|
+
}]
|
|
895
|
+
}]
|
|
896
|
+
}
|
|
897
|
+
} else if (message.listMessage) {
|
|
898
|
+
return {
|
|
899
|
+
tag: 'biz',
|
|
900
|
+
attrs: {},
|
|
901
|
+
content: [{
|
|
902
|
+
tag: 'list',
|
|
903
|
+
attrs: {
|
|
904
|
+
v: '2',
|
|
905
|
+
type: 'product_list'
|
|
906
|
+
}
|
|
907
|
+
}]
|
|
908
|
+
}
|
|
909
|
+
} else {
|
|
910
|
+
return {
|
|
911
|
+
tag: 'biz',
|
|
912
|
+
attrs: {}
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
|
|
776
917
|
const getPrivacyTokens = async (jids) => {
|
|
777
|
-
const t = unixTimestampSeconds().toString()
|
|
918
|
+
const t = Utils_1.unixTimestampSeconds().toString()
|
|
919
|
+
|
|
778
920
|
const result = await query({
|
|
779
921
|
tag: 'iq',
|
|
780
922
|
attrs: {
|
|
781
|
-
to: S_WHATSAPP_NET,
|
|
923
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
782
924
|
type: 'set',
|
|
783
925
|
xmlns: 'privacy'
|
|
784
926
|
},
|
|
@@ -789,165 +931,373 @@ export const makeMessagesSocket = (config) => {
|
|
|
789
931
|
content: jids.map(jid => ({
|
|
790
932
|
tag: 'token',
|
|
791
933
|
attrs: {
|
|
792
|
-
jid: jidNormalizedUser(jid),
|
|
934
|
+
jid: WABinary_1.jidNormalizedUser(jid),
|
|
793
935
|
t,
|
|
794
936
|
type: 'trusted_contact'
|
|
795
937
|
}
|
|
796
938
|
}))
|
|
797
939
|
}
|
|
798
940
|
]
|
|
799
|
-
})
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
941
|
+
})
|
|
942
|
+
|
|
943
|
+
return result
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
const getEphemeralGroup = (jid) => {
|
|
947
|
+
if (!WABinary_1.isJidGroup(jid)) throw new TypeError("Jid should originate from a group!")
|
|
948
|
+
|
|
949
|
+
return groupQuery(jid, 'get', [{
|
|
950
|
+
tag: 'query',
|
|
951
|
+
attrs: {
|
|
952
|
+
request: 'interactive'
|
|
953
|
+
}
|
|
954
|
+
}])
|
|
955
|
+
.then((groups) => WABinary_1.getBinaryNodeChild(groups, 'group'))
|
|
956
|
+
.then((metadata) => WABinary_1.getBinaryNodeChild(metadata, 'ephemeral')?.attrs?.expiration || 0)
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
const waUploadToServer = Utils_1.getWAUploadToServer(config, refreshMediaConn)
|
|
960
|
+
|
|
961
|
+
const waitForMsgMediaUpdate = Utils_1.bindWaitForEvent(ev, 'messages.media-update')
|
|
962
|
+
|
|
804
963
|
return {
|
|
805
|
-
...
|
|
964
|
+
...baron,
|
|
806
965
|
getPrivacyTokens,
|
|
807
966
|
assertSessions,
|
|
808
967
|
relayMessage,
|
|
809
968
|
sendReceipt,
|
|
810
969
|
sendReceipts,
|
|
811
970
|
readMessages,
|
|
971
|
+
profilePictureUrl,
|
|
972
|
+
getUSyncDevices,
|
|
812
973
|
refreshMediaConn,
|
|
813
974
|
waUploadToServer,
|
|
814
|
-
|
|
975
|
+
getEphemeralGroup,
|
|
976
|
+
fetchPrivacySettings,
|
|
977
|
+
createParticipantNodes,
|
|
815
978
|
sendPeerDataOperationMessage,
|
|
816
|
-
createParticipantNodes,
|
|
817
|
-
getUSyncDevices,
|
|
818
979
|
messageRetryManager,
|
|
819
980
|
updateMediaMessage: async (message) => {
|
|
820
|
-
const content = assertMediaContent(message.message)
|
|
821
|
-
const mediaKey = content.mediaKey
|
|
822
|
-
const meId = authState.creds.me.id
|
|
823
|
-
const node = await encryptMediaRetryRequest(message.key, mediaKey, meId)
|
|
824
|
-
let error = undefined
|
|
981
|
+
const content = Utils_1.assertMediaContent(message.message)
|
|
982
|
+
const mediaKey = content.mediaKey
|
|
983
|
+
const meId = authState.creds.me.id
|
|
984
|
+
const node = await Utils_1.encryptMediaRetryRequest(message.key, mediaKey, meId)
|
|
985
|
+
let error = undefined
|
|
986
|
+
|
|
825
987
|
await Promise.all([
|
|
826
988
|
sendNode(node),
|
|
827
989
|
waitForMsgMediaUpdate(async (update) => {
|
|
828
|
-
const result = update.find(c => c.key.id === message.key.id)
|
|
990
|
+
const result = update.find(c => c.key.id === message.key.id)
|
|
829
991
|
if (result) {
|
|
830
992
|
if (result.error) {
|
|
831
|
-
error = result.error
|
|
993
|
+
error = result.error
|
|
832
994
|
}
|
|
995
|
+
|
|
833
996
|
else {
|
|
834
997
|
try {
|
|
835
|
-
const media = await decryptMediaRetryData(result.media, mediaKey, result.key.id)
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
});
|
|
998
|
+
const media = await Utils_1.decryptMediaRetryData(result.media, mediaKey, result.key.id)
|
|
999
|
+
|
|
1000
|
+
if (media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
|
|
1001
|
+
const resultStr = WAProto_1.proto.MediaRetryNotification.ResultType[media.result]
|
|
1002
|
+
|
|
1003
|
+
throw new boom_1.Boom(`Media re-upload failed by device (${resultStr})`, { data: media, statusCode: Utils_1.getStatusCodeForMediaRetry(media.result) || 404 })
|
|
842
1004
|
}
|
|
843
|
-
|
|
844
|
-
content.
|
|
845
|
-
|
|
1005
|
+
|
|
1006
|
+
content.directPath = media.directPath
|
|
1007
|
+
|
|
1008
|
+
content.url = Utils_1.getUrlFromDirectPath(content.directPath)
|
|
1009
|
+
|
|
1010
|
+
logger.debug({ directPath: media.directPath, key: result.key }, 'media update successful')
|
|
846
1011
|
}
|
|
1012
|
+
|
|
847
1013
|
catch (err) {
|
|
848
|
-
error = err
|
|
1014
|
+
error = err
|
|
849
1015
|
}
|
|
850
1016
|
}
|
|
851
|
-
|
|
1017
|
+
|
|
1018
|
+
return true
|
|
852
1019
|
}
|
|
853
1020
|
})
|
|
854
|
-
])
|
|
1021
|
+
])
|
|
1022
|
+
|
|
855
1023
|
if (error) {
|
|
856
|
-
throw error
|
|
1024
|
+
throw error
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
ev.emit('messages.update', [
|
|
1028
|
+
{ key: message.key, update: { message: message.message } }
|
|
1029
|
+
])
|
|
1030
|
+
|
|
1031
|
+
return message
|
|
1032
|
+
},
|
|
1033
|
+
sendStatusMentions: async (content, jids = []) => {
|
|
1034
|
+
const userJid = WABinary_1.jidNormalizedUser(authState.creds.me.id)
|
|
1035
|
+
let allUsers = new Set()
|
|
1036
|
+
allUsers.add(userJid)
|
|
1037
|
+
|
|
1038
|
+
for (const id of jids) {
|
|
1039
|
+
const isGroup = WABinary_1.isJidGroup(id)
|
|
1040
|
+
const isPrivate = WABinary_1.isJidUser(id)
|
|
1041
|
+
|
|
1042
|
+
if (isGroup) {
|
|
1043
|
+
try {
|
|
1044
|
+
const metadata = await cachedGroupMetadata(id) || await groupMetadata(id)
|
|
1045
|
+
const participants = metadata.participants.map(p => WABinary_1.jidNormalizedUser(p.id))
|
|
1046
|
+
participants.forEach(jid => allUsers.add(jid))
|
|
1047
|
+
} catch (error) {
|
|
1048
|
+
logger.error(`Error getting metadata for group ${id}: ${error}`)
|
|
1049
|
+
}
|
|
1050
|
+
} else if (isPrivate) {
|
|
1051
|
+
allUsers.add(WABinary_1.jidNormalizedUser(id))
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
const uniqueUsers = Array.from(allUsers)
|
|
1056
|
+
const getRandomHexColor = () => "#" + Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0")
|
|
1057
|
+
|
|
1058
|
+
const isMedia = content.image || content.video || content.audio
|
|
1059
|
+
const isAudio = !!content.audio
|
|
1060
|
+
|
|
1061
|
+
const messageContent = { ...content }
|
|
1062
|
+
|
|
1063
|
+
if (isMedia && !isAudio) {
|
|
1064
|
+
if (messageContent.text) {
|
|
1065
|
+
messageContent.caption = messageContent.text
|
|
1066
|
+
|
|
1067
|
+
delete messageContent.text
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
delete messageContent.ptt
|
|
1071
|
+
delete messageContent.font
|
|
1072
|
+
delete messageContent.backgroundColor
|
|
1073
|
+
delete messageContent.textColor
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
if (isAudio) {
|
|
1077
|
+
delete messageContent.text
|
|
1078
|
+
delete messageContent.caption
|
|
1079
|
+
delete messageContent.font
|
|
1080
|
+
delete messageContent.textColor
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
const font = !isMedia ? (content.font || Math.floor(Math.random() * 9)) : undefined
|
|
1084
|
+
const textColor = !isMedia ? (content.textColor || getRandomHexColor()) : undefined
|
|
1085
|
+
const backgroundColor = (!isMedia || isAudio) ? (content.backgroundColor || getRandomHexColor()) : undefined
|
|
1086
|
+
const ptt = isAudio ? (typeof content.ptt === 'boolean' ? content.ptt : true) : undefined
|
|
1087
|
+
|
|
1088
|
+
let msg
|
|
1089
|
+
let mediaHandle
|
|
1090
|
+
try {
|
|
1091
|
+
msg = await Utils_1.generateWAMessage(WABinary_1.STORIES_JID, messageContent, {
|
|
1092
|
+
logger,
|
|
1093
|
+
userJid,
|
|
1094
|
+
getUrlInfo: text => link_preview_1.getUrlInfo(text, {
|
|
1095
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
1096
|
+
fetchOpts: { timeout: 3000, ...axiosOptions || {} },
|
|
1097
|
+
logger,
|
|
1098
|
+
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
1099
|
+
}),
|
|
1100
|
+
upload: async (encFilePath, opts) => {
|
|
1101
|
+
const up = await waUploadToServer(encFilePath, { ...opts })
|
|
1102
|
+
mediaHandle = up.handle
|
|
1103
|
+
return up
|
|
1104
|
+
},
|
|
1105
|
+
mediaCache: config.mediaCache,
|
|
1106
|
+
options: config.options,
|
|
1107
|
+
font,
|
|
1108
|
+
textColor,
|
|
1109
|
+
backgroundColor,
|
|
1110
|
+
ptt
|
|
1111
|
+
})
|
|
1112
|
+
} catch (error) {
|
|
1113
|
+
logger.error(`Error generating message: ${error}`)
|
|
1114
|
+
throw error
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
await relayMessage(WABinary_1.STORIES_JID, msg.message, {
|
|
1118
|
+
messageId: msg.key.id,
|
|
1119
|
+
statusJidList: uniqueUsers,
|
|
1120
|
+
additionalNodes: [
|
|
1121
|
+
{
|
|
1122
|
+
tag: 'meta',
|
|
1123
|
+
attrs: {},
|
|
1124
|
+
content: [
|
|
1125
|
+
{
|
|
1126
|
+
tag: 'mentioned_users',
|
|
1127
|
+
attrs: {},
|
|
1128
|
+
content: jids.map(jid => ({
|
|
1129
|
+
tag: 'to',
|
|
1130
|
+
attrs: { jid: WABinary_1.jidNormalizedUser(jid) }
|
|
1131
|
+
}))
|
|
1132
|
+
}]
|
|
1133
|
+
}]
|
|
1134
|
+
})
|
|
1135
|
+
|
|
1136
|
+
for (const id of jids) {
|
|
1137
|
+
try {
|
|
1138
|
+
const normalizedId = WABinary_1.jidNormalizedUser(id)
|
|
1139
|
+
const isPrivate = WABinary_1.isJidUser(normalizedId)
|
|
1140
|
+
const type = isPrivate ? 'statusMentionMessage' : 'groupStatusMentionMessage'
|
|
1141
|
+
|
|
1142
|
+
const protocolMessage = {
|
|
1143
|
+
[type]: {
|
|
1144
|
+
message: {
|
|
1145
|
+
protocolMessage: {
|
|
1146
|
+
key: msg.key,
|
|
1147
|
+
type: 25
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
},
|
|
1151
|
+
messageContextInfo: {
|
|
1152
|
+
messageSecret: crypto_1.randomBytes(32)
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
const statusMsg = await Utils_1.generateWAMessageFromContent(normalizedId,
|
|
1157
|
+
protocolMessage,
|
|
1158
|
+
{}
|
|
1159
|
+
)
|
|
1160
|
+
|
|
1161
|
+
await relayMessage(
|
|
1162
|
+
normalizedId,
|
|
1163
|
+
statusMsg.message,
|
|
1164
|
+
{
|
|
1165
|
+
additionalNodes: [{
|
|
1166
|
+
tag: 'meta',
|
|
1167
|
+
attrs: isPrivate ?
|
|
1168
|
+
{ is_status_mention: 'true' } :
|
|
1169
|
+
{ is_group_status_mention: 'true' }
|
|
1170
|
+
}]
|
|
1171
|
+
}
|
|
1172
|
+
)
|
|
1173
|
+
|
|
1174
|
+
await Utils_1.delay(2000)
|
|
1175
|
+
} catch (error) {
|
|
1176
|
+
logger.error(`Error sending to ${id}: ${error}`)
|
|
857
1177
|
}
|
|
858
|
-
|
|
859
|
-
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
return msg
|
|
860
1181
|
},
|
|
861
1182
|
sendMessage: async (jid, content, options = {}) => {
|
|
862
|
-
const userJid = authState.creds.me.id
|
|
1183
|
+
const userJid = authState.creds.me.id
|
|
1184
|
+
const additionalAttributes = {}
|
|
1185
|
+
|
|
1186
|
+
if (!options.ephemeralExpiration) {
|
|
1187
|
+
if (WABinary_1.isJidGroup(jid)) {
|
|
1188
|
+
const expiration = await getEphemeralGroup(jid)
|
|
1189
|
+
options.ephemeralExpiration = expiration
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
|
|
863
1193
|
if (typeof content === 'object' &&
|
|
864
1194
|
'disappearingMessagesInChat' in content &&
|
|
865
1195
|
typeof content['disappearingMessagesInChat'] !== 'undefined' &&
|
|
866
|
-
isJidGroup(jid)) {
|
|
867
|
-
|
|
868
|
-
const
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
1196
|
+
WABinary_1.isJidGroup(jid)) {
|
|
1197
|
+
|
|
1198
|
+
const { disappearingMessagesInChat } = content
|
|
1199
|
+
|
|
1200
|
+
const value = typeof disappearingMessagesInChat === 'boolean' ?
|
|
1201
|
+
(disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
|
|
1202
|
+
disappearingMessagesInChat
|
|
1203
|
+
|
|
1204
|
+
await groupToggleEphemeral(jid, value)
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
else if (typeof content === 'object' && 'album' in content && content.album) {
|
|
1208
|
+
const albumMsg = await Utils_1.prepareAlbumMessageContent(jid, content.album, {
|
|
1209
|
+
baron: {
|
|
1210
|
+
relayMessage,
|
|
1211
|
+
waUploadToServer
|
|
1212
|
+
},
|
|
1213
|
+
userJid: userJid,
|
|
1214
|
+
...options
|
|
1215
|
+
})
|
|
1216
|
+
|
|
1217
|
+
for (const media of albumMsg) {
|
|
1218
|
+
await Utils_1.delay(options.delay || 500)
|
|
1219
|
+
await relayMessage(jid, media.message, { messageId: media.key.id, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, statusJidList: options.statusJidList, additionalNodes: options.additionalNodes, AI: options.ai })
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
return albumMsg
|
|
874
1223
|
}
|
|
1224
|
+
|
|
875
1225
|
else {
|
|
876
|
-
|
|
1226
|
+
let mediaHandle
|
|
1227
|
+
|
|
1228
|
+
const fullMsg = await Utils_1.generateWAMessage(jid, content, {
|
|
877
1229
|
logger,
|
|
878
1230
|
userJid,
|
|
879
|
-
getUrlInfo: text => getUrlInfo(text, {
|
|
1231
|
+
getUrlInfo: text => link_preview_1.getUrlInfo(text, {
|
|
880
1232
|
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
881
1233
|
fetchOpts: {
|
|
882
1234
|
timeout: 3000,
|
|
883
|
-
...
|
|
1235
|
+
...axiosOptions || {}
|
|
884
1236
|
},
|
|
885
1237
|
logger,
|
|
886
|
-
uploadImage: generateHighQualityLinkPreview
|
|
1238
|
+
uploadImage: generateHighQualityLinkPreview
|
|
1239
|
+
? waUploadToServer
|
|
1240
|
+
: undefined
|
|
887
1241
|
}),
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
1242
|
+
getProfilePicUrl: profilePictureUrl,
|
|
1243
|
+
getCallLink: createCallLink,
|
|
1244
|
+
upload: async (encFilePath, opts) => {
|
|
1245
|
+
const up = await waUploadToServer(encFilePath, { ...opts, newsletter: WABinary_1.isJidNewsletter(jid) })
|
|
1246
|
+
mediaHandle = up.handle
|
|
1247
|
+
return up
|
|
1248
|
+
},
|
|
892
1249
|
mediaCache: config.mediaCache,
|
|
893
1250
|
options: config.options,
|
|
894
|
-
messageId:
|
|
895
|
-
...options
|
|
896
|
-
})
|
|
897
|
-
|
|
898
|
-
const
|
|
899
|
-
const
|
|
900
|
-
const
|
|
901
|
-
const
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
// required for delete
|
|
905
|
-
if (isDeleteMsg) {
|
|
1251
|
+
messageId: Utils_1.generateMessageID(userJid),
|
|
1252
|
+
...options,
|
|
1253
|
+
})
|
|
1254
|
+
|
|
1255
|
+
const isPin = 'pin' in content && !!content.pin
|
|
1256
|
+
const isEdit = 'edit' in content && !!content.edit
|
|
1257
|
+
const isDelete = 'delete' in content && !!content.delete
|
|
1258
|
+
const isKeep = 'keep' in content && !!content.keep && content.keep?.type === 2
|
|
1259
|
+
|
|
1260
|
+
if (isDelete || isKeep) {
|
|
906
1261
|
// if the chat is a group, and I am not the author, then delete the message as an admin
|
|
907
|
-
if (isJidGroup(content.delete?.remoteJid) && !content.delete?.fromMe) {
|
|
908
|
-
additionalAttributes.edit = '8'
|
|
1262
|
+
if (WABinary_1.isJidGroup(content.delete?.remoteJid) && !content.delete?.fromMe || WABinary_1.isJidNewsletter(jid)) {
|
|
1263
|
+
additionalAttributes.edit = '8'
|
|
909
1264
|
}
|
|
1265
|
+
|
|
910
1266
|
else {
|
|
911
|
-
additionalAttributes.edit = '7'
|
|
1267
|
+
additionalAttributes.edit = '7'
|
|
912
1268
|
}
|
|
913
1269
|
}
|
|
914
|
-
|
|
915
|
-
|
|
1270
|
+
|
|
1271
|
+
else if (isEdit) {
|
|
1272
|
+
additionalAttributes.edit = WABinary_1.isJidNewsletter(jid) ? '3' : '1'
|
|
916
1273
|
}
|
|
917
|
-
|
|
918
|
-
|
|
1274
|
+
|
|
1275
|
+
else if (isPin) {
|
|
1276
|
+
additionalAttributes.edit = '2'
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
if (mediaHandle) {
|
|
1280
|
+
additionalAttributes['media_id'] = mediaHandle
|
|
919
1281
|
}
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
attrs: {
|
|
924
|
-
polltype: 'creation'
|
|
925
|
-
}
|
|
926
|
-
});
|
|
927
|
-
}
|
|
928
|
-
else if (isEventMsg) {
|
|
929
|
-
additionalNodes.push({
|
|
930
|
-
tag: 'meta',
|
|
931
|
-
attrs: {
|
|
932
|
-
event_type: 'creation'
|
|
933
|
-
}
|
|
934
|
-
});
|
|
1282
|
+
|
|
1283
|
+
if ('cachedGroupMetadata' in options) {
|
|
1284
|
+
console.warn('cachedGroupMetadata in sendMessage are deprecated, now cachedGroupMetadata is part of the socket config.')
|
|
935
1285
|
}
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
additionalAttributes,
|
|
940
|
-
statusJidList: options.statusJidList,
|
|
941
|
-
additionalNodes
|
|
942
|
-
});
|
|
1286
|
+
|
|
1287
|
+
await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, statusJidList: options.statusJidList, additionalNodes: options.additionalNodes, AI: options.ai })
|
|
1288
|
+
|
|
943
1289
|
if (config.emitOwnEvents) {
|
|
944
1290
|
process.nextTick(() => {
|
|
945
|
-
processingMutex.mutex(() => upsertMessage(fullMsg, 'append'))
|
|
946
|
-
})
|
|
1291
|
+
processingMutex.mutex(() => (upsertMessage(fullMsg, 'append')))
|
|
1292
|
+
})
|
|
947
1293
|
}
|
|
948
|
-
|
|
1294
|
+
|
|
1295
|
+
return fullMsg
|
|
949
1296
|
}
|
|
950
1297
|
}
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
module.exports = {
|
|
1302
|
+
makeMessagesSocket
|
|
1303
|
+
}
|