@vinzsocket/baileys 2.8.35 → 3.0.10
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 +2 -2
- package/WAProto/WAProto.proto +1339 -493
- package/WAProto/fix-imports.js +75 -19
- package/WAProto/index.d.ts +5274 -1945
- package/WAProto/index.js +81079 -20694
- package/lib/Defaults/index.d.ts +75 -0
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +122 -110
- package/lib/Defaults/index.js.map +1 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
- package/lib/Signal/Group/ciphertext-message.js +11 -18
- package/lib/Signal/Group/ciphertext-message.js.map +1 -0
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
- package/lib/Signal/Group/group-session-builder.js +27 -35
- package/lib/Signal/Group/group-session-builder.js.map +1 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
- package/lib/Signal/Group/group_cipher.js +75 -95
- package/lib/Signal/Group/group_cipher.js.map +1 -0
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.d.ts.map +1 -0
- package/lib/Signal/Group/index.js +12 -79
- package/lib/Signal/Group/index.js.map +1 -0
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
- package/lib/Signal/Group/keyhelper.js +14 -25
- package/lib/Signal/Group/keyhelper.js.map +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-chain-key.js +24 -37
- package/lib/Signal/Group/sender-chain-key.js.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -61
- package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-message.js +64 -68
- package/lib/Signal/Group/sender-key-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-name.js +41 -47
- package/lib/Signal/Group/sender-key-name.js.map +1 -0
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-record.js +36 -50
- package/lib/Signal/Group/sender-key-record.js.map +1 -0
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-state.js +76 -96
- package/lib/Signal/Group/sender-key-state.js.map +1 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-message-key.js +25 -34
- package/lib/Signal/Group/sender-message-key.js.map +1 -0
- package/lib/Signal/libsignal.d.ts +5 -0
- package/lib/Signal/libsignal.d.ts.map +1 -0
- package/lib/Signal/libsignal.js +415 -402
- 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 +273 -111
- package/lib/Signal/lid-mapping.js.map +1 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.d.ts.map +1 -0
- package/lib/Socket/Client/index.js +3 -27
- package/lib/Socket/Client/index.js.map +1 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.d.ts.map +1 -0
- package/lib/Socket/Client/types.js +10 -17
- package/lib/Socket/Client/types.js.map +1 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +53 -57
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +217 -0
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +374 -363
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +124 -0
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +1162 -1041
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +273 -0
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +418 -469
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/groups.d.ts +161 -0
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +337 -393
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +260 -0
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +10 -20
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +203 -0
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +1738 -1394
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +199 -0
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +1101 -1245
- 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 +38 -51
- package/lib/Socket/mex.js.map +1 -0
- package/lib/Socket/newsletter.d.ts +170 -0
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +175 -225
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +59 -0
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +930 -914
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Types/Auth.d.ts +117 -0
- package/lib/Types/Auth.d.ts.map +1 -0
- package/lib/Types/Auth.js +2 -5
- 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 -5
- package/lib/Types/Bussines.js.map +1 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Call.d.ts.map +1 -0
- package/lib/Types/Call.js +2 -5
- package/lib/Types/Call.js.map +1 -0
- package/lib/Types/Chat.d.ts +124 -0
- package/lib/Types/Chat.d.ts.map +1 -0
- package/lib/Types/Chat.js +7 -7
- package/lib/Types/Chat.js.map +1 -0
- package/lib/Types/Contact.d.ts +26 -0
- package/lib/Types/Contact.d.ts.map +1 -0
- package/lib/Types/Contact.js +2 -5
- package/lib/Types/Contact.js.map +1 -0
- package/lib/Types/Events.d.ts +256 -0
- package/lib/Types/Events.d.ts.map +1 -0
- package/lib/Types/Events.js +2 -3
- package/lib/Types/Events.js.map +1 -0
- package/lib/Types/GroupMetadata.d.ts +71 -0
- package/lib/Types/GroupMetadata.d.ts.map +1 -0
- package/lib/Types/GroupMetadata.js +2 -5
- package/lib/Types/GroupMetadata.js.map +1 -0
- package/lib/Types/Label.d.ts +47 -0
- package/lib/Types/Label.d.ts.map +1 -0
- package/lib/Types/Label.js +22 -28
- package/lib/Types/Label.js.map +1 -0
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/LabelAssociation.d.ts.map +1 -0
- package/lib/Types/LabelAssociation.js +4 -10
- package/lib/Types/LabelAssociation.js.map +1 -0
- package/lib/Types/Message.d.ts +320 -0
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +8 -20
- package/lib/Types/Message.js.map +1 -0
- package/lib/Types/Mex.d.ts +141 -0
- package/lib/Types/Mex.d.ts.map +1 -0
- package/lib/Types/Mex.js +37 -0
- package/lib/Types/Mex.js.map +1 -0
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Product.d.ts.map +1 -0
- package/lib/Types/Product.js +2 -5
- package/lib/Types/Product.js.map +1 -0
- package/lib/Types/Signal.d.ts +87 -0
- package/lib/Types/Signal.d.ts.map +1 -0
- package/lib/Types/Signal.js +2 -3
- package/lib/Types/Signal.js.map +1 -0
- package/lib/Types/Socket.d.ts +136 -0
- package/lib/Types/Socket.d.ts.map +1 -0
- package/lib/Types/Socket.js +3 -4
- package/lib/Types/Socket.js.map +1 -0
- package/lib/Types/State.d.ts +97 -0
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +54 -17
- package/lib/Types/State.js.map +1 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.d.ts.map +1 -0
- package/lib/Types/USync.js +2 -3
- package/lib/Types/USync.js.map +1 -0
- package/lib/Types/index.d.ts +65 -0
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +24 -165
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/auth-utils.d.ts +24 -0
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +272 -461
- package/lib/Utils/auth-utils.js.map +1 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.d.ts.map +1 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/browser-utils.js.map +1 -0
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +207 -223
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +100 -0
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +828 -803
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
- package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/companion-reg-client-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +37 -0
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +87 -144
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +66 -0
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +291 -262
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +36 -0
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +598 -560
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +91 -0
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +329 -363
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts +24 -0
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +129 -96
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/identity-change-handler.d.ts +44 -0
- package/lib/Utils/identity-change-handler.d.ts.map +1 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/identity-change-handler.js.map +1 -0
- package/lib/Utils/index.d.ts +22 -0
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +22 -236
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +69 -86
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +12 -0
- package/lib/Utils/logger.d.ts.map +1 -0
- package/lib/Utils/logger.js +3 -11
- package/lib/Utils/logger.js.map +1 -0
- package/lib/Utils/lt-hash.d.ts +8 -0
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +2 -52
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts +9 -0
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +30 -43
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/message-retry-manager.d.ts +115 -0
- package/lib/Utils/message-retry-manager.d.ts.map +1 -0
- package/lib/Utils/message-retry-manager.js +259 -162
- package/lib/Utils/message-retry-manager.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +133 -0
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +732 -711
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +91 -0
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +817 -803
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +195 -168
- package/lib/Utils/noise-handler.js.map +1 -0
- package/lib/Utils/offline-node-processor.d.ts +17 -0
- package/lib/Utils/offline-node-processor.d.ts.map +1 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/offline-node-processor.js.map +1 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.d.ts.map +1 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/pre-key-manager.js.map +1 -0
- package/lib/Utils/process-message.d.ts +60 -0
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +601 -424
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.d.ts.map +1 -0
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/reporting-utils.js.map +1 -0
- package/lib/Utils/signal.d.ts +47 -0
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +180 -206
- package/lib/Utils/signal.js.map +1 -0
- package/lib/Utils/stanza-ack.d.ts +11 -0
- package/lib/Utils/stanza-ack.d.ts.map +1 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/stanza-ack.js.map +1 -0
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.d.ts.map +1 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/sync-action-utils.js.map +1 -0
- package/lib/Utils/tc-token-utils.d.ts +37 -0
- package/lib/Utils/tc-token-utils.d.ts.map +1 -0
- package/lib/Utils/tc-token-utils.js +163 -0
- package/lib/Utils/tc-token-utils.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +98 -101
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +191 -188
- package/lib/Utils/validate-connection.js.map +1 -0
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/constants.d.ts.map +1 -0
- package/lib/WABinary/constants.js +1295 -36
- package/lib/WABinary/constants.js.map +1 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.d.ts.map +1 -0
- package/lib/WABinary/decode.js +254 -232
- package/lib/WABinary/decode.js.map +1 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.d.ts.map +1 -0
- package/lib/WABinary/encode.js +208 -210
- package/lib/WABinary/encode.js.map +1 -0
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/generic-utils.d.ts.map +1 -0
- package/lib/WABinary/generic-utils.js +97 -106
- package/lib/WABinary/generic-utils.js.map +1 -0
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.d.ts.map +1 -0
- package/lib/WABinary/index.js +6 -60
- package/lib/WABinary/index.js.map +1 -0
- package/lib/WABinary/jid-utils.d.ts +48 -0
- package/lib/WABinary/jid-utils.d.ts.map +1 -0
- package/lib/WABinary/jid-utils.js +83 -70
- package/lib/WABinary/jid-utils.js.map +1 -0
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.d.ts.map +1 -0
- package/lib/WABinary/types.js +2 -4
- package/lib/WABinary/types.js.map +1 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/BinaryInfo.d.ts.map +1 -0
- package/lib/WAM/BinaryInfo.js +9 -16
- package/lib/WAM/BinaryInfo.js.map +1 -0
- package/lib/WAM/constants.d.ts +40 -0
- package/lib/WAM/constants.d.ts.map +1 -0
- package/lib/WAM/constants.js +22853 -13001
- package/lib/WAM/constants.js.map +1 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.d.ts.map +1 -0
- package/lib/WAM/encode.js +133 -133
- package/lib/WAM/encode.js.map +1 -0
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.d.ts.map +1 -0
- package/lib/WAM/index.js +4 -38
- package/lib/WAM/index.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +50 -34
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +50 -61
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +25 -32
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +35 -40
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +23 -29
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +47 -64
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +27 -26
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/index.d.ts +6 -0
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/index.js +6 -60
- package/lib/WAUSync/Protocols/index.js.map +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +30 -0
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
- package/lib/WAUSync/USyncQuery.js +94 -97
- package/lib/WAUSync/USyncQuery.js.map +1 -0
- package/lib/WAUSync/USyncUser.d.ts +17 -0
- package/lib/WAUSync/USyncUser.d.ts.map +1 -0
- package/lib/WAUSync/USyncUser.js +30 -29
- package/lib/WAUSync/USyncUser.js.map +1 -0
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.d.ts.map +1 -0
- package/lib/WAUSync/index.js +4 -38
- package/lib/WAUSync/index.js.map +1 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -114
- package/lib/index.js.map +1 -0
- package/package.json +47 -20
- package/README.md +0 -1315
- package/lib/Signal/Group/queue-job.js +0 -61
- package/lib/Store/index.js +0 -49
- package/lib/Store/make-cache-manager-store.js +0 -106
- package/lib/Store/make-in-memory-store.js +0 -497
- package/lib/Store/make-ordered-dictionary.js +0 -83
- package/lib/Store/object-repository.js +0 -32
- package/lib/Types/Newsletter.js +0 -37
- package/lib/Utils/baileys-event-stream.js +0 -74
- package/lib/Utils/extended-messages.js +0 -285
- package/lib/Utils/lid-resolver.js +0 -81
- package/lib/Utils/mention.js +0 -137
package/lib/Utils/messages.js
CHANGED
|
@@ -1,642 +1,633 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
require("stream");
|
|
14
|
-
var _index = require("../../WAProto/index.js");
|
|
15
|
-
var _index2 = require("../Defaults/index.js");
|
|
16
|
-
var _index3 = require("../Types/index.js");
|
|
17
|
-
var _index4 = require("../WABinary/index.js");
|
|
18
|
-
var _crypto2 = require("./crypto.js");
|
|
19
|
-
var _generics = require("./generics.js");
|
|
20
|
-
var _messagesMedia = require("./messages-media.js");
|
|
21
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { randomBytes } from 'crypto';
|
|
3
|
+
import { promises as fs } from 'fs';
|
|
4
|
+
import {} from 'stream';
|
|
5
|
+
import { proto } from '../../WAProto/index.js';
|
|
6
|
+
import { CALL_AUDIO_PREFIX, CALL_VIDEO_PREFIX, MEDIA_KEYS, URL_REGEX, WA_DEFAULT_EPHEMERAL } from '../Defaults/index.js';
|
|
7
|
+
import { WAMessageStatus, WAProto } from '../Types/index.js';
|
|
8
|
+
import { isJidGroup, isJidNewsletter, isJidStatusBroadcast, jidNormalizedUser } from '../WABinary/index.js';
|
|
9
|
+
import { sha256 } from './crypto.js';
|
|
10
|
+
import { generateMessageIDV2, getKeyAuthor, unixTimestampSeconds } from './generics.js';
|
|
11
|
+
import { downloadContentFromMessage, encryptedStream, generateThumbnail, getAudioDuration, getAudioWaveform, getRawMediaUploadData } from './messages-media.js';
|
|
12
|
+
import { shouldIncludeReportingToken } from './reporting-utils.js';
|
|
22
13
|
const MIMETYPE_MAP = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
14
|
+
image: 'image/jpeg',
|
|
15
|
+
video: 'video/mp4',
|
|
16
|
+
document: 'application/pdf',
|
|
17
|
+
audio: 'audio/ogg; codecs=opus',
|
|
18
|
+
sticker: 'image/webp',
|
|
19
|
+
'product-catalog-image': 'image/jpeg'
|
|
29
20
|
};
|
|
30
21
|
const MessageTypeProto = {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
22
|
+
image: WAProto.Message.ImageMessage,
|
|
23
|
+
video: WAProto.Message.VideoMessage,
|
|
24
|
+
audio: WAProto.Message.AudioMessage,
|
|
25
|
+
sticker: WAProto.Message.StickerMessage,
|
|
26
|
+
document: WAProto.Message.DocumentMessage
|
|
36
27
|
};
|
|
37
28
|
/**
|
|
38
29
|
* Uses a regex to test whether the string contains a URL, and returns the URL if it does.
|
|
39
30
|
* @param text eg. hello https://google.com
|
|
40
31
|
* @returns the URL, eg. https://google.com
|
|
41
32
|
*/
|
|
42
|
-
const extractUrlFromText = text => text.match(
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
}
|
|
33
|
+
export const extractUrlFromText = (text) => text.match(URL_REGEX)?.[0];
|
|
34
|
+
export const generateLinkPreviewIfRequired = async (text, getUrlInfo, logger) => {
|
|
35
|
+
const url = extractUrlFromText(text);
|
|
36
|
+
if (!!getUrlInfo && url) {
|
|
37
|
+
try {
|
|
38
|
+
const urlInfo = await getUrlInfo(url);
|
|
39
|
+
return urlInfo;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
// ignore if fails
|
|
43
|
+
logger?.warn({ trace: error.stack }, 'url generation failed');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
57
46
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
47
|
+
const assertColor = async (color) => {
|
|
48
|
+
let assertedColor;
|
|
49
|
+
if (typeof color === 'number') {
|
|
50
|
+
assertedColor = color > 0 ? color : 0xffffffff + Number(color) + 1;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
let hex = color.trim().replace('#', '');
|
|
54
|
+
if (hex.length <= 6) {
|
|
55
|
+
hex = 'FF' + hex.padStart(6, '0');
|
|
56
|
+
}
|
|
57
|
+
assertedColor = parseInt(hex, 16);
|
|
58
|
+
return assertedColor;
|
|
59
|
+
}
|
|
71
60
|
};
|
|
72
|
-
const prepareWAMessageMedia = async (message, options) => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
61
|
+
export const prepareWAMessageMedia = async (message, options) => {
|
|
62
|
+
const logger = options.logger;
|
|
63
|
+
let mediaType;
|
|
64
|
+
for (const key of MEDIA_KEYS) {
|
|
65
|
+
if (key in message) {
|
|
66
|
+
mediaType = key;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (!mediaType) {
|
|
70
|
+
throw new Boom('Invalid media type', { statusCode: 400 });
|
|
71
|
+
}
|
|
72
|
+
const uploadData = {
|
|
73
|
+
...message,
|
|
74
|
+
media: message[mediaType]
|
|
75
|
+
};
|
|
76
|
+
delete uploadData[mediaType];
|
|
77
|
+
// check if cacheable + generate cache key
|
|
78
|
+
const cacheableKey = typeof uploadData.media === 'object' &&
|
|
79
|
+
'url' in uploadData.media &&
|
|
80
|
+
!!uploadData.media.url &&
|
|
81
|
+
!!options.mediaCache &&
|
|
82
|
+
mediaType + ':' + uploadData.media.url.toString();
|
|
83
|
+
if (mediaType === 'document' && !uploadData.fileName) {
|
|
84
|
+
uploadData.fileName = 'file';
|
|
85
|
+
}
|
|
86
|
+
if (!uploadData.mimetype) {
|
|
87
|
+
uploadData.mimetype = MIMETYPE_MAP[mediaType];
|
|
88
|
+
}
|
|
89
|
+
if (cacheableKey) {
|
|
90
|
+
const mediaBuff = await options.mediaCache.get(cacheableKey);
|
|
91
|
+
if (mediaBuff) {
|
|
92
|
+
logger?.debug({ cacheableKey }, 'got media cache hit');
|
|
93
|
+
const obj = proto.Message.decode(mediaBuff);
|
|
94
|
+
const key = `${mediaType}Message`;
|
|
95
|
+
Object.assign(obj[key], { ...uploadData, media: undefined });
|
|
96
|
+
return obj;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const isNewsletter = !!options.jid && isJidNewsletter(options.jid);
|
|
100
|
+
if (isNewsletter) {
|
|
101
|
+
logger?.info({ key: cacheableKey }, 'Preparing raw media for newsletter');
|
|
102
|
+
const { filePath, fileSha256, fileLength } = await getRawMediaUploadData(uploadData.media, options.mediaTypeOverride || mediaType, logger);
|
|
103
|
+
const fileSha256B64 = fileSha256.toString('base64');
|
|
104
|
+
const { mediaUrl, directPath } = await options.upload(filePath, {
|
|
105
|
+
fileEncSha256B64: fileSha256B64,
|
|
106
|
+
mediaType: mediaType,
|
|
107
|
+
timeoutMs: options.mediaUploadTimeoutMs
|
|
108
|
+
});
|
|
109
|
+
await fs.unlink(filePath);
|
|
110
|
+
const obj = WAProto.Message.fromObject({
|
|
111
|
+
// todo: add more support here
|
|
112
|
+
[`${mediaType}Message`]: MessageTypeProto[mediaType].fromObject({
|
|
113
|
+
url: mediaUrl,
|
|
114
|
+
directPath,
|
|
115
|
+
fileSha256,
|
|
116
|
+
fileLength,
|
|
117
|
+
...uploadData,
|
|
118
|
+
media: undefined
|
|
119
|
+
})
|
|
120
|
+
});
|
|
121
|
+
if (uploadData.ptv) {
|
|
122
|
+
obj.ptvMessage = obj.videoMessage;
|
|
123
|
+
delete obj.videoMessage;
|
|
124
|
+
}
|
|
125
|
+
if (obj.stickerMessage) {
|
|
126
|
+
obj.stickerMessage.stickerSentTs = Date.now();
|
|
127
|
+
}
|
|
128
|
+
if (cacheableKey) {
|
|
129
|
+
logger?.debug({ cacheableKey }, 'set cache');
|
|
130
|
+
await options.mediaCache.set(cacheableKey, WAProto.Message.encode(obj).finish());
|
|
131
|
+
}
|
|
132
|
+
return obj;
|
|
133
|
+
}
|
|
134
|
+
const requiresDurationComputation = mediaType === 'audio' && typeof uploadData.seconds === 'undefined';
|
|
135
|
+
const requiresThumbnailComputation = (mediaType === 'image' || mediaType === 'video') && typeof uploadData['jpegThumbnail'] === 'undefined';
|
|
136
|
+
const requiresWaveformProcessing = mediaType === 'audio' && uploadData.ptt === true && typeof uploadData.waveform === 'undefined';
|
|
137
|
+
const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === true;
|
|
138
|
+
const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation;
|
|
139
|
+
const { mediaKey, encFilePath, originalFilePath, fileEncSha256, fileSha256, fileLength } = await encryptedStream(uploadData.media, options.mediaTypeOverride || mediaType, {
|
|
140
|
+
logger,
|
|
141
|
+
saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
|
|
142
|
+
opts: options.options
|
|
83
143
|
});
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
144
|
+
const fileEncSha256B64 = fileEncSha256.toString('base64');
|
|
145
|
+
const [{ mediaUrl, directPath }] = await Promise.all([
|
|
146
|
+
(async () => {
|
|
147
|
+
const result = await options.upload(encFilePath, {
|
|
148
|
+
fileEncSha256B64,
|
|
149
|
+
mediaType,
|
|
150
|
+
timeoutMs: options.mediaUploadTimeoutMs
|
|
151
|
+
});
|
|
152
|
+
logger?.debug({ mediaType, cacheableKey }, 'uploaded media');
|
|
153
|
+
return result;
|
|
154
|
+
})(),
|
|
155
|
+
(async () => {
|
|
156
|
+
try {
|
|
157
|
+
if (requiresThumbnailComputation) {
|
|
158
|
+
const { thumbnail, originalImageDimensions } = await generateThumbnail(originalFilePath, mediaType, options);
|
|
159
|
+
uploadData.jpegThumbnail = thumbnail;
|
|
160
|
+
if (!uploadData.width && originalImageDimensions) {
|
|
161
|
+
uploadData.width = originalImageDimensions.width;
|
|
162
|
+
uploadData.height = originalImageDimensions.height;
|
|
163
|
+
logger?.debug('set dimensions');
|
|
164
|
+
}
|
|
165
|
+
logger?.debug('generated thumbnail');
|
|
166
|
+
}
|
|
167
|
+
if (requiresDurationComputation) {
|
|
168
|
+
uploadData.seconds = await getAudioDuration(originalFilePath);
|
|
169
|
+
logger?.debug('computed audio duration');
|
|
170
|
+
}
|
|
171
|
+
if (requiresWaveformProcessing) {
|
|
172
|
+
uploadData.waveform = await getAudioWaveform(originalFilePath, logger);
|
|
173
|
+
logger?.debug('processed waveform');
|
|
174
|
+
}
|
|
175
|
+
if (requiresAudioBackground) {
|
|
176
|
+
uploadData.backgroundArgb = await assertColor(options.backgroundColor);
|
|
177
|
+
logger?.debug('computed backgroundColor audio status');
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
logger?.warn({ trace: error.stack }, 'failed to obtain extra info');
|
|
182
|
+
}
|
|
183
|
+
})()
|
|
184
|
+
]).finally(async () => {
|
|
185
|
+
try {
|
|
186
|
+
await fs.unlink(encFilePath);
|
|
187
|
+
if (originalFilePath) {
|
|
188
|
+
await fs.unlink(originalFilePath);
|
|
189
|
+
}
|
|
190
|
+
logger?.debug('removed tmp files');
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
logger?.warn('failed to remove tmp file');
|
|
194
|
+
}
|
|
131
195
|
});
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
196
|
+
const obj = WAProto.Message.fromObject({
|
|
197
|
+
[`${mediaType}Message`]: MessageTypeProto[mediaType].fromObject({
|
|
198
|
+
url: mediaUrl,
|
|
199
|
+
directPath,
|
|
200
|
+
mediaKey,
|
|
201
|
+
fileEncSha256,
|
|
202
|
+
fileSha256,
|
|
203
|
+
fileLength,
|
|
204
|
+
mediaKeyTimestamp: unixTimestampSeconds(),
|
|
205
|
+
...uploadData,
|
|
206
|
+
media: undefined
|
|
207
|
+
})
|
|
143
208
|
});
|
|
144
209
|
if (uploadData.ptv) {
|
|
145
|
-
|
|
146
|
-
|
|
210
|
+
obj.ptvMessage = obj.videoMessage;
|
|
211
|
+
delete obj.videoMessage;
|
|
147
212
|
}
|
|
148
213
|
if (cacheableKey) {
|
|
149
|
-
|
|
150
|
-
cacheableKey
|
|
151
|
-
}, 'set cache');
|
|
152
|
-
options.mediaCache.set(cacheableKey, _index3.WAProto.Message.encode(obj).finish());
|
|
214
|
+
logger?.debug({ cacheableKey }, 'set cache');
|
|
215
|
+
await options.mediaCache.set(cacheableKey, WAProto.Message.encode(obj).finish());
|
|
153
216
|
}
|
|
154
217
|
return obj;
|
|
155
|
-
}
|
|
156
|
-
const requiresDurationComputation = mediaType === 'audio' && typeof uploadData.seconds === 'undefined';
|
|
157
|
-
const requiresThumbnailComputation = (mediaType === 'image' || mediaType === 'video') && typeof uploadData['jpegThumbnail'] === 'undefined';
|
|
158
|
-
const requiresWaveformProcessing = mediaType === 'audio' && uploadData.ptt === true;
|
|
159
|
-
const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === true;
|
|
160
|
-
const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation;
|
|
161
|
-
const {
|
|
162
|
-
mediaKey,
|
|
163
|
-
encFilePath,
|
|
164
|
-
originalFilePath,
|
|
165
|
-
fileEncSha256,
|
|
166
|
-
fileSha256,
|
|
167
|
-
fileLength
|
|
168
|
-
} = await (0, _messagesMedia.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
|
|
169
|
-
logger,
|
|
170
|
-
saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
|
|
171
|
-
opts: options.options
|
|
172
|
-
});
|
|
173
|
-
const fileEncSha256B64 = fileEncSha256.toString('base64');
|
|
174
|
-
const [{
|
|
175
|
-
mediaUrl,
|
|
176
|
-
directPath
|
|
177
|
-
}] = await Promise.all([(async () => {
|
|
178
|
-
const result = await options.upload(encFilePath, {
|
|
179
|
-
fileEncSha256B64,
|
|
180
|
-
mediaType,
|
|
181
|
-
timeoutMs: options.mediaUploadTimeoutMs
|
|
182
|
-
});
|
|
183
|
-
logger?.debug({
|
|
184
|
-
mediaType,
|
|
185
|
-
cacheableKey
|
|
186
|
-
}, 'uploaded media');
|
|
187
|
-
return result;
|
|
188
|
-
})(), (async () => {
|
|
189
|
-
try {
|
|
190
|
-
if (requiresThumbnailComputation) {
|
|
191
|
-
const {
|
|
192
|
-
thumbnail,
|
|
193
|
-
originalImageDimensions
|
|
194
|
-
} = await (0, _messagesMedia.generateThumbnail)(originalFilePath, mediaType, options);
|
|
195
|
-
uploadData.jpegThumbnail = thumbnail;
|
|
196
|
-
if (!uploadData.width && originalImageDimensions) {
|
|
197
|
-
uploadData.width = originalImageDimensions.width;
|
|
198
|
-
uploadData.height = originalImageDimensions.height;
|
|
199
|
-
logger?.debug('set dimensions');
|
|
200
|
-
}
|
|
201
|
-
logger?.debug('generated thumbnail');
|
|
202
|
-
}
|
|
203
|
-
if (requiresDurationComputation) {
|
|
204
|
-
uploadData.seconds = await (0, _messagesMedia.getAudioDuration)(originalFilePath);
|
|
205
|
-
logger?.debug('computed audio duration');
|
|
206
|
-
}
|
|
207
|
-
if (requiresWaveformProcessing) {
|
|
208
|
-
uploadData.waveform = await (0, _messagesMedia.getAudioWaveform)(originalFilePath, logger);
|
|
209
|
-
logger?.debug('processed waveform');
|
|
210
|
-
}
|
|
211
|
-
if (requiresAudioBackground) {
|
|
212
|
-
uploadData.backgroundArgb = await assertColor(options.backgroundColor);
|
|
213
|
-
logger?.debug('computed backgroundColor audio status');
|
|
214
|
-
}
|
|
215
|
-
} catch (error) {
|
|
216
|
-
logger?.warn({
|
|
217
|
-
trace: error.stack
|
|
218
|
-
}, 'failed to obtain extra info');
|
|
219
|
-
}
|
|
220
|
-
})()]).finally(async () => {
|
|
221
|
-
try {
|
|
222
|
-
await _fs.promises.unlink(encFilePath);
|
|
223
|
-
if (originalFilePath) {
|
|
224
|
-
await _fs.promises.unlink(originalFilePath);
|
|
225
|
-
}
|
|
226
|
-
logger?.debug('removed tmp files');
|
|
227
|
-
} catch (error) {
|
|
228
|
-
logger?.warn('failed to remove tmp file');
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
const obj = _index3.WAProto.Message.create({
|
|
232
|
-
[`${mediaType}Message`]: MessageTypeProto[mediaType].create({
|
|
233
|
-
url: mediaUrl,
|
|
234
|
-
directPath,
|
|
235
|
-
mediaKey,
|
|
236
|
-
fileEncSha256,
|
|
237
|
-
fileSha256,
|
|
238
|
-
fileLength,
|
|
239
|
-
mediaKeyTimestamp: (0, _generics.unixTimestampSeconds)(),
|
|
240
|
-
...uploadData,
|
|
241
|
-
media: undefined
|
|
242
|
-
})
|
|
243
|
-
});
|
|
244
|
-
if (uploadData.ptv) {
|
|
245
|
-
obj.ptvMessage = obj.videoMessage;
|
|
246
|
-
delete obj.videoMessage;
|
|
247
|
-
}
|
|
248
|
-
if (cacheableKey) {
|
|
249
|
-
logger?.debug({
|
|
250
|
-
cacheableKey
|
|
251
|
-
}, 'set cache');
|
|
252
|
-
options.mediaCache.set(cacheableKey, _index3.WAProto.Message.encode(obj).finish());
|
|
253
|
-
}
|
|
254
|
-
return obj;
|
|
255
218
|
};
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
return _index3.WAProto.Message.create(content);
|
|
219
|
+
export const prepareDisappearingMessageSettingContent = (ephemeralExpiration) => {
|
|
220
|
+
ephemeralExpiration = ephemeralExpiration || 0;
|
|
221
|
+
const content = {
|
|
222
|
+
ephemeralMessage: {
|
|
223
|
+
message: {
|
|
224
|
+
protocolMessage: {
|
|
225
|
+
type: WAProto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING,
|
|
226
|
+
ephemeralExpiration
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
return WAProto.Message.fromObject(content);
|
|
270
232
|
};
|
|
271
233
|
/**
|
|
272
234
|
* Generate forwarded message content like WA does
|
|
273
235
|
* @param message the message to forward
|
|
274
236
|
* @param options.forceForward will show the message as forwarded even if it is from you
|
|
275
237
|
*/
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
forwardingScore: score,
|
|
301
|
-
isForwarded: true
|
|
302
|
-
};
|
|
303
|
-
} else {
|
|
304
|
-
key_.contextInfo = {};
|
|
305
|
-
}
|
|
306
|
-
return content;
|
|
238
|
+
export const generateForwardMessageContent = (message, forceForward) => {
|
|
239
|
+
let content = message.message;
|
|
240
|
+
if (!content) {
|
|
241
|
+
throw new Boom('no content in message', { statusCode: 400 });
|
|
242
|
+
}
|
|
243
|
+
// hacky copy
|
|
244
|
+
content = normalizeMessageContent(content);
|
|
245
|
+
content = proto.Message.decode(proto.Message.encode(content).finish());
|
|
246
|
+
let key = Object.keys(content)[0];
|
|
247
|
+
let score = content?.[key]?.contextInfo?.forwardingScore || 0;
|
|
248
|
+
score += message.key.fromMe && !forceForward ? 0 : 1;
|
|
249
|
+
if (key === 'conversation') {
|
|
250
|
+
content.extendedTextMessage = { text: content[key] };
|
|
251
|
+
delete content.conversation;
|
|
252
|
+
key = 'extendedTextMessage';
|
|
253
|
+
}
|
|
254
|
+
const key_ = content?.[key];
|
|
255
|
+
if (score > 0) {
|
|
256
|
+
key_.contextInfo = { forwardingScore: score, isForwarded: true };
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
key_.contextInfo = {};
|
|
260
|
+
}
|
|
261
|
+
return content;
|
|
307
262
|
};
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
if (
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
263
|
+
export const hasNonNullishProperty = (message, key) => {
|
|
264
|
+
return (typeof message === 'object' &&
|
|
265
|
+
message !== null &&
|
|
266
|
+
key in message &&
|
|
267
|
+
message[key] !== null &&
|
|
268
|
+
message[key] !== undefined);
|
|
269
|
+
};
|
|
270
|
+
function hasOptionalProperty(obj, key) {
|
|
271
|
+
return typeof obj === 'object' && obj !== null && key in obj && obj[key] !== null;
|
|
272
|
+
}
|
|
273
|
+
export const generateWAMessageContent = async (message, options) => {
|
|
274
|
+
var _a, _b;
|
|
275
|
+
let m = {};
|
|
276
|
+
if (hasNonNullishProperty(message, 'text')) {
|
|
277
|
+
const extContent = { text: message.text };
|
|
278
|
+
let urlInfo = message.linkPreview;
|
|
279
|
+
if (typeof urlInfo === 'undefined') {
|
|
280
|
+
urlInfo = await generateLinkPreviewIfRequired(message.text, options.getUrlInfo, options.logger);
|
|
281
|
+
}
|
|
282
|
+
if (urlInfo) {
|
|
283
|
+
extContent.matchedText = urlInfo['matched-text'];
|
|
284
|
+
extContent.jpegThumbnail = urlInfo.jpegThumbnail;
|
|
285
|
+
extContent.description = urlInfo.description;
|
|
286
|
+
extContent.title = urlInfo.title;
|
|
287
|
+
extContent.previewType = 0;
|
|
288
|
+
const img = urlInfo.highQualityThumbnail;
|
|
289
|
+
if (img) {
|
|
290
|
+
extContent.thumbnailDirectPath = img.directPath;
|
|
291
|
+
extContent.mediaKey = img.mediaKey;
|
|
292
|
+
extContent.mediaKeyTimestamp = img.mediaKeyTimestamp;
|
|
293
|
+
extContent.thumbnailWidth = img.width;
|
|
294
|
+
extContent.thumbnailHeight = img.height;
|
|
295
|
+
extContent.thumbnailSha256 = img.fileSha256;
|
|
296
|
+
extContent.thumbnailEncSha256 = img.fileEncSha256;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
if (options.backgroundColor) {
|
|
300
|
+
extContent.backgroundArgb = await assertColor(options.backgroundColor);
|
|
301
|
+
}
|
|
302
|
+
if (options.font) {
|
|
303
|
+
extContent.font = options.font;
|
|
304
|
+
}
|
|
305
|
+
m.extendedTextMessage = extContent;
|
|
306
|
+
}
|
|
307
|
+
else if (hasNonNullishProperty(message, 'contacts')) {
|
|
308
|
+
const contactLen = message.contacts.contacts.length;
|
|
309
|
+
if (!contactLen) {
|
|
310
|
+
throw new Boom('require atleast 1 contact', { statusCode: 400 });
|
|
311
|
+
}
|
|
312
|
+
if (contactLen === 1) {
|
|
313
|
+
m.contactMessage = WAProto.Message.ContactMessage.create(message.contacts.contacts[0]);
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
m.contactsArrayMessage = WAProto.Message.ContactsArrayMessage.create(message.contacts);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
else if (hasNonNullishProperty(message, 'location')) {
|
|
320
|
+
m.locationMessage = WAProto.Message.LocationMessage.create(message.location);
|
|
321
|
+
}
|
|
322
|
+
else if (hasNonNullishProperty(message, 'react')) {
|
|
323
|
+
if (!message.react.senderTimestampMs) {
|
|
324
|
+
message.react.senderTimestampMs = Date.now();
|
|
325
|
+
}
|
|
326
|
+
m.reactionMessage = WAProto.Message.ReactionMessage.create(message.react);
|
|
327
|
+
}
|
|
328
|
+
else if (hasNonNullishProperty(message, 'delete')) {
|
|
329
|
+
m.protocolMessage = {
|
|
330
|
+
key: message.delete,
|
|
331
|
+
type: WAProto.Message.ProtocolMessage.Type.REVOKE
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
else if (hasNonNullishProperty(message, 'forward')) {
|
|
335
|
+
m = generateForwardMessageContent(message.forward, message.force);
|
|
336
|
+
}
|
|
337
|
+
else if (hasNonNullishProperty(message, 'disappearingMessagesInChat')) {
|
|
338
|
+
const exp = typeof message.disappearingMessagesInChat === 'boolean'
|
|
339
|
+
? message.disappearingMessagesInChat
|
|
340
|
+
? WA_DEFAULT_EPHEMERAL
|
|
341
|
+
: 0
|
|
342
|
+
: message.disappearingMessagesInChat;
|
|
343
|
+
m = prepareDisappearingMessageSettingContent(exp);
|
|
344
|
+
}
|
|
345
|
+
else if (hasNonNullishProperty(message, 'groupInvite')) {
|
|
346
|
+
m.groupInviteMessage = {};
|
|
347
|
+
m.groupInviteMessage.inviteCode = message.groupInvite.inviteCode;
|
|
348
|
+
m.groupInviteMessage.inviteExpiration = message.groupInvite.inviteExpiration;
|
|
349
|
+
m.groupInviteMessage.caption = message.groupInvite.text;
|
|
350
|
+
m.groupInviteMessage.groupJid = message.groupInvite.jid;
|
|
351
|
+
m.groupInviteMessage.groupName = message.groupInvite.subject;
|
|
352
|
+
//TODO: use built-in interface and get disappearing mode info etc.
|
|
353
|
+
//TODO: cache / use store!?
|
|
354
|
+
if (options.getProfilePicUrl) {
|
|
355
|
+
const pfpUrl = await options.getProfilePicUrl(message.groupInvite.jid, 'preview');
|
|
356
|
+
if (pfpUrl) {
|
|
357
|
+
const resp = await fetch(pfpUrl, { method: 'GET', dispatcher: options?.options?.dispatcher });
|
|
358
|
+
if (resp.ok) {
|
|
359
|
+
const buf = Buffer.from(await resp.arrayBuffer());
|
|
360
|
+
m.groupInviteMessage.jpegThumbnail = buf;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
else if (hasNonNullishProperty(message, 'pin')) {
|
|
366
|
+
m.pinInChatMessage = {};
|
|
367
|
+
m.messageContextInfo = {};
|
|
368
|
+
m.pinInChatMessage.key = message.pin;
|
|
369
|
+
m.pinInChatMessage.type = message.type;
|
|
370
|
+
m.pinInChatMessage.senderTimestampMs = Date.now();
|
|
371
|
+
m.messageContextInfo.messageAddOnDurationInSecs = message.type === 1 ? message.time || 86400 : 0;
|
|
372
|
+
}
|
|
373
|
+
else if (hasNonNullishProperty(message, 'buttonReply')) {
|
|
374
|
+
switch (message.type) {
|
|
375
|
+
case 'template':
|
|
376
|
+
m.templateButtonReplyMessage = {
|
|
377
|
+
selectedDisplayText: message.buttonReply.displayText,
|
|
378
|
+
selectedId: message.buttonReply.id,
|
|
379
|
+
selectedIndex: message.buttonReply.index
|
|
380
|
+
};
|
|
381
|
+
break;
|
|
382
|
+
case 'plain':
|
|
383
|
+
m.buttonsResponseMessage = {
|
|
384
|
+
selectedButtonId: message.buttonReply.id,
|
|
385
|
+
selectedDisplayText: message.buttonReply.displayText,
|
|
386
|
+
type: proto.Message.ButtonsResponseMessage.Type.DISPLAY_TEXT
|
|
387
|
+
};
|
|
388
|
+
break;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
else if (hasOptionalProperty(message, 'ptv') && message.ptv) {
|
|
392
|
+
const { videoMessage } = await prepareWAMessageMedia({ video: message.video }, options);
|
|
393
|
+
m.ptvMessage = videoMessage;
|
|
394
|
+
}
|
|
395
|
+
else if (hasNonNullishProperty(message, 'product')) {
|
|
396
|
+
const { imageMessage } = await prepareWAMessageMedia({ image: message.product.productImage }, options);
|
|
397
|
+
m.productMessage = WAProto.Message.ProductMessage.create({
|
|
398
|
+
...message,
|
|
399
|
+
product: {
|
|
400
|
+
...message.product,
|
|
401
|
+
productImage: imageMessage
|
|
402
|
+
}
|
|
387
403
|
});
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
case 'template':
|
|
403
|
-
m.templateButtonReplyMessage = {
|
|
404
|
-
selectedDisplayText: message.buttonReply.displayText,
|
|
405
|
-
selectedId: message.buttonReply.id,
|
|
406
|
-
selectedIndex: message.buttonReply.index
|
|
404
|
+
}
|
|
405
|
+
else if (hasNonNullishProperty(message, 'listReply')) {
|
|
406
|
+
m.listResponseMessage = { ...message.listReply };
|
|
407
|
+
}
|
|
408
|
+
else if (hasNonNullishProperty(message, 'event')) {
|
|
409
|
+
m.eventMessage = {};
|
|
410
|
+
const startTime = Math.floor(message.event.startDate.getTime() / 1000);
|
|
411
|
+
if (message.event.call && options.getCallLink) {
|
|
412
|
+
const token = await options.getCallLink(message.event.call, { startTime });
|
|
413
|
+
m.eventMessage.joinLink = (message.event.call === 'audio' ? CALL_AUDIO_PREFIX : CALL_VIDEO_PREFIX) + token;
|
|
414
|
+
}
|
|
415
|
+
m.messageContextInfo = {
|
|
416
|
+
// encKey
|
|
417
|
+
messageSecret: message.event.messageSecret || randomBytes(32)
|
|
407
418
|
};
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
m.
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
419
|
+
m.eventMessage.name = message.event.name;
|
|
420
|
+
m.eventMessage.description = message.event.description;
|
|
421
|
+
m.eventMessage.startTime = startTime;
|
|
422
|
+
m.eventMessage.endTime = message.event.endDate ? message.event.endDate.getTime() / 1000 : undefined;
|
|
423
|
+
m.eventMessage.isCanceled = message.event.isCancelled ?? false;
|
|
424
|
+
m.eventMessage.extraGuestsAllowed = message.event.extraGuestsAllowed;
|
|
425
|
+
m.eventMessage.isScheduleCall = message.event.isScheduleCall ?? false;
|
|
426
|
+
m.eventMessage.location = message.event.location;
|
|
427
|
+
}
|
|
428
|
+
else if (hasNonNullishProperty(message, 'poll')) {
|
|
429
|
+
(_a = message.poll).selectableCount || (_a.selectableCount = 0);
|
|
430
|
+
(_b = message.poll).toAnnouncementGroup || (_b.toAnnouncementGroup = false);
|
|
431
|
+
if (!Array.isArray(message.poll.values)) {
|
|
432
|
+
throw new Boom('Invalid poll values', { statusCode: 400 });
|
|
433
|
+
}
|
|
434
|
+
if (message.poll.selectableCount < 0 || message.poll.selectableCount > message.poll.values.length) {
|
|
435
|
+
throw new Boom(`poll.selectableCount in poll should be >= 0 and <= ${message.poll.values.length}`, {
|
|
436
|
+
statusCode: 400
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
m.messageContextInfo = {
|
|
440
|
+
// encKey
|
|
441
|
+
messageSecret: message.poll.messageSecret || randomBytes(32)
|
|
414
442
|
};
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
(
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
}
|
|
486
|
-
if (message
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
};
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
if ('edit' in message) {
|
|
526
|
-
m = {
|
|
527
|
-
protocolMessage: {
|
|
528
|
-
key: message.edit,
|
|
529
|
-
editedMessage: m,
|
|
530
|
-
timestampMs: Date.now(),
|
|
531
|
-
type: _index3.WAProto.Message.ProtocolMessage.Type.MESSAGE_EDIT
|
|
532
|
-
}
|
|
533
|
-
};
|
|
534
|
-
}
|
|
535
|
-
if ('contextInfo' in message && !!message.contextInfo) {
|
|
536
|
-
const messageType = Object.keys(m)[0];
|
|
537
|
-
const key = m[messageType];
|
|
538
|
-
if ('contextInfo' in key && !!key.contextInfo) {
|
|
539
|
-
key.contextInfo = {
|
|
540
|
-
...key.contextInfo,
|
|
541
|
-
...message.contextInfo
|
|
542
|
-
};
|
|
543
|
-
} else if (key) {
|
|
544
|
-
key.contextInfo = message.contextInfo;
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
return _index3.WAProto.Message.create(m);
|
|
443
|
+
const pollCreationMessage = {
|
|
444
|
+
name: message.poll.name,
|
|
445
|
+
selectableOptionsCount: message.poll.selectableCount,
|
|
446
|
+
options: message.poll.values.map(optionName => ({ optionName }))
|
|
447
|
+
};
|
|
448
|
+
if (message.poll.toAnnouncementGroup) {
|
|
449
|
+
// poll v2 is for community announcement groups (single select and multiple)
|
|
450
|
+
m.pollCreationMessageV2 = pollCreationMessage;
|
|
451
|
+
}
|
|
452
|
+
else {
|
|
453
|
+
if (message.poll.selectableCount === 1) {
|
|
454
|
+
//poll v3 is for single select polls
|
|
455
|
+
m.pollCreationMessageV3 = pollCreationMessage;
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
// poll for multiple choice polls
|
|
459
|
+
m.pollCreationMessage = pollCreationMessage;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
else if (hasNonNullishProperty(message, 'album')) {
|
|
464
|
+
m.albumMessage = {
|
|
465
|
+
expectedImageCount: message.album.expectedImageCount,
|
|
466
|
+
expectedVideoCount: message.album.expectedVideoCount
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
else if (hasNonNullishProperty(message, 'sharePhoneNumber')) {
|
|
470
|
+
m.protocolMessage = {
|
|
471
|
+
type: proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
else if (hasNonNullishProperty(message, 'requestPhoneNumber')) {
|
|
475
|
+
m.requestPhoneNumberMessage = {};
|
|
476
|
+
}
|
|
477
|
+
else if (hasNonNullishProperty(message, 'limitSharing')) {
|
|
478
|
+
m.protocolMessage = {
|
|
479
|
+
type: proto.Message.ProtocolMessage.Type.LIMIT_SHARING,
|
|
480
|
+
limitSharing: {
|
|
481
|
+
sharingLimited: message.limitSharing === true,
|
|
482
|
+
trigger: 1,
|
|
483
|
+
limitSharingSettingTimestamp: Date.now(),
|
|
484
|
+
initiatedByMe: true
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
m = await prepareWAMessageMedia(message, options);
|
|
490
|
+
}
|
|
491
|
+
if (hasOptionalProperty(message, 'viewOnce') && !!message.viewOnce) {
|
|
492
|
+
m = { viewOnceMessage: { message: m } };
|
|
493
|
+
}
|
|
494
|
+
if ((hasOptionalProperty(message, 'mentions') && message.mentions?.length) ||
|
|
495
|
+
(hasOptionalProperty(message, 'mentionAll') && message.mentionAll)) {
|
|
496
|
+
const messageType = Object.keys(m)[0];
|
|
497
|
+
const key = m[messageType];
|
|
498
|
+
if (key && 'contextInfo' in key) {
|
|
499
|
+
key.contextInfo = key.contextInfo || {};
|
|
500
|
+
if (message.mentions?.length) {
|
|
501
|
+
key.contextInfo.mentionedJid = message.mentions;
|
|
502
|
+
}
|
|
503
|
+
if (message.mentionAll) {
|
|
504
|
+
key.contextInfo.nonJidMentions = 1;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
else if (key) {
|
|
508
|
+
key.contextInfo = {
|
|
509
|
+
mentionedJid: message.mentions,
|
|
510
|
+
nonJidMentions: message.mentionAll ? 1 : 0
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
if (hasOptionalProperty(message, 'edit')) {
|
|
515
|
+
m = {
|
|
516
|
+
protocolMessage: {
|
|
517
|
+
key: message.edit,
|
|
518
|
+
editedMessage: m,
|
|
519
|
+
timestampMs: Date.now(),
|
|
520
|
+
type: WAProto.Message.ProtocolMessage.Type.MESSAGE_EDIT
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
if (hasOptionalProperty(message, 'contextInfo') && !!message.contextInfo) {
|
|
525
|
+
const messageType = Object.keys(m)[0];
|
|
526
|
+
const key = m[messageType];
|
|
527
|
+
if ('contextInfo' in key && !!key.contextInfo) {
|
|
528
|
+
key.contextInfo = { ...key.contextInfo, ...message.contextInfo };
|
|
529
|
+
}
|
|
530
|
+
else if (key) {
|
|
531
|
+
key.contextInfo = message.contextInfo;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
if (hasOptionalProperty(message, 'albumParentKey') && !!message.albumParentKey) {
|
|
535
|
+
m.messageContextInfo = {
|
|
536
|
+
...m.messageContextInfo,
|
|
537
|
+
messageAssociation: {
|
|
538
|
+
associationType: WAProto.MessageAssociation.AssociationType.MEDIA_ALBUM,
|
|
539
|
+
parentMessageKey: message.albumParentKey
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
if (shouldIncludeReportingToken(m)) {
|
|
544
|
+
m.messageContextInfo = m.messageContextInfo || {};
|
|
545
|
+
if (!m.messageContextInfo.messageSecret) {
|
|
546
|
+
m.messageContextInfo.messageSecret = randomBytes(32);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return WAProto.Message.create(m);
|
|
548
550
|
};
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
551
|
+
export const generateWAMessageFromContent = (jid, message, options) => {
|
|
552
|
+
// set timestamp to now
|
|
553
|
+
// if not specified
|
|
554
|
+
if (!options.timestamp) {
|
|
555
|
+
options.timestamp = new Date();
|
|
556
|
+
}
|
|
557
|
+
const innerMessage = normalizeMessageContent(message);
|
|
558
|
+
const key = getContentType(innerMessage);
|
|
559
|
+
const timestamp = unixTimestampSeconds(options.timestamp);
|
|
560
|
+
const { quoted, userJid } = options;
|
|
561
|
+
if (quoted && !isJidNewsletter(jid)) {
|
|
562
|
+
const participant = quoted.key.fromMe
|
|
563
|
+
? userJid // TODO: Add support for LIDs
|
|
564
|
+
: quoted.participant || quoted.key.participant || quoted.key.remoteJid;
|
|
565
|
+
let quotedMsg = normalizeMessageContent(quoted.message);
|
|
566
|
+
const msgType = getContentType(quotedMsg);
|
|
567
|
+
// strip any redundant properties
|
|
568
|
+
quotedMsg = proto.Message.create({ [msgType]: quotedMsg[msgType] });
|
|
569
|
+
const quotedContent = quotedMsg[msgType];
|
|
570
|
+
if (typeof quotedContent === 'object' && quotedContent && 'contextInfo' in quotedContent) {
|
|
571
|
+
delete quotedContent.contextInfo;
|
|
572
|
+
}
|
|
573
|
+
const contextInfo = ('contextInfo' in innerMessage[key] && innerMessage[key]?.contextInfo) || {};
|
|
574
|
+
contextInfo.participant = jidNormalizedUser(participant);
|
|
575
|
+
contextInfo.stanzaId = quoted.key.id;
|
|
576
|
+
contextInfo.quotedMessage = quotedMsg;
|
|
577
|
+
// if a participant is quoted, then it must be a group
|
|
578
|
+
// hence, remoteJid of group must also be entered
|
|
579
|
+
if (jid !== quoted.key.remoteJid) {
|
|
580
|
+
contextInfo.remoteJid = quoted.key.remoteJid;
|
|
581
|
+
}
|
|
582
|
+
if (contextInfo && innerMessage[key]) {
|
|
583
|
+
/* @ts-ignore */
|
|
584
|
+
innerMessage[key].contextInfo = contextInfo;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
if (
|
|
588
|
+
// if we want to send a disappearing message
|
|
589
|
+
!!options?.ephemeralExpiration &&
|
|
590
|
+
// and it's not a protocol message -- delete, toggle disappear message
|
|
591
|
+
key !== 'protocolMessage' &&
|
|
592
|
+
// already not converted to disappearing message
|
|
593
|
+
key !== 'ephemeralMessage' &&
|
|
594
|
+
// newsletters don't support ephemeral messages
|
|
595
|
+
!isJidNewsletter(jid)) {
|
|
596
|
+
/* @ts-ignore */
|
|
597
|
+
innerMessage[key].contextInfo = {
|
|
598
|
+
...(innerMessage[key].contextInfo || {}),
|
|
599
|
+
expiration: options.ephemeralExpiration || WA_DEFAULT_EPHEMERAL
|
|
600
|
+
//ephemeralSettingTimestamp: options.ephemeralOptions.eph_setting_ts?.toString()
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
message = WAProto.Message.create(message);
|
|
604
|
+
const messageJSON = {
|
|
605
|
+
key: {
|
|
606
|
+
remoteJid: jid,
|
|
607
|
+
fromMe: true,
|
|
608
|
+
id: options?.messageId || generateMessageIDV2()
|
|
609
|
+
},
|
|
610
|
+
message: message,
|
|
611
|
+
messageTimestamp: timestamp,
|
|
612
|
+
messageStubParameters: [],
|
|
613
|
+
participant: isJidGroup(jid) || isJidStatusBroadcast(jid) ? userJid : undefined, // TODO: Add support for LIDs
|
|
614
|
+
status: WAMessageStatus.PENDING
|
|
603
615
|
};
|
|
604
|
-
|
|
605
|
-
message = _index3.WAProto.Message.create(message);
|
|
606
|
-
const messageJSON = {
|
|
607
|
-
key: {
|
|
608
|
-
remoteJid: jid,
|
|
609
|
-
fromMe: true,
|
|
610
|
-
id: options?.messageId || (0, _generics.generateMessageIDV2)()
|
|
611
|
-
},
|
|
612
|
-
message: message,
|
|
613
|
-
messageTimestamp: timestamp,
|
|
614
|
-
messageStubParameters: [],
|
|
615
|
-
participant: (0, _index4.isJidGroup)(jid) || (0, _index4.isJidStatusBroadcast)(jid) ? userJid : undefined,
|
|
616
|
-
status: _index3.WAMessageStatus.PENDING
|
|
617
|
-
};
|
|
618
|
-
return _index3.WAProto.WebMessageInfo.create(messageJSON);
|
|
616
|
+
return WAProto.WebMessageInfo.fromObject(messageJSON);
|
|
619
617
|
};
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
});
|
|
626
|
-
// Pass jid in the options to generateWAMessageContent
|
|
627
|
-
return generateWAMessageFromContent(jid, await generateWAMessageContent(content, {
|
|
628
|
-
...options,
|
|
629
|
-
jid
|
|
630
|
-
}), options);
|
|
618
|
+
export const generateWAMessage = async (jid, content, options) => {
|
|
619
|
+
// ensure msg ID is with every log
|
|
620
|
+
options.logger = options?.logger?.child({ msgId: options.messageId });
|
|
621
|
+
// Pass jid in the options to generateWAMessageContent
|
|
622
|
+
return generateWAMessageFromContent(jid, await generateWAMessageContent(content, { ...options, jid }), options);
|
|
631
623
|
};
|
|
632
624
|
/** Get the key to access the true type of content */
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
}
|
|
625
|
+
export const getContentType = (content) => {
|
|
626
|
+
if (content) {
|
|
627
|
+
const keys = Object.keys(content);
|
|
628
|
+
const key = keys.find(k => (k === 'conversation' || k.includes('Message')) && k !== 'senderKeyDistributionMessage');
|
|
629
|
+
return key;
|
|
630
|
+
}
|
|
640
631
|
};
|
|
641
632
|
/**
|
|
642
633
|
* Normalizes ephemeral, view once messages to regular message content
|
|
@@ -644,102 +635,116 @@ const getContentType = content => {
|
|
|
644
635
|
* @param content
|
|
645
636
|
* @returns
|
|
646
637
|
*/
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
638
|
+
export const normalizeMessageContent = (content) => {
|
|
639
|
+
if (!content) {
|
|
640
|
+
return undefined;
|
|
641
|
+
}
|
|
642
|
+
// set max iterations to prevent an infinite loop
|
|
643
|
+
for (let i = 0; i < 5; i++) {
|
|
644
|
+
const inner = getFutureProofMessage(content);
|
|
645
|
+
if (!inner) {
|
|
646
|
+
break;
|
|
647
|
+
}
|
|
648
|
+
content = inner.message;
|
|
649
|
+
}
|
|
650
|
+
return content;
|
|
651
|
+
function getFutureProofMessage(message) {
|
|
652
|
+
return (message?.ephemeralMessage ||
|
|
653
|
+
message?.viewOnceMessage ||
|
|
654
|
+
message?.documentWithCaptionMessage ||
|
|
655
|
+
message?.viewOnceMessageV2 ||
|
|
656
|
+
message?.viewOnceMessageV2Extension ||
|
|
657
|
+
message?.editedMessage ||
|
|
658
|
+
message?.associatedChildMessage ||
|
|
659
|
+
message?.groupStatusMessage ||
|
|
660
|
+
message?.groupStatusMessageV2);
|
|
661
|
+
}
|
|
664
662
|
};
|
|
665
663
|
/**
|
|
666
664
|
* Extract the true message content from a message
|
|
667
665
|
* Eg. extracts the inner message from a disappearing message/view once message
|
|
668
666
|
*/
|
|
669
|
-
|
|
670
|
-
const
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
return
|
|
703
|
-
}
|
|
704
|
-
if (content?.templateMessage?.fourRowTemplate) {
|
|
705
|
-
return extractFromTemplateMessage(content?.templateMessage?.fourRowTemplate);
|
|
706
|
-
}
|
|
707
|
-
return content;
|
|
667
|
+
export const extractMessageContent = (content) => {
|
|
668
|
+
const extractFromTemplateMessage = (msg) => {
|
|
669
|
+
if (msg.imageMessage) {
|
|
670
|
+
return { imageMessage: msg.imageMessage };
|
|
671
|
+
}
|
|
672
|
+
else if (msg.documentMessage) {
|
|
673
|
+
return { documentMessage: msg.documentMessage };
|
|
674
|
+
}
|
|
675
|
+
else if (msg.videoMessage) {
|
|
676
|
+
return { videoMessage: msg.videoMessage };
|
|
677
|
+
}
|
|
678
|
+
else if (msg.locationMessage) {
|
|
679
|
+
return { locationMessage: msg.locationMessage };
|
|
680
|
+
}
|
|
681
|
+
else {
|
|
682
|
+
return {
|
|
683
|
+
conversation: 'contentText' in msg ? msg.contentText : 'hydratedContentText' in msg ? msg.hydratedContentText : ''
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
};
|
|
687
|
+
content = normalizeMessageContent(content);
|
|
688
|
+
if (content?.buttonsMessage) {
|
|
689
|
+
return extractFromTemplateMessage(content.buttonsMessage);
|
|
690
|
+
}
|
|
691
|
+
if (content?.templateMessage?.hydratedFourRowTemplate) {
|
|
692
|
+
return extractFromTemplateMessage(content?.templateMessage?.hydratedFourRowTemplate);
|
|
693
|
+
}
|
|
694
|
+
if (content?.templateMessage?.hydratedTemplate) {
|
|
695
|
+
return extractFromTemplateMessage(content?.templateMessage?.hydratedTemplate);
|
|
696
|
+
}
|
|
697
|
+
if (content?.templateMessage?.fourRowTemplate) {
|
|
698
|
+
return extractFromTemplateMessage(content?.templateMessage?.fourRowTemplate);
|
|
699
|
+
}
|
|
700
|
+
return content;
|
|
708
701
|
};
|
|
709
702
|
/**
|
|
710
703
|
* Returns the device predicted by message ID
|
|
711
704
|
*/
|
|
712
|
-
|
|
713
|
-
|
|
705
|
+
export const getDevice = (id) => /^3A.{18}$/.test(id)
|
|
706
|
+
? 'ios'
|
|
707
|
+
: /^3E.{20}$/.test(id)
|
|
708
|
+
? 'web'
|
|
709
|
+
: /^(.{21}|.{32})$/.test(id)
|
|
710
|
+
? 'android'
|
|
711
|
+
: /^(3F|.{18}$)/.test(id)
|
|
712
|
+
? 'desktop'
|
|
713
|
+
: 'unknown';
|
|
714
714
|
/** Upserts a receipt in the message */
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
715
|
+
export const updateMessageWithReceipt = (msg, receipt) => {
|
|
716
|
+
msg.userReceipt = msg.userReceipt || [];
|
|
717
|
+
const recp = msg.userReceipt.find(m => m.userJid === receipt.userJid);
|
|
718
|
+
if (recp) {
|
|
719
|
+
Object.assign(recp, receipt);
|
|
720
|
+
}
|
|
721
|
+
else {
|
|
722
|
+
msg.userReceipt.push(receipt);
|
|
723
|
+
}
|
|
724
724
|
};
|
|
725
725
|
/** Update the message with a new reaction */
|
|
726
|
-
|
|
727
|
-
const
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
msg.reactions = reactions;
|
|
726
|
+
export const updateMessageWithReaction = (msg, reaction) => {
|
|
727
|
+
const authorID = getKeyAuthor(reaction.key);
|
|
728
|
+
const reactions = (msg.reactions || []).filter(r => getKeyAuthor(r.key) !== authorID);
|
|
729
|
+
reaction.text = reaction.text || '';
|
|
730
|
+
reactions.push(reaction);
|
|
731
|
+
msg.reactions = reactions;
|
|
733
732
|
};
|
|
734
733
|
/** Update the message with a new poll update */
|
|
735
|
-
|
|
736
|
-
const
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
734
|
+
export const updateMessageWithPollUpdate = (msg, update) => {
|
|
735
|
+
const authorID = getKeyAuthor(update.pollUpdateMessageKey);
|
|
736
|
+
const reactions = (msg.pollUpdates || []).filter(r => getKeyAuthor(r.pollUpdateMessageKey) !== authorID);
|
|
737
|
+
if (update.vote?.selectedOptions?.length) {
|
|
738
|
+
reactions.push(update);
|
|
739
|
+
}
|
|
740
|
+
msg.pollUpdates = reactions;
|
|
741
|
+
};
|
|
742
|
+
/** Update the message with a new event response */
|
|
743
|
+
export const updateMessageWithEventResponse = (msg, update) => {
|
|
744
|
+
const authorID = getKeyAuthor(update.eventResponseMessageKey);
|
|
745
|
+
const responses = (msg.eventResponses || []).filter(r => getKeyAuthor(r.eventResponseMessageKey) !== authorID);
|
|
746
|
+
responses.push(update);
|
|
747
|
+
msg.eventResponses = responses;
|
|
743
748
|
};
|
|
744
749
|
/**
|
|
745
750
|
* Aggregates all poll updates in a poll.
|
|
@@ -747,133 +752,142 @@ const updateMessageWithPollUpdate = (msg, update) => {
|
|
|
747
752
|
* @param meId your jid
|
|
748
753
|
* @returns A list of options & their voters
|
|
749
754
|
*/
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
voters: []
|
|
761
|
-
};
|
|
762
|
-
return acc;
|
|
763
|
-
}, {});
|
|
764
|
-
for (const update of pollUpdates || []) {
|
|
765
|
-
const {
|
|
766
|
-
vote
|
|
767
|
-
} = update;
|
|
768
|
-
if (!vote) {
|
|
769
|
-
continue;
|
|
770
|
-
}
|
|
771
|
-
for (const option of vote.selectedOptions || []) {
|
|
772
|
-
const hash = option.toString();
|
|
773
|
-
let data = voteHashMap[hash];
|
|
774
|
-
if (!data) {
|
|
775
|
-
voteHashMap[hash] = {
|
|
776
|
-
name: 'Unknown',
|
|
777
|
-
voters: []
|
|
755
|
+
export function getAggregateVotesInPollMessage({ message, pollUpdates }, meId) {
|
|
756
|
+
const opts = message?.pollCreationMessage?.options ||
|
|
757
|
+
message?.pollCreationMessageV2?.options ||
|
|
758
|
+
message?.pollCreationMessageV3?.options ||
|
|
759
|
+
[];
|
|
760
|
+
const voteHashMap = opts.reduce((acc, opt) => {
|
|
761
|
+
const hash = sha256(Buffer.from(opt.optionName || '')).toString();
|
|
762
|
+
acc[hash] = {
|
|
763
|
+
name: opt.optionName || '',
|
|
764
|
+
voters: []
|
|
778
765
|
};
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
766
|
+
return acc;
|
|
767
|
+
}, {});
|
|
768
|
+
for (const update of pollUpdates || []) {
|
|
769
|
+
const { vote } = update;
|
|
770
|
+
if (!vote) {
|
|
771
|
+
continue;
|
|
772
|
+
}
|
|
773
|
+
for (const option of vote.selectedOptions || []) {
|
|
774
|
+
const hash = option.toString();
|
|
775
|
+
let data = voteHashMap[hash];
|
|
776
|
+
if (!data) {
|
|
777
|
+
voteHashMap[hash] = {
|
|
778
|
+
name: 'Unknown',
|
|
779
|
+
voters: []
|
|
780
|
+
};
|
|
781
|
+
data = voteHashMap[hash];
|
|
782
|
+
}
|
|
783
|
+
voteHashMap[hash].voters.push(getKeyAuthor(update.pollUpdateMessageKey, meId));
|
|
784
|
+
}
|
|
782
785
|
}
|
|
783
|
-
|
|
784
|
-
return Object.values(voteHashMap);
|
|
786
|
+
return Object.values(voteHashMap);
|
|
785
787
|
}
|
|
786
|
-
/**
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
jid: remoteJid,
|
|
800
|
-
participant: participant,
|
|
801
|
-
messageIds: []
|
|
788
|
+
/**
|
|
789
|
+
* Aggregates all event responses in an event message.
|
|
790
|
+
* @param msg the event creation message
|
|
791
|
+
* @param meId your jid
|
|
792
|
+
* @returns A list of response types & their responders
|
|
793
|
+
*/
|
|
794
|
+
export function getAggregateResponsesInEventMessage({ eventResponses }, meId) {
|
|
795
|
+
const responseTypes = ['GOING', 'NOT_GOING', 'MAYBE'];
|
|
796
|
+
const responseMap = {};
|
|
797
|
+
for (const type of responseTypes) {
|
|
798
|
+
responseMap[type] = {
|
|
799
|
+
response: type,
|
|
800
|
+
responders: []
|
|
802
801
|
};
|
|
803
|
-
}
|
|
804
|
-
keyMap[uqKey].messageIds.push(id);
|
|
805
802
|
}
|
|
806
|
-
|
|
807
|
-
|
|
803
|
+
for (const update of eventResponses || []) {
|
|
804
|
+
const responseType = update.eventResponse || 'UNKNOWN';
|
|
805
|
+
if (responseType !== 'UNKNOWN' && responseMap[responseType]) {
|
|
806
|
+
responseMap[responseType].responders.push(getKeyAuthor(update.eventResponseMessageKey, meId));
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
return Object.values(responseMap);
|
|
810
|
+
}
|
|
811
|
+
/** Given a list of message keys, aggregates them by chat & sender. Useful for sending read receipts in bulk */
|
|
812
|
+
export const aggregateMessageKeysNotFromMe = (keys) => {
|
|
813
|
+
const keyMap = {};
|
|
814
|
+
for (const { remoteJid, id, participant, fromMe } of keys) {
|
|
815
|
+
if (!fromMe) {
|
|
816
|
+
const uqKey = `${remoteJid}:${participant || ''}`;
|
|
817
|
+
if (!keyMap[uqKey]) {
|
|
818
|
+
keyMap[uqKey] = {
|
|
819
|
+
jid: remoteJid,
|
|
820
|
+
participant: participant,
|
|
821
|
+
messageIds: []
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
keyMap[uqKey].messageIds.push(id);
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
return Object.values(keyMap);
|
|
808
828
|
};
|
|
809
|
-
exports.aggregateMessageKeysNotFromMe = aggregateMessageKeysNotFromMe;
|
|
810
829
|
const REUPLOAD_REQUIRED_STATUS = [410, 404];
|
|
811
830
|
/**
|
|
812
831
|
* Downloads the given message. Throws an error if it's not a media message
|
|
813
832
|
*/
|
|
814
|
-
const downloadMediaMessage = async (message, type, options, ctx) => {
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
return Buffer.concat(bufferArray);
|
|
861
|
-
}
|
|
862
|
-
return stream;
|
|
863
|
-
}
|
|
833
|
+
export const downloadMediaMessage = async (message, type, options, ctx) => {
|
|
834
|
+
const result = await downloadMsg().catch(async (error) => {
|
|
835
|
+
if (ctx &&
|
|
836
|
+
typeof error?.status === 'number' && // treat errors with status as HTTP failures requiring reupload
|
|
837
|
+
REUPLOAD_REQUIRED_STATUS.includes(error.status)) {
|
|
838
|
+
ctx.logger.info({ key: message.key }, 'sending reupload media request...');
|
|
839
|
+
// request reupload
|
|
840
|
+
message = await ctx.reuploadRequest(message);
|
|
841
|
+
const result = await downloadMsg();
|
|
842
|
+
return result;
|
|
843
|
+
}
|
|
844
|
+
throw error;
|
|
845
|
+
});
|
|
846
|
+
return result;
|
|
847
|
+
async function downloadMsg() {
|
|
848
|
+
const mContent = extractMessageContent(message.message);
|
|
849
|
+
if (!mContent) {
|
|
850
|
+
throw new Boom('No message present', { statusCode: 400, data: message });
|
|
851
|
+
}
|
|
852
|
+
const contentType = getContentType(mContent);
|
|
853
|
+
let mediaType = contentType?.replace('Message', '');
|
|
854
|
+
const media = mContent[contentType];
|
|
855
|
+
if (!media || typeof media !== 'object' || (!('url' in media) && !('thumbnailDirectPath' in media))) {
|
|
856
|
+
throw new Boom(`"${contentType}" message is not a media message`);
|
|
857
|
+
}
|
|
858
|
+
let download;
|
|
859
|
+
if ('thumbnailDirectPath' in media && !('url' in media)) {
|
|
860
|
+
download = {
|
|
861
|
+
directPath: media.thumbnailDirectPath,
|
|
862
|
+
mediaKey: media.mediaKey
|
|
863
|
+
};
|
|
864
|
+
mediaType = 'thumbnail-link';
|
|
865
|
+
}
|
|
866
|
+
else {
|
|
867
|
+
download = media;
|
|
868
|
+
}
|
|
869
|
+
const stream = await downloadContentFromMessage(download, mediaType, options);
|
|
870
|
+
if (type === 'buffer') {
|
|
871
|
+
const bufferArray = [];
|
|
872
|
+
for await (const chunk of stream) {
|
|
873
|
+
bufferArray.push(chunk);
|
|
874
|
+
}
|
|
875
|
+
return Buffer.concat(bufferArray);
|
|
876
|
+
}
|
|
877
|
+
return stream;
|
|
878
|
+
}
|
|
864
879
|
};
|
|
865
880
|
/** Checks whether the given message is a media message; if it is returns the inner content */
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
881
|
+
export const assertMediaContent = (content) => {
|
|
882
|
+
content = extractMessageContent(content);
|
|
883
|
+
const mediaContent = content?.documentMessage ||
|
|
884
|
+
content?.imageMessage ||
|
|
885
|
+
content?.videoMessage ||
|
|
886
|
+
content?.audioMessage ||
|
|
887
|
+
content?.stickerMessage;
|
|
888
|
+
if (!mediaContent) {
|
|
889
|
+
throw new Boom('given message is not a media message', { statusCode: 400, data: content });
|
|
890
|
+
}
|
|
891
|
+
return mediaContent;
|
|
877
892
|
};
|
|
878
|
-
//# sourceMappingURL=messages.js.map
|
|
879
|
-
exports.assertMediaContent = assertMediaContent;
|
|
893
|
+
//# sourceMappingURL=messages.js.map
|