violetics 7.0.6-alpha → 7.0.8-alpha
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 +1 -2
- package/README.md +456 -978
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +5479 -0
- package/WAProto/fix-imports.js +81 -0
- package/WAProto/index.d.ts +14017 -0
- package/WAProto/index.js +2728 -7894
- package/engine-requirements.js +7 -10
- package/index.cjs +196 -0
- package/index.d.ts +30 -0
- package/lib/Defaults/index.d.ts +74 -0
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +16 -25
- package/lib/Defaults/index.js.map +1 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -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 +2 -1
- 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 +2 -1
- 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 +2 -1
- 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 +2 -1
- 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 +2 -1
- 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 +2 -1
- 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 +2 -1
- 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 +2 -1
- 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 +2 -1
- 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 +2 -1
- 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 +2 -1
- 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 +2 -1
- 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 +44 -8
- package/lib/Signal/libsignal.js.map +1 -0
- package/lib/Signal/lid-mapping.d.ts +19 -0
- package/lib/Signal/lid-mapping.d.ts.map +1 -0
- package/lib/Signal/lid-mapping.js +2 -1
- 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 +2 -1
- 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 +2 -1
- 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 +3 -11
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +202 -0
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +2 -1
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +111 -0
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +155 -71
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +258 -0
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +2 -1
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/community.js +361 -0
- package/lib/Socket/groups.d.ts +150 -0
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +140 -9
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +245 -0
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +2 -1
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +187 -0
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +481 -204
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +183 -0
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +622 -233
- 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 +2 -1
- package/lib/Socket/mex.js.map +1 -0
- package/lib/Socket/newsletter.d.ts +160 -0
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +107 -68
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +55 -0
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +25 -26
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Socket/usync.js +76 -0
- package/lib/Store/index.js +2 -1
- package/lib/Store/make-cache-manager-store.js +77 -0
- package/lib/Store/make-in-memory-store.js +44 -65
- package/lib/Store/make-ordered-dictionary.js +1 -1
- package/lib/Store/object-repository.js +1 -1
- package/lib/Types/Auth.d.ts +116 -0
- package/lib/Types/Auth.d.ts.map +1 -0
- package/lib/Types/Auth.js +2 -1
- 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 -1
- package/lib/Types/Bussines.js.map +1 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Call.d.ts.map +1 -0
- package/lib/Types/Call.js +2 -1
- 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 +2 -1
- package/lib/Types/Chat.js.map +1 -0
- package/lib/Types/Contact.d.ts +24 -0
- package/lib/Types/Contact.d.ts.map +1 -0
- package/lib/Types/Contact.js +2 -1
- package/lib/Types/Contact.js.map +1 -0
- package/lib/Types/Events.d.ts +237 -0
- package/lib/Types/Events.d.ts.map +1 -0
- package/lib/Types/Events.js +2 -1
- package/lib/Types/Events.js.map +1 -0
- package/lib/Types/GroupMetadata.d.ts +67 -0
- package/lib/Types/GroupMetadata.d.ts.map +1 -0
- package/lib/Types/GroupMetadata.js +2 -1
- 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 +2 -1
- 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 +2 -1
- package/lib/Types/LabelAssociation.js.map +1 -0
- package/lib/Types/Message.d.ts +305 -0
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +2 -8
- package/lib/Types/Message.js.map +1 -0
- package/lib/Types/MexUpdates.js +9 -0
- package/lib/Types/Newsletter.d.ts +135 -0
- package/lib/Types/Newsletter.d.ts.map +1 -0
- package/lib/Types/Newsletter.js +14 -4
- 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 -1
- package/lib/Types/Product.js.map +1 -0
- package/lib/Types/Signal.d.ts +76 -0
- package/lib/Types/Signal.d.ts.map +1 -0
- package/lib/Types/Signal.js +2 -1
- package/lib/Types/Signal.js.map +1 -0
- package/lib/Types/Socket.d.ts +133 -0
- package/lib/Types/Socket.d.ts.map +1 -0
- package/lib/Types/Socket.js +2 -1
- package/lib/Types/Socket.js.map +1 -0
- package/lib/Types/State.d.ts +39 -0
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +2 -1
- 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 -1
- package/lib/Types/USync.js.map +1 -0
- package/lib/Types/index.d.ts +65 -0
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +3 -1
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/audioToBuffer.js +31 -0
- package/lib/Utils/auth-utils.d.ts +19 -0
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +2 -1
- package/lib/Utils/auth-utils.js.map +1 -0
- package/lib/Utils/baileys-event-stream.js +54 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.d.ts.map +1 -0
- package/lib/Utils/browser-utils.js +35 -22
- 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 +2 -1
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +2 -1
- package/lib/Utils/chat-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 +2 -1
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +48 -0
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +2 -1
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +34 -0
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +4 -3
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +91 -0
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +34 -7
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts +22 -0
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +2 -1
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/identity-change-handler.d.ts +37 -0
- package/lib/Utils/identity-change-handler.d.ts.map +1 -0
- package/lib/Utils/identity-change-handler.js +2 -1
- package/lib/Utils/identity-change-handler.js.map +1 -0
- package/lib/Utils/index.d.ts +22 -0
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +8 -1
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +2 -1
- 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 +2 -1
- package/lib/Utils/logger.js.map +1 -0
- package/lib/Utils/lt-hash.d.ts +8 -0
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +2 -1
- 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 +2 -1
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/message-retry-manager.d.ts +110 -0
- package/lib/Utils/message-retry-manager.d.ts.map +1 -0
- package/lib/Utils/message-retry-manager.js +3 -2
- package/lib/Utils/message-retry-manager.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +130 -0
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +186 -180
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages-newsletter.d.ts +84 -0
- package/lib/Utils/messages-newsletter.js +316 -0
- package/lib/Utils/messages.d.ts +92 -0
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +929 -1116
- 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 +2 -7
- package/lib/Utils/noise-handler.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 +2 -1
- 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 +2 -1
- 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 +2 -1
- package/lib/Utils/reporting-utils.js.map +1 -0
- package/lib/Utils/resolve-jid.d.ts +43 -0
- package/lib/Utils/resolve-jid.js +101 -0
- package/lib/Utils/signal.d.ts +34 -0
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +2 -1
- package/lib/Utils/signal.js.map +1 -0
- package/lib/Utils/streamToBuffer.js +17 -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 +2 -1
- package/lib/Utils/sync-action-utils.js.map +1 -0
- package/lib/Utils/tc-token-utils.d.ts +12 -0
- package/lib/Utils/tc-token-utils.d.ts.map +1 -0
- package/lib/Utils/tc-token-utils.js +2 -1
- package/lib/Utils/tc-token-utils.js.map +1 -0
- package/lib/Utils/use-mongo-file-auth-state.js +77 -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 +2 -1
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/use-single-file-auth-state.js +74 -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 +4 -10
- package/lib/Utils/validate-connection.js.map +1 -0
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/constants.d.ts.map +1 -0
- package/lib/WABinary/constants.js +2 -1
- 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 +2 -1
- 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 +2 -1
- 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 +15 -97
- 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 +3 -1
- 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 +4 -1
- 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 -1
- 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 +2 -1
- 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 +2 -1
- 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 +2 -1
- 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 +2 -1
- 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 +2 -1
- 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 +2 -1
- 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 +2 -1
- 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 +2 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.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 +2 -1
- 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 +2 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/index.js +3 -1
- package/lib/WAUSync/Protocols/index.js.map +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +29 -0
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
- package/lib/WAUSync/USyncQuery.js +2 -1
- package/lib/WAUSync/USyncQuery.js.map +1 -0
- package/lib/WAUSync/USyncUser.d.ts +13 -0
- package/lib/WAUSync/USyncUser.d.ts.map +1 -0
- package/lib/WAUSync/USyncUser.js +2 -1
- 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 +2 -1
- 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 +22 -2
- package/lib/index.js.map +1 -0
- package/package.json +75 -72
- package/lib/Utils/offline-node-processor.js +0 -39
- package/lib/Utils/stanza-ack.js +0 -37
|
@@ -2,15 +2,19 @@ import NodeCache from '@cacheable/node-cache';
|
|
|
2
2
|
import { Boom } from '@hapi/boom';
|
|
3
3
|
import { randomBytes } from 'crypto';
|
|
4
4
|
import { proto } from '../../WAProto/index.js';
|
|
5
|
-
import {
|
|
6
|
-
import { aggregateMessageKeysNotFromMe, assertMediaContent, bindWaitForEvent, decryptMediaRetryData,
|
|
7
|
-
import { AssociationType } from '../Types/index.js';
|
|
5
|
+
import { DEFAULT_CACHE_TTLS, WA_DEFAULT_EPHEMERAL } from '../Defaults/index.js';
|
|
6
|
+
import { aggregateMessageKeysNotFromMe, assertMediaContent, bindWaitForEvent, decryptMediaRetryData, encodeNewsletterMessage, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, extractDeviceJids, generateMessageIDV2, generateParticipantHashV2, generateWAMessage, generateWAMessageFromContent, prepareWAMessageMedia, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, MessageRetryManager, normalizeMessageContent, parseAndInjectE2ESessions, unixTimestampSeconds } from '../Utils/index.js';
|
|
8
7
|
import { getUrlInfo } from '../Utils/link-preview.js';
|
|
9
8
|
import { makeKeyedMutex } from '../Utils/make-mutex.js';
|
|
10
9
|
import { getMessageReportingToken, shouldIncludeReportingToken } from '../Utils/reporting-utils.js';
|
|
11
|
-
import { areJidsSameUser, getBinaryNodeChild, getBinaryNodeChildren,
|
|
10
|
+
import { areJidsSameUser, getBinaryFilteredBizBot, getBinaryNodeChild, getBinaryNodeChildren, isHostedLidUser, isHostedPnUser, isJidGroup, isJidUser, isLidUser, isPnUser, jidDecode, jidEncode, jidNormalizedUser, S_WHATSAPP_NET, STORIES_JID } from '../WABinary/index.js';
|
|
11
|
+
import { delay } from '../Utils/generics.js';
|
|
12
|
+
|
|
12
13
|
import { USyncQuery, USyncUser } from '../WAUSync/index.js';
|
|
13
14
|
import { makeNewsletterSocket } from './newsletter.js';
|
|
15
|
+
// Inline helper — no external import needed
|
|
16
|
+
const _isNewsletterJid = (jid) => typeof jid === 'string' && jid.endsWith('@newsletter');
|
|
17
|
+
|
|
14
18
|
export const makeMessagesSocket = (config) => {
|
|
15
19
|
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: httpRequestOptions, patchMessageBeforeSending, cachedGroupMetadata, enableRecentMessageCache, maxMsgRetryCount } = config;
|
|
16
20
|
const sock = makeNewsletterSocket(config);
|
|
@@ -129,21 +133,21 @@ export const makeMessagesSocket = (config) => {
|
|
|
129
133
|
const toFetch = [];
|
|
130
134
|
const jidsWithUser = jids
|
|
131
135
|
.map(jid => {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
136
|
+
const decoded = jidDecode(jid);
|
|
137
|
+
const user = decoded?.user;
|
|
138
|
+
const device = decoded?.device;
|
|
139
|
+
const isExplicitDevice = typeof device === 'number' && device >= 0;
|
|
140
|
+
if (isExplicitDevice && user) {
|
|
141
|
+
deviceResults.push({
|
|
142
|
+
user,
|
|
143
|
+
device,
|
|
144
|
+
jid
|
|
145
|
+
});
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
jid = jidNormalizedUser(jid);
|
|
149
|
+
return { jid, user };
|
|
150
|
+
})
|
|
147
151
|
.filter(jid => jid !== null);
|
|
148
152
|
let mgetDevices;
|
|
149
153
|
if (useCache && userDevicesCache.mget) {
|
|
@@ -242,7 +246,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
242
246
|
const userDeviceUpdates = {};
|
|
243
247
|
for (const [userId, devices] of Object.entries(deviceMap)) {
|
|
244
248
|
if (devices && devices.length > 0) {
|
|
245
|
-
userDeviceUpdates[userId] = devices.map(d => d.device?.toString());
|
|
249
|
+
userDeviceUpdates[userId] = devices.map(d => d.device?.toString() || '0');
|
|
246
250
|
}
|
|
247
251
|
}
|
|
248
252
|
if (Object.keys(userDeviceUpdates).length > 0) {
|
|
@@ -429,7 +433,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
429
433
|
}
|
|
430
434
|
return { nodes, shouldIncludeDeviceIdentity };
|
|
431
435
|
};
|
|
432
|
-
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }) => {
|
|
436
|
+
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList, AI = false }) => {
|
|
433
437
|
const meId = authState.creds.me.id;
|
|
434
438
|
const meLid = authState.creds.me?.lid;
|
|
435
439
|
const isRetryResend = Boolean(participant?.jid);
|
|
@@ -470,28 +474,94 @@ export const makeMessagesSocket = (config) => {
|
|
|
470
474
|
});
|
|
471
475
|
}
|
|
472
476
|
await authState.keys.transaction(async () => {
|
|
473
|
-
|
|
474
|
-
const innerMessage = normalizeMessageContent(message);
|
|
475
|
-
const mediaType = getMediaType(innerMessage);
|
|
477
|
+
const mediaType = getMediaType(message);
|
|
476
478
|
if (mediaType) {
|
|
477
479
|
extraAttrs['mediatype'] = mediaType;
|
|
478
480
|
}
|
|
479
481
|
if (isNewsletter) {
|
|
480
|
-
|
|
481
|
-
|
|
482
|
+
// Handle edit
|
|
483
|
+
if (message.protocolMessage?.editedMessage) {
|
|
484
|
+
msgId = message.protocolMessage.key?.id;
|
|
485
|
+
message = message.protocolMessage.editedMessage;
|
|
486
|
+
}
|
|
487
|
+
// Handle delete/revoke
|
|
488
|
+
if (message.protocolMessage?.type === proto.Message.ProtocolMessage.Type.REVOKE) {
|
|
489
|
+
msgId = message.protocolMessage.key?.id;
|
|
490
|
+
message = {};
|
|
482
491
|
}
|
|
492
|
+
// ── Newsletter Button Compatibility Patch ──────────────────────
|
|
493
|
+
// interactiveMessage (quick_reply / single_select / cta_url) bisa
|
|
494
|
+
// dikirim ke newsletter langsung — WA menerima via proto encoding.
|
|
495
|
+
// listMessage & buttonsMessage dikonversi ke interactiveMessage
|
|
496
|
+
// supaya konsisten dengan cara bot menulis pesan.
|
|
497
|
+
// ──────────────────────────────────────────────────────────────
|
|
498
|
+
if (message.listMessage) {
|
|
499
|
+
const list = message.listMessage;
|
|
500
|
+
message = {
|
|
501
|
+
interactiveMessage: {
|
|
502
|
+
nativeFlowMessage: {
|
|
503
|
+
buttons: [{
|
|
504
|
+
name: 'single_select',
|
|
505
|
+
buttonParamsJson: JSON.stringify({
|
|
506
|
+
title: list.buttonText || 'Select',
|
|
507
|
+
sections: (list.sections || []).map(sec => ({
|
|
508
|
+
title: sec.title || '',
|
|
509
|
+
highlight_label: '',
|
|
510
|
+
rows: (sec.rows || []).map(row => ({
|
|
511
|
+
header: '',
|
|
512
|
+
title: row.title || '',
|
|
513
|
+
description: row.description || '',
|
|
514
|
+
id: row.rowId || row.id || ''
|
|
515
|
+
}))
|
|
516
|
+
}))
|
|
517
|
+
})
|
|
518
|
+
}],
|
|
519
|
+
messageParamsJson: '',
|
|
520
|
+
messageVersion: 1
|
|
521
|
+
},
|
|
522
|
+
body: { text: list.description || '' },
|
|
523
|
+
...(list.footerText ? { footer: { text: list.footerText } } : {}),
|
|
524
|
+
...(list.title ? { header: { title: list.title, hasMediaAttachment: false, subtitle: '' } } : {})
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
else if (message.buttonsMessage) {
|
|
529
|
+
const bMsg = message.buttonsMessage;
|
|
530
|
+
message = {
|
|
531
|
+
interactiveMessage: {
|
|
532
|
+
nativeFlowMessage: {
|
|
533
|
+
buttons: (bMsg.buttons || []).map(btn => ({
|
|
534
|
+
name: 'quick_reply',
|
|
535
|
+
buttonParamsJson: JSON.stringify({
|
|
536
|
+
display_text: btn.buttonText?.displayText || btn.buttonText || '',
|
|
537
|
+
id: btn.buttonId || btn.buttonText?.displayText || ''
|
|
538
|
+
})
|
|
539
|
+
})),
|
|
540
|
+
messageParamsJson: '',
|
|
541
|
+
messageVersion: 1
|
|
542
|
+
},
|
|
543
|
+
body: { text: bMsg.contentText || bMsg.text || '' },
|
|
544
|
+
...(bMsg.footerText ? { footer: { text: bMsg.footerText } } : {}),
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
// ── End Newsletter Button Compatibility Patch ──────────────────
|
|
483
549
|
const patched = patchMessageBeforeSending ? await patchMessageBeforeSending(message, []) : message;
|
|
550
|
+
if (Array.isArray(patched)) {
|
|
551
|
+
throw new Error('Per-jid patching is not supported in channel');
|
|
552
|
+
}
|
|
484
553
|
const bytes = encodeNewsletterMessage(patched);
|
|
485
|
-
//
|
|
486
|
-
if (
|
|
487
|
-
;
|
|
488
|
-
binaryNodeContent.push(...additionalNodes);
|
|
554
|
+
// Set mediatype for interactive messages
|
|
555
|
+
if (patched.interactiveMessage && !extraAttrs['mediatype']) {
|
|
556
|
+
extraAttrs['mediatype'] = 'interactive';
|
|
489
557
|
}
|
|
558
|
+
// extraAttrs already has mediatype set above if media message
|
|
490
559
|
binaryNodeContent.push({
|
|
491
560
|
tag: 'plaintext',
|
|
492
|
-
attrs: extraAttrs,
|
|
561
|
+
attrs: extraAttrs,
|
|
493
562
|
content: bytes
|
|
494
563
|
});
|
|
564
|
+
logger.debug({ msgId, extraAttrs }, `sending newsletter message to ${jid}`);
|
|
495
565
|
const stanza = {
|
|
496
566
|
tag: 'message',
|
|
497
567
|
attrs: {
|
|
@@ -502,18 +572,12 @@ export const makeMessagesSocket = (config) => {
|
|
|
502
572
|
},
|
|
503
573
|
content: binaryNodeContent
|
|
504
574
|
};
|
|
505
|
-
logger.debug({ msgId }, `sending newsletter message to ${jid}`);
|
|
506
575
|
await sendNode(stanza);
|
|
507
576
|
return;
|
|
508
577
|
}
|
|
509
|
-
|
|
510
|
-
if (innerMessage?.pinInChatMessage || innerMessage?.pollUpdateMessage || innerMessage?.keepInChatMessage || innerMessage?.protocolMessage?.editedMessage || innerMessage?.protocolMessage?.mediaNotifyMessage || innerMessage?.reactionMessage) {
|
|
578
|
+
if (normalizeMessageContent(message)?.pinInChatMessage || normalizeMessageContent(message)?.reactionMessage) {
|
|
511
579
|
extraAttrs['decrypt-fail'] = 'hide'; // todo: expand for reactions and other types
|
|
512
580
|
}
|
|
513
|
-
// vltcs@changes 02-02-26 --- Add native_flow_name to extraAttrs when sending interactiveResponseMessage
|
|
514
|
-
if (innerMessage?.interactiveResponseMessage?.nativeFlowResponseMessage) {
|
|
515
|
-
extraAttrs['native_flow_name'] = innerMessage.interactiveResponseMessage.nativeFlowResponseMessage.name;
|
|
516
|
-
}
|
|
517
581
|
if (isGroupOrStatus && !isRetryResend) {
|
|
518
582
|
const [groupData, senderKeyMap] = await Promise.all([
|
|
519
583
|
(async () => {
|
|
@@ -554,6 +618,147 @@ export const makeMessagesSocket = (config) => {
|
|
|
554
618
|
addressing_mode: groupData?.addressingMode || 'lid'
|
|
555
619
|
};
|
|
556
620
|
}
|
|
621
|
+
// Ensure groupStatusMessageV2 always has messageContextInfo.messageSecret
|
|
622
|
+
if (message?.groupStatusMessageV2 && !message?.messageContextInfo?.messageSecret) {
|
|
623
|
+
const { randomBytes } = await import('node:crypto');
|
|
624
|
+
message = {
|
|
625
|
+
...message,
|
|
626
|
+
messageContextInfo: {
|
|
627
|
+
...(message.messageContextInfo || {}),
|
|
628
|
+
messageSecret: randomBytes(32)
|
|
629
|
+
},
|
|
630
|
+
groupStatusMessageV2: {
|
|
631
|
+
...message.groupStatusMessageV2,
|
|
632
|
+
message: {
|
|
633
|
+
...(message.groupStatusMessageV2.message || {}),
|
|
634
|
+
messageContextInfo: {
|
|
635
|
+
...(message.groupStatusMessageV2.message?.messageContextInfo || {}),
|
|
636
|
+
messageSecret: message.messageContextInfo?.messageSecret || randomBytes(32)
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
// ── Group Interactive Message Compatibility Patch ──────────────
|
|
643
|
+
// WhatsApp groups do NOT render listMessage, buttonsMessage, or
|
|
644
|
+
// templateMessage natively in MD protocol. All must be converted
|
|
645
|
+
// to interactiveMessage with nativeFlowMessage so they display
|
|
646
|
+
// and are interactive in group chats.
|
|
647
|
+
// ──────────────────────────────────────────────────────────────
|
|
648
|
+
|
|
649
|
+
// 1. listMessage → interactiveMessage single_select
|
|
650
|
+
if (message.listMessage) {
|
|
651
|
+
const list = message.listMessage;
|
|
652
|
+
const interactiveMessage = {
|
|
653
|
+
nativeFlowMessage: {
|
|
654
|
+
buttons: [{
|
|
655
|
+
name: 'single_select',
|
|
656
|
+
buttonParamsJson: JSON.stringify({
|
|
657
|
+
title: list.buttonText || 'Select',
|
|
658
|
+
sections: (list.sections || []).map(section => ({
|
|
659
|
+
title: section.title || '',
|
|
660
|
+
highlight_label: '',
|
|
661
|
+
rows: (section.rows || []).map(row => ({
|
|
662
|
+
header: '',
|
|
663
|
+
title: row.title || '',
|
|
664
|
+
description: row.description || '',
|
|
665
|
+
id: row.rowId || row.id || ''
|
|
666
|
+
}))
|
|
667
|
+
}))
|
|
668
|
+
})
|
|
669
|
+
}],
|
|
670
|
+
messageParamsJson: '',
|
|
671
|
+
messageVersion: 1
|
|
672
|
+
},
|
|
673
|
+
body: { text: list.description || '' },
|
|
674
|
+
footer: list.footerText ? { text: list.footerText } : undefined,
|
|
675
|
+
header: list.title ? { title: list.title, hasMediaAttachment: false, subtitle: '' } : undefined,
|
|
676
|
+
contextInfo: list.contextInfo
|
|
677
|
+
};
|
|
678
|
+
message = { interactiveMessage };
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// 2. buttonsMessage → interactiveMessage nativeFlowMessage quick_reply buttons
|
|
682
|
+
else if (message.buttonsMessage) {
|
|
683
|
+
const bMsg = message.buttonsMessage;
|
|
684
|
+
const buttons = (bMsg.buttons || []).map(btn => ({
|
|
685
|
+
name: 'quick_reply',
|
|
686
|
+
buttonParamsJson: JSON.stringify({
|
|
687
|
+
display_text: btn.buttonText?.displayText || btn.buttonText || '',
|
|
688
|
+
id: btn.buttonId || btn.buttonText?.displayText || ''
|
|
689
|
+
})
|
|
690
|
+
}));
|
|
691
|
+
const interactiveMessage = {
|
|
692
|
+
nativeFlowMessage: {
|
|
693
|
+
buttons,
|
|
694
|
+
messageParamsJson: '',
|
|
695
|
+
messageVersion: 1
|
|
696
|
+
},
|
|
697
|
+
body: { text: bMsg.contentText || bMsg.text || '' },
|
|
698
|
+
footer: bMsg.footerText ? { text: bMsg.footerText } : undefined,
|
|
699
|
+
header: bMsg.text
|
|
700
|
+
? { title: bMsg.text, hasMediaAttachment: false, subtitle: '' }
|
|
701
|
+
: (bMsg.imageMessage || bMsg.videoMessage || bMsg.documentMessage
|
|
702
|
+
? { hasMediaAttachment: true, ...(bMsg.imageMessage ? { imageMessage: bMsg.imageMessage } : {}), ...(bMsg.videoMessage ? { videoMessage: bMsg.videoMessage } : {}) }
|
|
703
|
+
: undefined),
|
|
704
|
+
contextInfo: bMsg.contextInfo
|
|
705
|
+
};
|
|
706
|
+
message = { interactiveMessage };
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
// 3. templateMessage (hydratedFourRowTemplate) → interactiveMessage nativeFlowMessage
|
|
710
|
+
else if (message.templateMessage) {
|
|
711
|
+
const tmpl = message.templateMessage.hydratedTemplate || message.templateMessage.fourRowTemplate;
|
|
712
|
+
if (tmpl) {
|
|
713
|
+
const hydratedButtons = tmpl.hydratedButtons || [];
|
|
714
|
+
const buttons = hydratedButtons.map(hBtn => {
|
|
715
|
+
if (hBtn.quickReplyButton) {
|
|
716
|
+
return {
|
|
717
|
+
name: 'quick_reply',
|
|
718
|
+
buttonParamsJson: JSON.stringify({
|
|
719
|
+
display_text: hBtn.quickReplyButton.displayText || '',
|
|
720
|
+
id: hBtn.quickReplyButton.id || hBtn.quickReplyButton.displayText || ''
|
|
721
|
+
})
|
|
722
|
+
};
|
|
723
|
+
} else if (hBtn.urlButton) {
|
|
724
|
+
return {
|
|
725
|
+
name: 'cta_url',
|
|
726
|
+
buttonParamsJson: JSON.stringify({
|
|
727
|
+
display_text: hBtn.urlButton.displayText || '',
|
|
728
|
+
url: hBtn.urlButton.url || '',
|
|
729
|
+
merchant_url: hBtn.urlButton.url || ''
|
|
730
|
+
})
|
|
731
|
+
};
|
|
732
|
+
} else if (hBtn.callButton) {
|
|
733
|
+
return {
|
|
734
|
+
name: 'cta_call',
|
|
735
|
+
buttonParamsJson: JSON.stringify({
|
|
736
|
+
display_text: hBtn.callButton.displayText || '',
|
|
737
|
+
phone_number: hBtn.callButton.phoneNumber || ''
|
|
738
|
+
})
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
return null;
|
|
742
|
+
}).filter(Boolean);
|
|
743
|
+
const interactiveMessage = {
|
|
744
|
+
nativeFlowMessage: {
|
|
745
|
+
buttons,
|
|
746
|
+
messageParamsJson: '',
|
|
747
|
+
messageVersion: 1
|
|
748
|
+
},
|
|
749
|
+
body: { text: tmpl.hydratedContentText || tmpl.contentText || '' },
|
|
750
|
+
footer: tmpl.hydratedFooterText ? { text: tmpl.hydratedFooterText } : undefined,
|
|
751
|
+
header: tmpl.hydratedTitleText
|
|
752
|
+
? { title: tmpl.hydratedTitleText, hasMediaAttachment: false, subtitle: '' }
|
|
753
|
+
: (tmpl.imageMessage || tmpl.videoMessage || tmpl.documentMessage
|
|
754
|
+
? { hasMediaAttachment: true, ...(tmpl.imageMessage ? { imageMessage: tmpl.imageMessage } : {}), ...(tmpl.videoMessage ? { videoMessage: tmpl.videoMessage } : {}) }
|
|
755
|
+
: undefined),
|
|
756
|
+
contextInfo: tmpl.contextInfo
|
|
757
|
+
};
|
|
758
|
+
message = { interactiveMessage };
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
// ── End Group Interactive Message Compatibility Patch ──────────
|
|
557
762
|
const patched = await patchMessageBeforeSending(message);
|
|
558
763
|
if (Array.isArray(patched)) {
|
|
559
764
|
throw new Boom('Per-jid patching is not supported in groups');
|
|
@@ -706,7 +911,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
706
911
|
attrs: {
|
|
707
912
|
v: '2',
|
|
708
913
|
type,
|
|
709
|
-
count: participant.count
|
|
914
|
+
count: participant.count.toString()
|
|
710
915
|
},
|
|
711
916
|
content: encryptedContent
|
|
712
917
|
});
|
|
@@ -797,22 +1002,22 @@ export const makeMessagesSocket = (config) => {
|
|
|
797
1002
|
content: tcTokenBuffer
|
|
798
1003
|
});
|
|
799
1004
|
}
|
|
800
|
-
if (
|
|
1005
|
+
if (AI && !isGroup && !isStatus && !isNewsletter) {
|
|
1006
|
+
const existingBizBot = getBinaryFilteredBizBot(additionalNodes || []);
|
|
1007
|
+
if (existingBizBot) {
|
|
1008
|
+
if (additionalNodes && additionalNodes.length > 0) {
|
|
1009
|
+
stanza.content.push(...additionalNodes);
|
|
1010
|
+
}
|
|
1011
|
+
} else {
|
|
1012
|
+
stanza.content.push({ tag: 'bot', attrs: { biz_bot: '1' } });
|
|
1013
|
+
if (additionalNodes && additionalNodes.length > 0) {
|
|
1014
|
+
stanza.content.push(...additionalNodes);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
} else if (additionalNodes && additionalNodes.length > 0) {
|
|
801
1018
|
;
|
|
802
1019
|
stanza.content.push(...additionalNodes);
|
|
803
1020
|
}
|
|
804
|
-
// vltcs@changes 30-01-26 --- Add Biz Binary Node to support button messages
|
|
805
|
-
else if (shouldIncludeBizBinaryNode(innerMessage)) {
|
|
806
|
-
const bizNode = getBizBinaryNode(innerMessage);
|
|
807
|
-
stanza.content.push(bizNode);
|
|
808
|
-
}
|
|
809
|
-
if (isGroup && OLD_GROUP_ID_REGEX.test(jid) && !innerMessage.reactionMessage) {
|
|
810
|
-
stanza.content.push({
|
|
811
|
-
tag: 'multicast',
|
|
812
|
-
attrs: {},
|
|
813
|
-
content: undefined
|
|
814
|
-
})
|
|
815
|
-
}
|
|
816
1021
|
logger.debug({ msgId }, `sending message to ${participants.length} devices`);
|
|
817
1022
|
await sendNode(stanza);
|
|
818
1023
|
// Add message to retry cache if enabled
|
|
@@ -823,6 +1028,11 @@ export const makeMessagesSocket = (config) => {
|
|
|
823
1028
|
return msgId;
|
|
824
1029
|
};
|
|
825
1030
|
const getMessageType = (message) => {
|
|
1031
|
+
// groupStatusMessageV2 must be checked BEFORE normalizeMessageContent
|
|
1032
|
+
// because normalizeMessageContent will unwrap it into inner message
|
|
1033
|
+
if (message?.groupStatusMessageV2 || message?.groupStatusMessage) {
|
|
1034
|
+
return 'text';
|
|
1035
|
+
}
|
|
826
1036
|
const normalizedMessage = normalizeMessageContent(message);
|
|
827
1037
|
if (!normalizedMessage)
|
|
828
1038
|
return 'text';
|
|
@@ -832,14 +1042,15 @@ export const makeMessagesSocket = (config) => {
|
|
|
832
1042
|
if (normalizedMessage.pollCreationMessage ||
|
|
833
1043
|
normalizedMessage.pollCreationMessageV2 ||
|
|
834
1044
|
normalizedMessage.pollCreationMessageV3 ||
|
|
835
|
-
normalizedMessage.pollCreationMessageV5 ||
|
|
836
|
-
normalizedMessage.pollCreationMessageV6 ||
|
|
837
1045
|
normalizedMessage.pollUpdateMessage) {
|
|
838
1046
|
return 'poll';
|
|
839
1047
|
}
|
|
840
1048
|
if (normalizedMessage.eventMessage) {
|
|
841
1049
|
return 'event';
|
|
842
1050
|
}
|
|
1051
|
+
if (normalizedMessage.interactiveMessage) {
|
|
1052
|
+
return 'text';
|
|
1053
|
+
}
|
|
843
1054
|
if (getMediaType(normalizedMessage) !== '') {
|
|
844
1055
|
return 'media';
|
|
845
1056
|
}
|
|
@@ -852,15 +1063,12 @@ export const makeMessagesSocket = (config) => {
|
|
|
852
1063
|
else if (message.videoMessage) {
|
|
853
1064
|
return message.videoMessage.gifPlayback ? 'gif' : 'video';
|
|
854
1065
|
}
|
|
855
|
-
else if (message.
|
|
856
|
-
return
|
|
1066
|
+
else if (message.ptvMessage) {
|
|
1067
|
+
return 'video';
|
|
857
1068
|
}
|
|
858
1069
|
else if (message.audioMessage) {
|
|
859
1070
|
return message.audioMessage.ptt ? 'ptt' : 'audio';
|
|
860
1071
|
}
|
|
861
|
-
else if (message.albumMessage) {
|
|
862
|
-
return 'collection';
|
|
863
|
-
}
|
|
864
1072
|
else if (message.contactMessage) {
|
|
865
1073
|
return 'vcard';
|
|
866
1074
|
}
|
|
@@ -873,6 +1081,9 @@ export const makeMessagesSocket = (config) => {
|
|
|
873
1081
|
else if (message.liveLocationMessage) {
|
|
874
1082
|
return 'livelocation';
|
|
875
1083
|
}
|
|
1084
|
+
else if (message.stickerMessage) {
|
|
1085
|
+
return 'sticker';
|
|
1086
|
+
}
|
|
876
1087
|
else if (message.stickerPackMessage) {
|
|
877
1088
|
return 'sticker_pack';
|
|
878
1089
|
}
|
|
@@ -894,17 +1105,10 @@ export const makeMessagesSocket = (config) => {
|
|
|
894
1105
|
else if (message.interactiveResponseMessage) {
|
|
895
1106
|
return 'native_flow_response';
|
|
896
1107
|
}
|
|
897
|
-
else if (message.
|
|
1108
|
+
else if (message.groupInviteMessage) {
|
|
898
1109
|
return 'url';
|
|
899
1110
|
}
|
|
900
|
-
|
|
901
|
-
else if ((message.extendedTextMessage?.text || message.conversation || '').includes('://wa.me/c/')) {
|
|
902
|
-
return 'cataloglink';
|
|
903
|
-
}
|
|
904
|
-
else if ((message.extendedTextMessage?.text || message.conversation || '').includes('://wa.me/p/')) {
|
|
905
|
-
return 'productlink';
|
|
906
|
-
}
|
|
907
|
-
return ''
|
|
1111
|
+
return '';
|
|
908
1112
|
};
|
|
909
1113
|
const getPrivacyTokens = async (jids) => {
|
|
910
1114
|
const t = unixTimestampSeconds().toString();
|
|
@@ -934,6 +1138,64 @@ export const makeMessagesSocket = (config) => {
|
|
|
934
1138
|
};
|
|
935
1139
|
const waUploadToServer = getWAUploadToServer(config, refreshMediaConn);
|
|
936
1140
|
const waitForMsgMediaUpdate = bindWaitForEvent(ev, 'messages.media-update');
|
|
1141
|
+
// ── Button type helpers (ported from itsukichan) ──────────────────────────
|
|
1142
|
+
const getButtonType = (message) => {
|
|
1143
|
+
if (message.listMessage) return 'list';
|
|
1144
|
+
if (message.buttonsMessage) return 'buttons';
|
|
1145
|
+
if (message.templateMessage) return 'template';
|
|
1146
|
+
if (message.interactiveMessage?.nativeFlowMessage) return 'native_flow';
|
|
1147
|
+
if (message.interactiveMessage?.shopStorefrontMessage) return 'shop';
|
|
1148
|
+
if (message.interactiveMessage?.collectionMessage) return 'collection';
|
|
1149
|
+
if (message.interactiveMessage?.carouselMessage) return 'carousel';
|
|
1150
|
+
if (message.interactiveMessage) return 'interactive';
|
|
1151
|
+
return null;
|
|
1152
|
+
};
|
|
1153
|
+
const getButtonArgs = (message) => {
|
|
1154
|
+
const nativeFlow = message.interactiveMessage?.nativeFlowMessage;
|
|
1155
|
+
const firstButtonName = nativeFlow?.buttons?.[0]?.name;
|
|
1156
|
+
const nativeFlowSpecials = [
|
|
1157
|
+
'mpm', 'cta_catalog', 'send_location',
|
|
1158
|
+
'call_permission_request', 'wa_payment_transaction_details',
|
|
1159
|
+
'automated_greeting_message_view_catalog'
|
|
1160
|
+
];
|
|
1161
|
+
const ts = unixTimestampSeconds().toString();
|
|
1162
|
+
const bizBase = { actual_actors: '2', host_storage: '2', privacy_mode_ts: ts };
|
|
1163
|
+
const qualityControl = { tag: 'quality_control', attrs: { source_type: 'third_party' } };
|
|
1164
|
+
if (nativeFlow && (firstButtonName === 'review_and_pay' || firstButtonName === 'payment_info')) {
|
|
1165
|
+
return {
|
|
1166
|
+
tag: 'biz',
|
|
1167
|
+
attrs: { native_flow_name: firstButtonName === 'review_and_pay' ? 'order_details' : firstButtonName }
|
|
1168
|
+
};
|
|
1169
|
+
} else if (nativeFlow && nativeFlowSpecials.includes(firstButtonName)) {
|
|
1170
|
+
return {
|
|
1171
|
+
tag: 'biz', attrs: bizBase,
|
|
1172
|
+
content: [{
|
|
1173
|
+
tag: 'interactive', attrs: { type: 'native_flow', v: '1' },
|
|
1174
|
+
content: [{ tag: 'native_flow', attrs: { v: '2', name: firstButtonName } }]
|
|
1175
|
+
}, qualityControl]
|
|
1176
|
+
};
|
|
1177
|
+
} else if (nativeFlow || message.buttonsMessage || message.templateMessage || message.interactiveMessage) {
|
|
1178
|
+
// All interactive types in groups use native_flow biz node
|
|
1179
|
+
// This covers: nativeFlowMessage, buttonsMessage→interactiveMessage,
|
|
1180
|
+
// templateMessage→interactiveMessage, and direct interactiveMessage
|
|
1181
|
+
return {
|
|
1182
|
+
tag: 'biz', attrs: bizBase,
|
|
1183
|
+
content: [{
|
|
1184
|
+
tag: 'interactive', attrs: { type: 'native_flow', v: '1' },
|
|
1185
|
+
content: [{ tag: 'native_flow', attrs: { v: '9', name: 'mixed' } }]
|
|
1186
|
+
}, qualityControl]
|
|
1187
|
+
};
|
|
1188
|
+
} else if (message.listMessage) {
|
|
1189
|
+
// Standalone listMessage (private chat) keeps the list biz node
|
|
1190
|
+
return {
|
|
1191
|
+
tag: 'biz', attrs: bizBase,
|
|
1192
|
+
content: [{ tag: 'list', attrs: { v: '2', type: 'product_list' } }, qualityControl]
|
|
1193
|
+
};
|
|
1194
|
+
} else {
|
|
1195
|
+
return { tag: 'biz', attrs: bizBase };
|
|
1196
|
+
}
|
|
1197
|
+
};
|
|
1198
|
+
// ── End button type helpers ───────────────────────────────────────────────
|
|
937
1199
|
return {
|
|
938
1200
|
...sock,
|
|
939
1201
|
getPrivacyTokens,
|
|
@@ -992,105 +1254,263 @@ export const makeMessagesSocket = (config) => {
|
|
|
992
1254
|
ev.emit('messages.update', [{ key: message.key, update: { message: message.message } }]);
|
|
993
1255
|
return message;
|
|
994
1256
|
},
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
if (
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1257
|
+
resize: async (media, width, height) => {
|
|
1258
|
+
const { getStream, toBuffer } = await import('../Utils/messages-media.js');
|
|
1259
|
+
let sharp;
|
|
1260
|
+
try { sharp = (await import('sharp')).default; } catch (_) {}
|
|
1261
|
+
if (!sharp) throw new Error('sharp is required for resize');
|
|
1262
|
+
const { stream } = await getStream(media);
|
|
1263
|
+
const buf = await toBuffer(stream);
|
|
1264
|
+
return sharp(buf).resize(width, height, { fit: 'cover' }).toBuffer();
|
|
1265
|
+
},
|
|
1266
|
+
sendStatusMentions: async (content, jids = []) => {
|
|
1267
|
+
const userJid = jidNormalizedUser(authState.creds.me.id);
|
|
1268
|
+
let allUsers = new Set();
|
|
1269
|
+
allUsers.add(userJid);
|
|
1270
|
+
|
|
1271
|
+
for (const id of jids) {
|
|
1272
|
+
const isGroup = isJidGroup(id);
|
|
1273
|
+
const isPrivate = isJidUser(id);
|
|
1274
|
+
if (isGroup) {
|
|
1275
|
+
try {
|
|
1276
|
+
const metadata = (cachedGroupMetadata ? await cachedGroupMetadata(id) : null) || await groupMetadata(id);
|
|
1277
|
+
const participants = metadata.participants.map(p => jidNormalizedUser(p.id));
|
|
1278
|
+
participants.forEach(j => allUsers.add(j));
|
|
1279
|
+
} catch (error) {
|
|
1280
|
+
logger.error(`Error getting metadata for group ${id}: ${error}`);
|
|
1281
|
+
}
|
|
1282
|
+
} else if (isPrivate) {
|
|
1283
|
+
allUsers.add(jidNormalizedUser(id));
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
const uniqueUsers = Array.from(allUsers);
|
|
1288
|
+
const getRandomHexColor = () => '#' + Math.floor(Math.random() * 16777215).toString(16).padStart(6, '0');
|
|
1289
|
+
|
|
1290
|
+
const isMedia = content.image || content.video || content.audio;
|
|
1291
|
+
const isAudio = !!content.audio;
|
|
1292
|
+
|
|
1293
|
+
const messageContent = { ...content };
|
|
1294
|
+
|
|
1295
|
+
if (isMedia && !isAudio) {
|
|
1296
|
+
if (messageContent.text) {
|
|
1297
|
+
messageContent.caption = messageContent.text;
|
|
1298
|
+
delete messageContent.text;
|
|
1299
|
+
}
|
|
1300
|
+
delete messageContent.ptt;
|
|
1301
|
+
delete messageContent.font;
|
|
1302
|
+
delete messageContent.backgroundColor;
|
|
1303
|
+
delete messageContent.textColor;
|
|
1304
|
+
}
|
|
1305
|
+
if (isAudio) {
|
|
1306
|
+
delete messageContent.text;
|
|
1307
|
+
delete messageContent.caption;
|
|
1308
|
+
delete messageContent.font;
|
|
1309
|
+
delete messageContent.textColor;
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
const font = !isMedia ? (content.font ?? Math.floor(Math.random() * 9)) : undefined;
|
|
1313
|
+
const textColor = !isMedia ? (content.textColor ?? getRandomHexColor()) : undefined;
|
|
1314
|
+
const backgroundColor = (!isMedia || isAudio) ? (content.backgroundColor ?? getRandomHexColor()) : undefined;
|
|
1315
|
+
const ptt = isAudio ? (typeof content.ptt === 'boolean' ? content.ptt : true) : undefined;
|
|
1316
|
+
|
|
1317
|
+
let msg;
|
|
1318
|
+
let mediaHandle;
|
|
1319
|
+
try {
|
|
1320
|
+
msg = await generateWAMessage(STORIES_JID, messageContent, {
|
|
1003
1321
|
logger,
|
|
1004
1322
|
userJid,
|
|
1005
|
-
|
|
1323
|
+
getUrlInfo: text => getUrlInfo(text, {
|
|
1324
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
1325
|
+
fetchOpts: { timeout: 3000 },
|
|
1326
|
+
logger,
|
|
1327
|
+
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
1328
|
+
}),
|
|
1329
|
+
upload: async (encFilePath, opts) => {
|
|
1330
|
+
const up = await waUploadToServer(encFilePath, { ...opts });
|
|
1331
|
+
mediaHandle = up.handle;
|
|
1332
|
+
return up;
|
|
1333
|
+
},
|
|
1006
1334
|
mediaCache: config.mediaCache,
|
|
1007
1335
|
options: config.options,
|
|
1008
|
-
|
|
1009
|
-
|
|
1336
|
+
font,
|
|
1337
|
+
textColor,
|
|
1338
|
+
backgroundColor,
|
|
1339
|
+
ptt
|
|
1010
1340
|
});
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
content: jid.map(id => ({
|
|
1041
|
-
tag: 'to',
|
|
1042
|
-
attrs: { jid: id },
|
|
1043
|
-
content: undefined
|
|
1044
|
-
}))
|
|
1045
|
-
}
|
|
1046
|
-
]
|
|
1047
|
-
}
|
|
1048
|
-
]
|
|
1049
|
-
});
|
|
1050
|
-
if (config.emitOwnEvents) {
|
|
1051
|
-
process.nextTick(async () => {
|
|
1052
|
-
await messageMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
|
1053
|
-
});
|
|
1054
|
-
}
|
|
1055
|
-
for (const id of jid) {
|
|
1056
|
-
const isGroup = isJidGroup(id)
|
|
1057
|
-
const sendType = isGroup ? 'groupStatusMentionMessage' : 'statusMentionMessage';
|
|
1058
|
-
const mentionMsg = generateWAMessageFromContent(id, {
|
|
1059
|
-
messageContextInfo: {
|
|
1060
|
-
messageSecret: randomBytes(32)
|
|
1061
|
-
},
|
|
1062
|
-
[sendType]: {
|
|
1341
|
+
} catch (error) {
|
|
1342
|
+
logger.error(`Error generating status message: ${error}`);
|
|
1343
|
+
throw error;
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
await relayMessage(STORIES_JID, msg.message, {
|
|
1347
|
+
messageId: msg.key.id,
|
|
1348
|
+
statusJidList: uniqueUsers,
|
|
1349
|
+
additionalNodes: [{
|
|
1350
|
+
tag: 'meta',
|
|
1351
|
+
attrs: {},
|
|
1352
|
+
content: [{
|
|
1353
|
+
tag: 'mentioned_users',
|
|
1354
|
+
attrs: {},
|
|
1355
|
+
content: jids.map(jid => ({
|
|
1356
|
+
tag: 'to',
|
|
1357
|
+
attrs: { jid: jidNormalizedUser(jid) }
|
|
1358
|
+
}))
|
|
1359
|
+
}]
|
|
1360
|
+
}]
|
|
1361
|
+
});
|
|
1362
|
+
|
|
1363
|
+
for (const id of jids) {
|
|
1364
|
+
try {
|
|
1365
|
+
const normalizedId = jidNormalizedUser(id);
|
|
1366
|
+
const isPrivate = isJidUser(normalizedId);
|
|
1367
|
+
const type = isPrivate ? 'statusMentionMessage' : 'groupStatusMentionMessage';
|
|
1368
|
+
const protocolMessage = {
|
|
1369
|
+
[type]: {
|
|
1063
1370
|
message: {
|
|
1064
1371
|
protocolMessage: {
|
|
1065
|
-
key:
|
|
1372
|
+
key: msg.key,
|
|
1066
1373
|
type: 25
|
|
1067
1374
|
}
|
|
1068
1375
|
}
|
|
1376
|
+
},
|
|
1377
|
+
messageContextInfo: {
|
|
1378
|
+
messageSecret: randomBytes(32)
|
|
1069
1379
|
}
|
|
1070
|
-
}
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
{ is_status_mention: 'true' },
|
|
1080
|
-
content: undefined
|
|
1081
|
-
}
|
|
1082
|
-
]
|
|
1380
|
+
};
|
|
1381
|
+
const statusMsg = await generateWAMessageFromContent(normalizedId, protocolMessage, {});
|
|
1382
|
+
await relayMessage(normalizedId, statusMsg.message, {
|
|
1383
|
+
additionalNodes: [{
|
|
1384
|
+
tag: 'meta',
|
|
1385
|
+
attrs: isPrivate
|
|
1386
|
+
? { is_status_mention: 'true' }
|
|
1387
|
+
: { is_group_status_mention: 'true' }
|
|
1388
|
+
}]
|
|
1083
1389
|
});
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1390
|
+
await delay(2000);
|
|
1391
|
+
} catch (error) {
|
|
1392
|
+
logger.error(`Error sending status mention to ${id}: ${error}`);
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
return msg;
|
|
1397
|
+
},
|
|
1398
|
+
sendMessage: async (jid, content, options = {}) => {
|
|
1399
|
+
const userJid = authState.creds.me.id;
|
|
1400
|
+
// ── Normalize: buttons[].nativeFlowInfo -> interactiveButtons ──────
|
|
1401
|
+
if (
|
|
1402
|
+
typeof content === 'object' &&
|
|
1403
|
+
Array.isArray(content.buttons) &&
|
|
1404
|
+
content.buttons.length > 0 &&
|
|
1405
|
+
content.buttons.some(b => b.nativeFlowInfo)
|
|
1406
|
+
) {
|
|
1407
|
+
const interactiveButtons = content.buttons.map(b => {
|
|
1408
|
+
if (b.nativeFlowInfo) {
|
|
1409
|
+
return {
|
|
1410
|
+
name: b.nativeFlowInfo.name,
|
|
1411
|
+
buttonParamsJson: b.nativeFlowInfo.paramsJson || '{}'
|
|
1412
|
+
};
|
|
1088
1413
|
}
|
|
1089
|
-
|
|
1414
|
+
return {
|
|
1415
|
+
name: 'quick_reply',
|
|
1416
|
+
buttonParamsJson: JSON.stringify({
|
|
1417
|
+
display_text: b.buttonText?.displayText || b.buttonId || 'Button',
|
|
1418
|
+
id: b.buttonId || b.buttonText?.displayText || 'btn'
|
|
1419
|
+
})
|
|
1420
|
+
};
|
|
1421
|
+
});
|
|
1422
|
+
const { buttons, headerType, viewOnce, ...rest } = content;
|
|
1423
|
+
content = { ...rest, interactiveButtons };
|
|
1424
|
+
}
|
|
1425
|
+
// ── Interactive Button (sendButton logic) ──────────────────────────
|
|
1426
|
+
if (typeof content === 'object' && Array.isArray(content.interactiveButtons) && content.interactiveButtons.length > 0) {
|
|
1427
|
+
const {
|
|
1428
|
+
text = '',
|
|
1429
|
+
caption = '',
|
|
1430
|
+
title = '',
|
|
1431
|
+
footer = '',
|
|
1432
|
+
interactiveButtons,
|
|
1433
|
+
hasMediaAttachment = false,
|
|
1434
|
+
image = null,
|
|
1435
|
+
video = null,
|
|
1436
|
+
document = null,
|
|
1437
|
+
mimetype = null,
|
|
1438
|
+
jpegThumbnail = null,
|
|
1439
|
+
location = null,
|
|
1440
|
+
product = null,
|
|
1441
|
+
businessOwnerJid = null,
|
|
1442
|
+
externalAdReply = null,
|
|
1443
|
+
} = content;
|
|
1444
|
+
// Normalize buttons
|
|
1445
|
+
const processedButtons = [];
|
|
1446
|
+
for (let i = 0; i < interactiveButtons.length; i++) {
|
|
1447
|
+
const btn = interactiveButtons[i];
|
|
1448
|
+
if (!btn || typeof btn !== 'object') throw new Error(`interactiveButtons[${i}] must be an object`);
|
|
1449
|
+
if (btn.name && btn.buttonParamsJson) { processedButtons.push(btn); continue; }
|
|
1450
|
+
if (btn.id || btn.text || btn.displayText) {
|
|
1451
|
+
processedButtons.push({ name: 'quick_reply', buttonParamsJson: JSON.stringify({ display_text: btn.text || btn.displayText || `Button ${i + 1}`, id: btn.id || `quick_${i + 1}` }) });
|
|
1452
|
+
continue;
|
|
1453
|
+
}
|
|
1454
|
+
if (btn.buttonId && btn.buttonText?.displayText) {
|
|
1455
|
+
processedButtons.push({ name: 'quick_reply', buttonParamsJson: JSON.stringify({ display_text: btn.buttonText.displayText, id: btn.buttonId }) });
|
|
1456
|
+
continue;
|
|
1457
|
+
}
|
|
1458
|
+
throw new Error(`interactiveButtons[${i}] has invalid shape`);
|
|
1090
1459
|
}
|
|
1091
|
-
|
|
1460
|
+
let messageContent = {};
|
|
1461
|
+
// Header
|
|
1462
|
+
if (image) {
|
|
1463
|
+
const mi = Buffer.isBuffer(image) ? { image } : { image: { url: typeof image === 'object' ? image.url : image } };
|
|
1464
|
+
const pm = await prepareWAMessageMedia(mi, { upload: waUploadToServer });
|
|
1465
|
+
messageContent.header = { title: title || '', hasMediaAttachment: true, imageMessage: pm.imageMessage };
|
|
1466
|
+
} else if (video) {
|
|
1467
|
+
const mi = Buffer.isBuffer(video) ? { video } : { video: { url: typeof video === 'object' ? video.url : video } };
|
|
1468
|
+
const pm = await prepareWAMessageMedia(mi, { upload: waUploadToServer });
|
|
1469
|
+
messageContent.header = { title: title || '', hasMediaAttachment: true, videoMessage: pm.videoMessage };
|
|
1470
|
+
} else if (document) {
|
|
1471
|
+
const mi = Buffer.isBuffer(document) ? { document } : { document: { url: typeof document === 'object' ? document.url : document } };
|
|
1472
|
+
if (mimetype && typeof mi.document === 'object') mi.document.mimetype = mimetype;
|
|
1473
|
+
if (jpegThumbnail) {
|
|
1474
|
+
const thumb = Buffer.isBuffer(jpegThumbnail) ? jpegThumbnail : await (async () => { try { const r = await fetch(jpegThumbnail); return Buffer.from(await r.arrayBuffer()); } catch { return undefined; } })();
|
|
1475
|
+
if (thumb) mi.document.jpegThumbnail = thumb;
|
|
1476
|
+
}
|
|
1477
|
+
const pm = await prepareWAMessageMedia(mi, { upload: waUploadToServer });
|
|
1478
|
+
messageContent.header = { title: title || '', hasMediaAttachment: true, documentMessage: pm.documentMessage };
|
|
1479
|
+
} else if (location && typeof location === 'object') {
|
|
1480
|
+
messageContent.header = { title: title || location.name || 'Location', hasMediaAttachment: false, locationMessage: { degreesLatitude: location.degreesLatitude || location.degressLatitude || 0, degreesLongitude: location.degreesLongitude || location.degressLongitude || 0, name: location.name || '', address: location.address || '' } };
|
|
1481
|
+
} else if (product && typeof product === 'object') {
|
|
1482
|
+
let productImageMessage = null;
|
|
1483
|
+
if (product.productImage) {
|
|
1484
|
+
const mi = Buffer.isBuffer(product.productImage) ? { image: product.productImage } : { image: { url: typeof product.productImage === 'object' ? product.productImage.url : product.productImage } };
|
|
1485
|
+
const pm = await prepareWAMessageMedia(mi, { upload: waUploadToServer });
|
|
1486
|
+
productImageMessage = pm.imageMessage;
|
|
1487
|
+
}
|
|
1488
|
+
messageContent.header = { title: title || product.title || 'Product', hasMediaAttachment: false, productMessage: { product: { productImage: productImageMessage, productId: product.productId || '', title: product.title || '', description: product.description || '', currencyCode: product.currencyCode || 'USD', priceAmount1000: parseInt(product.priceAmount1000) || 0, retailerId: product.retailerId || '', url: product.url || '', productImageCount: product.productImageCount || 1 }, businessOwnerJid: businessOwnerJid || product.businessOwnerJid || userJid } };
|
|
1489
|
+
} else if (title) {
|
|
1490
|
+
messageContent.header = { title, hasMediaAttachment: false };
|
|
1491
|
+
}
|
|
1492
|
+
const hasMedia = !!(image || video || document || location || product);
|
|
1493
|
+
const bodyText = hasMedia ? caption : text || caption;
|
|
1494
|
+
if (bodyText) messageContent.body = { text: bodyText };
|
|
1495
|
+
if (footer) messageContent.footer = { text: footer };
|
|
1496
|
+
messageContent.nativeFlowMessage = { buttons: processedButtons };
|
|
1497
|
+
// Context info
|
|
1498
|
+
if (externalAdReply && typeof externalAdReply === 'object') {
|
|
1499
|
+
messageContent.contextInfo = { externalAdReply: { title: externalAdReply.title || '', body: externalAdReply.body || '', mediaType: externalAdReply.mediaType || 1, sourceUrl: externalAdReply.sourceUrl || externalAdReply.url || '', thumbnailUrl: externalAdReply.thumbnailUrl || externalAdReply.thumbnail || '', renderLargerThumbnail: externalAdReply.renderLargerThumbnail || false, showAdAttribution: externalAdReply.showAdAttribution !== false, containsAutoReply: externalAdReply.containsAutoReply || false, ...(externalAdReply.mediaUrl && { mediaUrl: externalAdReply.mediaUrl }), ...(Buffer.isBuffer(externalAdReply.thumbnail) && { thumbnail: externalAdReply.thumbnail }), ...(externalAdReply.jpegThumbnail && { jpegThumbnail: externalAdReply.jpegThumbnail }) }, ...(options.mentionedJid && { mentionedJid: options.mentionedJid }) };
|
|
1500
|
+
} else if (options.mentionedJid) {
|
|
1501
|
+
messageContent.contextInfo = { mentionedJid: options.mentionedJid };
|
|
1502
|
+
}
|
|
1503
|
+
const payload = proto.Message.InteractiveMessage.create(messageContent);
|
|
1504
|
+
const msg = generateWAMessageFromContent(jid, { viewOnceMessage: { message: { interactiveMessage: payload } } }, { userJid, quoted: options?.quoted || null });
|
|
1505
|
+
const additionalNodes = [{ tag: 'biz', attrs: {}, content: [{ tag: 'interactive', attrs: { type: 'native_flow', v: '1' }, content: [{ tag: 'native_flow', attrs: { v: '9', name: 'mixed' } }] }] }];
|
|
1506
|
+
await relayMessage(jid, msg.message, { messageId: msg.key.id, additionalNodes });
|
|
1507
|
+
return msg;
|
|
1092
1508
|
}
|
|
1093
|
-
|
|
1509
|
+
// ── End Interactive Button ─────────────────────────────────────────
|
|
1510
|
+
if (typeof content === 'object' &&
|
|
1511
|
+
'disappearingMessagesInChat' in content &&
|
|
1512
|
+
typeof content['disappearingMessagesInChat'] !== 'undefined' &&
|
|
1513
|
+
isJidGroup(jid)) {
|
|
1094
1514
|
const { disappearingMessagesInChat } = content;
|
|
1095
1515
|
const value = typeof disappearingMessagesInChat === 'boolean'
|
|
1096
1516
|
? disappearingMessagesInChat
|
|
@@ -1100,6 +1520,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
1100
1520
|
await groupToggleEphemeral(jid, value);
|
|
1101
1521
|
}
|
|
1102
1522
|
else {
|
|
1523
|
+
let mediaHandle;
|
|
1103
1524
|
const fullMsg = await generateWAMessage(jid, content, {
|
|
1104
1525
|
logger,
|
|
1105
1526
|
userJid,
|
|
@@ -1115,27 +1536,45 @@ export const makeMessagesSocket = (config) => {
|
|
|
1115
1536
|
//TODO: CACHE
|
|
1116
1537
|
getProfilePicUrl: sock.profilePictureUrl,
|
|
1117
1538
|
getCallLink: sock.createCallLink,
|
|
1118
|
-
|
|
1539
|
+
newsletter: _isNewsletterJid(jid),
|
|
1540
|
+
upload: async (encFilePath, opts) => {
|
|
1541
|
+
const up = await waUploadToServer(encFilePath, { ...opts, newsletter: _isNewsletterJid(jid) });
|
|
1542
|
+
mediaHandle = up.handle;
|
|
1543
|
+
return up;
|
|
1544
|
+
},
|
|
1119
1545
|
mediaCache: config.mediaCache,
|
|
1120
1546
|
options: config.options,
|
|
1121
|
-
|
|
1122
|
-
|
|
1547
|
+
messageId: generateMessageIDV2(sock.user?.id),
|
|
1548
|
+
...options
|
|
1123
1549
|
});
|
|
1124
|
-
|
|
1550
|
+
if (content?.audio && options?.contextInfo) {
|
|
1551
|
+
const msgContent = fullMsg.message;
|
|
1552
|
+
if (msgContent?.audioMessage) {
|
|
1553
|
+
msgContent.audioMessage.contextInfo = options.contextInfo;
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
// Extract handle from newsletter upload (set by prepareWAMessageMedia)
|
|
1557
|
+
if (!mediaHandle) {
|
|
1558
|
+
const msgContent = fullMsg.message;
|
|
1559
|
+
const msgTypes = ['audioMessage','imageMessage','videoMessage','documentMessage','stickerMessage'];
|
|
1560
|
+
for (const t of msgTypes) {
|
|
1561
|
+
if (msgContent?.[t]?._uploadHandle) {
|
|
1562
|
+
mediaHandle = msgContent[t]._uploadHandle;
|
|
1563
|
+
|
|
1564
|
+
delete msgContent[t]._uploadHandle;
|
|
1565
|
+
break;
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1125
1569
|
const isEventMsg = 'event' in content && !!content.event;
|
|
1126
1570
|
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
1127
1571
|
const isEditMsg = 'edit' in content && !!content.edit;
|
|
1128
1572
|
const isPinMsg = 'pin' in content && !!content.pin;
|
|
1129
|
-
const
|
|
1130
|
-
const
|
|
1131
|
-
const
|
|
1132
|
-
const isPollResultMsg = 'pollResult' in content && !!content.pollResult;
|
|
1133
|
-
const isPollUpdateMsg = 'pollUpdate' in content && !!content.pollUpdate;
|
|
1134
|
-
const isAiMsg = 'ai' in content && !!content.ai;
|
|
1135
|
-
const additionalAttributes = options.additionalAttributes || {};
|
|
1136
|
-
const additionalNodes = options.additionalNodes || [];
|
|
1573
|
+
const isPollMessage = 'poll' in content && !!content.poll;
|
|
1574
|
+
const additionalAttributes = {};
|
|
1575
|
+
const additionalNodes = [];
|
|
1137
1576
|
// required for delete
|
|
1138
|
-
if (isDeleteMsg
|
|
1577
|
+
if (isDeleteMsg) {
|
|
1139
1578
|
// if the chat is a group, and I am not the author, then delete the message as an admin
|
|
1140
1579
|
if (isJidGroup(content.delete?.remoteJid) && !content.delete?.fromMe) {
|
|
1141
1580
|
additionalAttributes.edit = '8';
|
|
@@ -1145,23 +1584,17 @@ export const makeMessagesSocket = (config) => {
|
|
|
1145
1584
|
}
|
|
1146
1585
|
}
|
|
1147
1586
|
else if (isEditMsg) {
|
|
1148
|
-
additionalAttributes.edit =
|
|
1587
|
+
additionalAttributes.edit = '1';
|
|
1149
1588
|
}
|
|
1150
1589
|
else if (isPinMsg) {
|
|
1151
1590
|
additionalAttributes.edit = '2';
|
|
1152
1591
|
}
|
|
1153
|
-
else if (
|
|
1154
|
-
if (!isJidNewsletter(jid) && isQuizMsg) {
|
|
1155
|
-
throw new Boom('Quiz are only allowed for newsletter', { statusCode: 400 });
|
|
1156
|
-
}
|
|
1592
|
+
else if (isPollMessage) {
|
|
1157
1593
|
additionalNodes.push({
|
|
1158
1594
|
tag: 'meta',
|
|
1159
1595
|
attrs: {
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
contenttype: isPollMsg && isNewsletter ? 'text' : undefined
|
|
1163
|
-
},
|
|
1164
|
-
content: undefined
|
|
1596
|
+
polltype: 'creation'
|
|
1597
|
+
}
|
|
1165
1598
|
});
|
|
1166
1599
|
}
|
|
1167
1600
|
else if (isEventMsg) {
|
|
@@ -1169,78 +1602,34 @@ export const makeMessagesSocket = (config) => {
|
|
|
1169
1602
|
tag: 'meta',
|
|
1170
1603
|
attrs: {
|
|
1171
1604
|
event_type: 'creation'
|
|
1172
|
-
}
|
|
1173
|
-
content: undefined
|
|
1605
|
+
}
|
|
1174
1606
|
});
|
|
1175
1607
|
}
|
|
1176
|
-
//
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
additionalNodes.push({
|
|
1185
|
-
tag: 'bot',
|
|
1186
|
-
attrs: {
|
|
1187
|
-
biz_bot: '1'
|
|
1188
|
-
},
|
|
1189
|
-
content: undefined
|
|
1190
|
-
});
|
|
1191
|
-
delete content.ai;
|
|
1608
|
+
// Auto-attach biz node for button/list/interactive messages
|
|
1609
|
+
const buttonType = getButtonType(fullMsg.message);
|
|
1610
|
+
if (buttonType) {
|
|
1611
|
+
const btnNode = getButtonArgs(fullMsg.message);
|
|
1612
|
+
if (btnNode) additionalNodes.push(btnNode);
|
|
1613
|
+
}
|
|
1614
|
+
if (mediaHandle) {
|
|
1615
|
+
additionalAttributes['media_id'] = mediaHandle;
|
|
1192
1616
|
}
|
|
1193
1617
|
await relayMessage(jid, fullMsg.message, {
|
|
1194
1618
|
messageId: fullMsg.key.id,
|
|
1195
1619
|
useCachedGroupMetadata: options.useCachedGroupMetadata,
|
|
1196
|
-
statusJidList: options.statusJidList,
|
|
1197
1620
|
additionalAttributes,
|
|
1198
|
-
|
|
1621
|
+
statusJidList: options.statusJidList,
|
|
1622
|
+
additionalNodes,
|
|
1623
|
+
AI: options.ai || false
|
|
1199
1624
|
});
|
|
1200
1625
|
if (config.emitOwnEvents) {
|
|
1201
1626
|
process.nextTick(async () => {
|
|
1202
1627
|
await messageMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
|
1203
1628
|
});
|
|
1204
1629
|
}
|
|
1205
|
-
// vltcs@changes 31-01-26 --- Add support for album messages
|
|
1206
|
-
// Lia@Note 06-02-26 --- Refactored to reduce high RSS usage (╥﹏╥)
|
|
1207
|
-
if ('album' in content) {
|
|
1208
|
-
const { delayMs = 1500 } = options;
|
|
1209
|
-
for (const albumMedia of content.album) {
|
|
1210
|
-
const albumMsg = await generateWAMessage(jid, albumMedia, {
|
|
1211
|
-
logger,
|
|
1212
|
-
userJid,
|
|
1213
|
-
upload: waUploadToServer,
|
|
1214
|
-
mediaCache: config.mediaCache,
|
|
1215
|
-
options: config.options,
|
|
1216
|
-
...options,
|
|
1217
|
-
messageId: generateMessageIDV2(userJid)
|
|
1218
|
-
});
|
|
1219
|
-
if (!hasValidAlbumMedia(normalizeMessageContent(albumMsg.message))) {
|
|
1220
|
-
throw new Boom('Invalid message type for album', { statusCode: 400 });
|
|
1221
|
-
}
|
|
1222
|
-
albumMsg.message.messageContextInfo ||= {};
|
|
1223
|
-
albumMsg.message.messageContextInfo.messageAssociation = {
|
|
1224
|
-
parentMessageKey: fullMsg.key,
|
|
1225
|
-
associationType: AssociationType.MEDIA_ALBUM
|
|
1226
|
-
};
|
|
1227
|
-
await relayMessage(jid, albumMsg.message, {
|
|
1228
|
-
messageId: albumMsg.key.id,
|
|
1229
|
-
useCachedGroupMetadata: options.useCachedGroupMetadata,
|
|
1230
|
-
statusJidList: options.statusJidList,
|
|
1231
|
-
additionalAttributes,
|
|
1232
|
-
additionalNodes
|
|
1233
|
-
});
|
|
1234
|
-
if (config.emitOwnEvents) {
|
|
1235
|
-
process.nextTick(async () => {
|
|
1236
|
-
await messageMutex.mutex(() => upsertMessage(albumMsg, 'append'));
|
|
1237
|
-
});
|
|
1238
|
-
}
|
|
1239
|
-
await delay(delayMs);
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
1630
|
return fullMsg;
|
|
1243
1631
|
}
|
|
1244
1632
|
}
|
|
1245
1633
|
};
|
|
1246
|
-
};
|
|
1634
|
+
};
|
|
1635
|
+
//# sourceMappingURL=messages-send.js.map
|