@modzneverdie/baileys 17.1.2 → 17.1.3
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 +21 -0
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +6035 -0
- package/WAProto/fix-imports.js +81 -0
- package/WAProto/index.d.ts +2 -0
- package/WAProto/index.js +59469 -96804
- package/lib/Defaults/index.d.ts +29 -8
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +134 -141
- package/lib/Defaults/index.js.map +1 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +1 -0
- package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
- package/lib/Signal/Group/ciphertext-message.js +2 -5
- package/lib/Signal/Group/ciphertext-message.js.map +1 -0
- package/lib/Signal/Group/group-session-builder.d.ts +4 -3
- package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
- package/lib/Signal/Group/group-session-builder.js +7 -41
- package/lib/Signal/Group/group-session-builder.js.map +1 -0
- package/lib/Signal/Group/group_cipher.d.ts +4 -4
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
- package/lib/Signal/Group/group_cipher.js +37 -51
- package/lib/Signal/Group/group_cipher.js.map +1 -0
- package/lib/Signal/Group/index.d.ts +12 -11
- package/lib/Signal/Group/index.d.ts.map +1 -0
- package/lib/Signal/Group/index.js +12 -57
- package/lib/Signal/Group/index.js.map +1 -0
- package/lib/Signal/Group/keyhelper.d.ts +2 -1
- package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
- package/lib/Signal/Group/keyhelper.js +7 -44
- package/lib/Signal/Group/keyhelper.js.map +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +3 -2
- package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-chain-key.js +7 -15
- package/lib/Signal/Group/sender-chain-key.js.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +2 -1
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +8 -11
- package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-message.d.ts +2 -1
- package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-message.js +9 -12
- package/lib/Signal/Group/sender-key-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-name.d.ts +1 -0
- package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-name.js +2 -5
- package/lib/Signal/Group/sender-key-name.js.map +1 -0
- package/lib/Signal/Group/sender-key-record.d.ts +3 -2
- package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-record.js +9 -21
- package/lib/Signal/Group/sender-key-record.js.map +1 -0
- package/lib/Signal/Group/sender-key-state.d.ts +7 -6
- package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-state.js +27 -42
- package/lib/Signal/Group/sender-key-state.js.map +1 -0
- package/lib/Signal/Group/sender-message-key.d.ts +1 -0
- package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-message-key.js +4 -7
- package/lib/Signal/Group/sender-message-key.js.map +1 -0
- package/lib/Signal/libsignal.d.ts +5 -3
- package/lib/Signal/libsignal.d.ts.map +1 -0
- package/lib/Signal/libsignal.js +319 -90
- package/lib/Signal/libsignal.js.map +1 -0
- package/lib/Signal/lid-mapping.d.ts +19 -0
- package/lib/Signal/lid-mapping.d.ts.map +1 -0
- package/lib/Signal/lid-mapping.js +271 -0
- package/lib/Signal/lid-mapping.js.map +1 -0
- package/lib/Socket/Client/index.d.ts +3 -3
- package/lib/Socket/Client/index.d.ts.map +1 -0
- package/lib/Socket/Client/index.js +3 -19
- package/lib/Socket/Client/index.js.map +1 -0
- package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +4 -5
- 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/{web-socket-client.d.ts → websocket.d.ts} +3 -2
- 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 +533 -168
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +405 -243
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +84 -240
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +406 -385
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +645 -0
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/dugong.d.ts +125 -249
- package/lib/Socket/dugong.d.ts.map +1 -0
- package/lib/Socket/dugong.js +749 -465
- package/lib/Socket/dugong.js.map +1 -0
- package/lib/Socket/groups.d.ts +93 -58
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +105 -95
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +632 -169
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +15 -11
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +162 -85
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +806 -608
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +576 -146
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +1563 -861
- 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 +48 -0
- package/lib/Socket/mex.js.map +1 -0
- package/lib/Socket/newsletter.d.ts +129 -86
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +438 -297
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +31 -19
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +512 -241
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Types/Auth.d.ts +18 -12
- package/lib/Types/Auth.d.ts.map +1 -0
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Auth.js.map +1 -0
- package/lib/Types/Bussines.d.ts +37 -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 +3 -1
- package/lib/Types/Call.d.ts.map +1 -0
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Call.js.map +1 -0
- package/lib/Types/Chat.d.ts +34 -13
- package/lib/Types/Chat.d.ts.map +1 -0
- package/lib/Types/Chat.js +8 -4
- package/lib/Types/Chat.js.map +1 -0
- package/lib/Types/Contact.d.ts +6 -1
- package/lib/Types/Contact.d.ts.map +1 -0
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Contact.js.map +1 -0
- package/lib/Types/Events.d.ts +97 -17
- package/lib/Types/Events.d.ts.map +1 -0
- package/lib/Types/Events.js +2 -2
- package/lib/Types/Events.js.map +1 -0
- package/lib/Types/GroupMetadata.d.ts +18 -5
- package/lib/Types/GroupMetadata.d.ts.map +1 -0
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/GroupMetadata.js.map +1 -0
- package/lib/Types/Label.d.ts +12 -0
- package/lib/Types/Label.d.ts.map +1 -0
- package/lib/Types/Label.js +3 -5
- package/lib/Types/Label.js.map +1 -0
- package/lib/Types/LabelAssociation.d.ts +1 -0
- package/lib/Types/LabelAssociation.d.ts.map +1 -0
- package/lib/Types/LabelAssociation.js +3 -5
- package/lib/Types/LabelAssociation.js.map +1 -0
- package/lib/Types/Message.d.ts +355 -206
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +11 -9
- package/lib/Types/Message.js.map +1 -0
- package/lib/Types/Newsletter.d.ts +130 -98
- package/lib/Types/Newsletter.d.ts.map +1 -0
- package/lib/Types/Newsletter.js +31 -38
- package/lib/Types/Newsletter.js.map +1 -0
- package/lib/Types/Product.d.ts +2 -1
- package/lib/Types/Product.d.ts.map +1 -0
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Product.js.map +1 -0
- package/lib/Types/Signal.d.ts +20 -1
- package/lib/Types/Signal.d.ts.map +1 -0
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Signal.js.map +1 -0
- package/lib/Types/Socket.d.ts +152 -105
- package/lib/Types/Socket.d.ts.map +1 -0
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/Socket.js.map +1 -0
- package/lib/Types/State.d.ts +14 -2
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +13 -2
- package/lib/Types/State.js.map +1 -0
- package/lib/Types/USync.d.ts +3 -2
- package/lib/Types/USync.d.ts.map +1 -0
- package/lib/Types/USync.js +2 -2
- package/lib/Types/USync.js.map +1 -0
- package/lib/Types/index.d.ts +54 -45
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +32 -41
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/auth-utils.d.ts +7 -6
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +228 -144
- 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 +28 -0
- package/lib/Utils/browser-utils.js.map +1 -0
- package/lib/Utils/business.d.ts +3 -2
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +66 -69
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +19 -20
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +331 -248
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +10 -14
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +57 -90
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +37 -8
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +169 -84
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +7 -8
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +138 -78
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +26 -27
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +170 -209
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts +16 -9
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +83 -48
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/identity-change-handler.d.ts +37 -0
- package/lib/Utils/identity-change-handler.d.ts.map +1 -0
- package/lib/Utils/identity-change-handler.js +49 -0
- package/lib/Utils/identity-change-handler.js.map +1 -0
- package/lib/Utils/index.d.ts +23 -17
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +23 -33
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/link-preview.d.ts +5 -5
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +14 -22
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +12 -3
- package/lib/Utils/logger.d.ts.map +1 -0
- package/lib/Utils/logger.js +3 -7
- package/lib/Utils/logger.js.map +1 -0
- package/lib/Utils/lt-hash.d.ts +8 -12
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +3 -46
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts +4 -2
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +24 -34
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/message-retry-manager.d.ts +110 -0
- package/lib/Utils/message-retry-manager.d.ts.map +1 -0
- package/lib/Utils/message-retry-manager.js +225 -0
- package/lib/Utils/message-retry-manager.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +56 -42
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +411 -448
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +32 -18
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +1132 -710
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts +12 -13
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +145 -99
- 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 +31 -12
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +357 -150
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.d.ts.map +1 -0
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/reporting-utils.js.map +1 -0
- package/lib/Utils/rich-messages.d.ts +277 -0
- package/lib/Utils/rich-messages.d.ts.map +1 -0
- package/lib/Utils/rich-messages.js +1144 -0
- package/lib/Utils/rich-messages.js.map +1 -0
- package/lib/Utils/signal.d.ts +7 -5
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +78 -72
- 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/sticker-pack.d.ts +10 -0
- package/lib/Utils/sticker-pack.js +111 -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 +48 -0
- package/lib/Utils/sync-action-utils.js.map +1 -0
- package/lib/Utils/tc-token-utils.d.ts +12 -0
- package/lib/Utils/tc-token-utils.d.ts.map +1 -0
- package/lib/Utils/tc-token-utils.js +18 -0
- package/lib/Utils/tc-token-utils.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +2 -2
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +29 -27
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts +7 -7
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +70 -99
- package/lib/Utils/validate-connection.js.map +1 -0
- package/lib/WABinary/constants.d.ts +25 -27
- package/lib/WABinary/constants.d.ts.map +1 -0
- package/lib/WABinary/constants.js +1281 -20
- package/lib/WABinary/constants.js.map +1 -0
- package/lib/WABinary/decode.d.ts +5 -5
- package/lib/WABinary/decode.d.ts.map +1 -0
- package/lib/WABinary/decode.js +52 -42
- package/lib/WABinary/decode.js.map +1 -0
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.d.ts.map +1 -0
- package/lib/WABinary/encode.js +110 -155
- package/lib/WABinary/encode.js.map +1 -0
- package/lib/WABinary/generic-utils.d.ts +8 -8
- package/lib/WABinary/generic-utils.d.ts.map +1 -0
- package/lib/WABinary/generic-utils.js +142 -149
- package/lib/WABinary/generic-utils.js.map +1 -0
- package/lib/WABinary/index.d.ts +6 -5
- package/lib/WABinary/index.d.ts.map +1 -0
- package/lib/WABinary/index.js +6 -21
- package/lib/WABinary/index.js.map +1 -0
- package/lib/WABinary/jid-utils.d.ts +25 -8
- package/lib/WABinary/jid-utils.d.ts.map +1 -0
- package/lib/WABinary/jid-utils.js +74 -40
- package/lib/WABinary/jid-utils.js.map +1 -0
- package/lib/WABinary/types.d.ts +2 -1
- package/lib/WABinary/types.d.ts.map +1 -0
- package/lib/WABinary/types.js +2 -2
- package/lib/WABinary/types.js.map +1 -0
- package/lib/WAM/BinaryInfo.d.ts +3 -11
- package/lib/WAM/BinaryInfo.d.ts.map +1 -0
- package/lib/WAM/BinaryInfo.js +2 -5
- package/lib/WAM/BinaryInfo.js.map +1 -0
- package/lib/WAM/constants.d.ts +5 -3
- package/lib/WAM/constants.d.ts.map +1 -0
- package/lib/WAM/constants.js +19071 -11568
- package/lib/WAM/constants.js.map +1 -0
- package/lib/WAM/encode.d.ts +2 -2
- package/lib/WAM/encode.d.ts.map +1 -0
- package/lib/WAM/encode.js +17 -22
- package/lib/WAM/encode.js.map +1 -0
- package/lib/WAM/index.d.ts +4 -3
- package/lib/WAM/index.d.ts.map +1 -0
- package/lib/WAM/index.js +4 -19
- package/lib/WAM/index.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +4 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +8 -11
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -14
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -12
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -13
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +4 -3
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -22
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +5 -3
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +13 -8
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/index.d.ts +5 -4
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/index.js +5 -20
- package/lib/WAUSync/Protocols/index.js.map +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +5 -4
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
- package/lib/WAUSync/USyncQuery.js +40 -35
- package/lib/WAUSync/USyncQuery.js.map +1 -0
- package/lib/WAUSync/USyncUser.d.ts +6 -5
- package/lib/WAUSync/USyncUser.d.ts.map +1 -0
- package/lib/WAUSync/USyncUser.js +2 -5
- package/lib/WAUSync/USyncUser.js.map +1 -0
- package/lib/WAUSync/index.d.ts +4 -3
- package/lib/WAUSync/index.d.ts.map +1 -0
- package/lib/WAUSync/index.js +4 -19
- package/lib/WAUSync/index.js.map +1 -0
- package/lib/index.d.ts +10 -9
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +12 -33
- package/lib/index.js.map +1 -0
- package/package.json +64 -105
- package/README.md +0 -364
- package/engine-requirements.js +0 -10
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/registration.d.ts +0 -267
- package/lib/Socket/registration.js +0 -166
- package/lib/Socket/usync.d.ts +0 -36
- package/lib/Socket/usync.js +0 -70
- package/lib/Store/index.d.ts +0 -3
- package/lib/Store/index.js +0 -10
- package/lib/Store/make-cache-manager-store.d.ts +0 -13
- package/lib/Store/make-cache-manager-store.js +0 -83
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-in-memory-store.js +0 -427
- package/lib/Store/make-ordered-dictionary.d.ts +0 -13
- package/lib/Store/make-ordered-dictionary.js +0 -81
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Store/object-repository.js +0 -27
- package/lib/Utils/baileys-event-stream.d.ts +0 -16
- package/lib/Utils/baileys-event-stream.js +0 -63
|
@@ -1,909 +1,1611 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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 {
|
|
6
|
+
aggregateMessageKeysNotFromMe,
|
|
7
|
+
assertMediaContent,
|
|
8
|
+
bindWaitForEvent,
|
|
9
|
+
decryptMediaRetryData,
|
|
10
|
+
encodeNewsletterMessage,
|
|
11
|
+
encodeSignedDeviceIdentity,
|
|
12
|
+
encodeWAMessage,
|
|
13
|
+
encryptMediaRetryRequest,
|
|
14
|
+
extractDeviceJids,
|
|
15
|
+
generateMessageIDV2,
|
|
16
|
+
generateParticipantHashV2,
|
|
17
|
+
generateWAMessage,
|
|
18
|
+
generateWAMessageFromContent,
|
|
19
|
+
getStatusCodeForMediaRetry,
|
|
20
|
+
getUrlFromDirectPath,
|
|
21
|
+
getWAUploadToServer,
|
|
22
|
+
MessageRetryManager,
|
|
23
|
+
normalizeMessageContent,
|
|
24
|
+
prepareWAMessageMedia,
|
|
25
|
+
parseAndInjectE2ESessions,
|
|
26
|
+
unixTimestampSeconds,
|
|
27
|
+
} from "../Utils/index.js";
|
|
28
|
+
import {
|
|
29
|
+
generateTableContent,
|
|
30
|
+
generateTableContentV2,
|
|
31
|
+
generateListContent,
|
|
32
|
+
generateCodeBlockContent,
|
|
33
|
+
generateCodeBlockContentV2,
|
|
34
|
+
generateLinkContent,
|
|
35
|
+
generateLinkContentV2,
|
|
36
|
+
generateRichMessageContent,
|
|
37
|
+
generateLatexContent,
|
|
38
|
+
generateLatexImageContent,
|
|
39
|
+
generateLatexInlineImageContent,
|
|
40
|
+
generateUnifiedResponseContent,
|
|
41
|
+
captureUnifiedResponse,
|
|
42
|
+
} from "../Utils/rich-messages.js";
|
|
43
|
+
import { getUrlInfo } from "../Utils/link-preview.js";
|
|
44
|
+
import { makeKeyedMutex } from "../Utils/make-mutex.js";
|
|
45
|
+
import {
|
|
46
|
+
getMessageReportingToken,
|
|
47
|
+
shouldIncludeReportingToken,
|
|
48
|
+
} from "../Utils/reporting-utils.js";
|
|
49
|
+
import {
|
|
50
|
+
areJidsSameUser,
|
|
51
|
+
getAdditionalNode,
|
|
52
|
+
getBinaryNodeChild,
|
|
53
|
+
getBinaryNodeChildren,
|
|
54
|
+
isHostedLidUser,
|
|
55
|
+
isHostedPnUser,
|
|
56
|
+
isJidGroup,
|
|
57
|
+
isJidNewsletter,
|
|
58
|
+
isLidUser,
|
|
59
|
+
isPnUser,
|
|
60
|
+
jidDecode,
|
|
61
|
+
jidEncode,
|
|
62
|
+
jidNormalizedUser,
|
|
63
|
+
S_WHATSAPP_NET,
|
|
64
|
+
} from "../WABinary/index.js";
|
|
65
|
+
import { USyncQuery, USyncUser } from "../WAUSync/index.js";
|
|
66
|
+
import { Dugong } from "./dugong.js";
|
|
67
|
+
import { makeNewsletterSocket } from "./newsletter.js";
|
|
68
|
+
const NATIVE_FLOW_BUTTON_MAP = {
|
|
69
|
+
review_and_pay: "order_details",
|
|
70
|
+
review_order: "order_status",
|
|
71
|
+
payment_info: "payment_info",
|
|
72
|
+
payment_status: "payment_status",
|
|
73
|
+
payment_method: "payment_method",
|
|
74
|
+
};
|
|
75
|
+
const getButtonType = (message) => {
|
|
76
|
+
const msg = normalizeMessageContent(message) || message;
|
|
77
|
+
if (msg?.buttonsMessage || msg?.listMessage)
|
|
78
|
+
return msg.listMessage ? "list" : "buttons";
|
|
79
|
+
const vm = msg?.viewOnceMessage?.message || msg?.viewOnceMessageV2?.message;
|
|
80
|
+
const im = vm?.interactiveMessage || msg?.interactiveMessage;
|
|
81
|
+
if (!im?.nativeFlowMessage) return null;
|
|
82
|
+
const btnName = im.nativeFlowMessage?.buttons?.[0]?.name;
|
|
83
|
+
if (btnName && NATIVE_FLOW_BUTTON_MAP[btnName])
|
|
84
|
+
return NATIVE_FLOW_BUTTON_MAP[btnName];
|
|
85
|
+
return "interactive";
|
|
86
|
+
};
|
|
87
|
+
export const makeMessagesSocket = (config) => {
|
|
88
|
+
const {
|
|
89
|
+
logger,
|
|
90
|
+
linkPreviewImageThumbnailWidth,
|
|
91
|
+
generateHighQualityLinkPreview,
|
|
92
|
+
options: httpRequestOptions,
|
|
93
|
+
patchMessageBeforeSending,
|
|
94
|
+
cachedGroupMetadata,
|
|
95
|
+
enableRecentMessageCache,
|
|
96
|
+
maxMsgRetryCount,
|
|
97
|
+
} = config;
|
|
98
|
+
const sock = makeNewsletterSocket(config);
|
|
99
|
+
const {
|
|
100
|
+
ev,
|
|
101
|
+
authState,
|
|
102
|
+
messageMutex,
|
|
103
|
+
signalRepository,
|
|
104
|
+
upsertMessage,
|
|
105
|
+
query,
|
|
106
|
+
fetchPrivacySettings,
|
|
107
|
+
sendNode,
|
|
108
|
+
groupMetadata,
|
|
109
|
+
groupToggleEphemeral,
|
|
110
|
+
} = sock;
|
|
111
|
+
const userDevicesCache =
|
|
112
|
+
config.userDevicesCache ||
|
|
113
|
+
new NodeCache({
|
|
114
|
+
stdTTL: DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
|
|
115
|
+
useClones: false,
|
|
46
116
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* generic send receipt function
|
|
79
|
-
* used for receipts of phone call, read, delivery etc.
|
|
80
|
-
* */
|
|
81
|
-
const sendReceipt = async (jid, participant, messageIds, type) => {
|
|
117
|
+
const peerSessionsCache = new NodeCache({
|
|
118
|
+
stdTTL: DEFAULT_CACHE_TTLS.USER_DEVICES,
|
|
119
|
+
useClones: false,
|
|
120
|
+
});
|
|
121
|
+
// Initialize message retry manager if enabled
|
|
122
|
+
const messageRetryManager = enableRecentMessageCache
|
|
123
|
+
? new MessageRetryManager(logger, maxMsgRetryCount)
|
|
124
|
+
: null;
|
|
125
|
+
// Prevent race conditions in Signal session encryption by user
|
|
126
|
+
const encryptionMutex = makeKeyedMutex();
|
|
127
|
+
let mediaConn;
|
|
128
|
+
const refreshMediaConn = async (forceGet = false) => {
|
|
129
|
+
const media = await mediaConn;
|
|
130
|
+
if (
|
|
131
|
+
!media ||
|
|
132
|
+
forceGet ||
|
|
133
|
+
new Date().getTime() - media.fetchDate.getTime() > media.ttl * 1000
|
|
134
|
+
) {
|
|
135
|
+
mediaConn = (async () => {
|
|
136
|
+
const result = await query({
|
|
137
|
+
tag: "iq",
|
|
138
|
+
attrs: {
|
|
139
|
+
type: "set",
|
|
140
|
+
xmlns: "w:m",
|
|
141
|
+
to: S_WHATSAPP_NET,
|
|
142
|
+
},
|
|
143
|
+
content: [{ tag: "media_conn", attrs: {} }],
|
|
144
|
+
});
|
|
145
|
+
const mediaConnNode = getBinaryNodeChild(result, "media_conn");
|
|
146
|
+
// TODO: explore full length of data that whatsapp provides
|
|
82
147
|
const node = {
|
|
83
|
-
|
|
84
|
-
attrs
|
|
85
|
-
|
|
86
|
-
|
|
148
|
+
hosts: getBinaryNodeChildren(mediaConnNode, "host").map(
|
|
149
|
+
({ attrs }) => ({
|
|
150
|
+
hostname: attrs.hostname,
|
|
151
|
+
maxContentLengthBytes: +attrs.maxContentLengthBytes,
|
|
152
|
+
}),
|
|
153
|
+
),
|
|
154
|
+
auth: mediaConnNode.attrs.auth,
|
|
155
|
+
ttl: +mediaConnNode.attrs.ttl,
|
|
156
|
+
fetchDate: new Date(),
|
|
87
157
|
};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
158
|
+
logger.debug("fetched media conn");
|
|
159
|
+
return node;
|
|
160
|
+
})();
|
|
161
|
+
}
|
|
162
|
+
return mediaConn;
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* generic send receipt function
|
|
166
|
+
* used for receipts of phone call, read, delivery etc.
|
|
167
|
+
* */
|
|
168
|
+
const sendReceipt = async (jid, participant, messageIds, type) => {
|
|
169
|
+
if (!messageIds || messageIds.length === 0) {
|
|
170
|
+
throw new Boom("missing ids in receipt");
|
|
171
|
+
}
|
|
172
|
+
const node = {
|
|
173
|
+
tag: "receipt",
|
|
174
|
+
attrs: {
|
|
175
|
+
id: messageIds[0],
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
const isReadReceipt = type === "read" || type === "read-self";
|
|
179
|
+
if (isReadReceipt) {
|
|
180
|
+
node.attrs.t = unixTimestampSeconds().toString();
|
|
181
|
+
}
|
|
182
|
+
if (type === "sender" && (isPnUser(jid) || isLidUser(jid))) {
|
|
183
|
+
node.attrs.recipient = jid;
|
|
184
|
+
node.attrs.to = participant;
|
|
185
|
+
} else {
|
|
186
|
+
node.attrs.to = jid;
|
|
187
|
+
if (participant) {
|
|
188
|
+
node.attrs.participant = participant;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (type) {
|
|
192
|
+
node.attrs.type = type;
|
|
193
|
+
}
|
|
194
|
+
const remainingMessageIds = messageIds.slice(1);
|
|
195
|
+
if (remainingMessageIds.length) {
|
|
196
|
+
node.content = [
|
|
197
|
+
{
|
|
198
|
+
tag: "list",
|
|
199
|
+
attrs: {},
|
|
200
|
+
content: remainingMessageIds.map((id) => ({
|
|
201
|
+
tag: "item",
|
|
202
|
+
attrs: { id },
|
|
203
|
+
})),
|
|
204
|
+
},
|
|
205
|
+
];
|
|
206
|
+
}
|
|
207
|
+
logger.debug(
|
|
208
|
+
{ attrs: node.attrs, messageIds },
|
|
209
|
+
"sending receipt for messages",
|
|
210
|
+
);
|
|
211
|
+
await sendNode(node);
|
|
212
|
+
};
|
|
213
|
+
/** Correctly bulk send receipts to multiple chats, participants */
|
|
214
|
+
const sendReceipts = async (keys, type) => {
|
|
215
|
+
const recps = aggregateMessageKeysNotFromMe(keys);
|
|
216
|
+
for (const { jid, participant, messageIds } of recps) {
|
|
217
|
+
await sendReceipt(jid, participant, messageIds, type);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
/** Bulk read messages. Keys can be from different chats & participants */
|
|
221
|
+
const readMessages = async (keys) => {
|
|
222
|
+
const privacySettings = await fetchPrivacySettings();
|
|
223
|
+
// based on privacy settings, we have to change the read type
|
|
224
|
+
const readType =
|
|
225
|
+
privacySettings.readreceipts === "all" ? "read" : "read-self";
|
|
226
|
+
await sendReceipts(keys, readType);
|
|
227
|
+
};
|
|
228
|
+
/** Fetch all the devices we've to send a message to */
|
|
229
|
+
const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
|
|
230
|
+
const deviceResults = [];
|
|
231
|
+
if (!useCache) {
|
|
232
|
+
logger.debug("not using cache for devices");
|
|
233
|
+
}
|
|
234
|
+
const toFetch = [];
|
|
235
|
+
const jidsWithUser = jids
|
|
236
|
+
.map((jid) => {
|
|
237
|
+
const decoded = jidDecode(jid);
|
|
238
|
+
const user = decoded?.user;
|
|
239
|
+
const device = decoded?.device;
|
|
240
|
+
const isExplicitDevice = typeof device === "number" && device >= 0;
|
|
241
|
+
if (isExplicitDevice && user) {
|
|
242
|
+
deviceResults.push({
|
|
243
|
+
user,
|
|
244
|
+
device,
|
|
245
|
+
jid,
|
|
246
|
+
});
|
|
247
|
+
return null;
|
|
101
248
|
}
|
|
102
|
-
|
|
103
|
-
|
|
249
|
+
jid = jidNormalizedUser(jid);
|
|
250
|
+
return { jid, user };
|
|
251
|
+
})
|
|
252
|
+
.filter((jid) => jid !== null);
|
|
253
|
+
let mgetDevices;
|
|
254
|
+
if (useCache && userDevicesCache.mget) {
|
|
255
|
+
const usersToFetch = jidsWithUser.map((j) => j?.user).filter(Boolean);
|
|
256
|
+
mgetDevices = await userDevicesCache.mget(usersToFetch);
|
|
257
|
+
}
|
|
258
|
+
for (const { jid, user } of jidsWithUser) {
|
|
259
|
+
if (useCache) {
|
|
260
|
+
const devices =
|
|
261
|
+
mgetDevices?.[user] ||
|
|
262
|
+
(userDevicesCache.mget
|
|
263
|
+
? undefined
|
|
264
|
+
: await userDevicesCache.get(user));
|
|
265
|
+
if (devices) {
|
|
266
|
+
const devicesWithJid = devices.map((d) => ({
|
|
267
|
+
...d,
|
|
268
|
+
jid: jidEncode(d.user, d.server, d.device),
|
|
269
|
+
}));
|
|
270
|
+
deviceResults.push(...devicesWithJid);
|
|
271
|
+
logger.trace({ user }, "using cache for devices");
|
|
272
|
+
} else {
|
|
273
|
+
toFetch.push(jid);
|
|
104
274
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
275
|
+
} else {
|
|
276
|
+
toFetch.push(jid);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
if (!toFetch.length) {
|
|
280
|
+
return deviceResults;
|
|
281
|
+
}
|
|
282
|
+
const requestedLidUsers = new Set();
|
|
283
|
+
for (const jid of toFetch) {
|
|
284
|
+
if (isLidUser(jid) || isHostedLidUser(jid)) {
|
|
285
|
+
const user = jidDecode(jid)?.user;
|
|
286
|
+
if (user) requestedLidUsers.add(user);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
const query = new USyncQuery()
|
|
290
|
+
.withContext("message")
|
|
291
|
+
.withDeviceProtocol()
|
|
292
|
+
.withLIDProtocol();
|
|
293
|
+
for (const jid of toFetch) {
|
|
294
|
+
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
|
|
295
|
+
}
|
|
296
|
+
const result = await sock.executeUSyncQuery(query);
|
|
297
|
+
if (result) {
|
|
298
|
+
// TODO: LID MAP this stuff (lid protocol will now return lid with devices)
|
|
299
|
+
const lidResults = result.list.filter((a) => !!a.lid);
|
|
300
|
+
if (lidResults.length > 0) {
|
|
301
|
+
logger.trace("Storing LID maps from device call");
|
|
302
|
+
await signalRepository.lidMapping.storeLIDPNMappings(
|
|
303
|
+
lidResults.map((a) => ({ lid: a.lid, pn: a.id })),
|
|
304
|
+
);
|
|
305
|
+
// Force-refresh sessions for newly mapped LIDs to align identity addressing
|
|
306
|
+
try {
|
|
307
|
+
const lids = lidResults.map((a) => a.lid);
|
|
308
|
+
if (lids.length) {
|
|
309
|
+
await assertSessions(lids, true);
|
|
310
|
+
}
|
|
311
|
+
} catch (e) {
|
|
312
|
+
logger.warn(
|
|
313
|
+
{ e, count: lidResults.length },
|
|
314
|
+
"failed to assert sessions for newly mapped LIDs",
|
|
315
|
+
);
|
|
117
316
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
317
|
+
}
|
|
318
|
+
const extracted = extractDeviceJids(
|
|
319
|
+
result?.list,
|
|
320
|
+
authState.creds.me.id,
|
|
321
|
+
authState.creds.me.lid,
|
|
322
|
+
ignoreZeroDevices,
|
|
323
|
+
);
|
|
324
|
+
const deviceMap = {};
|
|
325
|
+
for (const item of extracted) {
|
|
326
|
+
deviceMap[item.user] = deviceMap[item.user] || [];
|
|
327
|
+
deviceMap[item.user]?.push(item);
|
|
328
|
+
}
|
|
329
|
+
// Process each user's devices as a group for bulk LID migration
|
|
330
|
+
for (const [user, userDevices] of Object.entries(deviceMap)) {
|
|
331
|
+
const isLidUser = requestedLidUsers.has(user);
|
|
332
|
+
// Process all devices for this user
|
|
333
|
+
for (const item of userDevices) {
|
|
334
|
+
const finalJid = isLidUser
|
|
335
|
+
? jidEncode(user, item.server, item.device)
|
|
336
|
+
: jidEncode(item.user, item.server, item.device);
|
|
337
|
+
deviceResults.push({
|
|
338
|
+
...item,
|
|
339
|
+
jid: finalJid,
|
|
340
|
+
});
|
|
341
|
+
logger.debug(
|
|
342
|
+
{
|
|
343
|
+
user: item.user,
|
|
344
|
+
device: item.device,
|
|
345
|
+
finalJid,
|
|
346
|
+
usedLid: isLidUser,
|
|
347
|
+
},
|
|
348
|
+
"Processed device with LID priority",
|
|
349
|
+
);
|
|
126
350
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
|
|
137
|
-
const deviceResults = []
|
|
138
|
-
|
|
139
|
-
if (!useCache) {
|
|
140
|
-
logger.debug('not using cache for devices')
|
|
351
|
+
}
|
|
352
|
+
if (userDevicesCache.mset) {
|
|
353
|
+
// if the cache supports mset, we can set all devices in one go
|
|
354
|
+
await userDevicesCache.mset(
|
|
355
|
+
Object.entries(deviceMap).map(([key, value]) => ({ key, value })),
|
|
356
|
+
);
|
|
357
|
+
} else {
|
|
358
|
+
for (const key in deviceMap) {
|
|
359
|
+
if (deviceMap[key]) await userDevicesCache.set(key, deviceMap[key]);
|
|
141
360
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
jid = WABinary_1.jidNormalizedUser(jid)
|
|
151
|
-
|
|
152
|
-
if (useCache) {
|
|
153
|
-
const devices = userDevicesCache.get(user)
|
|
154
|
-
|
|
155
|
-
if (devices) {
|
|
156
|
-
deviceResults.push(...devices)
|
|
157
|
-
logger.trace({ user }, 'using cache for devices')
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
else {
|
|
161
|
-
toFetch.push(jid)
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
else {
|
|
166
|
-
toFetch.push(jid)
|
|
167
|
-
}
|
|
361
|
+
}
|
|
362
|
+
const userDeviceUpdates = {};
|
|
363
|
+
for (const [userId, devices] of Object.entries(deviceMap)) {
|
|
364
|
+
if (devices && devices.length > 0) {
|
|
365
|
+
userDeviceUpdates[userId] = devices.map(
|
|
366
|
+
(d) => d.device?.toString() || "0",
|
|
367
|
+
);
|
|
168
368
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
369
|
+
}
|
|
370
|
+
if (Object.keys(userDeviceUpdates).length > 0) {
|
|
371
|
+
try {
|
|
372
|
+
await authState.keys.set({ "device-list": userDeviceUpdates });
|
|
373
|
+
logger.debug(
|
|
374
|
+
{ userCount: Object.keys(userDeviceUpdates).length },
|
|
375
|
+
"stored user device lists for bulk migration",
|
|
376
|
+
);
|
|
377
|
+
} catch (error) {
|
|
378
|
+
logger.warn({ error }, "failed to store user device lists");
|
|
172
379
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return deviceResults;
|
|
383
|
+
};
|
|
384
|
+
/**
|
|
385
|
+
* Update Member Label
|
|
386
|
+
*/
|
|
387
|
+
const updateMemberLabel = (jid, memberLabel) => {
|
|
388
|
+
return relayMessage(
|
|
389
|
+
jid,
|
|
390
|
+
{
|
|
391
|
+
protocolMessage: {
|
|
392
|
+
type: proto.Message.ProtocolMessage.Type.GROUP_MEMBER_LABEL_CHANGE,
|
|
393
|
+
memberLabel: {
|
|
394
|
+
label: memberLabel?.slice(0, 30),
|
|
395
|
+
labelTimestamp: unixTimestampSeconds(),
|
|
396
|
+
},
|
|
397
|
+
},
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
additionalNodes: [
|
|
401
|
+
{
|
|
402
|
+
tag: "meta",
|
|
403
|
+
attrs: {
|
|
404
|
+
tag_reason: "user_update",
|
|
405
|
+
appdata: "member_tag",
|
|
406
|
+
},
|
|
407
|
+
content: undefined,
|
|
408
|
+
},
|
|
409
|
+
],
|
|
410
|
+
},
|
|
411
|
+
);
|
|
412
|
+
};
|
|
413
|
+
const assertSessions = async (jids, force) => {
|
|
414
|
+
let didFetchNewSession = false;
|
|
415
|
+
const uniqueJids = [...new Set(jids)]; // Deduplicate JIDs
|
|
416
|
+
const jidsRequiringFetch = [];
|
|
417
|
+
logger.debug({ jids }, "assertSessions call with jids");
|
|
418
|
+
// Check peerSessionsCache and validate sessions using libsignal loadSession
|
|
419
|
+
for (const jid of uniqueJids) {
|
|
420
|
+
const signalId = signalRepository.jidToSignalProtocolAddress(jid);
|
|
421
|
+
const cachedSession = peerSessionsCache.get(signalId);
|
|
422
|
+
if (cachedSession !== undefined) {
|
|
423
|
+
if (cachedSession && !force) {
|
|
424
|
+
continue; // Session exists in cache
|
|
180
425
|
}
|
|
181
|
-
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
for (const item of extracted) {
|
|
189
|
-
deviceMap[item.user] = deviceMap[item.user] || []
|
|
190
|
-
deviceMap[item.user].push(item)
|
|
191
|
-
deviceResults.push(item)
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
for (const key in deviceMap) {
|
|
195
|
-
userDevicesCache.set(key, deviceMap[key])
|
|
196
|
-
}
|
|
426
|
+
} else {
|
|
427
|
+
const sessionValidation = await signalRepository.validateSession(jid);
|
|
428
|
+
const hasSession = sessionValidation.exists;
|
|
429
|
+
peerSessionsCache.set(signalId, hasSession);
|
|
430
|
+
if (hasSession && !force) {
|
|
431
|
+
continue;
|
|
197
432
|
}
|
|
198
|
-
|
|
199
|
-
|
|
433
|
+
}
|
|
434
|
+
jidsRequiringFetch.push(jid);
|
|
200
435
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
436
|
+
if (jidsRequiringFetch.length) {
|
|
437
|
+
// LID if mapped, otherwise original
|
|
438
|
+
const wireJids = [
|
|
439
|
+
...jidsRequiringFetch.filter(
|
|
440
|
+
(jid) => !!isLidUser(jid) || !!isHostedLidUser(jid),
|
|
441
|
+
),
|
|
442
|
+
...(
|
|
443
|
+
(await signalRepository.lidMapping.getLIDsForPNs(
|
|
444
|
+
jidsRequiringFetch.filter(
|
|
445
|
+
(jid) => !!isPnUser(jid) || !!isHostedPnUser(jid),
|
|
446
|
+
),
|
|
447
|
+
)) || []
|
|
448
|
+
).map((a) => a.lid),
|
|
449
|
+
];
|
|
450
|
+
logger.debug({ jidsRequiringFetch, wireJids }, "fetching sessions");
|
|
451
|
+
const result = await query({
|
|
452
|
+
tag: "iq",
|
|
453
|
+
attrs: {
|
|
454
|
+
xmlns: "encrypt",
|
|
455
|
+
type: "get",
|
|
456
|
+
to: S_WHATSAPP_NET,
|
|
457
|
+
},
|
|
458
|
+
content: [
|
|
459
|
+
{
|
|
460
|
+
tag: "key",
|
|
461
|
+
attrs: {},
|
|
462
|
+
content: wireJids.map((jid) => {
|
|
463
|
+
const attrs = { jid };
|
|
464
|
+
if (force) attrs.reason = "identity";
|
|
465
|
+
return { tag: "user", attrs };
|
|
466
|
+
}),
|
|
467
|
+
},
|
|
468
|
+
],
|
|
469
|
+
});
|
|
470
|
+
await parseAndInjectE2ESessions(result, signalRepository);
|
|
471
|
+
didFetchNewSession = true;
|
|
472
|
+
// Cache fetched sessions using wire JIDs
|
|
473
|
+
for (const wireJid of wireJids) {
|
|
474
|
+
const signalId = signalRepository.jidToSignalProtocolAddress(wireJid);
|
|
475
|
+
peerSessionsCache.set(signalId, true);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
return didFetchNewSession;
|
|
479
|
+
};
|
|
480
|
+
const sendPeerDataOperationMessage = async (pdoMessage) => {
|
|
481
|
+
//TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
|
|
482
|
+
if (!authState.creds.me?.id) {
|
|
483
|
+
throw new Boom("Not authenticated");
|
|
484
|
+
}
|
|
485
|
+
const protocolMessage = {
|
|
486
|
+
protocolMessage: {
|
|
487
|
+
peerDataOperationRequestMessage: pdoMessage,
|
|
488
|
+
type: proto.Message.ProtocolMessage.Type
|
|
489
|
+
.PEER_DATA_OPERATION_REQUEST_MESSAGE,
|
|
490
|
+
},
|
|
491
|
+
};
|
|
492
|
+
const meJid = jidNormalizedUser(authState.creds.me.id);
|
|
493
|
+
const msgId = await relayMessage(meJid, protocolMessage, {
|
|
494
|
+
additionalAttributes: {
|
|
495
|
+
category: "peer",
|
|
496
|
+
push_priority: "high_force",
|
|
497
|
+
},
|
|
498
|
+
additionalNodes: [
|
|
499
|
+
{
|
|
500
|
+
tag: "meta",
|
|
501
|
+
attrs: { appdata: "default" },
|
|
502
|
+
},
|
|
503
|
+
],
|
|
504
|
+
});
|
|
505
|
+
return msgId;
|
|
506
|
+
};
|
|
507
|
+
const createParticipantNodes = async (
|
|
508
|
+
recipientJids,
|
|
509
|
+
message,
|
|
510
|
+
extraAttrs,
|
|
511
|
+
dsmMessage,
|
|
512
|
+
) => {
|
|
513
|
+
if (!recipientJids.length) {
|
|
514
|
+
return { nodes: [], shouldIncludeDeviceIdentity: false };
|
|
515
|
+
}
|
|
516
|
+
const patched = await patchMessageBeforeSending(message, recipientJids);
|
|
517
|
+
const patchedMessages = Array.isArray(patched)
|
|
518
|
+
? patched
|
|
519
|
+
: recipientJids.map((jid) => ({ recipientJid: jid, message: patched }));
|
|
520
|
+
let shouldIncludeDeviceIdentity = false;
|
|
521
|
+
const meId = authState.creds.me.id;
|
|
522
|
+
const meLid = authState.creds.me?.lid;
|
|
523
|
+
const meLidUser = meLid ? jidDecode(meLid)?.user : null;
|
|
524
|
+
const encryptionPromises = patchedMessages.map(
|
|
525
|
+
async ({ recipientJid: jid, message: patchedMessage }) => {
|
|
526
|
+
try {
|
|
527
|
+
if (!jid) return null;
|
|
528
|
+
let msgToEncrypt = patchedMessage;
|
|
529
|
+
if (dsmMessage) {
|
|
530
|
+
const { user: targetUser } = jidDecode(jid);
|
|
531
|
+
const { user: ownPnUser } = jidDecode(meId);
|
|
532
|
+
const ownLidUser = meLidUser;
|
|
533
|
+
const isOwnUser =
|
|
534
|
+
targetUser === ownPnUser ||
|
|
535
|
+
(ownLidUser && targetUser === ownLidUser);
|
|
536
|
+
const isExactSenderDevice =
|
|
537
|
+
jid === meId || (meLid && jid === meLid);
|
|
538
|
+
if (isOwnUser && !isExactSenderDevice) {
|
|
539
|
+
msgToEncrypt = dsmMessage;
|
|
540
|
+
logger.debug({ jid, targetUser }, "Using DSM for own device");
|
|
217
541
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
type: 'get',
|
|
226
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
227
|
-
},
|
|
228
|
-
content: [
|
|
229
|
-
{
|
|
230
|
-
tag: 'key',
|
|
231
|
-
attrs: {},
|
|
232
|
-
content: jidsRequiringFetch.map(jid => ({
|
|
233
|
-
tag: 'user',
|
|
234
|
-
attrs: { jid },
|
|
235
|
-
}))
|
|
236
|
-
}
|
|
237
|
-
]
|
|
542
|
+
}
|
|
543
|
+
const bytes = encodeWAMessage(msgToEncrypt);
|
|
544
|
+
const mutexKey = jid;
|
|
545
|
+
const node = await encryptionMutex.mutex(mutexKey, async () => {
|
|
546
|
+
const { type, ciphertext } = await signalRepository.encryptMessage({
|
|
547
|
+
jid,
|
|
548
|
+
data: bytes,
|
|
238
549
|
});
|
|
239
|
-
|
|
240
|
-
|
|
550
|
+
if (type === "pkmsg") {
|
|
551
|
+
shouldIncludeDeviceIdentity = true;
|
|
552
|
+
}
|
|
553
|
+
return {
|
|
554
|
+
tag: "to",
|
|
555
|
+
attrs: { jid },
|
|
556
|
+
content: [
|
|
557
|
+
{
|
|
558
|
+
tag: "enc",
|
|
559
|
+
attrs: { v: "2", type, ...(extraAttrs || {}) },
|
|
560
|
+
content: ciphertext,
|
|
561
|
+
},
|
|
562
|
+
],
|
|
563
|
+
};
|
|
564
|
+
});
|
|
565
|
+
return node;
|
|
566
|
+
} catch (err) {
|
|
567
|
+
logger.error({ jid, err }, "Failed to encrypt for recipient");
|
|
568
|
+
return null;
|
|
241
569
|
}
|
|
242
|
-
|
|
570
|
+
},
|
|
571
|
+
);
|
|
572
|
+
const nodes = (await Promise.all(encryptionPromises)).filter(
|
|
573
|
+
(node) => node !== null,
|
|
574
|
+
);
|
|
575
|
+
if (recipientJids.length > 0 && nodes.length === 0) {
|
|
576
|
+
throw new Boom("All encryptions failed", { statusCode: 500 });
|
|
577
|
+
}
|
|
578
|
+
return { nodes, shouldIncludeDeviceIdentity };
|
|
579
|
+
};
|
|
580
|
+
const relayMessage = async (
|
|
581
|
+
jid,
|
|
582
|
+
message,
|
|
583
|
+
{
|
|
584
|
+
messageId: msgId,
|
|
585
|
+
participant,
|
|
586
|
+
additionalAttributes,
|
|
587
|
+
additionalNodes,
|
|
588
|
+
useUserDevicesCache,
|
|
589
|
+
useCachedGroupMetadata,
|
|
590
|
+
statusJidList,
|
|
591
|
+
},
|
|
592
|
+
) => {
|
|
593
|
+
const meId = authState.creds.me.id;
|
|
594
|
+
const meLid = authState.creds.me?.lid;
|
|
595
|
+
const isRetryResend = Boolean(participant?.jid);
|
|
596
|
+
let shouldIncludeDeviceIdentity = isRetryResend;
|
|
597
|
+
const statusJid = "status@broadcast";
|
|
598
|
+
const { user, server } = jidDecode(jid);
|
|
599
|
+
const isGroup = server === "g.us";
|
|
600
|
+
const isStatus = jid === statusJid;
|
|
601
|
+
const isLid = server === "lid";
|
|
602
|
+
const isNewsletter = server === "newsletter";
|
|
603
|
+
const isGroupOrStatus = isGroup || isStatus;
|
|
604
|
+
const finalJid = jid;
|
|
605
|
+
msgId = msgId || generateMessageIDV2(meId);
|
|
606
|
+
useUserDevicesCache = useUserDevicesCache !== false;
|
|
607
|
+
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
|
|
608
|
+
const participants = [];
|
|
609
|
+
const destinationJid = !isStatus ? finalJid : statusJid;
|
|
610
|
+
const binaryNodeContent = [];
|
|
611
|
+
const devices = [];
|
|
612
|
+
let reportingMessage;
|
|
613
|
+
const meMsg = {
|
|
614
|
+
deviceSentMessage: {
|
|
615
|
+
destinationJid,
|
|
616
|
+
message,
|
|
617
|
+
},
|
|
618
|
+
messageContextInfo: message.messageContextInfo,
|
|
243
619
|
};
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
const protocolMessage = {
|
|
252
|
-
protocolMessage: {
|
|
253
|
-
peerDataOperationRequestMessage: pdoMessage,
|
|
254
|
-
type: WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
|
|
255
|
-
}
|
|
620
|
+
const extraAttrs = {};
|
|
621
|
+
if (participant) {
|
|
622
|
+
if (!isGroup && !isStatus) {
|
|
623
|
+
additionalAttributes = {
|
|
624
|
+
...additionalAttributes,
|
|
625
|
+
device_fanout: "false",
|
|
256
626
|
};
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
627
|
+
}
|
|
628
|
+
const { user, device } = jidDecode(participant.jid);
|
|
629
|
+
devices.push({
|
|
630
|
+
user,
|
|
631
|
+
device,
|
|
632
|
+
jid: participant.jid,
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
await authState.keys.transaction(async () => {
|
|
636
|
+
const mediaType = getMediaType(
|
|
637
|
+
normalizeMessageContent(message) || message,
|
|
638
|
+
);
|
|
639
|
+
if (mediaType) {
|
|
640
|
+
extraAttrs["mediatype"] = mediaType;
|
|
641
|
+
}
|
|
642
|
+
if (isNewsletter) {
|
|
643
|
+
const patched = patchMessageBeforeSending
|
|
644
|
+
? await patchMessageBeforeSending(message, [])
|
|
645
|
+
: message;
|
|
646
|
+
const bytes = encodeNewsletterMessage(patched);
|
|
647
|
+
binaryNodeContent.push({
|
|
648
|
+
tag: "plaintext",
|
|
649
|
+
attrs: extraAttrs || {},
|
|
650
|
+
content: bytes,
|
|
264
651
|
});
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
if (type === 'pkmsg') {
|
|
275
|
-
shouldIncludeDeviceIdentity = true;
|
|
276
|
-
}
|
|
277
|
-
const node = {
|
|
278
|
-
tag: 'to',
|
|
279
|
-
attrs: { jid },
|
|
280
|
-
content: [{
|
|
281
|
-
tag: 'enc',
|
|
282
|
-
attrs: {
|
|
283
|
-
v: '2',
|
|
284
|
-
type,
|
|
285
|
-
...extraAttrs || {}
|
|
286
|
-
},
|
|
287
|
-
content: ciphertext
|
|
288
|
-
}]
|
|
289
|
-
};
|
|
290
|
-
return node;
|
|
291
|
-
}));
|
|
292
|
-
return { nodes, shouldIncludeDeviceIdentity };
|
|
293
|
-
}; //apela
|
|
294
|
-
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, useCachedGroupMetadata, statusJidList, AI = true }) => {
|
|
295
|
-
const meId = authState.creds.me.id;
|
|
296
|
-
let shouldIncludeDeviceIdentity = false;
|
|
297
|
-
let didPushAdditional = false
|
|
298
|
-
const { user, server } = WABinary_1.jidDecode(jid);
|
|
299
|
-
const statusJid = 'status@broadcast';
|
|
300
|
-
const isGroup = server === 'g.us';
|
|
301
|
-
const isStatus = jid === statusJid;
|
|
302
|
-
const isLid = server === 'lid';
|
|
303
|
-
const isPrivate = server === 's.whatsapp.net'
|
|
304
|
-
const isNewsletter = server === 'newsletter';
|
|
305
|
-
msgId = msgId || (0, Utils_1.generateMessageID)();
|
|
306
|
-
useUserDevicesCache = useUserDevicesCache !== false;
|
|
307
|
-
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus
|
|
308
|
-
const participants = [];
|
|
309
|
-
const destinationJid = (!isStatus) ? WABinary_1.jidEncode(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
|
|
310
|
-
const binaryNodeContent = [];
|
|
311
|
-
const devices = [];
|
|
312
|
-
const meMsg = {
|
|
313
|
-
deviceSentMessage: {
|
|
314
|
-
destinationJid,
|
|
315
|
-
message
|
|
316
|
-
}
|
|
652
|
+
const stanza = {
|
|
653
|
+
tag: "message",
|
|
654
|
+
attrs: {
|
|
655
|
+
to: jid,
|
|
656
|
+
id: msgId,
|
|
657
|
+
type: getMessageType(message),
|
|
658
|
+
...(additionalAttributes || {}),
|
|
659
|
+
},
|
|
660
|
+
content: binaryNodeContent,
|
|
317
661
|
};
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
if (messages.interactiveResponseMessage?.nativeFlowResponseMessage) {
|
|
343
|
-
extraAttrs['native_flow_name'] = messages.interactiveResponseMessage?.nativeFlowResponseMessage.name
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
if (isGroup || isStatus) {
|
|
347
|
-
const [groupData, senderKeyMap] = await Promise.all([
|
|
348
|
-
(async () => {
|
|
349
|
-
let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined
|
|
350
|
-
if (groupData) {
|
|
351
|
-
logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
else if (!isStatus) {
|
|
355
|
-
groupData = await groupMetadata(jid)
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
return groupData;
|
|
359
|
-
})(),
|
|
360
|
-
(async () => {
|
|
361
|
-
if (!participant && !isStatus) {
|
|
362
|
-
const result = await authState.keys.get('sender-key-memory', [jid])
|
|
363
|
-
return result[jid] || {}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
return {}
|
|
367
|
-
|
|
368
|
-
})()
|
|
369
|
-
]);
|
|
370
|
-
if (!participant) {
|
|
371
|
-
const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : []
|
|
372
|
-
|
|
373
|
-
if (isStatus && statusJidList) {
|
|
374
|
-
participantsList.push(...statusJidList)
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
// if (!isStatus) {
|
|
378
|
-
// const expiration = await getEphemeralGroup(jid)
|
|
379
|
-
// additionalAttributes = {
|
|
380
|
-
// ...additionalAttributes,
|
|
381
|
-
// addressing_mode: 'pn',
|
|
382
|
-
// ...expiration ? { expiration: expiration.toString() } : null
|
|
383
|
-
// }
|
|
384
|
-
// }
|
|
385
|
-
|
|
386
|
-
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false)
|
|
387
|
-
devices.push(...additionalDevices)
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
const patched = await patchMessageBeforeSending(message, devices.map(d => WABinary_1.jidEncode(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device)));
|
|
391
|
-
const bytes = Utils_1.encodeWAMessage(patched);
|
|
392
|
-
|
|
393
|
-
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
|
|
394
|
-
group: destinationJid,
|
|
395
|
-
data: bytes,
|
|
396
|
-
meId,
|
|
397
|
-
});
|
|
398
|
-
const senderKeyJids = [];
|
|
399
|
-
|
|
400
|
-
for (const { user, device } of devices) {
|
|
401
|
-
const jid = WABinary_1.jidEncode(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
|
|
402
|
-
if (!senderKeyMap[jid] || !!participant) {
|
|
403
|
-
senderKeyJids.push(jid);
|
|
404
|
-
// store that this person has had the sender keys sent to them
|
|
405
|
-
senderKeyMap[jid] = true;
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
// if there are some participants with whom the session has not been established
|
|
409
|
-
// if there are, we re-send the senderkey
|
|
410
|
-
if (senderKeyJids.length) {
|
|
411
|
-
logger.debug({ senderKeyJids }, 'sending new sender key');
|
|
412
|
-
const senderKeyMsg = {
|
|
413
|
-
senderKeyDistributionMessage: {
|
|
414
|
-
axolotlSenderKeyDistributionMessage: senderKeyDistributionMessage,
|
|
415
|
-
groupId: destinationJid
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
await assertSessions(senderKeyJids, false);
|
|
419
|
-
const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, extraAttrs)
|
|
420
|
-
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
|
|
421
|
-
participants.push(...result.nodes);
|
|
422
|
-
}
|
|
423
|
-
binaryNodeContent.push({
|
|
424
|
-
tag: 'enc',
|
|
425
|
-
attrs: { v: '2', type: 'skmsg', ...extraAttrs },
|
|
426
|
-
content: ciphertext
|
|
427
|
-
});
|
|
428
|
-
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
|
|
429
|
-
}
|
|
430
|
-
else if (isNewsletter) {
|
|
431
|
-
// Message edit
|
|
432
|
-
if (message.protocolMessage?.editedMessage) {
|
|
433
|
-
msgId = message.protocolMessage.key?.id
|
|
434
|
-
message = message.protocolMessage.editedMessage
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
// Message delete
|
|
438
|
-
if (message.protocolMessage?.type === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
|
|
439
|
-
msgId = message.protocolMessage.key?.id
|
|
440
|
-
message = {}
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
const patched = await patchMessageBeforeSending(message, [])
|
|
444
|
-
const bytes = Utils_1.encodeNewsletterMessage(patched)
|
|
445
|
-
|
|
446
|
-
binaryNodeContent.push({
|
|
447
|
-
tag: 'plaintext',
|
|
448
|
-
attrs: extraAttrs ? extraAttrs : {},
|
|
449
|
-
content: bytes
|
|
450
|
-
})
|
|
451
|
-
}
|
|
452
|
-
else {
|
|
453
|
-
const { user: meUser } = WABinary_1.jidDecode(meId);
|
|
454
|
-
if (!participant) {
|
|
455
|
-
devices.push({ user })
|
|
456
|
-
if (user !== meUser) {
|
|
457
|
-
devices.push({ user: meUser })
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
if (additionalAttributes?.['category'] !== 'peer') {
|
|
461
|
-
const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true)
|
|
462
|
-
|
|
463
|
-
devices.push(...additionalDevices)
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
const allJids = [];
|
|
467
|
-
const meJids = [];
|
|
468
|
-
const otherJids = [];
|
|
469
|
-
for (const { user, device } of devices) {
|
|
470
|
-
const isMe = user === meUser
|
|
471
|
-
const jid = WABinary_1.jidEncode(isMe && isLid ? authState.creds?.me?.lid?.split(':')[0] || user : user, isLid ? 'lid' : 's.whatsapp.net', device)
|
|
472
|
-
|
|
473
|
-
if (isMe) {
|
|
474
|
-
meJids.push(jid)
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
else {
|
|
478
|
-
otherJids.push(jid)
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
allJids.push(jid)
|
|
482
|
-
}
|
|
483
|
-
await assertSessions(allJids, false);
|
|
484
|
-
const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
|
|
485
|
-
createParticipantNodes(meJids, meMsg, extraAttrs),
|
|
486
|
-
createParticipantNodes(otherJids, message, extraAttrs)
|
|
487
|
-
])
|
|
488
|
-
participants.push(...meNodes);
|
|
489
|
-
participants.push(...otherNodes);
|
|
490
|
-
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
|
|
491
|
-
}
|
|
492
|
-
if (participants.length) {
|
|
493
|
-
if (additionalAttributes?.['category'] === 'peer') {
|
|
494
|
-
const peerNode = participants[0]?.content?.[0]
|
|
495
|
-
|
|
496
|
-
if (peerNode) {
|
|
497
|
-
binaryNodeContent.push(peerNode) // push only enc
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
else {
|
|
502
|
-
binaryNodeContent.push({
|
|
503
|
-
tag: 'participants',
|
|
504
|
-
attrs: {},
|
|
505
|
-
content: participants
|
|
506
|
-
})
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
const stanza = {
|
|
511
|
-
tag: 'message',
|
|
512
|
-
attrs: {
|
|
513
|
-
id: msgId,
|
|
514
|
-
type: getTypeMessage(messages),
|
|
515
|
-
...(additionalAttributes || {})
|
|
516
|
-
},
|
|
517
|
-
content: binaryNodeContent
|
|
518
|
-
}
|
|
519
|
-
// if the participant to send to is explicitly specified (generally retry recp)
|
|
520
|
-
// ensure the message is only sent to that person
|
|
521
|
-
// if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
|
|
522
|
-
if (participant) {
|
|
523
|
-
if (WABinary_1.isJidGroup(destinationJid)) {
|
|
524
|
-
stanza.attrs.to = destinationJid;
|
|
525
|
-
stanza.attrs.participant = participant.jid;
|
|
526
|
-
}
|
|
527
|
-
else if (WABinary_1.areJidsSameUser(participant.jid, meId)) {
|
|
528
|
-
stanza.attrs.to = participant.jid;
|
|
529
|
-
stanza.attrs.recipient = destinationJid;
|
|
530
|
-
}
|
|
531
|
-
else {
|
|
532
|
-
stanza.attrs.to = participant.jid;
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
else {
|
|
536
|
-
stanza.attrs.to = destinationJid;
|
|
537
|
-
}
|
|
538
|
-
if (shouldIncludeDeviceIdentity) {
|
|
539
|
-
stanza.content.push({
|
|
540
|
-
tag: 'device-identity',
|
|
541
|
-
attrs: {},
|
|
542
|
-
content: (0, Utils_1.encodeSignedDeviceIdentity)(authState.creds.account, true)
|
|
543
|
-
});
|
|
544
|
-
logger.debug({ jid }, 'adding device identity');
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
if (AI && isPrivate) {
|
|
548
|
-
const botNode = {
|
|
549
|
-
tag: 'bot',
|
|
550
|
-
attrs: {
|
|
551
|
-
biz_bot: '1'
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
const filteredBizBot = WABinary_1.getBinaryNodeFilter(additionalNodes ? additionalNodes : [])
|
|
556
|
-
|
|
557
|
-
if (filteredBizBot) {
|
|
558
|
-
stanza.content.push(...additionalNodes)
|
|
559
|
-
didPushAdditional = true
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
else {
|
|
563
|
-
stanza.content.push(botNode)
|
|
564
|
-
}
|
|
662
|
+
logger.debug({ msgId }, `sending newsletter message to ${jid}`);
|
|
663
|
+
await sendNode(stanza);
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
if (
|
|
667
|
+
normalizeMessageContent(message)?.pinInChatMessage ||
|
|
668
|
+
normalizeMessageContent(message)?.reactionMessage
|
|
669
|
+
) {
|
|
670
|
+
extraAttrs["decrypt-fail"] = "hide"; // todo: expand for reactions and other types
|
|
671
|
+
}
|
|
672
|
+
if (isGroupOrStatus && !isRetryResend) {
|
|
673
|
+
const [groupData, senderKeyMap] = await Promise.all([
|
|
674
|
+
(async () => {
|
|
675
|
+
let groupData =
|
|
676
|
+
useCachedGroupMetadata && cachedGroupMetadata
|
|
677
|
+
? await cachedGroupMetadata(jid)
|
|
678
|
+
: undefined; // todo: should we rely on the cache specially if the cache is outdated and the metadata has new fields?
|
|
679
|
+
if (groupData && Array.isArray(groupData?.participants)) {
|
|
680
|
+
logger.trace(
|
|
681
|
+
{ jid, participants: groupData.participants.length },
|
|
682
|
+
"using cached group metadata",
|
|
683
|
+
);
|
|
684
|
+
} else if (!isStatus) {
|
|
685
|
+
groupData = await groupMetadata(jid); // TODO: start storing group participant list + addr mode in Signal & stop relying on this
|
|
565
686
|
}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
stanza.content.push(...content)
|
|
577
|
-
}
|
|
578
|
-
logger.debug({ jid }, 'adding business node')
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
if (!didPushAdditional && additionalNodes && additionalNodes.length > 0) {
|
|
582
|
-
stanza.content.push(...additionalNodes);
|
|
687
|
+
return groupData;
|
|
688
|
+
})(),
|
|
689
|
+
(async () => {
|
|
690
|
+
if (!participant && !isStatus) {
|
|
691
|
+
// what if sender memory is less accurate than the cached metadata
|
|
692
|
+
// on participant change in group, we should do sender memory manipulation
|
|
693
|
+
const result = await authState.keys.get("sender-key-memory", [
|
|
694
|
+
jid,
|
|
695
|
+
]); // TODO: check out what if the sender key memory doesn't include the LID stuff now?
|
|
696
|
+
return result[jid] || {};
|
|
583
697
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
id: msgId
|
|
596
|
-
},
|
|
597
|
-
message: message,
|
|
598
|
-
messageTimestamp: Utils_1.unixTimestampSeconds(new Date()),
|
|
599
|
-
messageStubParameters: [],
|
|
600
|
-
participant: WABinary_1.isJidGroup(jid) || WABinary_1.isJidStatusBroadcast(jid) ? meId : undefined,
|
|
601
|
-
status: Types_1.WAMessageStatus.PENDING
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
return Types_1.WAProto.WebMessageInfo.fromObject(messageJSON)
|
|
605
|
-
// return msgId;
|
|
606
|
-
};
|
|
607
|
-
const getTypeMessage = (msg) => {
|
|
608
|
-
const message = Utils_1.normalizeMessageContent(msg)
|
|
609
|
-
if (message.reactionMessage) {
|
|
610
|
-
return 'reaction'
|
|
611
|
-
}
|
|
612
|
-
else if (getMediaType(message)) {
|
|
613
|
-
return 'media'
|
|
614
|
-
}
|
|
615
|
-
else {
|
|
616
|
-
return 'text'
|
|
698
|
+
return {};
|
|
699
|
+
})(),
|
|
700
|
+
]);
|
|
701
|
+
const participantsList = groupData
|
|
702
|
+
? groupData.participants.map((p) => p.id)
|
|
703
|
+
: [];
|
|
704
|
+
if (groupData?.ephemeralDuration && groupData.ephemeralDuration > 0) {
|
|
705
|
+
additionalAttributes = {
|
|
706
|
+
...additionalAttributes,
|
|
707
|
+
expiration: groupData.ephemeralDuration.toString(),
|
|
708
|
+
};
|
|
617
709
|
}
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
const getMediaType = (message) => {
|
|
621
|
-
if (message.imageMessage) {
|
|
622
|
-
return 'image'
|
|
623
|
-
}
|
|
624
|
-
else if (message.videoMessage) {
|
|
625
|
-
return message.videoMessage.gifPlayback ? 'gif' : 'video'
|
|
626
|
-
}
|
|
627
|
-
else if (message.audioMessage) {
|
|
628
|
-
return message.audioMessage.ptt ? 'ptt' : 'audio'
|
|
710
|
+
if (isStatus && statusJidList) {
|
|
711
|
+
participantsList.push(...statusJidList);
|
|
629
712
|
}
|
|
630
|
-
|
|
631
|
-
|
|
713
|
+
const additionalDevices = await getUSyncDevices(
|
|
714
|
+
participantsList,
|
|
715
|
+
!!useUserDevicesCache,
|
|
716
|
+
false,
|
|
717
|
+
);
|
|
718
|
+
devices.push(...additionalDevices);
|
|
719
|
+
if (isGroup) {
|
|
720
|
+
additionalAttributes = {
|
|
721
|
+
...additionalAttributes,
|
|
722
|
+
addressing_mode: groupData?.addressingMode || "lid",
|
|
723
|
+
};
|
|
632
724
|
}
|
|
633
|
-
|
|
634
|
-
|
|
725
|
+
const patched = await patchMessageBeforeSending(message);
|
|
726
|
+
if (Array.isArray(patched)) {
|
|
727
|
+
throw new Boom("Per-jid patching is not supported in groups");
|
|
635
728
|
}
|
|
636
|
-
|
|
637
|
-
|
|
729
|
+
const bytes = encodeWAMessage(patched);
|
|
730
|
+
reportingMessage = patched;
|
|
731
|
+
const groupAddressingMode =
|
|
732
|
+
additionalAttributes?.["addressing_mode"] ||
|
|
733
|
+
groupData?.addressingMode ||
|
|
734
|
+
"lid";
|
|
735
|
+
const groupSenderIdentity =
|
|
736
|
+
groupAddressingMode === "lid" && meLid ? meLid : meId;
|
|
737
|
+
const { ciphertext, senderKeyDistributionMessage } =
|
|
738
|
+
await signalRepository.encryptGroupMessage({
|
|
739
|
+
group: destinationJid,
|
|
740
|
+
data: bytes,
|
|
741
|
+
meId: groupSenderIdentity,
|
|
742
|
+
});
|
|
743
|
+
const senderKeyRecipients = [];
|
|
744
|
+
for (const device of devices) {
|
|
745
|
+
const deviceJid = device.jid;
|
|
746
|
+
const hasKey = !!senderKeyMap[deviceJid];
|
|
747
|
+
if (
|
|
748
|
+
(!hasKey || !!participant) &&
|
|
749
|
+
!isHostedLidUser(deviceJid) &&
|
|
750
|
+
!isHostedPnUser(deviceJid) &&
|
|
751
|
+
device.device !== 99
|
|
752
|
+
) {
|
|
753
|
+
//todo: revamp all this logic
|
|
754
|
+
// 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
|
|
755
|
+
senderKeyRecipients.push(deviceJid);
|
|
756
|
+
senderKeyMap[deviceJid] = true;
|
|
757
|
+
}
|
|
638
758
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
759
|
+
if (senderKeyRecipients.length) {
|
|
760
|
+
logger.debug(
|
|
761
|
+
{ senderKeyJids: senderKeyRecipients },
|
|
762
|
+
"sending new sender key",
|
|
763
|
+
);
|
|
764
|
+
const senderKeyMsg = {
|
|
765
|
+
senderKeyDistributionMessage: {
|
|
766
|
+
axolotlSenderKeyDistributionMessage: senderKeyDistributionMessage,
|
|
767
|
+
groupId: destinationJid,
|
|
768
|
+
},
|
|
769
|
+
};
|
|
770
|
+
const senderKeySessionTargets = senderKeyRecipients;
|
|
771
|
+
await assertSessions(senderKeySessionTargets);
|
|
772
|
+
const result = await createParticipantNodes(
|
|
773
|
+
senderKeyRecipients,
|
|
774
|
+
senderKeyMsg,
|
|
775
|
+
extraAttrs,
|
|
776
|
+
);
|
|
777
|
+
shouldIncludeDeviceIdentity =
|
|
778
|
+
shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
|
|
779
|
+
participants.push(...result.nodes);
|
|
644
780
|
}
|
|
645
|
-
|
|
646
|
-
|
|
781
|
+
binaryNodeContent.push({
|
|
782
|
+
tag: "enc",
|
|
783
|
+
attrs: { v: "2", type: "skmsg", ...extraAttrs },
|
|
784
|
+
content: ciphertext,
|
|
785
|
+
});
|
|
786
|
+
await authState.keys.set({
|
|
787
|
+
"sender-key-memory": { [jid]: senderKeyMap },
|
|
788
|
+
});
|
|
789
|
+
} else {
|
|
790
|
+
// ADDRESSING CONSISTENCY: Match own identity to conversation context
|
|
791
|
+
// TODO: investigate if this is true
|
|
792
|
+
let ownId = meId;
|
|
793
|
+
if (isLid && meLid) {
|
|
794
|
+
ownId = meLid;
|
|
795
|
+
logger.debug(
|
|
796
|
+
{ to: jid, ownId },
|
|
797
|
+
"Using LID identity for @lid conversation",
|
|
798
|
+
);
|
|
799
|
+
} else {
|
|
800
|
+
logger.debug(
|
|
801
|
+
{ to: jid, ownId },
|
|
802
|
+
"Using PN identity for @s.whatsapp.net conversation",
|
|
803
|
+
);
|
|
647
804
|
}
|
|
648
|
-
|
|
649
|
-
|
|
805
|
+
const { user: ownUser } = jidDecode(ownId);
|
|
806
|
+
if (!participant) {
|
|
807
|
+
const patchedForReporting = await patchMessageBeforeSending(message, [
|
|
808
|
+
jid,
|
|
809
|
+
]);
|
|
810
|
+
reportingMessage = Array.isArray(patchedForReporting)
|
|
811
|
+
? patchedForReporting.find((item) => item.recipientJid === jid) ||
|
|
812
|
+
patchedForReporting[0]
|
|
813
|
+
: patchedForReporting;
|
|
650
814
|
}
|
|
651
|
-
|
|
652
|
-
|
|
815
|
+
if (!isRetryResend) {
|
|
816
|
+
const targetUserServer = isLid ? "lid" : "s.whatsapp.net";
|
|
817
|
+
devices.push({
|
|
818
|
+
user,
|
|
819
|
+
device: 0,
|
|
820
|
+
jid: jidEncode(user, targetUserServer, 0), // rajeh, todo: this entire logic is convoluted and weird.
|
|
821
|
+
});
|
|
822
|
+
if (user !== ownUser) {
|
|
823
|
+
const ownUserServer = isLid ? "lid" : "s.whatsapp.net";
|
|
824
|
+
const ownUserForAddressing =
|
|
825
|
+
isLid && meLid ? jidDecode(meLid).user : jidDecode(meId).user;
|
|
826
|
+
devices.push({
|
|
827
|
+
user: ownUserForAddressing,
|
|
828
|
+
device: 0,
|
|
829
|
+
jid: jidEncode(ownUserForAddressing, ownUserServer, 0),
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
if (additionalAttributes?.["category"] !== "peer") {
|
|
833
|
+
// Clear placeholders and enumerate actual devices
|
|
834
|
+
devices.length = 0;
|
|
835
|
+
// Use conversation-appropriate sender identity
|
|
836
|
+
const senderIdentity =
|
|
837
|
+
isLid && meLid
|
|
838
|
+
? jidEncode(jidDecode(meLid)?.user, "lid", undefined)
|
|
839
|
+
: jidEncode(jidDecode(meId)?.user, "s.whatsapp.net", undefined);
|
|
840
|
+
// Enumerate devices for sender and target with consistent addressing
|
|
841
|
+
const sessionDevices = await getUSyncDevices(
|
|
842
|
+
[senderIdentity, jid],
|
|
843
|
+
true,
|
|
844
|
+
false,
|
|
845
|
+
);
|
|
846
|
+
devices.push(...sessionDevices);
|
|
847
|
+
logger.debug(
|
|
848
|
+
{
|
|
849
|
+
deviceCount: devices.length,
|
|
850
|
+
devices: devices.map(
|
|
851
|
+
(d) => `${d.user}:${d.device}@${jidDecode(d.jid)?.server}`,
|
|
852
|
+
),
|
|
853
|
+
},
|
|
854
|
+
"Device enumeration complete with unified addressing",
|
|
855
|
+
);
|
|
856
|
+
}
|
|
653
857
|
}
|
|
654
|
-
|
|
655
|
-
|
|
858
|
+
const allRecipients = [];
|
|
859
|
+
const meRecipients = [];
|
|
860
|
+
const otherRecipients = [];
|
|
861
|
+
const { user: mePnUser } = jidDecode(meId);
|
|
862
|
+
const { user: meLidUser } = meLid ? jidDecode(meLid) : { user: null };
|
|
863
|
+
for (const { user, jid } of devices) {
|
|
864
|
+
const isExactSenderDevice = jid === meId || (meLid && jid === meLid);
|
|
865
|
+
if (isExactSenderDevice) {
|
|
866
|
+
logger.debug(
|
|
867
|
+
{ jid, meId, meLid },
|
|
868
|
+
"Skipping exact sender device (whatsmeow pattern)",
|
|
869
|
+
);
|
|
870
|
+
continue;
|
|
871
|
+
}
|
|
872
|
+
// Check if this is our device (could match either PN or LID user)
|
|
873
|
+
const isMe = user === mePnUser || user === meLidUser;
|
|
874
|
+
if (isMe) {
|
|
875
|
+
meRecipients.push(jid);
|
|
876
|
+
} else {
|
|
877
|
+
otherRecipients.push(jid);
|
|
878
|
+
}
|
|
879
|
+
allRecipients.push(jid);
|
|
656
880
|
}
|
|
657
|
-
|
|
658
|
-
|
|
881
|
+
await assertSessions(allRecipients);
|
|
882
|
+
const [
|
|
883
|
+
{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 },
|
|
884
|
+
{ nodes: otherNodes, shouldIncludeDeviceIdentity: s2 },
|
|
885
|
+
] = await Promise.all([
|
|
886
|
+
// For own devices: use DSM if available (1:1 chats only)
|
|
887
|
+
createParticipantNodes(meRecipients, meMsg || message, extraAttrs),
|
|
888
|
+
createParticipantNodes(otherRecipients, message, extraAttrs, meMsg),
|
|
889
|
+
]);
|
|
890
|
+
participants.push(...meNodes);
|
|
891
|
+
participants.push(...otherNodes);
|
|
892
|
+
if (meRecipients.length > 0 || otherRecipients.length > 0) {
|
|
893
|
+
extraAttrs["phash"] = generateParticipantHashV2([
|
|
894
|
+
...meRecipients,
|
|
895
|
+
...otherRecipients,
|
|
896
|
+
]);
|
|
659
897
|
}
|
|
660
|
-
|
|
661
|
-
|
|
898
|
+
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
|
|
899
|
+
}
|
|
900
|
+
if (isRetryResend) {
|
|
901
|
+
const isParticipantLid = isLidUser(participant.jid);
|
|
902
|
+
const isMe = areJidsSameUser(
|
|
903
|
+
participant.jid,
|
|
904
|
+
isParticipantLid ? meLid : meId,
|
|
905
|
+
);
|
|
906
|
+
const encodedMessageToSend = isMe
|
|
907
|
+
? encodeWAMessage({
|
|
908
|
+
deviceSentMessage: {
|
|
909
|
+
destinationJid,
|
|
910
|
+
message,
|
|
911
|
+
},
|
|
912
|
+
})
|
|
913
|
+
: encodeWAMessage(message);
|
|
914
|
+
const { type, ciphertext: encryptedContent } =
|
|
915
|
+
await signalRepository.encryptMessage({
|
|
916
|
+
data: encodedMessageToSend,
|
|
917
|
+
jid: participant.jid,
|
|
918
|
+
});
|
|
919
|
+
binaryNodeContent.push({
|
|
920
|
+
tag: "enc",
|
|
921
|
+
attrs: {
|
|
922
|
+
v: "2",
|
|
923
|
+
type,
|
|
924
|
+
count: participant.count.toString(),
|
|
925
|
+
},
|
|
926
|
+
content: encryptedContent,
|
|
927
|
+
});
|
|
928
|
+
}
|
|
929
|
+
if (participants.length) {
|
|
930
|
+
if (additionalAttributes?.["category"] === "peer") {
|
|
931
|
+
const peerNode = participants[0]?.content?.[0];
|
|
932
|
+
if (peerNode) {
|
|
933
|
+
binaryNodeContent.push(peerNode); // push only enc
|
|
934
|
+
}
|
|
935
|
+
} else {
|
|
936
|
+
binaryNodeContent.push({
|
|
937
|
+
tag: "participants",
|
|
938
|
+
attrs: {},
|
|
939
|
+
content: participants,
|
|
940
|
+
});
|
|
662
941
|
}
|
|
663
|
-
|
|
664
|
-
|
|
942
|
+
}
|
|
943
|
+
const stanza = {
|
|
944
|
+
tag: "message",
|
|
945
|
+
attrs: {
|
|
946
|
+
id: msgId,
|
|
947
|
+
to: destinationJid,
|
|
948
|
+
type: getMessageType(message),
|
|
949
|
+
...(additionalAttributes || {}),
|
|
950
|
+
},
|
|
951
|
+
content: binaryNodeContent,
|
|
952
|
+
};
|
|
953
|
+
// if the participant to send to is explicitly specified (generally retry recp)
|
|
954
|
+
// ensure the message is only sent to that person
|
|
955
|
+
// if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
|
|
956
|
+
if (participant) {
|
|
957
|
+
if (isJidGroup(destinationJid)) {
|
|
958
|
+
stanza.attrs.to = destinationJid;
|
|
959
|
+
stanza.attrs.participant = participant.jid;
|
|
960
|
+
} else if (areJidsSameUser(participant.jid, meId)) {
|
|
961
|
+
stanza.attrs.to = participant.jid;
|
|
962
|
+
stanza.attrs.recipient = destinationJid;
|
|
963
|
+
} else {
|
|
964
|
+
stanza.attrs.to = participant.jid;
|
|
665
965
|
}
|
|
666
|
-
|
|
667
|
-
|
|
966
|
+
} else {
|
|
967
|
+
stanza.attrs.to = destinationJid;
|
|
968
|
+
}
|
|
969
|
+
if (shouldIncludeDeviceIdentity) {
|
|
970
|
+
stanza.content.push({
|
|
971
|
+
tag: "device-identity",
|
|
972
|
+
attrs: {},
|
|
973
|
+
content: encodeSignedDeviceIdentity(authState.creds.account, true),
|
|
974
|
+
});
|
|
975
|
+
logger.debug({ jid }, "adding device identity");
|
|
976
|
+
}
|
|
977
|
+
if (
|
|
978
|
+
!isNewsletter &&
|
|
979
|
+
!isRetryResend &&
|
|
980
|
+
reportingMessage?.messageContextInfo?.messageSecret &&
|
|
981
|
+
shouldIncludeReportingToken(reportingMessage)
|
|
982
|
+
) {
|
|
983
|
+
try {
|
|
984
|
+
const encoded = encodeWAMessage(reportingMessage);
|
|
985
|
+
const reportingKey = {
|
|
986
|
+
id: msgId,
|
|
987
|
+
fromMe: true,
|
|
988
|
+
remoteJid: destinationJid,
|
|
989
|
+
participant: participant?.jid,
|
|
990
|
+
};
|
|
991
|
+
const reportingNode = await getMessageReportingToken(
|
|
992
|
+
encoded,
|
|
993
|
+
reportingMessage,
|
|
994
|
+
reportingKey,
|
|
995
|
+
);
|
|
996
|
+
if (reportingNode) {
|
|
997
|
+
stanza.content.push(reportingNode);
|
|
998
|
+
logger.trace({ jid }, "added reporting token to message");
|
|
999
|
+
}
|
|
1000
|
+
} catch (error) {
|
|
1001
|
+
logger.warn(
|
|
1002
|
+
{ jid, trace: error?.stack },
|
|
1003
|
+
"failed to attach reporting token",
|
|
1004
|
+
);
|
|
668
1005
|
}
|
|
1006
|
+
}
|
|
1007
|
+
const contactTcTokenData =
|
|
1008
|
+
!isGroup && !isRetryResend && !isStatus
|
|
1009
|
+
? await authState.keys.get("tctoken", [destinationJid])
|
|
1010
|
+
: {};
|
|
1011
|
+
const tcTokenBuffer = contactTcTokenData[destinationJid]?.token;
|
|
1012
|
+
if (tcTokenBuffer) {
|
|
1013
|
+
stanza.content.push({
|
|
1014
|
+
tag: "tctoken",
|
|
1015
|
+
attrs: {},
|
|
1016
|
+
content: tcTokenBuffer,
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
if (additionalNodes && additionalNodes.length > 0) {
|
|
1020
|
+
stanza.content.push(...additionalNodes);
|
|
1021
|
+
}
|
|
1022
|
+
const buttonType = getButtonType(message);
|
|
1023
|
+
if (buttonType && !isNewsletter && !isStatus) {
|
|
1024
|
+
const bizNodes = getAdditionalNode(buttonType);
|
|
1025
|
+
stanza.content.push(...bizNodes);
|
|
1026
|
+
}
|
|
1027
|
+
logger.debug(
|
|
1028
|
+
{ msgId },
|
|
1029
|
+
`sending message to ${participants.length} devices`,
|
|
1030
|
+
);
|
|
1031
|
+
await sendNode(stanza);
|
|
1032
|
+
// Add message to retry cache if enabled
|
|
1033
|
+
if (messageRetryManager && !participant) {
|
|
1034
|
+
messageRetryManager.addRecentMessage(destinationJid, msgId, message);
|
|
1035
|
+
}
|
|
1036
|
+
}, meId);
|
|
1037
|
+
return msgId;
|
|
1038
|
+
};
|
|
1039
|
+
const getMessageType = (message) => {
|
|
1040
|
+
const normalizedMessage = normalizeMessageContent(message);
|
|
1041
|
+
if (!normalizedMessage) return "text";
|
|
1042
|
+
if (
|
|
1043
|
+
normalizedMessage.reactionMessage ||
|
|
1044
|
+
normalizedMessage.encReactionMessage
|
|
1045
|
+
) {
|
|
1046
|
+
return "reaction";
|
|
669
1047
|
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
}
|
|
678
|
-
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'review_and_pay') {
|
|
679
|
-
return 'review_and_pay'
|
|
680
|
-
}
|
|
681
|
-
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'review_order') {
|
|
682
|
-
return 'review_order'
|
|
683
|
-
}
|
|
684
|
-
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_info') {
|
|
685
|
-
return 'payment_info'
|
|
686
|
-
}
|
|
687
|
-
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_status') {
|
|
688
|
-
return 'payment_status'
|
|
689
|
-
}
|
|
690
|
-
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_method') {
|
|
691
|
-
return 'payment_method'
|
|
692
|
-
}
|
|
693
|
-
else if (message.interactiveMessage && message.interactiveMessage?.nativeFlowMessage) {
|
|
694
|
-
return 'interactive'
|
|
695
|
-
}
|
|
696
|
-
else if (message.interactiveMessage?.nativeFlowMessage) {
|
|
697
|
-
return 'native_flow'
|
|
698
|
-
}
|
|
1048
|
+
if (
|
|
1049
|
+
normalizedMessage.pollCreationMessage ||
|
|
1050
|
+
normalizedMessage.pollCreationMessageV2 ||
|
|
1051
|
+
normalizedMessage.pollCreationMessageV3 ||
|
|
1052
|
+
normalizedMessage.pollUpdateMessage
|
|
1053
|
+
) {
|
|
1054
|
+
return "poll";
|
|
699
1055
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
1056
|
+
if (normalizedMessage.eventMessage) {
|
|
1057
|
+
return "event";
|
|
1058
|
+
}
|
|
1059
|
+
if (getMediaType(normalizedMessage) !== "") {
|
|
1060
|
+
return "media";
|
|
1061
|
+
}
|
|
1062
|
+
return "text";
|
|
1063
|
+
};
|
|
1064
|
+
const getMediaType = (message) => {
|
|
1065
|
+
if (message.imageMessage) {
|
|
1066
|
+
return "image";
|
|
1067
|
+
} else if (message.videoMessage) {
|
|
1068
|
+
return message.videoMessage.gifPlayback ? "gif" : "video";
|
|
1069
|
+
} else if (message.audioMessage) {
|
|
1070
|
+
return message.audioMessage.ptt ? "ptt" : "audio";
|
|
1071
|
+
} else if (message.contactMessage) {
|
|
1072
|
+
return "vcard";
|
|
1073
|
+
} else if (message.documentMessage) {
|
|
1074
|
+
return "document";
|
|
1075
|
+
} else if (message.contactsArrayMessage) {
|
|
1076
|
+
return "contact_array";
|
|
1077
|
+
} else if (message.liveLocationMessage) {
|
|
1078
|
+
return "livelocation";
|
|
1079
|
+
} else if (message.stickerMessage) {
|
|
1080
|
+
return message.stickerMessage.isLottie
|
|
1081
|
+
? "1p_sticker"
|
|
1082
|
+
: message.stickerMessage.isAvatar
|
|
1083
|
+
? "avatar_sticker"
|
|
1084
|
+
: "sticker";
|
|
1085
|
+
} else if (message.listMessage) {
|
|
1086
|
+
return "list";
|
|
1087
|
+
} else if (message.listResponseMessage) {
|
|
1088
|
+
return "list_response";
|
|
1089
|
+
} else if (message.buttonsResponseMessage) {
|
|
1090
|
+
return "buttons_response";
|
|
1091
|
+
} else if (message.orderMessage) {
|
|
1092
|
+
return "order";
|
|
1093
|
+
} else if (message.productMessage) {
|
|
1094
|
+
return "product";
|
|
1095
|
+
} else if (message.interactiveResponseMessage) {
|
|
1096
|
+
return "native_flow_response";
|
|
1097
|
+
} else if (message.groupInviteMessage) {
|
|
1098
|
+
return "url";
|
|
1099
|
+
}
|
|
1100
|
+
return "";
|
|
1101
|
+
};
|
|
1102
|
+
const getPrivacyTokens = async (jids) => {
|
|
1103
|
+
const t = unixTimestampSeconds().toString();
|
|
1104
|
+
const result = await query({
|
|
1105
|
+
tag: "iq",
|
|
1106
|
+
attrs: {
|
|
1107
|
+
to: S_WHATSAPP_NET,
|
|
1108
|
+
type: "set",
|
|
1109
|
+
xmlns: "privacy",
|
|
1110
|
+
},
|
|
1111
|
+
content: [
|
|
1112
|
+
{
|
|
1113
|
+
tag: "tokens",
|
|
1114
|
+
attrs: {},
|
|
1115
|
+
content: jids.map((jid) => ({
|
|
1116
|
+
tag: "token",
|
|
704
1117
|
attrs: {
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
1118
|
+
jid: jidNormalizedUser(jid),
|
|
1119
|
+
t,
|
|
1120
|
+
type: "trusted_contact",
|
|
708
1121
|
},
|
|
709
|
-
|
|
710
|
-
{
|
|
711
|
-
tag: 'tokens',
|
|
712
|
-
attrs: {},
|
|
713
|
-
content: jids.map(jid => ({
|
|
714
|
-
tag: 'token',
|
|
715
|
-
attrs: {
|
|
716
|
-
jid: WABinary_1.jidNormalizedUser(jid),
|
|
717
|
-
t,
|
|
718
|
-
type: 'trusted_contact'
|
|
719
|
-
}
|
|
720
|
-
}))
|
|
721
|
-
}
|
|
722
|
-
]
|
|
723
|
-
});
|
|
724
|
-
return result;
|
|
725
|
-
}
|
|
726
|
-
const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
|
|
727
|
-
const rahmi = new kikyy(Utils_1, waUploadToServer, relayMessage);
|
|
728
|
-
const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
|
|
729
|
-
return {
|
|
730
|
-
...sock,
|
|
731
|
-
getPrivacyTokens,
|
|
732
|
-
assertSessions,
|
|
733
|
-
relayMessage,
|
|
734
|
-
sendReceipt,
|
|
735
|
-
sendReceipts,
|
|
736
|
-
rahmi,
|
|
737
|
-
readMessages,
|
|
738
|
-
refreshMediaConn,
|
|
739
|
-
getUSyncDevices,
|
|
740
|
-
createParticipantNodes,
|
|
741
|
-
waUploadToServer,
|
|
742
|
-
sendPeerDataOperationMessage,
|
|
743
|
-
fetchPrivacySettings,
|
|
744
|
-
updateMediaMessage: async (message) => {
|
|
745
|
-
const content = (0, Utils_1.assertMediaContent)(message.message);
|
|
746
|
-
const mediaKey = content.mediaKey;
|
|
747
|
-
const meId = authState.creds.me.id;
|
|
748
|
-
const node = (0, Utils_1.encryptMediaRetryRequest)(message.key, mediaKey, meId);
|
|
749
|
-
let error = undefined;
|
|
750
|
-
await Promise.all([
|
|
751
|
-
sendNode(node),
|
|
752
|
-
waitForMsgMediaUpdate(update => {
|
|
753
|
-
const result = update.find(c => c.key.id === message.key.id);
|
|
754
|
-
if (result) {
|
|
755
|
-
if (result.error) {
|
|
756
|
-
error = result.error;
|
|
757
|
-
}
|
|
758
|
-
else {
|
|
759
|
-
try {
|
|
760
|
-
const media = (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
|
|
761
|
-
if (media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
|
|
762
|
-
const resultStr = WAProto_1.proto.MediaRetryNotification.ResultType[media.result];
|
|
763
|
-
throw new boom_1.Boom(`Media re-upload failed by device (${resultStr})`, { data: media, statusCode: (0, Utils_1.getStatusCodeForMediaRetry)(media.result) || 404 });
|
|
764
|
-
}
|
|
765
|
-
content.directPath = media.directPath;
|
|
766
|
-
content.url = (0, Utils_1.getUrlFromDirectPath)(content.directPath);
|
|
767
|
-
logger.debug({ directPath: media.directPath, key: result.key }, 'media update successful');
|
|
768
|
-
}
|
|
769
|
-
catch (err) {
|
|
770
|
-
error = err;
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
return true;
|
|
774
|
-
}
|
|
775
|
-
})
|
|
776
|
-
]);
|
|
777
|
-
if (error) {
|
|
778
|
-
throw error;
|
|
779
|
-
}
|
|
780
|
-
ev.emit('messages.update', [
|
|
781
|
-
{
|
|
782
|
-
key: message.key,
|
|
783
|
-
update: {
|
|
784
|
-
message: message.message
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
]);
|
|
788
|
-
return message;
|
|
1122
|
+
})),
|
|
789
1123
|
},
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
1124
|
+
],
|
|
1125
|
+
});
|
|
1126
|
+
return result;
|
|
1127
|
+
};
|
|
1128
|
+
const waUploadToServer = getWAUploadToServer(config, refreshMediaConn);
|
|
1129
|
+
const ourin = new Dugong(waUploadToServer, relayMessage, config, sock);
|
|
1130
|
+
const waitForMsgMediaUpdate = bindWaitForEvent(ev, "messages.media-update");
|
|
1131
|
+
return {
|
|
1132
|
+
...sock,
|
|
1133
|
+
getPrivacyTokens,
|
|
1134
|
+
assertSessions,
|
|
1135
|
+
relayMessage,
|
|
1136
|
+
sendReceipt,
|
|
1137
|
+
sendReceipts,
|
|
1138
|
+
ourin,
|
|
1139
|
+
readMessages,
|
|
1140
|
+
refreshMediaConn,
|
|
1141
|
+
waUploadToServer,
|
|
1142
|
+
fetchPrivacySettings,
|
|
1143
|
+
sendPeerDataOperationMessage,
|
|
1144
|
+
createParticipantNodes,
|
|
1145
|
+
getUSyncDevices,
|
|
1146
|
+
messageRetryManager,
|
|
1147
|
+
updateMemberLabel,
|
|
1148
|
+
updateMediaMessage: async (message) => {
|
|
1149
|
+
const content = assertMediaContent(message.message);
|
|
1150
|
+
const mediaKey = content.mediaKey;
|
|
1151
|
+
const meId = authState.creds.me.id;
|
|
1152
|
+
const node = encryptMediaRetryRequest(message.key, mediaKey, meId);
|
|
1153
|
+
let error = undefined;
|
|
1154
|
+
await Promise.all([
|
|
1155
|
+
sendNode(node),
|
|
1156
|
+
waitForMsgMediaUpdate(async (update) => {
|
|
1157
|
+
const result = update.find((c) => c.key.id === message.key.id);
|
|
1158
|
+
if (result) {
|
|
1159
|
+
if (result.error) {
|
|
1160
|
+
error = result.error;
|
|
1161
|
+
} else {
|
|
1162
|
+
try {
|
|
1163
|
+
const media = decryptMediaRetryData(
|
|
1164
|
+
result.media,
|
|
1165
|
+
mediaKey,
|
|
1166
|
+
result.key.id,
|
|
1167
|
+
);
|
|
1168
|
+
if (
|
|
1169
|
+
media.result !==
|
|
1170
|
+
proto.MediaRetryNotification.ResultType.SUCCESS
|
|
1171
|
+
) {
|
|
1172
|
+
const resultStr =
|
|
1173
|
+
proto.MediaRetryNotification.ResultType[media.result];
|
|
1174
|
+
throw new Boom(
|
|
1175
|
+
`Media re-upload failed by device (${resultStr})`,
|
|
1176
|
+
{
|
|
1177
|
+
data: media,
|
|
1178
|
+
statusCode:
|
|
1179
|
+
getStatusCodeForMediaRetry(media.result) || 404,
|
|
1180
|
+
},
|
|
1181
|
+
);
|
|
843
1182
|
}
|
|
1183
|
+
content.directPath = media.directPath;
|
|
1184
|
+
content.url = getUrlFromDirectPath(content.directPath);
|
|
1185
|
+
logger.debug(
|
|
1186
|
+
{ directPath: media.directPath, key: result.key },
|
|
1187
|
+
"media update successful",
|
|
1188
|
+
);
|
|
1189
|
+
} catch (err) {
|
|
1190
|
+
error = err;
|
|
1191
|
+
}
|
|
844
1192
|
}
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
1193
|
+
return true;
|
|
1194
|
+
}
|
|
1195
|
+
}),
|
|
1196
|
+
]);
|
|
1197
|
+
if (error) {
|
|
1198
|
+
throw error;
|
|
1199
|
+
}
|
|
1200
|
+
ev.emit("messages.update", [
|
|
1201
|
+
{ key: message.key, update: { message: message.message } },
|
|
1202
|
+
]);
|
|
1203
|
+
return message;
|
|
1204
|
+
},
|
|
1205
|
+
sendStatusMention: async (content, jids = []) => {
|
|
1206
|
+
return await ourin.sendStatusWhatsApp(content, jids);
|
|
1207
|
+
},
|
|
1208
|
+
swgc: async (jid, content, options = {}) => {
|
|
1209
|
+
if (!isJidGroup(jid)) {
|
|
1210
|
+
throw new Boom("JID must be a group", { statusCode: 400 });
|
|
1211
|
+
}
|
|
1212
|
+
const storyContent = { groupStatusMessage: content };
|
|
1213
|
+
return await ourin.handleGroupStory(storyContent, jid, null);
|
|
1214
|
+
},
|
|
1215
|
+
sendPreview: async (jid, preview, options = {}) => {
|
|
1216
|
+
const extContent = {
|
|
1217
|
+
text: preview.caption || preview.text || "",
|
|
1218
|
+
matchedText: preview.matchedText || preview.url || "",
|
|
1219
|
+
previewType: preview.previewType ?? 0,
|
|
1220
|
+
};
|
|
1221
|
+
if (preview.title) extContent.title = preview.title;
|
|
1222
|
+
if (preview.description) extContent.description = preview.description;
|
|
1223
|
+
if (preview.inviteLinkGroupTypeV2)
|
|
1224
|
+
extContent.inviteLinkGroupTypeV2 = preview.inviteLinkGroupTypeV2;
|
|
1225
|
+
if (preview.image) {
|
|
1226
|
+
let imgBuf = preview.image;
|
|
1227
|
+
if (typeof imgBuf === "string" && imgBuf.startsWith("http")) {
|
|
1228
|
+
try {
|
|
1229
|
+
const resp = await fetch(imgBuf);
|
|
1230
|
+
imgBuf = Buffer.from(await resp.arrayBuffer());
|
|
1231
|
+
} catch {}
|
|
1232
|
+
}
|
|
1233
|
+
if (Buffer.isBuffer(imgBuf)) {
|
|
1234
|
+
try {
|
|
1235
|
+
const { imageMessage } = await prepareWAMessageMedia(
|
|
1236
|
+
{ image: imgBuf },
|
|
1237
|
+
{ upload: waUploadToServer, mediaTypeOverride: "thumbnail-link" },
|
|
1238
|
+
);
|
|
1239
|
+
if (imageMessage) {
|
|
1240
|
+
extContent.jpegThumbnail = imageMessage.jpegThumbnail;
|
|
1241
|
+
if (imageMessage.directPath)
|
|
1242
|
+
extContent.thumbnailDirectPath = imageMessage.directPath;
|
|
1243
|
+
if (imageMessage.mediaKey)
|
|
1244
|
+
extContent.mediaKey = imageMessage.mediaKey;
|
|
1245
|
+
if (imageMessage.mediaKeyTimestamp)
|
|
1246
|
+
extContent.mediaKeyTimestamp = imageMessage.mediaKeyTimestamp;
|
|
1247
|
+
if (imageMessage.fileSha256)
|
|
1248
|
+
extContent.thumbnailSha256 = imageMessage.fileSha256;
|
|
1249
|
+
if (imageMessage.fileEncSha256)
|
|
1250
|
+
extContent.thumbnailEncSha256 = imageMessage.fileEncSha256;
|
|
1251
|
+
if (imageMessage.width)
|
|
1252
|
+
extContent.thumbnailWidth = imageMessage.width;
|
|
1253
|
+
if (imageMessage.height)
|
|
1254
|
+
extContent.thumbnailHeight = imageMessage.height;
|
|
889
1255
|
}
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
1256
|
+
} catch {
|
|
1257
|
+
extContent.jpegThumbnail = imgBuf;
|
|
1258
|
+
}
|
|
1259
|
+
} else {
|
|
1260
|
+
extContent.jpegThumbnail = imgBuf;
|
|
1261
|
+
}
|
|
1262
|
+
} else if (preview.jpegThumbnail) {
|
|
1263
|
+
extContent.jpegThumbnail = preview.jpegThumbnail;
|
|
1264
|
+
}
|
|
1265
|
+
if (preview.thumbnailHeight)
|
|
1266
|
+
extContent.thumbnailHeight = preview.thumbnailHeight;
|
|
1267
|
+
if (preview.thumbnailWidth)
|
|
1268
|
+
extContent.thumbnailWidth = preview.thumbnailWidth;
|
|
1269
|
+
if (options.quoted) {
|
|
1270
|
+
const participant = options.quoted.key.fromMe
|
|
1271
|
+
? authState.creds.me.id
|
|
1272
|
+
: options.quoted.participant ||
|
|
1273
|
+
options.quoted.key.participant ||
|
|
1274
|
+
options.quoted.key.remoteJid;
|
|
1275
|
+
extContent.contextInfo = {
|
|
1276
|
+
stanzaId: options.quoted.key.id,
|
|
1277
|
+
participant,
|
|
1278
|
+
quotedMessage: options.quoted.message,
|
|
1279
|
+
};
|
|
1280
|
+
}
|
|
1281
|
+
if (options.contextInfo) {
|
|
1282
|
+
extContent.contextInfo = {
|
|
1283
|
+
...extContent.contextInfo,
|
|
1284
|
+
...options.contextInfo,
|
|
1285
|
+
};
|
|
1286
|
+
}
|
|
1287
|
+
const messageId = generateMessageIDV2(sock.user?.id);
|
|
1288
|
+
await relayMessage(
|
|
1289
|
+
jid,
|
|
1290
|
+
{ extendedTextMessage: extContent },
|
|
1291
|
+
{ messageId },
|
|
1292
|
+
);
|
|
1293
|
+
return messageId;
|
|
1294
|
+
},
|
|
1295
|
+
// Aku tau kamu pasti bakalan nyari ini, tapi gak papa deh
|
|
1296
|
+
// support ourin terus yahh kawan kawan
|
|
1297
|
+
// @Zann
|
|
1298
|
+
sendTable: async (jid, title, headers, rows, quoted, options = {}) => {
|
|
1299
|
+
const { message, messageId } = generateTableContent(
|
|
1300
|
+
title,
|
|
1301
|
+
headers,
|
|
1302
|
+
rows,
|
|
1303
|
+
quoted,
|
|
1304
|
+
options,
|
|
1305
|
+
);
|
|
1306
|
+
await relayMessage(jid, message, { messageId });
|
|
1307
|
+
return { message, messageId };
|
|
1308
|
+
},
|
|
1309
|
+
sendTableV2: async (jid, table, quoted, options = {}) => {
|
|
1310
|
+
const { message, messageId } = generateTableContentV2(
|
|
1311
|
+
table,
|
|
1312
|
+
quoted,
|
|
1313
|
+
options,
|
|
1314
|
+
);
|
|
1315
|
+
await relayMessage(jid, message, { messageId });
|
|
1316
|
+
return { message, messageId };
|
|
1317
|
+
},
|
|
1318
|
+
sendList: async (jid, title, items, quoted, options = {}) => {
|
|
1319
|
+
const { message, messageId } = generateListContent(
|
|
1320
|
+
title,
|
|
1321
|
+
items,
|
|
1322
|
+
quoted,
|
|
1323
|
+
options,
|
|
1324
|
+
);
|
|
1325
|
+
await relayMessage(jid, message, { messageId });
|
|
1326
|
+
return { message, messageId };
|
|
1327
|
+
},
|
|
1328
|
+
sendCodeBlock: async (jid, code, quoted, options = {}) => {
|
|
1329
|
+
const { message, messageId } = generateCodeBlockContent(
|
|
1330
|
+
code,
|
|
1331
|
+
quoted,
|
|
1332
|
+
options,
|
|
1333
|
+
);
|
|
1334
|
+
await relayMessage(jid, message, { messageId });
|
|
1335
|
+
return { message, messageId };
|
|
1336
|
+
},
|
|
1337
|
+
sendCodeBlockV2: async (jid, code, quoted, options = {}) => {
|
|
1338
|
+
const { message, messageId } = generateCodeBlockContentV2(
|
|
1339
|
+
code,
|
|
1340
|
+
quoted,
|
|
1341
|
+
options,
|
|
1342
|
+
);
|
|
1343
|
+
await relayMessage(jid, message, { messageId });
|
|
1344
|
+
return { message, messageId };
|
|
1345
|
+
},
|
|
1346
|
+
sendLink: async (jid, text, links, quoted, options = {}) => {
|
|
1347
|
+
const { message, messageId } = generateLinkContent(
|
|
1348
|
+
text,
|
|
1349
|
+
links,
|
|
1350
|
+
quoted,
|
|
1351
|
+
options,
|
|
1352
|
+
);
|
|
1353
|
+
await relayMessage(jid, message, { messageId });
|
|
1354
|
+
return { message, messageId };
|
|
1355
|
+
},
|
|
1356
|
+
sendLinkV2: async (jid, text, links, quoted, options = {}) => {
|
|
1357
|
+
const { message, messageId } = generateLinkContentV2(
|
|
1358
|
+
text,
|
|
1359
|
+
links,
|
|
1360
|
+
quoted,
|
|
1361
|
+
options,
|
|
1362
|
+
);
|
|
1363
|
+
await relayMessage(jid, message, { messageId });
|
|
1364
|
+
return { message, messageId };
|
|
1365
|
+
},
|
|
1366
|
+
sendLatex: async (jid, quoted, options) => {
|
|
1367
|
+
const { message, messageId } = generateLatexContent(quoted, options);
|
|
1368
|
+
await relayMessage(jid, message, { messageId });
|
|
1369
|
+
return { message, messageId };
|
|
1370
|
+
},
|
|
1371
|
+
sendLatexImage: async (
|
|
1372
|
+
jid,
|
|
1373
|
+
quoted,
|
|
1374
|
+
options,
|
|
1375
|
+
renderLatexToPng,
|
|
1376
|
+
uploadFn,
|
|
1377
|
+
) => {
|
|
1378
|
+
const { message, messageId } = await generateLatexImageContent(
|
|
1379
|
+
quoted,
|
|
1380
|
+
options,
|
|
1381
|
+
uploadFn,
|
|
1382
|
+
renderLatexToPng,
|
|
1383
|
+
);
|
|
1384
|
+
await relayMessage(jid, message, { messageId });
|
|
1385
|
+
return { message, messageId };
|
|
1386
|
+
},
|
|
1387
|
+
sendLatexInlineImage: async (
|
|
1388
|
+
jid,
|
|
1389
|
+
quoted,
|
|
1390
|
+
options,
|
|
1391
|
+
renderLatexToPng,
|
|
1392
|
+
uploadFn,
|
|
1393
|
+
) => {
|
|
1394
|
+
const { message, messageId } = await generateLatexInlineImageContent(
|
|
1395
|
+
quoted,
|
|
1396
|
+
options,
|
|
1397
|
+
uploadFn,
|
|
1398
|
+
renderLatexToPng,
|
|
1399
|
+
);
|
|
1400
|
+
await relayMessage(jid, message, { messageId });
|
|
1401
|
+
return { message, messageId };
|
|
1402
|
+
},
|
|
1403
|
+
captureUnifiedResponse,
|
|
1404
|
+
sendUnifiedResponse: async (jid, quoted, captured) => {
|
|
1405
|
+
const { message, messageId } = generateUnifiedResponseContent(
|
|
1406
|
+
quoted,
|
|
1407
|
+
captured,
|
|
1408
|
+
);
|
|
1409
|
+
await relayMessage(jid, message, { messageId });
|
|
1410
|
+
return { message, messageId };
|
|
1411
|
+
},
|
|
1412
|
+
sendRichMessage: async (jid, submessages, quoted, options = {}) => {
|
|
1413
|
+
const { message, messageId } = generateRichMessageContent(
|
|
1414
|
+
submessages,
|
|
1415
|
+
quoted,
|
|
1416
|
+
);
|
|
1417
|
+
await relayMessage(jid, message, { messageId });
|
|
1418
|
+
return { message, messageId };
|
|
1419
|
+
},
|
|
1420
|
+
sendMessage: async (jid, content, options = {}) => {
|
|
1421
|
+
const userJid = authState.creds.me.id;
|
|
1422
|
+
const { quoted } = options;
|
|
1423
|
+
const messageType = ourin.detectType(content);
|
|
1424
|
+
if (
|
|
1425
|
+
typeof content === "object" &&
|
|
1426
|
+
"disappearingMessagesInChat" in content &&
|
|
1427
|
+
typeof content["disappearingMessagesInChat"] !== "undefined" &&
|
|
1428
|
+
isJidGroup(jid)
|
|
1429
|
+
) {
|
|
1430
|
+
const { disappearingMessagesInChat } = content;
|
|
1431
|
+
const value =
|
|
1432
|
+
typeof disappearingMessagesInChat === "boolean"
|
|
1433
|
+
? disappearingMessagesInChat
|
|
1434
|
+
? WA_DEFAULT_EPHEMERAL
|
|
1435
|
+
: 0
|
|
1436
|
+
: disappearingMessagesInChat;
|
|
1437
|
+
await groupToggleEphemeral(jid, value);
|
|
1438
|
+
} else if (messageType) {
|
|
1439
|
+
switch (messageType) {
|
|
1440
|
+
case "PAYMENT": {
|
|
1441
|
+
const paymentContent = await ourin.handlePayment(content, quoted);
|
|
1442
|
+
return await relayMessage(jid, paymentContent, {
|
|
1443
|
+
messageId: generateMessageIDV2(userJid),
|
|
897
1444
|
});
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
1445
|
+
}
|
|
1446
|
+
case "PRODUCT": {
|
|
1447
|
+
const productContent = await ourin.handleProduct(
|
|
1448
|
+
content,
|
|
1449
|
+
jid,
|
|
1450
|
+
quoted,
|
|
1451
|
+
);
|
|
1452
|
+
const productMsg = await generateWAMessageFromContent(
|
|
1453
|
+
jid,
|
|
1454
|
+
productContent,
|
|
1455
|
+
{ quoted, userJid },
|
|
1456
|
+
);
|
|
1457
|
+
return await relayMessage(jid, productMsg.message, {
|
|
1458
|
+
messageId: productMsg.key.id,
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
case "CAROUSEL": {
|
|
1462
|
+
const carouselContent = await ourin.handleCarousel(
|
|
1463
|
+
content,
|
|
1464
|
+
jid,
|
|
1465
|
+
quoted,
|
|
1466
|
+
);
|
|
1467
|
+
const carouselMsg = await generateWAMessageFromContent(
|
|
1468
|
+
jid,
|
|
1469
|
+
carouselContent,
|
|
1470
|
+
{ quoted, userJid },
|
|
1471
|
+
);
|
|
1472
|
+
return await relayMessage(jid, carouselMsg.message, {
|
|
1473
|
+
messageId: carouselMsg.key.id,
|
|
1474
|
+
});
|
|
1475
|
+
}
|
|
1476
|
+
case "INTERACTIVE": {
|
|
1477
|
+
const interactiveContent = await ourin.handleInteractive(
|
|
1478
|
+
content,
|
|
1479
|
+
jid,
|
|
1480
|
+
quoted,
|
|
1481
|
+
);
|
|
1482
|
+
const interactiveMsg = await generateWAMessageFromContent(
|
|
1483
|
+
jid,
|
|
1484
|
+
interactiveContent,
|
|
1485
|
+
{ quoted, userJid },
|
|
1486
|
+
);
|
|
1487
|
+
return await relayMessage(jid, interactiveMsg.message, {
|
|
1488
|
+
messageId: interactiveMsg.key.id,
|
|
1489
|
+
});
|
|
1490
|
+
}
|
|
1491
|
+
case "INTERACTIVE_BUTTONS": {
|
|
1492
|
+
const ibContent = await ourin.handleInteractiveButtons(
|
|
1493
|
+
content,
|
|
1494
|
+
jid,
|
|
1495
|
+
quoted,
|
|
1496
|
+
);
|
|
1497
|
+
const ibMsg = await generateWAMessageFromContent(jid, ibContent, {
|
|
1498
|
+
quoted,
|
|
1499
|
+
userJid,
|
|
1500
|
+
});
|
|
1501
|
+
return await relayMessage(jid, ibMsg.message, {
|
|
1502
|
+
messageId: ibMsg.key.id,
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
case "ALBUM":
|
|
1506
|
+
return await ourin.handleAlbum(content, jid, quoted);
|
|
1507
|
+
case "EVENT":
|
|
1508
|
+
return await ourin.handleEvent(content, jid, quoted);
|
|
1509
|
+
case "POLL_RESULT":
|
|
1510
|
+
return await ourin.handlePollResult(content, jid, quoted);
|
|
1511
|
+
case "GROUP_STORY":
|
|
1512
|
+
return await ourin.handleGroupStory(content, jid, quoted, options);
|
|
1513
|
+
}
|
|
1514
|
+
} else {
|
|
1515
|
+
let mediaHandle;
|
|
1516
|
+
const fullMsg = await generateWAMessage(jid, content, {
|
|
1517
|
+
logger,
|
|
1518
|
+
userJid,
|
|
1519
|
+
getUrlInfo: (text) =>
|
|
1520
|
+
getUrlInfo(text, {
|
|
1521
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
1522
|
+
fetchOpts: {
|
|
1523
|
+
timeout: 3000,
|
|
1524
|
+
...(httpRequestOptions || {}),
|
|
1525
|
+
},
|
|
1526
|
+
logger,
|
|
1527
|
+
uploadImage: generateHighQualityLinkPreview
|
|
1528
|
+
? waUploadToServer
|
|
1529
|
+
: undefined,
|
|
1530
|
+
}),
|
|
1531
|
+
getProfilePicUrl: sock.profilePictureUrl,
|
|
1532
|
+
getCallLink: sock.createCallLink,
|
|
1533
|
+
upload: async (readStream, opts) => {
|
|
1534
|
+
const up = await waUploadToServer(readStream, {
|
|
1535
|
+
...opts,
|
|
1536
|
+
newsletter: isJidNewsletter(jid),
|
|
1537
|
+
});
|
|
1538
|
+
return up;
|
|
1539
|
+
},
|
|
1540
|
+
mediaCache: config.mediaCache,
|
|
1541
|
+
options: config.options,
|
|
1542
|
+
messageId: generateMessageIDV2(sock.user?.id),
|
|
1543
|
+
...options,
|
|
1544
|
+
});
|
|
1545
|
+
const isEventMsg = "event" in content && !!content.event;
|
|
1546
|
+
const isDeleteMsg = "delete" in content && !!content.delete;
|
|
1547
|
+
const isEditMsg = "edit" in content && !!content.edit;
|
|
1548
|
+
const isPinMsg = "pin" in content && !!content.pin;
|
|
1549
|
+
const isPollMessage = "poll" in content && !!content.poll;
|
|
1550
|
+
const isAiMsg = "ai" in content && !!content.ai;
|
|
1551
|
+
const additionalAttributes = {};
|
|
1552
|
+
const additionalNodes = [];
|
|
1553
|
+
if (isDeleteMsg) {
|
|
1554
|
+
const fromMe = content.delete?.fromMe;
|
|
1555
|
+
const isGroup = isJidGroup(content.delete?.remoteJid);
|
|
1556
|
+
additionalAttributes.edit =
|
|
1557
|
+
(isGroup && !fromMe) || isJidNewsletter(jid) ? "8" : "7";
|
|
1558
|
+
} else if (isEditMsg) {
|
|
1559
|
+
additionalAttributes.edit = isJidNewsletter(jid) ? "3" : "1";
|
|
1560
|
+
} else if (isPinMsg) {
|
|
1561
|
+
additionalAttributes.edit = "2";
|
|
1562
|
+
} else if (isPollMessage) {
|
|
1563
|
+
additionalNodes.push({
|
|
1564
|
+
tag: "meta",
|
|
1565
|
+
attrs: { polltype: "creation" },
|
|
1566
|
+
});
|
|
1567
|
+
} else if (isEventMsg) {
|
|
1568
|
+
additionalNodes.push({
|
|
1569
|
+
tag: "meta",
|
|
1570
|
+
attrs: { event_type: "creation" },
|
|
1571
|
+
});
|
|
1572
|
+
}
|
|
1573
|
+
additionalNodes.push({
|
|
1574
|
+
tag: "bot",
|
|
1575
|
+
attrs: { biz_bot: "1" },
|
|
1576
|
+
});
|
|
1577
|
+
const finalNodes = options.additionalNodes
|
|
1578
|
+
? [...options.additionalNodes, ...additionalNodes]
|
|
1579
|
+
: additionalNodes;
|
|
1580
|
+
const isGroupOrChannel = jid.endsWith('@g.us') || jid.endsWith('@newsletter');
|
|
1581
|
+
let forcedAiNodes = options.additionalNodes;
|
|
1582
|
+
if (!isGroupOrChannel) {
|
|
1583
|
+
if (options.additionalNodes) {
|
|
1584
|
+
forcedAiNodes = [...options.additionalNodes];
|
|
1585
|
+
if (!forcedAiNodes.some(n => n.tag === 'bot')) {
|
|
1586
|
+
forcedAiNodes.push({ tag: "bot", attrs: { biz_bot: "1" } });
|
|
1587
|
+
}
|
|
1588
|
+
} else {
|
|
1589
|
+
forcedAiNodes = [{ tag: "bot", attrs: { biz_bot: "1" } }];
|
|
905
1590
|
}
|
|
906
1591
|
}
|
|
907
|
-
|
|
1592
|
+
await relayMessage(jid, fullMsg.message, {
|
|
1593
|
+
messageId: fullMsg.key.id,
|
|
1594
|
+
cachedGroupMetadata: options.cachedGroupMetadata,
|
|
1595
|
+
useCachedGroupMetadata: options.useCachedGroupMetadata,
|
|
1596
|
+
additionalAttributes,
|
|
1597
|
+
statusJidList: options.statusJidList,
|
|
1598
|
+
additionalNodes: forcedAiNodes
|
|
1599
|
+
});
|
|
1600
|
+
|
|
1601
|
+
if (config.emitOwnEvents) {
|
|
1602
|
+
process.nextTick(async () => {
|
|
1603
|
+
await messageMutex.mutex(() => upsertMessage(fullMsg, "append"));
|
|
1604
|
+
});
|
|
1605
|
+
}
|
|
1606
|
+
return fullMsg;
|
|
1607
|
+
}
|
|
1608
|
+
},
|
|
1609
|
+
};
|
|
908
1610
|
};
|
|
909
|
-
|
|
1611
|
+
//# sourceMappingURL=messages-send.js.map
|