@queenanya/baileys 8.6.0-beta → 9.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +4633 -0
- package/WAProto/fix-imports.js +29 -0
- package/WAProto/index.d.ts +2165 -45253
- package/WAProto/index.js +45236 -130529
- package/lib/Defaults/index.d.ts +14 -3
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +64 -55
- 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 +258 -90
- package/lib/Signal/libsignal.js.map +1 -0
- package/lib/Signal/lid-mapping.d.ts +23 -0
- package/lib/Signal/lid-mapping.d.ts.map +1 -0
- package/lib/Signal/lid-mapping.js +171 -0
- package/lib/Signal/lid-mapping.js.map +1 -0
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.d.ts.map +1 -0
- package/lib/Socket/Client/index.js +3 -18
- package/lib/Socket/Client/index.js.map +1 -0
- package/lib/Socket/Client/types.d.ts +2 -2
- package/lib/Socket/Client/types.d.ts.map +1 -0
- package/lib/Socket/Client/types.js +4 -6
- package/lib/Socket/Client/types.js.map +1 -0
- package/lib/Socket/Client/websocket.d.ts +2 -2
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +15 -37
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +106 -94
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +159 -43
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +39 -27
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +271 -261
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +111 -86
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +138 -70
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/groups.d.ts +53 -43
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +94 -99
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +133 -108
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +17 -9
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +90 -82
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +635 -480
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +90 -76
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +476 -402
- package/lib/Socket/messages-send.js.map +1 -0
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.d.ts.map +1 -0
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/mex.js.map +1 -0
- package/lib/Socket/newsletter.d.ts +83 -73
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +181 -202
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +24 -16
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +402 -196
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Types/Auth.d.ts +13 -5
- 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 +25 -0
- package/lib/Types/Bussines.d.ts.map +1 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Bussines.js.map +1 -0
- package/lib/Types/Call.d.ts +1 -0
- 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 +18 -9
- 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 +5 -4
- 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 +36 -33
- 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 +12 -11
- 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 +51 -148
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +11 -7
- package/lib/Types/Message.js.map +1 -0
- package/lib/Types/Newsletter.d.ts +173 -71
- package/lib/Types/Newsletter.d.ts.map +1 -0
- package/lib/Types/Newsletter.js +54 -11
- 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 +34 -20
- 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 +15 -14
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +15 -31
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/auth-utils.d.ts +5 -4
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +199 -141
- package/lib/Utils/auth-utils.js.map +1 -0
- package/lib/Utils/baileys-event-stream.d.ts +2 -1
- package/lib/Utils/baileys-event-stream.d.ts.map +1 -0
- package/lib/Utils/baileys-event-stream.js +15 -22
- package/lib/Utils/baileys-event-stream.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 +11 -11
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +203 -194
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +8 -7
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +50 -101
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +18 -5
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +134 -62
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +6 -7
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +99 -69
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +57 -68
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +179 -356
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts +10 -10
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +37 -50
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/index.d.ts +21 -17
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +21 -33
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/link-preview.d.ts +4 -4
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +15 -56
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +8 -6
- 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 +9 -8
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +23 -26
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts +1 -0
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +7 -10
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/message-retry-manager.d.ts +82 -0
- package/lib/Utils/message-retry-manager.d.ts.map +1 -0
- package/lib/Utils/message-retry-manager.js +149 -0
- package/lib/Utils/message-retry-manager.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +32 -38
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +283 -496
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +11 -10
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +309 -519
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts +5 -4
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +23 -26
- package/lib/Utils/noise-handler.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 +12 -12
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +196 -155
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/signal.d.ts +7 -6
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +70 -64
- package/lib/Utils/signal.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +23 -27
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +3 -2
- package/lib/Utils/use-single-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-single-file-auth-state.js +63 -41
- package/lib/Utils/use-single-file-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts +4 -3
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +99 -77
- package/lib/Utils/validate-connection.js.map +1 -0
- package/lib/WABinary/constants.d.ts +1 -0
- package/lib/WABinary/constants.d.ts.map +1 -0
- package/lib/WABinary/constants.js +9 -11
- package/lib/WABinary/constants.js.map +1 -0
- package/lib/WABinary/decode.d.ts +2 -1
- package/lib/WABinary/decode.d.ts.map +1 -0
- package/lib/WABinary/decode.js +25 -52
- package/lib/WABinary/decode.js.map +1 -0
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.d.ts.map +1 -0
- package/lib/WABinary/encode.js +14 -48
- package/lib/WABinary/encode.js.map +1 -0
- package/lib/WABinary/generic-utils.d.ts +4 -3
- package/lib/WABinary/generic-utils.d.ts.map +1 -0
- package/lib/WABinary/generic-utils.js +31 -39
- 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 +21 -11
- package/lib/WABinary/jid-utils.d.ts.map +1 -0
- package/lib/WABinary/jid-utils.js +71 -60
- 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 +2 -1
- 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 -1
- 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 +8 -11
- 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 -12
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -34
- package/lib/index.js.map +1 -0
- package/package.json +55 -65
- package/CHANGELOG.md +0 -4
- package/README-anya.md +0 -459
- package/README-shizo.md +0 -445
- package/README-whiskey.md +0 -44
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/usync.d.ts +0 -36
- package/lib/Socket/usync.js +0 -70
- package/lib/Store/index.d.ts +0 -2
- package/lib/Store/index.js +0 -8
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-in-memory-store.js +0 -429
- 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/WAMedia/index.d.ts +0 -2
- package/lib/WAMedia/index.js +0 -18
- package/lib/WAMedia/media-messages.d.ts +0 -18
- package/lib/WAMedia/media-messages.js +0 -102
- package/lib/WAMedia/media-set.d.ts +0 -9
- package/lib/WAMedia/media-set.js +0 -312
|
@@ -1,47 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const userDevicesCache = (config.userDevicesCache || new node_cache_1.default({
|
|
23
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
|
|
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 { aggregateMessageKeysNotFromMe, assertMediaContent, bindWaitForEvent, decryptMediaRetryData, encodeNewsletterMessage, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, extractDeviceJids, generateMessageIDV2, generateParticipantHashV2, generateWAMessage, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, MessageRetryManager, normalizeMessageContent, parseAndInjectE2ESessions, unixTimestampSeconds } from '../Utils/index.js';
|
|
6
|
+
import { getUrlInfo } from '../Utils/link-preview.js';
|
|
7
|
+
import { makeKeyedMutex } from '../Utils/make-mutex.js';
|
|
8
|
+
import { areJidsSameUser, getBinaryNodeChild, getBinaryNodeChildren, isHostedLidUser, isHostedPnUser, isJidGroup, isLidUser, isPnUser, jidDecode, jidEncode, jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
9
|
+
import { USyncQuery, USyncUser } from '../WAUSync/index.js';
|
|
10
|
+
import { makeNewsletterSocket } from './newsletter.js';
|
|
11
|
+
export const makeMessagesSocket = (config) => {
|
|
12
|
+
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: httpRequestOptions, patchMessageBeforeSending, cachedGroupMetadata, enableRecentMessageCache, maxMsgRetryCount } = config;
|
|
13
|
+
const sock = makeNewsletterSocket(config);
|
|
14
|
+
const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral } = sock;
|
|
15
|
+
const userDevicesCache = config.userDevicesCache ||
|
|
16
|
+
new NodeCache({
|
|
17
|
+
stdTTL: DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
|
|
18
|
+
useClones: false
|
|
19
|
+
});
|
|
20
|
+
const peerSessionsCache = new NodeCache({
|
|
21
|
+
stdTTL: DEFAULT_CACHE_TTLS.USER_DEVICES,
|
|
24
22
|
useClones: false
|
|
25
|
-
})
|
|
23
|
+
});
|
|
24
|
+
// Initialize message retry manager if enabled
|
|
25
|
+
const messageRetryManager = enableRecentMessageCache ? new MessageRetryManager(logger, maxMsgRetryCount) : null;
|
|
26
|
+
// Prevent race conditions in Signal session encryption by user
|
|
27
|
+
const encryptionMutex = makeKeyedMutex();
|
|
26
28
|
let mediaConn;
|
|
27
29
|
const refreshMediaConn = async (forceGet = false) => {
|
|
28
30
|
const media = await mediaConn;
|
|
29
|
-
if (!media || forceGet ||
|
|
31
|
+
if (!media || forceGet || new Date().getTime() - media.fetchDate.getTime() > media.ttl * 1000) {
|
|
30
32
|
mediaConn = (async () => {
|
|
31
33
|
const result = await query({
|
|
32
34
|
tag: 'iq',
|
|
33
35
|
attrs: {
|
|
34
36
|
type: 'set',
|
|
35
37
|
xmlns: 'w:m',
|
|
36
|
-
to:
|
|
38
|
+
to: S_WHATSAPP_NET
|
|
37
39
|
},
|
|
38
40
|
content: [{ tag: 'media_conn', attrs: {} }]
|
|
39
41
|
});
|
|
40
|
-
const mediaConnNode =
|
|
42
|
+
const mediaConnNode = getBinaryNodeChild(result, 'media_conn');
|
|
43
|
+
// TODO: explore full length of data that whatsapp provides
|
|
41
44
|
const node = {
|
|
42
|
-
hosts:
|
|
45
|
+
hosts: getBinaryNodeChildren(mediaConnNode, 'host').map(({ attrs }) => ({
|
|
43
46
|
hostname: attrs.hostname,
|
|
44
|
-
maxContentLengthBytes: +attrs.maxContentLengthBytes
|
|
47
|
+
maxContentLengthBytes: +attrs.maxContentLengthBytes
|
|
45
48
|
})),
|
|
46
49
|
auth: mediaConnNode.attrs.auth,
|
|
47
50
|
ttl: +mediaConnNode.attrs.ttl,
|
|
@@ -58,17 +61,20 @@ const makeMessagesSocket = (config) => {
|
|
|
58
61
|
* used for receipts of phone call, read, delivery etc.
|
|
59
62
|
* */
|
|
60
63
|
const sendReceipt = async (jid, participant, messageIds, type) => {
|
|
64
|
+
if (!messageIds || messageIds.length === 0) {
|
|
65
|
+
throw new Boom('missing ids in receipt');
|
|
66
|
+
}
|
|
61
67
|
const node = {
|
|
62
68
|
tag: 'receipt',
|
|
63
69
|
attrs: {
|
|
64
|
-
id: messageIds[0]
|
|
65
|
-
}
|
|
70
|
+
id: messageIds[0]
|
|
71
|
+
}
|
|
66
72
|
};
|
|
67
73
|
const isReadReceipt = type === 'read' || type === 'read-self';
|
|
68
74
|
if (isReadReceipt) {
|
|
69
|
-
node.attrs.t =
|
|
75
|
+
node.attrs.t = unixTimestampSeconds().toString();
|
|
70
76
|
}
|
|
71
|
-
if (type === 'sender' && (
|
|
77
|
+
if (type === 'sender' && (isPnUser(jid) || isLidUser(jid))) {
|
|
72
78
|
node.attrs.recipient = jid;
|
|
73
79
|
node.attrs.to = participant;
|
|
74
80
|
}
|
|
@@ -79,7 +85,7 @@ const makeMessagesSocket = (config) => {
|
|
|
79
85
|
}
|
|
80
86
|
}
|
|
81
87
|
if (type) {
|
|
82
|
-
node.attrs.type =
|
|
88
|
+
node.attrs.type = type;
|
|
83
89
|
}
|
|
84
90
|
const remainingMessageIds = messageIds.slice(1);
|
|
85
91
|
if (remainingMessageIds.length) {
|
|
@@ -99,7 +105,7 @@ const makeMessagesSocket = (config) => {
|
|
|
99
105
|
};
|
|
100
106
|
/** Correctly bulk send receipts to multiple chats, participants */
|
|
101
107
|
const sendReceipts = async (keys, type) => {
|
|
102
|
-
const recps =
|
|
108
|
+
const recps = aggregateMessageKeysNotFromMe(keys);
|
|
103
109
|
for (const { jid, participant, messageIds } of recps) {
|
|
104
110
|
await sendReceipt(jid, participant, messageIds, type);
|
|
105
111
|
}
|
|
@@ -113,20 +119,44 @@ const makeMessagesSocket = (config) => {
|
|
|
113
119
|
};
|
|
114
120
|
/** Fetch all the devices we've to send a message to */
|
|
115
121
|
const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
|
|
116
|
-
var _a;
|
|
117
122
|
const deviceResults = [];
|
|
118
123
|
if (!useCache) {
|
|
119
124
|
logger.debug('not using cache for devices');
|
|
120
125
|
}
|
|
121
126
|
const toFetch = [];
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
127
|
+
const jidsWithUser = jids
|
|
128
|
+
.map(jid => {
|
|
129
|
+
const decoded = jidDecode(jid);
|
|
130
|
+
const user = decoded?.user;
|
|
131
|
+
const device = decoded?.device;
|
|
132
|
+
const isExplicitDevice = typeof device === 'number' && device >= 0;
|
|
133
|
+
if (isExplicitDevice && user) {
|
|
134
|
+
deviceResults.push({
|
|
135
|
+
user,
|
|
136
|
+
device,
|
|
137
|
+
jid
|
|
138
|
+
});
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
jid = jidNormalizedUser(jid);
|
|
142
|
+
return { jid, user };
|
|
143
|
+
})
|
|
144
|
+
.filter(jid => jid !== null);
|
|
145
|
+
let mgetDevices;
|
|
146
|
+
if (useCache && userDevicesCache.mget) {
|
|
147
|
+
const usersToFetch = jidsWithUser.map(j => j?.user).filter(Boolean);
|
|
148
|
+
mgetDevices = await userDevicesCache.mget(usersToFetch);
|
|
149
|
+
}
|
|
150
|
+
for (const { jid, user } of jidsWithUser) {
|
|
126
151
|
if (useCache) {
|
|
127
|
-
const devices =
|
|
152
|
+
const devices = mgetDevices?.[user] ||
|
|
153
|
+
(userDevicesCache.mget ? undefined : (await userDevicesCache.get(user)));
|
|
128
154
|
if (devices) {
|
|
129
|
-
|
|
155
|
+
const devicesWithJid = devices.map(d => ({
|
|
156
|
+
...d,
|
|
157
|
+
jid: jidEncode(d.user, d.server, d.device)
|
|
158
|
+
}));
|
|
159
|
+
deviceResults.push(...devicesWithJid);
|
|
130
160
|
logger.trace({ user }, 'using cache for devices');
|
|
131
161
|
}
|
|
132
162
|
else {
|
|
@@ -140,141 +170,240 @@ const makeMessagesSocket = (config) => {
|
|
|
140
170
|
if (!toFetch.length) {
|
|
141
171
|
return deviceResults;
|
|
142
172
|
}
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
173
|
+
const requestedLidUsers = new Set();
|
|
174
|
+
for (const jid of toFetch) {
|
|
175
|
+
if (isLidUser(jid) || isHostedLidUser(jid)) {
|
|
176
|
+
const user = jidDecode(jid)?.user;
|
|
177
|
+
if (user)
|
|
178
|
+
requestedLidUsers.add(user);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const query = new USyncQuery().withContext('message').withDeviceProtocol().withLIDProtocol();
|
|
146
182
|
for (const jid of toFetch) {
|
|
147
|
-
query.withUser(new
|
|
183
|
+
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
|
|
148
184
|
}
|
|
149
185
|
const result = await sock.executeUSyncQuery(query);
|
|
150
186
|
if (result) {
|
|
151
|
-
|
|
187
|
+
// TODO: LID MAP this stuff (lid protocol will now return lid with devices)
|
|
188
|
+
const lidResults = result.list.filter(a => !!a.lid);
|
|
189
|
+
if (lidResults.length > 0) {
|
|
190
|
+
logger.trace('Storing LID maps from device call');
|
|
191
|
+
await signalRepository.lidMapping.storeLIDPNMappings(lidResults.map(a => ({ lid: a.lid, pn: a.id })));
|
|
192
|
+
}
|
|
193
|
+
const extracted = extractDeviceJids(result?.list, authState.creds.me.id, authState.creds.me.lid, ignoreZeroDevices);
|
|
152
194
|
const deviceMap = {};
|
|
153
195
|
for (const item of extracted) {
|
|
154
196
|
deviceMap[item.user] = deviceMap[item.user] || [];
|
|
155
|
-
deviceMap[item.user]
|
|
156
|
-
|
|
197
|
+
deviceMap[item.user]?.push(item);
|
|
198
|
+
}
|
|
199
|
+
// Process each user's devices as a group for bulk LID migration
|
|
200
|
+
for (const [user, userDevices] of Object.entries(deviceMap)) {
|
|
201
|
+
const isLidUser = requestedLidUsers.has(user);
|
|
202
|
+
// Process all devices for this user
|
|
203
|
+
for (const item of userDevices) {
|
|
204
|
+
const finalJid = isLidUser
|
|
205
|
+
? jidEncode(user, item.server, item.device)
|
|
206
|
+
: jidEncode(item.user, item.server, item.device);
|
|
207
|
+
deviceResults.push({
|
|
208
|
+
...item,
|
|
209
|
+
jid: finalJid
|
|
210
|
+
});
|
|
211
|
+
logger.debug({
|
|
212
|
+
user: item.user,
|
|
213
|
+
device: item.device,
|
|
214
|
+
finalJid,
|
|
215
|
+
usedLid: isLidUser
|
|
216
|
+
}, 'Processed device with LID priority');
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (userDevicesCache.mset) {
|
|
220
|
+
// if the cache supports mset, we can set all devices in one go
|
|
221
|
+
await userDevicesCache.mset(Object.entries(deviceMap).map(([key, value]) => ({ key, value })));
|
|
157
222
|
}
|
|
158
|
-
|
|
159
|
-
|
|
223
|
+
else {
|
|
224
|
+
for (const key in deviceMap) {
|
|
225
|
+
if (deviceMap[key])
|
|
226
|
+
await userDevicesCache.set(key, deviceMap[key]);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const userDeviceUpdates = {};
|
|
230
|
+
for (const [userId, devices] of Object.entries(deviceMap)) {
|
|
231
|
+
if (devices && devices.length > 0) {
|
|
232
|
+
userDeviceUpdates[userId] = devices.map(d => d.device?.toString() || '0');
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (Object.keys(userDeviceUpdates).length > 0) {
|
|
236
|
+
try {
|
|
237
|
+
await authState.keys.set({ 'device-list': userDeviceUpdates });
|
|
238
|
+
logger.debug({ userCount: Object.keys(userDeviceUpdates).length }, 'stored user device lists for bulk migration');
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
logger.warn({ error }, 'failed to store user device lists');
|
|
242
|
+
}
|
|
160
243
|
}
|
|
161
244
|
}
|
|
162
245
|
return deviceResults;
|
|
163
246
|
};
|
|
164
|
-
const assertSessions = async (jids
|
|
247
|
+
const assertSessions = async (jids) => {
|
|
165
248
|
let didFetchNewSession = false;
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
.jidToSignalProtocolAddress(jid);
|
|
177
|
-
if (!sessions[signalId]) {
|
|
178
|
-
jidsRequiringFetch.push(jid);
|
|
249
|
+
const uniqueJids = [...new Set(jids)]; // Deduplicate JIDs
|
|
250
|
+
const jidsRequiringFetch = [];
|
|
251
|
+
logger.debug({ jids }, 'assertSessions call with jids');
|
|
252
|
+
// Check peerSessionsCache and validate sessions using libsignal loadSession
|
|
253
|
+
for (const jid of uniqueJids) {
|
|
254
|
+
const signalId = signalRepository.jidToSignalProtocolAddress(jid);
|
|
255
|
+
const cachedSession = peerSessionsCache.get(signalId);
|
|
256
|
+
if (cachedSession !== undefined) {
|
|
257
|
+
if (cachedSession) {
|
|
258
|
+
continue; // Session exists in cache
|
|
179
259
|
}
|
|
180
260
|
}
|
|
261
|
+
else {
|
|
262
|
+
const sessionValidation = await signalRepository.validateSession(jid);
|
|
263
|
+
const hasSession = sessionValidation.exists;
|
|
264
|
+
peerSessionsCache.set(signalId, hasSession);
|
|
265
|
+
if (hasSession) {
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
jidsRequiringFetch.push(jid);
|
|
181
270
|
}
|
|
182
271
|
if (jidsRequiringFetch.length) {
|
|
183
|
-
|
|
272
|
+
// LID if mapped, otherwise original
|
|
273
|
+
const wireJids = [
|
|
274
|
+
...jidsRequiringFetch.filter(jid => !!isLidUser(jid) || !!isHostedLidUser(jid)),
|
|
275
|
+
...((await signalRepository.lidMapping.getLIDsForPNs(jidsRequiringFetch.filter(jid => !!isPnUser(jid) || !!isHostedPnUser(jid)))) || []).map(a => a.lid)
|
|
276
|
+
];
|
|
277
|
+
logger.debug({ jidsRequiringFetch, wireJids }, 'fetching sessions');
|
|
184
278
|
const result = await query({
|
|
185
279
|
tag: 'iq',
|
|
186
280
|
attrs: {
|
|
187
281
|
xmlns: 'encrypt',
|
|
188
282
|
type: 'get',
|
|
189
|
-
to:
|
|
283
|
+
to: S_WHATSAPP_NET
|
|
190
284
|
},
|
|
191
285
|
content: [
|
|
192
286
|
{
|
|
193
287
|
tag: 'key',
|
|
194
288
|
attrs: {},
|
|
195
|
-
content:
|
|
289
|
+
content: wireJids.map(jid => ({
|
|
196
290
|
tag: 'user',
|
|
197
|
-
attrs: { jid }
|
|
291
|
+
attrs: { jid }
|
|
198
292
|
}))
|
|
199
293
|
}
|
|
200
294
|
]
|
|
201
295
|
});
|
|
202
|
-
await
|
|
296
|
+
await parseAndInjectE2ESessions(result, signalRepository);
|
|
203
297
|
didFetchNewSession = true;
|
|
298
|
+
// Cache fetched sessions using wire JIDs
|
|
299
|
+
for (const wireJid of wireJids) {
|
|
300
|
+
const signalId = signalRepository.jidToSignalProtocolAddress(wireJid);
|
|
301
|
+
peerSessionsCache.set(signalId, true);
|
|
302
|
+
}
|
|
204
303
|
}
|
|
205
304
|
return didFetchNewSession;
|
|
206
305
|
};
|
|
207
306
|
const sendPeerDataOperationMessage = async (pdoMessage) => {
|
|
208
|
-
var _a;
|
|
209
307
|
//TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
|
|
210
|
-
if (!
|
|
211
|
-
throw new
|
|
308
|
+
if (!authState.creds.me?.id) {
|
|
309
|
+
throw new Boom('Not authenticated');
|
|
212
310
|
}
|
|
213
311
|
const protocolMessage = {
|
|
214
312
|
protocolMessage: {
|
|
215
313
|
peerDataOperationRequestMessage: pdoMessage,
|
|
216
|
-
type:
|
|
314
|
+
type: proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
|
|
217
315
|
}
|
|
218
316
|
};
|
|
219
|
-
const meJid =
|
|
317
|
+
const meJid = jidNormalizedUser(authState.creds.me.id);
|
|
220
318
|
const msgId = await relayMessage(meJid, protocolMessage, {
|
|
221
319
|
additionalAttributes: {
|
|
222
320
|
category: 'peer',
|
|
223
|
-
|
|
224
|
-
push_priority: 'high_force',
|
|
321
|
+
push_priority: 'high_force'
|
|
225
322
|
},
|
|
323
|
+
additionalNodes: [
|
|
324
|
+
{
|
|
325
|
+
tag: 'meta',
|
|
326
|
+
attrs: { appdata: 'default' }
|
|
327
|
+
}
|
|
328
|
+
]
|
|
226
329
|
});
|
|
227
330
|
return msgId;
|
|
228
331
|
};
|
|
229
|
-
const createParticipantNodes = async (
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
332
|
+
const createParticipantNodes = async (recipientJids, message, extraAttrs, dsmMessage) => {
|
|
333
|
+
if (!recipientJids.length) {
|
|
334
|
+
return { nodes: [], shouldIncludeDeviceIdentity: false };
|
|
335
|
+
}
|
|
336
|
+
const patched = await patchMessageBeforeSending(message, recipientJids);
|
|
337
|
+
const patchedMessages = Array.isArray(patched)
|
|
338
|
+
? patched
|
|
339
|
+
: recipientJids.map(jid => ({ recipientJid: jid, message: patched }));
|
|
234
340
|
let shouldIncludeDeviceIdentity = false;
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
341
|
+
const meId = authState.creds.me.id;
|
|
342
|
+
const meLid = authState.creds.me?.lid;
|
|
343
|
+
const meLidUser = meLid ? jidDecode(meLid)?.user : null;
|
|
344
|
+
const encryptionPromises = patchedMessages.map(async ({ recipientJid: jid, message: patchedMessage }) => {
|
|
345
|
+
if (!jid)
|
|
346
|
+
return null;
|
|
347
|
+
let msgToEncrypt = patchedMessage;
|
|
348
|
+
if (dsmMessage) {
|
|
349
|
+
const { user: targetUser } = jidDecode(jid);
|
|
350
|
+
const { user: ownPnUser } = jidDecode(meId);
|
|
351
|
+
const ownLidUser = meLidUser;
|
|
352
|
+
const isOwnUser = targetUser === ownPnUser || (ownLidUser && targetUser === ownLidUser);
|
|
353
|
+
const isExactSenderDevice = jid === meId || (meLid && jid === meLid);
|
|
354
|
+
if (isOwnUser && !isExactSenderDevice) {
|
|
355
|
+
msgToEncrypt = dsmMessage;
|
|
356
|
+
logger.debug({ jid, targetUser }, 'Using DSM for own device');
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
const bytes = encodeWAMessage(msgToEncrypt);
|
|
360
|
+
const mutexKey = jid;
|
|
361
|
+
const node = await encryptionMutex.mutex(mutexKey, async () => {
|
|
362
|
+
const { type, ciphertext } = await signalRepository.encryptMessage({
|
|
363
|
+
jid,
|
|
364
|
+
data: bytes
|
|
365
|
+
});
|
|
366
|
+
if (type === 'pkmsg') {
|
|
367
|
+
shouldIncludeDeviceIdentity = true;
|
|
368
|
+
}
|
|
369
|
+
return {
|
|
370
|
+
tag: 'to',
|
|
371
|
+
attrs: { jid },
|
|
372
|
+
content: [
|
|
373
|
+
{
|
|
374
|
+
tag: 'enc',
|
|
375
|
+
attrs: {
|
|
376
|
+
v: '2',
|
|
377
|
+
type,
|
|
378
|
+
...(extraAttrs || {})
|
|
379
|
+
},
|
|
380
|
+
content: ciphertext
|
|
381
|
+
}
|
|
382
|
+
]
|
|
383
|
+
};
|
|
384
|
+
});
|
|
259
385
|
return node;
|
|
260
|
-
})
|
|
386
|
+
});
|
|
387
|
+
const nodes = (await Promise.all(encryptionPromises)).filter(node => node !== null);
|
|
261
388
|
return { nodes, shouldIncludeDeviceIdentity };
|
|
262
389
|
};
|
|
263
390
|
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }) => {
|
|
264
|
-
var _a;
|
|
265
391
|
const meId = authState.creds.me.id;
|
|
266
|
-
|
|
267
|
-
const
|
|
392
|
+
const meLid = authState.creds.me?.lid;
|
|
393
|
+
const isRetryResend = Boolean(participant?.jid);
|
|
394
|
+
let shouldIncludeDeviceIdentity = isRetryResend;
|
|
268
395
|
const statusJid = 'status@broadcast';
|
|
396
|
+
const { user, server } = jidDecode(jid);
|
|
269
397
|
const isGroup = server === 'g.us';
|
|
270
|
-
const isNewsletter = server === 'newsletter';
|
|
271
398
|
const isStatus = jid === statusJid;
|
|
272
399
|
const isLid = server === 'lid';
|
|
273
|
-
|
|
400
|
+
const isNewsletter = server === 'newsletter';
|
|
401
|
+
const finalJid = jid;
|
|
402
|
+
msgId = msgId || generateMessageIDV2(meId);
|
|
274
403
|
useUserDevicesCache = useUserDevicesCache !== false;
|
|
275
404
|
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
|
|
276
405
|
const participants = [];
|
|
277
|
-
const destinationJid =
|
|
406
|
+
const destinationJid = !isStatus ? finalJid : statusJid;
|
|
278
407
|
const binaryNodeContent = [];
|
|
279
408
|
const devices = [];
|
|
280
409
|
const meMsg = {
|
|
@@ -286,161 +415,241 @@ const makeMessagesSocket = (config) => {
|
|
|
286
415
|
};
|
|
287
416
|
const extraAttrs = {};
|
|
288
417
|
if (participant) {
|
|
289
|
-
// when the retry request is not for a group
|
|
290
|
-
// only send to the specific device that asked for a retry
|
|
291
|
-
// otherwise the message is sent out to every device that should be a recipient
|
|
292
418
|
if (!isGroup && !isStatus) {
|
|
293
|
-
additionalAttributes = { ...additionalAttributes,
|
|
419
|
+
additionalAttributes = { ...additionalAttributes, device_fanout: 'false' };
|
|
294
420
|
}
|
|
295
|
-
const { user, device } =
|
|
296
|
-
devices.push({
|
|
421
|
+
const { user, device } = jidDecode(participant.jid);
|
|
422
|
+
devices.push({
|
|
423
|
+
user,
|
|
424
|
+
device,
|
|
425
|
+
jid: participant.jid
|
|
426
|
+
});
|
|
297
427
|
}
|
|
298
428
|
await authState.keys.transaction(async () => {
|
|
299
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
300
429
|
const mediaType = getMediaType(message);
|
|
301
430
|
if (mediaType) {
|
|
302
431
|
extraAttrs['mediatype'] = mediaType;
|
|
303
432
|
}
|
|
304
|
-
if (
|
|
305
|
-
|
|
433
|
+
if (isNewsletter) {
|
|
434
|
+
const patched = patchMessageBeforeSending ? await patchMessageBeforeSending(message, []) : message;
|
|
435
|
+
const bytes = encodeNewsletterMessage(patched);
|
|
436
|
+
binaryNodeContent.push({
|
|
437
|
+
tag: 'plaintext',
|
|
438
|
+
attrs: {},
|
|
439
|
+
content: bytes
|
|
440
|
+
});
|
|
441
|
+
const stanza = {
|
|
442
|
+
tag: 'message',
|
|
443
|
+
attrs: {
|
|
444
|
+
to: jid,
|
|
445
|
+
id: msgId,
|
|
446
|
+
type: getMessageType(message),
|
|
447
|
+
...(additionalAttributes || {})
|
|
448
|
+
},
|
|
449
|
+
content: binaryNodeContent
|
|
450
|
+
};
|
|
451
|
+
logger.debug({ msgId }, `sending newsletter message to ${jid}`);
|
|
452
|
+
await sendNode(stanza);
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
if (normalizeMessageContent(message)?.pinInChatMessage) {
|
|
456
|
+
extraAttrs['decrypt-fail'] = 'hide'; // todo: expand for reactions and other types
|
|
306
457
|
}
|
|
307
458
|
if (isGroup || isStatus) {
|
|
308
459
|
const [groupData, senderKeyMap] = await Promise.all([
|
|
309
460
|
(async () => {
|
|
310
|
-
let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined;
|
|
311
|
-
if (groupData && Array.isArray(groupData
|
|
461
|
+
let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined; // todo: should we rely on the cache specially if the cache is outdated and the metadata has new fields?
|
|
462
|
+
if (groupData && Array.isArray(groupData?.participants)) {
|
|
312
463
|
logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
|
|
313
464
|
}
|
|
314
465
|
else if (!isStatus) {
|
|
315
|
-
groupData = await groupMetadata(jid);
|
|
466
|
+
groupData = await groupMetadata(jid); // TODO: start storing group participant list + addr mode in Signal & stop relying on this
|
|
316
467
|
}
|
|
317
468
|
return groupData;
|
|
318
469
|
})(),
|
|
319
470
|
(async () => {
|
|
320
471
|
if (!participant && !isStatus) {
|
|
321
|
-
|
|
472
|
+
// what if sender memory is less accurate than the cached metadata
|
|
473
|
+
// on participant change in group, we should do sender memory manipulation
|
|
474
|
+
const result = await authState.keys.get('sender-key-memory', [jid]); // TODO: check out what if the sender key memory doesn't include the LID stuff now?
|
|
322
475
|
return result[jid] || {};
|
|
323
476
|
}
|
|
324
477
|
return {};
|
|
325
478
|
})()
|
|
326
479
|
]);
|
|
327
480
|
if (!participant) {
|
|
328
|
-
const participantsList =
|
|
329
|
-
if (isStatus
|
|
330
|
-
|
|
481
|
+
const participantsList = [];
|
|
482
|
+
if (isStatus) {
|
|
483
|
+
if (statusJidList?.length)
|
|
484
|
+
participantsList.push(...statusJidList);
|
|
331
485
|
}
|
|
332
|
-
|
|
486
|
+
else {
|
|
487
|
+
// default to LID based groups
|
|
488
|
+
let groupAddressingMode = 'lid';
|
|
489
|
+
if (groupData) {
|
|
490
|
+
participantsList.push(...groupData.participants.map(p => p.id));
|
|
491
|
+
groupAddressingMode = groupData?.addressingMode || groupAddressingMode;
|
|
492
|
+
}
|
|
493
|
+
// default to lid addressing mode in a group
|
|
333
494
|
additionalAttributes = {
|
|
334
495
|
...additionalAttributes,
|
|
335
|
-
|
|
336
|
-
addressing_mode: (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) || 'pn'
|
|
496
|
+
addressing_mode: groupAddressingMode
|
|
337
497
|
};
|
|
338
498
|
}
|
|
339
499
|
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
|
|
340
500
|
devices.push(...additionalDevices);
|
|
341
501
|
}
|
|
502
|
+
if (groupData?.ephemeralDuration && groupData.ephemeralDuration > 0) {
|
|
503
|
+
additionalAttributes = {
|
|
504
|
+
...additionalAttributes,
|
|
505
|
+
expiration: groupData.ephemeralDuration.toString()
|
|
506
|
+
};
|
|
507
|
+
}
|
|
342
508
|
const patched = await patchMessageBeforeSending(message);
|
|
343
509
|
if (Array.isArray(patched)) {
|
|
344
|
-
throw new
|
|
510
|
+
throw new Boom('Per-jid patching is not supported in groups');
|
|
345
511
|
}
|
|
346
|
-
const bytes =
|
|
512
|
+
const bytes = encodeWAMessage(patched);
|
|
513
|
+
const groupAddressingMode = additionalAttributes?.['addressing_mode'] || groupData?.addressingMode || 'lid';
|
|
514
|
+
const groupSenderIdentity = groupAddressingMode === 'lid' && meLid ? meLid : meId;
|
|
347
515
|
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
|
|
348
516
|
group: destinationJid,
|
|
349
517
|
data: bytes,
|
|
350
|
-
meId
|
|
518
|
+
meId: groupSenderIdentity
|
|
351
519
|
});
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
const
|
|
356
|
-
if (!
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
520
|
+
const senderKeyRecipients = [];
|
|
521
|
+
for (const device of devices) {
|
|
522
|
+
const deviceJid = device.jid;
|
|
523
|
+
const hasKey = !!senderKeyMap[deviceJid];
|
|
524
|
+
if ((!hasKey || !!participant) &&
|
|
525
|
+
!isHostedLidUser(deviceJid) &&
|
|
526
|
+
!isHostedPnUser(deviceJid) &&
|
|
527
|
+
device.device !== 99) {
|
|
528
|
+
//todo: revamp all this logic
|
|
529
|
+
// 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
|
|
530
|
+
senderKeyRecipients.push(deviceJid);
|
|
531
|
+
senderKeyMap[deviceJid] = true;
|
|
360
532
|
}
|
|
361
533
|
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
if (senderKeyJids.length) {
|
|
365
|
-
logger.debug({ senderKeyJids }, 'sending new sender key');
|
|
534
|
+
if (senderKeyRecipients.length) {
|
|
535
|
+
logger.debug({ senderKeyJids: senderKeyRecipients }, 'sending new sender key');
|
|
366
536
|
const senderKeyMsg = {
|
|
367
537
|
senderKeyDistributionMessage: {
|
|
368
538
|
axolotlSenderKeyDistributionMessage: senderKeyDistributionMessage,
|
|
369
539
|
groupId: destinationJid
|
|
370
540
|
}
|
|
371
541
|
};
|
|
372
|
-
|
|
373
|
-
|
|
542
|
+
const senderKeySessionTargets = senderKeyRecipients;
|
|
543
|
+
await assertSessions(senderKeySessionTargets);
|
|
544
|
+
const result = await createParticipantNodes(senderKeyRecipients, senderKeyMsg, extraAttrs);
|
|
374
545
|
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
|
|
375
546
|
participants.push(...result.nodes);
|
|
376
547
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
if (((_d = message.protocolMessage) === null || _d === void 0 ? void 0 : _d.type) === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
|
|
392
|
-
msgId = (_e = message.protocolMessage.key) === null || _e === void 0 ? void 0 : _e.id;
|
|
393
|
-
message = {};
|
|
548
|
+
if (isRetryResend) {
|
|
549
|
+
const { type, ciphertext: encryptedContent } = await signalRepository.encryptMessage({
|
|
550
|
+
data: bytes,
|
|
551
|
+
jid: participant?.jid
|
|
552
|
+
});
|
|
553
|
+
binaryNodeContent.push({
|
|
554
|
+
tag: 'enc',
|
|
555
|
+
attrs: {
|
|
556
|
+
v: '2',
|
|
557
|
+
type,
|
|
558
|
+
count: participant.count.toString()
|
|
559
|
+
},
|
|
560
|
+
content: encryptedContent
|
|
561
|
+
});
|
|
394
562
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
563
|
+
else {
|
|
564
|
+
binaryNodeContent.push({
|
|
565
|
+
tag: 'enc',
|
|
566
|
+
attrs: { v: '2', type: 'skmsg', ...extraAttrs },
|
|
567
|
+
content: ciphertext
|
|
568
|
+
});
|
|
569
|
+
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
|
|
398
570
|
}
|
|
399
|
-
const bytes = (0, Utils_1.encodeNewsletterMessage)(patched);
|
|
400
|
-
binaryNodeContent.push({
|
|
401
|
-
tag: 'plaintext',
|
|
402
|
-
attrs: mediaType ? { mediatype: mediaType } : {},
|
|
403
|
-
content: bytes
|
|
404
|
-
});
|
|
405
571
|
}
|
|
406
572
|
else {
|
|
407
|
-
|
|
573
|
+
// ADDRESSING CONSISTENCY: Match own identity to conversation context
|
|
574
|
+
// TODO: investigate if this is true
|
|
575
|
+
let ownId = meId;
|
|
576
|
+
if (isLid && meLid) {
|
|
577
|
+
ownId = meLid;
|
|
578
|
+
logger.debug({ to: jid, ownId }, 'Using LID identity for @lid conversation');
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
logger.debug({ to: jid, ownId }, 'Using PN identity for @s.whatsapp.net conversation');
|
|
582
|
+
}
|
|
583
|
+
const { user: ownUser } = jidDecode(ownId);
|
|
408
584
|
if (!participant) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
585
|
+
const targetUserServer = isLid ? 'lid' : 's.whatsapp.net';
|
|
586
|
+
devices.push({
|
|
587
|
+
user,
|
|
588
|
+
device: 0,
|
|
589
|
+
jid: jidEncode(user, targetUserServer, 0) // rajeh, todo: this entire logic is convoluted and weird.
|
|
590
|
+
});
|
|
591
|
+
if (user !== ownUser) {
|
|
592
|
+
const ownUserServer = isLid ? 'lid' : 's.whatsapp.net';
|
|
593
|
+
const ownUserForAddressing = isLid && meLid ? jidDecode(meLid).user : jidDecode(meId).user;
|
|
594
|
+
devices.push({
|
|
595
|
+
user: ownUserForAddressing,
|
|
596
|
+
device: 0,
|
|
597
|
+
jid: jidEncode(ownUserForAddressing, ownUserServer, 0)
|
|
598
|
+
});
|
|
412
599
|
}
|
|
413
|
-
if (
|
|
414
|
-
|
|
415
|
-
devices.
|
|
600
|
+
if (additionalAttributes?.['category'] !== 'peer') {
|
|
601
|
+
// Clear placeholders and enumerate actual devices
|
|
602
|
+
devices.length = 0;
|
|
603
|
+
// Use conversation-appropriate sender identity
|
|
604
|
+
const senderIdentity = isLid && meLid
|
|
605
|
+
? jidEncode(jidDecode(meLid)?.user, 'lid', undefined)
|
|
606
|
+
: jidEncode(jidDecode(meId)?.user, 's.whatsapp.net', undefined);
|
|
607
|
+
// Enumerate devices for sender and target with consistent addressing
|
|
608
|
+
const sessionDevices = await getUSyncDevices([senderIdentity, jid], true, false);
|
|
609
|
+
devices.push(...sessionDevices);
|
|
610
|
+
logger.debug({
|
|
611
|
+
deviceCount: devices.length,
|
|
612
|
+
devices: devices.map(d => `${d.user}:${d.device}@${jidDecode(d.jid)?.server}`)
|
|
613
|
+
}, 'Device enumeration complete with unified addressing');
|
|
416
614
|
}
|
|
417
615
|
}
|
|
418
|
-
const
|
|
419
|
-
const
|
|
420
|
-
const
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
616
|
+
const allRecipients = [];
|
|
617
|
+
const meRecipients = [];
|
|
618
|
+
const otherRecipients = [];
|
|
619
|
+
const { user: mePnUser } = jidDecode(meId);
|
|
620
|
+
const { user: meLidUser } = meLid ? jidDecode(meLid) : { user: null };
|
|
621
|
+
for (const { user, jid } of devices) {
|
|
622
|
+
const isExactSenderDevice = jid === meId || (meLid && jid === meLid);
|
|
623
|
+
if (isExactSenderDevice) {
|
|
624
|
+
logger.debug({ jid, meId, meLid }, 'Skipping exact sender device (whatsmeow pattern)');
|
|
625
|
+
continue;
|
|
626
|
+
}
|
|
627
|
+
// Check if this is our device (could match either PN or LID user)
|
|
628
|
+
const isMe = user === mePnUser || user === meLidUser;
|
|
424
629
|
if (isMe) {
|
|
425
|
-
|
|
630
|
+
meRecipients.push(jid);
|
|
426
631
|
}
|
|
427
632
|
else {
|
|
428
|
-
|
|
633
|
+
otherRecipients.push(jid);
|
|
429
634
|
}
|
|
430
|
-
|
|
635
|
+
allRecipients.push(jid);
|
|
431
636
|
}
|
|
432
|
-
await assertSessions(
|
|
637
|
+
await assertSessions(allRecipients);
|
|
433
638
|
const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
|
|
434
|
-
|
|
435
|
-
createParticipantNodes(
|
|
639
|
+
// For own devices: use DSM if available (1:1 chats only)
|
|
640
|
+
createParticipantNodes(meRecipients, meMsg || message, extraAttrs),
|
|
641
|
+
createParticipantNodes(otherRecipients, message, extraAttrs, meMsg)
|
|
436
642
|
]);
|
|
437
643
|
participants.push(...meNodes);
|
|
438
644
|
participants.push(...otherNodes);
|
|
645
|
+
if (meRecipients.length > 0 || otherRecipients.length > 0) {
|
|
646
|
+
extraAttrs['phash'] = generateParticipantHashV2([...meRecipients, ...otherRecipients]);
|
|
647
|
+
}
|
|
439
648
|
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
|
|
440
649
|
}
|
|
441
650
|
if (participants.length) {
|
|
442
|
-
if (
|
|
443
|
-
const peerNode =
|
|
651
|
+
if (additionalAttributes?.['category'] === 'peer') {
|
|
652
|
+
const peerNode = participants[0]?.content?.[0];
|
|
444
653
|
if (peerNode) {
|
|
445
654
|
binaryNodeContent.push(peerNode); // push only enc
|
|
446
655
|
}
|
|
@@ -457,7 +666,8 @@ const makeMessagesSocket = (config) => {
|
|
|
457
666
|
tag: 'message',
|
|
458
667
|
attrs: {
|
|
459
668
|
id: msgId,
|
|
460
|
-
|
|
669
|
+
to: destinationJid,
|
|
670
|
+
type: getMessageType(message),
|
|
461
671
|
...(additionalAttributes || {})
|
|
462
672
|
},
|
|
463
673
|
content: binaryNodeContent
|
|
@@ -466,11 +676,11 @@ const makeMessagesSocket = (config) => {
|
|
|
466
676
|
// ensure the message is only sent to that person
|
|
467
677
|
// if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
|
|
468
678
|
if (participant) {
|
|
469
|
-
if (
|
|
679
|
+
if (isJidGroup(destinationJid)) {
|
|
470
680
|
stanza.attrs.to = destinationJid;
|
|
471
681
|
stanza.attrs.participant = participant.jid;
|
|
472
682
|
}
|
|
473
|
-
else if (
|
|
683
|
+
else if (areJidsSameUser(participant.jid, meId)) {
|
|
474
684
|
stanza.attrs.to = participant.jid;
|
|
475
685
|
stanza.attrs.recipient = destinationJid;
|
|
476
686
|
}
|
|
@@ -482,80 +692,38 @@ const makeMessagesSocket = (config) => {
|
|
|
482
692
|
stanza.attrs.to = destinationJid;
|
|
483
693
|
}
|
|
484
694
|
if (shouldIncludeDeviceIdentity) {
|
|
695
|
+
;
|
|
485
696
|
stanza.content.push({
|
|
486
697
|
tag: 'device-identity',
|
|
487
698
|
attrs: {},
|
|
488
|
-
content:
|
|
699
|
+
content: encodeSignedDeviceIdentity(authState.creds.account, true)
|
|
489
700
|
});
|
|
490
701
|
logger.debug({ jid }, 'adding device identity');
|
|
491
702
|
}
|
|
492
703
|
if (additionalNodes && additionalNodes.length > 0) {
|
|
704
|
+
;
|
|
493
705
|
stanza.content.push(...additionalNodes);
|
|
494
706
|
}
|
|
495
|
-
const content = (0, Utils_1.normalizeMessageContent)(message);
|
|
496
|
-
const contentType = (0, Utils_1.getContentType)(content);
|
|
497
|
-
if (((0, WABinary_1.isJidGroup)(jid) || (0, WABinary_1.isJidUser)(jid)) && (contentType === 'interactiveMessage' ||
|
|
498
|
-
contentType === 'buttonsMessage' ||
|
|
499
|
-
contentType === 'listMessage')) {
|
|
500
|
-
const bizNode = { tag: 'biz', attrs: {} };
|
|
501
|
-
if ((((_l = (_k = message === null || message === void 0 ? void 0 : message.viewOnceMessage) === null || _k === void 0 ? void 0 : _k.message) === null || _l === void 0 ? void 0 : _l.interactiveMessage) || ((_o = (_m = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2) === null || _m === void 0 ? void 0 : _m.message) === null || _o === void 0 ? void 0 : _o.interactiveMessage) || ((_q = (_p = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension) === null || _p === void 0 ? void 0 : _p.message) === null || _q === void 0 ? void 0 : _q.interactiveMessage) || (message === null || message === void 0 ? void 0 : message.interactiveMessage)) || (((_s = (_r = message === null || message === void 0 ? void 0 : message.viewOnceMessage) === null || _r === void 0 ? void 0 : _r.message) === null || _s === void 0 ? void 0 : _s.buttonsMessage) || ((_u = (_t = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2) === null || _t === void 0 ? void 0 : _t.message) === null || _u === void 0 ? void 0 : _u.buttonsMessage) || ((_w = (_v = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension) === null || _v === void 0 ? void 0 : _v.message) === null || _w === void 0 ? void 0 : _w.buttonsMessage) || (message === null || message === void 0 ? void 0 : message.buttonsMessage))) {
|
|
502
|
-
bizNode.content = [{
|
|
503
|
-
tag: 'interactive',
|
|
504
|
-
attrs: {
|
|
505
|
-
type: 'native_flow',
|
|
506
|
-
v: '1'
|
|
507
|
-
},
|
|
508
|
-
content: [{
|
|
509
|
-
tag: 'native_flow',
|
|
510
|
-
attrs: { v: '9', name: 'mixed' }
|
|
511
|
-
}]
|
|
512
|
-
}];
|
|
513
|
-
}
|
|
514
|
-
else if (message === null || message === void 0 ? void 0 : message.listMessage) {
|
|
515
|
-
// list message only support in private chat
|
|
516
|
-
bizNode.content = [{
|
|
517
|
-
tag: 'list',
|
|
518
|
-
attrs: {
|
|
519
|
-
type: 'product_list',
|
|
520
|
-
v: '2'
|
|
521
|
-
}
|
|
522
|
-
}];
|
|
523
|
-
}
|
|
524
|
-
stanza.content.push(bizNode);
|
|
525
|
-
}
|
|
526
707
|
logger.debug({ msgId }, `sending message to ${participants.length} devices`);
|
|
527
708
|
await sendNode(stanza);
|
|
528
|
-
|
|
709
|
+
// Add message to retry cache if enabled
|
|
710
|
+
if (messageRetryManager && !participant) {
|
|
711
|
+
messageRetryManager.addRecentMessage(destinationJid, msgId, message);
|
|
712
|
+
}
|
|
713
|
+
}, meId);
|
|
529
714
|
return msgId;
|
|
530
715
|
};
|
|
531
|
-
const
|
|
532
|
-
if (
|
|
533
|
-
return getTypeMessage(msg.viewOnceMessage.message);
|
|
534
|
-
}
|
|
535
|
-
else if (msg.viewOnceMessageV2) {
|
|
536
|
-
return getTypeMessage(msg.viewOnceMessageV2.message);
|
|
537
|
-
}
|
|
538
|
-
else if (msg.viewOnceMessageV2Extension) {
|
|
539
|
-
return getTypeMessage(msg.viewOnceMessageV2Extension.message);
|
|
540
|
-
}
|
|
541
|
-
else if (msg.ephemeralMessage) {
|
|
542
|
-
return getTypeMessage(msg.ephemeralMessage.message);
|
|
543
|
-
}
|
|
544
|
-
else if (msg.documentWithCaptionMessage) {
|
|
545
|
-
return getTypeMessage(msg.documentWithCaptionMessage.message);
|
|
546
|
-
}
|
|
547
|
-
else if (msg.reactionMessage) {
|
|
548
|
-
return 'reaction';
|
|
549
|
-
}
|
|
550
|
-
else if (msg.pollCreationMessage || msg.pollCreationMessageV2 || msg.pollCreationMessageV3 || msg.pollUpdateMessage) {
|
|
716
|
+
const getMessageType = (message) => {
|
|
717
|
+
if (message.pollCreationMessage || message.pollCreationMessageV2 || message.pollCreationMessageV3) {
|
|
551
718
|
return 'poll';
|
|
552
719
|
}
|
|
553
|
-
|
|
554
|
-
return '
|
|
720
|
+
if (message.eventMessage) {
|
|
721
|
+
return 'event';
|
|
555
722
|
}
|
|
556
|
-
|
|
557
|
-
return '
|
|
723
|
+
if (getMediaType(message) !== '') {
|
|
724
|
+
return 'media';
|
|
558
725
|
}
|
|
726
|
+
return 'text';
|
|
559
727
|
};
|
|
560
728
|
const getMediaType = (message) => {
|
|
561
729
|
if (message.imageMessage) {
|
|
@@ -603,13 +771,14 @@ const makeMessagesSocket = (config) => {
|
|
|
603
771
|
else if (message.groupInviteMessage) {
|
|
604
772
|
return 'url';
|
|
605
773
|
}
|
|
774
|
+
return '';
|
|
606
775
|
};
|
|
607
776
|
const getPrivacyTokens = async (jids) => {
|
|
608
|
-
const t =
|
|
777
|
+
const t = unixTimestampSeconds().toString();
|
|
609
778
|
const result = await query({
|
|
610
779
|
tag: 'iq',
|
|
611
780
|
attrs: {
|
|
612
|
-
to:
|
|
781
|
+
to: S_WHATSAPP_NET,
|
|
613
782
|
type: 'set',
|
|
614
783
|
xmlns: 'privacy'
|
|
615
784
|
},
|
|
@@ -620,7 +789,7 @@ const makeMessagesSocket = (config) => {
|
|
|
620
789
|
content: jids.map(jid => ({
|
|
621
790
|
tag: 'token',
|
|
622
791
|
attrs: {
|
|
623
|
-
jid:
|
|
792
|
+
jid: jidNormalizedUser(jid),
|
|
624
793
|
t,
|
|
625
794
|
type: 'trusted_contact'
|
|
626
795
|
}
|
|
@@ -630,8 +799,8 @@ const makeMessagesSocket = (config) => {
|
|
|
630
799
|
});
|
|
631
800
|
return result;
|
|
632
801
|
};
|
|
633
|
-
const waUploadToServer =
|
|
634
|
-
const waitForMsgMediaUpdate =
|
|
802
|
+
const waUploadToServer = getWAUploadToServer(config, refreshMediaConn);
|
|
803
|
+
const waitForMsgMediaUpdate = bindWaitForEvent(ev, 'messages.media-update');
|
|
635
804
|
return {
|
|
636
805
|
...sock,
|
|
637
806
|
getPrivacyTokens,
|
|
@@ -643,14 +812,15 @@ const makeMessagesSocket = (config) => {
|
|
|
643
812
|
refreshMediaConn,
|
|
644
813
|
waUploadToServer,
|
|
645
814
|
fetchPrivacySettings,
|
|
646
|
-
getUSyncDevices,
|
|
647
|
-
createParticipantNodes,
|
|
648
815
|
sendPeerDataOperationMessage,
|
|
816
|
+
createParticipantNodes,
|
|
817
|
+
getUSyncDevices,
|
|
818
|
+
messageRetryManager,
|
|
649
819
|
updateMediaMessage: async (message) => {
|
|
650
|
-
const content =
|
|
820
|
+
const content = assertMediaContent(message.message);
|
|
651
821
|
const mediaKey = content.mediaKey;
|
|
652
822
|
const meId = authState.creds.me.id;
|
|
653
|
-
const node = await
|
|
823
|
+
const node = await encryptMediaRetryRequest(message.key, mediaKey, meId);
|
|
654
824
|
let error = undefined;
|
|
655
825
|
await Promise.all([
|
|
656
826
|
sendNode(node),
|
|
@@ -662,13 +832,16 @@ const makeMessagesSocket = (config) => {
|
|
|
662
832
|
}
|
|
663
833
|
else {
|
|
664
834
|
try {
|
|
665
|
-
const media = await
|
|
666
|
-
if (media.result !==
|
|
667
|
-
const resultStr =
|
|
668
|
-
throw new
|
|
835
|
+
const media = await decryptMediaRetryData(result.media, mediaKey, result.key.id);
|
|
836
|
+
if (media.result !== proto.MediaRetryNotification.ResultType.SUCCESS) {
|
|
837
|
+
const resultStr = proto.MediaRetryNotification.ResultType[media.result];
|
|
838
|
+
throw new Boom(`Media re-upload failed by device (${resultStr})`, {
|
|
839
|
+
data: media,
|
|
840
|
+
statusCode: getStatusCodeForMediaRetry(media.result) || 404
|
|
841
|
+
});
|
|
669
842
|
}
|
|
670
843
|
content.directPath = media.directPath;
|
|
671
|
-
content.url =
|
|
844
|
+
content.url = getUrlFromDirectPath(content.directPath);
|
|
672
845
|
logger.debug({ directPath: media.directPath, key: result.key }, 'media update successful');
|
|
673
846
|
}
|
|
674
847
|
catch (err) {
|
|
@@ -682,193 +855,94 @@ const makeMessagesSocket = (config) => {
|
|
|
682
855
|
if (error) {
|
|
683
856
|
throw error;
|
|
684
857
|
}
|
|
685
|
-
ev.emit('messages.update', [
|
|
686
|
-
{ key: message.key, update: { message: message.message } }
|
|
687
|
-
]);
|
|
858
|
+
ev.emit('messages.update', [{ key: message.key, update: { message: message.message } }]);
|
|
688
859
|
return message;
|
|
689
860
|
},
|
|
690
|
-
sendStatusMentions: async (jid, content) => {
|
|
691
|
-
return await (0, WAMedia_1.sendStatusMentions)(jid, content, sock);
|
|
692
|
-
},
|
|
693
|
-
sendStatusMentionsV2: async (jid, content) => {
|
|
694
|
-
return await (0, WAMedia_1.sendStatusMentionsV2)(jid, content, sock);
|
|
695
|
-
},
|
|
696
861
|
sendMessage: async (jid, content, options = {}) => {
|
|
697
|
-
var _a, _b, _c;
|
|
698
862
|
const userJid = authState.creds.me.id;
|
|
699
|
-
if (!options.ephemeralExpiration) {
|
|
700
|
-
if ((0, WABinary_1.isJidGroup)(jid)) {
|
|
701
|
-
const groups = await sock.groupQuery(jid, 'get', [{
|
|
702
|
-
tag: 'query',
|
|
703
|
-
attrs: {
|
|
704
|
-
request: 'interactive'
|
|
705
|
-
}
|
|
706
|
-
}]);
|
|
707
|
-
const metadata = (0, WABinary_1.getBinaryNodeChild)(groups, 'group');
|
|
708
|
-
const expiration = ((_b = (_a = (0, WABinary_1.getBinaryNodeChild)(metadata, 'ephemeral')) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.expiration) || 0;
|
|
709
|
-
options.ephemeralExpiration = expiration;
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
863
|
if (typeof content === 'object' &&
|
|
713
864
|
'disappearingMessagesInChat' in content &&
|
|
714
865
|
typeof content['disappearingMessagesInChat'] !== 'undefined' &&
|
|
715
|
-
|
|
866
|
+
isJidGroup(jid)) {
|
|
716
867
|
const { disappearingMessagesInChat } = content;
|
|
717
|
-
const value = typeof disappearingMessagesInChat === 'boolean'
|
|
718
|
-
|
|
719
|
-
|
|
868
|
+
const value = typeof disappearingMessagesInChat === 'boolean'
|
|
869
|
+
? disappearingMessagesInChat
|
|
870
|
+
? WA_DEFAULT_EPHEMERAL
|
|
871
|
+
: 0
|
|
872
|
+
: disappearingMessagesInChat;
|
|
720
873
|
await groupToggleEphemeral(jid, value);
|
|
721
874
|
}
|
|
722
|
-
if (typeof content === 'object' && 'album' in content && content.album) {
|
|
723
|
-
const { album, caption } = content;
|
|
724
|
-
if (caption && !album[0].caption) {
|
|
725
|
-
album[0].caption = caption;
|
|
726
|
-
}
|
|
727
|
-
let mediaHandle;
|
|
728
|
-
let mediaMsg;
|
|
729
|
-
const albumMsg = (0, Utils_1.generateWAMessageFromContent)(jid, {
|
|
730
|
-
albumMessage: {
|
|
731
|
-
expectedImageCount: album.filter(item => 'image' in item).length,
|
|
732
|
-
expectedVideoCount: album.filter(item => 'video' in item).length
|
|
733
|
-
}
|
|
734
|
-
}, { userJid, ...options });
|
|
735
|
-
await relayMessage(jid, albumMsg.message, {
|
|
736
|
-
messageId: albumMsg.key.id
|
|
737
|
-
});
|
|
738
|
-
for (const i in album) {
|
|
739
|
-
const media = album[i];
|
|
740
|
-
if ('image' in media) {
|
|
741
|
-
mediaMsg = await (0, Utils_1.generateWAMessage)(jid, {
|
|
742
|
-
image: media.image,
|
|
743
|
-
...(media.caption ? { caption: media.caption } : {}),
|
|
744
|
-
...options
|
|
745
|
-
}, {
|
|
746
|
-
userJid,
|
|
747
|
-
upload: async (readStream, opts) => {
|
|
748
|
-
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
|
|
749
|
-
mediaHandle = up.handle;
|
|
750
|
-
return up;
|
|
751
|
-
},
|
|
752
|
-
...options,
|
|
753
|
-
});
|
|
754
|
-
}
|
|
755
|
-
else if ('video' in media) {
|
|
756
|
-
mediaMsg = await (0, Utils_1.generateWAMessage)(jid, {
|
|
757
|
-
video: media.video,
|
|
758
|
-
...(media.caption ? { caption: media.caption } : {}),
|
|
759
|
-
...(media.gifPlayback !== undefined ? { gifPlayback: media.gifPlayback } : {}),
|
|
760
|
-
...options
|
|
761
|
-
}, {
|
|
762
|
-
userJid,
|
|
763
|
-
upload: async (readStream, opts) => {
|
|
764
|
-
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
|
|
765
|
-
mediaHandle = up.handle;
|
|
766
|
-
return up;
|
|
767
|
-
},
|
|
768
|
-
...options,
|
|
769
|
-
});
|
|
770
|
-
}
|
|
771
|
-
if (mediaMsg) {
|
|
772
|
-
mediaMsg.message.messageContextInfo = {
|
|
773
|
-
messageSecret: (0, crypto_1.randomBytes)(32),
|
|
774
|
-
messageAssociation: {
|
|
775
|
-
associationType: 1,
|
|
776
|
-
parentMessageKey: albumMsg.key
|
|
777
|
-
}
|
|
778
|
-
};
|
|
779
|
-
}
|
|
780
|
-
await relayMessage(jid, mediaMsg.message, {
|
|
781
|
-
messageId: mediaMsg.key.id
|
|
782
|
-
});
|
|
783
|
-
await new Promise(resolve => setTimeout(resolve, 800));
|
|
784
|
-
}
|
|
785
|
-
return albumMsg;
|
|
786
|
-
}
|
|
787
875
|
else {
|
|
788
|
-
|
|
789
|
-
const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
|
|
876
|
+
const fullMsg = await generateWAMessage(jid, content, {
|
|
790
877
|
logger,
|
|
791
878
|
userJid,
|
|
792
|
-
getUrlInfo: text =>
|
|
879
|
+
getUrlInfo: text => getUrlInfo(text, {
|
|
793
880
|
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
794
881
|
fetchOpts: {
|
|
795
882
|
timeout: 3000,
|
|
796
|
-
...
|
|
883
|
+
...(httpRequestOptions || {})
|
|
797
884
|
},
|
|
798
885
|
logger,
|
|
799
|
-
uploadImage: generateHighQualityLinkPreview
|
|
800
|
-
? waUploadToServer
|
|
801
|
-
: undefined
|
|
886
|
+
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
802
887
|
}),
|
|
888
|
+
//TODO: CACHE
|
|
803
889
|
getProfilePicUrl: sock.profilePictureUrl,
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
mediaHandle = up.handle;
|
|
807
|
-
return up;
|
|
808
|
-
},
|
|
890
|
+
getCallLink: sock.createCallLink,
|
|
891
|
+
upload: waUploadToServer,
|
|
809
892
|
mediaCache: config.mediaCache,
|
|
810
893
|
options: config.options,
|
|
811
|
-
messageId:
|
|
812
|
-
...options
|
|
894
|
+
messageId: generateMessageIDV2(sock.user?.id),
|
|
895
|
+
...options
|
|
813
896
|
});
|
|
897
|
+
const isEventMsg = 'event' in content && !!content.event;
|
|
814
898
|
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
815
899
|
const isEditMsg = 'edit' in content && !!content.edit;
|
|
816
900
|
const isPinMsg = 'pin' in content && !!content.pin;
|
|
817
|
-
const isKeepMsg = 'keep' in content && content.keep;
|
|
818
901
|
const isPollMessage = 'poll' in content && !!content.poll;
|
|
819
|
-
const isAiMsg = 'ai' in content && !!content.ai;
|
|
820
902
|
const additionalAttributes = {};
|
|
821
903
|
const additionalNodes = [];
|
|
822
904
|
// required for delete
|
|
823
905
|
if (isDeleteMsg) {
|
|
824
906
|
// if the chat is a group, and I am not the author, then delete the message as an admin
|
|
825
|
-
if (
|
|
907
|
+
if (isJidGroup(content.delete?.remoteJid) && !content.delete?.fromMe) {
|
|
826
908
|
additionalAttributes.edit = '8';
|
|
827
909
|
}
|
|
828
910
|
else {
|
|
829
911
|
additionalAttributes.edit = '7';
|
|
830
912
|
}
|
|
831
|
-
// required for edit message
|
|
832
913
|
}
|
|
833
914
|
else if (isEditMsg) {
|
|
834
|
-
additionalAttributes.edit =
|
|
835
|
-
// required for pin message
|
|
915
|
+
additionalAttributes.edit = '1';
|
|
836
916
|
}
|
|
837
917
|
else if (isPinMsg) {
|
|
838
918
|
additionalAttributes.edit = '2';
|
|
839
|
-
// required for keep message
|
|
840
|
-
}
|
|
841
|
-
else if (isKeepMsg) {
|
|
842
|
-
additionalAttributes.edit = '6';
|
|
843
|
-
// required for polling message
|
|
844
919
|
}
|
|
845
920
|
else if (isPollMessage) {
|
|
846
921
|
additionalNodes.push({
|
|
847
922
|
tag: 'meta',
|
|
848
923
|
attrs: {
|
|
849
924
|
polltype: 'creation'
|
|
850
|
-
}
|
|
925
|
+
}
|
|
851
926
|
});
|
|
852
|
-
// required to display AI icon on message
|
|
853
927
|
}
|
|
854
|
-
else if (
|
|
928
|
+
else if (isEventMsg) {
|
|
855
929
|
additionalNodes.push({
|
|
930
|
+
tag: 'meta',
|
|
856
931
|
attrs: {
|
|
857
|
-
|
|
858
|
-
}
|
|
859
|
-
tag: "bot"
|
|
932
|
+
event_type: 'creation'
|
|
933
|
+
}
|
|
860
934
|
});
|
|
861
935
|
}
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
936
|
+
await relayMessage(jid, fullMsg.message, {
|
|
937
|
+
messageId: fullMsg.key.id,
|
|
938
|
+
useCachedGroupMetadata: options.useCachedGroupMetadata,
|
|
939
|
+
additionalAttributes,
|
|
940
|
+
statusJidList: options.statusJidList,
|
|
941
|
+
additionalNodes
|
|
942
|
+
});
|
|
869
943
|
if (config.emitOwnEvents) {
|
|
870
944
|
process.nextTick(() => {
|
|
871
|
-
processingMutex.mutex(() =>
|
|
945
|
+
processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
|
872
946
|
});
|
|
873
947
|
}
|
|
874
948
|
return fullMsg;
|
|
@@ -876,4 +950,4 @@ const makeMessagesSocket = (config) => {
|
|
|
876
950
|
}
|
|
877
951
|
};
|
|
878
952
|
};
|
|
879
|
-
|
|
953
|
+
//# sourceMappingURL=messages-send.js.map
|