@modzneverdie/baileys 17.1.2 → 17.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +6035 -0
- package/WAProto/fix-imports.js +81 -0
- package/WAProto/index.d.ts +2 -0
- package/WAProto/index.js +59469 -96804
- package/lib/Defaults/index.d.ts +29 -8
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +134 -141
- package/lib/Defaults/index.js.map +1 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +1 -0
- package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
- package/lib/Signal/Group/ciphertext-message.js +2 -5
- package/lib/Signal/Group/ciphertext-message.js.map +1 -0
- package/lib/Signal/Group/group-session-builder.d.ts +4 -3
- package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
- package/lib/Signal/Group/group-session-builder.js +7 -41
- package/lib/Signal/Group/group-session-builder.js.map +1 -0
- package/lib/Signal/Group/group_cipher.d.ts +4 -4
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
- package/lib/Signal/Group/group_cipher.js +37 -51
- package/lib/Signal/Group/group_cipher.js.map +1 -0
- package/lib/Signal/Group/index.d.ts +12 -11
- package/lib/Signal/Group/index.d.ts.map +1 -0
- package/lib/Signal/Group/index.js +12 -57
- package/lib/Signal/Group/index.js.map +1 -0
- package/lib/Signal/Group/keyhelper.d.ts +2 -1
- package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
- package/lib/Signal/Group/keyhelper.js +7 -44
- package/lib/Signal/Group/keyhelper.js.map +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +3 -2
- package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-chain-key.js +7 -15
- package/lib/Signal/Group/sender-chain-key.js.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +2 -1
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +8 -11
- package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-message.d.ts +2 -1
- package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-message.js +9 -12
- package/lib/Signal/Group/sender-key-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-name.d.ts +1 -0
- package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-name.js +2 -5
- package/lib/Signal/Group/sender-key-name.js.map +1 -0
- package/lib/Signal/Group/sender-key-record.d.ts +3 -2
- package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-record.js +9 -21
- package/lib/Signal/Group/sender-key-record.js.map +1 -0
- package/lib/Signal/Group/sender-key-state.d.ts +7 -6
- package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-state.js +27 -42
- package/lib/Signal/Group/sender-key-state.js.map +1 -0
- package/lib/Signal/Group/sender-message-key.d.ts +1 -0
- package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-message-key.js +4 -7
- package/lib/Signal/Group/sender-message-key.js.map +1 -0
- package/lib/Signal/libsignal.d.ts +5 -3
- package/lib/Signal/libsignal.d.ts.map +1 -0
- package/lib/Signal/libsignal.js +319 -90
- package/lib/Signal/libsignal.js.map +1 -0
- package/lib/Signal/lid-mapping.d.ts +19 -0
- package/lib/Signal/lid-mapping.d.ts.map +1 -0
- package/lib/Signal/lid-mapping.js +271 -0
- package/lib/Signal/lid-mapping.js.map +1 -0
- package/lib/Socket/Client/index.d.ts +3 -3
- package/lib/Socket/Client/index.d.ts.map +1 -0
- package/lib/Socket/Client/index.js +3 -19
- package/lib/Socket/Client/index.js.map +1 -0
- package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +4 -5
- package/lib/Socket/Client/types.d.ts.map +1 -0
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/types.js.map +1 -0
- package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +3 -2
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +54 -0
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +533 -168
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +405 -243
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +84 -240
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +406 -385
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +645 -0
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/dugong.d.ts +125 -249
- package/lib/Socket/dugong.d.ts.map +1 -0
- package/lib/Socket/dugong.js +749 -465
- package/lib/Socket/dugong.js.map +1 -0
- package/lib/Socket/groups.d.ts +93 -58
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +105 -95
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +632 -169
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +15 -11
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +162 -85
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +806 -608
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +576 -146
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +1563 -861
- package/lib/Socket/messages-send.js.map +1 -0
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.d.ts.map +1 -0
- package/lib/Socket/mex.js +48 -0
- package/lib/Socket/mex.js.map +1 -0
- package/lib/Socket/newsletter.d.ts +129 -86
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +438 -297
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +31 -19
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +512 -241
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Types/Auth.d.ts +18 -12
- package/lib/Types/Auth.d.ts.map +1 -0
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Auth.js.map +1 -0
- package/lib/Types/Bussines.d.ts +37 -0
- package/lib/Types/Bussines.d.ts.map +1 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Bussines.js.map +1 -0
- package/lib/Types/Call.d.ts +3 -1
- package/lib/Types/Call.d.ts.map +1 -0
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Call.js.map +1 -0
- package/lib/Types/Chat.d.ts +34 -13
- package/lib/Types/Chat.d.ts.map +1 -0
- package/lib/Types/Chat.js +8 -4
- package/lib/Types/Chat.js.map +1 -0
- package/lib/Types/Contact.d.ts +6 -1
- package/lib/Types/Contact.d.ts.map +1 -0
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Contact.js.map +1 -0
- package/lib/Types/Events.d.ts +97 -17
- package/lib/Types/Events.d.ts.map +1 -0
- package/lib/Types/Events.js +2 -2
- package/lib/Types/Events.js.map +1 -0
- package/lib/Types/GroupMetadata.d.ts +18 -5
- package/lib/Types/GroupMetadata.d.ts.map +1 -0
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/GroupMetadata.js.map +1 -0
- package/lib/Types/Label.d.ts +12 -0
- package/lib/Types/Label.d.ts.map +1 -0
- package/lib/Types/Label.js +3 -5
- package/lib/Types/Label.js.map +1 -0
- package/lib/Types/LabelAssociation.d.ts +1 -0
- package/lib/Types/LabelAssociation.d.ts.map +1 -0
- package/lib/Types/LabelAssociation.js +3 -5
- package/lib/Types/LabelAssociation.js.map +1 -0
- package/lib/Types/Message.d.ts +355 -206
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +11 -9
- package/lib/Types/Message.js.map +1 -0
- package/lib/Types/Newsletter.d.ts +130 -98
- package/lib/Types/Newsletter.d.ts.map +1 -0
- package/lib/Types/Newsletter.js +31 -38
- package/lib/Types/Newsletter.js.map +1 -0
- package/lib/Types/Product.d.ts +2 -1
- package/lib/Types/Product.d.ts.map +1 -0
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Product.js.map +1 -0
- package/lib/Types/Signal.d.ts +20 -1
- package/lib/Types/Signal.d.ts.map +1 -0
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Signal.js.map +1 -0
- package/lib/Types/Socket.d.ts +152 -105
- package/lib/Types/Socket.d.ts.map +1 -0
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/Socket.js.map +1 -0
- package/lib/Types/State.d.ts +14 -2
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +13 -2
- package/lib/Types/State.js.map +1 -0
- package/lib/Types/USync.d.ts +3 -2
- package/lib/Types/USync.d.ts.map +1 -0
- package/lib/Types/USync.js +2 -2
- package/lib/Types/USync.js.map +1 -0
- package/lib/Types/index.d.ts +54 -45
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +32 -41
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/auth-utils.d.ts +7 -6
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +228 -144
- package/lib/Utils/auth-utils.js.map +1 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.d.ts.map +1 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/browser-utils.js.map +1 -0
- package/lib/Utils/business.d.ts +3 -2
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +66 -69
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +19 -20
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +331 -248
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +10 -14
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +57 -90
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +37 -8
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +169 -84
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +7 -8
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +138 -78
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +26 -27
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +170 -209
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts +16 -9
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +83 -48
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/identity-change-handler.d.ts +37 -0
- package/lib/Utils/identity-change-handler.d.ts.map +1 -0
- package/lib/Utils/identity-change-handler.js +49 -0
- package/lib/Utils/identity-change-handler.js.map +1 -0
- package/lib/Utils/index.d.ts +23 -17
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +23 -33
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/link-preview.d.ts +5 -5
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +14 -22
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +12 -3
- package/lib/Utils/logger.d.ts.map +1 -0
- package/lib/Utils/logger.js +3 -7
- package/lib/Utils/logger.js.map +1 -0
- package/lib/Utils/lt-hash.d.ts +8 -12
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +3 -46
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts +4 -2
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +24 -34
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/message-retry-manager.d.ts +110 -0
- package/lib/Utils/message-retry-manager.d.ts.map +1 -0
- package/lib/Utils/message-retry-manager.js +225 -0
- package/lib/Utils/message-retry-manager.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +56 -42
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +411 -448
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +32 -18
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +1132 -710
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts +12 -13
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +145 -99
- package/lib/Utils/noise-handler.js.map +1 -0
- package/lib/Utils/offline-node-processor.d.ts +17 -0
- package/lib/Utils/offline-node-processor.d.ts.map +1 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/offline-node-processor.js.map +1 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.d.ts.map +1 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/pre-key-manager.js.map +1 -0
- package/lib/Utils/process-message.d.ts +31 -12
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +357 -150
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.d.ts.map +1 -0
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/reporting-utils.js.map +1 -0
- package/lib/Utils/rich-messages.d.ts +277 -0
- package/lib/Utils/rich-messages.d.ts.map +1 -0
- package/lib/Utils/rich-messages.js +1144 -0
- package/lib/Utils/rich-messages.js.map +1 -0
- package/lib/Utils/signal.d.ts +7 -5
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +78 -72
- package/lib/Utils/signal.js.map +1 -0
- package/lib/Utils/stanza-ack.d.ts +11 -0
- package/lib/Utils/stanza-ack.d.ts.map +1 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/stanza-ack.js.map +1 -0
- package/lib/Utils/sticker-pack.d.ts +10 -0
- package/lib/Utils/sticker-pack.js +111 -0
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.d.ts.map +1 -0
- package/lib/Utils/sync-action-utils.js +48 -0
- package/lib/Utils/sync-action-utils.js.map +1 -0
- package/lib/Utils/tc-token-utils.d.ts +12 -0
- package/lib/Utils/tc-token-utils.d.ts.map +1 -0
- package/lib/Utils/tc-token-utils.js +18 -0
- package/lib/Utils/tc-token-utils.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +2 -2
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +29 -27
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts +7 -7
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +70 -99
- package/lib/Utils/validate-connection.js.map +1 -0
- package/lib/WABinary/constants.d.ts +25 -27
- package/lib/WABinary/constants.d.ts.map +1 -0
- package/lib/WABinary/constants.js +1281 -20
- package/lib/WABinary/constants.js.map +1 -0
- package/lib/WABinary/decode.d.ts +5 -5
- package/lib/WABinary/decode.d.ts.map +1 -0
- package/lib/WABinary/decode.js +52 -42
- package/lib/WABinary/decode.js.map +1 -0
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.d.ts.map +1 -0
- package/lib/WABinary/encode.js +110 -155
- package/lib/WABinary/encode.js.map +1 -0
- package/lib/WABinary/generic-utils.d.ts +8 -8
- package/lib/WABinary/generic-utils.d.ts.map +1 -0
- package/lib/WABinary/generic-utils.js +142 -149
- package/lib/WABinary/generic-utils.js.map +1 -0
- package/lib/WABinary/index.d.ts +6 -5
- package/lib/WABinary/index.d.ts.map +1 -0
- package/lib/WABinary/index.js +6 -21
- package/lib/WABinary/index.js.map +1 -0
- package/lib/WABinary/jid-utils.d.ts +25 -8
- package/lib/WABinary/jid-utils.d.ts.map +1 -0
- package/lib/WABinary/jid-utils.js +74 -40
- package/lib/WABinary/jid-utils.js.map +1 -0
- package/lib/WABinary/types.d.ts +2 -1
- package/lib/WABinary/types.d.ts.map +1 -0
- package/lib/WABinary/types.js +2 -2
- package/lib/WABinary/types.js.map +1 -0
- package/lib/WAM/BinaryInfo.d.ts +3 -11
- package/lib/WAM/BinaryInfo.d.ts.map +1 -0
- package/lib/WAM/BinaryInfo.js +2 -5
- package/lib/WAM/BinaryInfo.js.map +1 -0
- package/lib/WAM/constants.d.ts +5 -3
- package/lib/WAM/constants.d.ts.map +1 -0
- package/lib/WAM/constants.js +19071 -11568
- package/lib/WAM/constants.js.map +1 -0
- package/lib/WAM/encode.d.ts +2 -2
- package/lib/WAM/encode.d.ts.map +1 -0
- package/lib/WAM/encode.js +17 -22
- package/lib/WAM/encode.js.map +1 -0
- package/lib/WAM/index.d.ts +4 -3
- package/lib/WAM/index.d.ts.map +1 -0
- package/lib/WAM/index.js +4 -19
- package/lib/WAM/index.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +4 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +8 -11
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -14
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -12
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -13
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +4 -3
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -22
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +5 -3
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +13 -8
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/index.d.ts +5 -4
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/index.js +5 -20
- package/lib/WAUSync/Protocols/index.js.map +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +5 -4
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
- package/lib/WAUSync/USyncQuery.js +40 -35
- package/lib/WAUSync/USyncQuery.js.map +1 -0
- package/lib/WAUSync/USyncUser.d.ts +6 -5
- package/lib/WAUSync/USyncUser.d.ts.map +1 -0
- package/lib/WAUSync/USyncUser.js +2 -5
- package/lib/WAUSync/USyncUser.js.map +1 -0
- package/lib/WAUSync/index.d.ts +4 -3
- package/lib/WAUSync/index.d.ts.map +1 -0
- package/lib/WAUSync/index.js +4 -19
- package/lib/WAUSync/index.js.map +1 -0
- package/lib/index.d.ts +10 -9
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +12 -33
- package/lib/index.js.map +1 -0
- package/package.json +64 -105
- package/README.md +0 -364
- package/engine-requirements.js +0 -10
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/registration.d.ts +0 -267
- package/lib/Socket/registration.js +0 -166
- package/lib/Socket/usync.d.ts +0 -36
- package/lib/Socket/usync.js +0 -70
- package/lib/Store/index.d.ts +0 -3
- package/lib/Store/index.js +0 -10
- package/lib/Store/make-cache-manager-store.d.ts +0 -13
- package/lib/Store/make-cache-manager-store.js +0 -83
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-in-memory-store.js +0 -427
- package/lib/Store/make-ordered-dictionary.d.ts +0 -13
- package/lib/Store/make-ordered-dictionary.js +0 -81
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Store/object-repository.js +0 -27
- package/lib/Utils/baileys-event-stream.d.ts +0 -16
- package/lib/Utils/baileys-event-stream.js +0 -63
package/lib/Utils/messages.js
CHANGED
|
@@ -1,816 +1,1238 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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 {
|
|
7
|
+
CALL_AUDIO_PREFIX,
|
|
8
|
+
CALL_VIDEO_PREFIX,
|
|
9
|
+
MEDIA_KEYS,
|
|
10
|
+
URL_REGEX,
|
|
11
|
+
WA_DEFAULT_EPHEMERAL,
|
|
12
|
+
} from "../Defaults/index.js";
|
|
13
|
+
import { WAMessageStatus, WAProto } from "../Types/index.js";
|
|
14
|
+
import {
|
|
15
|
+
isJidGroup,
|
|
16
|
+
isJidNewsletter,
|
|
17
|
+
isJidStatusBroadcast,
|
|
18
|
+
jidNormalizedUser,
|
|
19
|
+
} from "../WABinary/index.js";
|
|
20
|
+
import { sha256 } from "./crypto.js";
|
|
21
|
+
import {
|
|
22
|
+
generateMessageIDV2,
|
|
23
|
+
getKeyAuthor,
|
|
24
|
+
unixTimestampSeconds,
|
|
25
|
+
} from "./generics.js";
|
|
26
|
+
import {
|
|
27
|
+
downloadContentFromMessage,
|
|
28
|
+
encryptedStream,
|
|
29
|
+
generateThumbnail,
|
|
30
|
+
getAudioDuration,
|
|
31
|
+
getAudioWaveform,
|
|
32
|
+
getRawMediaUploadData,
|
|
33
|
+
} from "./messages-media.js";
|
|
34
|
+
import { shouldIncludeReportingToken } from "./reporting-utils.js";
|
|
18
35
|
const MIMETYPE_MAP = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
36
|
+
image: "image/jpeg",
|
|
37
|
+
video: "video/mp4",
|
|
38
|
+
document: "application/pdf",
|
|
39
|
+
audio: "audio/ogg; codecs=opus",
|
|
40
|
+
sticker: "image/webp",
|
|
41
|
+
"product-catalog-image": "image/jpeg",
|
|
25
42
|
};
|
|
26
43
|
const MessageTypeProto = {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
44
|
+
image: WAProto.Message.ImageMessage,
|
|
45
|
+
video: WAProto.Message.VideoMessage,
|
|
46
|
+
audio: WAProto.Message.AudioMessage,
|
|
47
|
+
sticker: WAProto.Message.StickerMessage,
|
|
48
|
+
document: WAProto.Message.DocumentMessage,
|
|
32
49
|
};
|
|
33
|
-
const ButtonType = WAProto_1.proto.Message.ButtonsMessage.HeaderType;
|
|
34
50
|
/**
|
|
35
51
|
* Uses a regex to test whether the string contains a URL, and returns the URL if it does.
|
|
36
52
|
* @param text eg. hello https://google.com
|
|
37
53
|
* @returns the URL, eg. https://google.com
|
|
38
54
|
*/
|
|
39
|
-
const extractUrlFromText = (text) =>
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
55
|
+
export const extractUrlFromText = (text) => text.match(URL_REGEX)?.[0];
|
|
56
|
+
export const generateLinkPreviewIfRequired = async (
|
|
57
|
+
text,
|
|
58
|
+
getUrlInfo,
|
|
59
|
+
logger,
|
|
60
|
+
) => {
|
|
61
|
+
const url = extractUrlFromText(text);
|
|
62
|
+
if (!!getUrlInfo && url) {
|
|
63
|
+
try {
|
|
64
|
+
const urlInfo = await getUrlInfo(url);
|
|
65
|
+
return urlInfo;
|
|
66
|
+
} catch (error) {
|
|
67
|
+
// ignore if fails
|
|
68
|
+
logger?.warn({ trace: error.stack }, "url generation failed");
|
|
51
69
|
}
|
|
70
|
+
}
|
|
52
71
|
};
|
|
53
|
-
exports.generateLinkPreviewIfRequired = generateLinkPreviewIfRequired;
|
|
54
72
|
const assertColor = async (color) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
hex = 'FF' + hex.padStart(6, '0');
|
|
63
|
-
}
|
|
64
|
-
assertedColor = parseInt(hex, 16);
|
|
65
|
-
return assertedColor;
|
|
73
|
+
let assertedColor;
|
|
74
|
+
if (typeof color === "number") {
|
|
75
|
+
assertedColor = color > 0 ? color : 0xffffffff + Number(color) + 1;
|
|
76
|
+
} else {
|
|
77
|
+
let hex = color.trim().replace("#", "");
|
|
78
|
+
if (hex.length <= 6) {
|
|
79
|
+
hex = "FF" + hex.padStart(6, "0");
|
|
66
80
|
}
|
|
81
|
+
assertedColor = parseInt(hex, 16);
|
|
82
|
+
return assertedColor;
|
|
83
|
+
}
|
|
67
84
|
};
|
|
68
|
-
const prepareWAMessageMedia = async (message, options) => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
85
|
+
export const prepareWAMessageMedia = async (message, options) => {
|
|
86
|
+
const logger = options.logger;
|
|
87
|
+
let mediaType;
|
|
88
|
+
for (const key of MEDIA_KEYS) {
|
|
89
|
+
if (key in message) {
|
|
90
|
+
mediaType = key;
|
|
75
91
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
92
|
+
}
|
|
93
|
+
if (!mediaType) {
|
|
94
|
+
throw new Boom("Invalid media type", { statusCode: 400 });
|
|
95
|
+
}
|
|
96
|
+
const uploadData = {
|
|
97
|
+
...message,
|
|
98
|
+
media: message[mediaType],
|
|
99
|
+
};
|
|
100
|
+
delete uploadData[mediaType];
|
|
101
|
+
// check if cacheable + generate cache key
|
|
102
|
+
const cacheableKey =
|
|
103
|
+
typeof uploadData.media === "object" &&
|
|
104
|
+
"url" in uploadData.media &&
|
|
105
|
+
!!uploadData.media.url &&
|
|
106
|
+
!!options.mediaCache &&
|
|
107
|
+
mediaType + ":" + uploadData.media.url.toString();
|
|
108
|
+
if (mediaType === "document" && !uploadData.fileName) {
|
|
109
|
+
uploadData.fileName = "file";
|
|
110
|
+
}
|
|
111
|
+
if (!uploadData.mimetype) {
|
|
112
|
+
uploadData.mimetype = MIMETYPE_MAP[mediaType];
|
|
113
|
+
}
|
|
114
|
+
if (cacheableKey) {
|
|
115
|
+
const mediaBuff = await options.mediaCache.get(cacheableKey);
|
|
116
|
+
if (mediaBuff) {
|
|
117
|
+
logger?.debug({ cacheableKey }, "got media cache hit");
|
|
118
|
+
const obj = proto.Message.decode(mediaBuff);
|
|
119
|
+
const key = `${mediaType}Message`;
|
|
120
|
+
Object.assign(obj[key], { ...uploadData, media: undefined });
|
|
121
|
+
return obj;
|
|
80
122
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
media: message[mediaType]
|
|
117
|
-
};
|
|
118
|
-
delete uploadData[mediaType];
|
|
119
|
-
const cacheableKey = typeof uploadData.media === 'object' &&
|
|
120
|
-
('url' in uploadData.media) &&
|
|
121
|
-
!!uploadData.media.url &&
|
|
122
|
-
!!options.mediaCache && (
|
|
123
|
-
mediaType + ':' + uploadData.media.url.toString());
|
|
124
|
-
|
|
125
|
-
if (mediaType === 'document' && !uploadData.fileName) {
|
|
126
|
-
uploadData.fileName = 'file';
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (!uploadData.mimetype) {
|
|
130
|
-
uploadData.mimetype = MIMETYPE_MAP[mediaType];
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (cacheableKey) {
|
|
134
|
-
const mediaBuff = options.mediaCache.get(cacheableKey);
|
|
135
|
-
if (mediaBuff) {
|
|
136
|
-
logger === null || logger === void 0 ? void 0 : logger.debug({ cacheableKey }, 'got media cache hit');
|
|
137
|
-
const obj = Types_1.WAProto.Message.decode(mediaBuff);
|
|
138
|
-
const key = `${mediaType}Message`;
|
|
139
|
-
Object.assign(obj[key], { ...uploadData, media: undefined });
|
|
140
|
-
return obj;
|
|
123
|
+
}
|
|
124
|
+
const isNewsletter = !!options.jid && isJidNewsletter(options.jid);
|
|
125
|
+
if (isNewsletter) {
|
|
126
|
+
logger?.info({ key: cacheableKey }, "Preparing raw media for newsletter");
|
|
127
|
+
const { filePath, fileSha256, fileLength } = await getRawMediaUploadData(
|
|
128
|
+
uploadData.media,
|
|
129
|
+
options.mediaTypeOverride || mediaType,
|
|
130
|
+
logger,
|
|
131
|
+
);
|
|
132
|
+
const requiresDurationComputation =
|
|
133
|
+
mediaType === "audio" && typeof uploadData.seconds === "undefined";
|
|
134
|
+
const requiresThumbnailComputation =
|
|
135
|
+
(mediaType === "image" || mediaType === "video") &&
|
|
136
|
+
typeof uploadData["jpegThumbnail"] === "undefined";
|
|
137
|
+
const requiresWaveformProcessing =
|
|
138
|
+
mediaType === "audio" &&
|
|
139
|
+
uploadData.ptt === true &&
|
|
140
|
+
typeof uploadData.waveform === "undefined";
|
|
141
|
+
const requiresAudioBackground =
|
|
142
|
+
options.backgroundColor &&
|
|
143
|
+
mediaType === "audio" &&
|
|
144
|
+
uploadData.ptt === true;
|
|
145
|
+
try {
|
|
146
|
+
if (requiresThumbnailComputation) {
|
|
147
|
+
const { thumbnail, originalImageDimensions } = await generateThumbnail(
|
|
148
|
+
filePath,
|
|
149
|
+
mediaType,
|
|
150
|
+
options,
|
|
151
|
+
);
|
|
152
|
+
uploadData.jpegThumbnail = thumbnail;
|
|
153
|
+
if (!uploadData.width && originalImageDimensions) {
|
|
154
|
+
uploadData.width = originalImageDimensions.width;
|
|
155
|
+
uploadData.height = originalImageDimensions.height;
|
|
156
|
+
logger?.debug("set dimensions");
|
|
141
157
|
}
|
|
158
|
+
logger?.debug("generated thumbnail");
|
|
159
|
+
}
|
|
160
|
+
if (requiresDurationComputation) {
|
|
161
|
+
uploadData.seconds = await getAudioDuration(filePath);
|
|
162
|
+
logger?.debug("computed audio duration");
|
|
163
|
+
}
|
|
164
|
+
if (requiresWaveformProcessing) {
|
|
165
|
+
uploadData.waveform = await getAudioWaveform(filePath, logger);
|
|
166
|
+
logger?.debug("processed waveform");
|
|
167
|
+
}
|
|
168
|
+
if (requiresAudioBackground) {
|
|
169
|
+
uploadData.backgroundArgb = await assertColor(options.backgroundColor);
|
|
170
|
+
logger?.debug("computed backgroundColor audio status");
|
|
171
|
+
}
|
|
172
|
+
} catch (error) {
|
|
173
|
+
logger?.warn({ trace: error.stack }, "failed to obtain extra info");
|
|
142
174
|
}
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation;
|
|
150
|
-
|
|
151
|
-
const { mediaKey, encWriteStream, bodyPath, fileEncSha256, fileSha256, fileLength, didSaveToTmpPath, opusConverted } = await (options.newsletter ? messages_media_1.prepareStream : messages_media_1.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
|
|
152
|
-
logger,
|
|
153
|
-
saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
|
|
154
|
-
opts: options.options,
|
|
155
|
-
isPtt: uploadData.ptt,
|
|
156
|
-
forceOpus: (mediaType === "audio" && uploadData.mimetype && uploadData.mimetype.includes('opus'))
|
|
175
|
+
const fileSha256B64 = fileSha256.toString("base64");
|
|
176
|
+
const { mediaUrl, directPath } = await options.upload(filePath, {
|
|
177
|
+
fileEncSha256B64: fileSha256B64,
|
|
178
|
+
mediaType: mediaType,
|
|
179
|
+
newsletter: true,
|
|
180
|
+
timeoutMs: options.mediaUploadTimeoutMs,
|
|
157
181
|
});
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return result;
|
|
170
|
-
})(),
|
|
171
|
-
(async () => {
|
|
172
|
-
try {
|
|
173
|
-
if (requiresThumbnailComputation) {
|
|
174
|
-
const { thumbnail, originalImageDimensions } = await (0, messages_media_1.generateThumbnail)(bodyPath, mediaType, options);
|
|
175
|
-
uploadData.jpegThumbnail = thumbnail;
|
|
176
|
-
if (!uploadData.width && originalImageDimensions) {
|
|
177
|
-
uploadData.width = originalImageDimensions.width;
|
|
178
|
-
uploadData.height = originalImageDimensions.height;
|
|
179
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('set dimensions');
|
|
180
|
-
}
|
|
181
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('generated thumbnail');
|
|
182
|
-
}
|
|
183
|
-
if (requiresDurationComputation) {
|
|
184
|
-
uploadData.seconds = await (0, messages_media_1.getAudioDuration)(bodyPath);
|
|
185
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('computed audio duration');
|
|
186
|
-
}
|
|
187
|
-
if (requiresWaveformProcessing) {
|
|
188
|
-
uploadData.waveform = await (0, messages_media_1.getAudioWaveform)(bodyPath, logger);
|
|
189
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('processed waveform');
|
|
190
|
-
}
|
|
191
|
-
if (requiresAudioBackground) {
|
|
192
|
-
uploadData.backgroundArgb = await assertColor(options.backgroundColor);
|
|
193
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('computed backgroundColor audio status');
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
catch (error) {
|
|
197
|
-
logger === null || logger === void 0 ? void 0 : logger.warn({ trace: error.stack }, 'failed to obtain extra info');
|
|
198
|
-
}
|
|
199
|
-
})(),
|
|
200
|
-
])
|
|
201
|
-
.finally(async () => {
|
|
202
|
-
if (!Buffer.isBuffer(encWriteStream)) {
|
|
203
|
-
encWriteStream.destroy();
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (didSaveToTmpPath && bodyPath) {
|
|
207
|
-
await fs_1.promises.unlink(bodyPath);
|
|
208
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('removed tmp files');
|
|
209
|
-
}
|
|
182
|
+
await fs.unlink(filePath);
|
|
183
|
+
const obj = WAProto.Message.fromObject({
|
|
184
|
+
[`${mediaType}Message`]: MessageTypeProto[mediaType].fromObject({
|
|
185
|
+
url: mediaUrl,
|
|
186
|
+
directPath,
|
|
187
|
+
fileSha256,
|
|
188
|
+
fileLength,
|
|
189
|
+
mediaKeyTimestamp: unixTimestampSeconds(),
|
|
190
|
+
...uploadData,
|
|
191
|
+
media: undefined,
|
|
192
|
+
}),
|
|
210
193
|
});
|
|
211
|
-
|
|
212
|
-
const obj = Types_1.WAProto.Message.fromObject({
|
|
213
|
-
[`${mediaType}Message`]: MessageTypeProto[mediaType].fromObject({
|
|
214
|
-
url: handle ? undefined : mediaUrl,
|
|
215
|
-
directPath,
|
|
216
|
-
mediaKey: mediaKey,
|
|
217
|
-
fileEncSha256: fileEncSha256,
|
|
218
|
-
fileSha256,
|
|
219
|
-
fileLength,
|
|
220
|
-
mediaKeyTimestamp: handle ? undefined : (0, generics_1.unixTimestampSeconds)(),
|
|
221
|
-
...uploadData,
|
|
222
|
-
media: undefined
|
|
223
|
-
})
|
|
224
|
-
});
|
|
225
|
-
|
|
226
194
|
if (uploadData.ptv) {
|
|
227
|
-
|
|
228
|
-
|
|
195
|
+
obj.ptvMessage = obj.videoMessage;
|
|
196
|
+
delete obj.videoMessage;
|
|
197
|
+
}
|
|
198
|
+
if (obj.stickerMessage) {
|
|
199
|
+
obj.stickerMessage.stickerSentTs = Date.now();
|
|
229
200
|
}
|
|
230
|
-
|
|
231
201
|
if (cacheableKey) {
|
|
232
|
-
|
|
233
|
-
|
|
202
|
+
logger?.debug({ cacheableKey }, "set cache");
|
|
203
|
+
await options.mediaCache.set(
|
|
204
|
+
cacheableKey,
|
|
205
|
+
WAProto.Message.encode(obj).finish(),
|
|
206
|
+
);
|
|
234
207
|
}
|
|
235
|
-
|
|
236
208
|
return obj;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
209
|
+
}
|
|
210
|
+
const requiresDurationComputation =
|
|
211
|
+
mediaType === "audio" && typeof uploadData.seconds === "undefined";
|
|
212
|
+
const requiresThumbnailComputation =
|
|
213
|
+
(mediaType === "image" || mediaType === "video") &&
|
|
214
|
+
typeof uploadData["jpegThumbnail"] === "undefined";
|
|
215
|
+
const requiresWaveformProcessing =
|
|
216
|
+
mediaType === "audio" &&
|
|
217
|
+
uploadData.ptt === true &&
|
|
218
|
+
typeof uploadData.waveform === "undefined";
|
|
219
|
+
const requiresAudioBackground =
|
|
220
|
+
options.backgroundColor && mediaType === "audio" && uploadData.ptt === true;
|
|
221
|
+
const requiresOriginalForSomeProcessing =
|
|
222
|
+
requiresDurationComputation ||
|
|
223
|
+
requiresThumbnailComputation ||
|
|
224
|
+
requiresWaveformProcessing;
|
|
225
|
+
const {
|
|
226
|
+
mediaKey,
|
|
227
|
+
encWriteStream,
|
|
228
|
+
bodyPath,
|
|
229
|
+
fileEncSha256,
|
|
230
|
+
fileSha256,
|
|
231
|
+
fileLength,
|
|
232
|
+
didSaveToTmpPath,
|
|
233
|
+
} = await encryptedStream(
|
|
234
|
+
uploadData.media,
|
|
235
|
+
options.mediaTypeOverride || mediaType,
|
|
236
|
+
{
|
|
237
|
+
logger,
|
|
238
|
+
saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
|
|
239
|
+
opts: options.options,
|
|
240
|
+
},
|
|
241
|
+
);
|
|
242
|
+
const fileEncSha256B64 = fileEncSha256.toString("base64");
|
|
243
|
+
const [{ mediaUrl, directPath }] = await Promise.all([
|
|
244
|
+
(async () => {
|
|
245
|
+
const result = await options.upload(encWriteStream, {
|
|
246
|
+
fileEncSha256B64,
|
|
247
|
+
mediaType,
|
|
248
|
+
timeoutMs: options.mediaUploadTimeoutMs,
|
|
249
|
+
});
|
|
250
|
+
logger?.debug({ mediaType, cacheableKey }, "uploaded media");
|
|
251
|
+
return result;
|
|
252
|
+
})(),
|
|
253
|
+
(async () => {
|
|
254
|
+
try {
|
|
255
|
+
if (requiresThumbnailComputation) {
|
|
256
|
+
const { thumbnail, originalImageDimensions } =
|
|
257
|
+
await generateThumbnail(bodyPath, mediaType, options);
|
|
258
|
+
uploadData.jpegThumbnail = thumbnail;
|
|
259
|
+
if (!uploadData.width && originalImageDimensions) {
|
|
260
|
+
uploadData.width = originalImageDimensions.width;
|
|
261
|
+
uploadData.height = originalImageDimensions.height;
|
|
262
|
+
logger?.debug("set dimensions");
|
|
263
|
+
}
|
|
264
|
+
logger?.debug("generated thumbnail");
|
|
265
|
+
}
|
|
266
|
+
if (requiresDurationComputation) {
|
|
267
|
+
try {
|
|
268
|
+
if (bodyPath) {
|
|
269
|
+
uploadData.seconds = await getAudioDuration(bodyPath);
|
|
248
270
|
}
|
|
271
|
+
} catch (err) {
|
|
272
|
+
uploadData.seconds = 0;
|
|
273
|
+
}
|
|
274
|
+
if (
|
|
275
|
+
typeof uploadData.seconds !== "number" ||
|
|
276
|
+
isNaN(uploadData.seconds)
|
|
277
|
+
) {
|
|
278
|
+
uploadData.seconds = 0;
|
|
279
|
+
}
|
|
280
|
+
logger?.debug("computed audio duration");
|
|
249
281
|
}
|
|
250
|
-
|
|
251
|
-
|
|
282
|
+
if (requiresWaveformProcessing) {
|
|
283
|
+
try {
|
|
284
|
+
uploadData.waveform = await getAudioWaveform(bodyPath, logger);
|
|
285
|
+
} catch (err) {}
|
|
286
|
+
if (!uploadData.waveform) {
|
|
287
|
+
uploadData.waveform = new Uint8Array([
|
|
288
|
+
0, 99, 0, 99, 0, 99, 0, 99, 88, 99, 0, 99, 0, 55, 0, 99, 0, 99, 0,
|
|
289
|
+
99, 0, 99, 0, 99, 88, 99, 0, 99, 0, 55, 0, 99,
|
|
290
|
+
]);
|
|
291
|
+
}
|
|
292
|
+
logger?.debug("processed waveform");
|
|
293
|
+
}
|
|
294
|
+
if (requiresAudioBackground) {
|
|
295
|
+
uploadData.backgroundArgb = await assertColor(
|
|
296
|
+
options.backgroundColor,
|
|
297
|
+
);
|
|
298
|
+
logger?.debug("computed backgroundColor audio status");
|
|
299
|
+
}
|
|
300
|
+
} catch (error) {
|
|
301
|
+
logger?.warn({ trace: error.stack }, "failed to obtain extra info");
|
|
302
|
+
}
|
|
303
|
+
})(),
|
|
304
|
+
]).finally(async () => {
|
|
305
|
+
try {
|
|
306
|
+
if (!Buffer.isBuffer(encWriteStream)) {
|
|
307
|
+
encWriteStream.destroy?.();
|
|
308
|
+
}
|
|
309
|
+
if (didSaveToTmpPath && bodyPath) {
|
|
310
|
+
await fs.unlink(bodyPath).catch(() => {});
|
|
311
|
+
}
|
|
312
|
+
} catch (error) {
|
|
313
|
+
logger?.warn("failed to remove tmp file");
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
const obj = WAProto.Message.fromObject({
|
|
317
|
+
[`${mediaType}Message`]: MessageTypeProto[mediaType].fromObject({
|
|
318
|
+
url: mediaUrl,
|
|
319
|
+
directPath,
|
|
320
|
+
mediaKey,
|
|
321
|
+
fileEncSha256,
|
|
322
|
+
fileSha256,
|
|
323
|
+
fileLength,
|
|
324
|
+
mediaKeyTimestamp: unixTimestampSeconds(),
|
|
325
|
+
...uploadData,
|
|
326
|
+
media: undefined,
|
|
327
|
+
}),
|
|
328
|
+
});
|
|
329
|
+
if (uploadData.ptv) {
|
|
330
|
+
obj.ptvMessage = obj.videoMessage;
|
|
331
|
+
delete obj.videoMessage;
|
|
332
|
+
}
|
|
333
|
+
if (obj.stickerMessage) {
|
|
334
|
+
obj.stickerMessage.stickerSentTs = Date.now();
|
|
335
|
+
}
|
|
336
|
+
if (cacheableKey) {
|
|
337
|
+
logger?.debug({ cacheableKey }, "set cache");
|
|
338
|
+
await options.mediaCache.set(
|
|
339
|
+
cacheableKey,
|
|
340
|
+
WAProto.Message.encode(obj).finish(),
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
return obj;
|
|
344
|
+
};
|
|
345
|
+
export const prepareDisappearingMessageSettingContent = (
|
|
346
|
+
ephemeralExpiration,
|
|
347
|
+
) => {
|
|
348
|
+
ephemeralExpiration = ephemeralExpiration || 0;
|
|
349
|
+
const content = {
|
|
350
|
+
ephemeralMessage: {
|
|
351
|
+
message: {
|
|
352
|
+
protocolMessage: {
|
|
353
|
+
type: WAProto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING,
|
|
354
|
+
ephemeralExpiration,
|
|
355
|
+
},
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
};
|
|
359
|
+
return WAProto.Message.fromObject(content);
|
|
252
360
|
};
|
|
253
|
-
exports.prepareDisappearingMessageSettingContent = prepareDisappearingMessageSettingContent;
|
|
254
361
|
/**
|
|
255
362
|
* Generate forwarded message content like WA does
|
|
256
363
|
* @param message the message to forward
|
|
257
364
|
* @param options.forceForward will show the message as forwarded even if it is from you
|
|
258
365
|
*/
|
|
259
|
-
const generateForwardMessageContent = (message, forceForward) => {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
return content;
|
|
366
|
+
export const generateForwardMessageContent = (message, forceForward) => {
|
|
367
|
+
let content = message.message;
|
|
368
|
+
if (!content) {
|
|
369
|
+
throw new Boom("no content in message", { statusCode: 400 });
|
|
370
|
+
}
|
|
371
|
+
// hacky copy
|
|
372
|
+
content = normalizeMessageContent(content);
|
|
373
|
+
content = proto.Message.decode(proto.Message.encode(content).finish());
|
|
374
|
+
let key = Object.keys(content)[0];
|
|
375
|
+
let score = content?.[key]?.contextInfo?.forwardingScore || 0;
|
|
376
|
+
score += message.key.fromMe && !forceForward ? 0 : 1;
|
|
377
|
+
if (key === "conversation") {
|
|
378
|
+
content.extendedTextMessage = { text: content[key] };
|
|
379
|
+
delete content.conversation;
|
|
380
|
+
key = "extendedTextMessage";
|
|
381
|
+
}
|
|
382
|
+
const key_ = content?.[key];
|
|
383
|
+
if (score > 0) {
|
|
384
|
+
key_.contextInfo = { forwardingScore: score, isForwarded: true };
|
|
385
|
+
} else {
|
|
386
|
+
key_.contextInfo = {};
|
|
387
|
+
}
|
|
388
|
+
return content;
|
|
283
389
|
};
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
extContent.thumbnailEncSha256 = img.fileEncSha256;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
if (options.backgroundColor) {
|
|
314
|
-
extContent.backgroundArgb = await assertColor(options.backgroundColor);
|
|
315
|
-
}
|
|
316
|
-
if (options.font) {
|
|
317
|
-
extContent.font = options.font;
|
|
318
|
-
}
|
|
319
|
-
m.extendedTextMessage = extContent;
|
|
390
|
+
export const hasNonNullishProperty = (message, key) => {
|
|
391
|
+
return (
|
|
392
|
+
typeof message === "object" &&
|
|
393
|
+
message !== null &&
|
|
394
|
+
key in message &&
|
|
395
|
+
message[key] !== null &&
|
|
396
|
+
message[key] !== undefined
|
|
397
|
+
);
|
|
398
|
+
};
|
|
399
|
+
function hasOptionalProperty(obj, key) {
|
|
400
|
+
return (
|
|
401
|
+
typeof obj === "object" && obj !== null && key in obj && obj[key] !== null
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
export const generateWAMessageContent = async (message, options) => {
|
|
405
|
+
var _a, _b;
|
|
406
|
+
let m = {};
|
|
407
|
+
if (hasNonNullishProperty(message, "text")) {
|
|
408
|
+
const extContent = { text: message.text };
|
|
409
|
+
let urlInfo = message.linkPreview;
|
|
410
|
+
if (typeof urlInfo === "undefined") {
|
|
411
|
+
urlInfo = await generateLinkPreviewIfRequired(
|
|
412
|
+
message.text,
|
|
413
|
+
options.getUrlInfo,
|
|
414
|
+
options.logger,
|
|
415
|
+
);
|
|
320
416
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
417
|
+
if (urlInfo) {
|
|
418
|
+
extContent.matchedText = urlInfo["matched-text"];
|
|
419
|
+
extContent.jpegThumbnail = urlInfo.jpegThumbnail;
|
|
420
|
+
extContent.description = urlInfo.description;
|
|
421
|
+
extContent.title = urlInfo.title;
|
|
422
|
+
extContent.previewType = 0;
|
|
423
|
+
const img = urlInfo.highQualityThumbnail;
|
|
424
|
+
if (img) {
|
|
425
|
+
extContent.thumbnailDirectPath = img.directPath;
|
|
426
|
+
extContent.mediaKey = img.mediaKey;
|
|
427
|
+
extContent.mediaKeyTimestamp = img.mediaKeyTimestamp;
|
|
428
|
+
extContent.thumbnailWidth = img.width;
|
|
429
|
+
extContent.thumbnailHeight = img.height;
|
|
430
|
+
extContent.thumbnailSha256 = img.fileSha256;
|
|
431
|
+
extContent.thumbnailEncSha256 = img.fileEncSha256;
|
|
432
|
+
}
|
|
332
433
|
}
|
|
333
|
-
|
|
334
|
-
|
|
434
|
+
if (options.backgroundColor) {
|
|
435
|
+
extContent.backgroundArgb = await assertColor(options.backgroundColor);
|
|
335
436
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
message.react.senderTimestampMs = Date.now();
|
|
339
|
-
}
|
|
340
|
-
m.reactionMessage = Types_1.WAProto.Message.ReactionMessage.fromObject(message.react);
|
|
437
|
+
if (options.textColor) {
|
|
438
|
+
extContent.textArgb = await assertColor(options.textColor);
|
|
341
439
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
key: message.delete,
|
|
345
|
-
type: Types_1.WAProto.Message.ProtocolMessage.Type.REVOKE
|
|
346
|
-
};
|
|
440
|
+
if (options.font) {
|
|
441
|
+
extContent.font = options.font;
|
|
347
442
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
(message.disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
|
|
354
|
-
message.disappearingMessagesInChat;
|
|
355
|
-
m = (0, exports.prepareDisappearingMessageSettingContent)(exp);
|
|
356
|
-
}
|
|
357
|
-
else if ('buttonReply' in message) {
|
|
358
|
-
switch (message.type) {
|
|
359
|
-
case 'template':
|
|
360
|
-
m.templateButtonReplyMessage = {
|
|
361
|
-
selectedDisplayText: message.buttonReply.displayText,
|
|
362
|
-
selectedId: message.buttonReply.id,
|
|
363
|
-
selectedIndex: message.buttonReply.index,
|
|
364
|
-
};
|
|
365
|
-
break;
|
|
366
|
-
case 'plain':
|
|
367
|
-
m.buttonsResponseMessage = {
|
|
368
|
-
selectedButtonId: message.buttonReply.id,
|
|
369
|
-
selectedDisplayText: message.buttonReply.displayText,
|
|
370
|
-
type: WAProto_1.proto.Message.ButtonsResponseMessage.Type.DISPLAY_TEXT,
|
|
371
|
-
};
|
|
372
|
-
break;
|
|
373
|
-
}
|
|
443
|
+
m.extendedTextMessage = extContent;
|
|
444
|
+
} else if (hasNonNullishProperty(message, "contacts")) {
|
|
445
|
+
const contactLen = message.contacts.contacts.length;
|
|
446
|
+
if (!contactLen) {
|
|
447
|
+
throw new Boom("require atleast 1 contact", { statusCode: 400 });
|
|
374
448
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
});
|
|
449
|
+
if (contactLen === 1) {
|
|
450
|
+
m.contactMessage = WAProto.Message.ContactMessage.create(
|
|
451
|
+
message.contacts.contacts[0],
|
|
452
|
+
);
|
|
453
|
+
} else {
|
|
454
|
+
m.contactsArrayMessage = WAProto.Message.ContactsArrayMessage.create(
|
|
455
|
+
message.contacts,
|
|
456
|
+
);
|
|
384
457
|
}
|
|
385
|
-
|
|
386
|
-
|
|
458
|
+
} else if (hasNonNullishProperty(message, "location")) {
|
|
459
|
+
m.locationMessage = WAProto.Message.LocationMessage.create(
|
|
460
|
+
message.location,
|
|
461
|
+
);
|
|
462
|
+
} else if (hasNonNullishProperty(message, "react")) {
|
|
463
|
+
if (!message.react.senderTimestampMs) {
|
|
464
|
+
message.react.senderTimestampMs = Date.now();
|
|
387
465
|
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
466
|
+
m.reactionMessage = WAProto.Message.ReactionMessage.create(message.react);
|
|
467
|
+
} else if (hasNonNullishProperty(message, "delete")) {
|
|
468
|
+
m.protocolMessage = {
|
|
469
|
+
key: message.delete,
|
|
470
|
+
type: WAProto.Message.ProtocolMessage.Type.REVOKE,
|
|
471
|
+
};
|
|
472
|
+
} else if (hasNonNullishProperty(message, "forward")) {
|
|
473
|
+
m = generateForwardMessageContent(message.forward, message.force);
|
|
474
|
+
} else if (hasNonNullishProperty(message, "disappearingMessagesInChat")) {
|
|
475
|
+
const exp =
|
|
476
|
+
typeof message.disappearingMessagesInChat === "boolean"
|
|
477
|
+
? message.disappearingMessagesInChat
|
|
478
|
+
? WA_DEFAULT_EPHEMERAL
|
|
479
|
+
: 0
|
|
480
|
+
: message.disappearingMessagesInChat;
|
|
481
|
+
m = prepareDisappearingMessageSettingContent(exp);
|
|
482
|
+
} else if (hasNonNullishProperty(message, "groupInvite")) {
|
|
483
|
+
m.groupInviteMessage = {};
|
|
484
|
+
m.groupInviteMessage.inviteCode = message.groupInvite.inviteCode;
|
|
485
|
+
m.groupInviteMessage.inviteExpiration =
|
|
486
|
+
message.groupInvite.inviteExpiration;
|
|
487
|
+
m.groupInviteMessage.caption = message.groupInvite.text;
|
|
488
|
+
m.groupInviteMessage.groupJid = message.groupInvite.jid;
|
|
489
|
+
m.groupInviteMessage.groupName = message.groupInvite.subject;
|
|
490
|
+
//TODO: use built-in interface and get disappearing mode info etc.
|
|
491
|
+
//TODO: cache / use store!?
|
|
492
|
+
if (options.getProfilePicUrl) {
|
|
493
|
+
const pfpUrl = await options.getProfilePicUrl(
|
|
494
|
+
message.groupInvite.jid,
|
|
495
|
+
"preview",
|
|
496
|
+
);
|
|
497
|
+
if (pfpUrl) {
|
|
498
|
+
const resp = await fetch(pfpUrl, {
|
|
499
|
+
method: "GET",
|
|
500
|
+
dispatcher: options?.options?.dispatcher,
|
|
501
|
+
});
|
|
502
|
+
if (resp.ok) {
|
|
503
|
+
const buf = Buffer.from(await resp.arrayBuffer());
|
|
504
|
+
m.groupInviteMessage.jpegThumbnail = buf;
|
|
396
505
|
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
} else if (hasNonNullishProperty(message, "pin")) {
|
|
509
|
+
m.pinInChatMessage = {};
|
|
510
|
+
m.messageContextInfo = {};
|
|
511
|
+
m.pinInChatMessage.key = message.pin;
|
|
512
|
+
m.pinInChatMessage.type = message.type;
|
|
513
|
+
m.pinInChatMessage.senderTimestampMs = Date.now();
|
|
514
|
+
m.messageContextInfo.messageAddOnDurationInSecs =
|
|
515
|
+
message.type === 1 ? message.time || 86400 : 0;
|
|
516
|
+
} else if (hasNonNullishProperty(message, "buttonReply")) {
|
|
517
|
+
switch (message.type) {
|
|
518
|
+
case "template":
|
|
519
|
+
m.templateButtonReplyMessage = {
|
|
520
|
+
selectedDisplayText: message.buttonReply.displayText,
|
|
521
|
+
selectedId: message.buttonReply.id,
|
|
522
|
+
selectedIndex: message.buttonReply.index,
|
|
400
523
|
};
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
524
|
+
break;
|
|
525
|
+
case "plain":
|
|
526
|
+
m.buttonsResponseMessage = {
|
|
527
|
+
selectedButtonId: message.buttonReply.id,
|
|
528
|
+
selectedDisplayText: message.buttonReply.displayText,
|
|
529
|
+
type: proto.Message.ButtonsResponseMessage.Type.DISPLAY_TEXT,
|
|
405
530
|
};
|
|
531
|
+
break;
|
|
406
532
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
533
|
+
} else if (hasOptionalProperty(message, "ptv") && message.ptv) {
|
|
534
|
+
const { videoMessage } = await prepareWAMessageMedia(
|
|
535
|
+
{ video: message.video },
|
|
536
|
+
options,
|
|
537
|
+
);
|
|
538
|
+
m.ptvMessage = videoMessage;
|
|
539
|
+
} else if (hasNonNullishProperty(message, "product")) {
|
|
540
|
+
const { imageMessage } = await prepareWAMessageMedia(
|
|
541
|
+
{ image: message.product.productImage },
|
|
542
|
+
options,
|
|
543
|
+
);
|
|
544
|
+
m.productMessage = WAProto.Message.ProductMessage.create({
|
|
545
|
+
...message,
|
|
546
|
+
product: {
|
|
547
|
+
...message.product,
|
|
548
|
+
productImage: imageMessage,
|
|
549
|
+
},
|
|
550
|
+
});
|
|
551
|
+
} else if (hasNonNullishProperty(message, "listReply")) {
|
|
552
|
+
m.listResponseMessage = { ...message.listReply };
|
|
553
|
+
} else if (hasNonNullishProperty(message, "event")) {
|
|
554
|
+
m.eventMessage = {};
|
|
555
|
+
const startTime = Math.floor(message.event.startDate.getTime() / 1000);
|
|
556
|
+
if (message.event.call && options.getCallLink) {
|
|
557
|
+
const token = await options.getCallLink(message.event.call, {
|
|
558
|
+
startTime,
|
|
559
|
+
});
|
|
560
|
+
m.eventMessage.joinLink =
|
|
561
|
+
(message.event.call === "audio"
|
|
562
|
+
? CALL_AUDIO_PREFIX
|
|
563
|
+
: CALL_VIDEO_PREFIX) + token;
|
|
411
564
|
}
|
|
412
|
-
|
|
413
|
-
|
|
565
|
+
m.messageContextInfo = {
|
|
566
|
+
// encKey
|
|
567
|
+
messageSecret: message.event.messageSecret || randomBytes(32),
|
|
568
|
+
};
|
|
569
|
+
m.eventMessage.name = message.event.name;
|
|
570
|
+
m.eventMessage.description = message.event.description;
|
|
571
|
+
m.eventMessage.startTime = startTime;
|
|
572
|
+
m.eventMessage.endTime = message.event.endDate
|
|
573
|
+
? message.event.endDate.getTime() / 1000
|
|
574
|
+
: undefined;
|
|
575
|
+
m.eventMessage.isCanceled = message.event.isCancelled ?? false;
|
|
576
|
+
m.eventMessage.extraGuestsAllowed = message.event.extraGuestsAllowed;
|
|
577
|
+
m.eventMessage.isScheduleCall = message.event.isScheduleCall ?? false;
|
|
578
|
+
m.eventMessage.location = message.event.location;
|
|
579
|
+
} else if (hasNonNullishProperty(message, "poll")) {
|
|
580
|
+
(_a = message.poll).selectableCount || (_a.selectableCount = 0);
|
|
581
|
+
(_b = message.poll).toAnnouncementGroup || (_b.toAnnouncementGroup = false);
|
|
582
|
+
if (!Array.isArray(message.poll.values)) {
|
|
583
|
+
throw new Boom("Invalid poll values", { statusCode: 400 });
|
|
414
584
|
}
|
|
415
|
-
|
|
416
|
-
|
|
585
|
+
if (
|
|
586
|
+
message.poll.selectableCount < 0 ||
|
|
587
|
+
message.poll.selectableCount > message.poll.values.length
|
|
588
|
+
) {
|
|
589
|
+
throw new Boom(
|
|
590
|
+
`poll.selectableCount in poll should be >= 0 and <= ${message.poll.values.length}`,
|
|
591
|
+
{
|
|
592
|
+
statusCode: 400,
|
|
593
|
+
},
|
|
594
|
+
);
|
|
417
595
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
596
|
+
m.messageContextInfo = {
|
|
597
|
+
// encKey
|
|
598
|
+
messageSecret: message.poll.messageSecret || randomBytes(32),
|
|
599
|
+
};
|
|
600
|
+
const pollCreationMessage = {
|
|
601
|
+
name: message.poll.name,
|
|
602
|
+
selectableOptionsCount: message.poll.selectableCount,
|
|
603
|
+
options: message.poll.values.map((optionName) => ({ optionName })),
|
|
604
|
+
};
|
|
605
|
+
if (message.poll.toAnnouncementGroup) {
|
|
606
|
+
// poll v2 is for community announcement groups (single select and multiple)
|
|
607
|
+
m.pollCreationMessageV2 = pollCreationMessage;
|
|
608
|
+
} else {
|
|
609
|
+
if (message.poll.selectableCount === 1) {
|
|
610
|
+
//poll v3 is for single select polls
|
|
611
|
+
m.pollCreationMessageV3 = pollCreationMessage;
|
|
612
|
+
} else {
|
|
613
|
+
// poll for multiple choice polls
|
|
614
|
+
m.pollCreationMessage = pollCreationMessage;
|
|
615
|
+
}
|
|
438
616
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
617
|
+
} else if (hasNonNullishProperty(message, "sharePhoneNumber")) {
|
|
618
|
+
m.protocolMessage = {
|
|
619
|
+
type: proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER,
|
|
620
|
+
};
|
|
621
|
+
} else if (hasNonNullishProperty(message, "requestPhoneNumber")) {
|
|
622
|
+
m.requestPhoneNumberMessage = {};
|
|
623
|
+
} else if (hasNonNullishProperty(message, "limitSharing")) {
|
|
624
|
+
m.protocolMessage = {
|
|
625
|
+
type: proto.Message.ProtocolMessage.Type.LIMIT_SHARING,
|
|
626
|
+
limitSharing: {
|
|
627
|
+
sharingLimited: message.limitSharing === true,
|
|
628
|
+
trigger: 1,
|
|
629
|
+
limitSharingSettingTimestamp: Date.now(),
|
|
630
|
+
initiatedByMe: true,
|
|
631
|
+
},
|
|
632
|
+
};
|
|
633
|
+
} else if (hasNonNullishProperty(message, "stickerPack")) {
|
|
634
|
+
const { zip } = await import("fflate").then((m) => m);
|
|
635
|
+
const { stickers, cover, name, publisher, packId, description } =
|
|
636
|
+
message.stickerPack;
|
|
637
|
+
if (!stickers?.length)
|
|
638
|
+
throw new Boom("Sticker pack must contain at least one sticker", {
|
|
639
|
+
statusCode: 400,
|
|
640
|
+
});
|
|
641
|
+
if (stickers.length > 60)
|
|
642
|
+
throw new Boom("Sticker pack exceeds the maximum limit of 60 stickers", {
|
|
643
|
+
statusCode: 400,
|
|
644
|
+
});
|
|
645
|
+
const stickerPackId = packId || generateMessageIDV2();
|
|
646
|
+
const [_sharp] = await Promise.all([import("sharp").catch(() => null)]);
|
|
647
|
+
if (!_sharp)
|
|
648
|
+
throw new Boom("sharp is required for sticker pack generation");
|
|
649
|
+
const sharpLib = _sharp.default || _sharp;
|
|
650
|
+
const isWebP = (buf) =>
|
|
651
|
+
buf.length >= 12 &&
|
|
652
|
+
buf[0] === 0x52 &&
|
|
653
|
+
buf[1] === 0x49 &&
|
|
654
|
+
buf[2] === 0x46 &&
|
|
655
|
+
buf[3] === 0x46 &&
|
|
656
|
+
buf[8] === 0x57 &&
|
|
657
|
+
buf[9] === 0x45 &&
|
|
658
|
+
buf[10] === 0x42 &&
|
|
659
|
+
buf[11] === 0x50;
|
|
660
|
+
const isAnimatedWebP = (buf) => {
|
|
661
|
+
if (!isWebP(buf)) return false;
|
|
662
|
+
let o = 12;
|
|
663
|
+
while (o < buf.length - 8) {
|
|
664
|
+
const tag = buf.toString("ascii", o, o + 4);
|
|
665
|
+
const sz = buf.readUInt32LE(o + 4);
|
|
666
|
+
if (tag === "VP8X" && buf[o + 8] & 0x02) return true;
|
|
667
|
+
if (tag === "ANIM" || tag === "ANMF") return true;
|
|
668
|
+
o += 8 + sz + (sz % 2);
|
|
669
|
+
}
|
|
670
|
+
return false;
|
|
671
|
+
};
|
|
672
|
+
const { Readable } = await import("stream");
|
|
673
|
+
const toReadable = (buf) => {
|
|
674
|
+
const r = new Readable({ read: () => {} });
|
|
675
|
+
r.push(buf);
|
|
676
|
+
r.push(null);
|
|
677
|
+
return r;
|
|
678
|
+
};
|
|
679
|
+
const toBuffer = async (stream) => {
|
|
680
|
+
const c = [];
|
|
681
|
+
for await (const ch of stream) c.push(ch);
|
|
682
|
+
return Buffer.concat(c);
|
|
683
|
+
};
|
|
684
|
+
const getStreamBuf = async (item) => {
|
|
685
|
+
if (Buffer.isBuffer(item)) return item;
|
|
686
|
+
if (item?.stream) return toBuffer(item.stream);
|
|
687
|
+
const u = item?.url?.toString?.() || item?.url;
|
|
688
|
+
if (u?.startsWith("data:")) return Buffer.from(u.split(",")[1], "base64");
|
|
689
|
+
const resp = await fetch(u);
|
|
690
|
+
return Buffer.from(await resp.arrayBuffer());
|
|
691
|
+
};
|
|
692
|
+
const zipData = {};
|
|
693
|
+
const stickerMeta = await Promise.all(
|
|
694
|
+
stickers.map(async (s, i) => {
|
|
695
|
+
const raw = await getStreamBuf(s.data || s.sticker);
|
|
696
|
+
let webp;
|
|
697
|
+
let animated = false;
|
|
698
|
+
if (isWebP(raw)) {
|
|
699
|
+
webp = raw;
|
|
700
|
+
animated = isAnimatedWebP(raw);
|
|
701
|
+
} else {
|
|
702
|
+
webp = await sharpLib(raw).webp().toBuffer();
|
|
454
703
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
704
|
+
if (webp.length > 1024 * 1024)
|
|
705
|
+
throw new Boom(`Sticker ${i} exceeds 1MB`);
|
|
706
|
+
const hash = sha256(webp).toString("base64").replace(/\//g, "-");
|
|
707
|
+
const fname = `${hash}.webp`;
|
|
708
|
+
zipData[fname] = [new Uint8Array(webp), { level: 0 }];
|
|
709
|
+
return {
|
|
710
|
+
fileName: fname,
|
|
711
|
+
mimetype: "image/webp",
|
|
712
|
+
isAnimated: animated,
|
|
713
|
+
emojis: s.emojis || [],
|
|
714
|
+
accessibilityLabel: s.accessibilityLabel || "",
|
|
460
715
|
};
|
|
716
|
+
}),
|
|
717
|
+
);
|
|
718
|
+
const coverRaw = await getStreamBuf(cover);
|
|
719
|
+
const coverWebp = isWebP(coverRaw)
|
|
720
|
+
? coverRaw
|
|
721
|
+
: await sharpLib(coverRaw).webp().toBuffer();
|
|
722
|
+
const trayIconFileName = `${stickerPackId}.webp`;
|
|
723
|
+
zipData[trayIconFileName] = [new Uint8Array(coverWebp), { level: 0 }];
|
|
724
|
+
const zipBuffer = await new Promise((res, rej) =>
|
|
725
|
+
zip(zipData, (e, d) => (e ? rej(e) : res(Buffer.from(d)))),
|
|
726
|
+
);
|
|
727
|
+
const stickerPackUpload = await encryptedStream(zipBuffer, "sticker-pack", {
|
|
728
|
+
logger: options.logger,
|
|
729
|
+
opts: options.options,
|
|
730
|
+
});
|
|
731
|
+
const stickerPackResult = await options.upload(
|
|
732
|
+
stickerPackUpload.encWriteStream,
|
|
733
|
+
{
|
|
734
|
+
fileEncSha256B64: stickerPackUpload.fileEncSha256.toString("base64"),
|
|
735
|
+
mediaType: "sticker-pack",
|
|
736
|
+
timeoutMs: options.mediaUploadTimeoutMs,
|
|
737
|
+
},
|
|
738
|
+
);
|
|
739
|
+
m.stickerPackMessage = {
|
|
740
|
+
name,
|
|
741
|
+
publisher,
|
|
742
|
+
stickerPackId,
|
|
743
|
+
packDescription: description,
|
|
744
|
+
stickerPackOrigin:
|
|
745
|
+
WAProto.Message.StickerPackMessage.StickerPackOrigin.THIRD_PARTY,
|
|
746
|
+
stickerPackSize: zipBuffer.length,
|
|
747
|
+
stickers: stickerMeta,
|
|
748
|
+
fileSha256: stickerPackUpload.fileSha256,
|
|
749
|
+
fileEncSha256: stickerPackUpload.fileEncSha256,
|
|
750
|
+
mediaKey: stickerPackUpload.mediaKey,
|
|
751
|
+
directPath: stickerPackResult.directPath,
|
|
752
|
+
fileLength: stickerPackUpload.fileLength,
|
|
753
|
+
mediaKeyTimestamp: unixTimestampSeconds(),
|
|
754
|
+
trayIconFileName,
|
|
755
|
+
};
|
|
756
|
+
try {
|
|
757
|
+
const thumbBuf = await sharpLib(coverRaw)
|
|
758
|
+
.resize(252, 252)
|
|
759
|
+
.jpeg()
|
|
760
|
+
.toBuffer();
|
|
761
|
+
const thumbUpload = await encryptedStream(
|
|
762
|
+
thumbBuf,
|
|
763
|
+
"thumbnail-sticker-pack",
|
|
764
|
+
{
|
|
765
|
+
logger: options.logger,
|
|
766
|
+
opts: options.options,
|
|
767
|
+
mediaKey: stickerPackUpload.mediaKey,
|
|
768
|
+
},
|
|
769
|
+
);
|
|
770
|
+
const thumbResult = await options.upload(thumbUpload.encWriteStream, {
|
|
771
|
+
fileEncSha256B64: thumbUpload.fileEncSha256.toString("base64"),
|
|
772
|
+
mediaType: "thumbnail-sticker-pack",
|
|
773
|
+
timeoutMs: options.mediaUploadTimeoutMs,
|
|
774
|
+
});
|
|
775
|
+
Object.assign(m.stickerPackMessage, {
|
|
776
|
+
thumbnailDirectPath: thumbResult.directPath,
|
|
777
|
+
thumbnailSha256: thumbUpload.fileSha256,
|
|
778
|
+
thumbnailEncSha256: thumbUpload.fileEncSha256,
|
|
779
|
+
thumbnailHeight: 252,
|
|
780
|
+
thumbnailWidth: 252,
|
|
781
|
+
imageDataHash: sha256(thumbBuf).toString("base64"),
|
|
782
|
+
});
|
|
783
|
+
} catch (e) {
|
|
784
|
+
options.logger?.warn?.(`Sticker pack thumbnail failed: ${e?.message}`);
|
|
461
785
|
}
|
|
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
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
786
|
+
m.stickerPackMessage.contextInfo = {
|
|
787
|
+
...(message.contextInfo || {}),
|
|
788
|
+
...(message.mentions ? { mentionedJid: message.mentions } : {}),
|
|
789
|
+
};
|
|
790
|
+
} else {
|
|
791
|
+
m = await prepareWAMessageMedia(message, options);
|
|
792
|
+
}
|
|
793
|
+
if (hasOptionalProperty(message, "viewOnce") && !!message.viewOnce) {
|
|
794
|
+
m = { viewOnceMessage: { message: m } };
|
|
795
|
+
}
|
|
796
|
+
if (
|
|
797
|
+
(hasOptionalProperty(message, "mentions") && message.mentions?.length) ||
|
|
798
|
+
(hasOptionalProperty(message, "mentionAll") && message.mentionAll)
|
|
799
|
+
) {
|
|
800
|
+
const messageType = Object.keys(m)[0];
|
|
801
|
+
const key = m[messageType];
|
|
802
|
+
if (key && "contextInfo" in key) {
|
|
803
|
+
key.contextInfo = key.contextInfo || {};
|
|
804
|
+
if (message.mentions?.length) {
|
|
805
|
+
key.contextInfo.mentionedJid = message.mentions;
|
|
806
|
+
}
|
|
807
|
+
if (message.mentionAll) {
|
|
808
|
+
key.contextInfo.nonJidMentions = 1;
|
|
809
|
+
}
|
|
810
|
+
} else if (key) {
|
|
811
|
+
key.contextInfo = {
|
|
812
|
+
mentionedJid: message.mentions,
|
|
813
|
+
nonJidMentions: message.mentionAll ? 1 : 0,
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
if (hasOptionalProperty(message, "edit")) {
|
|
818
|
+
m = {
|
|
819
|
+
protocolMessage: {
|
|
820
|
+
key: message.edit,
|
|
821
|
+
editedMessage: m,
|
|
822
|
+
timestampMs: Date.now(),
|
|
823
|
+
type: WAProto.Message.ProtocolMessage.Type.MESSAGE_EDIT,
|
|
824
|
+
},
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
if (hasOptionalProperty(message, "contextInfo") && !!message.contextInfo) {
|
|
828
|
+
const messageType = Object.keys(m)[0];
|
|
829
|
+
const key = m[messageType];
|
|
830
|
+
if ("contextInfo" in key && !!key.contextInfo) {
|
|
831
|
+
key.contextInfo = { ...key.contextInfo, ...message.contextInfo };
|
|
832
|
+
} else if (key) {
|
|
833
|
+
key.contextInfo = message.contextInfo;
|
|
490
834
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
835
|
+
}
|
|
836
|
+
if (shouldIncludeReportingToken(m)) {
|
|
837
|
+
m.messageContextInfo = m.messageContextInfo || {};
|
|
838
|
+
if (!m.messageContextInfo.messageSecret) {
|
|
839
|
+
m.messageContextInfo.messageSecret = randomBytes(32);
|
|
495
840
|
}
|
|
496
|
-
|
|
841
|
+
}
|
|
842
|
+
return WAProto.Message.create(m);
|
|
497
843
|
};
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
delete quotedContent.contextInfo;
|
|
518
|
-
}
|
|
519
|
-
const contextInfo = innerMessage[key].contextInfo || {};
|
|
520
|
-
contextInfo.participant = (0, WABinary_1.jidNormalizedUser)(participant);
|
|
521
|
-
contextInfo.stanzaId = quoted.key.id;
|
|
522
|
-
contextInfo.quotedMessage = quotedMsg;
|
|
523
|
-
// if a participant is quoted, then it must be a group
|
|
524
|
-
// hence, remoteJid of group must also be entered
|
|
525
|
-
if (jid !== quoted.key.remoteJid) {
|
|
526
|
-
contextInfo.remoteJid = quoted.key.remoteJid;
|
|
527
|
-
}
|
|
528
|
-
innerMessage[key].contextInfo = contextInfo;
|
|
529
|
-
}
|
|
844
|
+
export const generateWAMessageFromContent = (jid, message, options) => {
|
|
845
|
+
// set timestamp to now
|
|
846
|
+
// if not specified
|
|
847
|
+
if (!options.timestamp) {
|
|
848
|
+
options.timestamp = new Date();
|
|
849
|
+
}
|
|
850
|
+
const innerMessage = normalizeMessageContent(message);
|
|
851
|
+
const key = getContentType(innerMessage);
|
|
852
|
+
const timestamp = unixTimestampSeconds(options.timestamp);
|
|
853
|
+
const { quoted, userJid } = options;
|
|
854
|
+
if (quoted && !isJidNewsletter(jid)) {
|
|
855
|
+
const participant = quoted.key.fromMe
|
|
856
|
+
? userJid // TODO: Add support for LIDs
|
|
857
|
+
: quoted.participant || quoted.key.participant || quoted.key.remoteJid;
|
|
858
|
+
let quotedMsg = normalizeMessageContent(quoted.message);
|
|
859
|
+
const msgType = getContentType(quotedMsg);
|
|
860
|
+
// strip any redundant properties
|
|
861
|
+
quotedMsg = proto.Message.create({ [msgType]: quotedMsg[msgType] });
|
|
862
|
+
const quotedContent = quotedMsg[msgType];
|
|
530
863
|
if (
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
key !== 'ephemeralMessage' &&
|
|
537
|
-
// newsletter not accept disappearing messages
|
|
538
|
-
!(0, WABinary_1.isJidNewsLetter)(jid)) {
|
|
539
|
-
innerMessage[key].contextInfo = {
|
|
540
|
-
...(innerMessage[key].contextInfo || {}),
|
|
541
|
-
expiration: options.ephemeralExpiration || Defaults_1.WA_DEFAULT_EPHEMERAL,
|
|
542
|
-
//ephemeralSettingTimestamp: options.ephemeralOptions.eph_setting_ts?.toString()
|
|
543
|
-
};
|
|
864
|
+
typeof quotedContent === "object" &&
|
|
865
|
+
quotedContent &&
|
|
866
|
+
"contextInfo" in quotedContent
|
|
867
|
+
) {
|
|
868
|
+
delete quotedContent.contextInfo;
|
|
544
869
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
870
|
+
const contextInfo =
|
|
871
|
+
("contextInfo" in innerMessage[key] && innerMessage[key]?.contextInfo) ||
|
|
872
|
+
{};
|
|
873
|
+
contextInfo.participant = jidNormalizedUser(participant);
|
|
874
|
+
contextInfo.stanzaId = quoted.key.id;
|
|
875
|
+
contextInfo.quotedMessage = quotedMsg;
|
|
876
|
+
// if a participant is quoted, then it must be a group
|
|
877
|
+
// hence, remoteJid of group must also be entered
|
|
878
|
+
if (jid !== quoted.key.remoteJid) {
|
|
879
|
+
contextInfo.remoteJid = quoted.key.remoteJid;
|
|
880
|
+
}
|
|
881
|
+
if (contextInfo && innerMessage[key]) {
|
|
882
|
+
/* @ts-ignore */
|
|
883
|
+
innerMessage[key].contextInfo = contextInfo;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
if (
|
|
887
|
+
// if we want to send a disappearing message
|
|
888
|
+
!!options?.ephemeralExpiration &&
|
|
889
|
+
// and it's not a protocol message -- delete, toggle disappear message
|
|
890
|
+
key !== "protocolMessage" &&
|
|
891
|
+
// already not converted to disappearing message
|
|
892
|
+
key !== "ephemeralMessage" &&
|
|
893
|
+
// newsletters don't support ephemeral messages
|
|
894
|
+
!isJidNewsletter(jid)
|
|
895
|
+
) {
|
|
896
|
+
/* @ts-ignore */
|
|
897
|
+
innerMessage[key].contextInfo = {
|
|
898
|
+
...(innerMessage[key].contextInfo || {}),
|
|
899
|
+
expiration: options.ephemeralExpiration || WA_DEFAULT_EPHEMERAL,
|
|
900
|
+
//ephemeralSettingTimestamp: options.ephemeralOptions.eph_setting_ts?.toString()
|
|
557
901
|
};
|
|
558
|
-
|
|
902
|
+
}
|
|
903
|
+
message = WAProto.Message.create(message);
|
|
904
|
+
const messageJSON = {
|
|
905
|
+
key: {
|
|
906
|
+
remoteJid: jid,
|
|
907
|
+
fromMe: true,
|
|
908
|
+
id: options?.messageId || generateMessageIDV2(),
|
|
909
|
+
},
|
|
910
|
+
message: message,
|
|
911
|
+
messageTimestamp: timestamp,
|
|
912
|
+
messageStubParameters: [],
|
|
913
|
+
participant:
|
|
914
|
+
isJidGroup(jid) || isJidStatusBroadcast(jid) ? userJid : undefined, // TODO: Add support for LIDs
|
|
915
|
+
status: WAMessageStatus.PENDING,
|
|
916
|
+
};
|
|
917
|
+
return WAProto.WebMessageInfo.fromObject(messageJSON);
|
|
559
918
|
};
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
919
|
+
export const generateWAMessage = async (jid, content, options) => {
|
|
920
|
+
// ensure msg ID is with every log
|
|
921
|
+
options.logger = options?.logger?.child({ msgId: options.messageId });
|
|
922
|
+
// Pass jid in the options to generateWAMessageContent
|
|
923
|
+
return generateWAMessageFromContent(
|
|
924
|
+
jid,
|
|
925
|
+
await generateWAMessageContent(content, { ...options, jid }),
|
|
926
|
+
options,
|
|
927
|
+
);
|
|
566
928
|
};
|
|
567
|
-
exports.generateWAMessage = generateWAMessage;
|
|
568
929
|
/** Get the key to access the true type of content */
|
|
569
|
-
const getContentType = (content) => {
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
930
|
+
export const getContentType = (content) => {
|
|
931
|
+
if (content) {
|
|
932
|
+
const keys = Object.keys(content);
|
|
933
|
+
const key = keys.find(
|
|
934
|
+
(k) =>
|
|
935
|
+
(k === "conversation" || k.includes("Message")) &&
|
|
936
|
+
k !== "senderKeyDistributionMessage",
|
|
937
|
+
);
|
|
938
|
+
return key;
|
|
939
|
+
}
|
|
575
940
|
};
|
|
576
|
-
exports.getContentType = getContentType;
|
|
577
941
|
/**
|
|
578
942
|
* Normalizes ephemeral, view once messages to regular message content
|
|
579
943
|
* Eg. image messages in ephemeral messages, in view once messages etc.
|
|
580
944
|
* @param content
|
|
581
945
|
* @returns
|
|
582
946
|
*/
|
|
583
|
-
const normalizeMessageContent = (content) => {
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
}
|
|
593
|
-
content = inner.message;
|
|
594
|
-
}
|
|
595
|
-
return content;
|
|
596
|
-
function getFutureProofMessage(message) {
|
|
597
|
-
return ((message === null || message === void 0 ? void 0 : message.ephemeralMessage)
|
|
598
|
-
|| (message === null || message === void 0 ? void 0 : message.viewOnceMessage)
|
|
599
|
-
|| (message === null || message === void 0 ? void 0 : message.documentWithCaptionMessage)
|
|
600
|
-
|| (message === null || message === void 0 ? void 0 : message.viewOnceMessageV2)
|
|
601
|
-
|| (message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension)
|
|
602
|
-
|| (message === null || message === void 0 ? void 0 : message.editedMessage));
|
|
947
|
+
export const normalizeMessageContent = (content) => {
|
|
948
|
+
if (!content) {
|
|
949
|
+
return undefined;
|
|
950
|
+
}
|
|
951
|
+
// set max iterations to prevent an infinite loop
|
|
952
|
+
for (let i = 0; i < 5; i++) {
|
|
953
|
+
const inner = getFutureProofMessage(content);
|
|
954
|
+
if (!inner) {
|
|
955
|
+
break;
|
|
603
956
|
}
|
|
957
|
+
content = inner.message;
|
|
958
|
+
}
|
|
959
|
+
return content;
|
|
960
|
+
function getFutureProofMessage(message) {
|
|
961
|
+
return (
|
|
962
|
+
message?.ephemeralMessage ||
|
|
963
|
+
message?.viewOnceMessage ||
|
|
964
|
+
message?.documentWithCaptionMessage ||
|
|
965
|
+
message?.viewOnceMessageV2 ||
|
|
966
|
+
message?.viewOnceMessageV2Extension ||
|
|
967
|
+
message?.editedMessage ||
|
|
968
|
+
message?.associatedChildMessage ||
|
|
969
|
+
message?.groupStatusMessage ||
|
|
970
|
+
message?.groupStatusMessageV2
|
|
971
|
+
);
|
|
972
|
+
}
|
|
604
973
|
};
|
|
605
|
-
exports.normalizeMessageContent = normalizeMessageContent;
|
|
606
974
|
/**
|
|
607
975
|
* Extract the true message content from a message
|
|
608
976
|
* Eg. extracts the inner message from a disappearing message/view once message
|
|
609
977
|
*/
|
|
610
|
-
const extractMessageContent = (content) => {
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
: ('hydratedContentText' in msg ? msg.hydratedContentText : '')
|
|
630
|
-
};
|
|
631
|
-
}
|
|
632
|
-
};
|
|
633
|
-
content = (0, exports.normalizeMessageContent)(content);
|
|
634
|
-
if (content === null || content === void 0 ? void 0 : content.buttonsMessage) {
|
|
635
|
-
return extractFromTemplateMessage(content.buttonsMessage);
|
|
636
|
-
}
|
|
637
|
-
if ((_a = content === null || content === void 0 ? void 0 : content.templateMessage) === null || _a === void 0 ? void 0 : _a.hydratedFourRowTemplate) {
|
|
638
|
-
return extractFromTemplateMessage((_b = content === null || content === void 0 ? void 0 : content.templateMessage) === null || _b === void 0 ? void 0 : _b.hydratedFourRowTemplate);
|
|
978
|
+
export const extractMessageContent = (content) => {
|
|
979
|
+
const extractFromTemplateMessage = (msg) => {
|
|
980
|
+
if (msg.imageMessage) {
|
|
981
|
+
return { imageMessage: msg.imageMessage };
|
|
982
|
+
} else if (msg.documentMessage) {
|
|
983
|
+
return { documentMessage: msg.documentMessage };
|
|
984
|
+
} else if (msg.videoMessage) {
|
|
985
|
+
return { videoMessage: msg.videoMessage };
|
|
986
|
+
} else if (msg.locationMessage) {
|
|
987
|
+
return { locationMessage: msg.locationMessage };
|
|
988
|
+
} else {
|
|
989
|
+
return {
|
|
990
|
+
conversation:
|
|
991
|
+
"contentText" in msg
|
|
992
|
+
? msg.contentText
|
|
993
|
+
: "hydratedContentText" in msg
|
|
994
|
+
? msg.hydratedContentText
|
|
995
|
+
: "",
|
|
996
|
+
};
|
|
639
997
|
}
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
return
|
|
998
|
+
};
|
|
999
|
+
content = normalizeMessageContent(content);
|
|
1000
|
+
if (content?.buttonsMessage) {
|
|
1001
|
+
return extractFromTemplateMessage(content.buttonsMessage);
|
|
1002
|
+
}
|
|
1003
|
+
if (content?.templateMessage?.hydratedFourRowTemplate) {
|
|
1004
|
+
return extractFromTemplateMessage(
|
|
1005
|
+
content?.templateMessage?.hydratedFourRowTemplate,
|
|
1006
|
+
);
|
|
1007
|
+
}
|
|
1008
|
+
if (content?.templateMessage?.hydratedTemplate) {
|
|
1009
|
+
return extractFromTemplateMessage(
|
|
1010
|
+
content?.templateMessage?.hydratedTemplate,
|
|
1011
|
+
);
|
|
1012
|
+
}
|
|
1013
|
+
if (content?.templateMessage?.fourRowTemplate) {
|
|
1014
|
+
return extractFromTemplateMessage(
|
|
1015
|
+
content?.templateMessage?.fourRowTemplate,
|
|
1016
|
+
);
|
|
1017
|
+
}
|
|
1018
|
+
return content;
|
|
647
1019
|
};
|
|
648
|
-
exports.extractMessageContent = extractMessageContent;
|
|
649
1020
|
/**
|
|
650
1021
|
* Returns the device predicted by message ID
|
|
651
1022
|
*/
|
|
652
|
-
const getDevice = (id) =>
|
|
653
|
-
|
|
1023
|
+
export const getDevice = (id) =>
|
|
1024
|
+
/^3A.{18}$/.test(id)
|
|
1025
|
+
? "ios"
|
|
1026
|
+
: /^3E.{20}$/.test(id)
|
|
1027
|
+
? "web"
|
|
1028
|
+
: /^(.{21}|.{32})$/.test(id)
|
|
1029
|
+
? "android"
|
|
1030
|
+
: /^(3F|.{18}$)/.test(id)
|
|
1031
|
+
? "desktop"
|
|
1032
|
+
: "unknown";
|
|
654
1033
|
/** Upserts a receipt in the message */
|
|
655
|
-
const updateMessageWithReceipt = (msg, receipt) => {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
}
|
|
1034
|
+
export const updateMessageWithReceipt = (msg, receipt) => {
|
|
1035
|
+
msg.userReceipt = msg.userReceipt || [];
|
|
1036
|
+
const recp = msg.userReceipt.find((m) => m.userJid === receipt.userJid);
|
|
1037
|
+
if (recp) {
|
|
1038
|
+
Object.assign(recp, receipt);
|
|
1039
|
+
} else {
|
|
1040
|
+
msg.userReceipt.push(receipt);
|
|
1041
|
+
}
|
|
664
1042
|
};
|
|
665
|
-
exports.updateMessageWithReceipt = updateMessageWithReceipt;
|
|
666
1043
|
/** Update the message with a new reaction */
|
|
667
|
-
const updateMessageWithReaction = (msg, reaction) => {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
1044
|
+
export const updateMessageWithReaction = (msg, reaction) => {
|
|
1045
|
+
const authorID = getKeyAuthor(reaction.key);
|
|
1046
|
+
const reactions = (msg.reactions || []).filter(
|
|
1047
|
+
(r) => getKeyAuthor(r.key) !== authorID,
|
|
1048
|
+
);
|
|
1049
|
+
reaction.text = reaction.text || "";
|
|
1050
|
+
reactions.push(reaction);
|
|
1051
|
+
msg.reactions = reactions;
|
|
675
1052
|
};
|
|
676
|
-
exports.updateMessageWithReaction = updateMessageWithReaction;
|
|
677
1053
|
/** Update the message with a new poll update */
|
|
678
|
-
const updateMessageWithPollUpdate = (msg, update) => {
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
1054
|
+
export const updateMessageWithPollUpdate = (msg, update) => {
|
|
1055
|
+
const authorID = getKeyAuthor(update.pollUpdateMessageKey);
|
|
1056
|
+
const reactions = (msg.pollUpdates || []).filter(
|
|
1057
|
+
(r) => getKeyAuthor(r.pollUpdateMessageKey) !== authorID,
|
|
1058
|
+
);
|
|
1059
|
+
if (update.vote?.selectedOptions?.length) {
|
|
1060
|
+
reactions.push(update);
|
|
1061
|
+
}
|
|
1062
|
+
msg.pollUpdates = reactions;
|
|
1063
|
+
};
|
|
1064
|
+
/** Update the message with a new event response */
|
|
1065
|
+
export const updateMessageWithEventResponse = (msg, update) => {
|
|
1066
|
+
const authorID = getKeyAuthor(update.eventResponseMessageKey);
|
|
1067
|
+
const responses = (msg.eventResponses || []).filter(
|
|
1068
|
+
(r) => getKeyAuthor(r.eventResponseMessageKey) !== authorID,
|
|
1069
|
+
);
|
|
1070
|
+
responses.push(update);
|
|
1071
|
+
msg.eventResponses = responses;
|
|
687
1072
|
};
|
|
688
|
-
exports.updateMessageWithPollUpdate = updateMessageWithPollUpdate;
|
|
689
1073
|
/**
|
|
690
1074
|
* Aggregates all poll updates in a poll.
|
|
691
1075
|
* @param msg the poll creation message
|
|
692
1076
|
* @param meId your jid
|
|
693
1077
|
* @returns A list of options & their voters
|
|
694
1078
|
*/
|
|
695
|
-
function getAggregateVotesInPollMessage({ message, pollUpdates }, meId) {
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
1079
|
+
export function getAggregateVotesInPollMessage({ message, pollUpdates }, meId) {
|
|
1080
|
+
const opts =
|
|
1081
|
+
message?.pollCreationMessage?.options ||
|
|
1082
|
+
message?.pollCreationMessageV2?.options ||
|
|
1083
|
+
message?.pollCreationMessageV3?.options ||
|
|
1084
|
+
[];
|
|
1085
|
+
const voteHashMap = opts.reduce((acc, opt) => {
|
|
1086
|
+
const hash = sha256(Buffer.from(opt.optionName || "")).toString();
|
|
1087
|
+
acc[hash] = {
|
|
1088
|
+
name: opt.optionName || "",
|
|
1089
|
+
voters: [],
|
|
1090
|
+
};
|
|
1091
|
+
return acc;
|
|
1092
|
+
}, {});
|
|
1093
|
+
for (const update of pollUpdates || []) {
|
|
1094
|
+
const { vote } = update;
|
|
1095
|
+
if (!vote) {
|
|
1096
|
+
continue;
|
|
1097
|
+
}
|
|
1098
|
+
for (const option of vote.selectedOptions || []) {
|
|
1099
|
+
const hash = option.toString();
|
|
1100
|
+
let data = voteHashMap[hash];
|
|
1101
|
+
if (!data) {
|
|
1102
|
+
voteHashMap[hash] = {
|
|
1103
|
+
name: "Unknown",
|
|
1104
|
+
voters: [],
|
|
703
1105
|
};
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
1106
|
+
data = voteHashMap[hash];
|
|
1107
|
+
}
|
|
1108
|
+
voteHashMap[hash].voters.push(
|
|
1109
|
+
getKeyAuthor(update.pollUpdateMessageKey, meId),
|
|
1110
|
+
);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
return Object.values(voteHashMap);
|
|
1114
|
+
}
|
|
1115
|
+
/**
|
|
1116
|
+
* Aggregates all event responses in an event message.
|
|
1117
|
+
* @param msg the event creation message
|
|
1118
|
+
* @param meId your jid
|
|
1119
|
+
* @returns A list of response types & their responders
|
|
1120
|
+
*/
|
|
1121
|
+
export function getAggregateResponsesInEventMessage({ eventResponses }, meId) {
|
|
1122
|
+
const responseTypes = ["GOING", "NOT_GOING", "MAYBE"];
|
|
1123
|
+
const responseMap = {};
|
|
1124
|
+
for (const type of responseTypes) {
|
|
1125
|
+
responseMap[type] = {
|
|
1126
|
+
response: type,
|
|
1127
|
+
responders: [],
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
for (const update of eventResponses || []) {
|
|
1131
|
+
const responseType = update.eventResponse || "UNKNOWN";
|
|
1132
|
+
if (responseType !== "UNKNOWN" && responseMap[responseType]) {
|
|
1133
|
+
responseMap[responseType].responders.push(
|
|
1134
|
+
getKeyAuthor(update.eventResponseMessageKey, meId),
|
|
1135
|
+
);
|
|
723
1136
|
}
|
|
724
|
-
|
|
1137
|
+
}
|
|
1138
|
+
return Object.values(responseMap);
|
|
725
1139
|
}
|
|
726
|
-
exports.getAggregateVotesInPollMessage = getAggregateVotesInPollMessage;
|
|
727
1140
|
/** Given a list of message keys, aggregates them by chat & sender. Useful for sending read receipts in bulk */
|
|
728
|
-
const aggregateMessageKeysNotFromMe = (keys) => {
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
}
|
|
1141
|
+
export const aggregateMessageKeysNotFromMe = (keys) => {
|
|
1142
|
+
const keyMap = {};
|
|
1143
|
+
for (const { remoteJid, id, participant, fromMe } of keys) {
|
|
1144
|
+
if (!fromMe) {
|
|
1145
|
+
const uqKey = `${remoteJid}:${participant || ""}`;
|
|
1146
|
+
if (!keyMap[uqKey]) {
|
|
1147
|
+
keyMap[uqKey] = {
|
|
1148
|
+
jid: remoteJid,
|
|
1149
|
+
participant: participant,
|
|
1150
|
+
messageIds: [],
|
|
1151
|
+
};
|
|
1152
|
+
}
|
|
1153
|
+
keyMap[uqKey].messageIds.push(id);
|
|
742
1154
|
}
|
|
743
|
-
|
|
1155
|
+
}
|
|
1156
|
+
return Object.values(keyMap);
|
|
744
1157
|
};
|
|
745
|
-
exports.aggregateMessageKeysNotFromMe = aggregateMessageKeysNotFromMe;
|
|
746
1158
|
const REUPLOAD_REQUIRED_STATUS = [410, 404];
|
|
747
1159
|
/**
|
|
748
1160
|
* Downloads the given message. Throws an error if it's not a media message
|
|
749
1161
|
*/
|
|
750
|
-
const downloadMediaMessage = async (message, type, options, ctx) => {
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
directPath: media.thumbnailDirectPath,
|
|
784
|
-
mediaKey: media.mediaKey
|
|
785
|
-
};
|
|
786
|
-
mediaType = 'thumbnail-link';
|
|
787
|
-
}
|
|
788
|
-
else {
|
|
789
|
-
download = media;
|
|
790
|
-
}
|
|
791
|
-
const stream = await (0, messages_media_1.downloadContentFromMessage)(download, mediaType, options);
|
|
792
|
-
if (type === 'buffer') {
|
|
793
|
-
const bufferArray = [];
|
|
794
|
-
for await (const chunk of stream) {
|
|
795
|
-
bufferArray.push(chunk);
|
|
796
|
-
}
|
|
797
|
-
return Buffer.concat(bufferArray);
|
|
798
|
-
}
|
|
799
|
-
return stream;
|
|
1162
|
+
export const downloadMediaMessage = async (message, type, options, ctx) => {
|
|
1163
|
+
const result = await downloadMsg().catch(async (error) => {
|
|
1164
|
+
if (
|
|
1165
|
+
ctx &&
|
|
1166
|
+
typeof error?.status === "number" && // treat errors with status as HTTP failures requiring reupload
|
|
1167
|
+
REUPLOAD_REQUIRED_STATUS.includes(error.status)
|
|
1168
|
+
) {
|
|
1169
|
+
ctx.logger.info(
|
|
1170
|
+
{ key: message.key },
|
|
1171
|
+
"sending reupload media request...",
|
|
1172
|
+
);
|
|
1173
|
+
// request reupload
|
|
1174
|
+
message = await ctx.reuploadRequest(message);
|
|
1175
|
+
const result = await downloadMsg();
|
|
1176
|
+
return result;
|
|
1177
|
+
}
|
|
1178
|
+
throw error;
|
|
1179
|
+
});
|
|
1180
|
+
return result;
|
|
1181
|
+
async function downloadMsg() {
|
|
1182
|
+
const mContent = extractMessageContent(message.message);
|
|
1183
|
+
if (!mContent) {
|
|
1184
|
+
throw new Boom("No message present", { statusCode: 400, data: message });
|
|
1185
|
+
}
|
|
1186
|
+
const contentType = getContentType(mContent);
|
|
1187
|
+
let mediaType = contentType?.replace("Message", "");
|
|
1188
|
+
const media = mContent[contentType];
|
|
1189
|
+
if (
|
|
1190
|
+
!media ||
|
|
1191
|
+
typeof media !== "object" ||
|
|
1192
|
+
(!("url" in media) && !("thumbnailDirectPath" in media))
|
|
1193
|
+
) {
|
|
1194
|
+
throw new Boom(`"${contentType}" message is not a media message`);
|
|
800
1195
|
}
|
|
1196
|
+
let download;
|
|
1197
|
+
if ("thumbnailDirectPath" in media && !("url" in media)) {
|
|
1198
|
+
download = {
|
|
1199
|
+
directPath: media.thumbnailDirectPath,
|
|
1200
|
+
mediaKey: media.mediaKey,
|
|
1201
|
+
};
|
|
1202
|
+
mediaType = "thumbnail-link";
|
|
1203
|
+
} else {
|
|
1204
|
+
download = media;
|
|
1205
|
+
}
|
|
1206
|
+
const stream = await downloadContentFromMessage(
|
|
1207
|
+
download,
|
|
1208
|
+
mediaType,
|
|
1209
|
+
options,
|
|
1210
|
+
);
|
|
1211
|
+
if (type === "buffer") {
|
|
1212
|
+
const bufferArray = [];
|
|
1213
|
+
for await (const chunk of stream) {
|
|
1214
|
+
bufferArray.push(chunk);
|
|
1215
|
+
}
|
|
1216
|
+
return Buffer.concat(bufferArray);
|
|
1217
|
+
}
|
|
1218
|
+
return stream;
|
|
1219
|
+
}
|
|
801
1220
|
};
|
|
802
|
-
exports.downloadMediaMessage = downloadMediaMessage;
|
|
803
1221
|
/** Checks whether the given message is a media message; if it is returns the inner content */
|
|
804
|
-
const assertMediaContent = (content) => {
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
1222
|
+
export const assertMediaContent = (content) => {
|
|
1223
|
+
content = extractMessageContent(content);
|
|
1224
|
+
const mediaContent =
|
|
1225
|
+
content?.documentMessage ||
|
|
1226
|
+
content?.imageMessage ||
|
|
1227
|
+
content?.videoMessage ||
|
|
1228
|
+
content?.audioMessage ||
|
|
1229
|
+
content?.stickerMessage;
|
|
1230
|
+
if (!mediaContent) {
|
|
1231
|
+
throw new Boom("given message is not a media message", {
|
|
1232
|
+
statusCode: 400,
|
|
1233
|
+
data: content,
|
|
1234
|
+
});
|
|
1235
|
+
}
|
|
1236
|
+
return mediaContent;
|
|
815
1237
|
};
|
|
816
|
-
|
|
1238
|
+
//# sourceMappingURL=messages.js.map
|