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