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