lordceaser-baileys 2.0.0 → 2.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/index.js +136901 -78899
- package/WASignalGroup/GroupProtocol.js +1697 -0
- package/WASignalGroup/ciphertext_message.js +16 -0
- package/WASignalGroup/group_cipher.js +120 -0
- package/WASignalGroup/group_session_builder.js +46 -0
- package/WASignalGroup/index.js +5 -0
- package/WASignalGroup/keyhelper.js +21 -0
- package/WASignalGroup/protobufs.js +3 -0
- package/WASignalGroup/queue_job.js +69 -0
- package/WASignalGroup/sender_chain_key.js +50 -0
- package/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/WASignalGroup/sender_key_message.js +92 -0
- package/WASignalGroup/sender_key_name.js +70 -0
- package/WASignalGroup/sender_key_record.js +56 -0
- package/WASignalGroup/sender_key_state.js +129 -0
- package/{lib/Signal/Group/sender-message-key.js → WASignalGroup/sender_message_key.js} +16 -3
- package/index.js +17 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +15 -37
- package/lib/Defaults/index.js +60 -81
- package/lib/Signal/libsignal.d.ts +3 -5
- package/lib/Signal/libsignal.js +80 -359
- package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +5 -4
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +3 -3
- package/lib/Socket/Client/index.js +19 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +2 -3
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.d.ts +100 -147
- package/lib/Socket/business.js +43 -162
- package/lib/Socket/chats.d.ts +41 -85
- package/lib/Socket/chats.js +321 -569
- package/lib/Socket/groups.d.ts +57 -103
- package/lib/Socket/groups.js +84 -116
- package/lib/Socket/index.d.ts +106 -194
- package/lib/Socket/index.js +9 -11
- package/lib/Socket/messages-recv.d.ts +89 -134
- package/lib/Socket/messages-recv.js +475 -1275
- package/lib/Socket/messages-send.d.ts +97 -141
- package/lib/Socket/messages-send.js +633 -691
- package/lib/Socket/newsletter.d.ts +74 -112
- package/lib/Socket/newsletter.js +202 -147
- package/lib/Socket/registration.d.ts +264 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +19 -34
- package/lib/Socket/socket.js +219 -547
- package/lib/Socket/usync.d.ts +37 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +10 -0
- package/lib/Store/make-cache-manager-store.d.ts +14 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-in-memory-store.js +431 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.d.ts +11 -19
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.d.ts +1 -3
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.d.ts +8 -25
- package/lib/Types/Chat.js +4 -8
- package/lib/Types/Contact.d.ts +1 -8
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.d.ts +17 -101
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.d.ts +3 -18
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.d.ts +0 -1
- package/lib/Types/Label.js +5 -3
- package/lib/Types/LabelAssociation.d.ts +0 -1
- package/lib/Types/LabelAssociation.js +5 -3
- package/lib/Types/Message.d.ts +204 -91
- package/lib/Types/Message.js +9 -11
- package/lib/Types/Newsletter.d.ts +92 -0
- package/lib/Types/Newsletter.js +32 -0
- package/lib/Types/Product.d.ts +1 -2
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.d.ts +2 -32
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.d.ts +24 -44
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.d.ts +2 -72
- package/lib/Types/State.js +2 -56
- package/lib/Types/USync.d.ts +2 -3
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.d.ts +16 -16
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.d.ts +6 -12
- package/lib/Utils/auth-utils.js +143 -239
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/business.d.ts +3 -4
- package/lib/Utils/business.js +69 -66
- package/lib/Utils/c4-compat.js +0 -8
- package/lib/Utils/chat-utils.d.ts +17 -47
- package/lib/Utils/chat-utils.js +237 -364
- package/lib/Utils/crypto.d.ts +21 -18
- package/lib/Utils/crypto.js +125 -44
- package/lib/Utils/decode-wa-message.d.ts +8 -38
- package/lib/Utils/decode-wa-message.js +90 -173
- package/lib/Utils/event-buffer.d.ts +8 -9
- package/lib/Utils/event-buffer.js +71 -176
- package/lib/Utils/generics.d.ts +22 -26
- package/lib/Utils/generics.js +175 -166
- package/lib/Utils/history.d.ts +11 -16
- package/lib/Utils/history.js +53 -93
- package/lib/Utils/index.d.ts +17 -22
- package/lib/Utils/index.js +34 -22
- package/lib/Utils/link-preview.d.ts +5 -5
- package/lib/Utils/link-preview.js +24 -16
- package/lib/Utils/logger.d.ts +1 -11
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.d.ts +12 -8
- package/lib/Utils/lt-hash.js +46 -3
- package/lib/Utils/make-mutex.d.ts +0 -2
- package/lib/Utils/make-mutex.js +34 -24
- package/lib/Utils/messages-media.d.ts +45 -65
- package/lib/Utils/messages-media.js +358 -425
- package/lib/Utils/messages.d.ts +18 -32
- package/lib/Utils/messages.js +720 -392
- package/lib/Utils/noise-handler.d.ts +13 -13
- package/lib/Utils/noise-handler.js +108 -149
- package/lib/Utils/process-message.d.ts +11 -30
- package/lib/Utils/process-message.js +166 -423
- package/lib/Utils/signal.d.ts +6 -20
- package/lib/Utils/signal.js +65 -107
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -2
- package/lib/Utils/use-multi-file-auth-state.js +103 -57
- package/lib/Utils/use-single-file-auth-state.d.ts +12 -0
- package/lib/Utils/use-single-file-auth-state.js +76 -0
- package/lib/Utils/validate-connection.d.ts +6 -6
- package/lib/Utils/validate-connection.js +114 -119
- package/lib/WABinary/constants.d.ts +4 -5
- package/lib/WABinary/constants.js +20 -1281
- package/lib/WABinary/decode.d.ts +3 -4
- package/lib/WABinary/decode.js +53 -51
- package/lib/WABinary/encode.d.ts +1 -2
- package/lib/WABinary/encode.js +44 -12
- package/lib/WABinary/generic-utils.d.ts +6 -7
- package/lib/WABinary/generic-utils.js +43 -46
- package/lib/WABinary/index.d.ts +5 -6
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.d.ts +7 -24
- package/lib/WABinary/jid-utils.js +40 -74
- package/lib/WABinary/types.d.ts +1 -2
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.d.ts +1 -2
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.d.ts +3 -5
- package/lib/WAM/constants.js +11958 -19461
- package/lib/WAM/encode.d.ts +2 -3
- package/lib/WAM/encode.js +22 -17
- package/lib/WAM/index.d.ts +3 -4
- package/lib/WAM/index.js +19 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +13 -33
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -9
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -5
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +8 -13
- package/lib/WAUSync/Protocols/index.d.ts +4 -6
- package/lib/WAUSync/Protocols/index.js +20 -6
- package/lib/WAUSync/USyncQuery.d.ts +4 -6
- package/lib/WAUSync/USyncQuery.js +35 -44
- package/lib/WAUSync/USyncUser.d.ts +4 -11
- package/lib/WAUSync/USyncUser.js +5 -10
- package/lib/WAUSync/index.d.ts +3 -4
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.js +31 -13
- package/package.json +19 -10
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/WAProto.proto +0 -5479
- package/WAProto/fix-imports.js +0 -85
- package/WAProto/index.d.ts +0 -14017
- package/lib/Defaults/index.d.ts.map +0 -1
- package/lib/Defaults/index.js.map +0 -1
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -10
- package/lib/Signal/Group/ciphertext-message.d.ts.map +0 -1
- package/lib/Signal/Group/ciphertext-message.js +0 -12
- package/lib/Signal/Group/ciphertext-message.js.map +0 -1
- package/lib/Signal/Group/group-session-builder.d.ts +0 -15
- package/lib/Signal/Group/group-session-builder.d.ts.map +0 -1
- package/lib/Signal/Group/group-session-builder.js +0 -30
- package/lib/Signal/Group/group-session-builder.js.map +0 -1
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/group_cipher.d.ts.map +0 -1
- package/lib/Signal/Group/group_cipher.js +0 -82
- package/lib/Signal/Group/group_cipher.js.map +0 -1
- package/lib/Signal/Group/index.d.ts +0 -12
- package/lib/Signal/Group/index.d.ts.map +0 -1
- package/lib/Signal/Group/index.js +0 -12
- package/lib/Signal/Group/index.js.map +0 -1
- package/lib/Signal/Group/keyhelper.d.ts +0 -11
- package/lib/Signal/Group/keyhelper.d.ts.map +0 -1
- package/lib/Signal/Group/keyhelper.js +0 -18
- package/lib/Signal/Group/keyhelper.js.map +0 -1
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
- package/lib/Signal/Group/sender-chain-key.d.ts.map +0 -1
- package/lib/Signal/Group/sender-chain-key.js +0 -26
- package/lib/Signal/Group/sender-chain-key.js.map +0 -1
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
- package/lib/Signal/Group/sender-key-distribution-message.js.map +0 -1
- package/lib/Signal/Group/sender-key-message.d.ts +0 -19
- package/lib/Signal/Group/sender-key-message.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-message.js +0 -66
- package/lib/Signal/Group/sender-key-message.js.map +0 -1
- package/lib/Signal/Group/sender-key-name.d.ts +0 -18
- package/lib/Signal/Group/sender-key-name.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-name.js +0 -48
- package/lib/Signal/Group/sender-key-name.js.map +0 -1
- package/lib/Signal/Group/sender-key-record.d.ts +0 -31
- package/lib/Signal/Group/sender-key-record.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-record.js +0 -41
- package/lib/Signal/Group/sender-key-record.js.map +0 -1
- package/lib/Signal/Group/sender-key-state.d.ts +0 -39
- package/lib/Signal/Group/sender-key-state.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-state.js +0 -84
- package/lib/Signal/Group/sender-key-state.js.map +0 -1
- package/lib/Signal/Group/sender-message-key.d.ts +0 -12
- package/lib/Signal/Group/sender-message-key.d.ts.map +0 -1
- package/lib/Signal/Group/sender-message-key.js.map +0 -1
- package/lib/Signal/libsignal.d.ts.map +0 -1
- package/lib/Signal/libsignal.js.map +0 -1
- package/lib/Signal/lid-mapping.d.ts +0 -23
- package/lib/Signal/lid-mapping.d.ts.map +0 -1
- package/lib/Signal/lid-mapping.js +0 -277
- package/lib/Signal/lid-mapping.js.map +0 -1
- package/lib/Socket/Client/index.d.ts.map +0 -1
- package/lib/Socket/Client/index.js.map +0 -1
- package/lib/Socket/Client/types.d.ts.map +0 -1
- package/lib/Socket/Client/types.js +0 -11
- package/lib/Socket/Client/types.js.map +0 -1
- package/lib/Socket/Client/websocket.d.ts.map +0 -1
- package/lib/Socket/Client/websocket.js +0 -54
- package/lib/Socket/Client/websocket.js.map +0 -1
- package/lib/Socket/business.d.ts.map +0 -1
- package/lib/Socket/business.js.map +0 -1
- package/lib/Socket/chats.d.ts.map +0 -1
- package/lib/Socket/chats.js.map +0 -1
- package/lib/Socket/communities.d.ts +0 -273
- package/lib/Socket/communities.d.ts.map +0 -1
- package/lib/Socket/communities.js +0 -431
- package/lib/Socket/communities.js.map +0 -1
- package/lib/Socket/groups.d.ts.map +0 -1
- package/lib/Socket/groups.js.map +0 -1
- package/lib/Socket/index.d.ts.map +0 -1
- package/lib/Socket/index.js.map +0 -1
- package/lib/Socket/messages-recv.d.ts.map +0 -1
- package/lib/Socket/messages-recv.js.map +0 -1
- package/lib/Socket/messages-send.d.ts.map +0 -1
- package/lib/Socket/messages-send.js.map +0 -1
- package/lib/Socket/mex.d.ts +0 -3
- package/lib/Socket/mex.d.ts.map +0 -1
- package/lib/Socket/mex.js +0 -42
- package/lib/Socket/mex.js.map +0 -1
- package/lib/Socket/newsletter.d.ts.map +0 -1
- package/lib/Socket/newsletter.js.map +0 -1
- package/lib/Socket/socket.d.ts.map +0 -1
- package/lib/Socket/socket.js.map +0 -1
- package/lib/Types/Auth.d.ts.map +0 -1
- package/lib/Types/Auth.js.map +0 -1
- package/lib/Types/Bussines.d.ts +0 -25
- package/lib/Types/Bussines.d.ts.map +0 -1
- package/lib/Types/Bussines.js +0 -2
- package/lib/Types/Bussines.js.map +0 -1
- package/lib/Types/Call.d.ts.map +0 -1
- package/lib/Types/Call.js.map +0 -1
- package/lib/Types/Chat.d.ts.map +0 -1
- package/lib/Types/Chat.js.map +0 -1
- package/lib/Types/Contact.d.ts.map +0 -1
- package/lib/Types/Contact.js.map +0 -1
- package/lib/Types/Events.d.ts.map +0 -1
- package/lib/Types/Events.js.map +0 -1
- package/lib/Types/GroupMetadata.d.ts.map +0 -1
- package/lib/Types/GroupMetadata.js.map +0 -1
- package/lib/Types/Label.d.ts.map +0 -1
- package/lib/Types/Label.js.map +0 -1
- package/lib/Types/LabelAssociation.d.ts.map +0 -1
- package/lib/Types/LabelAssociation.js.map +0 -1
- package/lib/Types/Message.d.ts.map +0 -1
- package/lib/Types/Message.js.map +0 -1
- package/lib/Types/Mex.d.ts +0 -141
- package/lib/Types/Mex.d.ts.map +0 -1
- package/lib/Types/Mex.js +0 -37
- package/lib/Types/Mex.js.map +0 -1
- package/lib/Types/Product.d.ts.map +0 -1
- package/lib/Types/Product.js.map +0 -1
- package/lib/Types/Signal.d.ts.map +0 -1
- package/lib/Types/Signal.js.map +0 -1
- package/lib/Types/Socket.d.ts.map +0 -1
- package/lib/Types/Socket.js.map +0 -1
- package/lib/Types/State.d.ts.map +0 -1
- package/lib/Types/State.js.map +0 -1
- package/lib/Types/USync.d.ts.map +0 -1
- package/lib/Types/USync.js.map +0 -1
- package/lib/Types/index.d.ts.map +0 -1
- package/lib/Types/index.js.map +0 -1
- package/lib/Utils/auth-utils.d.ts.map +0 -1
- package/lib/Utils/auth-utils.js.map +0 -1
- package/lib/Utils/browser-utils.d.ts +0 -4
- package/lib/Utils/browser-utils.d.ts.map +0 -1
- package/lib/Utils/browser-utils.js +0 -29
- package/lib/Utils/browser-utils.js.map +0 -1
- package/lib/Utils/business.d.ts.map +0 -1
- package/lib/Utils/business.js.map +0 -1
- package/lib/Utils/chat-utils.d.ts.map +0 -1
- package/lib/Utils/chat-utils.js.map +0 -1
- package/lib/Utils/companion-reg-client-utils.d.ts +0 -17
- package/lib/Utils/companion-reg-client-utils.d.ts.map +0 -1
- package/lib/Utils/companion-reg-client-utils.js +0 -35
- package/lib/Utils/companion-reg-client-utils.js.map +0 -1
- package/lib/Utils/crypto.d.ts.map +0 -1
- package/lib/Utils/crypto.js.map +0 -1
- package/lib/Utils/decode-wa-message.d.ts.map +0 -1
- package/lib/Utils/decode-wa-message.js.map +0 -1
- package/lib/Utils/event-buffer.d.ts.map +0 -1
- package/lib/Utils/event-buffer.js.map +0 -1
- package/lib/Utils/generics.d.ts.map +0 -1
- package/lib/Utils/generics.js.map +0 -1
- package/lib/Utils/history.d.ts.map +0 -1
- package/lib/Utils/history.js.map +0 -1
- package/lib/Utils/identity-change-handler.d.ts +0 -44
- package/lib/Utils/identity-change-handler.d.ts.map +0 -1
- package/lib/Utils/identity-change-handler.js +0 -50
- package/lib/Utils/identity-change-handler.js.map +0 -1
- package/lib/Utils/index.d.ts.map +0 -1
- package/lib/Utils/index.js.map +0 -1
- package/lib/Utils/link-preview.d.ts.map +0 -1
- package/lib/Utils/link-preview.js.map +0 -1
- package/lib/Utils/logger.d.ts.map +0 -1
- package/lib/Utils/logger.js.map +0 -1
- package/lib/Utils/lt-hash.d.ts.map +0 -1
- package/lib/Utils/lt-hash.js.map +0 -1
- package/lib/Utils/make-mutex.d.ts.map +0 -1
- package/lib/Utils/make-mutex.js.map +0 -1
- package/lib/Utils/message-retry-manager.d.ts +0 -115
- package/lib/Utils/message-retry-manager.d.ts.map +0 -1
- package/lib/Utils/message-retry-manager.js +0 -265
- package/lib/Utils/message-retry-manager.js.map +0 -1
- package/lib/Utils/messages-media.d.ts.map +0 -1
- package/lib/Utils/messages-media.js.map +0 -1
- package/lib/Utils/messages.d.ts.map +0 -1
- package/lib/Utils/messages.js.map +0 -1
- package/lib/Utils/noise-handler.d.ts.map +0 -1
- package/lib/Utils/noise-handler.js.map +0 -1
- package/lib/Utils/offline-node-processor.d.ts +0 -17
- package/lib/Utils/offline-node-processor.d.ts.map +0 -1
- package/lib/Utils/offline-node-processor.js +0 -40
- package/lib/Utils/offline-node-processor.js.map +0 -1
- package/lib/Utils/pre-key-manager.d.ts +0 -28
- package/lib/Utils/pre-key-manager.d.ts.map +0 -1
- package/lib/Utils/pre-key-manager.js +0 -106
- package/lib/Utils/pre-key-manager.js.map +0 -1
- package/lib/Utils/process-message.d.ts.map +0 -1
- package/lib/Utils/process-message.js.map +0 -1
- package/lib/Utils/reporting-utils.d.ts +0 -11
- package/lib/Utils/reporting-utils.d.ts.map +0 -1
- package/lib/Utils/reporting-utils.js +0 -258
- package/lib/Utils/reporting-utils.js.map +0 -1
- package/lib/Utils/signal.d.ts.map +0 -1
- package/lib/Utils/signal.js.map +0 -1
- package/lib/Utils/stanza-ack.d.ts +0 -11
- package/lib/Utils/stanza-ack.d.ts.map +0 -1
- package/lib/Utils/stanza-ack.js +0 -38
- package/lib/Utils/stanza-ack.js.map +0 -1
- package/lib/Utils/sync-action-utils.d.ts +0 -19
- package/lib/Utils/sync-action-utils.d.ts.map +0 -1
- package/lib/Utils/sync-action-utils.js +0 -49
- package/lib/Utils/sync-action-utils.js.map +0 -1
- package/lib/Utils/tc-token-utils.d.ts +0 -37
- package/lib/Utils/tc-token-utils.d.ts.map +0 -1
- package/lib/Utils/tc-token-utils.js +0 -164
- package/lib/Utils/tc-token-utils.js.map +0 -1
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +0 -1
- package/lib/Utils/use-multi-file-auth-state.js.map +0 -1
- package/lib/Utils/validate-connection.d.ts.map +0 -1
- package/lib/Utils/validate-connection.js.map +0 -1
- package/lib/WABinary/constants.d.ts.map +0 -1
- package/lib/WABinary/constants.js.map +0 -1
- package/lib/WABinary/decode.d.ts.map +0 -1
- package/lib/WABinary/decode.js.map +0 -1
- package/lib/WABinary/encode.d.ts.map +0 -1
- package/lib/WABinary/encode.js.map +0 -1
- package/lib/WABinary/generic-utils.d.ts.map +0 -1
- package/lib/WABinary/generic-utils.js.map +0 -1
- package/lib/WABinary/index.d.ts.map +0 -1
- package/lib/WABinary/index.js.map +0 -1
- package/lib/WABinary/jid-utils.d.ts.map +0 -1
- package/lib/WABinary/jid-utils.js.map +0 -1
- package/lib/WABinary/types.d.ts.map +0 -1
- package/lib/WABinary/types.js.map +0 -1
- package/lib/WAM/BinaryInfo.d.ts.map +0 -1
- package/lib/WAM/BinaryInfo.js.map +0 -1
- package/lib/WAM/constants.d.ts.map +0 -1
- package/lib/WAM/constants.js.map +0 -1
- package/lib/WAM/encode.d.ts.map +0 -1
- package/lib/WAM/encode.js.map +0 -1
- package/lib/WAM/index.d.ts.map +0 -1
- package/lib/WAM/index.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -25
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/index.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/index.js.map +0 -1
- package/lib/WAUSync/USyncQuery.d.ts.map +0 -1
- package/lib/WAUSync/USyncQuery.js.map +0 -1
- package/lib/WAUSync/USyncUser.d.ts.map +0 -1
- package/lib/WAUSync/USyncUser.js.map +0 -1
- package/lib/WAUSync/index.d.ts.map +0 -1
- package/lib/WAUSync/index.js.map +0 -1
- package/lib/index.d.ts +0 -12
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
|
@@ -1,68 +1,65 @@
|
|
|
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
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.makeMessagesSocket = void 0;
|
|
7
|
+
const boom_1 = require("@hapi/boom");
|
|
8
|
+
const node_cache_1 = __importDefault(require("node-cache"));
|
|
9
|
+
const WAProto_1 = require("../../WAProto");
|
|
10
|
+
const Defaults_1 = require("../Defaults");
|
|
11
|
+
const Types_1 = require("../Types");
|
|
12
|
+
const Utils_1 = require("../Utils");
|
|
13
|
+
const link_preview_1 = require("../Utils/link-preview");
|
|
14
|
+
const WABinary_1 = require("../WABinary");
|
|
15
|
+
const WAUSync_1 = require("../WAUSync");
|
|
16
|
+
const newsletter_1 = require("./newsletter");
|
|
17
|
+
var ListType = WAProto_1.proto.Message.ListMessage.ListType;
|
|
18
|
+
const makeMessagesSocket = (config) => {
|
|
19
|
+
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, } = config;
|
|
20
|
+
const sock = (0, newsletter_1.makeNewsletterSocket)(config);
|
|
21
|
+
const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, generateMessageTag, sendNode, groupMetadata, groupQuery, newsletterWMexQuery, groupToggleEphemeral } = sock;
|
|
22
|
+
const patchMessageRequiresBeforeSending = (msg, recipientJids) => {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
if ((_b = (_a = msg === null || msg === void 0 ? void 0 : msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.listMessage) {
|
|
25
|
+
msg = JSON.parse(JSON.stringify(msg));
|
|
26
|
+
msg.deviceSentMessage.message.listMessage.listType = WAProto_1.proto.Message.ListMessage.ListType.SINGLE_SELECT;
|
|
27
|
+
}
|
|
28
|
+
if (msg === null || msg === void 0 ? void 0 : msg.listMessage) {
|
|
29
|
+
msg = JSON.parse(JSON.stringify(msg));
|
|
30
|
+
msg.listMessage.listType = WAProto_1.proto.Message.ListMessage.ListType.SINGLE_SELECT;
|
|
31
|
+
}
|
|
32
|
+
return msg;
|
|
33
|
+
};
|
|
34
|
+
const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
|
|
35
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
|
|
36
|
+
useClones: false
|
|
37
|
+
});
|
|
35
38
|
let mediaConn;
|
|
36
|
-
/** Per-socket media host; updated whenever media_conn is fetched. Defaults to the public WhatsApp host. */
|
|
37
|
-
let mediaHost = DEF_MEDIA_HOST;
|
|
38
39
|
const refreshMediaConn = async (forceGet = false) => {
|
|
39
40
|
const media = await mediaConn;
|
|
40
|
-
if (!media || forceGet || new Date().getTime() - media.fetchDate.getTime() > media.ttl * 1000) {
|
|
41
|
+
if (!media || forceGet || (new Date().getTime() - media.fetchDate.getTime()) > media.ttl * 1000) {
|
|
41
42
|
mediaConn = (async () => {
|
|
42
43
|
const result = await query({
|
|
43
44
|
tag: 'iq',
|
|
44
45
|
attrs: {
|
|
45
46
|
type: 'set',
|
|
46
47
|
xmlns: 'w:m',
|
|
47
|
-
to: S_WHATSAPP_NET
|
|
48
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
48
49
|
},
|
|
49
50
|
content: [{ tag: 'media_conn', attrs: {} }]
|
|
50
51
|
});
|
|
51
|
-
const mediaConnNode = getBinaryNodeChild(result, 'media_conn');
|
|
52
|
-
// TODO: explore full length of data that whatsapp provides
|
|
52
|
+
const mediaConnNode = (0, WABinary_1.getBinaryNodeChild)(result, 'media_conn');
|
|
53
53
|
const node = {
|
|
54
|
-
hosts: getBinaryNodeChildren(mediaConnNode, 'host').map(({ attrs }) => ({
|
|
54
|
+
hosts: (0, WABinary_1.getBinaryNodeChildren)(mediaConnNode, 'host').map(({ attrs }) => ({
|
|
55
55
|
hostname: attrs.hostname,
|
|
56
|
-
maxContentLengthBytes: +attrs.maxContentLengthBytes
|
|
56
|
+
maxContentLengthBytes: +attrs.maxContentLengthBytes,
|
|
57
57
|
})),
|
|
58
58
|
auth: mediaConnNode.attrs.auth,
|
|
59
59
|
ttl: +mediaConnNode.attrs.ttl,
|
|
60
60
|
fetchDate: new Date()
|
|
61
61
|
};
|
|
62
62
|
logger.debug('fetched media conn');
|
|
63
|
-
if (node.hosts[0]) {
|
|
64
|
-
mediaHost = node.hosts[0].hostname;
|
|
65
|
-
}
|
|
66
63
|
return node;
|
|
67
64
|
})();
|
|
68
65
|
}
|
|
@@ -73,20 +70,17 @@ export const makeMessagesSocket = (config) => {
|
|
|
73
70
|
* used for receipts of phone call, read, delivery etc.
|
|
74
71
|
* */
|
|
75
72
|
const sendReceipt = async (jid, participant, messageIds, type) => {
|
|
76
|
-
if (!messageIds || messageIds.length === 0) {
|
|
77
|
-
throw new Boom('missing ids in receipt');
|
|
78
|
-
}
|
|
79
73
|
const node = {
|
|
80
74
|
tag: 'receipt',
|
|
81
75
|
attrs: {
|
|
82
|
-
id: messageIds[0]
|
|
83
|
-
}
|
|
76
|
+
id: messageIds[0],
|
|
77
|
+
},
|
|
84
78
|
};
|
|
85
79
|
const isReadReceipt = type === 'read' || type === 'read-self';
|
|
86
80
|
if (isReadReceipt) {
|
|
87
|
-
node.attrs.t = unixTimestampSeconds().toString();
|
|
81
|
+
node.attrs.t = (0, Utils_1.unixTimestampSeconds)().toString();
|
|
88
82
|
}
|
|
89
|
-
if (type === 'sender' && (
|
|
83
|
+
if (type === 'sender' && (0, WABinary_1.isJidUser)(jid)) {
|
|
90
84
|
node.attrs.recipient = jid;
|
|
91
85
|
node.attrs.to = participant;
|
|
92
86
|
}
|
|
@@ -97,7 +91,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
97
91
|
}
|
|
98
92
|
}
|
|
99
93
|
if (type) {
|
|
100
|
-
node.attrs.type = type;
|
|
94
|
+
node.attrs.type = (0, WABinary_1.isJidNewsLetter)(jid) ? 'read-self' : type;
|
|
101
95
|
}
|
|
102
96
|
const remainingMessageIds = messageIds.slice(1);
|
|
103
97
|
if (remainingMessageIds.length) {
|
|
@@ -117,7 +111,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
117
111
|
};
|
|
118
112
|
/** Correctly bulk send receipts to multiple chats, participants */
|
|
119
113
|
const sendReceipts = async (keys, type) => {
|
|
120
|
-
const recps = aggregateMessageKeysNotFromMe(keys);
|
|
114
|
+
const recps = (0, Utils_1.aggregateMessageKeysNotFromMe)(keys);
|
|
121
115
|
for (const { jid, participant, messageIds } of recps) {
|
|
122
116
|
await sendReceipt(jid, participant, messageIds, type);
|
|
123
117
|
}
|
|
@@ -129,46 +123,59 @@ export const makeMessagesSocket = (config) => {
|
|
|
129
123
|
const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self';
|
|
130
124
|
await sendReceipts(keys, readType);
|
|
131
125
|
};
|
|
126
|
+
const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
|
|
127
|
+
var _a, _b, _c, _d;
|
|
128
|
+
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
129
|
+
if ((0, WABinary_1.isJidNewsLetter)(jid)) {
|
|
130
|
+
const node = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
131
|
+
input: {
|
|
132
|
+
key: jid,
|
|
133
|
+
type: "JID",
|
|
134
|
+
'view_role': 'GUEST'
|
|
135
|
+
},
|
|
136
|
+
'fetch_viewer_metadata': true,
|
|
137
|
+
'fetch_full_image': true,
|
|
138
|
+
'fetch_creation_time': true
|
|
139
|
+
});
|
|
140
|
+
const result = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(node, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
|
|
141
|
+
const metadataPath = JSON.parse(result).data[Types_1.XWAPaths.NEWSLETTER];
|
|
142
|
+
const pictype = type === 'image' ? 'picture' : 'preview';
|
|
143
|
+
const directPath = (_c = metadataPath === null || metadataPath === void 0 ? void 0 : metadataPath.thread_metadata[pictype]) === null || _c === void 0 ? void 0 : _c.direct_path;
|
|
144
|
+
return directPath ? (0, Utils_1.getUrlFromDirectPath)(directPath) : null;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
const result = await query({
|
|
148
|
+
tag: 'iq',
|
|
149
|
+
attrs: {
|
|
150
|
+
target: jid,
|
|
151
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
152
|
+
type: 'get',
|
|
153
|
+
xmlns: 'w:profile:picture'
|
|
154
|
+
},
|
|
155
|
+
content: [
|
|
156
|
+
{ tag: 'picture', attrs: { type, query: 'url' } }
|
|
157
|
+
]
|
|
158
|
+
}, timeoutMs);
|
|
159
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
|
|
160
|
+
return (_d = child === null || child === void 0 ? void 0 : child.attrs) === null || _d === void 0 ? void 0 : _d.url;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
132
163
|
/** Fetch all the devices we've to send a message to */
|
|
133
164
|
const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
|
|
165
|
+
var _a;
|
|
134
166
|
const deviceResults = [];
|
|
135
167
|
if (!useCache) {
|
|
136
168
|
logger.debug('not using cache for devices');
|
|
137
169
|
}
|
|
138
170
|
const toFetch = [];
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
const device = decoded?.device;
|
|
144
|
-
const isExplicitDevice = typeof device === 'number' && device >= 0;
|
|
145
|
-
if (isExplicitDevice && user) {
|
|
146
|
-
deviceResults.push({
|
|
147
|
-
user,
|
|
148
|
-
device,
|
|
149
|
-
jid
|
|
150
|
-
});
|
|
151
|
-
return null;
|
|
152
|
-
}
|
|
153
|
-
jid = jidNormalizedUser(jid);
|
|
154
|
-
return { jid, user };
|
|
155
|
-
})
|
|
156
|
-
.filter(jid => jid !== null);
|
|
157
|
-
let mgetDevices;
|
|
158
|
-
if (useCache && userDevicesCache.mget) {
|
|
159
|
-
const usersToFetch = jidsWithUser.map(j => j?.user).filter(Boolean);
|
|
160
|
-
mgetDevices = await userDevicesCache.mget(usersToFetch);
|
|
161
|
-
}
|
|
162
|
-
for (const { jid, user } of jidsWithUser) {
|
|
171
|
+
jids = Array.from(new Set(jids));
|
|
172
|
+
for (let jid of jids) {
|
|
173
|
+
const user = (_a = (0, WABinary_1.jidDecode)(jid)) === null || _a === void 0 ? void 0 : _a.user;
|
|
174
|
+
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
|
163
175
|
if (useCache) {
|
|
164
|
-
const devices =
|
|
165
|
-
(userDevicesCache.mget ? undefined : (await userDevicesCache.get(user)));
|
|
176
|
+
const devices = userDevicesCache.get(user);
|
|
166
177
|
if (devices) {
|
|
167
|
-
|
|
168
|
-
...d,
|
|
169
|
-
jid: jidEncode(d.user, d.server, d.device)
|
|
170
|
-
}));
|
|
171
|
-
deviceResults.push(...devicesWithJid);
|
|
178
|
+
deviceResults.push(...devices);
|
|
172
179
|
logger.trace({ user }, 'using cache for devices');
|
|
173
180
|
}
|
|
174
181
|
else {
|
|
@@ -182,547 +189,291 @@ export const makeMessagesSocket = (config) => {
|
|
|
182
189
|
if (!toFetch.length) {
|
|
183
190
|
return deviceResults;
|
|
184
191
|
}
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const user = jidDecode(jid)?.user;
|
|
189
|
-
if (user)
|
|
190
|
-
requestedLidUsers.add(user);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
const query = new USyncQuery().withContext('message').withDeviceProtocol().withLIDProtocol();
|
|
192
|
+
const query = new WAUSync_1.USyncQuery()
|
|
193
|
+
.withContext('message')
|
|
194
|
+
.withDeviceProtocol();
|
|
194
195
|
for (const jid of toFetch) {
|
|
195
|
-
query.withUser(new USyncUser().withId(jid));
|
|
196
|
+
query.withUser(new WAUSync_1.USyncUser().withId(jid));
|
|
196
197
|
}
|
|
197
198
|
const result = await sock.executeUSyncQuery(query);
|
|
198
199
|
if (result) {
|
|
199
|
-
|
|
200
|
-
const lidResults = result.list.filter(a => !!a.lid);
|
|
201
|
-
if (lidResults.length > 0) {
|
|
202
|
-
logger.trace('Storing LID maps from device call');
|
|
203
|
-
await signalRepository.lidMapping.storeLIDPNMappings(lidResults.map(a => ({ lid: a.lid, pn: a.id })));
|
|
204
|
-
// Force-refresh sessions for newly mapped LIDs to align identity addressing
|
|
205
|
-
try {
|
|
206
|
-
const lids = lidResults.map(a => a.lid);
|
|
207
|
-
if (lids.length) {
|
|
208
|
-
await assertSessions(lids, true);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
catch (e) {
|
|
212
|
-
logger.warn({ e, count: lidResults.length }, 'failed to assert sessions for newly mapped LIDs');
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
const extracted = extractDeviceJids(result?.list, authState.creds.me.id, authState.creds.me.lid, ignoreZeroDevices);
|
|
200
|
+
const extracted = (0, Utils_1.extractDeviceJids)(result === null || result === void 0 ? void 0 : result.list, authState.creds.me.id, ignoreZeroDevices);
|
|
216
201
|
const deviceMap = {};
|
|
217
202
|
for (const item of extracted) {
|
|
218
203
|
deviceMap[item.user] = deviceMap[item.user] || [];
|
|
219
|
-
deviceMap[item.user]
|
|
204
|
+
deviceMap[item.user].push(item);
|
|
205
|
+
deviceResults.push(item);
|
|
220
206
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const isLidUser = requestedLidUsers.has(user);
|
|
224
|
-
// Process all devices for this user
|
|
225
|
-
for (const item of userDevices) {
|
|
226
|
-
const finalJid = isLidUser
|
|
227
|
-
? jidEncode(user, item.server, item.device)
|
|
228
|
-
: jidEncode(item.user, item.server, item.device);
|
|
229
|
-
deviceResults.push({
|
|
230
|
-
...item,
|
|
231
|
-
jid: finalJid
|
|
232
|
-
});
|
|
233
|
-
logger.debug({
|
|
234
|
-
user: item.user,
|
|
235
|
-
device: item.device,
|
|
236
|
-
finalJid,
|
|
237
|
-
usedLid: isLidUser
|
|
238
|
-
}, 'Processed device with LID priority');
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
await devicesMutex.mutex(async () => {
|
|
242
|
-
if (userDevicesCache.mset) {
|
|
243
|
-
// if the cache supports mset, we can set all devices in one go
|
|
244
|
-
await userDevicesCache.mset(Object.entries(deviceMap).map(([key, value]) => ({ key, value })));
|
|
245
|
-
}
|
|
246
|
-
else {
|
|
247
|
-
for (const key in deviceMap) {
|
|
248
|
-
if (deviceMap[key])
|
|
249
|
-
await userDevicesCache.set(key, deviceMap[key]);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
const userDeviceUpdates = {};
|
|
254
|
-
for (const [userId, devices] of Object.entries(deviceMap)) {
|
|
255
|
-
if (devices && devices.length > 0) {
|
|
256
|
-
userDeviceUpdates[userId] = devices.map(d => d.device?.toString() || '0');
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
if (Object.keys(userDeviceUpdates).length > 0) {
|
|
260
|
-
try {
|
|
261
|
-
await authState.keys.set({ 'device-list': userDeviceUpdates });
|
|
262
|
-
logger.debug({ userCount: Object.keys(userDeviceUpdates).length }, 'stored user device lists for bulk migration');
|
|
263
|
-
}
|
|
264
|
-
catch (error) {
|
|
265
|
-
logger.warn({ error }, 'failed to store user device lists');
|
|
266
|
-
}
|
|
207
|
+
for (const key in deviceMap) {
|
|
208
|
+
userDevicesCache.set(key, deviceMap[key]);
|
|
267
209
|
}
|
|
268
210
|
}
|
|
269
211
|
return deviceResults;
|
|
270
212
|
};
|
|
271
|
-
/**
|
|
272
|
-
* Update Member Label
|
|
273
|
-
*/
|
|
274
|
-
const updateMemberLabel = (jid, memberLabel) => {
|
|
275
|
-
return relayMessage(jid, {
|
|
276
|
-
protocolMessage: {
|
|
277
|
-
type: proto.Message.ProtocolMessage.Type.GROUP_MEMBER_LABEL_CHANGE,
|
|
278
|
-
memberLabel: {
|
|
279
|
-
label: memberLabel?.slice(0, 30),
|
|
280
|
-
labelTimestamp: unixTimestampSeconds()
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}, {
|
|
284
|
-
additionalNodes: [
|
|
285
|
-
{
|
|
286
|
-
tag: 'meta',
|
|
287
|
-
attrs: {
|
|
288
|
-
tag_reason: 'user_update',
|
|
289
|
-
appdata: 'member_tag'
|
|
290
|
-
},
|
|
291
|
-
content: undefined
|
|
292
|
-
}
|
|
293
|
-
]
|
|
294
|
-
});
|
|
295
|
-
};
|
|
296
213
|
const assertSessions = async (jids, force) => {
|
|
297
214
|
let didFetchNewSession = false;
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
215
|
+
let jidsRequiringFetch = [];
|
|
216
|
+
if (force) {
|
|
217
|
+
jidsRequiringFetch = jids;
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
const addrs = jids.map(jid => (signalRepository
|
|
221
|
+
.jidToSignalProtocolAddress(jid)));
|
|
222
|
+
const sessions = await authState.keys.get('session', addrs);
|
|
223
|
+
for (const jid of jids) {
|
|
224
|
+
const signalId = signalRepository
|
|
225
|
+
.jidToSignalProtocolAddress(jid);
|
|
226
|
+
if (!sessions[signalId]) {
|
|
227
|
+
jidsRequiringFetch.push(jid);
|
|
306
228
|
}
|
|
307
229
|
}
|
|
308
|
-
jidsRequiringFetch.push(jid);
|
|
309
230
|
}
|
|
310
231
|
if (jidsRequiringFetch.length) {
|
|
311
|
-
|
|
312
|
-
const wireJids = [
|
|
313
|
-
...jidsRequiringFetch.filter(jid => !!isLidUser(jid) || !!isHostedLidUser(jid)),
|
|
314
|
-
...((await signalRepository.lidMapping.getLIDsForPNs(jidsRequiringFetch.filter(jid => !!isPnUser(jid) || !!isHostedPnUser(jid)))) || []).map(a => a.lid)
|
|
315
|
-
];
|
|
316
|
-
logger.debug({ jidsRequiringFetch, wireJids }, 'fetching sessions');
|
|
232
|
+
logger.debug({ jidsRequiringFetch }, 'fetching sessions');
|
|
317
233
|
const result = await query({
|
|
318
234
|
tag: 'iq',
|
|
319
235
|
attrs: {
|
|
320
236
|
xmlns: 'encrypt',
|
|
321
237
|
type: 'get',
|
|
322
|
-
to: S_WHATSAPP_NET
|
|
238
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
323
239
|
},
|
|
324
240
|
content: [
|
|
325
241
|
{
|
|
326
242
|
tag: 'key',
|
|
327
243
|
attrs: {},
|
|
328
|
-
content:
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
return { tag: 'user', attrs };
|
|
333
|
-
})
|
|
244
|
+
content: jidsRequiringFetch.map(jid => ({
|
|
245
|
+
tag: 'user',
|
|
246
|
+
attrs: { jid },
|
|
247
|
+
}))
|
|
334
248
|
}
|
|
335
249
|
]
|
|
336
250
|
});
|
|
337
|
-
await parseAndInjectE2ESessions(result, signalRepository);
|
|
251
|
+
await (0, Utils_1.parseAndInjectE2ESessions)(result, signalRepository);
|
|
338
252
|
didFetchNewSession = true;
|
|
339
253
|
}
|
|
340
254
|
return didFetchNewSession;
|
|
341
255
|
};
|
|
342
256
|
const sendPeerDataOperationMessage = async (pdoMessage) => {
|
|
257
|
+
var _a;
|
|
343
258
|
//TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
|
|
344
|
-
if (!authState.creds.me
|
|
345
|
-
throw new Boom('Not authenticated');
|
|
259
|
+
if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
260
|
+
throw new boom_1.Boom('Not authenticated');
|
|
346
261
|
}
|
|
347
262
|
const protocolMessage = {
|
|
348
263
|
protocolMessage: {
|
|
349
264
|
peerDataOperationRequestMessage: pdoMessage,
|
|
350
|
-
type: proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
|
|
265
|
+
type: WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
|
|
351
266
|
}
|
|
352
267
|
};
|
|
353
|
-
const meJid = jidNormalizedUser(authState.creds.me.id);
|
|
268
|
+
const meJid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
|
|
354
269
|
const msgId = await relayMessage(meJid, protocolMessage, {
|
|
355
270
|
additionalAttributes: {
|
|
356
271
|
category: 'peer',
|
|
357
|
-
|
|
272
|
+
// eslint-disable-next-line camelcase
|
|
273
|
+
push_priority: 'high_force',
|
|
358
274
|
},
|
|
359
|
-
additionalNodes: [
|
|
360
|
-
{
|
|
361
|
-
tag: 'meta',
|
|
362
|
-
attrs: { appdata: 'default' }
|
|
363
|
-
}
|
|
364
|
-
]
|
|
365
275
|
});
|
|
366
276
|
return msgId;
|
|
367
277
|
};
|
|
368
|
-
const createParticipantNodes = async (
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
const patched = await patchMessageBeforeSending(message, recipientJids);
|
|
373
|
-
const patchedMessages = Array.isArray(patched)
|
|
374
|
-
? patched
|
|
375
|
-
: recipientJids.map(jid => ({ recipientJid: jid, message: patched }));
|
|
278
|
+
const createParticipantNodes = async (jids, message, extraAttrs) => {
|
|
279
|
+
let patched = await patchMessageBeforeSending(message, jids);
|
|
280
|
+
const requiredPatched = patchMessageRequiresBeforeSending(patched, jids);
|
|
281
|
+
const bytes = (0, Utils_1.encodeWAMessage)(requiredPatched);
|
|
376
282
|
let shouldIncludeDeviceIdentity = false;
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
if (!jid)
|
|
383
|
-
return null;
|
|
384
|
-
let msgToEncrypt = patchedMessage;
|
|
385
|
-
if (dsmMessage) {
|
|
386
|
-
const { user: targetUser } = jidDecode(jid);
|
|
387
|
-
const { user: ownPnUser } = jidDecode(meId);
|
|
388
|
-
const ownLidUser = meLidUser;
|
|
389
|
-
const isOwnUser = targetUser === ownPnUser || (ownLidUser && targetUser === ownLidUser);
|
|
390
|
-
const isExactSenderDevice = jid === meId || (meLid && jid === meLid);
|
|
391
|
-
if (isOwnUser && !isExactSenderDevice) {
|
|
392
|
-
msgToEncrypt = dsmMessage;
|
|
393
|
-
logger.debug({ jid, targetUser }, 'Using DSM for own device');
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
const bytes = encodeWAMessage(msgToEncrypt);
|
|
397
|
-
const mutexKey = jid;
|
|
398
|
-
const node = await encryptionMutex.mutex(mutexKey, async () => {
|
|
399
|
-
const { type, ciphertext } = await signalRepository.encryptMessage({ jid, data: bytes });
|
|
400
|
-
if (type === 'pkmsg') {
|
|
401
|
-
shouldIncludeDeviceIdentity = true;
|
|
402
|
-
}
|
|
403
|
-
return {
|
|
404
|
-
tag: 'to',
|
|
405
|
-
attrs: { jid },
|
|
406
|
-
content: [
|
|
407
|
-
{
|
|
408
|
-
tag: 'enc',
|
|
409
|
-
attrs: { v: '2', type, ...(extraAttrs || {}) },
|
|
410
|
-
content: ciphertext
|
|
411
|
-
}
|
|
412
|
-
]
|
|
413
|
-
};
|
|
414
|
-
});
|
|
415
|
-
return node;
|
|
416
|
-
}
|
|
417
|
-
catch (err) {
|
|
418
|
-
logger.error({ jid, err }, 'Failed to encrypt for recipient');
|
|
419
|
-
return null;
|
|
283
|
+
const nodes = await Promise.all(jids.map(async (jid) => {
|
|
284
|
+
const { type, ciphertext } = await signalRepository
|
|
285
|
+
.encryptMessage({ jid, data: bytes });
|
|
286
|
+
if (type === 'pkmsg') {
|
|
287
|
+
shouldIncludeDeviceIdentity = true;
|
|
420
288
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
289
|
+
const node = {
|
|
290
|
+
tag: 'to',
|
|
291
|
+
attrs: { jid },
|
|
292
|
+
content: [{
|
|
293
|
+
tag: 'enc',
|
|
294
|
+
attrs: {
|
|
295
|
+
v: '2',
|
|
296
|
+
type,
|
|
297
|
+
...extraAttrs || {}
|
|
298
|
+
},
|
|
299
|
+
content: ciphertext
|
|
300
|
+
}]
|
|
301
|
+
};
|
|
302
|
+
return node;
|
|
303
|
+
}));
|
|
426
304
|
return { nodes, shouldIncludeDeviceIdentity };
|
|
427
|
-
};
|
|
428
|
-
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }) => {
|
|
429
|
-
const meId =
|
|
430
|
-
|
|
431
|
-
const
|
|
432
|
-
let shouldIncludeDeviceIdentity = isRetryResend;
|
|
305
|
+
}; //apela
|
|
306
|
+
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, useCachedGroupMetadata, statusJidList }) => {
|
|
307
|
+
const meId = authState.creds.me.id;
|
|
308
|
+
let shouldIncludeDeviceIdentity = false;
|
|
309
|
+
const { user, server } = (0, WABinary_1.jidDecode)(jid);
|
|
433
310
|
const statusJid = 'status@broadcast';
|
|
434
|
-
const { user, server } = jidDecode(jid);
|
|
435
311
|
const isGroup = server === 'g.us';
|
|
436
312
|
const isStatus = jid === statusJid;
|
|
437
313
|
const isLid = server === 'lid';
|
|
314
|
+
const isPrivate = server === 's.whatsapp.net';
|
|
438
315
|
const isNewsletter = server === 'newsletter';
|
|
439
|
-
|
|
440
|
-
const finalJid = jid;
|
|
441
|
-
msgId = msgId || generateMessageIDV2(meId);
|
|
316
|
+
msgId = msgId || (await config.generateMessageID() ?? (0, Utils_1.generateMessageID)());
|
|
442
317
|
useUserDevicesCache = useUserDevicesCache !== false;
|
|
443
318
|
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
|
|
444
319
|
const participants = [];
|
|
445
|
-
const destinationJid = !isStatus ?
|
|
320
|
+
const destinationJid = (!isStatus) ? (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
|
|
446
321
|
const binaryNodeContent = [];
|
|
447
322
|
const devices = [];
|
|
448
|
-
let reportingMessage;
|
|
449
323
|
const meMsg = {
|
|
450
324
|
deviceSentMessage: {
|
|
451
325
|
destinationJid,
|
|
452
326
|
message
|
|
453
|
-
}
|
|
454
|
-
messageContextInfo: message.messageContextInfo
|
|
327
|
+
}
|
|
455
328
|
};
|
|
456
329
|
const extraAttrs = {};
|
|
457
330
|
if (participant) {
|
|
331
|
+
// when the retry request is not for a group
|
|
332
|
+
// only send to the specific device that asked for a retry
|
|
333
|
+
// otherwise the message is sent out to every device that should be a recipient
|
|
458
334
|
if (!isGroup && !isStatus) {
|
|
459
|
-
additionalAttributes = { ...additionalAttributes, device_fanout: 'false' };
|
|
335
|
+
additionalAttributes = { ...additionalAttributes, 'device_fanout': 'false' };
|
|
460
336
|
}
|
|
461
|
-
const { user, device } = jidDecode(participant.jid);
|
|
462
|
-
devices.push({
|
|
463
|
-
user,
|
|
464
|
-
device,
|
|
465
|
-
jid: participant.jid
|
|
466
|
-
});
|
|
337
|
+
const { user, device } = (0, WABinary_1.jidDecode)(participant.jid);
|
|
338
|
+
devices.push({ user, device });
|
|
467
339
|
}
|
|
468
340
|
await authState.keys.transaction(async () => {
|
|
341
|
+
var _a, _b, _c, _d, _e, _f;
|
|
469
342
|
const mediaType = getMediaType(message);
|
|
470
343
|
if (mediaType) {
|
|
471
344
|
extraAttrs['mediatype'] = mediaType;
|
|
472
345
|
}
|
|
473
|
-
if (
|
|
474
|
-
|
|
475
|
-
const bytes = encodeNewsletterMessage(patched);
|
|
476
|
-
binaryNodeContent.push({
|
|
477
|
-
tag: 'plaintext',
|
|
478
|
-
attrs: {},
|
|
479
|
-
content: bytes
|
|
480
|
-
});
|
|
481
|
-
const stanza = {
|
|
482
|
-
tag: 'message',
|
|
483
|
-
attrs: {
|
|
484
|
-
to: jid,
|
|
485
|
-
id: msgId,
|
|
486
|
-
type: getMessageType(message),
|
|
487
|
-
...(additionalAttributes || {})
|
|
488
|
-
},
|
|
489
|
-
content: binaryNodeContent
|
|
490
|
-
};
|
|
491
|
-
logger.debug({ msgId }, `sending newsletter message to ${jid}`);
|
|
492
|
-
await sendNode(stanza);
|
|
493
|
-
return;
|
|
346
|
+
if ((_a = (0, Utils_1.normalizeMessageContent)(message)) === null || _a === void 0 ? void 0 : _a.pinInChatMessage) {
|
|
347
|
+
extraAttrs['decrypt-fail'] = 'hide';
|
|
494
348
|
}
|
|
495
|
-
if (
|
|
496
|
-
extraAttrs['decrypt-fail'] = 'hide'; // todo: expand for reactions and other types
|
|
497
|
-
}
|
|
498
|
-
if (isGroupOrStatus && !isRetryResend) {
|
|
349
|
+
if (isGroup || isStatus) {
|
|
499
350
|
const [groupData, senderKeyMap] = await Promise.all([
|
|
500
351
|
(async () => {
|
|
501
|
-
let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined;
|
|
502
|
-
if (groupData && Array.isArray(groupData
|
|
352
|
+
let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined;
|
|
353
|
+
if (groupData && Array.isArray(groupData === null || groupData === void 0 ? void 0 : groupData.participants)) {
|
|
503
354
|
logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
|
|
504
355
|
}
|
|
505
|
-
|
|
506
|
-
groupData = await groupMetadata(jid);
|
|
356
|
+
if (!groupData && !isStatus) {
|
|
357
|
+
groupData = await groupMetadata(jid);
|
|
507
358
|
}
|
|
508
359
|
return groupData;
|
|
509
360
|
})(),
|
|
510
361
|
(async () => {
|
|
511
362
|
if (!participant && !isStatus) {
|
|
512
|
-
|
|
513
|
-
// on participant change in group, we should do sender memory manipulation
|
|
514
|
-
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?
|
|
363
|
+
const result = await authState.keys.get('sender-key-memory', [jid]);
|
|
515
364
|
return result[jid] || {};
|
|
516
365
|
}
|
|
517
366
|
return {};
|
|
518
367
|
})()
|
|
519
368
|
]);
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
...
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
if (isStatus && statusJidList) {
|
|
528
|
-
participantsList.push(...statusJidList);
|
|
529
|
-
}
|
|
530
|
-
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
|
|
531
|
-
devices.push(...additionalDevices);
|
|
532
|
-
if (isGroup) {
|
|
533
|
-
additionalAttributes = {
|
|
534
|
-
...additionalAttributes,
|
|
535
|
-
addressing_mode: groupData?.addressingMode || 'lid'
|
|
536
|
-
};
|
|
537
|
-
}
|
|
538
|
-
const patched = await patchMessageBeforeSending(message);
|
|
539
|
-
if (Array.isArray(patched)) {
|
|
540
|
-
throw new Boom('Per-jid patching is not supported in groups');
|
|
369
|
+
if (!participant) {
|
|
370
|
+
const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : [];
|
|
371
|
+
if (isStatus && statusJidList) {
|
|
372
|
+
participantsList.push(...statusJidList);
|
|
373
|
+
}
|
|
374
|
+
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
|
|
375
|
+
devices.push(...additionalDevices);
|
|
541
376
|
}
|
|
542
|
-
const
|
|
543
|
-
|
|
544
|
-
const
|
|
545
|
-
const groupSenderIdentity = groupAddressingMode === 'lid' && meLid ? meLid : meId;
|
|
377
|
+
const patched = await patchMessageBeforeSending(message, devices.map(d => (0, WABinary_1.jidEncode)(d.user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net', d.device)));
|
|
378
|
+
const requiredPatched = patchMessageRequiresBeforeSending(patched, devices.map(d => (0, WABinary_1.jidEncode)(d.user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net', d.device)));
|
|
379
|
+
const bytes = (0, Utils_1.encodeWAMessage)(requiredPatched);
|
|
546
380
|
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
|
|
547
381
|
group: destinationJid,
|
|
548
382
|
data: bytes,
|
|
549
|
-
meId
|
|
383
|
+
meId,
|
|
550
384
|
});
|
|
551
|
-
const
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
const
|
|
555
|
-
if (
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
//todo: revamp all this logic
|
|
560
|
-
// 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
|
|
561
|
-
senderKeyRecipients.push(deviceJid);
|
|
562
|
-
senderKeyMap[deviceJid] = true;
|
|
385
|
+
const senderKeyJids = [];
|
|
386
|
+
// ensure a connection is established with every device
|
|
387
|
+
for (const { user, device } of devices) {
|
|
388
|
+
const jid = (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : 's.whatsapp.net', device);
|
|
389
|
+
if (!senderKeyMap[jid] || !!participant) {
|
|
390
|
+
senderKeyJids.push(jid);
|
|
391
|
+
// store that this person has had the sender keys sent to them
|
|
392
|
+
senderKeyMap[jid] = true;
|
|
563
393
|
}
|
|
564
394
|
}
|
|
565
|
-
if
|
|
566
|
-
|
|
395
|
+
// if there are some participants with whom the session has not been established
|
|
396
|
+
// if there are, we re-send the senderkey
|
|
397
|
+
if (senderKeyJids.length) {
|
|
398
|
+
logger.debug({ senderKeyJids }, 'sending new sender key');
|
|
567
399
|
const senderKeyMsg = {
|
|
568
400
|
senderKeyDistributionMessage: {
|
|
569
401
|
axolotlSenderKeyDistributionMessage: senderKeyDistributionMessage,
|
|
570
402
|
groupId: destinationJid
|
|
571
403
|
}
|
|
572
404
|
};
|
|
573
|
-
|
|
574
|
-
await
|
|
575
|
-
const result = await createParticipantNodes(senderKeyRecipients, senderKeyMsg, extraAttrs);
|
|
405
|
+
await assertSessions(senderKeyJids, false);
|
|
406
|
+
const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, mediaType ? { ...extraAttrs, mediatype: mediaType } : extraAttrs);
|
|
576
407
|
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
|
|
577
408
|
participants.push(...result.nodes);
|
|
578
409
|
}
|
|
579
410
|
binaryNodeContent.push({
|
|
580
411
|
tag: 'enc',
|
|
581
|
-
attrs: { v: '2', type: 'skmsg'
|
|
412
|
+
attrs: { v: '2', type: 'skmsg' },
|
|
582
413
|
content: ciphertext
|
|
583
414
|
});
|
|
584
415
|
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
|
|
585
416
|
}
|
|
586
|
-
else {
|
|
587
|
-
//
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
ownId = meLid;
|
|
592
|
-
logger.debug({ to: jid, ownId }, 'Using LID identity for @lid conversation');
|
|
417
|
+
else if (isNewsletter) {
|
|
418
|
+
// Message edit
|
|
419
|
+
if ((_a = message.protocolMessage) === null || _a === void 0 ? void 0 : _a.editedMessage) {
|
|
420
|
+
msgId = (_b = message.protocolMessage.key) === null || _b === void 0 ? void 0 : _b.id;
|
|
421
|
+
message = message.protocolMessage.editedMessage;
|
|
593
422
|
}
|
|
594
|
-
|
|
595
|
-
|
|
423
|
+
// Message delete
|
|
424
|
+
if (((_c = message.protocolMessage) === null || _c === void 0 ? void 0 : _c.type) === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
|
|
425
|
+
msgId = (_d = message.protocolMessage.key) === null || _d === void 0 ? void 0 : _d.id;
|
|
426
|
+
message = {};
|
|
596
427
|
}
|
|
597
|
-
const
|
|
428
|
+
const patched = await patchMessageBeforeSending(message, []);
|
|
429
|
+
const bytes = WAProto_1.proto.Message.encode(patched).finish();
|
|
430
|
+
binaryNodeContent.push({
|
|
431
|
+
tag: 'plaintext',
|
|
432
|
+
attrs: mediaType ? { mediatype: mediaType } : {},
|
|
433
|
+
content: bytes
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
else {
|
|
437
|
+
const { user: meUser, device: meDevice } = (0, WABinary_1.jidDecode)(meId);
|
|
598
438
|
if (!participant) {
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
:
|
|
603
|
-
}
|
|
604
|
-
if (!isRetryResend) {
|
|
605
|
-
const targetUserServer = isLid ? 'lid' : 's.whatsapp.net';
|
|
606
|
-
devices.push({
|
|
607
|
-
user,
|
|
608
|
-
device: 0,
|
|
609
|
-
jid: jidEncode(user, targetUserServer, 0) // rajeh, todo: this entire logic is convoluted and weird.
|
|
610
|
-
});
|
|
611
|
-
if (user !== ownUser) {
|
|
612
|
-
const ownUserServer = isLid ? 'lid' : 's.whatsapp.net';
|
|
613
|
-
const ownUserForAddressing = isLid && meLid ? jidDecode(meLid).user : jidDecode(meId).user;
|
|
614
|
-
devices.push({
|
|
615
|
-
user: ownUserForAddressing,
|
|
616
|
-
device: 0,
|
|
617
|
-
jid: jidEncode(ownUserForAddressing, ownUserServer, 0)
|
|
618
|
-
});
|
|
439
|
+
devices.push({ user });
|
|
440
|
+
// do not send message to self if the device is 0 (mobile)
|
|
441
|
+
if (meDevice !== undefined && meDevice !== 0) {
|
|
442
|
+
devices.push({ user: meUser });
|
|
619
443
|
}
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
const senderIdentity = isLid && meLid
|
|
625
|
-
? jidEncode(jidDecode(meLid)?.user, 'lid', undefined)
|
|
626
|
-
: jidEncode(jidDecode(meId)?.user, 's.whatsapp.net', undefined);
|
|
627
|
-
// Enumerate devices for sender and target with consistent addressing
|
|
628
|
-
const sessionDevices = await getUSyncDevices([senderIdentity, jid], true, false);
|
|
629
|
-
devices.push(...sessionDevices);
|
|
630
|
-
logger.debug({
|
|
631
|
-
deviceCount: devices.length,
|
|
632
|
-
devices: devices.map(d => `${d.user}:${d.device}@${jidDecode(d.jid)?.server}`)
|
|
633
|
-
}, 'Device enumeration complete with unified addressing');
|
|
444
|
+
const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
|
|
445
|
+
if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) !== 'peer') {
|
|
446
|
+
const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
|
|
447
|
+
devices.push(...additionalDevices);
|
|
634
448
|
}
|
|
449
|
+
devices.push(...additionalDevices);
|
|
635
450
|
}
|
|
636
|
-
const
|
|
637
|
-
const
|
|
638
|
-
const
|
|
639
|
-
const { user
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
const isExactSenderDevice = jid === meId || (meLid && jid === meLid);
|
|
643
|
-
if (isExactSenderDevice) {
|
|
644
|
-
logger.debug({ jid, meId, meLid }, 'Skipping exact sender device (whatsmeow pattern)');
|
|
645
|
-
continue;
|
|
646
|
-
}
|
|
647
|
-
// Check if this is our device (could match either PN or LID user)
|
|
648
|
-
const isMe = user === mePnUser || user === meLidUser;
|
|
451
|
+
const allJids = [];
|
|
452
|
+
const meJids = [];
|
|
453
|
+
const otherJids = [];
|
|
454
|
+
for (const { user, device } of devices) {
|
|
455
|
+
const isMe = user === meUser;
|
|
456
|
+
const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((_f = (_e = authState.creds) === null || _e === void 0 ? void 0 : _e.me) === null || _f === void 0 ? void 0 : _f.lid.split(':')[0]) || user : user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net', device);
|
|
649
457
|
if (isMe) {
|
|
650
|
-
|
|
458
|
+
meJids.push(jid);
|
|
651
459
|
}
|
|
652
460
|
else {
|
|
653
|
-
|
|
461
|
+
otherJids.push(jid);
|
|
654
462
|
}
|
|
655
|
-
|
|
463
|
+
allJids.push(jid);
|
|
656
464
|
}
|
|
657
|
-
await assertSessions(
|
|
465
|
+
await assertSessions(allJids, false);
|
|
658
466
|
const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
|
|
659
|
-
|
|
660
|
-
createParticipantNodes(
|
|
661
|
-
createParticipantNodes(otherRecipients, message, extraAttrs, meMsg)
|
|
467
|
+
createParticipantNodes(meJids, meMsg, mediaType ? { ...extraAttrs, mediatype: mediaType } : extraAttrs),
|
|
468
|
+
createParticipantNodes(otherJids, message, mediaType ? { ...extraAttrs, mediatype: mediaType } : extraAttrs)
|
|
662
469
|
]);
|
|
663
470
|
participants.push(...meNodes);
|
|
664
471
|
participants.push(...otherNodes);
|
|
665
|
-
if (meRecipients.length > 0 || otherRecipients.length > 0) {
|
|
666
|
-
extraAttrs['phash'] = generateParticipantHashV2([...meRecipients, ...otherRecipients]);
|
|
667
|
-
}
|
|
668
472
|
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
|
|
669
473
|
}
|
|
670
|
-
if (isRetryResend) {
|
|
671
|
-
const isParticipantLid = isLidUser(participant.jid);
|
|
672
|
-
const isMe = areJidsSameUser(participant.jid, isParticipantLid ? meLid : meId);
|
|
673
|
-
let messageToSend = message;
|
|
674
|
-
if (isGroupOrStatus) {
|
|
675
|
-
let groupSenderIdentity;
|
|
676
|
-
if (meLid && (await signalRepository.hasSenderKey({ group: destinationJid, meId: meLid }))) {
|
|
677
|
-
groupSenderIdentity = meLid;
|
|
678
|
-
}
|
|
679
|
-
else if (await signalRepository.hasSenderKey({ group: destinationJid, meId })) {
|
|
680
|
-
groupSenderIdentity = meId;
|
|
681
|
-
}
|
|
682
|
-
if (groupSenderIdentity) {
|
|
683
|
-
try {
|
|
684
|
-
const skdm = await signalRepository.getSenderKeyDistributionMessage({
|
|
685
|
-
group: destinationJid,
|
|
686
|
-
meId: groupSenderIdentity
|
|
687
|
-
});
|
|
688
|
-
messageToSend = {
|
|
689
|
-
...message,
|
|
690
|
-
senderKeyDistributionMessage: {
|
|
691
|
-
groupId: destinationJid,
|
|
692
|
-
axolotlSenderKeyDistributionMessage: skdm
|
|
693
|
-
}
|
|
694
|
-
};
|
|
695
|
-
}
|
|
696
|
-
catch (err) {
|
|
697
|
-
logger.warn({ err, jid: destinationJid }, 'failed to build SKDM for retry, sending without it');
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
const encodedMessageToSend = isMe
|
|
702
|
-
? encodeWAMessage({
|
|
703
|
-
deviceSentMessage: {
|
|
704
|
-
destinationJid,
|
|
705
|
-
message: messageToSend
|
|
706
|
-
}
|
|
707
|
-
})
|
|
708
|
-
: encodeWAMessage(messageToSend);
|
|
709
|
-
const { type, ciphertext: encryptedContent } = await signalRepository.encryptMessage({
|
|
710
|
-
data: encodedMessageToSend,
|
|
711
|
-
jid: participant.jid
|
|
712
|
-
});
|
|
713
|
-
binaryNodeContent.push({
|
|
714
|
-
tag: 'enc',
|
|
715
|
-
attrs: {
|
|
716
|
-
v: '2',
|
|
717
|
-
type,
|
|
718
|
-
count: participant.count.toString()
|
|
719
|
-
},
|
|
720
|
-
content: encryptedContent
|
|
721
|
-
});
|
|
722
|
-
}
|
|
723
474
|
if (participants.length) {
|
|
724
|
-
if (additionalAttributes
|
|
725
|
-
const peerNode = participants[0]
|
|
475
|
+
if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) === 'peer') {
|
|
476
|
+
const peerNode = (_e = (_d = participants[0]) === null || _d === void 0 ? void 0 : _d.content) === null || _e === void 0 ? void 0 : _e[0];
|
|
726
477
|
if (peerNode) {
|
|
727
478
|
binaryNodeContent.push(peerNode); // push only enc
|
|
728
479
|
}
|
|
@@ -739,8 +490,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
739
490
|
tag: 'message',
|
|
740
491
|
attrs: {
|
|
741
492
|
id: msgId,
|
|
742
|
-
|
|
743
|
-
type: getMessageType(message),
|
|
493
|
+
type: isNewsletter ? getTypeMessage(message) : 'text',
|
|
744
494
|
...(additionalAttributes || {})
|
|
745
495
|
},
|
|
746
496
|
content: binaryNodeContent
|
|
@@ -749,11 +499,11 @@ export const makeMessagesSocket = (config) => {
|
|
|
749
499
|
// ensure the message is only sent to that person
|
|
750
500
|
// if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
|
|
751
501
|
if (participant) {
|
|
752
|
-
if (isJidGroup(destinationJid)) {
|
|
502
|
+
if ((0, WABinary_1.isJidGroup)(destinationJid)) {
|
|
753
503
|
stanza.attrs.to = destinationJid;
|
|
754
504
|
stanza.attrs.participant = participant.jid;
|
|
755
505
|
}
|
|
756
|
-
else if (areJidsSameUser(participant.jid, meId)) {
|
|
506
|
+
else if ((0, WABinary_1.areJidsSameUser)(participant.jid, meId)) {
|
|
757
507
|
stanza.attrs.to = participant.jid;
|
|
758
508
|
stanza.attrs.recipient = destinationJid;
|
|
759
509
|
}
|
|
@@ -765,143 +515,144 @@ export const makeMessagesSocket = (config) => {
|
|
|
765
515
|
stanza.attrs.to = destinationJid;
|
|
766
516
|
}
|
|
767
517
|
if (shouldIncludeDeviceIdentity) {
|
|
768
|
-
;
|
|
769
518
|
stanza.content.push({
|
|
770
519
|
tag: 'device-identity',
|
|
771
520
|
attrs: {},
|
|
772
|
-
content: encodeSignedDeviceIdentity(authState.creds.account, true)
|
|
521
|
+
content: (0, Utils_1.encodeSignedDeviceIdentity)(authState.creds.account, true)
|
|
773
522
|
});
|
|
774
523
|
logger.debug({ jid }, 'adding device identity');
|
|
775
524
|
}
|
|
776
|
-
if (
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
525
|
+
if (additionalNodes && additionalNodes.length > 0) {
|
|
526
|
+
stanza.content.push(...additionalNodes);
|
|
527
|
+
}
|
|
528
|
+
const inMsg = (0, Utils_1.normalizeMessageContent)(message) || null;
|
|
529
|
+
const key = inMsg ? (0, Utils_1.getContentType)(inMsg) : null;
|
|
530
|
+
if (!isNewsletter && (key === 'interactiveMessage' || key === 'buttonsMessage')) {
|
|
531
|
+
const nativeNode = {
|
|
532
|
+
tag: 'biz',
|
|
533
|
+
attrs: {},
|
|
534
|
+
content: [{
|
|
535
|
+
tag: 'interactive',
|
|
536
|
+
attrs: {
|
|
537
|
+
type: 'native_flow',
|
|
538
|
+
v: '1'
|
|
539
|
+
},
|
|
540
|
+
content: [{
|
|
541
|
+
tag: 'native_flow',
|
|
542
|
+
attrs: {
|
|
543
|
+
name: 'quick_reply'
|
|
544
|
+
}
|
|
545
|
+
}]
|
|
546
|
+
}]
|
|
547
|
+
};
|
|
548
|
+
const resultNativeNode = filterNativeNode(additionalNodes);
|
|
549
|
+
if (resultNativeNode && additionalNodes && additionalNodes.length > 0) {
|
|
550
|
+
stanza.content.push(...resultNativeNode);
|
|
794
551
|
}
|
|
795
|
-
|
|
796
|
-
|
|
552
|
+
else {
|
|
553
|
+
stanza.content.push(nativeNode);
|
|
797
554
|
}
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
// Treat expired tokens the same as missing — clear from cache
|
|
808
|
-
if (tcTokenBuffer?.length && isTcTokenExpired(existingTokenEntry?.timestamp)) {
|
|
809
|
-
logger.debug({ jid: destinationJid, timestamp: existingTokenEntry?.timestamp }, 'tctoken expired, clearing');
|
|
810
|
-
tcTokenBuffer = undefined;
|
|
811
|
-
// Preserve senderTimestamp so the fire-and-forget issuance dedupe survives cleanup.
|
|
812
|
-
const cleared = existingTokenEntry?.senderTimestamp !== undefined
|
|
813
|
-
? { token: Buffer.alloc(0), senderTimestamp: existingTokenEntry.senderTimestamp }
|
|
814
|
-
: null;
|
|
815
|
-
try {
|
|
816
|
-
await authState.keys.set({ tctoken: { [tcTokenJid]: cleared } });
|
|
555
|
+
}/*
|
|
556
|
+
if (isPrivate) {
|
|
557
|
+
const botNode = {
|
|
558
|
+
tag: 'bot',
|
|
559
|
+
attrs: { biz_bot: '1' }
|
|
560
|
+
};
|
|
561
|
+
const resultBotNode = filterBotNode(additionalNodes);
|
|
562
|
+
if (resultBotNode && additionalNodes && additionalNodes.length > 0) {
|
|
563
|
+
stanza.content.push(...resultBotNode);
|
|
817
564
|
}
|
|
818
|
-
|
|
819
|
-
|
|
565
|
+
else {
|
|
566
|
+
stanza.content.push(botNode);
|
|
820
567
|
}
|
|
821
|
-
}
|
|
822
|
-
if (
|
|
823
|
-
;
|
|
568
|
+
}*
|
|
569
|
+
if (message && message.listMessage) {
|
|
824
570
|
stanza.content.push({
|
|
825
|
-
tag: '
|
|
571
|
+
tag: 'biz',
|
|
826
572
|
attrs: {},
|
|
827
|
-
content:
|
|
573
|
+
content: [
|
|
574
|
+
{
|
|
575
|
+
tag: 'list',
|
|
576
|
+
attrs: getButtonArgs(message)
|
|
577
|
+
}
|
|
578
|
+
]
|
|
828
579
|
});
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
if (is1on1Send &&
|
|
841
|
-
!isProtocolMsg &&
|
|
842
|
-
!isBotOrPSA &&
|
|
843
|
-
shouldSendNewTcToken(existingTokenEntry?.senderTimestamp) &&
|
|
844
|
-
!inFlightTcTokenIssuance.has(tcTokenJid)) {
|
|
845
|
-
inFlightTcTokenIssuance.add(tcTokenJid);
|
|
846
|
-
const issueTimestamp = unixTimestampSeconds();
|
|
847
|
-
const getPNForLID = signalRepository.lidMapping.getPNForLID.bind(signalRepository.lidMapping);
|
|
848
|
-
resolveIssuanceJid(destinationJid, sock.serverProps.lidTrustedTokenIssueToLid, getLIDForPN, getPNForLID)
|
|
849
|
-
.then(issueJid => issuePrivacyTokens([issueJid], issueTimestamp))
|
|
850
|
-
.then(async (result) => {
|
|
851
|
-
await storeTcTokensFromIqResult({
|
|
852
|
-
result,
|
|
853
|
-
fallbackJid: tcTokenJid,
|
|
854
|
-
keys: authState.keys,
|
|
855
|
-
getLIDForPN
|
|
856
|
-
});
|
|
857
|
-
const currentData = await authState.keys.get('tctoken', [tcTokenJid]);
|
|
858
|
-
const currentEntry = currentData[tcTokenJid];
|
|
859
|
-
const indexWrite = await buildMergedTcTokenIndexWrite(authState.keys, [tcTokenJid]);
|
|
860
|
-
await authState.keys.set({
|
|
861
|
-
tctoken: {
|
|
862
|
-
[tcTokenJid]: {
|
|
863
|
-
token: Buffer.alloc(0),
|
|
864
|
-
...currentEntry,
|
|
865
|
-
senderTimestamp: issueTimestamp
|
|
866
|
-
},
|
|
867
|
-
...indexWrite
|
|
580
|
+
logger.debug({ jid }, 'adding business node');
|
|
581
|
+
}*/
|
|
582
|
+
const buttonType = getButtonType(message);
|
|
583
|
+
if (buttonType) {
|
|
584
|
+
stanza.content.push({
|
|
585
|
+
tag: 'biz',
|
|
586
|
+
attrs: {},
|
|
587
|
+
content: [
|
|
588
|
+
{
|
|
589
|
+
tag: buttonType,
|
|
590
|
+
attrs: getButtonArgs(message),
|
|
868
591
|
}
|
|
869
|
-
|
|
870
|
-
})
|
|
871
|
-
.catch(err => {
|
|
872
|
-
logger.debug({ jid: destinationJid, err: err?.message }, 'fire-and-forget tctoken issuance failed');
|
|
873
|
-
})
|
|
874
|
-
.finally(() => {
|
|
875
|
-
inFlightTcTokenIssuance.delete(tcTokenJid);
|
|
592
|
+
]
|
|
876
593
|
});
|
|
594
|
+
logger.debug({ jid }, 'adding business node');
|
|
877
595
|
}
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
}
|
|
882
|
-
}, meId);
|
|
596
|
+
logger.debug({ msgId }, `sending message to ${participants.length} devices`);
|
|
597
|
+
await sendNode(stanza);
|
|
598
|
+
});
|
|
883
599
|
return msgId;
|
|
884
600
|
};
|
|
885
|
-
const
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
601
|
+
const filterNativeNode = (nodeContent) => {
|
|
602
|
+
if (Array.isArray(nodeContent)) {
|
|
603
|
+
return nodeContent.filter((item) => {
|
|
604
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
605
|
+
if (item.tag === 'biz' && ((_a = item === null || item === void 0 ? void 0 : item.content[0]) === null || _a === void 0 ? void 0 : _a.tag) === 'interactive' && ((_c = (_b = item === null || item === void 0 ? void 0 : item.content[0]) === null || _b === void 0 ? void 0 : _b.attrs) === null || _c === void 0 ? void 0 : _c.type) === 'native_flow' && ((_e = (_d = item === null || item === void 0 ? void 0 : item.content[0]) === null || _d === void 0 ? void 0 : _d.content[0]) === null || _e === void 0 ? void 0 : _e.tag) === 'native_flow' && ((_h = (_g = (_f = item === null || item === void 0 ? void 0 : item.content[0]) === null || _f === void 0 ? void 0 : _f.content[0]) === null || _g === void 0 ? void 0 : _g.attrs) === null || _h === void 0 ? void 0 : _h.name) === 'quick_reply') {
|
|
606
|
+
return false;
|
|
607
|
+
}
|
|
608
|
+
return true;
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
else {
|
|
612
|
+
return nodeContent;
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
const filterBotNode = (nodeContent) => {
|
|
616
|
+
if (Array.isArray(nodeContent)) {
|
|
617
|
+
return nodeContent.filter((item) => {
|
|
618
|
+
if (item.tag === 'bot' && item.attrs.biz_bot === '1') {
|
|
619
|
+
return false;
|
|
620
|
+
}
|
|
621
|
+
return true;
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
else {
|
|
625
|
+
return nodeContent;
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
const getTypeMessage = (msg) => {
|
|
629
|
+
if (msg.viewOnceMessage) {
|
|
630
|
+
return getTypeMessage(msg.viewOnceMessage.message);
|
|
631
|
+
}
|
|
632
|
+
else if (msg.viewOnceMessageV2) {
|
|
633
|
+
return getTypeMessage(msg.viewOnceMessageV2.message);
|
|
634
|
+
}
|
|
635
|
+
else if (msg.viewOnceMessageV2Extension) {
|
|
636
|
+
return getTypeMessage(msg.viewOnceMessageV2Extension.message);
|
|
637
|
+
}
|
|
638
|
+
else if (msg.ephemeralMessage) {
|
|
639
|
+
return getTypeMessage(msg.ephemeralMessage.message);
|
|
640
|
+
}
|
|
641
|
+
else if (msg.documentWithCaptionMessage) {
|
|
642
|
+
return getTypeMessage(msg.documentWithCaptionMessage.message);
|
|
643
|
+
}
|
|
644
|
+
else if (msg.reactionMessage) {
|
|
890
645
|
return 'reaction';
|
|
891
646
|
}
|
|
892
|
-
if (
|
|
893
|
-
normalizedMessage.pollCreationMessageV2 ||
|
|
894
|
-
normalizedMessage.pollCreationMessageV3 ||
|
|
895
|
-
normalizedMessage.pollUpdateMessage) {
|
|
647
|
+
else if (msg.pollCreationMessage || msg.pollCreationMessageV2 || msg.pollCreationMessageV3 || msg.pollUpdateMessage) {
|
|
896
648
|
return 'poll';
|
|
897
649
|
}
|
|
898
|
-
if (
|
|
899
|
-
return 'event';
|
|
900
|
-
}
|
|
901
|
-
if (getMediaType(normalizedMessage) !== '') {
|
|
650
|
+
else if (getMediaType(msg)) {
|
|
902
651
|
return 'media';
|
|
903
652
|
}
|
|
904
|
-
|
|
653
|
+
else {
|
|
654
|
+
return 'text';
|
|
655
|
+
}
|
|
905
656
|
};
|
|
906
657
|
const getMediaType = (message) => {
|
|
907
658
|
if (message.imageMessage) {
|
|
@@ -949,14 +700,46 @@ export const makeMessagesSocket = (config) => {
|
|
|
949
700
|
else if (message.groupInviteMessage) {
|
|
950
701
|
return 'url';
|
|
951
702
|
}
|
|
952
|
-
return '';
|
|
953
703
|
};
|
|
954
|
-
const
|
|
955
|
-
|
|
704
|
+
const getButtonType = (message) => {
|
|
705
|
+
if (message.buttonsMessage) {
|
|
706
|
+
return 'buttons';
|
|
707
|
+
}
|
|
708
|
+
else if (message.buttonsResponseMessage) {
|
|
709
|
+
return 'buttons_response';
|
|
710
|
+
}
|
|
711
|
+
else if (message.interactiveResponseMessage) {
|
|
712
|
+
return 'interactive_response';
|
|
713
|
+
}
|
|
714
|
+
else if (message.listMessage) {
|
|
715
|
+
return 'list';
|
|
716
|
+
}
|
|
717
|
+
else if (message.listResponseMessage) {
|
|
718
|
+
return 'list_response';
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
const getButtonArgs = (message) => {
|
|
722
|
+
if (message.templateMessage) {
|
|
723
|
+
// TODO: Add attributes
|
|
724
|
+
return {};
|
|
725
|
+
}
|
|
726
|
+
else if (message.listMessage) {
|
|
727
|
+
const type = message.listMessage.listType;
|
|
728
|
+
if (!type) {
|
|
729
|
+
throw new boom_1.Boom('Expected list type inside message');
|
|
730
|
+
}
|
|
731
|
+
return { v: '2', type: ListType[type].toLowerCase() };
|
|
732
|
+
}
|
|
733
|
+
else {
|
|
734
|
+
return {};
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
const getPrivacyTokens = async (jids) => {
|
|
738
|
+
const t = (0, Utils_1.unixTimestampSeconds)().toString();
|
|
956
739
|
const result = await query({
|
|
957
740
|
tag: 'iq',
|
|
958
741
|
attrs: {
|
|
959
|
-
to: S_WHATSAPP_NET,
|
|
742
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
960
743
|
type: 'set',
|
|
961
744
|
xmlns: 'privacy'
|
|
962
745
|
},
|
|
@@ -967,7 +750,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
967
750
|
content: jids.map(jid => ({
|
|
968
751
|
tag: 'token',
|
|
969
752
|
attrs: {
|
|
970
|
-
jid: jidNormalizedUser(jid),
|
|
753
|
+
jid: (0, WABinary_1.jidNormalizedUser)(jid),
|
|
971
754
|
t,
|
|
972
755
|
type: 'trusted_contact'
|
|
973
756
|
}
|
|
@@ -977,46 +760,33 @@ export const makeMessagesSocket = (config) => {
|
|
|
977
760
|
});
|
|
978
761
|
return result;
|
|
979
762
|
};
|
|
980
|
-
const waUploadToServer = getWAUploadToServer(config, refreshMediaConn);
|
|
981
|
-
const waitForMsgMediaUpdate = bindWaitForEvent(ev, 'messages.media-update');
|
|
982
|
-
registerSocketEndHandler(() => {
|
|
983
|
-
if (!config.userDevicesCache && userDevicesCache.close) {
|
|
984
|
-
userDevicesCache.close();
|
|
985
|
-
}
|
|
986
|
-
mediaConn = undefined;
|
|
987
|
-
if (messageRetryManager) {
|
|
988
|
-
messageRetryManager.clear();
|
|
989
|
-
}
|
|
990
|
-
});
|
|
763
|
+
const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
|
|
764
|
+
const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
|
|
991
765
|
return {
|
|
992
766
|
...sock,
|
|
993
|
-
|
|
994
|
-
devicesMutex,
|
|
995
|
-
issuePrivacyTokens,
|
|
767
|
+
getPrivacyTokens,
|
|
996
768
|
assertSessions,
|
|
997
769
|
relayMessage,
|
|
998
770
|
sendReceipt,
|
|
999
771
|
sendReceipts,
|
|
772
|
+
getButtonArgs,
|
|
1000
773
|
readMessages,
|
|
1001
774
|
refreshMediaConn,
|
|
1002
|
-
|
|
1003
|
-
getMediaHost: () => mediaHost,
|
|
1004
|
-
waUploadToServer,
|
|
1005
|
-
fetchPrivacySettings,
|
|
775
|
+
getUSyncDevices,
|
|
1006
776
|
sendPeerDataOperationMessage,
|
|
1007
777
|
createParticipantNodes,
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
778
|
+
profilePictureUrl,
|
|
779
|
+
waUploadToServer,
|
|
780
|
+
fetchPrivacySettings,
|
|
1011
781
|
updateMediaMessage: async (message) => {
|
|
1012
|
-
const content = assertMediaContent(message.message);
|
|
782
|
+
const content = (0, Utils_1.assertMediaContent)(message.message);
|
|
1013
783
|
const mediaKey = content.mediaKey;
|
|
1014
784
|
const meId = authState.creds.me.id;
|
|
1015
|
-
const node = encryptMediaRetryRequest(message.key, mediaKey, meId);
|
|
785
|
+
const node = await (0, Utils_1.encryptMediaRetryRequest)(message.key, mediaKey, meId);
|
|
1016
786
|
let error = undefined;
|
|
1017
787
|
await Promise.all([
|
|
1018
788
|
sendNode(node),
|
|
1019
|
-
waitForMsgMediaUpdate(async
|
|
789
|
+
waitForMsgMediaUpdate(async update => {
|
|
1020
790
|
const result = update.find(c => c.key.id === message.key.id);
|
|
1021
791
|
if (result) {
|
|
1022
792
|
if (result.error) {
|
|
@@ -1024,16 +794,13 @@ export const makeMessagesSocket = (config) => {
|
|
|
1024
794
|
}
|
|
1025
795
|
else {
|
|
1026
796
|
try {
|
|
1027
|
-
const media = decryptMediaRetryData(result.media, mediaKey, result.key.id);
|
|
1028
|
-
if (media.result !== proto.MediaRetryNotification.ResultType.SUCCESS) {
|
|
1029
|
-
const resultStr = proto.MediaRetryNotification.ResultType[media.result];
|
|
1030
|
-
throw new Boom(`Media re-upload failed by device (${resultStr})`, {
|
|
1031
|
-
data: media,
|
|
1032
|
-
statusCode: getStatusCodeForMediaRetry(media.result) || 404
|
|
1033
|
-
});
|
|
797
|
+
const media = await (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
|
|
798
|
+
if (media && media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
|
|
799
|
+
const resultStr = WAProto_1.proto.MediaRetryNotification.ResultType[media.result];
|
|
800
|
+
throw new boom_1.Boom(`Media re-upload failed by device (${resultStr})`, { data: media, statusCode: (0, Utils_1.getStatusCodeForMediaRetry)(media.result) || 404 });
|
|
1034
801
|
}
|
|
1035
802
|
content.directPath = media.directPath;
|
|
1036
|
-
content.url = getUrlFromDirectPath(content.directPath
|
|
803
|
+
content.url = (0, Utils_1.getUrlFromDirectPath)(content.directPath);
|
|
1037
804
|
logger.debug({ directPath: media.directPath, key: result.key }, 'media update successful');
|
|
1038
805
|
}
|
|
1039
806
|
catch (err) {
|
|
@@ -1047,56 +814,236 @@ export const makeMessagesSocket = (config) => {
|
|
|
1047
814
|
if (error) {
|
|
1048
815
|
throw error;
|
|
1049
816
|
}
|
|
1050
|
-
ev.emit('messages.update', [
|
|
817
|
+
ev.emit('messages.update', [
|
|
818
|
+
{ key: message.key, update: { message: message.message } }
|
|
819
|
+
]);
|
|
1051
820
|
return message;
|
|
1052
821
|
},
|
|
822
|
+
sendStatusMentions: async (content, jids = []) => {
|
|
823
|
+
const userJid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
|
|
824
|
+
let allUsers = [];
|
|
825
|
+
for (const id of jids) {
|
|
826
|
+
const { user, server } = (0, WABinary_1.jidDecode)(id);
|
|
827
|
+
const isGroup = server === 'g.us';
|
|
828
|
+
const isPrivate = server === 's.whatsapp.net';
|
|
829
|
+
if (isGroup) {
|
|
830
|
+
let userId = await groupMetadata(id);
|
|
831
|
+
let participant = await userId.participants;
|
|
832
|
+
let users = await Promise.all(participant.map(u => (0, WABinary_1.jidNormalizedUser)(u.id)));
|
|
833
|
+
allUsers = [...allUsers, ...users];
|
|
834
|
+
}
|
|
835
|
+
else if (isPrivate) {
|
|
836
|
+
let users = await Promise.all(jids.map(id => id.replace(/\b\d{18}@.{4}\b/g, '')));
|
|
837
|
+
allUsers = [...allUsers, ...users];
|
|
838
|
+
}
|
|
839
|
+
if (!allUsers.find(user => user.includes(userJid))) {
|
|
840
|
+
allUsers.push(userJid);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
;
|
|
844
|
+
const getRandomHexColor = () => {
|
|
845
|
+
return "#" + Math.floor(Math.random() * 16777215)
|
|
846
|
+
.toString(16)
|
|
847
|
+
.padStart(6, "0");
|
|
848
|
+
};
|
|
849
|
+
let mediaHandle;
|
|
850
|
+
let msg = await (0, Utils_1.generateWAMessage)(WABinary_1.STORIES_JID, content, {
|
|
851
|
+
logger,
|
|
852
|
+
userJid,
|
|
853
|
+
getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
|
|
854
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
855
|
+
fetchOpts: {
|
|
856
|
+
timeout: 3000,
|
|
857
|
+
...axiosOptions || {}
|
|
858
|
+
},
|
|
859
|
+
logger,
|
|
860
|
+
uploadImage: generateHighQualityLinkPreview
|
|
861
|
+
? waUploadToServer
|
|
862
|
+
: undefined
|
|
863
|
+
}),
|
|
864
|
+
upload: async (readStream, opts) => {
|
|
865
|
+
const up = await waUploadToServer(readStream, { ...opts });
|
|
866
|
+
mediaHandle = up.handle;
|
|
867
|
+
return up;
|
|
868
|
+
},
|
|
869
|
+
mediaCache: config.mediaCache,
|
|
870
|
+
options: config.options,
|
|
871
|
+
backgroundColor: getRandomHexColor(),
|
|
872
|
+
font: Math.floor(Math.random() * 9),
|
|
873
|
+
});
|
|
874
|
+
await relayMessage(WABinary_1.STORIES_JID, msg.message, {
|
|
875
|
+
messageId: msg.key.id,
|
|
876
|
+
statusJidList: allUsers,
|
|
877
|
+
additionalNodes: [
|
|
878
|
+
{
|
|
879
|
+
tag: 'meta',
|
|
880
|
+
attrs: {},
|
|
881
|
+
content: [
|
|
882
|
+
{
|
|
883
|
+
tag: 'mentioned_users',
|
|
884
|
+
attrs: {},
|
|
885
|
+
content: jids.map(jid => ({
|
|
886
|
+
tag: 'to',
|
|
887
|
+
attrs: { jid },
|
|
888
|
+
content: undefined,
|
|
889
|
+
})),
|
|
890
|
+
},
|
|
891
|
+
],
|
|
892
|
+
},
|
|
893
|
+
],
|
|
894
|
+
});
|
|
895
|
+
jids.forEach(async (id) => {
|
|
896
|
+
id = (0, WABinary_1.jidNormalizedUser)(id);
|
|
897
|
+
const { user, server } = (0, WABinary_1.jidDecode)(id);
|
|
898
|
+
const isPrivate = server === 's.whatsapp.net';
|
|
899
|
+
let type = isPrivate
|
|
900
|
+
? 'statusMentionMessage'
|
|
901
|
+
: 'groupStatusMentionMessage';
|
|
902
|
+
await relayMessage(id, {
|
|
903
|
+
[type]: {
|
|
904
|
+
message: {
|
|
905
|
+
protocolMessage: {
|
|
906
|
+
key: msg.key,
|
|
907
|
+
type: 25,
|
|
908
|
+
},
|
|
909
|
+
},
|
|
910
|
+
},
|
|
911
|
+
}, {});
|
|
912
|
+
await (0, Utils_1.delay)(2500);
|
|
913
|
+
});
|
|
914
|
+
return msg;
|
|
915
|
+
},
|
|
916
|
+
sendAlbumMessage: async (jid, medias, options = {}) => {
|
|
917
|
+
const userJid = authState.creds.me.id;
|
|
918
|
+
for (const media of medias) {
|
|
919
|
+
if (!media.image && !media.video)
|
|
920
|
+
throw new TypeError(`medias[i] must have image or video property`);
|
|
921
|
+
}
|
|
922
|
+
if (medias.length < 2)
|
|
923
|
+
throw new RangeError("Minimum 2 media");
|
|
924
|
+
const time = options.delay || 500;
|
|
925
|
+
delete options.delay;
|
|
926
|
+
const album = await (0, Utils_1.generateWAMessageFromContent)(jid, {
|
|
927
|
+
albumMessage: {
|
|
928
|
+
expectedImageCount: medias.filter(media => media.image).length,
|
|
929
|
+
expectedVideoCount: medias.filter(media => media.video).length,
|
|
930
|
+
...options
|
|
931
|
+
}
|
|
932
|
+
}, { userJid, ...options });
|
|
933
|
+
await relayMessage(jid, album.message, { messageId: album.key.id });
|
|
934
|
+
let mediaHandle;
|
|
935
|
+
let msg;
|
|
936
|
+
for (const i in medias) {
|
|
937
|
+
const media = medias[i];
|
|
938
|
+
if (media.image) {
|
|
939
|
+
msg = await (0, Utils_1.generateWAMessage)(jid, {
|
|
940
|
+
image: media.image,
|
|
941
|
+
...media,
|
|
942
|
+
...options
|
|
943
|
+
}, {
|
|
944
|
+
userJid,
|
|
945
|
+
upload: async (readStream, opts) => {
|
|
946
|
+
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsLetter)(jid) });
|
|
947
|
+
mediaHandle = up.handle;
|
|
948
|
+
return up;
|
|
949
|
+
},
|
|
950
|
+
...options,
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
else if (media.video) {
|
|
954
|
+
msg = await (0, Utils_1.generateWAMessage)(jid, {
|
|
955
|
+
video: media.video,
|
|
956
|
+
...media,
|
|
957
|
+
...options
|
|
958
|
+
}, {
|
|
959
|
+
userJid,
|
|
960
|
+
upload: async (readStream, opts) => {
|
|
961
|
+
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsLetter)(jid) });
|
|
962
|
+
mediaHandle = up.handle;
|
|
963
|
+
return up;
|
|
964
|
+
},
|
|
965
|
+
...options,
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
if (msg) {
|
|
969
|
+
msg.message.messageContextInfo = {
|
|
970
|
+
messageAssociation: {
|
|
971
|
+
associationType: 1,
|
|
972
|
+
parentMessageKey: album.key
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
}
|
|
976
|
+
await relayMessage(jid, msg.message, { messageId: msg.key.id });
|
|
977
|
+
await (0, Utils_1.delay)(time);
|
|
978
|
+
}
|
|
979
|
+
return album;
|
|
980
|
+
},
|
|
1053
981
|
sendMessage: async (jid, content, options = {}) => {
|
|
982
|
+
var _a, _b, _c;
|
|
1054
983
|
const userJid = authState.creds.me.id;
|
|
1055
984
|
if (typeof content === 'object' &&
|
|
1056
985
|
'disappearingMessagesInChat' in content &&
|
|
1057
986
|
typeof content['disappearingMessagesInChat'] !== 'undefined' &&
|
|
1058
|
-
isJidGroup(jid)) {
|
|
987
|
+
(0, WABinary_1.isJidGroup)(jid)) {
|
|
1059
988
|
const { disappearingMessagesInChat } = content;
|
|
1060
|
-
const value = typeof disappearingMessagesInChat === 'boolean'
|
|
1061
|
-
?
|
|
1062
|
-
|
|
1063
|
-
: 0
|
|
1064
|
-
: disappearingMessagesInChat;
|
|
989
|
+
const value = typeof disappearingMessagesInChat === 'boolean' ?
|
|
990
|
+
(disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
|
|
991
|
+
disappearingMessagesInChat;
|
|
1065
992
|
await groupToggleEphemeral(jid, value);
|
|
1066
993
|
}
|
|
1067
994
|
else {
|
|
1068
|
-
|
|
995
|
+
let mediaHandle;
|
|
996
|
+
const { server } = (0, WABinary_1.jidDecode)(jid);
|
|
997
|
+
const isGroup = server === 'g.us';
|
|
998
|
+
let eph;
|
|
999
|
+
if (isGroup) {
|
|
1000
|
+
const disappearingNode = await groupQuery(jid, 'get', [
|
|
1001
|
+
{
|
|
1002
|
+
tag: 'query',
|
|
1003
|
+
attrs: { request: 'interactive' }
|
|
1004
|
+
}
|
|
1005
|
+
]);
|
|
1006
|
+
const group = (0, WABinary_1.getBinaryNodeChild)(disappearingNode, 'group');
|
|
1007
|
+
const expiration = (0, WABinary_1.getBinaryNodeChild)(group, 'ephemeral');
|
|
1008
|
+
eph = (_a = expiration === null || expiration === void 0 ? void 0 : expiration.attrs) === null || _a === void 0 ? void 0 : _a.expiration;
|
|
1009
|
+
}
|
|
1010
|
+
const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
|
|
1069
1011
|
logger,
|
|
1070
1012
|
userJid,
|
|
1071
|
-
|
|
1013
|
+
ephemeralExpiration: (options.ephemeralExpiration && options.ephemeralExpiration > 0) ? options.ephemeralExpiration : eph,
|
|
1014
|
+
getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
|
|
1072
1015
|
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
1073
1016
|
fetchOpts: {
|
|
1074
1017
|
timeout: 3000,
|
|
1075
|
-
...
|
|
1018
|
+
...axiosOptions || {}
|
|
1076
1019
|
},
|
|
1077
1020
|
logger,
|
|
1078
|
-
uploadImage: generateHighQualityLinkPreview
|
|
1021
|
+
uploadImage: generateHighQualityLinkPreview
|
|
1022
|
+
? waUploadToServer
|
|
1023
|
+
: undefined
|
|
1079
1024
|
}),
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1025
|
+
upload: async (readStream, opts) => {
|
|
1026
|
+
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsLetter)(jid) });
|
|
1027
|
+
mediaHandle = up.handle;
|
|
1028
|
+
return up;
|
|
1029
|
+
},
|
|
1084
1030
|
mediaCache: config.mediaCache,
|
|
1085
1031
|
options: config.options,
|
|
1086
|
-
messageId: generateMessageIDV2(sock.user
|
|
1087
|
-
...options
|
|
1032
|
+
messageId: await config.generateMessageIDV2((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id) ?? (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id),
|
|
1033
|
+
...options,
|
|
1088
1034
|
});
|
|
1089
|
-
const
|
|
1090
|
-
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
1091
|
-
const isEditMsg = 'edit' in content && !!content.edit;
|
|
1035
|
+
const isAiMsg = 'ai' in content && !!content.ai;
|
|
1092
1036
|
const isPinMsg = 'pin' in content && !!content.pin;
|
|
1093
|
-
const
|
|
1037
|
+
const isKeepMsg = 'keep' in content && content.keep;
|
|
1038
|
+
const isPollMsg = 'poll' in content && !!content.poll;
|
|
1039
|
+
const isEditMsg = 'edit' in content && !!content.edit;
|
|
1040
|
+
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
1094
1041
|
const additionalAttributes = {};
|
|
1095
1042
|
const additionalNodes = [];
|
|
1096
1043
|
// required for delete
|
|
1097
1044
|
if (isDeleteMsg) {
|
|
1098
1045
|
// if the chat is a group, and I am not the author, then delete the message as an admin
|
|
1099
|
-
if (isJidGroup(content.delete
|
|
1046
|
+
if (((0, WABinary_1.isJidGroup)((_b = content.delete) === null || _b === void 0 ? void 0 : _b.remoteJid) && !((_c = content.delete) === null || _c === void 0 ? void 0 : _c.fromMe)) || (0, WABinary_1.isJidNewsLetter)(jid)) {
|
|
1100
1047
|
additionalAttributes.edit = '8';
|
|
1101
1048
|
}
|
|
1102
1049
|
else {
|
|
@@ -1104,37 +1051,32 @@ export const makeMessagesSocket = (config) => {
|
|
|
1104
1051
|
}
|
|
1105
1052
|
}
|
|
1106
1053
|
else if (isEditMsg) {
|
|
1107
|
-
additionalAttributes.edit = '1';
|
|
1054
|
+
additionalAttributes.edit = (0, WABinary_1.isJidNewsLetter)(jid) ? '3' : '1';
|
|
1108
1055
|
}
|
|
1109
1056
|
else if (isPinMsg) {
|
|
1110
1057
|
additionalAttributes.edit = '2';
|
|
1111
1058
|
}
|
|
1112
|
-
else if (
|
|
1059
|
+
else if (isAiMsg) {
|
|
1113
1060
|
additionalNodes.push({
|
|
1114
|
-
tag: 'meta',
|
|
1115
1061
|
attrs: {
|
|
1116
|
-
|
|
1117
|
-
}
|
|
1062
|
+
biz_bot: '1'
|
|
1063
|
+
},
|
|
1064
|
+
tag: 'bot'
|
|
1118
1065
|
});
|
|
1066
|
+
if (options.additionalNodes) {
|
|
1067
|
+
additionalNodes.push(...options.additionalNodes);
|
|
1068
|
+
}
|
|
1119
1069
|
}
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
tag: 'meta',
|
|
1123
|
-
attrs: {
|
|
1124
|
-
event_type: 'creation'
|
|
1125
|
-
}
|
|
1126
|
-
});
|
|
1070
|
+
if (mediaHandle) {
|
|
1071
|
+
additionalAttributes['media_id'] = mediaHandle;
|
|
1127
1072
|
}
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
statusJidList: options.statusJidList,
|
|
1133
|
-
additionalNodes
|
|
1134
|
-
});
|
|
1073
|
+
if ('cachedGroupMetadata' in options) {
|
|
1074
|
+
console.warn('cachedGroupMetadata in sendMessage are deprecated, now cachedGroupMetadata is part of the socket config.');
|
|
1075
|
+
}
|
|
1076
|
+
await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, cachedGroupMetadata: options.cachedGroupMetadata, additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes, additionalAttributes, statusJidList: options.statusJidList });
|
|
1135
1077
|
if (config.emitOwnEvents) {
|
|
1136
|
-
process.nextTick(
|
|
1137
|
-
|
|
1078
|
+
process.nextTick(() => {
|
|
1079
|
+
processingMutex.mutex(() => (upsertMessage(fullMsg, 'append')));
|
|
1138
1080
|
});
|
|
1139
1081
|
}
|
|
1140
1082
|
return fullMsg;
|
|
@@ -1142,4 +1084,4 @@ export const makeMessagesSocket = (config) => {
|
|
|
1142
1084
|
}
|
|
1143
1085
|
};
|
|
1144
1086
|
};
|
|
1145
|
-
|
|
1087
|
+
exports.makeMessagesSocket = makeMessagesSocket;
|