lordceaser-baileys 3.4.0 → 3.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +201 -0
- package/WAProto/_orig.js +92429 -277359
- package/WAProto/index.d.ts +11659 -95047
- package/WAProto/index.js +5 -2
- package/banner.png +0 -0
- package/index.js +11 -6
- package/lib/Defaults/index.d.ts +118 -48
- package/lib/Defaults/index.d.ts.map +1 -1
- package/lib/Defaults/index.js +29 -6
- package/lib/Defaults/index.js.map +1 -1
- package/lib/Signal/Group/ciphertext-message.d.ts +8 -8
- package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -1
- package/lib/Signal/Group/ciphertext-message.js.map +1 -1
- package/lib/Signal/Group/group-session-builder.d.ts +6 -13
- package/lib/Signal/Group/group-session-builder.d.ts.map +1 -1
- package/lib/Signal/Group/group-session-builder.js.map +1 -1
- package/lib/Signal/Group/group_cipher.d.ts +9 -15
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -1
- package/lib/Signal/Group/group_cipher.js.map +1 -1
- package/lib/Signal/Group/index.d.ts +11 -11
- package/lib/Signal/Group/index.d.ts.map +1 -1
- package/lib/Signal/Group/index.js.map +1 -1
- package/lib/Signal/Group/keyhelper.d.ts +6 -10
- package/lib/Signal/Group/keyhelper.d.ts.map +1 -1
- package/lib/Signal/Group/keyhelper.js.map +1 -1
- package/lib/Signal/Group/sender-chain-key.d.ts +10 -10
- package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -1
- package/lib/Signal/Group/sender-chain-key.js.map +1 -1
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +14 -14
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -1
- package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -1
- package/lib/Signal/Group/sender-key-message.d.ts +16 -16
- package/lib/Signal/Group/sender-key-message.d.ts.map +1 -1
- package/lib/Signal/Group/sender-key-message.js.map +1 -1
- package/lib/Signal/Group/sender-key-name.d.ts +7 -13
- package/lib/Signal/Group/sender-key-name.d.ts.map +1 -1
- package/lib/Signal/Group/sender-key-name.js.map +1 -1
- package/lib/Signal/Group/sender-key-record.d.ts +10 -28
- package/lib/Signal/Group/sender-key-record.d.ts.map +1 -1
- package/lib/Signal/Group/sender-key-record.js.map +1 -1
- package/lib/Signal/Group/sender-key-state.d.ts +14 -36
- package/lib/Signal/Group/sender-key-state.d.ts.map +1 -1
- package/lib/Signal/Group/sender-key-state.js.map +1 -1
- package/lib/Signal/Group/sender-message-key.d.ts +10 -10
- package/lib/Signal/Group/sender-message-key.d.ts.map +1 -1
- package/lib/Signal/Group/sender-message-key.js.map +1 -1
- package/lib/Signal/libsignal.d.ts +54 -4
- package/lib/Signal/libsignal.d.ts.map +1 -1
- package/lib/Signal/libsignal.js.map +1 -1
- package/lib/Signal/lid-mapping.d.ts +15 -17
- package/lib/Signal/lid-mapping.d.ts.map +1 -1
- package/lib/Signal/lid-mapping.js.map +1 -1
- package/lib/Socket/Client/index.d.ts +2 -2
- package/lib/Socket/Client/index.d.ts.map +1 -1
- package/lib/Socket/Client/index.js +1 -0
- package/lib/Socket/Client/index.js.map +1 -1
- package/lib/Socket/Client/types.d.ts +4 -14
- package/lib/Socket/Client/types.d.ts.map +1 -1
- package/lib/Socket/Client/types.js +2 -1
- package/lib/Socket/Client/types.js.map +1 -1
- package/lib/Socket/Client/websocket.d.ts +5 -5
- package/lib/Socket/Client/websocket.d.ts.map +1 -1
- package/lib/Socket/Client/websocket.js +2 -1
- package/lib/Socket/Client/websocket.js.map +1 -1
- package/lib/Socket/business.d.ts +353 -175
- package/lib/Socket/business.d.ts.map +1 -1
- package/lib/Socket/business.js +43 -70
- package/lib/Socket/business.js.map +1 -1
- package/lib/Socket/chats.d.ts +112 -93
- package/lib/Socket/chats.d.ts.map +1 -1
- package/lib/Socket/chats.js +20 -709
- package/lib/Socket/chats.js.map +1 -1
- package/lib/Socket/communities.d.ts +499 -210
- package/lib/Socket/communities.d.ts.map +1 -1
- package/lib/Socket/communities.js +1 -0
- package/lib/Socket/communities.js.map +1 -1
- package/lib/Socket/groups.d.ts +245 -120
- package/lib/Socket/groups.d.ts.map +1 -1
- package/lib/Socket/groups.js +5 -206
- package/lib/Socket/groups.js.map +1 -1
- package/lib/Socket/index.d.ts +478 -208
- package/lib/Socket/index.d.ts.map +1 -1
- package/lib/Socket/index.js +3 -28
- package/lib/Socket/index.js.map +1 -1
- package/lib/Socket/messages-recv.d.ts +295 -164
- package/lib/Socket/messages-recv.d.ts.map +1 -1
- package/lib/Socket/messages-recv.js +9 -381
- package/lib/Socket/messages-recv.js.map +1 -1
- package/lib/Socket/messages-send.d.ts +290 -159
- package/lib/Socket/messages-send.d.ts.map +1 -1
- package/lib/Socket/messages-send.js +154 -1963
- package/lib/Socket/messages-send.js.map +1 -1
- package/lib/Socket/mex.d.ts +1 -2
- package/lib/Socket/mex.d.ts.map +1 -1
- package/lib/Socket/mex.js +2 -1
- package/lib/Socket/mex.js.map +1 -1
- package/lib/Socket/newsletter.d.ts +251 -138
- package/lib/Socket/newsletter.d.ts.map +1 -1
- package/lib/Socket/newsletter.js +9 -43
- package/lib/Socket/newsletter.js.map +1 -1
- package/lib/Socket/socket.d.ts +44 -42
- package/lib/Socket/socket.d.ts.map +1 -1
- package/lib/Socket/socket.js +17 -64
- package/lib/Socket/socket.js.map +1 -1
- package/lib/Store/index.d.ts +4 -0
- package/lib/Store/index.d.ts.map +1 -0
- package/lib/Store/index.js +4 -0
- package/lib/Store/index.js.map +1 -0
- package/lib/Store/make-in-memory-store.d.ts +63 -0
- package/lib/Store/make-in-memory-store.d.ts.map +1 -0
- package/lib/Store/make-in-memory-store.js +421 -0
- package/lib/Store/make-in-memory-store.js.map +1 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.d.ts.map +1 -0
- package/lib/Store/make-ordered-dictionary.js +79 -0
- package/lib/Store/make-ordered-dictionary.js.map +1 -0
- package/lib/Store/object-repository.d.ts +11 -0
- package/lib/Store/object-repository.d.ts.map +1 -0
- package/lib/Store/object-repository.js +24 -0
- package/lib/Store/object-repository.js.map +1 -0
- package/lib/Types/Auth.d.ts +0 -115
- package/lib/Types/Auth.d.ts.map +1 -1
- package/lib/Types/Auth.js.map +1 -1
- package/lib/Types/Bussines.d.ts +1 -24
- package/lib/Types/Bussines.d.ts.map +1 -1
- package/lib/Types/Bussines.js.map +1 -1
- package/lib/Types/Call.d.ts +1 -14
- package/lib/Types/Call.d.ts.map +1 -1
- package/lib/Types/Call.js.map +1 -1
- package/lib/Types/Chat.d.ts +1 -123
- package/lib/Types/Chat.d.ts.map +1 -1
- package/lib/Types/Chat.js.map +1 -1
- package/lib/Types/Contact.d.ts +1 -25
- package/lib/Types/Contact.d.ts.map +1 -1
- package/lib/Types/Contact.js.map +1 -1
- package/lib/Types/Events.d.ts +1 -255
- package/lib/Types/Events.d.ts.map +1 -1
- package/lib/Types/Events.js.map +1 -1
- package/lib/Types/GroupMetadata.d.ts +1 -70
- package/lib/Types/GroupMetadata.d.ts.map +1 -1
- package/lib/Types/GroupMetadata.js.map +1 -1
- package/lib/Types/Label.d.ts +1 -45
- package/lib/Types/Label.d.ts.map +1 -1
- package/lib/Types/Label.js.map +1 -1
- package/lib/Types/LabelAssociation.d.ts +1 -28
- package/lib/Types/LabelAssociation.d.ts.map +1 -1
- package/lib/Types/LabelAssociation.js.map +1 -1
- package/lib/Types/Message.d.ts +10 -318
- package/lib/Types/Message.d.ts.map +1 -1
- package/lib/Types/Message.js +7 -0
- package/lib/Types/Message.js.map +1 -1
- package/lib/Types/Mex.d.ts +2 -140
- package/lib/Types/Mex.d.ts.map +1 -1
- package/lib/Types/Mex.js +2 -0
- package/lib/Types/Mex.js.map +1 -1
- package/lib/Types/Product.d.ts +1 -78
- package/lib/Types/Product.d.ts.map +1 -1
- package/lib/Types/Product.js.map +1 -1
- package/lib/Types/RichType.d.ts +3 -0
- package/lib/Types/RichType.d.ts.map +1 -0
- package/lib/Types/RichType.js +23 -0
- package/lib/Types/RichType.js.map +1 -0
- package/lib/Types/Signal.d.ts +0 -85
- package/lib/Types/Signal.d.ts.map +1 -1
- package/lib/Types/Signal.js.map +1 -1
- package/lib/Types/Socket.d.ts +1 -135
- package/lib/Types/Socket.d.ts.map +1 -1
- package/lib/Types/Socket.js +0 -1
- package/lib/Types/Socket.js.map +1 -1
- package/lib/Types/State.d.ts +5 -96
- package/lib/Types/State.d.ts.map +1 -1
- package/lib/Types/State.js.map +1 -1
- package/lib/Types/USync.d.ts +1 -25
- package/lib/Types/USync.d.ts.map +1 -1
- package/lib/Types/USync.js.map +1 -1
- package/lib/Types/index.d.ts +13 -65
- package/lib/Types/index.d.ts.map +1 -1
- package/lib/Types/index.js.map +1 -1
- package/lib/Utils/auth-utils.d.ts +51 -17
- package/lib/Utils/auth-utils.d.ts.map +1 -1
- package/lib/Utils/auth-utils.js +5 -1
- package/lib/Utils/auth-utils.js.map +1 -1
- package/lib/Utils/browser-utils.d.ts +9 -3
- package/lib/Utils/browser-utils.d.ts.map +1 -1
- package/lib/Utils/browser-utils.js.map +1 -1
- package/lib/Utils/business.d.ts +46 -19
- package/lib/Utils/business.d.ts.map +1 -1
- package/lib/Utils/business.js.map +1 -1
- package/lib/Utils/chat-utils.d.ts +398 -89
- package/lib/Utils/chat-utils.d.ts.map +1 -1
- package/lib/Utils/chat-utils.js.map +1 -1
- package/lib/Utils/companion-reg-client-utils.d.ts +4 -16
- package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -1
- package/lib/Utils/companion-reg-client-utils.js +7 -2
- package/lib/Utils/companion-reg-client-utils.js.map +1 -1
- package/lib/Utils/crypto.d.ts +29 -26
- package/lib/Utils/crypto.d.ts.map +1 -1
- package/lib/Utils/crypto.js +2 -0
- package/lib/Utils/crypto.js.map +1 -1
- package/lib/Utils/decode-wa-message.d.ts +76 -58
- package/lib/Utils/decode-wa-message.d.ts.map +1 -1
- package/lib/Utils/decode-wa-message.js.map +1 -1
- package/lib/Utils/event-buffer.d.ts +9 -32
- package/lib/Utils/event-buffer.d.ts.map +1 -1
- package/lib/Utils/event-buffer.js.map +1 -1
- package/lib/Utils/generics.d.ts +45 -73
- package/lib/Utils/generics.d.ts.map +1 -1
- package/lib/Utils/generics.js +17 -15
- package/lib/Utils/generics.js.map +1 -1
- package/lib/Utils/history.d.ts +73 -21
- package/lib/Utils/history.d.ts.map +1 -1
- package/lib/Utils/history.js.map +1 -1
- package/lib/Utils/identity-change-handler.d.ts +9 -39
- package/lib/Utils/identity-change-handler.d.ts.map +1 -1
- package/lib/Utils/identity-change-handler.js.map +1 -1
- package/lib/Utils/index.d.ts +24 -21
- package/lib/Utils/index.d.ts.map +1 -1
- package/lib/Utils/index.js +3 -0
- package/lib/Utils/index.js.map +1 -1
- package/lib/Utils/link-preview.d.ts +8 -16
- package/lib/Utils/link-preview.d.ts.map +1 -1
- package/lib/Utils/link-preview.js.map +1 -1
- package/lib/Utils/logger.d.ts +1 -10
- package/lib/Utils/logger.d.ts.map +1 -1
- package/lib/Utils/logger.js.map +1 -1
- package/lib/Utils/lt-hash.d.ts +1 -2
- package/lib/Utils/lt-hash.d.ts.map +1 -1
- package/lib/Utils/lt-hash.js.map +1 -1
- package/lib/Utils/make-mutex.d.ts +4 -6
- package/lib/Utils/make-mutex.d.ts.map +1 -1
- package/lib/Utils/make-mutex.js.map +1 -1
- package/lib/Utils/message-retry-manager.d.ts +36 -71
- package/lib/Utils/message-retry-manager.d.ts.map +1 -1
- package/lib/Utils/message-retry-manager.js +1 -1
- package/lib/Utils/message-retry-manager.js.map +1 -1
- package/lib/Utils/messages-media.d.ts +121 -117
- package/lib/Utils/messages-media.d.ts.map +1 -1
- package/lib/Utils/messages-media.js +87 -32
- package/lib/Utils/messages-media.js.map +1 -1
- package/lib/Utils/messages.d.ts +33 -78
- package/lib/Utils/messages.d.ts.map +1 -1
- package/lib/Utils/messages.js +1010 -63
- package/lib/Utils/messages.js.map +1 -1
- package/lib/Utils/noise-handler.d.ts +18 -17
- package/lib/Utils/noise-handler.d.ts.map +1 -1
- package/lib/Utils/noise-handler.js.map +1 -1
- package/lib/Utils/offline-node-processor.d.ts +2 -9
- package/lib/Utils/offline-node-processor.d.ts.map +1 -1
- package/lib/Utils/offline-node-processor.js.map +1 -1
- package/lib/Utils/pre-key-manager.d.ts +9 -11
- package/lib/Utils/pre-key-manager.d.ts.map +1 -1
- package/lib/Utils/pre-key-manager.js.map +1 -1
- package/lib/Utils/process-message.d.ts +70 -46
- package/lib/Utils/process-message.d.ts.map +1 -1
- package/lib/Utils/process-message.js +119 -0
- package/lib/Utils/process-message.js.map +1 -1
- package/lib/Utils/reporting-utils.d.ts +12 -10
- package/lib/Utils/reporting-utils.d.ts.map +1 -1
- package/lib/Utils/reporting-utils.js.map +1 -1
- package/lib/Utils/rich-message-utils.d.ts +49 -0
- package/lib/Utils/rich-message-utils.d.ts.map +1 -0
- package/lib/Utils/rich-message-utils.js +370 -0
- package/lib/Utils/rich-message-utils.js.map +1 -0
- package/lib/Utils/signal.d.ts +71 -35
- package/lib/Utils/signal.d.ts.map +1 -1
- package/lib/Utils/signal.js.map +1 -1
- package/lib/Utils/stanza-ack.d.ts +8 -2
- package/lib/Utils/stanza-ack.d.ts.map +1 -1
- package/lib/Utils/stanza-ack.js.map +1 -1
- package/lib/Utils/sync-action-utils.d.ts +2 -18
- package/lib/Utils/sync-action-utils.d.ts.map +1 -1
- package/lib/Utils/sync-action-utils.js.map +1 -1
- package/lib/Utils/tc-token-utils.d.ts +23 -30
- package/lib/Utils/tc-token-utils.d.ts.map +1 -1
- package/lib/Utils/tc-token-utils.js.map +1 -1
- package/lib/Utils/use-multi-file-auth-state.d.ts +9 -11
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -1
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -1
- package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-single-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-single-file-auth-state.js +109 -0
- package/lib/Utils/use-single-file-auth-state.js.map +1 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-sqlite-auth-state.js +109 -0
- package/lib/Utils/use-sqlite-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts +42 -9
- package/lib/Utils/validate-connection.d.ts.map +1 -1
- package/lib/Utils/validate-connection.js.map +1 -1
- package/lib/WABinary/constants.d.ts +60 -26
- package/lib/WABinary/constants.d.ts.map +1 -1
- package/lib/WABinary/constants.js +166 -0
- package/lib/WABinary/constants.js.map +1 -1
- package/lib/WABinary/decode.d.ts +8 -5
- package/lib/WABinary/decode.d.ts.map +1 -1
- package/lib/WABinary/decode.js.map +1 -1
- package/lib/WABinary/encode.d.ts +2 -2
- package/lib/WABinary/encode.d.ts.map +1 -1
- package/lib/WABinary/encode.js.map +1 -1
- package/lib/WABinary/generic-utils.d.ts +75 -13
- package/lib/WABinary/generic-utils.d.ts.map +1 -1
- package/lib/WABinary/generic-utils.js +114 -1
- package/lib/WABinary/generic-utils.js.map +1 -1
- package/lib/WABinary/index.d.ts +5 -5
- package/lib/WABinary/index.d.ts.map +1 -1
- package/lib/WABinary/index.js.map +1 -1
- package/lib/WABinary/jid-utils.d.ts +28 -47
- package/lib/WABinary/jid-utils.d.ts.map +1 -1
- package/lib/WABinary/jid-utils.js +1 -1
- package/lib/WABinary/jid-utils.js.map +1 -1
- package/lib/WABinary/types.d.ts +1 -18
- package/lib/WABinary/types.d.ts.map +1 -1
- package/lib/WABinary/types.js.map +1 -1
- package/lib/WAM/BinaryInfo.d.ts +4 -5
- package/lib/WAM/BinaryInfo.d.ts.map +1 -1
- package/lib/WAM/BinaryInfo.js.map +1 -1
- package/lib/WAM/constants.d.ts +34916 -29
- package/lib/WAM/constants.d.ts.map +1 -1
- package/lib/WAM/constants.js.map +1 -1
- package/lib/WAM/encode.d.ts +1 -2
- package/lib/WAM/encode.d.ts.map +1 -1
- package/lib/WAM/encode.js.map +1 -1
- package/lib/WAM/index.d.ts +3 -3
- package/lib/WAM/index.d.ts.map +1 -1
- package/lib/WAM/index.js.map +1 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +34 -7
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +3 -7
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +20 -20
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +9 -9
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +9 -9
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -1
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +7 -7
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +3 -2
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +36 -23
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +2 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +12 -7
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +2 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -1
- package/lib/WAUSync/Protocols/index.d.ts +5 -5
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/index.js +1 -7
- package/lib/WAUSync/Protocols/index.js.map +1 -1
- package/lib/WAUSync/USyncQuery.d.ts +10 -19
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -1
- package/lib/WAUSync/USyncQuery.js +23 -126
- package/lib/WAUSync/USyncQuery.js.map +1 -1
- package/lib/WAUSync/USyncUser.d.ts +15 -15
- package/lib/WAUSync/USyncUser.d.ts.map +1 -1
- package/lib/WAUSync/USyncUser.js +1 -24
- package/lib/WAUSync/USyncUser.js.map +1 -1
- package/lib/WAUSync/index.d.ts +3 -3
- package/lib/WAUSync/index.d.ts.map +1 -1
- package/lib/WAUSync/index.js +2 -1
- package/lib/WAUSync/index.js.map +1 -1
- package/lib/index.d.ts +9 -9
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/package.json +11 -3
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/V +0 -1
- package/WAProto/WAProto.proto +0 -8423
- package/WAProto/fix-imports.js +0 -85
- package/lib/Socket/aigroups.js +0 -315
- package/lib/Socket/ban-checker.js +0 -153
- package/lib/Socket/chats.js[old] +0 -1227
- package/lib/Socket/graphql.js +0 -899
- package/lib/Socket/groups.js[old] +0 -347
- package/lib/Socket/interactive-handler.js +0 -600
- package/lib/Socket/interop.js +0 -563
- package/lib/Socket/managed-account.js +0 -208
- package/lib/Socket/package.json +0 -1
- package/lib/Socket/privacy.js +0 -446
- package/lib/Socket/registration.js +0 -428
- package/lib/Socket/username.js +0 -229
- package/lib/Utils/package.json +0 -1
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +0 -96
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +0 -70
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +0 -28
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +0 -25
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +0 -34
- package/lib/package.json +0 -1
package/lib/Utils/messages.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { Boom } from '@hapi/boom';
|
|
2
2
|
import { randomBytes } from 'crypto';
|
|
3
|
+
import { zip } from 'fflate';
|
|
3
4
|
import { promises as fs } from 'fs';
|
|
4
|
-
import {} from 'stream';
|
|
5
5
|
import { proto } from '../../WAProto/index.js';
|
|
6
|
-
import { CALL_AUDIO_PREFIX, CALL_VIDEO_PREFIX, MEDIA_KEYS, URL_REGEX, WA_DEFAULT_EPHEMERAL } from '../Defaults/index.js';
|
|
7
|
-
import { WAMessageStatus, WAProto } from '../Types/index.js';
|
|
8
|
-
import { isJidGroup, isJidNewsletter, isJidStatusBroadcast, jidNormalizedUser } from '../WABinary/index.js';
|
|
6
|
+
import { CALL_AUDIO_PREFIX, CALL_VIDEO_PREFIX, DONATE_URL, LIBRARY_NAME, MEDIA_KEYS, URL_REGEX, WA_DEFAULT_EPHEMERAL } from '../Defaults/index.js';
|
|
7
|
+
import { AssociationType, ButtonHeaderType, ButtonType, CarouselCardType, ListType, ProtocolType, WAMessageStatus, WAProto } from '../Types/index.js';
|
|
8
|
+
import { isLidUser, isPnUser, isJidGroup, isJidNewsletter, isJidStatusBroadcast, jidNormalizedUser } from '../WABinary/index.js';
|
|
9
9
|
import { sha256 } from './crypto.js';
|
|
10
10
|
import { generateMessageIDV2, getKeyAuthor, unixTimestampSeconds } from './generics.js';
|
|
11
|
-
import { downloadContentFromMessage, encryptedStream, generateThumbnail, getAudioDuration, getAudioWaveform, getRawMediaUploadData } from './messages-media.js';
|
|
11
|
+
import { downloadContentFromMessage, encryptedStream, generateThumbnail, getAudioDuration, getAudioWaveform, getImageProcessingLibrary, getRawMediaUploadData, getStream, toBuffer } from './messages-media.js';
|
|
12
|
+
import { prepareRichResponseMessage } from './rich-message-utils.js';
|
|
12
13
|
import { shouldIncludeReportingToken } from './reporting-utils.js';
|
|
14
|
+
const CONCURRENCY_LIMIT = 15;
|
|
13
15
|
const MIMETYPE_MAP = {
|
|
14
16
|
image: 'image/jpeg',
|
|
15
17
|
video: 'video/mp4',
|
|
@@ -101,10 +103,11 @@ export const prepareWAMessageMedia = async (message, options) => {
|
|
|
101
103
|
logger?.info({ key: cacheableKey }, 'Preparing raw media for newsletter');
|
|
102
104
|
const { filePath, fileSha256, fileLength } = await getRawMediaUploadData(uploadData.media, options.mediaTypeOverride || mediaType, logger);
|
|
103
105
|
const fileSha256B64 = fileSha256.toString('base64');
|
|
104
|
-
const { mediaUrl, directPath } = await options.upload(filePath, {
|
|
106
|
+
const { mediaUrl, directPath, thumbnailDirectPath, thumbnailSha256 } = await options.upload(filePath, {
|
|
105
107
|
fileEncSha256B64: fileSha256B64,
|
|
106
108
|
mediaType: mediaType,
|
|
107
|
-
timeoutMs: options.mediaUploadTimeoutMs
|
|
109
|
+
timeoutMs: options.mediaUploadTimeoutMs,
|
|
110
|
+
newsletter: isNewsletter
|
|
108
111
|
});
|
|
109
112
|
await fs.unlink(filePath);
|
|
110
113
|
const obj = WAProto.Message.fromObject({
|
|
@@ -114,6 +117,8 @@ export const prepareWAMessageMedia = async (message, options) => {
|
|
|
114
117
|
directPath,
|
|
115
118
|
fileSha256,
|
|
116
119
|
fileLength,
|
|
120
|
+
thumbnailDirectPath,
|
|
121
|
+
thumbnailSha256,
|
|
117
122
|
...uploadData,
|
|
118
123
|
media: undefined
|
|
119
124
|
})
|
|
@@ -216,6 +221,309 @@ export const prepareWAMessageMedia = async (message, options) => {
|
|
|
216
221
|
}
|
|
217
222
|
return obj;
|
|
218
223
|
};
|
|
224
|
+
// Lia@Changes 31-01-26 --- Extract product message into a standalone function so it can also be reused as the header for interactive messages
|
|
225
|
+
const prepareProductMessage = async (message, options) => {
|
|
226
|
+
if (!message.businessOwnerJid) {
|
|
227
|
+
throw new Boom('"businessOwnerJid" is missing from the content', { statusCode: 400 });
|
|
228
|
+
}
|
|
229
|
+
const { imageMessage } = await prepareWAMessageMedia({ image: message.image || message.product.productImage }, options);
|
|
230
|
+
// Lia@Changes 01-02-26 --- Add product message default value
|
|
231
|
+
const { image, ...content } = message;
|
|
232
|
+
content.product = {
|
|
233
|
+
currencyCode: 'IDR',
|
|
234
|
+
priceAmount1000: 1000,
|
|
235
|
+
title: LIBRARY_NAME,
|
|
236
|
+
...message.product,
|
|
237
|
+
productImage: imageMessage
|
|
238
|
+
};
|
|
239
|
+
return content;
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* Lia@Note 30-01-26
|
|
243
|
+
* ---
|
|
244
|
+
* Credits: Work on ensuring stickerPackMessage fields are valid by @jlucaso1 (https://github.com/jlucaso1).
|
|
245
|
+
* based on https://github.com/WhiskeySockets/Baileys/pull/1561
|
|
246
|
+
*/
|
|
247
|
+
// Lia@Changes 21-04-26 --- Enhanced prepareStickerPackMessage
|
|
248
|
+
const prepareStickerPackMessage = async (message, options) => {
|
|
249
|
+
const { cover, stickers = [], name = '📦 Sticker Pack', publisher = 'GitHub: itsliaaa', description = '🏷️ itsliaaa/baileys' } = message;
|
|
250
|
+
if (stickers.length > 60) {
|
|
251
|
+
throw new Boom('Sticker pack exceeds the maximum limit of 60 stickers', { statusCode: 400 });
|
|
252
|
+
}
|
|
253
|
+
if (stickers.length === 0) {
|
|
254
|
+
throw new Boom('Sticker pack must contain at least one sticker', { statusCode: 400 });
|
|
255
|
+
}
|
|
256
|
+
if (!cover) {
|
|
257
|
+
throw new Boom('Sticker pack must contain a cover', { statusCode: 400 });
|
|
258
|
+
}
|
|
259
|
+
const logger = options.logger;
|
|
260
|
+
// Lia@Changes 01-02-26 --- Add caching for sticker pack
|
|
261
|
+
let cacheableKey = false;
|
|
262
|
+
if (Array.isArray(stickers) && stickers.length && options.mediaCache) {
|
|
263
|
+
const urls = [];
|
|
264
|
+
for (let i = 0; i < stickers.length; i++) {
|
|
265
|
+
const data = stickers[i].data;
|
|
266
|
+
if (typeof data === 'object' && data?.url) {
|
|
267
|
+
urls.push(data.url);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (urls.length > 0) {
|
|
271
|
+
cacheableKey = 'sticker:' + urls.join('@');
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (cacheableKey) {
|
|
275
|
+
const mediaBuff = await options.mediaCache.get(cacheableKey);
|
|
276
|
+
if (mediaBuff) {
|
|
277
|
+
logger?.debug({ cacheableKey }, 'got media cache hit');
|
|
278
|
+
return proto.Message.StickerPackMessage.decode(mediaBuff);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
const lib = await getImageProcessingLibrary();
|
|
282
|
+
const hasSharp = 'sharp' in lib && !!lib.sharp?.default;
|
|
283
|
+
const hasImage = 'image' in lib && !!lib.image?.Transformer;
|
|
284
|
+
const hasJimp = 'jimp' in lib && !!lib.jimp?.Jimp;
|
|
285
|
+
if (!hasSharp && !hasImage) {
|
|
286
|
+
throw new Boom('No image processing library (sharp or @napi-rs/image) available for converting sticker to WebP.');
|
|
287
|
+
}
|
|
288
|
+
const stickerPackIdValue = generateMessageIDV2();
|
|
289
|
+
const stickerData = {};
|
|
290
|
+
const stickerMetadata = new Array(stickers.length);
|
|
291
|
+
for (let i = 0; i < stickers.length; i += CONCURRENCY_LIMIT) {
|
|
292
|
+
const promises = [];
|
|
293
|
+
const chunkEnd = Math.min(i + CONCURRENCY_LIMIT, stickers.length);
|
|
294
|
+
for (let j = i; j < chunkEnd; j++) {
|
|
295
|
+
promises.push((async (index) => {
|
|
296
|
+
const sticker = stickers[index];
|
|
297
|
+
const { stream } = await getStream(sticker.data);
|
|
298
|
+
const buffer = await toBuffer(stream);
|
|
299
|
+
let webpBuffer;
|
|
300
|
+
let isAnimated = false;
|
|
301
|
+
if (isWebPBuffer(buffer)) {
|
|
302
|
+
webpBuffer = buffer;
|
|
303
|
+
isAnimated = isAnimatedWebP(buffer);
|
|
304
|
+
}
|
|
305
|
+
else if (hasSharp) {
|
|
306
|
+
webpBuffer = await lib.sharp.default(buffer)
|
|
307
|
+
.resize(512, 512, { fit: 'inside' })
|
|
308
|
+
.webp({ quality: 80 })
|
|
309
|
+
.toBuffer();
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
webpBuffer = await new lib.image.Transformer(buffer)
|
|
313
|
+
.resize(512, 512)
|
|
314
|
+
.webp(80);
|
|
315
|
+
}
|
|
316
|
+
if (webpBuffer.length > 1024 * 1024) {
|
|
317
|
+
throw new Boom(`Sticker at index ${index} exceeds the 1MB size limit`, { statusCode: 400 });
|
|
318
|
+
}
|
|
319
|
+
const hash = sha256(webpBuffer).toString('base64').replace(/\//g, '-');
|
|
320
|
+
const fileName = `${hash}.webp`;
|
|
321
|
+
stickerData[fileName] = [new Uint8Array(webpBuffer), { level: 0 }];
|
|
322
|
+
stickerMetadata[index] = {
|
|
323
|
+
fileName,
|
|
324
|
+
mimetype: 'image/webp',
|
|
325
|
+
isAnimated,
|
|
326
|
+
emojis: sticker.emojis || ['✨'],
|
|
327
|
+
accessibilityLabel: sticker.accessibilityLabel || ''
|
|
328
|
+
};
|
|
329
|
+
})(j));
|
|
330
|
+
}
|
|
331
|
+
await Promise.all(promises);
|
|
332
|
+
}
|
|
333
|
+
const trayIconFileName = `${stickerPackIdValue}.webp`;
|
|
334
|
+
const { stream: coverStream } = await getStream(cover);
|
|
335
|
+
const coverBuffer = await toBuffer(coverStream);
|
|
336
|
+
let coverWebpBuffer;
|
|
337
|
+
if (isWebPBuffer(coverBuffer)) {
|
|
338
|
+
coverWebpBuffer = coverBuffer;
|
|
339
|
+
}
|
|
340
|
+
else if (hasSharp) {
|
|
341
|
+
coverWebpBuffer = await lib.sharp.default(coverBuffer)
|
|
342
|
+
.resize(512, 512, { fit: 'inside' })
|
|
343
|
+
.webp({ quality: 80 })
|
|
344
|
+
.toBuffer();
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
coverWebpBuffer = await new lib.image.Transformer(coverBuffer)
|
|
348
|
+
.resize(512, 512)
|
|
349
|
+
.webp(80);
|
|
350
|
+
}
|
|
351
|
+
stickerData[trayIconFileName] = [new Uint8Array(coverWebpBuffer), { level: 0 }];
|
|
352
|
+
const zipBuffer = await new Promise((resolve, reject) => {
|
|
353
|
+
zip(stickerData, (error, data) => error ? reject(error) : resolve(Buffer.from(data)));
|
|
354
|
+
});
|
|
355
|
+
const stickerPackUpload = await encryptedStream(zipBuffer, 'sticker-pack', {
|
|
356
|
+
logger,
|
|
357
|
+
opts: options.options
|
|
358
|
+
});
|
|
359
|
+
let stickerPackUploadResult;
|
|
360
|
+
try {
|
|
361
|
+
stickerPackUploadResult = await options.upload(stickerPackUpload.encFilePath, {
|
|
362
|
+
fileEncSha256B64: stickerPackUpload.fileEncSha256.toString('base64'),
|
|
363
|
+
mediaType: 'sticker-pack',
|
|
364
|
+
timeoutMs: options.mediaUploadTimeoutMs
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
finally {
|
|
368
|
+
fs.unlink(stickerPackUpload.encFilePath).catch(() => logger?.warn('failed to remove tmp file'));
|
|
369
|
+
}
|
|
370
|
+
const obj = {
|
|
371
|
+
name,
|
|
372
|
+
publisher,
|
|
373
|
+
stickerPackId: stickerPackIdValue,
|
|
374
|
+
packDescription: description,
|
|
375
|
+
stickerPackOrigin: proto.Message.StickerPackMessage.StickerPackOrigin.USER_CREATED,
|
|
376
|
+
stickerPackSize: zipBuffer.length,
|
|
377
|
+
stickers: stickerMetadata,
|
|
378
|
+
fileSha256: stickerPackUpload.fileSha256,
|
|
379
|
+
fileEncSha256: stickerPackUpload.fileEncSha256,
|
|
380
|
+
mediaKey: stickerPackUpload.mediaKey,
|
|
381
|
+
directPath: stickerPackUploadResult.directPath,
|
|
382
|
+
fileLength: stickerPackUpload.fileLength,
|
|
383
|
+
mediaKeyTimestamp: unixTimestampSeconds(),
|
|
384
|
+
trayIconFileName
|
|
385
|
+
};
|
|
386
|
+
try {
|
|
387
|
+
let thumbnailBuffer;
|
|
388
|
+
if (hasSharp) {
|
|
389
|
+
thumbnailBuffer = await lib.sharp.default(coverBuffer).resize(252, 252).jpeg().toBuffer();
|
|
390
|
+
}
|
|
391
|
+
else if (hasImage) {
|
|
392
|
+
thumbnailBuffer = await new lib.image.Transformer(coverBuffer).resize(252, 252).jpeg();
|
|
393
|
+
}
|
|
394
|
+
else if (hasJimp) {
|
|
395
|
+
const jimpImage = await lib.jimp.Jimp.read(coverBuffer);
|
|
396
|
+
thumbnailBuffer = await jimpImage.resize({ w: 252, h: 252 }).getBuffer('image/jpeg');
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
throw new Error('No image processing library available for thumbnail generation');
|
|
400
|
+
}
|
|
401
|
+
if (!thumbnailBuffer || thumbnailBuffer.length === 0) {
|
|
402
|
+
throw new Error('Failed to generate thumbnail buffer');
|
|
403
|
+
}
|
|
404
|
+
const thumbUpload = await encryptedStream(thumbnailBuffer, 'thumbnail-sticker-pack', {
|
|
405
|
+
logger,
|
|
406
|
+
opts: options.options,
|
|
407
|
+
mediaKey: stickerPackUpload.mediaKey
|
|
408
|
+
});
|
|
409
|
+
let thumbUploadResult;
|
|
410
|
+
try {
|
|
411
|
+
thumbUploadResult = await options.upload(thumbUpload.encFilePath, {
|
|
412
|
+
fileEncSha256B64: thumbUpload.fileEncSha256.toString('base64'),
|
|
413
|
+
mediaType: 'thumbnail-sticker-pack',
|
|
414
|
+
timeoutMs: options.mediaUploadTimeoutMs
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
finally {
|
|
418
|
+
fs.unlink(thumbUpload.encFilePath).catch(() => logger?.warn('failed to remove tmp file'));
|
|
419
|
+
}
|
|
420
|
+
Object.assign(obj, {
|
|
421
|
+
thumbnailDirectPath: thumbUploadResult.directPath,
|
|
422
|
+
thumbnailSha256: thumbUpload.fileSha256,
|
|
423
|
+
thumbnailEncSha256: thumbUpload.fileEncSha256,
|
|
424
|
+
thumbnailHeight: 252,
|
|
425
|
+
thumbnailWidth: 252,
|
|
426
|
+
imageDataHash: sha256(thumbnailBuffer).toString('base64')
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
catch (error) {
|
|
430
|
+
logger?.warn(`Thumbnail generation failed: ${error}`);
|
|
431
|
+
}
|
|
432
|
+
if (cacheableKey) {
|
|
433
|
+
logger?.debug({ cacheableKey }, 'set cache (background)');
|
|
434
|
+
options.mediaCache.set(cacheableKey, WAProto.Message.StickerPackMessage.encode(obj).finish());
|
|
435
|
+
}
|
|
436
|
+
return WAProto.Message.StickerPackMessage.fromObject(obj);
|
|
437
|
+
};
|
|
438
|
+
// Lia@Changes 30-01-26 --- Add native flow button helper for interactive message
|
|
439
|
+
const prepareNativeFlowButtons = (message) => {
|
|
440
|
+
const buttons = message.nativeFlow;
|
|
441
|
+
const isButtonsFieldArray = Array.isArray(buttons);
|
|
442
|
+
const correctedField = isButtonsFieldArray ? buttons : buttons.buttons;
|
|
443
|
+
const messageParamsJson = {};
|
|
444
|
+
// Lia@Changes 31-01-26 --- Add offer and options inside interactive message
|
|
445
|
+
if (hasOptionalProperty(message, 'offerText') && !!message.offerText) {
|
|
446
|
+
Object.assign(messageParamsJson, {
|
|
447
|
+
limited_time_offer: {
|
|
448
|
+
text: message.offerText || LIBRARY_NAME,
|
|
449
|
+
url: message.offerUrl || DONATE_URL, // Lia@Note 02-02-26 --- Apologies if this feels cheeky, just a fallback
|
|
450
|
+
copy_code: message.offerCode,
|
|
451
|
+
expiration_time: message.offerExpiration
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
if (hasOptionalProperty(message, 'optionText') && !!message.optionText) {
|
|
456
|
+
Object.assign(messageParamsJson, {
|
|
457
|
+
bottom_sheet: {
|
|
458
|
+
in_thread_buttons_limit: 1,
|
|
459
|
+
divider_indices: Array.from({ length: correctedField.length }, (_, index) => index),
|
|
460
|
+
list_title: message.optionTitle || '📄 Select Options',
|
|
461
|
+
button_title: message.optionText
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
return {
|
|
466
|
+
buttons: correctedField.map(button => {
|
|
467
|
+
const buttonText = button.text || button.buttonText;
|
|
468
|
+
const buttonIcon = button.icon?.toUpperCase();
|
|
469
|
+
if (hasOptionalProperty(button, 'id') && !!button.id) {
|
|
470
|
+
return {
|
|
471
|
+
name: 'quick_reply',
|
|
472
|
+
buttonParamsJson: JSON.stringify({
|
|
473
|
+
display_text: buttonText || '👉🏻 Click',
|
|
474
|
+
id: button.id,
|
|
475
|
+
icon: buttonIcon
|
|
476
|
+
})
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
else if (hasOptionalProperty(button, 'copy') && !!button.copy) {
|
|
480
|
+
return {
|
|
481
|
+
name: 'cta_copy',
|
|
482
|
+
buttonParamsJson: JSON.stringify({
|
|
483
|
+
display_text: buttonText || '📋 Copy',
|
|
484
|
+
copy_code: button.copy,
|
|
485
|
+
icon: buttonIcon
|
|
486
|
+
})
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
else if (hasOptionalProperty(button, 'url') && !!button.url) {
|
|
490
|
+
return {
|
|
491
|
+
name: 'cta_url',
|
|
492
|
+
buttonParamsJson: JSON.stringify({
|
|
493
|
+
display_text: buttonText || '🌐 Visit',
|
|
494
|
+
url: button.url,
|
|
495
|
+
merchant_url: button.url,
|
|
496
|
+
webview_interaction: button.useWebview,
|
|
497
|
+
icon: buttonIcon
|
|
498
|
+
})
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
else if (hasOptionalProperty(button, 'call') && !!button.call) {
|
|
502
|
+
return {
|
|
503
|
+
name: 'cta_call',
|
|
504
|
+
buttonParamsJson: JSON.stringify({
|
|
505
|
+
display_text: buttonText || '📞 Call',
|
|
506
|
+
phone_number: button.call,
|
|
507
|
+
icon: buttonIcon
|
|
508
|
+
})
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
// Lia@Changes 12-03-26 --- Add "single_select" shortcut \(°o°)/
|
|
512
|
+
else if (hasOptionalProperty(button, 'sections') && !!button.sections) {
|
|
513
|
+
return {
|
|
514
|
+
name: 'single_select',
|
|
515
|
+
buttonParamsJson: JSON.stringify({
|
|
516
|
+
title: buttonText || '📋 Select',
|
|
517
|
+
sections: button.sections,
|
|
518
|
+
icon: buttonIcon
|
|
519
|
+
})
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
return button;
|
|
523
|
+
}),
|
|
524
|
+
messageParamsJson: JSON.stringify(messageParamsJson)
|
|
525
|
+
};
|
|
526
|
+
};
|
|
219
527
|
export const prepareDisappearingMessageSettingContent = (ephemeralExpiration) => {
|
|
220
528
|
ephemeralExpiration = ephemeralExpiration || 0;
|
|
221
529
|
const content = {
|
|
@@ -261,19 +569,51 @@ export const generateForwardMessageContent = (message, forceForward) => {
|
|
|
261
569
|
return content;
|
|
262
570
|
};
|
|
263
571
|
export const hasNonNullishProperty = (message, key) => {
|
|
264
|
-
return
|
|
265
|
-
message
|
|
572
|
+
return message != null &&
|
|
573
|
+
typeof message === 'object' &&
|
|
266
574
|
key in message &&
|
|
267
|
-
message[key]
|
|
268
|
-
|
|
575
|
+
message[key] != null;
|
|
576
|
+
};
|
|
577
|
+
export const hasOptionalProperty = (obj, key) => {
|
|
578
|
+
return obj != null &&
|
|
579
|
+
typeof obj === 'object' &&
|
|
580
|
+
key in obj &&
|
|
581
|
+
obj[key] != null;
|
|
582
|
+
};
|
|
583
|
+
// Lia@Changes 06-02-26 --- Validate album message media to avoid bug 👀
|
|
584
|
+
export const hasValidAlbumMedia = (message) => {
|
|
585
|
+
return !!(message.imageMessage ||
|
|
586
|
+
message.videoMessage);
|
|
587
|
+
};
|
|
588
|
+
export const hasValidInteractiveHeader = (message) => {
|
|
589
|
+
return !!(message.imageMessage ||
|
|
590
|
+
message.videoMessage ||
|
|
591
|
+
message.documentMessage ||
|
|
592
|
+
message.productMessage ||
|
|
593
|
+
message.locationMessage);
|
|
594
|
+
};
|
|
595
|
+
// Lia@Changes 30-01-26 --- Validate carousel cards header to avoid bug 👀
|
|
596
|
+
export const hasValidCarouselHeader = (message) => {
|
|
597
|
+
return !!(message.imageMessage ||
|
|
598
|
+
message.videoMessage ||
|
|
599
|
+
message.productMessage);
|
|
269
600
|
};
|
|
270
|
-
function hasOptionalProperty(obj, key) {
|
|
271
|
-
return typeof obj === 'object' && obj !== null && key in obj && obj[key] !== null;
|
|
272
|
-
}
|
|
273
601
|
export const generateWAMessageContent = async (message, options) => {
|
|
274
602
|
var _a, _b;
|
|
275
603
|
let m = {};
|
|
276
|
-
|
|
604
|
+
// Lia@Changes 30-01-26 --- Add "raw" boolean to send raw messages directly via generateWAMessage()
|
|
605
|
+
if (hasNonNullishProperty(message, 'raw')) {
|
|
606
|
+
delete message.raw;
|
|
607
|
+
return message;
|
|
608
|
+
}
|
|
609
|
+
// Lia@Changes 09-04-26 --- Add support for code block and table with richResponseMessage
|
|
610
|
+
else if (hasNonNullishProperty(message, 'code') ||
|
|
611
|
+
hasNonNullishProperty(message, 'links') ||
|
|
612
|
+
hasNonNullishProperty(message, 'table') ||
|
|
613
|
+
hasNonNullishProperty(message, 'richResponse')) {
|
|
614
|
+
m = prepareRichResponseMessage(message);
|
|
615
|
+
}
|
|
616
|
+
else if (hasNonNullishProperty(message, 'text')) {
|
|
277
617
|
const extContent = { text: message.text };
|
|
278
618
|
let urlInfo = message.linkPreview;
|
|
279
619
|
if (typeof urlInfo === 'undefined') {
|
|
@@ -284,7 +624,8 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
284
624
|
extContent.jpegThumbnail = urlInfo.jpegThumbnail;
|
|
285
625
|
extContent.description = urlInfo.description;
|
|
286
626
|
extContent.title = urlInfo.title;
|
|
287
|
-
extContent.previewType = 0;
|
|
627
|
+
extContent.previewType = urlInfo.previewType ?? 0;
|
|
628
|
+
extContent.linkPreviewMetadata = urlInfo.linkPreviewMetadata;
|
|
288
629
|
const img = urlInfo.highQualityThumbnail;
|
|
289
630
|
if (img) {
|
|
290
631
|
extContent.thumbnailDirectPath = img.directPath;
|
|
@@ -296,6 +637,21 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
296
637
|
extContent.thumbnailEncSha256 = img.fileEncSha256;
|
|
297
638
|
}
|
|
298
639
|
}
|
|
640
|
+
const faviconData = message.favicon;
|
|
641
|
+
if (faviconData && typeof options.upload === 'function') {
|
|
642
|
+
const { imageMessage } = await prepareWAMessageMedia({
|
|
643
|
+
image: faviconData
|
|
644
|
+
}, options);
|
|
645
|
+
extContent.faviconMMSMetadata = {
|
|
646
|
+
thumbnailDirectPath: imageMessage.directPath,
|
|
647
|
+
mediaKey: imageMessage.mediaKey,
|
|
648
|
+
mediaKeyTimestamp: imageMessage.mediaKeyTimestamp,
|
|
649
|
+
thumbnailWidth: 32,
|
|
650
|
+
thumbnailHeight: 32,
|
|
651
|
+
thumbnailSha256: imageMessage.fileSha256,
|
|
652
|
+
thumbnailEncSha256: imageMessage.fileEncSha256
|
|
653
|
+
};
|
|
654
|
+
}
|
|
299
655
|
if (options.backgroundColor) {
|
|
300
656
|
extContent.backgroundArgb = await assertColor(options.backgroundColor);
|
|
301
657
|
}
|
|
@@ -362,6 +718,9 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
362
718
|
}
|
|
363
719
|
}
|
|
364
720
|
}
|
|
721
|
+
else if (hasNonNullishProperty(message, 'stickers')) {
|
|
722
|
+
m.stickerPackMessage = await prepareStickerPackMessage(message, options);
|
|
723
|
+
}
|
|
365
724
|
else if (hasNonNullishProperty(message, 'pin')) {
|
|
366
725
|
m.pinInChatMessage = {};
|
|
367
726
|
m.messageContextInfo = {};
|
|
@@ -370,6 +729,25 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
370
729
|
m.pinInChatMessage.senderTimestampMs = Date.now();
|
|
371
730
|
m.messageContextInfo.messageAddOnDurationInSecs = message.type === 1 ? message.time || 86400 : 0;
|
|
372
731
|
}
|
|
732
|
+
else if (hasNonNullishProperty(message, 'keep')) {
|
|
733
|
+
m.keepInChatMessage = {};
|
|
734
|
+
m.keepInChatMessage.key = message.keep;
|
|
735
|
+
m.keepInChatMessage.keepType = message.type;
|
|
736
|
+
m.keepInChatMessage.timestampMs = Date.now();
|
|
737
|
+
}
|
|
738
|
+
else if (hasNonNullishProperty(message, 'flowReply')) {
|
|
739
|
+
m.interactiveResponseMessage = {
|
|
740
|
+
body: {
|
|
741
|
+
format: message.flowReply.format || proto.Message.InteractiveResponseMessage.Body.Format.DEFAULT,
|
|
742
|
+
text: message.flowReply.text
|
|
743
|
+
},
|
|
744
|
+
nativeFlowResponseMessage: {
|
|
745
|
+
name: message.flowReply.name,
|
|
746
|
+
paramsJson: message.flowReply.paramsJson || '{}',
|
|
747
|
+
version: message.flowReply.version || 1
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
}
|
|
373
751
|
else if (hasNonNullishProperty(message, 'buttonReply')) {
|
|
374
752
|
switch (message.type) {
|
|
375
753
|
case 'template':
|
|
@@ -388,22 +766,22 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
388
766
|
break;
|
|
389
767
|
}
|
|
390
768
|
}
|
|
769
|
+
else if (hasNonNullishProperty(message, 'listReply')) {
|
|
770
|
+
m.listResponseMessage = {
|
|
771
|
+
description: message.listReply.description,
|
|
772
|
+
listType: proto.Message.ListResponseMessage.ListType.SINGLE_SELECT,
|
|
773
|
+
singleSelectReply: {
|
|
774
|
+
selectedRowId: message.listReply.id
|
|
775
|
+
},
|
|
776
|
+
title: message.listReply.title
|
|
777
|
+
};
|
|
778
|
+
}
|
|
391
779
|
else if (hasOptionalProperty(message, 'ptv') && message.ptv) {
|
|
392
780
|
const { videoMessage } = await prepareWAMessageMedia({ video: message.video }, options);
|
|
393
781
|
m.ptvMessage = videoMessage;
|
|
394
782
|
}
|
|
395
783
|
else if (hasNonNullishProperty(message, 'product')) {
|
|
396
|
-
|
|
397
|
-
m.productMessage = WAProto.Message.ProductMessage.create({
|
|
398
|
-
...message,
|
|
399
|
-
product: {
|
|
400
|
-
...message.product,
|
|
401
|
-
productImage: imageMessage
|
|
402
|
-
}
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
else if (hasNonNullishProperty(message, 'listReply')) {
|
|
406
|
-
m.listResponseMessage = { ...message.listReply };
|
|
784
|
+
m.productMessage = await prepareProductMessage(message, options);
|
|
407
785
|
}
|
|
408
786
|
else if (hasNonNullishProperty(message, 'event')) {
|
|
409
787
|
m.eventMessage = {};
|
|
@@ -436,21 +814,35 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
436
814
|
statusCode: 400
|
|
437
815
|
});
|
|
438
816
|
}
|
|
439
|
-
m.messageContextInfo = {
|
|
440
|
-
// encKey
|
|
441
|
-
messageSecret: message.poll.messageSecret || randomBytes(32)
|
|
442
|
-
};
|
|
443
817
|
const pollCreationMessage = {
|
|
444
818
|
name: message.poll.name,
|
|
445
819
|
selectableOptionsCount: message.poll.selectableCount,
|
|
446
|
-
options: message.poll.values.map(optionName => ({ optionName }))
|
|
820
|
+
options: message.poll.values.map(optionName => ({ optionName })),
|
|
821
|
+
endTime: message.poll.endDate ? message.poll.endDate.getTime() : undefined,
|
|
822
|
+
hideParticipantName: message.poll.hideVoter ?? false,
|
|
823
|
+
allowAddOption: message.poll.canAddOption ?? false
|
|
447
824
|
};
|
|
448
825
|
if (message.poll.toAnnouncementGroup) {
|
|
449
826
|
// poll v2 is for community announcement groups (single select and multiple)
|
|
450
827
|
m.pollCreationMessageV2 = pollCreationMessage;
|
|
451
828
|
}
|
|
452
829
|
else {
|
|
453
|
-
|
|
830
|
+
// Lia@Changes 08-02-26 --- Add quiz message support
|
|
831
|
+
if (message.poll.pollType === 1) {
|
|
832
|
+
if (!message.poll.correctAnswer) {
|
|
833
|
+
throw new Boom('No "correctAnswer" provided for quiz', { statusCode: 400 });
|
|
834
|
+
}
|
|
835
|
+
m.pollCreationMessageV5 = {
|
|
836
|
+
// Lia@Note 08-02-26 --- quiz for newsletter only
|
|
837
|
+
...pollCreationMessage,
|
|
838
|
+
correctAnswer: {
|
|
839
|
+
optionName: message.poll.correctAnswer.toString()
|
|
840
|
+
},
|
|
841
|
+
pollType: 1,
|
|
842
|
+
selectableOptionsCount: 1
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
else if (message.poll.selectableCount === 1) {
|
|
454
846
|
//poll v3 is for single select polls
|
|
455
847
|
m.pollCreationMessageV3 = pollCreationMessage;
|
|
456
848
|
}
|
|
@@ -459,11 +851,93 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
459
851
|
m.pollCreationMessage = pollCreationMessage;
|
|
460
852
|
}
|
|
461
853
|
}
|
|
854
|
+
m.messageContextInfo = {
|
|
855
|
+
// encKey
|
|
856
|
+
messageSecret: message.poll.messageSecret || randomBytes(32)
|
|
857
|
+
};
|
|
858
|
+
}
|
|
859
|
+
// Lia@Changes 08-02-26 --- Add poll result snapshot message
|
|
860
|
+
else if (hasNonNullishProperty(message, 'pollResult')) {
|
|
861
|
+
const pollResultSnapshotMessage = {
|
|
862
|
+
name: message.pollResult.name,
|
|
863
|
+
pollVotes: message.pollResult.votes.map(vote => ({
|
|
864
|
+
optionName: vote.name,
|
|
865
|
+
optionVoteCount: parseInt(vote.voteCount)
|
|
866
|
+
}))
|
|
867
|
+
};
|
|
868
|
+
if (message.pollResult.pollType === 1) {
|
|
869
|
+
pollResultSnapshotMessage.pollType = proto.Message.PollType.QUIZ;
|
|
870
|
+
m.pollResultSnapshotMessageV3 = pollResultSnapshotMessage;
|
|
871
|
+
}
|
|
872
|
+
else {
|
|
873
|
+
pollResultSnapshotMessage.pollType = proto.Message.PollType.POLL;
|
|
874
|
+
m.pollResultSnapshotMessage = pollResultSnapshotMessage;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
// Lia@Changes 08-02-26 --- Add poll update message
|
|
878
|
+
else if (hasNonNullishProperty(message, 'pollUpdate')) {
|
|
879
|
+
if (!message.pollUpdate.key) {
|
|
880
|
+
throw new Boom('Message key is required', { statusCode: 400 });
|
|
881
|
+
}
|
|
882
|
+
if (!message.pollUpdate.vote) {
|
|
883
|
+
throw new Boom('Encrypted vote payload is required', { statusCode: 400 });
|
|
884
|
+
}
|
|
885
|
+
m.pollUpdateMessage = {
|
|
886
|
+
metadata: message.pollUpdate.metadata,
|
|
887
|
+
pollCreationMessageKey: message.pollUpdate.key,
|
|
888
|
+
senderTimestampMs: Date.now(),
|
|
889
|
+
vote: message.pollUpdate.vote
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
// Lia@Changes 01-02-26 --- Add payment invite message
|
|
893
|
+
else if (hasNonNullishProperty(message, 'paymentInviteServiceType')) {
|
|
894
|
+
m.paymentInviteMessage = {
|
|
895
|
+
expiryTimestamp: Date.now(),
|
|
896
|
+
serviceType: message.paymentInviteServiceType
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
// Lia@Changes 01-02-26 --- Add order message
|
|
900
|
+
else if (hasNonNullishProperty(message, 'orderText')) {
|
|
901
|
+
if (!Buffer.isBuffer(message.thumbnail)) {
|
|
902
|
+
throw new Boom('Must provide thumbnail buffer in order message', { statusCode: 400 });
|
|
903
|
+
}
|
|
904
|
+
m.orderMessage = {
|
|
905
|
+
itemCount: 1,
|
|
906
|
+
messageVersion: 1,
|
|
907
|
+
orderTitle: LIBRARY_NAME,
|
|
908
|
+
status: proto.Message.OrderMessage.OrderStatus.INQUIRY,
|
|
909
|
+
surface: proto.Message.OrderMessage.OrderSurface.CATALOG,
|
|
910
|
+
token: generateMessageIDV2(),
|
|
911
|
+
totalAmount1000: 1000,
|
|
912
|
+
totalCurrencyCode: 'IDR',
|
|
913
|
+
...message,
|
|
914
|
+
message: message.orderText
|
|
915
|
+
};
|
|
916
|
+
delete m.orderMessage.orderText;
|
|
462
917
|
}
|
|
918
|
+
// Lia@Changes 31-01-26 --- Add support for album messages
|
|
463
919
|
else if (hasNonNullishProperty(message, 'album')) {
|
|
920
|
+
if (!Array.isArray(message.album)) {
|
|
921
|
+
throw new Boom('Invalid album type. Expected an array.', { statusCode: 400 });
|
|
922
|
+
}
|
|
923
|
+
let videoCount = 0;
|
|
924
|
+
for (let i = 0; i < message.album.length; i++) {
|
|
925
|
+
if (message.album[i].video)
|
|
926
|
+
videoCount++;
|
|
927
|
+
}
|
|
928
|
+
;
|
|
929
|
+
let imageCount = 0;
|
|
930
|
+
for (let i = 0; i < message.album.length; i++) {
|
|
931
|
+
if (message.album[i].image)
|
|
932
|
+
imageCount++;
|
|
933
|
+
}
|
|
934
|
+
;
|
|
935
|
+
if ((videoCount + imageCount) < 2) {
|
|
936
|
+
throw new Boom('Minimum provide 2 media to upload album message', { statusCode: 400 });
|
|
937
|
+
}
|
|
464
938
|
m.albumMessage = {
|
|
465
|
-
expectedImageCount:
|
|
466
|
-
expectedVideoCount:
|
|
939
|
+
expectedImageCount: imageCount,
|
|
940
|
+
expectedVideoCount: videoCount
|
|
467
941
|
};
|
|
468
942
|
}
|
|
469
943
|
else if (hasNonNullishProperty(message, 'sharePhoneNumber')) {
|
|
@@ -488,8 +962,321 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
488
962
|
else {
|
|
489
963
|
m = await prepareWAMessageMedia(message, options);
|
|
490
964
|
}
|
|
491
|
-
|
|
492
|
-
|
|
965
|
+
// Lia@Changes 30-01-26 --- Add interactive messages (buttonsMessage, listMessage, interactiveMessage, templateMessage, and carouselMessage)
|
|
966
|
+
if (hasNonNullishProperty(message, 'buttons')) {
|
|
967
|
+
const buttonsMessage = {
|
|
968
|
+
buttons: message.buttons.map(button => {
|
|
969
|
+
// Lia@Changes 12-03-26 --- Add "single_select" shortcut!
|
|
970
|
+
const buttonText = button.text || button.buttonText;
|
|
971
|
+
if (hasOptionalProperty(button, 'sections')) {
|
|
972
|
+
return {
|
|
973
|
+
nativeFlowInfo: {
|
|
974
|
+
name: 'single_select',
|
|
975
|
+
paramsJson: JSON.stringify({
|
|
976
|
+
title: buttonText,
|
|
977
|
+
sections: button.sections
|
|
978
|
+
})
|
|
979
|
+
},
|
|
980
|
+
type: ButtonType.NATIVE_FLOW
|
|
981
|
+
};
|
|
982
|
+
}
|
|
983
|
+
else if (hasOptionalProperty(button, 'name')) {
|
|
984
|
+
return {
|
|
985
|
+
nativeFlowInfo: {
|
|
986
|
+
name: button.name,
|
|
987
|
+
paramsJson: button.paramsJson
|
|
988
|
+
},
|
|
989
|
+
type: ButtonType.NATIVE_FLOW
|
|
990
|
+
};
|
|
991
|
+
}
|
|
992
|
+
return {
|
|
993
|
+
buttonId: button.id || button.buttonId,
|
|
994
|
+
buttonText: typeof buttonText === 'string' ? { displayText: buttonText } : buttonText,
|
|
995
|
+
type: button.type || ButtonType.RESPONSE
|
|
996
|
+
};
|
|
997
|
+
})
|
|
998
|
+
};
|
|
999
|
+
if (hasOptionalProperty(message, 'text')) {
|
|
1000
|
+
buttonsMessage.contentText = message.text;
|
|
1001
|
+
buttonsMessage.headerType = ButtonHeaderType.EMPTY;
|
|
1002
|
+
}
|
|
1003
|
+
else {
|
|
1004
|
+
if (hasOptionalProperty(message, 'caption')) {
|
|
1005
|
+
buttonsMessage.contentText = message.caption;
|
|
1006
|
+
}
|
|
1007
|
+
const type = Object.keys(m)[0].replace('Message', '').toUpperCase();
|
|
1008
|
+
buttonsMessage.headerType = ButtonHeaderType[type];
|
|
1009
|
+
Object.assign(buttonsMessage, m);
|
|
1010
|
+
}
|
|
1011
|
+
if (hasOptionalProperty(message, 'footer')) {
|
|
1012
|
+
buttonsMessage.footerText = message.footer;
|
|
1013
|
+
}
|
|
1014
|
+
m = { buttonsMessage };
|
|
1015
|
+
}
|
|
1016
|
+
else if (hasNonNullishProperty(message, 'sections')) {
|
|
1017
|
+
const listMessage = {
|
|
1018
|
+
sections: message.sections,
|
|
1019
|
+
buttonText: message.buttonText,
|
|
1020
|
+
title: message.title,
|
|
1021
|
+
footerText: message.footer,
|
|
1022
|
+
description: message.text,
|
|
1023
|
+
listType: ListType.SINGLE_SELECT
|
|
1024
|
+
};
|
|
1025
|
+
m = { listMessage };
|
|
1026
|
+
}
|
|
1027
|
+
// Lia@Note 03-02-26 --- This message type is shown on WhatsApp Web/Desktop and iOS (I guess 。◕‿◕。). On Android, it only appears in newsletter (so far ಥ‿ಥ)
|
|
1028
|
+
else if (hasNonNullishProperty(message, 'templateButtons')) {
|
|
1029
|
+
const hydratedTemplate = {
|
|
1030
|
+
hydratedButtons: message.templateButtons.map((button, i) => {
|
|
1031
|
+
const buttonText = button.text || button.buttonText;
|
|
1032
|
+
if (hasOptionalProperty(button, 'id')) {
|
|
1033
|
+
return {
|
|
1034
|
+
index: i,
|
|
1035
|
+
quickReplyButton: {
|
|
1036
|
+
displayText: buttonText || '👉🏻 Click',
|
|
1037
|
+
id: button.id
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
else if (hasOptionalProperty(button, 'url')) {
|
|
1042
|
+
return {
|
|
1043
|
+
index: i,
|
|
1044
|
+
urlButton: {
|
|
1045
|
+
displayText: buttonText || '🌐 Visit',
|
|
1046
|
+
url: button.url
|
|
1047
|
+
}
|
|
1048
|
+
};
|
|
1049
|
+
}
|
|
1050
|
+
else if (hasOptionalProperty(button, 'call')) {
|
|
1051
|
+
return {
|
|
1052
|
+
index: i,
|
|
1053
|
+
callButton: {
|
|
1054
|
+
displayText: buttonText || '📞 Call',
|
|
1055
|
+
phoneNumber: button.call
|
|
1056
|
+
}
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
button.index = button.index || i;
|
|
1060
|
+
return button;
|
|
1061
|
+
})
|
|
1062
|
+
};
|
|
1063
|
+
if (hasOptionalProperty(message, 'text')) {
|
|
1064
|
+
hydratedTemplate.hydratedContentText = message.text;
|
|
1065
|
+
}
|
|
1066
|
+
else {
|
|
1067
|
+
if (hasOptionalProperty(message, 'caption')) {
|
|
1068
|
+
hydratedTemplate.hydratedTitleText = message.title;
|
|
1069
|
+
hydratedTemplate.hydratedContentText = message.caption;
|
|
1070
|
+
}
|
|
1071
|
+
;
|
|
1072
|
+
Object.assign(hydratedTemplate, m);
|
|
1073
|
+
}
|
|
1074
|
+
if (hasOptionalProperty(message, 'footer')) {
|
|
1075
|
+
hydratedTemplate.hydratedFooterText = message.footer;
|
|
1076
|
+
}
|
|
1077
|
+
hydratedTemplate.templateId = message.id || 'template-' + Date.now(); // Lia@Note 04-02-26 --- Minimal templateId to satisfy WhatsApp ( ꈍᴗꈍ)
|
|
1078
|
+
m = {
|
|
1079
|
+
templateMessage: {
|
|
1080
|
+
hydratedFourRowTemplate: hydratedTemplate,
|
|
1081
|
+
hydratedTemplate: hydratedTemplate
|
|
1082
|
+
}
|
|
1083
|
+
};
|
|
1084
|
+
}
|
|
1085
|
+
else if (hasNonNullishProperty(message, 'nativeFlow')) {
|
|
1086
|
+
const interactiveMessage = {
|
|
1087
|
+
nativeFlowMessage: prepareNativeFlowButtons(message)
|
|
1088
|
+
};
|
|
1089
|
+
if (hasOptionalProperty(message, 'bizJid')) {
|
|
1090
|
+
interactiveMessage.collectionMessage = {
|
|
1091
|
+
bizJid: message.bizJid,
|
|
1092
|
+
id: message.id,
|
|
1093
|
+
messageVersion: 1
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
else if (hasOptionalProperty(message, 'shopSurface')) {
|
|
1097
|
+
interactiveMessage.shopStorefrontMessage = {
|
|
1098
|
+
surface: message.shopSurface,
|
|
1099
|
+
id: message.id,
|
|
1100
|
+
messageVersion: 1
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
if (hasOptionalProperty(message, 'text')) {
|
|
1104
|
+
interactiveMessage.body = { text: message.text };
|
|
1105
|
+
}
|
|
1106
|
+
else {
|
|
1107
|
+
if (hasOptionalProperty(message, 'caption')) {
|
|
1108
|
+
const isValidHeader = hasValidInteractiveHeader(m);
|
|
1109
|
+
if (!isValidHeader) {
|
|
1110
|
+
throw new Boom('Invalid media type for interactive message header', { statusCode: 400 });
|
|
1111
|
+
}
|
|
1112
|
+
interactiveMessage.header = {
|
|
1113
|
+
title: message.title || '',
|
|
1114
|
+
subtitle: message.subtitle || '',
|
|
1115
|
+
hasMediaAttachment: isValidHeader
|
|
1116
|
+
};
|
|
1117
|
+
interactiveMessage.body = { text: message.caption };
|
|
1118
|
+
}
|
|
1119
|
+
if (hasOptionalProperty(message, 'thumbnail') && !!message.thumbnail) {
|
|
1120
|
+
interactiveMessage.jpegThumbnail = message.thumbnail;
|
|
1121
|
+
}
|
|
1122
|
+
Object.assign(interactiveMessage.header, m);
|
|
1123
|
+
}
|
|
1124
|
+
if (hasOptionalProperty(message, 'audioFooter')) {
|
|
1125
|
+
const { audioMessage } = await prepareWAMessageMedia({
|
|
1126
|
+
audio: message.audioFooter
|
|
1127
|
+
}, options);
|
|
1128
|
+
interactiveMessage.footer = {
|
|
1129
|
+
audioMessage,
|
|
1130
|
+
hasMediaAttachment: true
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
else if (hasOptionalProperty(message, 'footer')) {
|
|
1134
|
+
interactiveMessage.footer = { text: message.footer };
|
|
1135
|
+
}
|
|
1136
|
+
m = { interactiveMessage };
|
|
1137
|
+
}
|
|
1138
|
+
else if (hasNonNullishProperty(message, 'cards')) {
|
|
1139
|
+
const interactiveMessage = {
|
|
1140
|
+
carouselMessage: {
|
|
1141
|
+
cards: await Promise.all(message.cards.map(async (card) => {
|
|
1142
|
+
let carouselHeader = {};
|
|
1143
|
+
if (hasNonNullishProperty(card, 'product')) {
|
|
1144
|
+
carouselHeader.productMessage = await prepareProductMessage(card, options);
|
|
1145
|
+
}
|
|
1146
|
+
else {
|
|
1147
|
+
carouselHeader = await prepareWAMessageMedia(card, options).catch(() => ({}));
|
|
1148
|
+
}
|
|
1149
|
+
const isValidHeader = hasValidCarouselHeader(carouselHeader);
|
|
1150
|
+
if (!isValidHeader) {
|
|
1151
|
+
throw new Boom('Invalid media type for carousel card', { statusCode: 400 });
|
|
1152
|
+
}
|
|
1153
|
+
const carouselCard = {
|
|
1154
|
+
nativeFlowMessage: prepareNativeFlowButtons(card.nativeFlow ? card : [])
|
|
1155
|
+
};
|
|
1156
|
+
if (hasOptionalProperty(card, 'text')) {
|
|
1157
|
+
carouselCard.body = { text: card.text };
|
|
1158
|
+
}
|
|
1159
|
+
else {
|
|
1160
|
+
if (hasOptionalProperty(card, 'caption')) {
|
|
1161
|
+
carouselCard.header = {
|
|
1162
|
+
title: card.title || '',
|
|
1163
|
+
subtitle: card.subtitle || '',
|
|
1164
|
+
hasMediaAttachment: isValidHeader
|
|
1165
|
+
};
|
|
1166
|
+
carouselCard.body = { text: card.caption };
|
|
1167
|
+
}
|
|
1168
|
+
if (hasOptionalProperty(card, 'thumbnail') && !!card.thumbnail) {
|
|
1169
|
+
carouselCard.jpegThumbnail = card.thumbnail;
|
|
1170
|
+
}
|
|
1171
|
+
Object.assign(carouselCard.header, carouselHeader);
|
|
1172
|
+
}
|
|
1173
|
+
if (hasOptionalProperty(card, 'audioFooter')) {
|
|
1174
|
+
const { audioMessage } = await prepareWAMessageMedia({
|
|
1175
|
+
audio: card.audioFooter
|
|
1176
|
+
}, options);
|
|
1177
|
+
carouselCard.footer = {
|
|
1178
|
+
audioMessage,
|
|
1179
|
+
hasMediaAttachment: true
|
|
1180
|
+
};
|
|
1181
|
+
}
|
|
1182
|
+
else if (hasOptionalProperty(card, 'footer')) {
|
|
1183
|
+
carouselCard.footer = { text: card.footer };
|
|
1184
|
+
}
|
|
1185
|
+
return carouselCard;
|
|
1186
|
+
})),
|
|
1187
|
+
carouselCardType: CarouselCardType.UNKNOWN,
|
|
1188
|
+
messageVersion: 1
|
|
1189
|
+
}
|
|
1190
|
+
};
|
|
1191
|
+
if (hasOptionalProperty(message, 'text')) {
|
|
1192
|
+
interactiveMessage.body = { text: message.text };
|
|
1193
|
+
}
|
|
1194
|
+
if (hasOptionalProperty(message, 'footer')) {
|
|
1195
|
+
interactiveMessage.footer = { text: message.footer };
|
|
1196
|
+
}
|
|
1197
|
+
m = { interactiveMessage };
|
|
1198
|
+
}
|
|
1199
|
+
// Lia@Changes 01-02-26 --- Add request payment message
|
|
1200
|
+
else if (hasNonNullishProperty(message, 'requestPaymentFrom')) {
|
|
1201
|
+
const requestPaymentMessage = {
|
|
1202
|
+
amount: {
|
|
1203
|
+
currencyCode: 'IDR',
|
|
1204
|
+
offset: 1000,
|
|
1205
|
+
value: 1000
|
|
1206
|
+
},
|
|
1207
|
+
amount1000: 1000,
|
|
1208
|
+
currencyCodeIso4217: 'IDR',
|
|
1209
|
+
expiryTimestamp: Date.now(),
|
|
1210
|
+
noteMessage: m,
|
|
1211
|
+
requestFrom: message.requestPaymentFrom,
|
|
1212
|
+
...message
|
|
1213
|
+
};
|
|
1214
|
+
delete requestPaymentMessage.requestPaymentFrom;
|
|
1215
|
+
if (hasNonNullishProperty(m, 'extendedTextMessage') || hasNonNullishProperty(m, 'stickerMessage')) {
|
|
1216
|
+
Object.assign(requestPaymentMessage.noteMessage, m);
|
|
1217
|
+
}
|
|
1218
|
+
else {
|
|
1219
|
+
throw new Boom('Invalid message type for request payment note message', { statusCode: 400 });
|
|
1220
|
+
}
|
|
1221
|
+
m = { requestPaymentMessage };
|
|
1222
|
+
}
|
|
1223
|
+
// Lia@Changes 01-02-26 --- Add invoice message
|
|
1224
|
+
else if (hasNonNullishProperty(message, 'invoiceNote')) {
|
|
1225
|
+
const attachment = m.imageMessage || m.documentMessage;
|
|
1226
|
+
const type = Object.keys(m)[0].replace('Message', '').toUpperCase();
|
|
1227
|
+
const invoiceMessage = {
|
|
1228
|
+
attachmentType: proto.Message.InvoiceMessage.AttachmentType[type === 'DOCUMENT' ? 'PDF' : 'IMAGE'],
|
|
1229
|
+
note: message.invoiceNote
|
|
1230
|
+
};
|
|
1231
|
+
if (attachment) {
|
|
1232
|
+
const { directPath, fileEncSha256, fileSha256, jpegThumbnail = undefined, mediaKey, mediaKeyTimestamp, mimetype } = attachment;
|
|
1233
|
+
Object.assign(invoiceMessage, {
|
|
1234
|
+
attachmentDirectPath: directPath,
|
|
1235
|
+
attachmentFileEncSha256: fileEncSha256,
|
|
1236
|
+
attachmentFileSha256: fileSha256,
|
|
1237
|
+
attachmentJpegThumbnail: jpegThumbnail,
|
|
1238
|
+
attachmentMediaKey: mediaKey,
|
|
1239
|
+
attachmentMediaKeyTimestamp: mediaKeyTimestamp,
|
|
1240
|
+
attachmentMimetype: mimetype,
|
|
1241
|
+
token: generateMessageIDV2()
|
|
1242
|
+
});
|
|
1243
|
+
}
|
|
1244
|
+
else {
|
|
1245
|
+
throw new Boom('Invalid media type for invoice message', { statusCode: 400 });
|
|
1246
|
+
}
|
|
1247
|
+
m = { invoiceMessage };
|
|
1248
|
+
}
|
|
1249
|
+
// Lia@Changes 31-01-26 --- Add direct externalAdReply access (no need to create contextInfo first)
|
|
1250
|
+
if (hasOptionalProperty(message, 'externalAdReply') && !!message.externalAdReply) {
|
|
1251
|
+
const messageType = Object.keys(m)[0];
|
|
1252
|
+
const key = m[messageType];
|
|
1253
|
+
const content = message.externalAdReply;
|
|
1254
|
+
if ('thumbnail' in content && !Buffer.isBuffer(content.thumbnail)) {
|
|
1255
|
+
throw new Boom('Thumbnail must in buffer type', { statusCode: 400 });
|
|
1256
|
+
}
|
|
1257
|
+
if (!content.url || typeof content.url !== 'string') {
|
|
1258
|
+
content.url = DONATE_URL; // Lia@Note 02-02-26 --- Apologies if this feels cheeky, just a fallback
|
|
1259
|
+
}
|
|
1260
|
+
const externalAdReply = {
|
|
1261
|
+
...content,
|
|
1262
|
+
body: content.body,
|
|
1263
|
+
mediaType: content.mediaType || 1,
|
|
1264
|
+
mediaUrl: content.url,
|
|
1265
|
+
renderLargerThumbnail: content.largeThumbnail,
|
|
1266
|
+
sourceUrl: content.url,
|
|
1267
|
+
thumbnail: content.thumbnail,
|
|
1268
|
+
thumbnailUrl: content.url + '?update=' + Date.now(),
|
|
1269
|
+
title: content.title || LIBRARY_NAME
|
|
1270
|
+
};
|
|
1271
|
+
delete externalAdReply.subTitle;
|
|
1272
|
+
delete externalAdReply.largeThumbnail;
|
|
1273
|
+
delete externalAdReply.url;
|
|
1274
|
+
if ('contextInfo' in key && !!key.contextInfo) {
|
|
1275
|
+
key.contextInfo.externalAdReply = { ...key.contextInfo.externalAdReply, ...externalAdReply };
|
|
1276
|
+
}
|
|
1277
|
+
else if (key) {
|
|
1278
|
+
key.contextInfo = { externalAdReply };
|
|
1279
|
+
}
|
|
493
1280
|
}
|
|
494
1281
|
if ((hasOptionalProperty(message, 'mentions') && message.mentions?.length) ||
|
|
495
1282
|
(hasOptionalProperty(message, 'mentionAll') && message.mentionAll)) {
|
|
@@ -511,16 +1298,6 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
511
1298
|
};
|
|
512
1299
|
}
|
|
513
1300
|
}
|
|
514
|
-
if (hasOptionalProperty(message, 'edit')) {
|
|
515
|
-
m = {
|
|
516
|
-
protocolMessage: {
|
|
517
|
-
key: message.edit,
|
|
518
|
-
editedMessage: m,
|
|
519
|
-
timestampMs: Date.now(),
|
|
520
|
-
type: WAProto.Message.ProtocolMessage.Type.MESSAGE_EDIT
|
|
521
|
-
}
|
|
522
|
-
};
|
|
523
|
-
}
|
|
524
1301
|
if (hasOptionalProperty(message, 'contextInfo') && !!message.contextInfo) {
|
|
525
1302
|
const messageType = Object.keys(m)[0];
|
|
526
1303
|
const key = m[messageType];
|
|
@@ -531,12 +1308,78 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
531
1308
|
key.contextInfo = message.contextInfo;
|
|
532
1309
|
}
|
|
533
1310
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
1311
|
+
// Lia@Changes 31-01-26 --- Add "groupStatus" boolean to set contextInfo.isGroupStatus and wrap message into groupStatusMessageV2
|
|
1312
|
+
if (hasOptionalProperty(message, 'groupStatus') && !!message.groupStatus) {
|
|
1313
|
+
const messageType = Object.keys(m)[0];
|
|
1314
|
+
const key = m[messageType];
|
|
1315
|
+
if ('contextInfo' in key && !!key.contextInfo) {
|
|
1316
|
+
key.contextInfo.isGroupStatus = message.groupStatus;
|
|
1317
|
+
}
|
|
1318
|
+
else if (key) {
|
|
1319
|
+
key.contextInfo = {
|
|
1320
|
+
isGroupStatus: message.groupStatus
|
|
1321
|
+
};
|
|
1322
|
+
}
|
|
1323
|
+
m = { groupStatusMessageV2: { message: m } };
|
|
1324
|
+
delete message.groupStatus;
|
|
1325
|
+
}
|
|
1326
|
+
// Lia@Changes 06-05-26 --- Add "spoiler" boolean to set contextInfo.isSpoiler and wrap message into spoilerMessage
|
|
1327
|
+
if (hasOptionalProperty(message, 'spoiler') && !!message.spoiler) {
|
|
1328
|
+
const messageType = Object.keys(m)[0];
|
|
1329
|
+
const key = m[messageType];
|
|
1330
|
+
if ('contextInfo' in key && !!key.contextInfo) {
|
|
1331
|
+
key.contextInfo.isSpoiler = message.spoiler;
|
|
1332
|
+
}
|
|
1333
|
+
else if (key) {
|
|
1334
|
+
key.contextInfo = {
|
|
1335
|
+
isSpoiler: message.spoiler
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1338
|
+
m = { spoilerMessage: { message: m } };
|
|
1339
|
+
delete message.spoiler;
|
|
1340
|
+
}
|
|
1341
|
+
// Lia@Changes 02-02-26 --- Add "interactiveAsTemplate" boolean to wrap interactiveMessage into templateMessage
|
|
1342
|
+
else if (hasOptionalProperty(message, 'interactiveAsTemplate') && !!message.interactiveAsTemplate) {
|
|
1343
|
+
if (!m.interactiveMessage) {
|
|
1344
|
+
throw new Boom('Invalid message type for template', { statusCode: 400 }); // Lia@Note 02-02-26 --- To avoid bug 👀
|
|
1345
|
+
}
|
|
1346
|
+
m = {
|
|
1347
|
+
templateMessage: {
|
|
1348
|
+
interactiveMessageTemplate: m.interactiveMessage,
|
|
1349
|
+
templateId: message.id || 'template-' + Date.now() // Lia@Note 04-02-26 --- Minimal templateId to satisfy WhatsApp ( ꈍᴗꈍ)
|
|
1350
|
+
}
|
|
1351
|
+
};
|
|
1352
|
+
delete message.interactiveAsTemplate;
|
|
1353
|
+
}
|
|
1354
|
+
// Lia@Changes 30-01-26 --- Add "ephemeral" boolean to wrap message into ephemeralMessage like "viewOnce"
|
|
1355
|
+
if (hasOptionalProperty(message, 'ephemeral') && !!message.ephemeral) {
|
|
1356
|
+
m = { ephemeralMessage: { message: m } };
|
|
1357
|
+
delete message.ephemeral;
|
|
1358
|
+
}
|
|
1359
|
+
// Lia@Changes 16-05-26 --- Add wrap message into lottieStickerMessage by isLottie boolean
|
|
1360
|
+
if (hasOptionalProperty(message, 'isLottie') && !!message.isLottie) {
|
|
1361
|
+
m = { lottieStickerMessage: { message: m } };
|
|
1362
|
+
}
|
|
1363
|
+
else if (hasOptionalProperty(message, 'viewOnce') && !!message.viewOnce) {
|
|
1364
|
+
m = { viewOnceMessage: { message: m } };
|
|
1365
|
+
}
|
|
1366
|
+
// Lia@Changes 03-02-26 --- Add "viewOnceV2" boolean to wrap message into viewOnceMessageV2 like "viewOnce"
|
|
1367
|
+
else if (hasOptionalProperty(message, 'viewOnceV2') && !!message.viewOnceV2) {
|
|
1368
|
+
m = { viewOnceMessageV2: { message: m } };
|
|
1369
|
+
delete message.viewOnceV2;
|
|
1370
|
+
}
|
|
1371
|
+
// Lia@Changes 03-02-26 --- Add "viewOnceV2Extension" boolean to wrap message into viewOnceMessageV2Extension like "viewOnce"
|
|
1372
|
+
else if (hasOptionalProperty(message, 'viewOnceV2Extension') && !!message.viewOnceV2Extension) {
|
|
1373
|
+
m = { viewOnceMessageV2Extension: { message: m } };
|
|
1374
|
+
delete message.viewOnceV2Extension;
|
|
1375
|
+
}
|
|
1376
|
+
if (hasOptionalProperty(message, 'edit')) {
|
|
1377
|
+
m = {
|
|
1378
|
+
protocolMessage: {
|
|
1379
|
+
key: message.edit,
|
|
1380
|
+
editedMessage: m,
|
|
1381
|
+
timestampMs: Date.now(),
|
|
1382
|
+
type: WAProto.Message.ProtocolMessage.Type.MESSAGE_EDIT
|
|
540
1383
|
}
|
|
541
1384
|
};
|
|
542
1385
|
}
|
|
@@ -555,10 +1398,12 @@ export const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
555
1398
|
options.timestamp = new Date();
|
|
556
1399
|
}
|
|
557
1400
|
const innerMessage = normalizeMessageContent(message);
|
|
1401
|
+
const messageContextInfo = message.messageContextInfo;
|
|
558
1402
|
const key = getContentType(innerMessage);
|
|
559
1403
|
const timestamp = unixTimestampSeconds(options.timestamp);
|
|
1404
|
+
const isNewsletter = isJidNewsletter(jid);
|
|
560
1405
|
const { quoted, userJid } = options;
|
|
561
|
-
if (quoted
|
|
1406
|
+
if (quoted) {
|
|
562
1407
|
const participant = quoted.key.fromMe
|
|
563
1408
|
? userJid // TODO: Add support for LIDs
|
|
564
1409
|
: quoted.participant || quoted.key.participant || quoted.key.remoteJid;
|
|
@@ -576,7 +1421,7 @@ export const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
576
1421
|
contextInfo.quotedMessage = quotedMsg;
|
|
577
1422
|
// if a participant is quoted, then it must be a group
|
|
578
1423
|
// hence, remoteJid of group must also be entered
|
|
579
|
-
if (jid !== quoted.key.remoteJid) {
|
|
1424
|
+
if (!isNewsletter && jid !== quoted.key.remoteJid) {
|
|
580
1425
|
contextInfo.remoteJid = quoted.key.remoteJid;
|
|
581
1426
|
}
|
|
582
1427
|
if (contextInfo && innerMessage[key]) {
|
|
@@ -592,7 +1437,7 @@ export const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
592
1437
|
// already not converted to disappearing message
|
|
593
1438
|
key !== 'ephemeralMessage' &&
|
|
594
1439
|
// newsletters don't support ephemeral messages
|
|
595
|
-
!
|
|
1440
|
+
!isNewsletter) {
|
|
596
1441
|
/* @ts-ignore */
|
|
597
1442
|
innerMessage[key].contextInfo = {
|
|
598
1443
|
...(innerMessage[key].contextInfo || {}),
|
|
@@ -600,6 +1445,14 @@ export const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
600
1445
|
//ephemeralSettingTimestamp: options.ephemeralOptions.eph_setting_ts?.toString()
|
|
601
1446
|
};
|
|
602
1447
|
}
|
|
1448
|
+
// Lia@Changes 30-01-26 --- Add deviceListMetadata inside messageContextInfo for private chat
|
|
1449
|
+
if (messageContextInfo?.messageSecret && (isPnUser(jid) || isLidUser(jid))) {
|
|
1450
|
+
messageContextInfo.deviceListMetadata = {
|
|
1451
|
+
recipientKeyHash: randomBytes(10),
|
|
1452
|
+
recipientTimestamp: unixTimestampSeconds()
|
|
1453
|
+
};
|
|
1454
|
+
messageContextInfo.deviceListMetadataVersion = 2;
|
|
1455
|
+
}
|
|
603
1456
|
message = WAProto.Message.create(message);
|
|
604
1457
|
const messageJSON = {
|
|
605
1458
|
key: {
|
|
@@ -619,7 +1472,10 @@ export const generateWAMessage = async (jid, content, options) => {
|
|
|
619
1472
|
// ensure msg ID is with every log
|
|
620
1473
|
options.logger = options?.logger?.child({ msgId: options.messageId });
|
|
621
1474
|
// Pass jid in the options to generateWAMessageContent
|
|
622
|
-
|
|
1475
|
+
if (jid) {
|
|
1476
|
+
options.jid = jid;
|
|
1477
|
+
}
|
|
1478
|
+
return generateWAMessageFromContent(jid, await generateWAMessageContent(content, options), options);
|
|
623
1479
|
};
|
|
624
1480
|
/** Get the key to access the true type of content */
|
|
625
1481
|
export const getContentType = (content) => {
|
|
@@ -648,16 +1504,35 @@ export const normalizeMessageContent = (content) => {
|
|
|
648
1504
|
content = inner.message;
|
|
649
1505
|
}
|
|
650
1506
|
return content;
|
|
1507
|
+
// Lia@Changes 03-02-26 --- Add all futureProofMessage into getFutureProofMessage()
|
|
651
1508
|
function getFutureProofMessage(message) {
|
|
652
|
-
return (message?.
|
|
653
|
-
message?.
|
|
1509
|
+
return (message?.associatedChildMessage ||
|
|
1510
|
+
message?.botForwardedMessage ||
|
|
1511
|
+
message?.botInvokeMessage ||
|
|
1512
|
+
message?.botTaskMessage ||
|
|
654
1513
|
message?.documentWithCaptionMessage ||
|
|
655
|
-
message?.viewOnceMessageV2 ||
|
|
656
|
-
message?.viewOnceMessageV2Extension ||
|
|
657
1514
|
message?.editedMessage ||
|
|
658
|
-
message?.
|
|
1515
|
+
message?.ephemeralMessage ||
|
|
1516
|
+
message?.eventCoverImage ||
|
|
1517
|
+
message?.groupMentionedMessage ||
|
|
1518
|
+
message?.groupStatusMentionMessage ||
|
|
659
1519
|
message?.groupStatusMessage ||
|
|
660
|
-
message?.groupStatusMessageV2
|
|
1520
|
+
message?.groupStatusMessageV2 ||
|
|
1521
|
+
message?.limitSharingMessage ||
|
|
1522
|
+
message?.lottieStickerMessage ||
|
|
1523
|
+
message?.newsletterAdminProfileMessage ||
|
|
1524
|
+
message?.newsletterAdminProfileMessageV2 ||
|
|
1525
|
+
message?.newsletterAdminProfileStatusMessage ||
|
|
1526
|
+
message?.pollCreationMessageV4 ||
|
|
1527
|
+
message?.pollCreationOptionImageMessage ||
|
|
1528
|
+
message?.questionMessage ||
|
|
1529
|
+
message?.questionReplyMessage ||
|
|
1530
|
+
message?.spoilerMessage ||
|
|
1531
|
+
message?.statusAddYours ||
|
|
1532
|
+
message?.statusMentionMessage ||
|
|
1533
|
+
message?.viewOnceMessage ||
|
|
1534
|
+
message?.viewOnceMessageV2 ||
|
|
1535
|
+
message?.viewOnceMessageV2Extension);
|
|
661
1536
|
}
|
|
662
1537
|
};
|
|
663
1538
|
/**
|
|
@@ -890,4 +1765,76 @@ export const assertMediaContent = (content) => {
|
|
|
890
1765
|
}
|
|
891
1766
|
return mediaContent;
|
|
892
1767
|
};
|
|
1768
|
+
/**
|
|
1769
|
+
* Checks if a WebP buffer is animated by looking for VP8X chunk with animation flag
|
|
1770
|
+
* or ANIM/ANMF chunks
|
|
1771
|
+
*/
|
|
1772
|
+
const isAnimatedWebP = (buffer) => {
|
|
1773
|
+
// WebP must start with RIFF....WEBP
|
|
1774
|
+
if (buffer.length < 12 ||
|
|
1775
|
+
buffer[0] !== 0x52 ||
|
|
1776
|
+
buffer[1] !== 0x49 ||
|
|
1777
|
+
buffer[2] !== 0x46 ||
|
|
1778
|
+
buffer[3] !== 0x46 ||
|
|
1779
|
+
buffer[8] !== 0x57 ||
|
|
1780
|
+
buffer[9] !== 0x45 ||
|
|
1781
|
+
buffer[10] !== 0x42 ||
|
|
1782
|
+
buffer[11] !== 0x50) {
|
|
1783
|
+
return false;
|
|
1784
|
+
}
|
|
1785
|
+
;
|
|
1786
|
+
// Parse chunks starting after RIFF header (12 bytes)
|
|
1787
|
+
let offset = 12;
|
|
1788
|
+
while (offset < buffer.length - 8) {
|
|
1789
|
+
const chunkFourCC = buffer.toString('ascii', offset, offset + 4);
|
|
1790
|
+
const chunkSize = buffer.readUInt32LE(offset + 4);
|
|
1791
|
+
if (chunkFourCC === 'VP8X') {
|
|
1792
|
+
// VP8X extended header, check animation flag (bit 1 at offset+8)
|
|
1793
|
+
const flagsOffset = offset + 8;
|
|
1794
|
+
if (flagsOffset < buffer.length) {
|
|
1795
|
+
const flags = buffer[flagsOffset];
|
|
1796
|
+
if (flags & 0x02) {
|
|
1797
|
+
return true;
|
|
1798
|
+
}
|
|
1799
|
+
;
|
|
1800
|
+
}
|
|
1801
|
+
;
|
|
1802
|
+
}
|
|
1803
|
+
else if (chunkFourCC === 'ANIM' || chunkFourCC === 'ANMF') {
|
|
1804
|
+
// ANIM or ANMF chunks indicate animation
|
|
1805
|
+
return true;
|
|
1806
|
+
}
|
|
1807
|
+
;
|
|
1808
|
+
// Move to next chunk (chunk size + 8 bytes header, padded to even)
|
|
1809
|
+
offset += 8 + chunkSize + (chunkSize % 2);
|
|
1810
|
+
}
|
|
1811
|
+
;
|
|
1812
|
+
return false;
|
|
1813
|
+
};
|
|
1814
|
+
/**
|
|
1815
|
+
* Checks if a buffer is a WebP file
|
|
1816
|
+
*/
|
|
1817
|
+
const isWebPBuffer = (buffer) => {
|
|
1818
|
+
return (buffer.length >= 12 &&
|
|
1819
|
+
buffer[0] === 0x52 &&
|
|
1820
|
+
buffer[1] === 0x49 &&
|
|
1821
|
+
buffer[2] === 0x46 &&
|
|
1822
|
+
buffer[3] === 0x46 &&
|
|
1823
|
+
buffer[8] === 0x57 &&
|
|
1824
|
+
buffer[9] === 0x45 &&
|
|
1825
|
+
buffer[10] === 0x42 &&
|
|
1826
|
+
buffer[11] === 0x50);
|
|
1827
|
+
};
|
|
1828
|
+
/**
|
|
1829
|
+
* Lia@Changes 30-01-26
|
|
1830
|
+
* ---
|
|
1831
|
+
* Determines whether a message should include a Biz Binary Node.
|
|
1832
|
+
* A Biz Binary Node is added only for interactive messages
|
|
1833
|
+
* such as buttons or other supported interactive types.
|
|
1834
|
+
*/
|
|
1835
|
+
export const shouldIncludeBizBinaryNode = (message) => !!(message.buttonsMessage ||
|
|
1836
|
+
message.listMessage ||
|
|
1837
|
+
message.templateMessage ||
|
|
1838
|
+
(message.interactiveMessage &&
|
|
1839
|
+
message.interactiveMessage.nativeFlowMessage));
|
|
893
1840
|
//# sourceMappingURL=messages.js.map
|