@eduh_dev021/baileys 0.0.0-stage → 1.1.0
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 +23 -0
- package/README.md +1843 -2
- package/WAProto/index.d.ts +22220 -0
- package/WAProto/index.js +5 -0
- package/cjs/WAProto/index.d.ts +22220 -0
- package/cjs/WAProto/index.js +60125 -0
- package/cjs/engine-requirements.js +12 -0
- package/cjs/lib/Addon/cache.js +179 -0
- package/cjs/lib/Addon/crc32.js +41 -0
- package/cjs/lib/Addon/file-type.js +217 -0
- package/cjs/lib/Addon/get-file.js +99 -0
- package/cjs/lib/Addon/http-error.d.ts +18 -0
- package/cjs/lib/Addon/http-error.js +66 -0
- package/cjs/lib/Addon/index.d.ts +96 -0
- package/cjs/lib/Addon/index.js +58 -0
- package/cjs/lib/Addon/keyed-db.d.ts +14 -0
- package/cjs/lib/Addon/keyed-db.js +264 -0
- package/cjs/lib/Addon/link-preview.d.ts +15 -0
- package/cjs/lib/Addon/link-preview.js +104 -0
- package/cjs/lib/Addon/media-info.js +98 -0
- package/cjs/lib/Addon/mutex.js +78 -0
- package/cjs/lib/Addon/qr.js +464 -0
- package/cjs/lib/Addon/queue.js +54 -0
- package/cjs/lib/Addon/waveform.js +130 -0
- package/cjs/lib/Addon/zip.js +136 -0
- package/cjs/lib/Defaults/index.d.ts +184 -0
- package/cjs/lib/Defaults/index.js +292 -0
- package/cjs/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/cjs/lib/Signal/Group/ciphertext-message.js +37 -0
- package/cjs/lib/Signal/Group/group-cipher.d.ts +10 -0
- package/cjs/lib/Signal/Group/group-cipher.js +105 -0
- package/cjs/lib/Signal/Group/group-session-builder.d.ts +7 -0
- package/cjs/lib/Signal/Group/group-session-builder.js +65 -0
- package/cjs/lib/Signal/Group/index.d.ts +11 -0
- package/cjs/lib/Signal/Group/index.js +67 -0
- package/cjs/lib/Signal/Group/keyhelper.d.ts +6 -0
- package/cjs/lib/Signal/Group/keyhelper.js +47 -0
- package/cjs/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/cjs/lib/Signal/Group/sender-chain-key.js +51 -0
- package/cjs/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/cjs/lib/Signal/Group/sender-key-distribution-message.js +80 -0
- package/cjs/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/cjs/lib/Signal/Group/sender-key-message.js +87 -0
- package/cjs/lib/Signal/Group/sender-key-name.d.ts +11 -0
- package/cjs/lib/Signal/Group/sender-key-name.js +73 -0
- package/cjs/lib/Signal/Group/sender-key-record.d.ts +12 -0
- package/cjs/lib/Signal/Group/sender-key-record.js +66 -0
- package/cjs/lib/Signal/Group/sender-key-state.d.ts +16 -0
- package/cjs/lib/Signal/Group/sender-key-state.js +106 -0
- package/cjs/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/cjs/lib/Signal/Group/sender-message-key.js +51 -0
- package/cjs/lib/Signal/libsignal.d.ts +54 -0
- package/cjs/lib/Signal/libsignal.js +421 -0
- package/cjs/lib/Signal/lid-mapping.d.ts +20 -0
- package/cjs/lib/Signal/lid-mapping.js +292 -0
- package/cjs/lib/Socket/Client/index.d.ts +2 -0
- package/cjs/lib/Socket/Client/index.js +23 -0
- package/cjs/lib/Socket/Client/types.d.ts +5 -0
- package/cjs/lib/Socket/Client/types.js +36 -0
- package/cjs/lib/Socket/Client/websocket.d.ts +12 -0
- package/cjs/lib/Socket/Client/websocket.js +143 -0
- package/cjs/lib/Socket/business.d.ts +387 -0
- package/cjs/lib/Socket/business.js +402 -0
- package/cjs/lib/Socket/chats.d.ts +144 -0
- package/cjs/lib/Socket/chats.js +1118 -0
- package/cjs/lib/Socket/communities.d.ts +554 -0
- package/cjs/lib/Socket/communities.js +456 -0
- package/cjs/lib/Socket/groups.d.ts +286 -0
- package/cjs/lib/Socket/groups.js +366 -0
- package/cjs/lib/Socket/index.d.ts +522 -0
- package/cjs/lib/Socket/index.js +32 -0
- package/cjs/lib/Socket/messages-recv.d.ts +326 -0
- package/cjs/lib/Socket/messages-recv.js +1670 -0
- package/cjs/lib/Socket/messages-send.d.ts +321 -0
- package/cjs/lib/Socket/messages-send.js +1252 -0
- package/cjs/lib/Socket/mex.d.ts +1 -0
- package/cjs/lib/Socket/mex.js +65 -0
- package/cjs/lib/Socket/newsletter.d.ts +283 -0
- package/cjs/lib/Socket/newsletter.js +243 -0
- package/cjs/lib/Socket/socket.d.ts +61 -0
- package/cjs/lib/Socket/socket.js +908 -0
- package/cjs/lib/Store/index.d.ts +3 -0
- package/cjs/lib/Store/index.js +25 -0
- package/cjs/lib/Store/make-in-memory-store.d.ts +63 -0
- package/cjs/lib/Store/make-in-memory-store.js +431 -0
- package/cjs/lib/Store/make-ordered-dictionary.d.ts +12 -0
- package/cjs/lib/Store/make-ordered-dictionary.js +101 -0
- package/cjs/lib/Store/object-repository.d.ts +10 -0
- package/cjs/lib/Store/object-repository.js +49 -0
- package/cjs/lib/Transport/crypto.d.ts +6 -0
- package/cjs/lib/Transport/crypto.js +107 -0
- package/cjs/lib/Transport/curve.d.ts +8 -0
- package/cjs/lib/Transport/curve.js +94 -0
- package/cjs/lib/Transport/index.d.ts +16 -0
- package/cjs/lib/Transport/index.js +67 -0
- package/cjs/lib/Transport/internals.d.ts +57 -0
- package/cjs/lib/Transport/internals.js +203 -0
- package/cjs/lib/Transport/session-builder.d.ts +40 -0
- package/cjs/lib/Transport/session-builder.js +169 -0
- package/cjs/lib/Transport/session-cipher.d.ts +26 -0
- package/cjs/lib/Transport/session-cipher.js +328 -0
- package/cjs/lib/Transport/session-record.d.ts +55 -0
- package/cjs/lib/Transport/session-record.js +289 -0
- package/cjs/lib/Types/Auth.d.ts +1 -0
- package/cjs/lib/Types/Auth.js +15 -0
- package/cjs/lib/Types/Bussines.d.ts +1 -0
- package/cjs/lib/Types/Bussines.js +15 -0
- package/cjs/lib/Types/Call.d.ts +1 -0
- package/cjs/lib/Types/Call.js +15 -0
- package/cjs/lib/Types/Chat.d.ts +1 -0
- package/cjs/lib/Types/Chat.js +33 -0
- package/cjs/lib/Types/Contact.d.ts +1 -0
- package/cjs/lib/Types/Contact.js +15 -0
- package/cjs/lib/Types/Events.d.ts +1 -0
- package/cjs/lib/Types/Events.js +1 -0
- package/cjs/lib/Types/GroupMetadata.d.ts +1 -0
- package/cjs/lib/Types/GroupMetadata.js +15 -0
- package/cjs/lib/Types/Label.d.ts +2 -0
- package/cjs/lib/Types/Label.js +49 -0
- package/cjs/lib/Types/LabelAssociation.d.ts +2 -0
- package/cjs/lib/Types/LabelAssociation.js +31 -0
- package/cjs/lib/Types/Message.d.ts +11 -0
- package/cjs/lib/Types/Message.js +58 -0
- package/cjs/lib/Types/Mex.d.ts +2 -0
- package/cjs/lib/Types/Mex.js +66 -0
- package/cjs/lib/Types/Product.d.ts +1 -0
- package/cjs/lib/Types/Product.js +15 -0
- package/cjs/lib/Types/RichType.d.ts +2 -0
- package/cjs/lib/Types/RichType.js +50 -0
- package/cjs/lib/Types/Signal.d.ts +1 -0
- package/cjs/lib/Types/Signal.js +1 -0
- package/cjs/lib/Types/Socket.d.ts +1 -0
- package/cjs/lib/Types/Socket.js +1 -0
- package/cjs/lib/Types/State.d.ts +5 -0
- package/cjs/lib/Types/State.js +83 -0
- package/cjs/lib/Types/USync.d.ts +1 -0
- package/cjs/lib/Types/USync.js +1 -0
- package/cjs/lib/Types/index.d.ts +13 -0
- package/cjs/lib/Types/index.js +64 -0
- package/cjs/lib/Utils/auth-utils.d.ts +58 -0
- package/cjs/lib/Utils/auth-utils.js +275 -0
- package/cjs/lib/Utils/browser-utils.d.ts +9 -0
- package/cjs/lib/Utils/browser-utils.js +56 -0
- package/cjs/lib/Utils/business.d.ts +49 -0
- package/cjs/lib/Utils/business.js +259 -0
- package/cjs/lib/Utils/chat-utils.d.ts +408 -0
- package/cjs/lib/Utils/chat-utils.js +821 -0
- package/cjs/lib/Utils/companion-reg-client-utils.d.ts +4 -0
- package/cjs/lib/Utils/companion-reg-client-utils.js +71 -0
- package/cjs/lib/Utils/crypto.d.ts +39 -0
- package/cjs/lib/Utils/crypto.js +155 -0
- package/cjs/lib/Utils/decode-wa-message.d.ts +83 -0
- package/cjs/lib/Utils/decode-wa-message.js +316 -0
- package/cjs/lib/Utils/event-buffer.d.ts +12 -0
- package/cjs/lib/Utils/event-buffer.js +605 -0
- package/cjs/lib/Utils/generics.d.ts +63 -0
- package/cjs/lib/Utils/generics.js +440 -0
- package/cjs/lib/Utils/history.d.ts +75 -0
- package/cjs/lib/Utils/history.js +153 -0
- package/cjs/lib/Utils/identity-change-handler.d.ts +13 -0
- package/cjs/lib/Utils/identity-change-handler.js +73 -0
- package/cjs/lib/Utils/index.d.ts +24 -0
- package/cjs/lib/Utils/index.js +67 -0
- package/cjs/lib/Utils/link-preview.d.ts +13 -0
- package/cjs/lib/Utils/link-preview.js +87 -0
- package/cjs/lib/Utils/logger.d.ts +12 -0
- package/cjs/lib/Utils/logger.js +40 -0
- package/cjs/lib/Utils/lt-hash.d.ts +6 -0
- package/cjs/lib/Utils/lt-hash.js +28 -0
- package/cjs/lib/Utils/make-mutex.d.ts +6 -0
- package/cjs/lib/Utils/make-mutex.js +58 -0
- package/cjs/lib/Utils/message-retry-manager.d.ts +79 -0
- package/cjs/lib/Utils/message-retry-manager.js +274 -0
- package/cjs/lib/Utils/messages-media.d.ts +134 -0
- package/cjs/lib/Utils/messages-media.js +799 -0
- package/cjs/lib/Utils/messages.d.ts +47 -0
- package/cjs/lib/Utils/messages.js +1667 -0
- package/cjs/lib/Utils/noise-handler.d.ts +20 -0
- package/cjs/lib/Utils/noise-handler.js +223 -0
- package/cjs/lib/Utils/offline-node-processor.d.ts +10 -0
- package/cjs/lib/Utils/offline-node-processor.js +60 -0
- package/cjs/lib/Utils/pre-key-manager.d.ts +25 -0
- package/cjs/lib/Utils/pre-key-manager.js +116 -0
- package/cjs/lib/Utils/process-message.d.ts +83 -0
- package/cjs/lib/Utils/process-message.js +607 -0
- package/cjs/lib/Utils/reporting-utils.d.ts +12 -0
- package/cjs/lib/Utils/reporting-utils.js +282 -0
- package/cjs/lib/Utils/rich-message-utils.d.ts +48 -0
- package/cjs/lib/Utils/rich-message-utils.js +381 -0
- package/cjs/lib/Utils/signal.d.ts +82 -0
- package/cjs/lib/Utils/signal.js +232 -0
- package/cjs/lib/Utils/stanza-ack.d.ts +16 -0
- package/cjs/lib/Utils/stanza-ack.js +53 -0
- package/cjs/lib/Utils/sync-action-utils.d.ts +2 -0
- package/cjs/lib/Utils/sync-action-utils.js +68 -0
- package/cjs/lib/Utils/tc-token-utils.d.ts +29 -0
- package/cjs/lib/Utils/tc-token-utils.js +182 -0
- package/cjs/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
- package/cjs/lib/Utils/use-multi-file-auth-state.js +135 -0
- package/cjs/lib/Utils/use-single-file-auth-state.d.ts +11 -0
- package/cjs/lib/Utils/use-single-file-auth-state.js +115 -0
- package/cjs/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/cjs/lib/Utils/use-sqlite-auth-state.js +140 -0
- package/cjs/lib/Utils/validate-connection.d.ts +44 -0
- package/cjs/lib/Utils/validate-connection.js +229 -0
- package/cjs/lib/WABinary/constants.d.ts +61 -0
- package/cjs/lib/WABinary/constants.js +1992 -0
- package/cjs/lib/WABinary/decode.d.ts +9 -0
- package/cjs/lib/WABinary/decode.js +292 -0
- package/cjs/lib/WABinary/encode.d.ts +2 -0
- package/cjs/lib/WABinary/encode.js +240 -0
- package/cjs/lib/WABinary/generic-utils.d.ts +79 -0
- package/cjs/lib/WABinary/generic-utils.js +252 -0
- package/cjs/lib/WABinary/index.d.ts +5 -0
- package/cjs/lib/WABinary/index.js +29 -0
- package/cjs/lib/WABinary/jid-utils.d.ts +28 -0
- package/cjs/lib/WABinary/jid-utils.js +151 -0
- package/cjs/lib/WABinary/types.d.ts +1 -0
- package/cjs/lib/WABinary/types.js +23 -0
- package/cjs/lib/WACrypto/appstate-keys.js +39 -0
- package/cjs/lib/WACrypto/curves/constants.js +37 -0
- package/cjs/lib/WACrypto/hkdf.js +38 -0
- package/cjs/lib/WACrypto/index.js +51 -0
- package/cjs/lib/WACrypto/lthash.js +59 -0
- package/cjs/lib/WACrypto/math/constants.js +53 -0
- package/cjs/lib/WACrypto/math/edwards.js +206 -0
- package/cjs/lib/WACrypto/math/fe.js +449 -0
- package/cjs/lib/WACrypto/math/le.js +44 -0
- package/cjs/lib/WACrypto/math/mod.js +36 -0
- package/cjs/lib/WACrypto/util/bytes.js +348 -0
- package/cjs/lib/WACrypto/x25519.js +157 -0
- package/cjs/lib/WACrypto/xeddsa.js +134 -0
- package/cjs/lib/WAM/BinaryInfo.d.ts +7 -0
- package/cjs/lib/WAM/BinaryInfo.js +35 -0
- package/cjs/lib/WAM/constants.d.ts +34926 -0
- package/cjs/lib/WAM/constants.js +22890 -0
- package/cjs/lib/WAM/encode.d.ts +1 -0
- package/cjs/lib/WAM/encode.js +162 -0
- package/cjs/lib/WAM/index.d.ts +3 -0
- package/cjs/lib/WAM/index.js +25 -0
- package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
- package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.js +77 -0
- package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.js +76 -0
- package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +52 -0
- package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.js +61 -0
- package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
- package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.js +50 -0
- package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
- package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +76 -0
- package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
- package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.js +53 -0
- package/cjs/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/cjs/lib/WAUSync/Protocols/index.js +29 -0
- package/cjs/lib/WAUSync/USyncQuery.d.ts +20 -0
- package/cjs/lib/WAUSync/USyncQuery.js +113 -0
- package/cjs/lib/WAUSync/USyncUser.d.ts +16 -0
- package/cjs/lib/WAUSync/USyncUser.js +56 -0
- package/cjs/lib/WAUSync/index.d.ts +3 -0
- package/cjs/lib/WAUSync/index.js +25 -0
- package/cjs/lib/index.d.ts +11 -0
- package/cjs/lib/index.js +56 -0
- package/cjs/package.json +3 -0
- package/engine-requirements.js +12 -0
- package/lib/Addon/cache.js +201 -0
- package/lib/Addon/crc32.js +21 -0
- package/lib/Addon/file-type.js +198 -0
- package/lib/Addon/get-file.js +98 -0
- package/lib/Addon/http-error.d.ts +18 -0
- package/lib/Addon/http-error.js +40 -0
- package/lib/Addon/index.d.ts +96 -0
- package/lib/Addon/index.js +26 -0
- package/lib/Addon/keyed-db.d.ts +14 -0
- package/lib/Addon/keyed-db.js +241 -0
- package/lib/Addon/link-preview.d.ts +15 -0
- package/lib/Addon/link-preview.js +79 -0
- package/lib/Addon/media-info.js +96 -0
- package/lib/Addon/mutex.js +76 -0
- package/lib/Addon/qr.js +531 -0
- package/lib/Addon/queue.js +44 -0
- package/lib/Addon/waveform.js +135 -0
- package/lib/Addon/zip.js +144 -0
- package/lib/Defaults/index.d.ts +184 -0
- package/lib/Defaults/index.js +181 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +11 -0
- package/lib/Signal/Group/group-cipher.d.ts +10 -0
- package/lib/Signal/Group/group-cipher.js +81 -0
- package/lib/Signal/Group/group-session-builder.d.ts +7 -0
- package/lib/Signal/Group/group-session-builder.js +29 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +11 -0
- package/lib/Signal/Group/keyhelper.d.ts +6 -0
- package/lib/Signal/Group/keyhelper.js +17 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +25 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +65 -0
- package/lib/Signal/Group/sender-key-name.d.ts +11 -0
- package/lib/Signal/Group/sender-key-name.js +47 -0
- package/lib/Signal/Group/sender-key-record.d.ts +12 -0
- package/lib/Signal/Group/sender-key-record.js +40 -0
- package/lib/Signal/Group/sender-key-state.d.ts +16 -0
- package/lib/Signal/Group/sender-key-state.js +83 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/Group/sender-message-key.js +25 -0
- package/lib/Signal/libsignal.d.ts +54 -0
- package/lib/Signal/libsignal.js +426 -0
- package/lib/Signal/lid-mapping.d.ts +20 -0
- package/lib/Signal/lid-mapping.js +274 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/lib/Socket/Client/index.js +2 -0
- package/lib/Socket/Client/types.d.ts +5 -0
- package/lib/Socket/Client/types.js +10 -0
- package/lib/Socket/Client/websocket.d.ts +12 -0
- package/lib/Socket/Client/websocket.js +119 -0
- package/lib/Socket/business.d.ts +387 -0
- package/lib/Socket/business.js +379 -0
- package/lib/Socket/chats.d.ts +144 -0
- package/lib/Socket/chats.js +1216 -0
- package/lib/Socket/communities.d.ts +554 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/groups.d.ts +286 -0
- package/lib/Socket/groups.js +347 -0
- package/lib/Socket/index.d.ts +522 -0
- package/lib/Socket/index.js +11 -0
- package/lib/Socket/messages-recv.d.ts +326 -0
- package/lib/Socket/messages-recv.js +1822 -0
- package/lib/Socket/messages-send.d.ts +321 -0
- package/lib/Socket/messages-send.js +1378 -0
- package/lib/Socket/mex.d.ts +1 -0
- package/lib/Socket/mex.js +41 -0
- package/lib/Socket/newsletter.d.ts +283 -0
- package/lib/Socket/newsletter.js +225 -0
- package/lib/Socket/socket.d.ts +61 -0
- package/lib/Socket/socket.js +992 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +3 -0
- package/lib/Store/make-in-memory-store.d.ts +63 -0
- package/lib/Store/make-in-memory-store.js +419 -0
- package/lib/Store/make-ordered-dictionary.d.ts +12 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +23 -0
- package/lib/Transport/crypto.d.ts +6 -0
- package/lib/Transport/crypto.js +61 -0
- package/lib/Transport/curve.d.ts +8 -0
- package/lib/Transport/curve.js +66 -0
- package/lib/Transport/index.d.ts +16 -0
- package/lib/Transport/index.js +9 -0
- package/lib/Transport/internals.d.ts +57 -0
- package/lib/Transport/internals.js +155 -0
- package/lib/Transport/session-builder.d.ts +40 -0
- package/lib/Transport/session-builder.js +143 -0
- package/lib/Transport/session-cipher.d.ts +26 -0
- package/lib/Transport/session-cipher.js +301 -0
- package/lib/Transport/session-record.d.ts +55 -0
- package/lib/Transport/session-record.js +272 -0
- package/lib/Types/Auth.d.ts +1 -0
- package/lib/Types/Auth.js +1 -0
- package/lib/Types/Bussines.d.ts +1 -0
- package/lib/Types/Bussines.js +1 -0
- package/lib/Types/Call.d.ts +1 -0
- package/lib/Types/Call.js +1 -0
- package/lib/Types/Chat.d.ts +1 -0
- package/lib/Types/Chat.js +7 -0
- package/lib/Types/Contact.d.ts +1 -0
- package/lib/Types/Contact.js +1 -0
- package/lib/Types/Events.d.ts +1 -0
- package/lib/Types/Events.js +1 -0
- package/lib/Types/GroupMetadata.d.ts +1 -0
- package/lib/Types/GroupMetadata.js +1 -0
- package/lib/Types/Label.d.ts +2 -0
- package/lib/Types/Label.js +24 -0
- package/lib/Types/LabelAssociation.d.ts +2 -0
- package/lib/Types/LabelAssociation.js +6 -0
- package/lib/Types/Message.d.ts +11 -0
- package/lib/Types/Message.js +17 -0
- package/lib/Types/Mex.d.ts +2 -0
- package/lib/Types/Mex.js +38 -0
- package/lib/Types/Product.d.ts +1 -0
- package/lib/Types/Product.js +1 -0
- package/lib/Types/RichType.d.ts +2 -0
- package/lib/Types/RichType.js +22 -0
- package/lib/Types/Signal.d.ts +1 -0
- package/lib/Types/Signal.js +1 -0
- package/lib/Types/Socket.d.ts +1 -0
- package/lib/Types/Socket.js +1 -0
- package/lib/Types/State.d.ts +5 -0
- package/lib/Types/State.js +54 -0
- package/lib/Types/USync.d.ts +1 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.d.ts +13 -0
- package/lib/Types/index.js +25 -0
- package/lib/Utils/auth-utils.d.ts +58 -0
- package/lib/Utils/auth-utils.js +316 -0
- package/lib/Utils/browser-utils.d.ts +9 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/business.d.ts +49 -0
- package/lib/Utils/business.js +230 -0
- package/lib/Utils/chat-utils.d.ts +408 -0
- package/lib/Utils/chat-utils.js +871 -0
- package/lib/Utils/companion-reg-client-utils.d.ts +4 -0
- package/lib/Utils/companion-reg-client-utils.js +39 -0
- package/lib/Utils/crypto.d.ts +39 -0
- package/lib/Utils/crypto.js +117 -0
- package/lib/Utils/decode-wa-message.d.ts +83 -0
- package/lib/Utils/decode-wa-message.js +316 -0
- package/lib/Utils/event-buffer.d.ts +12 -0
- package/lib/Utils/event-buffer.js +621 -0
- package/lib/Utils/generics.d.ts +63 -0
- package/lib/Utils/generics.js +394 -0
- package/lib/Utils/history.d.ts +75 -0
- package/lib/Utils/history.js +133 -0
- package/lib/Utils/identity-change-handler.d.ts +13 -0
- package/lib/Utils/identity-change-handler.js +48 -0
- package/lib/Utils/index.d.ts +24 -0
- package/lib/Utils/index.js +24 -0
- package/lib/Utils/link-preview.d.ts +13 -0
- package/lib/Utils/link-preview.js +73 -0
- package/lib/Utils/logger.d.ts +12 -0
- package/lib/Utils/logger.js +12 -0
- package/lib/Utils/lt-hash.d.ts +6 -0
- package/lib/Utils/lt-hash.js +7 -0
- package/lib/Utils/make-mutex.d.ts +6 -0
- package/lib/Utils/make-mutex.js +32 -0
- package/lib/Utils/message-retry-manager.d.ts +79 -0
- package/lib/Utils/message-retry-manager.js +259 -0
- package/lib/Utils/messages-media.d.ts +134 -0
- package/lib/Utils/messages-media.js +802 -0
- package/lib/Utils/messages.d.ts +47 -0
- package/lib/Utils/messages.js +1907 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +200 -0
- package/lib/Utils/offline-node-processor.d.ts +10 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/pre-key-manager.d.ts +25 -0
- package/lib/Utils/pre-key-manager.js +105 -0
- package/lib/Utils/process-message.d.ts +83 -0
- package/lib/Utils/process-message.js +748 -0
- package/lib/Utils/reporting-utils.d.ts +12 -0
- package/lib/Utils/reporting-utils.js +257 -0
- package/lib/Utils/rich-message-utils.d.ts +48 -0
- package/lib/Utils/rich-message-utils.js +366 -0
- package/lib/Utils/signal.d.ts +82 -0
- package/lib/Utils/signal.js +200 -0
- package/lib/Utils/stanza-ack.d.ts +16 -0
- package/lib/Utils/stanza-ack.js +37 -0
- package/lib/Utils/sync-action-utils.d.ts +2 -0
- package/lib/Utils/sync-action-utils.js +48 -0
- package/lib/Utils/tc-token-utils.d.ts +29 -0
- package/lib/Utils/tc-token-utils.js +163 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
- package/lib/Utils/use-multi-file-auth-state.js +116 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-single-file-auth-state.js +94 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/lib/Utils/use-sqlite-auth-state.js +109 -0
- package/lib/Utils/validate-connection.d.ts +44 -0
- package/lib/Utils/validate-connection.js +210 -0
- package/lib/WABinary/constants.d.ts +61 -0
- package/lib/WABinary/constants.js +1466 -0
- package/lib/WABinary/decode.d.ts +9 -0
- package/lib/WABinary/decode.js +261 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +219 -0
- package/lib/WABinary/generic-utils.d.ts +79 -0
- package/lib/WABinary/generic-utils.js +226 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +5 -0
- package/lib/WABinary/jid-utils.d.ts +28 -0
- package/lib/WABinary/jid-utils.js +95 -0
- package/lib/WABinary/types.d.ts +1 -0
- package/lib/WABinary/types.js +1 -0
- package/lib/WACrypto/appstate-keys.js +26 -0
- package/lib/WACrypto/curves/constants.js +12 -0
- package/lib/WACrypto/hkdf.js +27 -0
- package/lib/WACrypto/index.js +20 -0
- package/lib/WACrypto/lthash.js +54 -0
- package/lib/WACrypto/math/constants.js +24 -0
- package/lib/WACrypto/math/edwards.js +194 -0
- package/lib/WACrypto/math/fe.js +698 -0
- package/lib/WACrypto/math/le.js +23 -0
- package/lib/WACrypto/math/mod.js +15 -0
- package/lib/WACrypto/util/bytes.js +339 -0
- package/lib/WACrypto/x25519.js +145 -0
- package/lib/WACrypto/xeddsa.js +92 -0
- package/lib/WAM/BinaryInfo.d.ts +7 -0
- package/lib/WAM/BinaryInfo.js +9 -0
- package/lib/WAM/constants.d.ts +34926 -0
- package/lib/WAM/constants.js +22852 -0
- package/lib/WAM/encode.d.ts +1 -0
- package/lib/WAM/encode.js +149 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +3 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +51 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
- package/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/lib/WAUSync/Protocols/index.js +5 -0
- package/lib/WAUSync/USyncQuery.d.ts +20 -0
- package/lib/WAUSync/USyncQuery.js +97 -0
- package/lib/WAUSync/USyncUser.d.ts +16 -0
- package/lib/WAUSync/USyncUser.js +30 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +3 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +11 -0
- package/package.json +74 -5
- package/tests/addon-test.mjs +162 -0
- package/tests/differential-test.mjs +90 -0
|
@@ -0,0 +1,1667 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var messages_exports = {};
|
|
19
|
+
__export(messages_exports, {
|
|
20
|
+
aggregateMessageKeysNotFromMe: () => aggregateMessageKeysNotFromMe,
|
|
21
|
+
assertMediaContent: () => assertMediaContent,
|
|
22
|
+
downloadMediaMessage: () => downloadMediaMessage,
|
|
23
|
+
extractMessageContent: () => extractMessageContent,
|
|
24
|
+
extractUrlFromText: () => extractUrlFromText,
|
|
25
|
+
generateForwardMessageContent: () => generateForwardMessageContent,
|
|
26
|
+
generateLinkPreviewIfRequired: () => generateLinkPreviewIfRequired,
|
|
27
|
+
generateWAMessage: () => generateWAMessage,
|
|
28
|
+
generateWAMessageContent: () => generateWAMessageContent,
|
|
29
|
+
generateWAMessageFromContent: () => generateWAMessageFromContent,
|
|
30
|
+
getAggregateResponsesInEventMessage: () => getAggregateResponsesInEventMessage,
|
|
31
|
+
getAggregateVotesInPollMessage: () => getAggregateVotesInPollMessage,
|
|
32
|
+
getContentType: () => getContentType,
|
|
33
|
+
getDevice: () => getDevice,
|
|
34
|
+
hasNonNullishProperty: () => hasNonNullishProperty,
|
|
35
|
+
hasOptionalProperty: () => hasOptionalProperty,
|
|
36
|
+
hasValidAlbumMedia: () => hasValidAlbumMedia,
|
|
37
|
+
hasValidCarouselHeader: () => hasValidCarouselHeader,
|
|
38
|
+
hasValidInteractiveHeader: () => hasValidInteractiveHeader,
|
|
39
|
+
isViewOnceMessage: () => isViewOnceMessage,
|
|
40
|
+
markViewOnce: () => markViewOnce,
|
|
41
|
+
normalizeMessageContent: () => normalizeMessageContent,
|
|
42
|
+
prepareDisappearingMessageSettingContent: () => prepareDisappearingMessageSettingContent,
|
|
43
|
+
prepareWAMessageMedia: () => prepareWAMessageMedia,
|
|
44
|
+
shouldIncludeBizBinaryNode: () => shouldIncludeBizBinaryNode,
|
|
45
|
+
updateMessageWithEventResponse: () => updateMessageWithEventResponse,
|
|
46
|
+
updateMessageWithPollUpdate: () => updateMessageWithPollUpdate,
|
|
47
|
+
updateMessageWithReaction: () => updateMessageWithReaction,
|
|
48
|
+
updateMessageWithReceipt: () => updateMessageWithReceipt
|
|
49
|
+
});
|
|
50
|
+
module.exports = __toCommonJS(messages_exports);
|
|
51
|
+
var import_node_crypto = require("node:crypto");
|
|
52
|
+
var import_node_fs = require("node:fs");
|
|
53
|
+
var import_WAProto = require("../../WAProto/index.js");
|
|
54
|
+
var import_Addon = require("../Addon/index.js");
|
|
55
|
+
var import_Defaults = require("../Defaults/index.js");
|
|
56
|
+
var import_Types = require("../Types/index.js");
|
|
57
|
+
var import_WABinary = require("../WABinary/index.js");
|
|
58
|
+
var import_crypto = require("./crypto.js");
|
|
59
|
+
var import_generics = require("./generics.js");
|
|
60
|
+
var import_messages_media = require("./messages-media.js");
|
|
61
|
+
var import_rich_message_utils = require("./rich-message-utils.js");
|
|
62
|
+
var import_reporting_utils = require("./reporting-utils.js");
|
|
63
|
+
const MIMETYPE_MAP = {
|
|
64
|
+
image: "image/jpeg",
|
|
65
|
+
video: "video/mp4",
|
|
66
|
+
document: "application/pdf",
|
|
67
|
+
audio: "audio/ogg; codecs=opus",
|
|
68
|
+
sticker: "image/webp",
|
|
69
|
+
"product-catalog-image": "image/jpeg"
|
|
70
|
+
};
|
|
71
|
+
const extractUrlFromText = (text) => text.match(import_Defaults.URL_REGEX)?.[0];
|
|
72
|
+
const generateLinkPreviewIfRequired = async (text, getUrlInfo, logger) => {
|
|
73
|
+
const url = extractUrlFromText(text);
|
|
74
|
+
if (!!getUrlInfo && url) {
|
|
75
|
+
try {
|
|
76
|
+
const urlInfo = await getUrlInfo(url);
|
|
77
|
+
return urlInfo;
|
|
78
|
+
} catch (error) {
|
|
79
|
+
logger?.warn({ trace: error.stack }, "url generation failed");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const ensureMessageProto = (m) => {
|
|
84
|
+
if (m instanceof import_Types.WAProto.Message)
|
|
85
|
+
return m;
|
|
86
|
+
return import_Types.WAProto.Message.fromObject(m);
|
|
87
|
+
};
|
|
88
|
+
const assertColor = (color) => {
|
|
89
|
+
if (typeof color === "number") {
|
|
90
|
+
return color < 0 ? 4294967295 + color + 1 : color;
|
|
91
|
+
}
|
|
92
|
+
let hex = color.trim();
|
|
93
|
+
if (hex.charCodeAt(0) === 35) {
|
|
94
|
+
hex = hex.slice(1);
|
|
95
|
+
}
|
|
96
|
+
if (hex.length <= 6) {
|
|
97
|
+
hex = hex.padStart(6, "0");
|
|
98
|
+
hex = "FF" + hex;
|
|
99
|
+
}
|
|
100
|
+
return parseInt(hex, 16);
|
|
101
|
+
};
|
|
102
|
+
const prepareWAMessageMedia = async (message, options) => {
|
|
103
|
+
const logger = options.logger;
|
|
104
|
+
let mediaType;
|
|
105
|
+
for (const key of import_Defaults.MEDIA_KEYS) {
|
|
106
|
+
if (key in message) {
|
|
107
|
+
mediaType = key;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (!mediaType) {
|
|
112
|
+
throw new import_Addon.HttpError("Invalid media type", { statusCode: 400 });
|
|
113
|
+
}
|
|
114
|
+
const uploadData = {
|
|
115
|
+
...message,
|
|
116
|
+
media: message[mediaType]
|
|
117
|
+
};
|
|
118
|
+
delete uploadData[mediaType];
|
|
119
|
+
const cacheableKey = typeof uploadData.media === "object" && "url" in uploadData.media && !!uploadData.media.url && !!options.mediaCache && mediaType + ":" + uploadData.media.url.toString();
|
|
120
|
+
if (mediaType === "document" && !uploadData.fileName) {
|
|
121
|
+
uploadData.fileName = import_Defaults.LIBRARY_NAME;
|
|
122
|
+
}
|
|
123
|
+
if (cacheableKey) {
|
|
124
|
+
const mediaBuff = await options.mediaCache.get(cacheableKey);
|
|
125
|
+
if (mediaBuff) {
|
|
126
|
+
logger?.debug({ cacheableKey }, "got media cache hit");
|
|
127
|
+
const obj2 = import_WAProto.proto.Message.decode(mediaBuff);
|
|
128
|
+
const key = `${mediaType}Message`;
|
|
129
|
+
Object.assign(obj2[key], { ...uploadData, media: void 0 });
|
|
130
|
+
return obj2;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const isNewsletter = (0, import_WABinary.isJidNewsletter)(options.jid);
|
|
134
|
+
const requiresMimetypeDetection = uploadData.mimetype == null;
|
|
135
|
+
const requiresThumbnailComputation = (mediaType === "image" || mediaType === "video") && uploadData.jpegThumbnail == null;
|
|
136
|
+
const requiresDurationComputation = mediaType === "audio" && uploadData.seconds == null;
|
|
137
|
+
const requiresWaveformProcessing = mediaType === "audio" && uploadData.ptt === true && uploadData.waveform == null;
|
|
138
|
+
const requiresAudioBackground = options.backgroundColor && mediaType === "audio" && uploadData.ptt === true;
|
|
139
|
+
if (isNewsletter) {
|
|
140
|
+
logger?.info({ key: cacheableKey }, "Preparing raw media for newsletter");
|
|
141
|
+
const { filePath, fileSha256: fileSha2562, fileLength: fileLength2 } = await (0, import_messages_media.getRawMediaUploadData)(uploadData.media, options.mediaTypeOverride || mediaType, logger);
|
|
142
|
+
const fileSha256B64 = fileSha2562.toString("base64");
|
|
143
|
+
const [{ mediaUrl: mediaUrl2, directPath: directPath2, thumbnailDirectPath, thumbnailSha256 }] = await Promise.all([
|
|
144
|
+
(async () => {
|
|
145
|
+
const result = await options.upload(filePath, {
|
|
146
|
+
fileEncSha256B64: fileSha256B64,
|
|
147
|
+
mediaType,
|
|
148
|
+
timeoutMs: options.mediaUploadTimeoutMs,
|
|
149
|
+
newsletter: isNewsletter
|
|
150
|
+
});
|
|
151
|
+
logger?.debug({ mediaType, cacheableKey }, "uploaded media");
|
|
152
|
+
return result;
|
|
153
|
+
})(),
|
|
154
|
+
(async () => {
|
|
155
|
+
try {
|
|
156
|
+
if (requiresMimetypeDetection) {
|
|
157
|
+
const { mime } = uploadData.ptt === true ? { mime: MIMETYPE_MAP["audio"] } : await (0, import_Addon.detectFileType)(filePath);
|
|
158
|
+
uploadData.mimetype = mime || MIMETYPE_MAP[mediaType];
|
|
159
|
+
logger?.debug("detected media mime");
|
|
160
|
+
}
|
|
161
|
+
if (requiresDurationComputation || requiresWaveformProcessing) {
|
|
162
|
+
const computedData = await (0, import_messages_media.getAudioData)(filePath, logger);
|
|
163
|
+
uploadData.seconds = computedData.durationSeconds;
|
|
164
|
+
uploadData.waveform = computedData.waveform;
|
|
165
|
+
logger?.debug("computed audio data");
|
|
166
|
+
}
|
|
167
|
+
if (requiresAudioBackground) {
|
|
168
|
+
uploadData.backgroundArgb = assertColor(options.backgroundColor);
|
|
169
|
+
logger?.debug("computed backgroundColor audio");
|
|
170
|
+
}
|
|
171
|
+
} catch (error) {
|
|
172
|
+
logger?.warn({ trace: error.stack }, "failed to obtain extra info");
|
|
173
|
+
}
|
|
174
|
+
})
|
|
175
|
+
]).finally(async () => {
|
|
176
|
+
try {
|
|
177
|
+
await import_node_fs.promises.unlink(filePath);
|
|
178
|
+
logger?.debug("removed tmp files");
|
|
179
|
+
} catch (error) {
|
|
180
|
+
logger?.warn("failed to remove tmp file");
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
const obj2 = ensureMessageProto({
|
|
184
|
+
// todo: add more support here
|
|
185
|
+
[`${mediaType}Message`]: {
|
|
186
|
+
url: mediaUrl2,
|
|
187
|
+
directPath: directPath2,
|
|
188
|
+
fileSha256: fileSha2562,
|
|
189
|
+
fileLength: fileLength2,
|
|
190
|
+
thumbnailDirectPath,
|
|
191
|
+
thumbnailSha256,
|
|
192
|
+
...uploadData,
|
|
193
|
+
media: void 0
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
if (uploadData.ptv) {
|
|
197
|
+
obj2.ptvMessage = obj2.videoMessage;
|
|
198
|
+
delete obj2.videoMessage;
|
|
199
|
+
}
|
|
200
|
+
if (obj2.stickerMessage) {
|
|
201
|
+
obj2.stickerMessage.stickerSentTs = Date.now();
|
|
202
|
+
}
|
|
203
|
+
if (cacheableKey) {
|
|
204
|
+
logger?.debug({ cacheableKey }, "set cache");
|
|
205
|
+
await options.mediaCache.set(cacheableKey, import_Types.WAProto.Message.encode(obj2).finish());
|
|
206
|
+
}
|
|
207
|
+
return obj2;
|
|
208
|
+
}
|
|
209
|
+
const requiresOriginalForSomeProcessing = requiresMimetypeDetection || requiresDurationComputation || requiresWaveformProcessing || requiresThumbnailComputation;
|
|
210
|
+
const { mediaKey, encFilePath, originalFilePath, fileEncSha256, fileSha256, fileLength } = await (0, import_messages_media.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
|
|
211
|
+
logger,
|
|
212
|
+
saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
|
|
213
|
+
opts: options.options
|
|
214
|
+
});
|
|
215
|
+
const fileEncSha256B64 = fileEncSha256.toString("base64");
|
|
216
|
+
const [{ mediaUrl, directPath }] = await Promise.all([
|
|
217
|
+
(async () => {
|
|
218
|
+
const result = await options.upload(encFilePath, {
|
|
219
|
+
fileEncSha256B64,
|
|
220
|
+
mediaType,
|
|
221
|
+
timeoutMs: options.mediaUploadTimeoutMs
|
|
222
|
+
});
|
|
223
|
+
logger?.debug({ mediaType, cacheableKey }, "uploaded media");
|
|
224
|
+
return result;
|
|
225
|
+
})(),
|
|
226
|
+
(async () => {
|
|
227
|
+
try {
|
|
228
|
+
if (requiresThumbnailComputation) {
|
|
229
|
+
const { thumbnail, originalImageDimensions } = await (0, import_messages_media.generateThumbnail)(originalFilePath, mediaType, options);
|
|
230
|
+
uploadData.jpegThumbnail = thumbnail;
|
|
231
|
+
if (!uploadData.width && originalImageDimensions) {
|
|
232
|
+
uploadData.width = originalImageDimensions.width;
|
|
233
|
+
uploadData.height = originalImageDimensions.height;
|
|
234
|
+
logger?.debug("set dimensions");
|
|
235
|
+
}
|
|
236
|
+
logger?.debug("generated thumbnail");
|
|
237
|
+
}
|
|
238
|
+
if (requiresMimetypeDetection) {
|
|
239
|
+
const { mime } = uploadData.ptt === true ? { mime: MIMETYPE_MAP["audio"] } : await (0, import_Addon.detectFileType)(originalFilePath);
|
|
240
|
+
uploadData.mimetype = mime || MIMETYPE_MAP[mediaType];
|
|
241
|
+
logger?.debug("detected media mime");
|
|
242
|
+
}
|
|
243
|
+
if (requiresDurationComputation || requiresWaveformProcessing) {
|
|
244
|
+
const computedData = await (0, import_messages_media.getAudioData)(originalFilePath, logger);
|
|
245
|
+
uploadData.seconds = computedData.durationSeconds;
|
|
246
|
+
uploadData.waveform = computedData.waveform;
|
|
247
|
+
logger?.debug("computed audio data");
|
|
248
|
+
}
|
|
249
|
+
if (requiresAudioBackground) {
|
|
250
|
+
uploadData.backgroundArgb = assertColor(options.backgroundColor);
|
|
251
|
+
logger?.debug("computed backgroundColor audio");
|
|
252
|
+
}
|
|
253
|
+
} catch (error) {
|
|
254
|
+
logger?.warn({ trace: error.stack }, "failed to obtain extra info");
|
|
255
|
+
}
|
|
256
|
+
})
|
|
257
|
+
]).finally(async () => {
|
|
258
|
+
try {
|
|
259
|
+
await import_node_fs.promises.unlink(encFilePath);
|
|
260
|
+
if (originalFilePath) {
|
|
261
|
+
await import_node_fs.promises.unlink(originalFilePath);
|
|
262
|
+
}
|
|
263
|
+
logger?.debug("removed tmp files");
|
|
264
|
+
} catch (error) {
|
|
265
|
+
logger?.warn("failed to remove tmp file");
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
const obj = ensureMessageProto({
|
|
269
|
+
[`${mediaType}Message`]: {
|
|
270
|
+
url: mediaUrl,
|
|
271
|
+
directPath,
|
|
272
|
+
mediaKey,
|
|
273
|
+
fileEncSha256,
|
|
274
|
+
fileSha256,
|
|
275
|
+
fileLength,
|
|
276
|
+
mediaKeyTimestamp: (0, import_generics.unixTimestampSeconds)(),
|
|
277
|
+
...uploadData,
|
|
278
|
+
media: void 0
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
if (uploadData.ptv) {
|
|
282
|
+
obj.ptvMessage = obj.videoMessage;
|
|
283
|
+
delete obj.videoMessage;
|
|
284
|
+
}
|
|
285
|
+
if (cacheableKey) {
|
|
286
|
+
logger?.debug({ cacheableKey }, "set cache");
|
|
287
|
+
await options.mediaCache.set(cacheableKey, import_Types.WAProto.Message.encode(obj).finish());
|
|
288
|
+
}
|
|
289
|
+
return obj;
|
|
290
|
+
};
|
|
291
|
+
const prepareProductMessage = async (message, options) => {
|
|
292
|
+
if (!message.businessOwnerJid) {
|
|
293
|
+
throw new import_Addon.HttpError('"businessOwnerJid" is missing from the content', { statusCode: 400 });
|
|
294
|
+
}
|
|
295
|
+
const { imageMessage } = await prepareWAMessageMedia({ image: message.image || message.product.productImage }, options);
|
|
296
|
+
const { image, ...content } = message;
|
|
297
|
+
content.product = {
|
|
298
|
+
currencyCode: "IDR",
|
|
299
|
+
priceAmount1000: 1e3,
|
|
300
|
+
title: import_Defaults.LIBRARY_NAME,
|
|
301
|
+
...message.product,
|
|
302
|
+
productImage: imageMessage
|
|
303
|
+
};
|
|
304
|
+
return content;
|
|
305
|
+
};
|
|
306
|
+
const prepareStickerPackMessage = async (message, options) => {
|
|
307
|
+
const { cover, stickers = [], name = "\u{1F4E6} Sticker Pack", publisher = "GitHub: eduh_dev021", description = "\u{1F3F7}\uFE0F eduh_dev021/baileys" } = message;
|
|
308
|
+
if (stickers.length > 60) {
|
|
309
|
+
throw new import_Addon.HttpError("Sticker pack exceeds the maximum limit of 60 stickers", { statusCode: 400 });
|
|
310
|
+
}
|
|
311
|
+
if (stickers.length === 0) {
|
|
312
|
+
throw new import_Addon.HttpError("Sticker pack must contain at least one sticker", { statusCode: 400 });
|
|
313
|
+
}
|
|
314
|
+
if (!cover) {
|
|
315
|
+
throw new import_Addon.HttpError("Sticker pack must contain a cover", { statusCode: 400 });
|
|
316
|
+
}
|
|
317
|
+
const logger = options.logger;
|
|
318
|
+
let cacheableKey = false;
|
|
319
|
+
if (Array.isArray(stickers) && stickers.length && options.mediaCache) {
|
|
320
|
+
const urls = [];
|
|
321
|
+
for (let i = 0; i < stickers.length; i++) {
|
|
322
|
+
const data = stickers[i].data;
|
|
323
|
+
if (typeof data === "object" && data?.url) {
|
|
324
|
+
urls.push(data.url);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
if (urls.length > 0) {
|
|
328
|
+
cacheableKey = "sticker:" + urls.join("@");
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (cacheableKey) {
|
|
332
|
+
const mediaBuff = await options.mediaCache.get(cacheableKey);
|
|
333
|
+
if (mediaBuff) {
|
|
334
|
+
logger?.debug({ cacheableKey }, "got media cache hit");
|
|
335
|
+
return import_WAProto.proto.Message.decode(mediaBuff);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
const lib = await (0, import_messages_media.getImageProcessingLibrary)();
|
|
339
|
+
const hasSharp = "sharp" in lib && !!lib.sharp?.default;
|
|
340
|
+
const hasImage = "image" in lib && !!lib.image?.Transformer;
|
|
341
|
+
const hasJimp = "jimp" in lib && !!lib.jimp?.Jimp;
|
|
342
|
+
if (!hasSharp && !hasImage) {
|
|
343
|
+
throw new import_Addon.HttpError("No image processing library (sharp or @napi-rs/image) available for converting sticker to WebP.");
|
|
344
|
+
}
|
|
345
|
+
const isNewsletter = (0, import_WABinary.isJidNewsletter)(options.jid);
|
|
346
|
+
const stickerPackIdValue = (0, import_generics.generateMessageIDV2)();
|
|
347
|
+
const stickerData = new Array(stickers.length);
|
|
348
|
+
const stickerMetadata = new Array(stickers.length);
|
|
349
|
+
await Promise.all(stickers.map(async (sticker, index) => {
|
|
350
|
+
const { stream } = await (0, import_messages_media.getStream)(sticker.data);
|
|
351
|
+
const buffer = await (0, import_messages_media.toBuffer)(stream);
|
|
352
|
+
let webpBuffer;
|
|
353
|
+
let isAnimated = false;
|
|
354
|
+
if (isWebPBuffer(buffer)) {
|
|
355
|
+
webpBuffer = buffer;
|
|
356
|
+
isAnimated = isAnimatedWebP(buffer);
|
|
357
|
+
} else if (hasSharp) {
|
|
358
|
+
webpBuffer = await lib.sharp.default(buffer).resize(512, 512, { fit: "inside" }).webp({ quality: 80 }).toBuffer();
|
|
359
|
+
} else {
|
|
360
|
+
webpBuffer = await new lib.image.Transformer(buffer).resize(512, 512).webp(80);
|
|
361
|
+
}
|
|
362
|
+
if (webpBuffer.length > 1024 * 1024) {
|
|
363
|
+
throw new import_Addon.HttpError(`Sticker at index ${index} exceeds the 1MB size limit`, { statusCode: 400 });
|
|
364
|
+
}
|
|
365
|
+
const hash = (0, import_crypto.sha256)(webpBuffer).toString("base64").replace(/\//g, "-");
|
|
366
|
+
const fileName = `${hash}.webp`;
|
|
367
|
+
stickerData[index] = {
|
|
368
|
+
name: fileName,
|
|
369
|
+
data: webpBuffer
|
|
370
|
+
};
|
|
371
|
+
stickerMetadata[index] = {
|
|
372
|
+
fileName,
|
|
373
|
+
mimetype: "image/webp",
|
|
374
|
+
isAnimated,
|
|
375
|
+
isLottie: sticker.isLottie || false,
|
|
376
|
+
emojis: sticker.emojis || ["\u2728"],
|
|
377
|
+
accessibilityLabel: sticker.accessibilityLabel || "\u200E"
|
|
378
|
+
};
|
|
379
|
+
}));
|
|
380
|
+
const trayIconFileName = `${stickerPackIdValue}.webp`;
|
|
381
|
+
const { stream: coverStream } = await (0, import_messages_media.getStream)(cover);
|
|
382
|
+
const coverBuffer = await (0, import_messages_media.toBuffer)(coverStream);
|
|
383
|
+
let coverWebpBuffer;
|
|
384
|
+
if (isWebPBuffer(coverBuffer)) {
|
|
385
|
+
coverWebpBuffer = coverBuffer;
|
|
386
|
+
} else if (hasSharp) {
|
|
387
|
+
coverWebpBuffer = await lib.sharp.default(coverBuffer).resize(512, 512, { fit: "inside" }).webp({ quality: 80 }).toBuffer();
|
|
388
|
+
} else {
|
|
389
|
+
coverWebpBuffer = await new lib.image.Transformer(coverBuffer).resize(512, 512).webp(80);
|
|
390
|
+
}
|
|
391
|
+
stickerData[stickers.length] = {
|
|
392
|
+
name: trayIconFileName,
|
|
393
|
+
data: coverWebpBuffer
|
|
394
|
+
};
|
|
395
|
+
const zipBuffer = await (0, import_Addon.createZip)(stickerData);
|
|
396
|
+
const { encFilePath, filePath, fileEncSha256, fileSha256, mediaKey, fileLength } = isNewsletter ? await (0, import_messages_media.getRawMediaUploadData)(zipBuffer, "sticker-pack", logger) : await (0, import_messages_media.encryptedStream)(zipBuffer, "sticker-pack", {
|
|
397
|
+
logger,
|
|
398
|
+
opts: options.options
|
|
399
|
+
});
|
|
400
|
+
let stickerPackUploadResult;
|
|
401
|
+
try {
|
|
402
|
+
stickerPackUploadResult = await options.upload(encFilePath || filePath, {
|
|
403
|
+
fileEncSha256B64: (fileEncSha256 || fileSha256).toString("base64"),
|
|
404
|
+
mediaType: "sticker-pack",
|
|
405
|
+
timeoutMs: options.mediaUploadTimeoutMs,
|
|
406
|
+
newsletter: isNewsletter
|
|
407
|
+
});
|
|
408
|
+
} finally {
|
|
409
|
+
await import_node_fs.promises.unlink(encFilePath || filePath).catch(() => logger?.warn("failed to remove tmp file"));
|
|
410
|
+
}
|
|
411
|
+
const obj = {
|
|
412
|
+
name,
|
|
413
|
+
publisher,
|
|
414
|
+
stickerPackId: stickerPackIdValue,
|
|
415
|
+
packDescription: description,
|
|
416
|
+
stickerPackOrigin: import_WAProto.proto.Message.StickerPackMessage.StickerPackOrigin.USER_CREATED,
|
|
417
|
+
stickerPackSize: zipBuffer.length,
|
|
418
|
+
stickers: stickerMetadata,
|
|
419
|
+
fileSha256,
|
|
420
|
+
fileEncSha256,
|
|
421
|
+
mediaKey,
|
|
422
|
+
directPath: stickerPackUploadResult.directPath,
|
|
423
|
+
fileLength,
|
|
424
|
+
mediaKeyTimestamp: (0, import_generics.unixTimestampSeconds)(),
|
|
425
|
+
trayIconFileName
|
|
426
|
+
};
|
|
427
|
+
try {
|
|
428
|
+
let thumbnailBuffer;
|
|
429
|
+
if (hasSharp) {
|
|
430
|
+
thumbnailBuffer = await lib.sharp.default(coverBuffer).resize(252, 252).jpeg().toBuffer();
|
|
431
|
+
} else if (hasImage) {
|
|
432
|
+
thumbnailBuffer = await new lib.image.Transformer(coverBuffer).resize(252, 252).jpeg();
|
|
433
|
+
} else if (hasJimp) {
|
|
434
|
+
const jimpImage = await lib.jimp.Jimp.read(coverBuffer);
|
|
435
|
+
thumbnailBuffer = await jimpImage.resize({ w: 252, h: 252 }).getBuffer("image/jpeg");
|
|
436
|
+
} else {
|
|
437
|
+
throw new Error("No image processing library available for thumbnail generation");
|
|
438
|
+
}
|
|
439
|
+
if (!thumbnailBuffer || thumbnailBuffer.length === 0) {
|
|
440
|
+
throw new Error("Failed to generate thumbnail buffer");
|
|
441
|
+
}
|
|
442
|
+
const thumbUpload = isNewsletter ? await await (0, import_messages_media.getRawMediaUploadData)(thumbnailBuffer, "thumbnail-sticker-pack", logger) : await (0, import_messages_media.encryptedStream)(thumbnailBuffer, "thumbnail-sticker-pack", {
|
|
443
|
+
logger,
|
|
444
|
+
opts: options.options,
|
|
445
|
+
mediaKey
|
|
446
|
+
});
|
|
447
|
+
let thumbUploadResult;
|
|
448
|
+
try {
|
|
449
|
+
thumbUploadResult = await options.upload(thumbUpload.encFilePath || thumbUpload.filePath, {
|
|
450
|
+
fileEncSha256B64: (thumbUpload.fileEncSha256 || thumbUpload.fileSha256).toString("base64"),
|
|
451
|
+
mediaType: "thumbnail-sticker-pack",
|
|
452
|
+
timeoutMs: options.mediaUploadTimeoutMs,
|
|
453
|
+
newsletter: isNewsletter
|
|
454
|
+
});
|
|
455
|
+
} finally {
|
|
456
|
+
await import_node_fs.promises.unlink(thumbUpload.encFilePath || thumbUpload.filePath).catch(() => logger?.warn("failed to remove tmp file"));
|
|
457
|
+
}
|
|
458
|
+
Object.assign(obj, {
|
|
459
|
+
thumbnailDirectPath: thumbUploadResult.directPath,
|
|
460
|
+
thumbnailSha256: thumbUpload.fileSha256,
|
|
461
|
+
thumbnailEncSha256: thumbUpload.fileEncSha256,
|
|
462
|
+
thumbnailHeight: 252,
|
|
463
|
+
thumbnailWidth: 252,
|
|
464
|
+
imageDataHash: (0, import_crypto.sha256)(thumbnailBuffer).toString("base64")
|
|
465
|
+
});
|
|
466
|
+
} catch (error) {
|
|
467
|
+
logger?.warn(`Thumbnail generation failed: ${error}`);
|
|
468
|
+
}
|
|
469
|
+
const payload = ensureMessageProto({ stickerPackMessage: obj });
|
|
470
|
+
if (cacheableKey) {
|
|
471
|
+
logger?.debug({ cacheableKey }, "set cache (background)");
|
|
472
|
+
options.mediaCache.set(cacheableKey, import_Types.WAProto.Message.encode(payload).finish());
|
|
473
|
+
}
|
|
474
|
+
return payload;
|
|
475
|
+
};
|
|
476
|
+
const prepareNativeFlowButtons = (message) => {
|
|
477
|
+
const buttons = message.nativeFlow;
|
|
478
|
+
const isButtonsFieldArray = Array.isArray(buttons);
|
|
479
|
+
const correctedField = isButtonsFieldArray ? buttons : buttons.buttons;
|
|
480
|
+
const messageParamsJson = {};
|
|
481
|
+
if (hasOptionalProperty(message, "offerText") && !!message.offerText) {
|
|
482
|
+
Object.assign(messageParamsJson, {
|
|
483
|
+
limited_time_offer: {
|
|
484
|
+
text: message.offerText || import_Defaults.LIBRARY_NAME,
|
|
485
|
+
url: message.offerUrl || import_Defaults.DONATE_URL,
|
|
486
|
+
// Apologies if this feels cheeky, just a fallback
|
|
487
|
+
copy_code: message.offerCode,
|
|
488
|
+
expiration_time: message.offerExpiration
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
if (hasOptionalProperty(message, "optionText") && !!message.optionText) {
|
|
493
|
+
Object.assign(messageParamsJson, {
|
|
494
|
+
bottom_sheet: {
|
|
495
|
+
in_thread_buttons_limit: 1,
|
|
496
|
+
divider_indices: Array.from({ length: correctedField.length }, (_, index) => index),
|
|
497
|
+
list_title: message.optionTitle || "\u{1F4C4} Select Options",
|
|
498
|
+
button_title: message.optionText
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
return {
|
|
503
|
+
buttons: correctedField.map((button) => {
|
|
504
|
+
const buttonText = button.text || button.buttonText;
|
|
505
|
+
const buttonIcon = button.icon?.toUpperCase();
|
|
506
|
+
if (hasOptionalProperty(button, "id") && !!button.id) {
|
|
507
|
+
return {
|
|
508
|
+
name: "quick_reply",
|
|
509
|
+
buttonParamsJson: JSON.stringify({
|
|
510
|
+
display_text: buttonText || "\u{1F449}\u{1F3FB} Click",
|
|
511
|
+
id: button.id,
|
|
512
|
+
icon: buttonIcon
|
|
513
|
+
})
|
|
514
|
+
};
|
|
515
|
+
} else if (hasOptionalProperty(button, "copy") && !!button.copy) {
|
|
516
|
+
return {
|
|
517
|
+
name: "cta_copy",
|
|
518
|
+
buttonParamsJson: JSON.stringify({
|
|
519
|
+
display_text: buttonText || "\u{1F4CB} Copy",
|
|
520
|
+
copy_code: button.copy,
|
|
521
|
+
icon: buttonIcon
|
|
522
|
+
})
|
|
523
|
+
};
|
|
524
|
+
} else if (hasOptionalProperty(button, "url") && !!button.url) {
|
|
525
|
+
return {
|
|
526
|
+
name: "cta_url",
|
|
527
|
+
buttonParamsJson: JSON.stringify({
|
|
528
|
+
display_text: buttonText || "\u{1F310} Visit",
|
|
529
|
+
url: button.url,
|
|
530
|
+
merchant_url: button.url,
|
|
531
|
+
webview_interaction: button.useWebview,
|
|
532
|
+
icon: buttonIcon
|
|
533
|
+
})
|
|
534
|
+
};
|
|
535
|
+
} else if (hasOptionalProperty(button, "call") && !!button.call) {
|
|
536
|
+
return {
|
|
537
|
+
name: "cta_call",
|
|
538
|
+
buttonParamsJson: JSON.stringify({
|
|
539
|
+
display_text: buttonText || "\u{1F4DE} Call",
|
|
540
|
+
phone_number: button.call,
|
|
541
|
+
icon: buttonIcon
|
|
542
|
+
})
|
|
543
|
+
};
|
|
544
|
+
} else if (hasOptionalProperty(button, "sections") && !!button.sections) {
|
|
545
|
+
return {
|
|
546
|
+
name: "single_select",
|
|
547
|
+
buttonParamsJson: JSON.stringify({
|
|
548
|
+
title: buttonText || "\u{1F4CB} Select",
|
|
549
|
+
sections: button.sections,
|
|
550
|
+
icon: buttonIcon
|
|
551
|
+
})
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
return button;
|
|
555
|
+
}),
|
|
556
|
+
messageParamsJson: JSON.stringify(messageParamsJson)
|
|
557
|
+
};
|
|
558
|
+
};
|
|
559
|
+
const prepareDisappearingMessageSettingContent = (ephemeralExpiration) => {
|
|
560
|
+
ephemeralExpiration = ephemeralExpiration || 0;
|
|
561
|
+
const content = {
|
|
562
|
+
ephemeralMessage: {
|
|
563
|
+
message: {
|
|
564
|
+
protocolMessage: {
|
|
565
|
+
type: import_Types.WAProto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING,
|
|
566
|
+
ephemeralExpiration
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
return ensureMessageProto(content);
|
|
572
|
+
};
|
|
573
|
+
const generateForwardMessageContent = (message, forceForward) => {
|
|
574
|
+
let content = message.message;
|
|
575
|
+
if (!content) {
|
|
576
|
+
throw new import_Addon.HttpError("no content in message", { statusCode: 400 });
|
|
577
|
+
}
|
|
578
|
+
content = normalizeMessageContent(content);
|
|
579
|
+
content = import_WAProto.proto.Message.decode(import_WAProto.proto.Message.encode(content).finish());
|
|
580
|
+
let key = Object.keys(content)[0];
|
|
581
|
+
let score = content?.[key]?.contextInfo?.forwardingScore || 0;
|
|
582
|
+
score += message.key.fromMe && !forceForward ? 0 : 1;
|
|
583
|
+
if (key === "conversation") {
|
|
584
|
+
content.extendedTextMessage = { text: content[key] };
|
|
585
|
+
delete content.conversation;
|
|
586
|
+
key = "extendedTextMessage";
|
|
587
|
+
}
|
|
588
|
+
const key_ = content?.[key];
|
|
589
|
+
if (score > 0) {
|
|
590
|
+
key_.contextInfo = { forwardingScore: score, isForwarded: true };
|
|
591
|
+
} else {
|
|
592
|
+
key_.contextInfo = {};
|
|
593
|
+
}
|
|
594
|
+
return content;
|
|
595
|
+
};
|
|
596
|
+
const hasNonNullishProperty = (message, key) => {
|
|
597
|
+
return message != null && typeof message === "object" && key in message && message[key] != null;
|
|
598
|
+
};
|
|
599
|
+
const hasOptionalProperty = (obj, key) => {
|
|
600
|
+
return obj != null && typeof obj === "object" && key in obj && obj[key] != null;
|
|
601
|
+
};
|
|
602
|
+
const hasValidAlbumMedia = (message) => {
|
|
603
|
+
return !!(message.imageMessage || message.videoMessage);
|
|
604
|
+
};
|
|
605
|
+
const hasValidInteractiveHeader = (message) => {
|
|
606
|
+
return !!(message.imageMessage || message.videoMessage || message.documentMessage || message.productMessage || message.locationMessage);
|
|
607
|
+
};
|
|
608
|
+
const hasValidCarouselHeader = (message) => {
|
|
609
|
+
return !!(message.imageMessage || message.videoMessage || message.productMessage);
|
|
610
|
+
};
|
|
611
|
+
const markViewOnce = (m) => {
|
|
612
|
+
const type = getContentType(m);
|
|
613
|
+
if (!type)
|
|
614
|
+
return;
|
|
615
|
+
const content = m[type];
|
|
616
|
+
if (!content || typeof content !== "object")
|
|
617
|
+
return;
|
|
618
|
+
const MessageType = import_Types.WAProto.Message[type.charAt(0).toUpperCase() + type.slice(1)];
|
|
619
|
+
if (!MessageType?.prototype || !("viewOnce" in MessageType.prototype))
|
|
620
|
+
return;
|
|
621
|
+
content.viewOnce = true;
|
|
622
|
+
};
|
|
623
|
+
const generateWAMessageContent = async (message, options) => {
|
|
624
|
+
var _a, _b;
|
|
625
|
+
let m = {};
|
|
626
|
+
if (hasNonNullishProperty(message, "raw")) {
|
|
627
|
+
delete message.raw;
|
|
628
|
+
return message;
|
|
629
|
+
} else if (hasNonNullishProperty(message, "code") || hasNonNullishProperty(message, "links") || hasNonNullishProperty(message, "table") || hasNonNullishProperty(message, "richResponse")) {
|
|
630
|
+
m = (0, import_rich_message_utils.prepareRichResponseMessage)(message);
|
|
631
|
+
} else if (hasNonNullishProperty(message, "text")) {
|
|
632
|
+
const extContent = { text: message.text };
|
|
633
|
+
let urlInfo = message.linkPreview;
|
|
634
|
+
if (urlInfo == null) {
|
|
635
|
+
urlInfo = await generateLinkPreviewIfRequired(message.text, options.getUrlInfo, options.logger);
|
|
636
|
+
}
|
|
637
|
+
if (urlInfo) {
|
|
638
|
+
extContent.matchedText = urlInfo["matched-text"];
|
|
639
|
+
extContent.jpegThumbnail = urlInfo.jpegThumbnail;
|
|
640
|
+
extContent.description = urlInfo.description;
|
|
641
|
+
extContent.title = urlInfo.title;
|
|
642
|
+
extContent.previewType = urlInfo.previewType ?? urlInfo["preview-type"] ?? 0;
|
|
643
|
+
extContent.linkPreviewMetadata = urlInfo.linkPreviewMetadata;
|
|
644
|
+
const img = urlInfo.highQualityThumbnail;
|
|
645
|
+
if (img) {
|
|
646
|
+
extContent.thumbnailDirectPath = img.directPath;
|
|
647
|
+
extContent.mediaKey = img.mediaKey;
|
|
648
|
+
extContent.mediaKeyTimestamp = img.mediaKeyTimestamp;
|
|
649
|
+
extContent.thumbnailWidth = img.width;
|
|
650
|
+
extContent.thumbnailHeight = img.height;
|
|
651
|
+
extContent.thumbnailSha256 = img.fileSha256;
|
|
652
|
+
extContent.thumbnailEncSha256 = img.fileEncSha256;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
const customFavicon = message.favicon;
|
|
656
|
+
const favicon = customFavicon && typeof options.upload === "function" ? (await prepareWAMessageMedia({ image: customFavicon }, options)).imageMessage : urlInfo?.favicon;
|
|
657
|
+
if (favicon) {
|
|
658
|
+
extContent.faviconMmsMetadata = {
|
|
659
|
+
thumbnailDirectPath: favicon.directPath,
|
|
660
|
+
mediaKey: favicon.mediaKey,
|
|
661
|
+
mediaKeyTimestamp: favicon.mediaKeyTimestamp,
|
|
662
|
+
thumbnailWidth: 32,
|
|
663
|
+
thumbnailHeight: 32,
|
|
664
|
+
thumbnailSha256: favicon.fileSha256,
|
|
665
|
+
thumbnailEncSha256: favicon.fileEncSha256
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
if (options.backgroundColor) {
|
|
669
|
+
extContent.backgroundArgb = assertColor(options.backgroundColor);
|
|
670
|
+
}
|
|
671
|
+
if (options.font) {
|
|
672
|
+
extContent.font = options.font;
|
|
673
|
+
}
|
|
674
|
+
m.extendedTextMessage = extContent;
|
|
675
|
+
} else if (hasNonNullishProperty(message, "contacts")) {
|
|
676
|
+
const contactLen = message.contacts.contacts.length;
|
|
677
|
+
if (!contactLen) {
|
|
678
|
+
throw new import_Addon.HttpError("require atleast 1 contact", { statusCode: 400 });
|
|
679
|
+
}
|
|
680
|
+
if (contactLen === 1) {
|
|
681
|
+
m.contactMessage = message.contacts.contacts[0];
|
|
682
|
+
} else {
|
|
683
|
+
m.contactsArrayMessage = message.contacts;
|
|
684
|
+
}
|
|
685
|
+
} else if (hasNonNullishProperty(message, "location")) {
|
|
686
|
+
m.locationMessage = message.location;
|
|
687
|
+
} else if (hasNonNullishProperty(message, "react")) {
|
|
688
|
+
if (!message.react.senderTimestampMs) {
|
|
689
|
+
message.react.senderTimestampMs = Date.now();
|
|
690
|
+
}
|
|
691
|
+
m.reactionMessage = message.react;
|
|
692
|
+
} else if (hasNonNullishProperty(message, "delete")) {
|
|
693
|
+
m.protocolMessage = {
|
|
694
|
+
key: message.delete,
|
|
695
|
+
type: import_Types.WAProto.Message.ProtocolMessage.Type.REVOKE
|
|
696
|
+
};
|
|
697
|
+
} else if (hasNonNullishProperty(message, "forward")) {
|
|
698
|
+
m = generateForwardMessageContent(message.forward, message.force);
|
|
699
|
+
} else if (hasNonNullishProperty(message, "disappearingMessagesInChat")) {
|
|
700
|
+
const exp = typeof message.disappearingMessagesInChat === "boolean" ? message.disappearingMessagesInChat ? import_Defaults.WA_DEFAULT_EPHEMERAL : 0 : message.disappearingMessagesInChat;
|
|
701
|
+
m = prepareDisappearingMessageSettingContent(exp);
|
|
702
|
+
} else if (hasNonNullishProperty(message, "groupInvite")) {
|
|
703
|
+
m.groupInviteMessage = {};
|
|
704
|
+
m.groupInviteMessage.inviteCode = message.groupInvite.inviteCode;
|
|
705
|
+
m.groupInviteMessage.inviteExpiration = message.groupInvite.inviteExpiration;
|
|
706
|
+
m.groupInviteMessage.caption = message.groupInvite.text;
|
|
707
|
+
m.groupInviteMessage.groupJid = message.groupInvite.jid;
|
|
708
|
+
m.groupInviteMessage.groupName = message.groupInvite.subject;
|
|
709
|
+
if (options.getProfilePicUrl) {
|
|
710
|
+
const pfpUrl = await options.getProfilePicUrl(message.groupInvite.jid, "preview");
|
|
711
|
+
if (pfpUrl) {
|
|
712
|
+
const resp = await fetch(pfpUrl, { method: "GET", dispatcher: options?.options?.dispatcher });
|
|
713
|
+
if (resp.ok) {
|
|
714
|
+
const buf = Buffer.from(await resp.arrayBuffer());
|
|
715
|
+
m.groupInviteMessage.jpegThumbnail = buf;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
} else if (hasNonNullishProperty(message, "pin")) {
|
|
720
|
+
m.pinInChatMessage = {};
|
|
721
|
+
m.messageContextInfo = {};
|
|
722
|
+
m.pinInChatMessage.key = message.pin;
|
|
723
|
+
m.pinInChatMessage.type = message.type;
|
|
724
|
+
m.pinInChatMessage.senderTimestampMs = Date.now();
|
|
725
|
+
m.messageContextInfo.messageAddOnDurationInSecs = message.type === 1 ? message.time || 86400 : 0;
|
|
726
|
+
} else if (hasNonNullishProperty(message, "keep")) {
|
|
727
|
+
m.keepInChatMessage = {};
|
|
728
|
+
m.keepInChatMessage.key = message.keep;
|
|
729
|
+
m.keepInChatMessage.keepType = message.type;
|
|
730
|
+
m.keepInChatMessage.timestampMs = Date.now();
|
|
731
|
+
} else if (hasNonNullishProperty(message, "flowReply")) {
|
|
732
|
+
m.interactiveResponseMessage = {
|
|
733
|
+
body: {
|
|
734
|
+
format: message.flowReply.format || import_WAProto.proto.Message.InteractiveResponseMessage.Body.Format.DEFAULT,
|
|
735
|
+
text: message.flowReply.text
|
|
736
|
+
},
|
|
737
|
+
nativeFlowResponseMessage: {
|
|
738
|
+
name: message.flowReply.name,
|
|
739
|
+
paramsJson: message.flowReply.paramsJson || "{}",
|
|
740
|
+
version: message.flowReply.version || 1
|
|
741
|
+
}
|
|
742
|
+
};
|
|
743
|
+
} else if (hasNonNullishProperty(message, "buttonReply")) {
|
|
744
|
+
switch (message.type) {
|
|
745
|
+
case "template":
|
|
746
|
+
m.templateButtonReplyMessage = {
|
|
747
|
+
selectedDisplayText: message.buttonReply.displayText,
|
|
748
|
+
selectedId: message.buttonReply.id,
|
|
749
|
+
selectedIndex: message.buttonReply.index
|
|
750
|
+
};
|
|
751
|
+
break;
|
|
752
|
+
case "plain":
|
|
753
|
+
m.buttonsResponseMessage = {
|
|
754
|
+
selectedButtonId: message.buttonReply.id,
|
|
755
|
+
selectedDisplayText: message.buttonReply.displayText,
|
|
756
|
+
type: import_WAProto.proto.Message.ButtonsResponseMessage.Type.DISPLAY_TEXT
|
|
757
|
+
};
|
|
758
|
+
break;
|
|
759
|
+
}
|
|
760
|
+
} else if (hasNonNullishProperty(message, "listReply")) {
|
|
761
|
+
m.listResponseMessage = {
|
|
762
|
+
description: message.listReply.description,
|
|
763
|
+
listType: import_WAProto.proto.Message.ListResponseMessage.ListType.SINGLE_SELECT,
|
|
764
|
+
singleSelectReply: {
|
|
765
|
+
selectedRowId: message.listReply.id
|
|
766
|
+
},
|
|
767
|
+
title: message.listReply.title
|
|
768
|
+
};
|
|
769
|
+
} else if (hasOptionalProperty(message, "ptv") && message.ptv) {
|
|
770
|
+
const { videoMessage } = await prepareWAMessageMedia({ video: message.video }, options);
|
|
771
|
+
m.ptvMessage = videoMessage;
|
|
772
|
+
} else if (hasNonNullishProperty(message, "product")) {
|
|
773
|
+
m.productMessage = await prepareProductMessage(message, options);
|
|
774
|
+
} else if (hasNonNullishProperty(message, "event")) {
|
|
775
|
+
m.eventMessage = {};
|
|
776
|
+
const startTime = Math.floor(message.event.startDate.getTime() / 1e3);
|
|
777
|
+
if (message.event.call && options.getCallLink) {
|
|
778
|
+
const token = await options.getCallLink(message.event.call, { startTime });
|
|
779
|
+
m.eventMessage.joinLink = (message.event.call === "audio" ? import_Defaults.CALL_AUDIO_PREFIX : import_Defaults.CALL_VIDEO_PREFIX) + token;
|
|
780
|
+
}
|
|
781
|
+
m.messageContextInfo = {
|
|
782
|
+
// encKey
|
|
783
|
+
messageSecret: message.event.messageSecret || (0, import_node_crypto.randomBytes)(32)
|
|
784
|
+
};
|
|
785
|
+
m.eventMessage.name = message.event.name;
|
|
786
|
+
m.eventMessage.description = message.event.description;
|
|
787
|
+
m.eventMessage.startTime = startTime;
|
|
788
|
+
m.eventMessage.endTime = message.event.endDate ? message.event.endDate.getTime() / 1e3 : void 0;
|
|
789
|
+
m.eventMessage.isCanceled = message.event.isCancelled ?? false;
|
|
790
|
+
m.eventMessage.extraGuestsAllowed = message.event.extraGuestsAllowed;
|
|
791
|
+
m.eventMessage.isScheduleCall = message.event.isScheduleCall ?? false;
|
|
792
|
+
m.eventMessage.location = message.event.location;
|
|
793
|
+
} else if (hasNonNullishProperty(message, "poll")) {
|
|
794
|
+
(_a = message.poll).selectableCount || (_a.selectableCount = 0);
|
|
795
|
+
(_b = message.poll).toAnnouncementGroup || (_b.toAnnouncementGroup = false);
|
|
796
|
+
if (!Array.isArray(message.poll.values)) {
|
|
797
|
+
throw new import_Addon.HttpError("Invalid poll values", { statusCode: 400 });
|
|
798
|
+
}
|
|
799
|
+
if (message.poll.selectableCount < 0 || message.poll.selectableCount > message.poll.values.length) {
|
|
800
|
+
throw new import_Addon.HttpError(`poll.selectableCount in poll should be >= 0 and <= ${message.poll.values.length}`, {
|
|
801
|
+
statusCode: 400
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
const pollCreationMessage = {
|
|
805
|
+
name: message.poll.name,
|
|
806
|
+
selectableOptionsCount: message.poll.selectableCount,
|
|
807
|
+
options: message.poll.values.map((optionName) => ({ optionName })),
|
|
808
|
+
endTime: message.poll.endDate ? message.poll.endDate.getTime() : void 0,
|
|
809
|
+
hideParticipantName: message.poll.hideVoter ?? false,
|
|
810
|
+
allowAddOption: message.poll.canAddOption ?? false
|
|
811
|
+
};
|
|
812
|
+
if (message.poll.toAnnouncementGroup) {
|
|
813
|
+
m.pollCreationMessageV2 = pollCreationMessage;
|
|
814
|
+
} else {
|
|
815
|
+
if (message.poll.pollType === 1) {
|
|
816
|
+
if (!message.poll.correctAnswer) {
|
|
817
|
+
throw new import_Addon.HttpError('No "correctAnswer" provided for quiz', { statusCode: 400 });
|
|
818
|
+
}
|
|
819
|
+
m.pollCreationMessageV5 = {
|
|
820
|
+
// quiz for newsletter only
|
|
821
|
+
...pollCreationMessage,
|
|
822
|
+
correctAnswer: {
|
|
823
|
+
optionName: message.poll.correctAnswer.toString
|
|
824
|
+
},
|
|
825
|
+
pollType: 1,
|
|
826
|
+
selectableOptionsCount: 1
|
|
827
|
+
};
|
|
828
|
+
} else if (message.poll.selectableCount === 1) {
|
|
829
|
+
m.pollCreationMessageV3 = pollCreationMessage;
|
|
830
|
+
} else {
|
|
831
|
+
m.pollCreationMessage = pollCreationMessage;
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
m.messageContextInfo = {
|
|
835
|
+
// encKey
|
|
836
|
+
messageSecret: message.poll.messageSecret || (0, import_node_crypto.randomBytes)(32)
|
|
837
|
+
};
|
|
838
|
+
} else if (hasNonNullishProperty(message, "pollResult")) {
|
|
839
|
+
const pollResultSnapshotMessage = {
|
|
840
|
+
name: message.pollResult.name,
|
|
841
|
+
pollVotes: message.pollResult.votes.map((vote) => ({
|
|
842
|
+
optionName: vote.name,
|
|
843
|
+
optionVoteCount: parseInt(vote.voteCount)
|
|
844
|
+
}))
|
|
845
|
+
};
|
|
846
|
+
if (message.pollResult.pollType === 1) {
|
|
847
|
+
pollResultSnapshotMessage.pollType = import_WAProto.proto.Message.PollType.QUIZ;
|
|
848
|
+
m.pollResultSnapshotMessageV3 = pollResultSnapshotMessage;
|
|
849
|
+
} else {
|
|
850
|
+
pollResultSnapshotMessage.pollType = import_WAProto.proto.Message.PollType.POLL;
|
|
851
|
+
m.pollResultSnapshotMessage = pollResultSnapshotMessage;
|
|
852
|
+
}
|
|
853
|
+
} else if (hasNonNullishProperty(message, "pollUpdate")) {
|
|
854
|
+
if (!message.pollUpdate.key) {
|
|
855
|
+
throw new import_Addon.HttpError("Message key is required", { statusCode: 400 });
|
|
856
|
+
}
|
|
857
|
+
if (!message.pollUpdate.vote) {
|
|
858
|
+
throw new import_Addon.HttpError("Encrypted vote payload is required", { statusCode: 400 });
|
|
859
|
+
}
|
|
860
|
+
m.pollUpdateMessage = {
|
|
861
|
+
metadata: message.pollUpdate.metadata,
|
|
862
|
+
pollCreationMessageKey: message.pollUpdate.key,
|
|
863
|
+
senderTimestampMs: Date.now(),
|
|
864
|
+
vote: message.pollUpdate.vote
|
|
865
|
+
};
|
|
866
|
+
} else if (hasNonNullishProperty(message, "paymentInviteServiceType")) {
|
|
867
|
+
m.paymentInviteMessage = {
|
|
868
|
+
expiryTimestamp: Date.now(),
|
|
869
|
+
serviceType: message.paymentInviteServiceType
|
|
870
|
+
};
|
|
871
|
+
} else if (hasNonNullishProperty(message, "orderText")) {
|
|
872
|
+
if (!Buffer.isBuffer(message.thumbnail)) {
|
|
873
|
+
throw new import_Addon.HttpError("Must provide thumbnail buffer in order message", { statusCode: 400 });
|
|
874
|
+
}
|
|
875
|
+
m.orderMessage = {
|
|
876
|
+
itemCount: 1,
|
|
877
|
+
messageVersion: 1,
|
|
878
|
+
orderTitle: import_Defaults.LIBRARY_NAME,
|
|
879
|
+
status: import_WAProto.proto.Message.OrderMessage.OrderStatus.INQUIRY,
|
|
880
|
+
surface: import_WAProto.proto.Message.OrderMessage.OrderSurface.CATALOG,
|
|
881
|
+
token: (0, import_generics.generateMessageIDV2)(),
|
|
882
|
+
totalAmount1000: 1e3,
|
|
883
|
+
totalCurrencyCode: "IDR",
|
|
884
|
+
...message,
|
|
885
|
+
message: message.orderText
|
|
886
|
+
};
|
|
887
|
+
delete m.orderMessage.orderText;
|
|
888
|
+
} else if (hasNonNullishProperty(message, "album")) {
|
|
889
|
+
if (!Array.isArray(message.album)) {
|
|
890
|
+
throw new import_Addon.HttpError("Invalid album type. Expected an array.", { statusCode: 400 });
|
|
891
|
+
}
|
|
892
|
+
let videoCount = 0;
|
|
893
|
+
for (let i = 0; i < message.album.length; i++) {
|
|
894
|
+
if (message.album[i].video)
|
|
895
|
+
videoCount++;
|
|
896
|
+
}
|
|
897
|
+
;
|
|
898
|
+
let imageCount = 0;
|
|
899
|
+
for (let i = 0; i < message.album.length; i++) {
|
|
900
|
+
if (message.album[i].image)
|
|
901
|
+
imageCount++;
|
|
902
|
+
}
|
|
903
|
+
;
|
|
904
|
+
if (videoCount + imageCount < 2) {
|
|
905
|
+
throw new import_Addon.HttpError("Minimum provide 2 media to upload album message", { statusCode: 400 });
|
|
906
|
+
}
|
|
907
|
+
m.albumMessage = {
|
|
908
|
+
expectedImageCount: imageCount,
|
|
909
|
+
expectedVideoCount: videoCount
|
|
910
|
+
};
|
|
911
|
+
} else if (hasNonNullishProperty(message, "sharePhoneNumber")) {
|
|
912
|
+
m.protocolMessage = {
|
|
913
|
+
type: import_WAProto.proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER
|
|
914
|
+
};
|
|
915
|
+
} else if (hasNonNullishProperty(message, "requestPhoneNumber")) {
|
|
916
|
+
m.requestPhoneNumberMessage = {};
|
|
917
|
+
} else if (hasNonNullishProperty(message, "limitSharing")) {
|
|
918
|
+
m.protocolMessage = {
|
|
919
|
+
type: import_WAProto.proto.Message.ProtocolMessage.Type.LIMIT_SHARING,
|
|
920
|
+
limitSharing: {
|
|
921
|
+
sharingLimited: message.limitSharing === true,
|
|
922
|
+
trigger: 1,
|
|
923
|
+
limitSharingSettingTimestamp: Date.now(),
|
|
924
|
+
initiatedByMe: true
|
|
925
|
+
}
|
|
926
|
+
};
|
|
927
|
+
} else if (hasNonNullishProperty(message, "stickers")) {
|
|
928
|
+
m = await prepareStickerPackMessage(message, options);
|
|
929
|
+
} else {
|
|
930
|
+
m = await prepareWAMessageMedia(message, options);
|
|
931
|
+
}
|
|
932
|
+
if (hasNonNullishProperty(message, "buttons")) {
|
|
933
|
+
const buttonsMessage = {
|
|
934
|
+
buttons: message.buttons.map((button) => {
|
|
935
|
+
const buttonText = button.text || button.buttonText;
|
|
936
|
+
if (hasOptionalProperty(button, "sections")) {
|
|
937
|
+
return {
|
|
938
|
+
nativeFlowInfo: {
|
|
939
|
+
name: "single_select",
|
|
940
|
+
paramsJson: JSON.stringify({
|
|
941
|
+
title: buttonText,
|
|
942
|
+
sections: button.sections
|
|
943
|
+
})
|
|
944
|
+
},
|
|
945
|
+
type: import_Types.ButtonType.NATIVE_FLOW
|
|
946
|
+
};
|
|
947
|
+
} else if (hasOptionalProperty(button, "name")) {
|
|
948
|
+
return {
|
|
949
|
+
nativeFlowInfo: {
|
|
950
|
+
name: button.name,
|
|
951
|
+
paramsJson: button.paramsJson
|
|
952
|
+
},
|
|
953
|
+
type: import_Types.ButtonType.NATIVE_FLOW
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
return {
|
|
957
|
+
buttonId: button.id || button.buttonId,
|
|
958
|
+
buttonText: typeof buttonText === "string" ? { displayText: buttonText } : buttonText,
|
|
959
|
+
type: button.type || import_Types.ButtonType.RESPONSE
|
|
960
|
+
};
|
|
961
|
+
})
|
|
962
|
+
};
|
|
963
|
+
if (hasOptionalProperty(message, "text")) {
|
|
964
|
+
buttonsMessage.contentText = message.text;
|
|
965
|
+
buttonsMessage.headerType = import_Types.ButtonHeaderType.EMPTY;
|
|
966
|
+
} else {
|
|
967
|
+
if (hasOptionalProperty(message, "caption")) {
|
|
968
|
+
buttonsMessage.contentText = message.caption;
|
|
969
|
+
}
|
|
970
|
+
const type = Object.keys(m)[0].replace("Message", "").toUpperCase();
|
|
971
|
+
buttonsMessage.headerType = import_Types.ButtonHeaderType[type];
|
|
972
|
+
Object.assign(buttonsMessage, m);
|
|
973
|
+
}
|
|
974
|
+
if (hasOptionalProperty(message, "footer")) {
|
|
975
|
+
buttonsMessage.footerText = message.footer;
|
|
976
|
+
}
|
|
977
|
+
m = { buttonsMessage };
|
|
978
|
+
} else if (hasNonNullishProperty(message, "sections")) {
|
|
979
|
+
const listMessage = {
|
|
980
|
+
sections: message.sections,
|
|
981
|
+
buttonText: message.buttonText,
|
|
982
|
+
title: message.title,
|
|
983
|
+
footerText: message.footer,
|
|
984
|
+
description: message.text,
|
|
985
|
+
listType: import_Types.ListType.SINGLE_SELECT
|
|
986
|
+
};
|
|
987
|
+
m = { listMessage };
|
|
988
|
+
} else if (hasNonNullishProperty(message, "templateButtons")) {
|
|
989
|
+
const hydratedTemplate = {
|
|
990
|
+
hydratedButtons: message.templateButtons.map((button, i) => {
|
|
991
|
+
const buttonText = button.text || button.buttonText;
|
|
992
|
+
if (hasOptionalProperty(button, "id")) {
|
|
993
|
+
return {
|
|
994
|
+
index: i,
|
|
995
|
+
quickReplyButton: {
|
|
996
|
+
displayText: buttonText || "\u{1F449}\u{1F3FB} Click",
|
|
997
|
+
id: button.id
|
|
998
|
+
}
|
|
999
|
+
};
|
|
1000
|
+
} else if (hasOptionalProperty(button, "url")) {
|
|
1001
|
+
return {
|
|
1002
|
+
index: i,
|
|
1003
|
+
urlButton: {
|
|
1004
|
+
displayText: buttonText || "\u{1F310} Visit",
|
|
1005
|
+
url: button.url
|
|
1006
|
+
}
|
|
1007
|
+
};
|
|
1008
|
+
} else if (hasOptionalProperty(button, "call")) {
|
|
1009
|
+
return {
|
|
1010
|
+
index: i,
|
|
1011
|
+
callButton: {
|
|
1012
|
+
displayText: buttonText || "\u{1F4DE} Call",
|
|
1013
|
+
phoneNumber: button.call
|
|
1014
|
+
}
|
|
1015
|
+
};
|
|
1016
|
+
}
|
|
1017
|
+
button.index = button.index || i;
|
|
1018
|
+
return button;
|
|
1019
|
+
})
|
|
1020
|
+
};
|
|
1021
|
+
if (hasOptionalProperty(message, "text")) {
|
|
1022
|
+
hydratedTemplate.hydratedContentText = message.text;
|
|
1023
|
+
} else {
|
|
1024
|
+
if (hasOptionalProperty(message, "caption")) {
|
|
1025
|
+
hydratedTemplate.hydratedTitleText = message.title;
|
|
1026
|
+
hydratedTemplate.hydratedContentText = message.caption;
|
|
1027
|
+
}
|
|
1028
|
+
;
|
|
1029
|
+
Object.assign(hydratedTemplate, m);
|
|
1030
|
+
}
|
|
1031
|
+
if (hasOptionalProperty(message, "footer")) {
|
|
1032
|
+
hydratedTemplate.hydratedFooterText = message.footer;
|
|
1033
|
+
}
|
|
1034
|
+
hydratedTemplate.templateId = message.id || "template-" + Date.now();
|
|
1035
|
+
m = {
|
|
1036
|
+
templateMessage: {
|
|
1037
|
+
hydratedFourRowTemplate: hydratedTemplate,
|
|
1038
|
+
hydratedTemplate
|
|
1039
|
+
}
|
|
1040
|
+
};
|
|
1041
|
+
} else if (hasNonNullishProperty(message, "nativeFlow")) {
|
|
1042
|
+
const interactiveMessage = {
|
|
1043
|
+
nativeFlowMessage: prepareNativeFlowButtons(message)
|
|
1044
|
+
};
|
|
1045
|
+
if (hasOptionalProperty(message, "bizJid")) {
|
|
1046
|
+
interactiveMessage.collectionMessage = {
|
|
1047
|
+
bizJid: message.bizJid,
|
|
1048
|
+
id: message.id,
|
|
1049
|
+
messageVersion: 1
|
|
1050
|
+
};
|
|
1051
|
+
} else if (hasOptionalProperty(message, "shopSurface")) {
|
|
1052
|
+
interactiveMessage.shopStorefrontMessage = {
|
|
1053
|
+
surface: message.shopSurface,
|
|
1054
|
+
id: message.id,
|
|
1055
|
+
messageVersion: 1
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
if (hasOptionalProperty(message, "text")) {
|
|
1059
|
+
interactiveMessage.body = { text: message.text };
|
|
1060
|
+
} else {
|
|
1061
|
+
if (hasOptionalProperty(message, "caption")) {
|
|
1062
|
+
const isValidHeader = hasValidInteractiveHeader(m);
|
|
1063
|
+
if (!isValidHeader) {
|
|
1064
|
+
throw new import_Addon.HttpError("Invalid media type for interactive message header", { statusCode: 400 });
|
|
1065
|
+
}
|
|
1066
|
+
interactiveMessage.header = {
|
|
1067
|
+
title: message.title || "",
|
|
1068
|
+
subtitle: message.subtitle || "",
|
|
1069
|
+
hasMediaAttachment: isValidHeader
|
|
1070
|
+
};
|
|
1071
|
+
interactiveMessage.body = { text: message.caption };
|
|
1072
|
+
}
|
|
1073
|
+
if (hasOptionalProperty(message, "thumbnail") && !!message.thumbnail) {
|
|
1074
|
+
interactiveMessage.jpegThumbnail = message.thumbnail;
|
|
1075
|
+
}
|
|
1076
|
+
Object.assign(interactiveMessage.header, m);
|
|
1077
|
+
}
|
|
1078
|
+
if (hasOptionalProperty(message, "audioFooter")) {
|
|
1079
|
+
const { audioMessage } = await prepareWAMessageMedia({
|
|
1080
|
+
audio: message.audioFooter
|
|
1081
|
+
}, options);
|
|
1082
|
+
interactiveMessage.footer = {
|
|
1083
|
+
audioMessage,
|
|
1084
|
+
hasMediaAttachment: true
|
|
1085
|
+
};
|
|
1086
|
+
} else if (hasOptionalProperty(message, "footer")) {
|
|
1087
|
+
interactiveMessage.footer = { text: message.footer };
|
|
1088
|
+
}
|
|
1089
|
+
m = { interactiveMessage };
|
|
1090
|
+
} else if (hasNonNullishProperty(message, "cards")) {
|
|
1091
|
+
const interactiveMessage = {
|
|
1092
|
+
carouselMessage: {
|
|
1093
|
+
cards: await Promise.all(message.cards.map(async (card) => {
|
|
1094
|
+
let carouselHeader = {};
|
|
1095
|
+
if (hasNonNullishProperty(card, "product")) {
|
|
1096
|
+
carouselHeader.productMessage = await prepareProductMessage(card, options);
|
|
1097
|
+
} else {
|
|
1098
|
+
carouselHeader = await prepareWAMessageMedia(card, options).catch(() => ({}));
|
|
1099
|
+
}
|
|
1100
|
+
const isValidHeader = hasValidCarouselHeader(carouselHeader);
|
|
1101
|
+
if (!isValidHeader) {
|
|
1102
|
+
throw new import_Addon.HttpError("Invalid media type for carousel card", { statusCode: 400 });
|
|
1103
|
+
}
|
|
1104
|
+
const carouselCard = {
|
|
1105
|
+
nativeFlowMessage: prepareNativeFlowButtons(card.nativeFlow ? card : [])
|
|
1106
|
+
};
|
|
1107
|
+
if (hasOptionalProperty(card, "text")) {
|
|
1108
|
+
carouselCard.body = { text: card.text };
|
|
1109
|
+
} else {
|
|
1110
|
+
if (hasOptionalProperty(card, "caption")) {
|
|
1111
|
+
carouselCard.header = {
|
|
1112
|
+
title: card.title || "",
|
|
1113
|
+
subtitle: card.subtitle || "",
|
|
1114
|
+
hasMediaAttachment: isValidHeader
|
|
1115
|
+
};
|
|
1116
|
+
carouselCard.body = { text: card.caption };
|
|
1117
|
+
}
|
|
1118
|
+
if (hasOptionalProperty(card, "thumbnail") && !!card.thumbnail) {
|
|
1119
|
+
carouselCard.jpegThumbnail = card.thumbnail;
|
|
1120
|
+
}
|
|
1121
|
+
Object.assign(carouselCard.header, carouselHeader);
|
|
1122
|
+
}
|
|
1123
|
+
if (hasOptionalProperty(card, "audioFooter")) {
|
|
1124
|
+
const { audioMessage } = await prepareWAMessageMedia({
|
|
1125
|
+
audio: card.audioFooter
|
|
1126
|
+
}, options);
|
|
1127
|
+
carouselCard.footer = {
|
|
1128
|
+
audioMessage,
|
|
1129
|
+
hasMediaAttachment: true
|
|
1130
|
+
};
|
|
1131
|
+
} else if (hasOptionalProperty(card, "footer")) {
|
|
1132
|
+
carouselCard.footer = { text: card.footer };
|
|
1133
|
+
}
|
|
1134
|
+
return carouselCard;
|
|
1135
|
+
})),
|
|
1136
|
+
carouselCardType: import_Types.CarouselCardType.UNKNOWN,
|
|
1137
|
+
messageVersion: 1
|
|
1138
|
+
}
|
|
1139
|
+
};
|
|
1140
|
+
if (hasOptionalProperty(message, "text")) {
|
|
1141
|
+
interactiveMessage.body = { text: message.text };
|
|
1142
|
+
}
|
|
1143
|
+
if (hasOptionalProperty(message, "footer")) {
|
|
1144
|
+
interactiveMessage.footer = { text: message.footer };
|
|
1145
|
+
}
|
|
1146
|
+
m = { interactiveMessage };
|
|
1147
|
+
} else if (hasNonNullishProperty(message, "requestPaymentFrom")) {
|
|
1148
|
+
const requestPaymentMessage = {
|
|
1149
|
+
amount: {
|
|
1150
|
+
currencyCode: "IDR",
|
|
1151
|
+
offset: 1e3,
|
|
1152
|
+
value: 1e3
|
|
1153
|
+
},
|
|
1154
|
+
amount1000: 1e3,
|
|
1155
|
+
currencyCodeIso4217: "IDR",
|
|
1156
|
+
expiryTimestamp: Date.now(),
|
|
1157
|
+
noteMessage: m,
|
|
1158
|
+
requestFrom: message.requestPaymentFrom,
|
|
1159
|
+
...message
|
|
1160
|
+
};
|
|
1161
|
+
delete requestPaymentMessage.requestPaymentFrom;
|
|
1162
|
+
if (hasNonNullishProperty(m, "extendedTextMessage") || hasNonNullishProperty(m, "stickerMessage")) {
|
|
1163
|
+
Object.assign(requestPaymentMessage.noteMessage, m);
|
|
1164
|
+
} else {
|
|
1165
|
+
throw new import_Addon.HttpError("Invalid message type for request payment note message", { statusCode: 400 });
|
|
1166
|
+
}
|
|
1167
|
+
m = { requestPaymentMessage };
|
|
1168
|
+
} else if (hasNonNullishProperty(message, "invoiceNote")) {
|
|
1169
|
+
const attachment = m.imageMessage || m.documentMessage;
|
|
1170
|
+
const type = Object.keys(m)[0].replace("Message", "").toUpperCase();
|
|
1171
|
+
const invoiceMessage = {
|
|
1172
|
+
attachmentType: import_WAProto.proto.Message.InvoiceMessage.AttachmentType[type === "DOCUMENT" ? "PDF" : "IMAGE"],
|
|
1173
|
+
note: message.invoiceNote
|
|
1174
|
+
};
|
|
1175
|
+
if (attachment) {
|
|
1176
|
+
const { directPath, fileEncSha256, fileSha256, jpegThumbnail = void 0, mediaKey, mediaKeyTimestamp, mimetype } = attachment;
|
|
1177
|
+
Object.assign(invoiceMessage, {
|
|
1178
|
+
attachmentDirectPath: directPath,
|
|
1179
|
+
attachmentFileEncSha256: fileEncSha256,
|
|
1180
|
+
attachmentFileSha256: fileSha256,
|
|
1181
|
+
attachmentJpegThumbnail: jpegThumbnail,
|
|
1182
|
+
attachmentMediaKey: mediaKey,
|
|
1183
|
+
attachmentMediaKeyTimestamp: mediaKeyTimestamp,
|
|
1184
|
+
attachmentMimetype: mimetype,
|
|
1185
|
+
token: import_generics.generateMessageIDV2
|
|
1186
|
+
});
|
|
1187
|
+
} else {
|
|
1188
|
+
throw new import_Addon.HttpError("Invalid media type for invoice message", { statusCode: 400 });
|
|
1189
|
+
}
|
|
1190
|
+
m = { invoiceMessage };
|
|
1191
|
+
}
|
|
1192
|
+
if (hasOptionalProperty(message, "externalAdReply") && !!message.externalAdReply) {
|
|
1193
|
+
const messageType = Object.keys(m)[0];
|
|
1194
|
+
const key = m[messageType];
|
|
1195
|
+
const content = message.externalAdReply;
|
|
1196
|
+
if ("thumbnail" in content && !Buffer.isBuffer(content.thumbnail)) {
|
|
1197
|
+
throw new import_Addon.HttpError("Thumbnail must in buffer type", { statusCode: 400 });
|
|
1198
|
+
}
|
|
1199
|
+
if (!content.url || typeof content.url !== "string") {
|
|
1200
|
+
content.url = import_Defaults.DONATE_URL;
|
|
1201
|
+
}
|
|
1202
|
+
const externalAdReply = {
|
|
1203
|
+
...content,
|
|
1204
|
+
body: content.body,
|
|
1205
|
+
mediaType: content.mediaType || 1,
|
|
1206
|
+
mediaUrl: content.url,
|
|
1207
|
+
renderLargerThumbnail: content.largeThumbnail,
|
|
1208
|
+
sourceUrl: content.url,
|
|
1209
|
+
thumbnail: content.thumbnail,
|
|
1210
|
+
thumbnailUrl: content.url + "?update=" + Date.now(),
|
|
1211
|
+
title: content.title || import_Defaults.LIBRARY_NAME
|
|
1212
|
+
};
|
|
1213
|
+
delete externalAdReply.subTitle;
|
|
1214
|
+
delete externalAdReply.largeThumbnail;
|
|
1215
|
+
delete externalAdReply.url;
|
|
1216
|
+
if ("contextInfo" in key && !!key.contextInfo) {
|
|
1217
|
+
key.contextInfo.externalAdReply = { ...key.contextInfo.externalAdReply, ...externalAdReply };
|
|
1218
|
+
} else if (key) {
|
|
1219
|
+
key.contextInfo = { externalAdReply };
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
if (hasOptionalProperty(message, "mentions") && message.mentions?.length || hasOptionalProperty(message, "mentionAll") && message.mentionAll) {
|
|
1223
|
+
const messageType = Object.keys(m)[0];
|
|
1224
|
+
const key = m[messageType];
|
|
1225
|
+
if (key && "contextInfo" in key) {
|
|
1226
|
+
key.contextInfo = key.contextInfo || {};
|
|
1227
|
+
if (message.mentions?.length) {
|
|
1228
|
+
key.contextInfo.mentionedJid = message.mentions;
|
|
1229
|
+
}
|
|
1230
|
+
if (message.mentionAll) {
|
|
1231
|
+
key.contextInfo.nonJidMentions = 1;
|
|
1232
|
+
}
|
|
1233
|
+
} else if (key) {
|
|
1234
|
+
key.contextInfo = {
|
|
1235
|
+
mentionedJid: message.mentions,
|
|
1236
|
+
nonJidMentions: message.mentionAll ? 1 : 0
|
|
1237
|
+
};
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
if (hasOptionalProperty(message, "contextInfo") && !!message.contextInfo) {
|
|
1241
|
+
const messageType = Object.keys(m)[0];
|
|
1242
|
+
const key = m[messageType];
|
|
1243
|
+
if ("contextInfo" in key && !!key.contextInfo) {
|
|
1244
|
+
key.contextInfo = { ...key.contextInfo, ...message.contextInfo };
|
|
1245
|
+
} else if (key) {
|
|
1246
|
+
key.contextInfo = message.contextInfo;
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
if (hasOptionalProperty(message, "groupStatus") && !!message.groupStatus) {
|
|
1250
|
+
const messageType = Object.keys(m)[0];
|
|
1251
|
+
const key = m[messageType];
|
|
1252
|
+
if ("contextInfo" in key && !!key.contextInfo) {
|
|
1253
|
+
key.contextInfo.isGroupStatus = message.groupStatus;
|
|
1254
|
+
} else if (key) {
|
|
1255
|
+
key.contextInfo = {
|
|
1256
|
+
isGroupStatus: message.groupStatus
|
|
1257
|
+
};
|
|
1258
|
+
}
|
|
1259
|
+
m = { groupStatusMessageV2: { message: m } };
|
|
1260
|
+
delete message.groupStatus;
|
|
1261
|
+
}
|
|
1262
|
+
if (hasOptionalProperty(message, "spoiler") && !!message.spoiler) {
|
|
1263
|
+
const messageType = Object.keys(m)[0];
|
|
1264
|
+
const key = m[messageType];
|
|
1265
|
+
if ("contextInfo" in key && !!key.contextInfo) {
|
|
1266
|
+
key.contextInfo.isSpoiler = message.spoiler;
|
|
1267
|
+
} else if (key) {
|
|
1268
|
+
key.contextInfo = {
|
|
1269
|
+
isSpoiler: message.spoiler
|
|
1270
|
+
};
|
|
1271
|
+
}
|
|
1272
|
+
m = { spoilerMessage: { message: m } };
|
|
1273
|
+
delete message.spoiler;
|
|
1274
|
+
} else if (hasOptionalProperty(message, "interactiveAsTemplate") && !!message.interactiveAsTemplate) {
|
|
1275
|
+
if (!m.interactiveMessage) {
|
|
1276
|
+
throw new import_Addon.HttpError("Invalid message type for template", { statusCode: 400 });
|
|
1277
|
+
}
|
|
1278
|
+
m = {
|
|
1279
|
+
templateMessage: {
|
|
1280
|
+
interactiveMessageTemplate: m.interactiveMessage,
|
|
1281
|
+
templateId: message.id || "template-" + Date.now()
|
|
1282
|
+
// Minimal templateId to satisfy WhatsApp ( ꈍᴗꈍ)
|
|
1283
|
+
}
|
|
1284
|
+
};
|
|
1285
|
+
delete message.interactiveAsTemplate;
|
|
1286
|
+
}
|
|
1287
|
+
if (hasOptionalProperty(message, "ephemeral") && !!message.ephemeral) {
|
|
1288
|
+
m = { ephemeralMessage: { message: m } };
|
|
1289
|
+
delete message.ephemeral;
|
|
1290
|
+
}
|
|
1291
|
+
if (hasOptionalProperty(message, "isLottie") && !!message.isLottie) {
|
|
1292
|
+
m = { lottieStickerMessage: { message: m } };
|
|
1293
|
+
} else if (hasOptionalProperty(message, "viewOnce") && !!message.viewOnce) {
|
|
1294
|
+
markViewOnce(m);
|
|
1295
|
+
m = { viewOnceMessage: { message: m } };
|
|
1296
|
+
} else if (hasOptionalProperty(message, "viewOnceV2") && !!message.viewOnceV2) {
|
|
1297
|
+
markViewOnce(m);
|
|
1298
|
+
m = { viewOnceMessageV2: { message: m } };
|
|
1299
|
+
delete message.viewOnceV2;
|
|
1300
|
+
} else if (hasOptionalProperty(message, "viewOnceV2Extension") && !!message.viewOnceV2Extension) {
|
|
1301
|
+
markViewOnce(m);
|
|
1302
|
+
m = { viewOnceMessageV2Extension: { message: m } };
|
|
1303
|
+
delete message.viewOnceV2Extension;
|
|
1304
|
+
}
|
|
1305
|
+
if (hasOptionalProperty(message, "edit")) {
|
|
1306
|
+
m = {
|
|
1307
|
+
protocolMessage: {
|
|
1308
|
+
key: message.edit,
|
|
1309
|
+
editedMessage: m,
|
|
1310
|
+
timestampMs: Date.now(),
|
|
1311
|
+
type: import_Types.WAProto.Message.ProtocolMessage.Type.MESSAGE_EDIT
|
|
1312
|
+
}
|
|
1313
|
+
};
|
|
1314
|
+
}
|
|
1315
|
+
if ((0, import_reporting_utils.shouldIncludeReportingToken)(m)) {
|
|
1316
|
+
m.messageContextInfo = m.messageContextInfo || {};
|
|
1317
|
+
if (!m.messageContextInfo.messageSecret) {
|
|
1318
|
+
m.messageContextInfo.messageSecret = (0, import_node_crypto.randomBytes)(32);
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
return ensureMessageProto(m);
|
|
1322
|
+
};
|
|
1323
|
+
const generateWAMessageFromContent = (jid, message, options) => {
|
|
1324
|
+
if (!options.timestamp) {
|
|
1325
|
+
options.timestamp = /* @__PURE__ */ new Date();
|
|
1326
|
+
}
|
|
1327
|
+
const innerMessage = normalizeMessageContent(message);
|
|
1328
|
+
const messageContextInfo = message.messageContextInfo;
|
|
1329
|
+
const key = getContentType(innerMessage);
|
|
1330
|
+
const timestamp = (0, import_generics.unixTimestampSeconds)(options.timestamp);
|
|
1331
|
+
const isNewsletter = (0, import_WABinary.isJidNewsletter)(jid);
|
|
1332
|
+
const { quoted, userJid } = options;
|
|
1333
|
+
if (quoted) {
|
|
1334
|
+
const participant = quoted.key.fromMe ? userJid : quoted.participant || quoted.key.participant || quoted.key.remoteJid;
|
|
1335
|
+
let quotedMsg = normalizeMessageContent(quoted.message);
|
|
1336
|
+
const msgType = getContentType(quotedMsg);
|
|
1337
|
+
quotedMsg = import_WAProto.proto.Message.create({ [msgType]: quotedMsg[msgType] });
|
|
1338
|
+
const quotedContent = quotedMsg[msgType];
|
|
1339
|
+
if (typeof quotedContent === "object" && quotedContent && "contextInfo" in quotedContent) {
|
|
1340
|
+
delete quotedContent.contextInfo;
|
|
1341
|
+
}
|
|
1342
|
+
const contextInfo = "contextInfo" in innerMessage[key] && innerMessage[key]?.contextInfo || {};
|
|
1343
|
+
contextInfo.participant = (0, import_WABinary.jidNormalizedUser)(participant);
|
|
1344
|
+
contextInfo.stanzaId = quoted.key.id;
|
|
1345
|
+
contextInfo.quotedMessage = quotedMsg;
|
|
1346
|
+
if (!isNewsletter && jid !== quoted.key.remoteJid) {
|
|
1347
|
+
contextInfo.remoteJid = quoted.key.remoteJid;
|
|
1348
|
+
}
|
|
1349
|
+
if (contextInfo && innerMessage[key]) {
|
|
1350
|
+
innerMessage[key].contextInfo = contextInfo;
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
if (
|
|
1354
|
+
// if we want to send a disappearing message
|
|
1355
|
+
!!options?.ephemeralExpiration && // and it's not a protocol message -- delete, toggle disappear message
|
|
1356
|
+
key !== "protocolMessage" && // already not converted to disappearing message
|
|
1357
|
+
key !== "ephemeralMessage" && // newsletters don't support ephemeral messages
|
|
1358
|
+
!isNewsletter
|
|
1359
|
+
) {
|
|
1360
|
+
innerMessage[key].contextInfo = {
|
|
1361
|
+
...innerMessage[key].contextInfo || {},
|
|
1362
|
+
expiration: options.ephemeralExpiration || import_Defaults.WA_DEFAULT_EPHEMERAL
|
|
1363
|
+
//ephemeralSettingTimestamp: options.ephemeralOptions.eph_setting_ts?.toString
|
|
1364
|
+
};
|
|
1365
|
+
}
|
|
1366
|
+
if (messageContextInfo?.messageSecret && ((0, import_WABinary.isPnUser)(jid) || (0, import_WABinary.isLidUser)(jid))) {
|
|
1367
|
+
messageContextInfo.deviceListMetadata = {
|
|
1368
|
+
recipientKeyHash: (0, import_node_crypto.randomBytes)(10),
|
|
1369
|
+
recipientTimestamp: import_generics.unixTimestampSeconds
|
|
1370
|
+
};
|
|
1371
|
+
messageContextInfo.deviceListMetadataVersion = 2;
|
|
1372
|
+
}
|
|
1373
|
+
return import_Types.WAProto.WebMessageInfo.create({
|
|
1374
|
+
key: {
|
|
1375
|
+
remoteJid: jid,
|
|
1376
|
+
fromMe: true,
|
|
1377
|
+
id: options?.messageId || import_generics.generateMessageIDV2
|
|
1378
|
+
},
|
|
1379
|
+
message: ensureMessageProto(message),
|
|
1380
|
+
messageTimestamp: timestamp,
|
|
1381
|
+
messageStubParameters: [],
|
|
1382
|
+
participant: (0, import_WABinary.isJidGroup)(jid) || (0, import_WABinary.isJidStatusBroadcast)(jid) ? userJid : void 0,
|
|
1383
|
+
// TODO: Add support for LIDs
|
|
1384
|
+
status: import_Types.WAMessageStatus.PENDING
|
|
1385
|
+
});
|
|
1386
|
+
};
|
|
1387
|
+
const generateWAMessage = async (jid, content, options) => {
|
|
1388
|
+
options.logger = options?.logger?.child({ msgId: options.messageId });
|
|
1389
|
+
if (jid) {
|
|
1390
|
+
options.jid = jid;
|
|
1391
|
+
}
|
|
1392
|
+
return generateWAMessageFromContent(jid, await generateWAMessageContent(content, options), options);
|
|
1393
|
+
};
|
|
1394
|
+
const getContentType = (content) => {
|
|
1395
|
+
if (content) {
|
|
1396
|
+
const keys = Object.keys(content);
|
|
1397
|
+
const key = keys.find((k) => (k === "conversation" || k.includes("Message")) && k !== "senderKeyDistributionMessage");
|
|
1398
|
+
return key;
|
|
1399
|
+
}
|
|
1400
|
+
};
|
|
1401
|
+
const normalizeMessageContent = (content) => {
|
|
1402
|
+
if (!content) {
|
|
1403
|
+
return void 0;
|
|
1404
|
+
}
|
|
1405
|
+
for (let i = 0; i < 5; i++) {
|
|
1406
|
+
const inner = getFutureProofMessage(content);
|
|
1407
|
+
if (!inner) {
|
|
1408
|
+
break;
|
|
1409
|
+
}
|
|
1410
|
+
content = inner.message;
|
|
1411
|
+
}
|
|
1412
|
+
return content;
|
|
1413
|
+
function getFutureProofMessage(message) {
|
|
1414
|
+
return message?.acp2SettingMessage || message?.associatedChildMessage || message?.audioStickerMessage || message?.botForwardedMessage || message?.botGroupParticipantMessage || message?.botInvokeMessage || message?.botPlatformRegistrationSuccessMessage || message?.botTaskMessage || message?.documentWithCaptionMessage || message?.editedMessage || message?.ephemeralMessage || message?.eventCoverImage || message?.groupMentionedMessage || message?.groupStatusMentionMessage || message?.groupStatusMessage || message?.groupStatusMessageV2 || message?.limitSharingMessage || message?.lottieStickerMessage || message?.newsletterAdminProfileMessage || message?.newsletterAdminProfileMessageV2 || message?.newsletterAdminProfileStatusMessage || message?.newsletterScheduledMessage || message?.pollCreationMessageV4 || message?.pollCreationOptionImageMessage || message?.questionMessage || message?.questionReplyMessage || message?.spoilerMessage || message?.statusAddYours || message?.statusMentionMessage || message?.viewOnceMessage || message?.viewOnceMessageV2 || message?.viewOnceMessageV2Extension;
|
|
1415
|
+
}
|
|
1416
|
+
};
|
|
1417
|
+
const extractMessageContent = (content) => {
|
|
1418
|
+
const extractFromTemplateMessage = (msg) => {
|
|
1419
|
+
if (msg.imageMessage) {
|
|
1420
|
+
return { imageMessage: msg.imageMessage };
|
|
1421
|
+
} else if (msg.documentMessage) {
|
|
1422
|
+
return { documentMessage: msg.documentMessage };
|
|
1423
|
+
} else if (msg.videoMessage) {
|
|
1424
|
+
return { videoMessage: msg.videoMessage };
|
|
1425
|
+
} else if (msg.locationMessage) {
|
|
1426
|
+
return { locationMessage: msg.locationMessage };
|
|
1427
|
+
} else {
|
|
1428
|
+
return {
|
|
1429
|
+
conversation: "contentText" in msg ? msg.contentText : "hydratedContentText" in msg ? msg.hydratedContentText : ""
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
};
|
|
1433
|
+
content = normalizeMessageContent(content);
|
|
1434
|
+
if (content?.buttonsMessage) {
|
|
1435
|
+
return extractFromTemplateMessage(content.buttonsMessage);
|
|
1436
|
+
}
|
|
1437
|
+
if (content?.templateMessage?.hydratedFourRowTemplate) {
|
|
1438
|
+
return extractFromTemplateMessage(content?.templateMessage?.hydratedFourRowTemplate);
|
|
1439
|
+
}
|
|
1440
|
+
if (content?.templateMessage?.hydratedTemplate) {
|
|
1441
|
+
return extractFromTemplateMessage(content?.templateMessage?.hydratedTemplate);
|
|
1442
|
+
}
|
|
1443
|
+
if (content?.templateMessage?.fourRowTemplate) {
|
|
1444
|
+
return extractFromTemplateMessage(content?.templateMessage?.fourRowTemplate);
|
|
1445
|
+
}
|
|
1446
|
+
return content;
|
|
1447
|
+
};
|
|
1448
|
+
const getDevice = (id) => /^3A.{18}$/.test(id) ? "ios" : /^3E.{20}$/.test(id) ? "web" : /^(.{21}|.{32})$/.test(id) ? "android" : /^(3F|.{18}$)/.test(id) ? "desktop" : "unknown";
|
|
1449
|
+
const updateMessageWithReceipt = (msg, receipt) => {
|
|
1450
|
+
msg.userReceipt = msg.userReceipt || [];
|
|
1451
|
+
const recp = msg.userReceipt.find((m) => m.userJid === receipt.userJid);
|
|
1452
|
+
if (recp) {
|
|
1453
|
+
Object.assign(recp, receipt);
|
|
1454
|
+
} else {
|
|
1455
|
+
msg.userReceipt.push(receipt);
|
|
1456
|
+
}
|
|
1457
|
+
};
|
|
1458
|
+
const updateMessageWithReaction = (msg, reaction) => {
|
|
1459
|
+
const authorID = (0, import_generics.getKeyAuthor)(reaction.key);
|
|
1460
|
+
const reactions = (msg.reactions || []).filter((r) => (0, import_generics.getKeyAuthor)(r.key) !== authorID);
|
|
1461
|
+
reaction.text = reaction.text || "";
|
|
1462
|
+
reactions.push(reaction);
|
|
1463
|
+
msg.reactions = reactions;
|
|
1464
|
+
};
|
|
1465
|
+
const updateMessageWithPollUpdate = (msg, update) => {
|
|
1466
|
+
const authorID = (0, import_generics.getKeyAuthor)(update.pollUpdateMessageKey);
|
|
1467
|
+
const reactions = (msg.pollUpdates || []).filter((r) => (0, import_generics.getKeyAuthor)(r.pollUpdateMessageKey) !== authorID);
|
|
1468
|
+
if (update.vote?.selectedOptions?.length) {
|
|
1469
|
+
reactions.push(update);
|
|
1470
|
+
}
|
|
1471
|
+
msg.pollUpdates = reactions;
|
|
1472
|
+
};
|
|
1473
|
+
const updateMessageWithEventResponse = (msg, update) => {
|
|
1474
|
+
const authorID = (0, import_generics.getKeyAuthor)(update.eventResponseMessageKey);
|
|
1475
|
+
const responses = (msg.eventResponses || []).filter((r) => (0, import_generics.getKeyAuthor)(r.eventResponseMessageKey) !== authorID);
|
|
1476
|
+
responses.push(update);
|
|
1477
|
+
msg.eventResponses = responses;
|
|
1478
|
+
};
|
|
1479
|
+
function getAggregateVotesInPollMessage({ message, pollUpdates }, meId) {
|
|
1480
|
+
const opts = message?.pollCreationMessage?.options || message?.pollCreationMessageV2?.options || message?.pollCreationMessageV3?.options || [];
|
|
1481
|
+
const voteHashMap = opts.reduce((acc, opt) => {
|
|
1482
|
+
const hash = (0, import_crypto.sha256)(Buffer.from(opt.optionName || "")).toString();
|
|
1483
|
+
acc[hash] = {
|
|
1484
|
+
name: opt.optionName || "",
|
|
1485
|
+
voters: []
|
|
1486
|
+
};
|
|
1487
|
+
return acc;
|
|
1488
|
+
}, {});
|
|
1489
|
+
for (const update of pollUpdates || []) {
|
|
1490
|
+
const { vote } = update;
|
|
1491
|
+
if (!vote) {
|
|
1492
|
+
continue;
|
|
1493
|
+
}
|
|
1494
|
+
for (const option of vote.selectedOptions || []) {
|
|
1495
|
+
const hash = option.toString();
|
|
1496
|
+
let data = voteHashMap[hash];
|
|
1497
|
+
if (!data) {
|
|
1498
|
+
voteHashMap[hash] = {
|
|
1499
|
+
name: "Unknown",
|
|
1500
|
+
voters: []
|
|
1501
|
+
};
|
|
1502
|
+
data = voteHashMap[hash];
|
|
1503
|
+
}
|
|
1504
|
+
voteHashMap[hash].voters.push((0, import_generics.getKeyAuthor)(update.pollUpdateMessageKey, meId));
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
return Object.values(voteHashMap);
|
|
1508
|
+
}
|
|
1509
|
+
function getAggregateResponsesInEventMessage({ eventResponses }, meId) {
|
|
1510
|
+
const responseTypes = ["GOING", "NOT_GOING", "MAYBE"];
|
|
1511
|
+
const responseMap = {};
|
|
1512
|
+
for (const type of responseTypes) {
|
|
1513
|
+
responseMap[type] = {
|
|
1514
|
+
response: type,
|
|
1515
|
+
responders: []
|
|
1516
|
+
};
|
|
1517
|
+
}
|
|
1518
|
+
for (const update of eventResponses || []) {
|
|
1519
|
+
const responseType = update.eventResponse || "UNKNOWN";
|
|
1520
|
+
if (responseType !== "UNKNOWN" && responseMap[responseType]) {
|
|
1521
|
+
responseMap[responseType].responders.push((0, import_generics.getKeyAuthor)(update.eventResponseMessageKey, meId));
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
return Object.values(responseMap);
|
|
1525
|
+
}
|
|
1526
|
+
const aggregateMessageKeysNotFromMe = (keys) => {
|
|
1527
|
+
const keyMap = {};
|
|
1528
|
+
for (const { remoteJid, id, participant, fromMe } of keys) {
|
|
1529
|
+
if (!fromMe) {
|
|
1530
|
+
const uqKey = `${remoteJid}:${participant || ""}`;
|
|
1531
|
+
if (!keyMap[uqKey]) {
|
|
1532
|
+
keyMap[uqKey] = {
|
|
1533
|
+
jid: remoteJid,
|
|
1534
|
+
participant,
|
|
1535
|
+
messageIds: []
|
|
1536
|
+
};
|
|
1537
|
+
}
|
|
1538
|
+
keyMap[uqKey].messageIds.push(id);
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
return Object.values(keyMap);
|
|
1542
|
+
};
|
|
1543
|
+
const REUPLOAD_REQUIRED_STATUS = [410, 404];
|
|
1544
|
+
const downloadMediaMessage = async (message, type, options, ctx) => {
|
|
1545
|
+
const result = await downloadMsg().catch(async (error) => {
|
|
1546
|
+
if (ctx && typeof error?.status === "number" && // treat errors with status as HTTP failures requiring reupload
|
|
1547
|
+
REUPLOAD_REQUIRED_STATUS.includes(error.status)) {
|
|
1548
|
+
ctx.logger.info({ key: message.key }, "sending reupload media request...");
|
|
1549
|
+
message = await ctx.reuploadRequest(message);
|
|
1550
|
+
const result2 = await downloadMsg();
|
|
1551
|
+
return result2;
|
|
1552
|
+
}
|
|
1553
|
+
throw error;
|
|
1554
|
+
});
|
|
1555
|
+
return result;
|
|
1556
|
+
async function downloadMsg() {
|
|
1557
|
+
const mContent = extractMessageContent(message.message);
|
|
1558
|
+
if (!mContent) {
|
|
1559
|
+
throw new import_Addon.HttpError("No message present", { statusCode: 400, data: message });
|
|
1560
|
+
}
|
|
1561
|
+
const contentType = getContentType(mContent);
|
|
1562
|
+
let mediaType = contentType?.replace("Message", "");
|
|
1563
|
+
const media = mContent[contentType];
|
|
1564
|
+
if (!media || typeof media !== "object" || !("url" in media) && !("thumbnailDirectPath" in media)) {
|
|
1565
|
+
throw new import_Addon.HttpError(`"${contentType}" message is not a media message`);
|
|
1566
|
+
}
|
|
1567
|
+
let download;
|
|
1568
|
+
if ("thumbnailDirectPath" in media && !("url" in media)) {
|
|
1569
|
+
download = {
|
|
1570
|
+
directPath: media.thumbnailDirectPath,
|
|
1571
|
+
mediaKey: media.mediaKey
|
|
1572
|
+
};
|
|
1573
|
+
mediaType = "thumbnail-link";
|
|
1574
|
+
} else {
|
|
1575
|
+
download = media;
|
|
1576
|
+
}
|
|
1577
|
+
const stream = await (0, import_messages_media.downloadContentFromMessage)(download, mediaType, options);
|
|
1578
|
+
if (type === "buffer") {
|
|
1579
|
+
const bufferArray = [];
|
|
1580
|
+
for await (const chunk of stream) {
|
|
1581
|
+
bufferArray.push(chunk);
|
|
1582
|
+
}
|
|
1583
|
+
return Buffer.concat(bufferArray);
|
|
1584
|
+
}
|
|
1585
|
+
return stream;
|
|
1586
|
+
}
|
|
1587
|
+
};
|
|
1588
|
+
const assertMediaContent = (content) => {
|
|
1589
|
+
content = extractMessageContent(content);
|
|
1590
|
+
const mediaContent = content?.documentMessage || content?.imageMessage || content?.videoMessage || content?.audioMessage || content?.stickerMessage;
|
|
1591
|
+
if (!mediaContent) {
|
|
1592
|
+
throw new import_Addon.HttpError("given message is not a media message", { statusCode: 400, data: content });
|
|
1593
|
+
}
|
|
1594
|
+
return mediaContent;
|
|
1595
|
+
};
|
|
1596
|
+
const isAnimatedWebP = (buffer) => {
|
|
1597
|
+
if (buffer.length < 12 || buffer[0] !== 82 || buffer[1] !== 73 || buffer[2] !== 70 || buffer[3] !== 70 || buffer[8] !== 87 || buffer[9] !== 69 || buffer[10] !== 66 || buffer[11] !== 80) {
|
|
1598
|
+
return false;
|
|
1599
|
+
}
|
|
1600
|
+
;
|
|
1601
|
+
let offset = 12;
|
|
1602
|
+
while (offset < buffer.length - 8) {
|
|
1603
|
+
const chunkFourCC = buffer.toString("ascii", offset, offset + 4);
|
|
1604
|
+
const chunkSize = buffer.readUInt32LE(offset + 4);
|
|
1605
|
+
if (chunkFourCC === "VP8X") {
|
|
1606
|
+
const flagsOffset = offset + 8;
|
|
1607
|
+
if (flagsOffset < buffer.length) {
|
|
1608
|
+
const flags = buffer[flagsOffset];
|
|
1609
|
+
if (flags & 2) {
|
|
1610
|
+
return true;
|
|
1611
|
+
}
|
|
1612
|
+
;
|
|
1613
|
+
}
|
|
1614
|
+
;
|
|
1615
|
+
} else if (chunkFourCC === "ANIM" || chunkFourCC === "ANMF") {
|
|
1616
|
+
return true;
|
|
1617
|
+
}
|
|
1618
|
+
;
|
|
1619
|
+
offset += 8 + chunkSize + chunkSize % 2;
|
|
1620
|
+
}
|
|
1621
|
+
;
|
|
1622
|
+
return false;
|
|
1623
|
+
};
|
|
1624
|
+
const isWebPBuffer = (buffer) => {
|
|
1625
|
+
return buffer.length >= 12 && buffer[0] === 82 && buffer[1] === 73 && buffer[2] === 70 && buffer[3] === 70 && buffer[8] === 87 && buffer[9] === 69 && buffer[10] === 66 && buffer[11] === 80;
|
|
1626
|
+
};
|
|
1627
|
+
const shouldIncludeBizBinaryNode = (message) => !!(message.buttonsMessage || message.listMessage || message.templateMessage || message.interactiveMessage && message.interactiveMessage.nativeFlowMessage);
|
|
1628
|
+
const isViewOnceMessage = (message) => {
|
|
1629
|
+
if (message?.viewOnce === true || message?.viewOnceMessage || message?.viewOnceMessageV2 || message?.viewOnceMessageV2Extension)
|
|
1630
|
+
return true;
|
|
1631
|
+
const innerMsg = normalizeMessageContent(message);
|
|
1632
|
+
const msgType = getContentType(innerMsg);
|
|
1633
|
+
const msgCtn = innerMsg?.[msgType];
|
|
1634
|
+
return msgCtn?.viewOnce === true;
|
|
1635
|
+
};
|
|
1636
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1637
|
+
0 && (module.exports = {
|
|
1638
|
+
aggregateMessageKeysNotFromMe,
|
|
1639
|
+
assertMediaContent,
|
|
1640
|
+
downloadMediaMessage,
|
|
1641
|
+
extractMessageContent,
|
|
1642
|
+
extractUrlFromText,
|
|
1643
|
+
generateForwardMessageContent,
|
|
1644
|
+
generateLinkPreviewIfRequired,
|
|
1645
|
+
generateWAMessage,
|
|
1646
|
+
generateWAMessageContent,
|
|
1647
|
+
generateWAMessageFromContent,
|
|
1648
|
+
getAggregateResponsesInEventMessage,
|
|
1649
|
+
getAggregateVotesInPollMessage,
|
|
1650
|
+
getContentType,
|
|
1651
|
+
getDevice,
|
|
1652
|
+
hasNonNullishProperty,
|
|
1653
|
+
hasOptionalProperty,
|
|
1654
|
+
hasValidAlbumMedia,
|
|
1655
|
+
hasValidCarouselHeader,
|
|
1656
|
+
hasValidInteractiveHeader,
|
|
1657
|
+
isViewOnceMessage,
|
|
1658
|
+
markViewOnce,
|
|
1659
|
+
normalizeMessageContent,
|
|
1660
|
+
prepareDisappearingMessageSettingContent,
|
|
1661
|
+
prepareWAMessageMedia,
|
|
1662
|
+
shouldIncludeBizBinaryNode,
|
|
1663
|
+
updateMessageWithEventResponse,
|
|
1664
|
+
updateMessageWithPollUpdate,
|
|
1665
|
+
updateMessageWithReaction,
|
|
1666
|
+
updateMessageWithReceipt
|
|
1667
|
+
});
|