@kelvdra/baileys 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1478 -0
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +4633 -0
- package/WAProto/fix-imports.js +29 -0
- package/WAProto/index.d.ts +37016 -0
- package/WAProto/index.js +169659 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/index.d.ts +62 -0
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +115 -0
- package/lib/Defaults/index.js.map +1 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/ciphertext-message.js.map +1 -0
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/lib/Signal/Group/group-session-builder.js.map +1 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
- package/lib/Signal/Group/group_cipher.js +82 -0
- package/lib/Signal/Group/group_cipher.js.map +1 -0
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.d.ts.map +1 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/index.js.map +1 -0
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
- package/lib/Signal/Group/keyhelper.js +18 -0
- package/lib/Signal/Group/keyhelper.js.map +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-chain-key.js +26 -0
- package/lib/Signal/Group/sender-chain-key.js.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-name.js +48 -0
- package/lib/Signal/Group/sender-key-name.js.map +1 -0
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-record.js +41 -0
- package/lib/Signal/Group/sender-key-record.js.map +1 -0
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-state.js +84 -0
- package/lib/Signal/Group/sender-key-state.js.map +1 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-message-key.js +26 -0
- package/lib/Signal/Group/sender-message-key.js.map +1 -0
- package/lib/Signal/libsignal.d.ts +5 -0
- package/lib/Signal/libsignal.d.ts.map +1 -0
- package/lib/Signal/libsignal.js +342 -0
- package/lib/Signal/libsignal.js.map +1 -0
- package/lib/Signal/lid-mapping.d.ts +23 -0
- package/lib/Signal/lid-mapping.d.ts.map +1 -0
- package/lib/Signal/lid-mapping.js +171 -0
- package/lib/Signal/lid-mapping.js.map +1 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.d.ts.map +1 -0
- package/lib/Socket/Client/index.js +3 -0
- package/lib/Socket/Client/index.js.map +1 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.d.ts.map +1 -0
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/types.js.map +1 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +50 -0
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +188 -0
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +376 -0
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +98 -0
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +962 -0
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +244 -0
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/groups.d.ts +137 -0
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +327 -0
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/hydra.d.ts +174 -0
- package/lib/Socket/hydra.js +715 -0
- package/lib/Socket/index.d.ts +231 -0
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +18 -0
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +173 -0
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +1228 -0
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +169 -0
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +1367 -0
- package/lib/Socket/messages-send.js.map +1 -0
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.d.ts.map +1 -0
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/mex.js.map +1 -0
- package/lib/Socket/newsletter.d.ts +147 -0
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +181 -0
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +51 -0
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +841 -0
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Store/index.d.ts +4 -0
- package/lib/Store/index.js +4 -0
- package/lib/Store/make-cache-manager-store.d.ts +14 -0
- package/lib/Store/make-cache-manager-store.js +81 -0
- package/lib/Store/make-in-memory-store.d.ts +123 -0
- package/lib/Store/make-in-memory-store.js +416 -0
- package/lib/Store/make-ordered-dictionary.d.ts +12 -0
- package/lib/Store/make-ordered-dictionary.js +82 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +31 -0
- package/lib/Types/Auth.d.ts +111 -0
- package/lib/Types/Auth.d.ts.map +1 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Auth.js.map +1 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.d.ts.map +1 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Bussines.js.map +1 -0
- package/lib/Types/Call.d.ts +14 -0
- package/lib/Types/Call.d.ts.map +1 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Call.js.map +1 -0
- package/lib/Types/Chat.d.ts +123 -0
- package/lib/Types/Chat.d.ts.map +1 -0
- package/lib/Types/Chat.js +8 -0
- package/lib/Types/Chat.js.map +1 -0
- package/lib/Types/Contact.d.ts +24 -0
- package/lib/Types/Contact.d.ts.map +1 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Contact.js.map +1 -0
- package/lib/Types/Events.d.ts +202 -0
- package/lib/Types/Events.d.ts.map +1 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/Events.js.map +1 -0
- package/lib/Types/GroupMetadata.d.ts +67 -0
- package/lib/Types/GroupMetadata.d.ts.map +1 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/GroupMetadata.js.map +1 -0
- package/lib/Types/Label.d.ts +47 -0
- package/lib/Types/Label.d.ts.map +1 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/Label.js.map +1 -0
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/LabelAssociation.d.ts.map +1 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/LabelAssociation.js.map +1 -0
- package/lib/Types/Message.d.ts +303 -0
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +11 -0
- package/lib/Types/Message.js.map +1 -0
- package/lib/Types/Newsletter.d.ts +135 -0
- package/lib/Types/Newsletter.d.ts.map +1 -0
- package/lib/Types/Newsletter.js +31 -0
- package/lib/Types/Newsletter.js.map +1 -0
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Product.d.ts.map +1 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Product.js.map +1 -0
- package/lib/Types/Signal.d.ts +76 -0
- package/lib/Types/Signal.d.ts.map +1 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Signal.js.map +1 -0
- package/lib/Types/Socket.d.ts +133 -0
- package/lib/Types/Socket.d.ts.map +1 -0
- package/lib/Types/Socket.js +3 -0
- package/lib/Types/Socket.js.map +1 -0
- package/lib/Types/State.d.ts +39 -0
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +13 -0
- package/lib/Types/State.js.map +1 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.d.ts.map +1 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/USync.js.map +1 -0
- package/lib/Types/index.d.ts +65 -0
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +26 -0
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/auth-utils.d.ts +19 -0
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +257 -0
- package/lib/Utils/auth-utils.js.map +1 -0
- package/lib/Utils/baileys-event-stream.d.ts +17 -0
- package/lib/Utils/baileys-event-stream.d.ts.map +1 -0
- package/lib/Utils/baileys-event-stream.js +56 -0
- package/lib/Utils/baileys-event-stream.js.map +1 -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 +28 -0
- package/lib/Utils/browser-utils.js.map +1 -0
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +231 -0
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +763 -0
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +142 -0
- 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 +279 -0
- 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 +548 -0
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +90 -0
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +381 -0
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts +19 -0
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +84 -0
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/index.d.ts +20 -0
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +20 -0
- 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 +85 -0
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +12 -0
- package/lib/Utils/logger.d.ts.map +1 -0
- package/lib/Utils/logger.js +3 -0
- package/lib/Utils/logger.js.map +1 -0
- package/lib/Utils/lt-hash.d.ts +13 -0
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +48 -0
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts +8 -0
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +40 -0
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/message-retry-manager.d.ts +82 -0
- package/lib/Utils/message-retry-manager.d.ts.map +1 -0
- package/lib/Utils/message-retry-manager.js +149 -0
- package/lib/Utils/message-retry-manager.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +114 -0
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +684 -0
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +76 -0
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +820 -0
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +147 -0
- 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 +106 -0
- package/lib/Utils/pre-key-manager.js.map +1 -0
- package/lib/Utils/process-message.d.ts +42 -0
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +413 -0
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/signal.d.ts +34 -0
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +159 -0
- package/lib/Utils/signal.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +121 -0
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +195 -0
- 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 +1301 -0
- package/lib/WABinary/constants.js.map +1 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.d.ts.map +1 -0
- package/lib/WABinary/decode.js +238 -0
- package/lib/WABinary/decode.js.map +1 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.d.ts.map +1 -0
- package/lib/WABinary/encode.js +216 -0
- package/lib/WABinary/encode.js.map +1 -0
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/generic-utils.d.ts.map +1 -0
- package/lib/WABinary/generic-utils.js +111 -0
- package/lib/WABinary/generic-utils.js.map +1 -0
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.d.ts.map +1 -0
- package/lib/WABinary/index.js +6 -0
- package/lib/WABinary/index.js.map +1 -0
- package/lib/WABinary/jid-utils.d.ts +48 -0
- package/lib/WABinary/jid-utils.d.ts.map +1 -0
- package/lib/WABinary/jid-utils.js +96 -0
- package/lib/WABinary/jid-utils.js.map +1 -0
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.d.ts.map +1 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WABinary/types.js.map +1 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/BinaryInfo.d.ts.map +1 -0
- package/lib/WAM/BinaryInfo.js +10 -0
- package/lib/WAM/BinaryInfo.js.map +1 -0
- package/lib/WAM/constants.d.ts +40 -0
- package/lib/WAM/constants.d.ts.map +1 -0
- package/lib/WAM/constants.js +22853 -0
- package/lib/WAM/constants.js.map +1 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.d.ts.map +1 -0
- package/lib/WAM/encode.js +150 -0
- package/lib/WAM/encode.js.map +1 -0
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.d.ts.map +1 -0
- package/lib/WAM/index.js +4 -0
- package/lib/WAM/index.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +29 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/index.js +5 -0
- 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 +94 -0
- 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 +23 -0
- package/lib/WAUSync/USyncUser.js.map +1 -0
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.d.ts.map +1 -0
- package/lib/WAUSync/index.js +4 -0
- package/lib/WAUSync/index.js.map +1 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +12 -0
- package/lib/index.js.map +1 -0
- package/package.json +104 -0
|
@@ -0,0 +1,1367 @@
|
|
|
1
|
+
import NodeCache from '@cacheable/node-cache';
|
|
2
|
+
import { Boom } from '@hapi/boom';
|
|
3
|
+
import * as Utils_1 from '../Utils/index.js';
|
|
4
|
+
import { proto } from '../../WAProto/index.js';
|
|
5
|
+
import { DEFAULT_CACHE_TTLS, WA_DEFAULT_EPHEMERAL } from '../Defaults/index.js';
|
|
6
|
+
import * as WABinary_1 from "../WABinary/index.js"
|
|
7
|
+
const { aggregateMessageKeysNotFromMe, assertMediaContent, bindWaitForEvent, decryptMediaRetryData, encodeNewsletterMessage, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, extractDeviceJids, generateMessageIDV2, generateParticipantHashV2, generateWAMessage, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, MessageRetryManager, normalizeMessageContent, parseAndInjectE2ESessions, unixTimestampSeconds } = Utils_1;
|
|
8
|
+
import { getUrlInfo } from '../Utils/link-preview.js';
|
|
9
|
+
import { makeKeyedMutex } from '../Utils/make-mutex.js';
|
|
10
|
+
import { areJidsSameUser, getBinaryNodeChild, getBinaryNodeChildren, isHostedLidUser, isHostedPnUser, isJidGroup, isLidUser, isPnUser, jidDecode, jidEncode, jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
11
|
+
import { USyncQuery, USyncUser } from '../WAUSync/index.js';
|
|
12
|
+
import { makeNewsletterSocket } from './newsletter.js';
|
|
13
|
+
import hydra from './hydra.js'
|
|
14
|
+
export const makeMessagesSocket = (config) => {
|
|
15
|
+
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: httpRequestOptions, patchMessageBeforeSending, cachedGroupMetadata, enableRecentMessageCache, maxMsgRetryCount } = config;
|
|
16
|
+
const sock = makeNewsletterSocket(config);
|
|
17
|
+
const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral } = sock;
|
|
18
|
+
const userDevicesCache = config.userDevicesCache ||
|
|
19
|
+
new NodeCache({
|
|
20
|
+
stdTTL: DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
|
|
21
|
+
useClones: false
|
|
22
|
+
});
|
|
23
|
+
const peerSessionsCache = new NodeCache({
|
|
24
|
+
stdTTL: DEFAULT_CACHE_TTLS.USER_DEVICES,
|
|
25
|
+
useClones: false
|
|
26
|
+
});
|
|
27
|
+
// Initialize message retry manager if enabled
|
|
28
|
+
const messageRetryManager = enableRecentMessageCache ? new MessageRetryManager(logger, maxMsgRetryCount) : null;
|
|
29
|
+
// Prevent race conditions in Signal session encryption by user
|
|
30
|
+
const encryptionMutex = makeKeyedMutex();
|
|
31
|
+
let mediaConn;
|
|
32
|
+
const refreshMediaConn = async (forceGet = false) => {
|
|
33
|
+
const media = await mediaConn;
|
|
34
|
+
if (!media || forceGet || new Date().getTime() - media.fetchDate.getTime() > media.ttl * 1000) {
|
|
35
|
+
mediaConn = (async () => {
|
|
36
|
+
const result = await query({
|
|
37
|
+
tag: 'iq',
|
|
38
|
+
attrs: {
|
|
39
|
+
type: 'set',
|
|
40
|
+
xmlns: 'w:m',
|
|
41
|
+
to: S_WHATSAPP_NET
|
|
42
|
+
},
|
|
43
|
+
content: [{ tag: 'media_conn', attrs: {} }]
|
|
44
|
+
});
|
|
45
|
+
const mediaConnNode = getBinaryNodeChild(result, 'media_conn');
|
|
46
|
+
// TODO: explore full length of data that whatsapp provides
|
|
47
|
+
const node = {
|
|
48
|
+
hosts: getBinaryNodeChildren(mediaConnNode, 'host').map(({ attrs }) => ({
|
|
49
|
+
hostname: attrs.hostname,
|
|
50
|
+
maxContentLengthBytes: +attrs.maxContentLengthBytes
|
|
51
|
+
})),
|
|
52
|
+
auth: mediaConnNode.attrs.auth,
|
|
53
|
+
ttl: +mediaConnNode.attrs.ttl,
|
|
54
|
+
fetchDate: new Date()
|
|
55
|
+
};
|
|
56
|
+
logger.debug('fetched media conn');
|
|
57
|
+
return node;
|
|
58
|
+
})();
|
|
59
|
+
}
|
|
60
|
+
return mediaConn;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* generic send receipt function
|
|
64
|
+
* used for receipts of phone call, read, delivery etc.
|
|
65
|
+
* */
|
|
66
|
+
const sendReceipt = async (jid, participant, messageIds, type) => {
|
|
67
|
+
if (!messageIds || messageIds.length === 0) {
|
|
68
|
+
throw new Boom('missing ids in receipt');
|
|
69
|
+
}
|
|
70
|
+
const node = {
|
|
71
|
+
tag: 'receipt',
|
|
72
|
+
attrs: {
|
|
73
|
+
id: messageIds[0]
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const isReadReceipt = type === 'read' || type === 'read-self';
|
|
77
|
+
if (isReadReceipt) {
|
|
78
|
+
node.attrs.t = unixTimestampSeconds().toString();
|
|
79
|
+
}
|
|
80
|
+
if (type === 'sender' && (isPnUser(jid) || isLidUser(jid))) {
|
|
81
|
+
node.attrs.recipient = jid;
|
|
82
|
+
node.attrs.to = participant;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
node.attrs.to = jid;
|
|
86
|
+
if (participant) {
|
|
87
|
+
node.attrs.participant = participant;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (type) {
|
|
91
|
+
node.attrs.type = type;
|
|
92
|
+
}
|
|
93
|
+
const remainingMessageIds = messageIds.slice(1);
|
|
94
|
+
if (remainingMessageIds.length) {
|
|
95
|
+
node.content = [
|
|
96
|
+
{
|
|
97
|
+
tag: 'list',
|
|
98
|
+
attrs: {},
|
|
99
|
+
content: remainingMessageIds.map(id => ({
|
|
100
|
+
tag: 'item',
|
|
101
|
+
attrs: { id }
|
|
102
|
+
}))
|
|
103
|
+
}
|
|
104
|
+
];
|
|
105
|
+
}
|
|
106
|
+
logger.debug({ attrs: node.attrs, messageIds }, 'sending receipt for messages');
|
|
107
|
+
await sendNode(node);
|
|
108
|
+
};
|
|
109
|
+
/** Correctly bulk send receipts to multiple chats, participants */
|
|
110
|
+
const sendReceipts = async (keys, type) => {
|
|
111
|
+
const recps = aggregateMessageKeysNotFromMe(keys);
|
|
112
|
+
for (const { jid, participant, messageIds } of recps) {
|
|
113
|
+
await sendReceipt(jid, participant, messageIds, type);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
/** Bulk read messages. Keys can be from different chats & participants */
|
|
117
|
+
const readMessages = async (keys) => {
|
|
118
|
+
const privacySettings = await fetchPrivacySettings();
|
|
119
|
+
// based on privacy settings, we have to change the read type
|
|
120
|
+
const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self';
|
|
121
|
+
await sendReceipts(keys, readType);
|
|
122
|
+
};
|
|
123
|
+
/** Fetch all the devices we've to send a message to */
|
|
124
|
+
const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
|
|
125
|
+
const deviceResults = [];
|
|
126
|
+
if (!useCache) {
|
|
127
|
+
logger.debug('not using cache for devices');
|
|
128
|
+
}
|
|
129
|
+
const toFetch = [];
|
|
130
|
+
const jidsWithUser = jids
|
|
131
|
+
.map(jid => {
|
|
132
|
+
const decoded = jidDecode(jid);
|
|
133
|
+
const user = decoded?.user;
|
|
134
|
+
const device = decoded?.device;
|
|
135
|
+
const isExplicitDevice = typeof device === 'number' && device >= 0;
|
|
136
|
+
if (isExplicitDevice && user) {
|
|
137
|
+
deviceResults.push({
|
|
138
|
+
user,
|
|
139
|
+
device,
|
|
140
|
+
jid
|
|
141
|
+
});
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
jid = jidNormalizedUser(jid);
|
|
145
|
+
return { jid, user };
|
|
146
|
+
})
|
|
147
|
+
.filter(jid => jid !== null);
|
|
148
|
+
let mgetDevices;
|
|
149
|
+
if (useCache && userDevicesCache.mget) {
|
|
150
|
+
const usersToFetch = jidsWithUser.map(j => j?.user).filter(Boolean);
|
|
151
|
+
mgetDevices = await userDevicesCache.mget(usersToFetch);
|
|
152
|
+
}
|
|
153
|
+
for (const { jid, user } of jidsWithUser) {
|
|
154
|
+
if (useCache) {
|
|
155
|
+
const devices = mgetDevices?.[user] ||
|
|
156
|
+
(userDevicesCache.mget ? undefined : (await userDevicesCache.get(user)));
|
|
157
|
+
if (devices) {
|
|
158
|
+
const devicesWithJid = devices.map(d => ({
|
|
159
|
+
...d,
|
|
160
|
+
jid: jidEncode(d.user, d.server, d.device)
|
|
161
|
+
}));
|
|
162
|
+
deviceResults.push(...devicesWithJid);
|
|
163
|
+
logger.trace({ user }, 'using cache for devices');
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
toFetch.push(jid);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
toFetch.push(jid);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (!toFetch.length) {
|
|
174
|
+
return deviceResults;
|
|
175
|
+
}
|
|
176
|
+
const requestedLidUsers = new Set();
|
|
177
|
+
for (const jid of toFetch) {
|
|
178
|
+
if (isLidUser(jid) || isHostedLidUser(jid)) {
|
|
179
|
+
const user = jidDecode(jid)?.user;
|
|
180
|
+
if (user)
|
|
181
|
+
requestedLidUsers.add(user);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const query = new USyncQuery().withContext('message').withDeviceProtocol().withLIDProtocol();
|
|
185
|
+
for (const jid of toFetch) {
|
|
186
|
+
query.withUser(new USyncUser().withId(jid)); // todo: investigate - the idea here is that <user> should have an inline lid field with the lid being the pn equivalent
|
|
187
|
+
}
|
|
188
|
+
const result = await sock.executeUSyncQuery(query);
|
|
189
|
+
if (result) {
|
|
190
|
+
// TODO: LID MAP this stuff (lid protocol will now return lid with devices)
|
|
191
|
+
const lidResults = result.list.filter(a => !!a.lid);
|
|
192
|
+
if (lidResults.length > 0) {
|
|
193
|
+
logger.trace('Storing LID maps from device call');
|
|
194
|
+
await signalRepository.lidMapping.storeLIDPNMappings(lidResults.map(a => ({ lid: a.lid, pn: a.id })));
|
|
195
|
+
}
|
|
196
|
+
const extracted = extractDeviceJids(result?.list, authState.creds.me.id, authState.creds.me.lid, ignoreZeroDevices);
|
|
197
|
+
const deviceMap = {};
|
|
198
|
+
for (const item of extracted) {
|
|
199
|
+
deviceMap[item.user] = deviceMap[item.user] || [];
|
|
200
|
+
deviceMap[item.user]?.push(item);
|
|
201
|
+
}
|
|
202
|
+
// Process each user's devices as a group for bulk LID migration
|
|
203
|
+
for (const [user, userDevices] of Object.entries(deviceMap)) {
|
|
204
|
+
const isLidUser = requestedLidUsers.has(user);
|
|
205
|
+
// Process all devices for this user
|
|
206
|
+
for (const item of userDevices) {
|
|
207
|
+
const finalJid = isLidUser
|
|
208
|
+
? jidEncode(user, item.server, item.device)
|
|
209
|
+
: jidEncode(item.user, item.server, item.device);
|
|
210
|
+
deviceResults.push({
|
|
211
|
+
...item,
|
|
212
|
+
jid: finalJid
|
|
213
|
+
});
|
|
214
|
+
logger.debug({
|
|
215
|
+
user: item.user,
|
|
216
|
+
device: item.device,
|
|
217
|
+
finalJid,
|
|
218
|
+
usedLid: isLidUser
|
|
219
|
+
}, 'Processed device with LID priority');
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (userDevicesCache.mset) {
|
|
223
|
+
// if the cache supports mset, we can set all devices in one go
|
|
224
|
+
await userDevicesCache.mset(Object.entries(deviceMap).map(([key, value]) => ({ key, value })));
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
for (const key in deviceMap) {
|
|
228
|
+
if (deviceMap[key])
|
|
229
|
+
await userDevicesCache.set(key, deviceMap[key]);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
const userDeviceUpdates = {};
|
|
233
|
+
for (const [userId, devices] of Object.entries(deviceMap)) {
|
|
234
|
+
if (devices && devices.length > 0) {
|
|
235
|
+
userDeviceUpdates[userId] = devices.map(d => d.device?.toString() || '0');
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (Object.keys(userDeviceUpdates).length > 0) {
|
|
239
|
+
try {
|
|
240
|
+
await authState.keys.set({ 'device-list': userDeviceUpdates });
|
|
241
|
+
logger.debug({ userCount: Object.keys(userDeviceUpdates).length }, 'stored user device lists for bulk migration');
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
logger.warn({ error }, 'failed to store user device lists');
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return deviceResults;
|
|
249
|
+
};
|
|
250
|
+
const assertSessions = async (jids) => {
|
|
251
|
+
let didFetchNewSession = false;
|
|
252
|
+
const uniqueJids = [...new Set(jids)]; // Deduplicate JIDs
|
|
253
|
+
const jidsRequiringFetch = [];
|
|
254
|
+
logger.debug({ jids }, 'assertSessions call with jids');
|
|
255
|
+
// Check peerSessionsCache and validate sessions using libsignal loadSession
|
|
256
|
+
for (const jid of uniqueJids) {
|
|
257
|
+
const signalId = signalRepository.jidToSignalProtocolAddress(jid);
|
|
258
|
+
const cachedSession = peerSessionsCache.get(signalId);
|
|
259
|
+
if (cachedSession !== undefined) {
|
|
260
|
+
if (cachedSession) {
|
|
261
|
+
continue; // Session exists in cache
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
const sessionValidation = await signalRepository.validateSession(jid);
|
|
266
|
+
const hasSession = sessionValidation.exists;
|
|
267
|
+
peerSessionsCache.set(signalId, hasSession);
|
|
268
|
+
if (hasSession) {
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
jidsRequiringFetch.push(jid);
|
|
273
|
+
}
|
|
274
|
+
if (jidsRequiringFetch.length) {
|
|
275
|
+
// LID if mapped, otherwise original
|
|
276
|
+
const wireJids = [
|
|
277
|
+
...jidsRequiringFetch.filter(jid => !!isLidUser(jid) || !!isHostedLidUser(jid)),
|
|
278
|
+
...((await signalRepository.lidMapping.getLIDsForPNs(jidsRequiringFetch.filter(jid => !!isPnUser(jid) || !!isHostedPnUser(jid)))) || []).map(a => a.lid)
|
|
279
|
+
];
|
|
280
|
+
logger.debug({ jidsRequiringFetch, wireJids }, 'fetching sessions');
|
|
281
|
+
const result = await query({
|
|
282
|
+
tag: 'iq',
|
|
283
|
+
attrs: {
|
|
284
|
+
xmlns: 'encrypt',
|
|
285
|
+
type: 'get',
|
|
286
|
+
to: S_WHATSAPP_NET
|
|
287
|
+
},
|
|
288
|
+
content: [
|
|
289
|
+
{
|
|
290
|
+
tag: 'key',
|
|
291
|
+
attrs: {},
|
|
292
|
+
content: wireJids.map(jid => ({
|
|
293
|
+
tag: 'user',
|
|
294
|
+
attrs: { jid }
|
|
295
|
+
}))
|
|
296
|
+
}
|
|
297
|
+
]
|
|
298
|
+
});
|
|
299
|
+
await parseAndInjectE2ESessions(result, signalRepository);
|
|
300
|
+
didFetchNewSession = true;
|
|
301
|
+
// Cache fetched sessions using wire JIDs
|
|
302
|
+
for (const wireJid of wireJids) {
|
|
303
|
+
const signalId = signalRepository.jidToSignalProtocolAddress(wireJid);
|
|
304
|
+
peerSessionsCache.set(signalId, true);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return didFetchNewSession;
|
|
308
|
+
};
|
|
309
|
+
const sendPeerDataOperationMessage = async (pdoMessage) => {
|
|
310
|
+
//TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
|
|
311
|
+
if (!authState.creds.me?.id) {
|
|
312
|
+
throw new Boom('Not authenticated');
|
|
313
|
+
}
|
|
314
|
+
const protocolMessage = {
|
|
315
|
+
protocolMessage: {
|
|
316
|
+
peerDataOperationRequestMessage: pdoMessage,
|
|
317
|
+
type: proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
const meJid = jidNormalizedUser(authState.creds.me.id);
|
|
321
|
+
const msgId = await relayMessage(meJid, protocolMessage, {
|
|
322
|
+
additionalAttributes: {
|
|
323
|
+
category: 'peer',
|
|
324
|
+
push_priority: 'high_force'
|
|
325
|
+
},
|
|
326
|
+
additionalNodes: [
|
|
327
|
+
{
|
|
328
|
+
tag: 'meta',
|
|
329
|
+
attrs: { appdata: 'default' }
|
|
330
|
+
}
|
|
331
|
+
]
|
|
332
|
+
});
|
|
333
|
+
return msgId;
|
|
334
|
+
};
|
|
335
|
+
const createParticipantNodes = async (recipientJids, message, extraAttrs, dsmMessage) => {
|
|
336
|
+
if (!recipientJids.length) {
|
|
337
|
+
return { nodes: [], shouldIncludeDeviceIdentity: false };
|
|
338
|
+
}
|
|
339
|
+
const patched = await patchMessageBeforeSending(message, recipientJids);
|
|
340
|
+
const patchedMessages = Array.isArray(patched)
|
|
341
|
+
? patched
|
|
342
|
+
: recipientJids.map(jid => ({ recipientJid: jid, message: patched }));
|
|
343
|
+
let shouldIncludeDeviceIdentity = false;
|
|
344
|
+
const meId = authState.creds.me.id;
|
|
345
|
+
const meLid = authState.creds.me?.lid;
|
|
346
|
+
const meLidUser = meLid ? jidDecode(meLid)?.user : null;
|
|
347
|
+
const encryptionPromises = patchedMessages.map(async ({ recipientJid: jid, message: patchedMessage }) => {
|
|
348
|
+
if (!jid)
|
|
349
|
+
return null;
|
|
350
|
+
let msgToEncrypt = patchedMessage;
|
|
351
|
+
if (dsmMessage) {
|
|
352
|
+
const { user: targetUser } = jidDecode(jid);
|
|
353
|
+
const { user: ownPnUser } = jidDecode(meId);
|
|
354
|
+
const ownLidUser = meLidUser;
|
|
355
|
+
const isOwnUser = targetUser === ownPnUser || (ownLidUser && targetUser === ownLidUser);
|
|
356
|
+
const isExactSenderDevice = jid === meId || (meLid && jid === meLid);
|
|
357
|
+
if (isOwnUser && !isExactSenderDevice) {
|
|
358
|
+
msgToEncrypt = dsmMessage;
|
|
359
|
+
logger.debug({ jid, targetUser }, 'Using DSM for own device');
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
const bytes = encodeWAMessage(msgToEncrypt);
|
|
363
|
+
const mutexKey = jid;
|
|
364
|
+
const node = await encryptionMutex.mutex(mutexKey, async () => {
|
|
365
|
+
const { type, ciphertext } = await signalRepository.encryptMessage({
|
|
366
|
+
jid,
|
|
367
|
+
data: bytes
|
|
368
|
+
});
|
|
369
|
+
if (type === 'pkmsg') {
|
|
370
|
+
shouldIncludeDeviceIdentity = true;
|
|
371
|
+
}
|
|
372
|
+
return {
|
|
373
|
+
tag: 'to',
|
|
374
|
+
attrs: { jid },
|
|
375
|
+
content: [
|
|
376
|
+
{
|
|
377
|
+
tag: 'enc',
|
|
378
|
+
attrs: {
|
|
379
|
+
v: '2',
|
|
380
|
+
type,
|
|
381
|
+
...(extraAttrs || {})
|
|
382
|
+
},
|
|
383
|
+
content: ciphertext
|
|
384
|
+
}
|
|
385
|
+
]
|
|
386
|
+
};
|
|
387
|
+
});
|
|
388
|
+
return node;
|
|
389
|
+
});
|
|
390
|
+
const nodes = (await Promise.all(encryptionPromises)).filter(node => node !== null);
|
|
391
|
+
return { nodes, shouldIncludeDeviceIdentity };
|
|
392
|
+
};
|
|
393
|
+
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }) => {
|
|
394
|
+
const meId = authState.creds.me.id;
|
|
395
|
+
const meLid = authState.creds.me?.lid;
|
|
396
|
+
const isRetryResend = Boolean(participant?.jid);
|
|
397
|
+
let shouldIncludeDeviceIdentity = isRetryResend;
|
|
398
|
+
const statusJid = 'status@broadcast';
|
|
399
|
+
const { user, server } = jidDecode(jid);
|
|
400
|
+
const isGroup = server === 'g.us';
|
|
401
|
+
const isStatus = jid === statusJid;
|
|
402
|
+
const isLid = server === 'lid';
|
|
403
|
+
const isNewsletter = server === 'newsletter';
|
|
404
|
+
const finalJid = jid;
|
|
405
|
+
msgId = msgId || generateMessageIDV2(meId);
|
|
406
|
+
useUserDevicesCache = useUserDevicesCache !== false;
|
|
407
|
+
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
|
|
408
|
+
const participants = [];
|
|
409
|
+
const destinationJid = !isStatus ? finalJid : statusJid;
|
|
410
|
+
const binaryNodeContent = [];
|
|
411
|
+
const devices = [];
|
|
412
|
+
const meMsg = {
|
|
413
|
+
deviceSentMessage: {
|
|
414
|
+
destinationJid,
|
|
415
|
+
message
|
|
416
|
+
},
|
|
417
|
+
messageContextInfo: message.messageContextInfo
|
|
418
|
+
};
|
|
419
|
+
const extraAttrs = {}
|
|
420
|
+
const regexGroupOld = /^(\d{1,15})-(\d+)@g\.us$/
|
|
421
|
+
const messages = Utils_1.normalizeMessageContent(message)
|
|
422
|
+
const buttonType = getButtonType(messages)
|
|
423
|
+
const pollMessage = messages.pollCreationMessage || messages.pollCreationMessageV2 || messages.pollCreationMessageV3
|
|
424
|
+
if (participant) {
|
|
425
|
+
if (!isGroup && !isStatus) {
|
|
426
|
+
additionalAttributes = { ...additionalAttributes, device_fanout: 'false' };
|
|
427
|
+
}
|
|
428
|
+
const { user, device } = jidDecode(participant.jid);
|
|
429
|
+
devices.push({
|
|
430
|
+
user,
|
|
431
|
+
device,
|
|
432
|
+
jid: participant.jid
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
await authState.keys.transaction(async () => {
|
|
436
|
+
const mediaType = getMediaType(message);
|
|
437
|
+
if (mediaType) {
|
|
438
|
+
extraAttrs['mediatype'] = mediaType;
|
|
439
|
+
}
|
|
440
|
+
if (isNewsletter) {
|
|
441
|
+
const patched = patchMessageBeforeSending ? await patchMessageBeforeSending(message, []) : message;
|
|
442
|
+
const bytes = encodeNewsletterMessage(patched);
|
|
443
|
+
binaryNodeContent.push({
|
|
444
|
+
tag: 'plaintext',
|
|
445
|
+
attrs: {},
|
|
446
|
+
content: bytes
|
|
447
|
+
});
|
|
448
|
+
const stanza = {
|
|
449
|
+
tag: 'message',
|
|
450
|
+
attrs: {
|
|
451
|
+
to: jid,
|
|
452
|
+
id: msgId,
|
|
453
|
+
type: getMessageType(message),
|
|
454
|
+
...(additionalAttributes || {})
|
|
455
|
+
},
|
|
456
|
+
content: binaryNodeContent
|
|
457
|
+
};
|
|
458
|
+
logger.debug({ msgId }, `sending newsletter message to ${jid}`);
|
|
459
|
+
await sendNode(stanza);
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
if (normalizeMessageContent(message)?.pinInChatMessage) {
|
|
463
|
+
extraAttrs['decrypt-fail'] = 'hide'; // todo: expand for reactions and other types
|
|
464
|
+
}
|
|
465
|
+
if (isGroup || isStatus) {
|
|
466
|
+
const [groupData, senderKeyMap] = await Promise.all([
|
|
467
|
+
(async () => {
|
|
468
|
+
let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined; // todo: should we rely on the cache specially if the cache is outdated and the metadata has new fields?
|
|
469
|
+
if (groupData && Array.isArray(groupData?.participants)) {
|
|
470
|
+
logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
|
|
471
|
+
}
|
|
472
|
+
else if (!isStatus) {
|
|
473
|
+
groupData = await groupMetadata(jid); // TODO: start storing group participant list + addr mode in Signal & stop relying on this
|
|
474
|
+
}
|
|
475
|
+
return groupData;
|
|
476
|
+
})(),
|
|
477
|
+
(async () => {
|
|
478
|
+
if (!participant && !isStatus) {
|
|
479
|
+
// what if sender memory is less accurate than the cached metadata
|
|
480
|
+
// on participant change in group, we should do sender memory manipulation
|
|
481
|
+
const result = await authState.keys.get('sender-key-memory', [jid]); // TODO: check out what if the sender key memory doesn't include the LID stuff now?
|
|
482
|
+
return result[jid] || {};
|
|
483
|
+
}
|
|
484
|
+
return {};
|
|
485
|
+
})()
|
|
486
|
+
]);
|
|
487
|
+
if (!participant) {
|
|
488
|
+
const participantsList = [];
|
|
489
|
+
if (isStatus) {
|
|
490
|
+
if (statusJidList?.length)
|
|
491
|
+
participantsList.push(...statusJidList);
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
// default to LID based groups
|
|
495
|
+
let groupAddressingMode = 'lid';
|
|
496
|
+
if (groupData) {
|
|
497
|
+
participantsList.push(...groupData.participants.map(p => p.id));
|
|
498
|
+
groupAddressingMode = groupData?.addressingMode || groupAddressingMode;
|
|
499
|
+
}
|
|
500
|
+
// default to lid addressing mode in a group
|
|
501
|
+
additionalAttributes = {
|
|
502
|
+
...additionalAttributes,
|
|
503
|
+
addressing_mode: groupAddressingMode
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
|
|
507
|
+
devices.push(...additionalDevices);
|
|
508
|
+
}
|
|
509
|
+
if (groupData?.ephemeralDuration && groupData.ephemeralDuration > 0) {
|
|
510
|
+
additionalAttributes = {
|
|
511
|
+
...additionalAttributes,
|
|
512
|
+
expiration: groupData.ephemeralDuration.toString()
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
const patched = await patchMessageBeforeSending(message);
|
|
516
|
+
if (Array.isArray(patched)) {
|
|
517
|
+
throw new Boom('Per-jid patching is not supported in groups');
|
|
518
|
+
}
|
|
519
|
+
const bytes = encodeWAMessage(patched);
|
|
520
|
+
const groupAddressingMode = additionalAttributes?.['addressing_mode'] || groupData?.addressingMode || 'lid';
|
|
521
|
+
const groupSenderIdentity = groupAddressingMode === 'lid' && meLid ? meLid : meId;
|
|
522
|
+
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
|
|
523
|
+
group: destinationJid,
|
|
524
|
+
data: bytes,
|
|
525
|
+
meId: groupSenderIdentity
|
|
526
|
+
});
|
|
527
|
+
const senderKeyRecipients = [];
|
|
528
|
+
for (const device of devices) {
|
|
529
|
+
const deviceJid = device.jid;
|
|
530
|
+
const hasKey = !!senderKeyMap[deviceJid];
|
|
531
|
+
if ((!hasKey || !!participant) &&
|
|
532
|
+
!isHostedLidUser(deviceJid) &&
|
|
533
|
+
!isHostedPnUser(deviceJid) &&
|
|
534
|
+
device.device !== 99) {
|
|
535
|
+
//todo: revamp all this logic
|
|
536
|
+
// the goal is to follow with what I said above for each group, and instead of a true false map of ids, we can set an array full of those the app has already sent pkmsgs
|
|
537
|
+
senderKeyRecipients.push(deviceJid);
|
|
538
|
+
senderKeyMap[deviceJid] = true;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
if (senderKeyRecipients.length) {
|
|
542
|
+
logger.debug({ senderKeyJids: senderKeyRecipients }, 'sending new sender key');
|
|
543
|
+
const senderKeyMsg = {
|
|
544
|
+
senderKeyDistributionMessage: {
|
|
545
|
+
axolotlSenderKeyDistributionMessage: senderKeyDistributionMessage,
|
|
546
|
+
groupId: destinationJid
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
const senderKeySessionTargets = senderKeyRecipients;
|
|
550
|
+
await assertSessions(senderKeySessionTargets);
|
|
551
|
+
const result = await createParticipantNodes(senderKeyRecipients, senderKeyMsg, extraAttrs);
|
|
552
|
+
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
|
|
553
|
+
participants.push(...result.nodes);
|
|
554
|
+
}
|
|
555
|
+
if (isRetryResend) {
|
|
556
|
+
const { type, ciphertext: encryptedContent } = await signalRepository.encryptMessage({
|
|
557
|
+
data: bytes,
|
|
558
|
+
jid: participant?.jid
|
|
559
|
+
});
|
|
560
|
+
binaryNodeContent.push({
|
|
561
|
+
tag: 'enc',
|
|
562
|
+
attrs: {
|
|
563
|
+
v: '2',
|
|
564
|
+
type,
|
|
565
|
+
count: participant.count.toString()
|
|
566
|
+
},
|
|
567
|
+
content: encryptedContent
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
else {
|
|
571
|
+
binaryNodeContent.push({
|
|
572
|
+
tag: 'enc',
|
|
573
|
+
attrs: { v: '2', type: 'skmsg', ...extraAttrs },
|
|
574
|
+
content: ciphertext
|
|
575
|
+
});
|
|
576
|
+
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
else {
|
|
580
|
+
// ADDRESSING CONSISTENCY: Match own identity to conversation context
|
|
581
|
+
// TODO: investigate if this is true
|
|
582
|
+
let ownId = meId;
|
|
583
|
+
if (isLid && meLid) {
|
|
584
|
+
ownId = meLid;
|
|
585
|
+
logger.debug({ to: jid, ownId }, 'Using LID identity for @lid conversation');
|
|
586
|
+
}
|
|
587
|
+
else {
|
|
588
|
+
logger.debug({ to: jid, ownId }, 'Using PN identity for @s.whatsapp.net conversation');
|
|
589
|
+
}
|
|
590
|
+
const { user: ownUser } = jidDecode(ownId);
|
|
591
|
+
if (!participant) {
|
|
592
|
+
const targetUserServer = isLid ? 'lid' : 's.whatsapp.net';
|
|
593
|
+
devices.push({
|
|
594
|
+
user,
|
|
595
|
+
device: 0,
|
|
596
|
+
jid: jidEncode(user, targetUserServer, 0) // rajeh, todo: this entire logic is convoluted and weird.
|
|
597
|
+
});
|
|
598
|
+
if (user !== ownUser) {
|
|
599
|
+
const ownUserServer = isLid ? 'lid' : 's.whatsapp.net';
|
|
600
|
+
const ownUserForAddressing = isLid && meLid ? jidDecode(meLid).user : jidDecode(meId).user;
|
|
601
|
+
devices.push({
|
|
602
|
+
user: ownUserForAddressing,
|
|
603
|
+
device: 0,
|
|
604
|
+
jid: jidEncode(ownUserForAddressing, ownUserServer, 0)
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
if (additionalAttributes?.['category'] !== 'peer') {
|
|
608
|
+
// Clear placeholders and enumerate actual devices
|
|
609
|
+
devices.length = 0;
|
|
610
|
+
// Use conversation-appropriate sender identity
|
|
611
|
+
const senderIdentity = isLid && meLid
|
|
612
|
+
? jidEncode(jidDecode(meLid)?.user, 'lid', undefined)
|
|
613
|
+
: jidEncode(jidDecode(meId)?.user, 's.whatsapp.net', undefined);
|
|
614
|
+
// Enumerate devices for sender and target with consistent addressing
|
|
615
|
+
const sessionDevices = await getUSyncDevices([senderIdentity, jid], true, false);
|
|
616
|
+
devices.push(...sessionDevices);
|
|
617
|
+
logger.debug({
|
|
618
|
+
deviceCount: devices.length,
|
|
619
|
+
devices: devices.map(d => `${d.user}:${d.device}@${jidDecode(d.jid)?.server}`)
|
|
620
|
+
}, 'Device enumeration complete with unified addressing');
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
const allRecipients = [];
|
|
624
|
+
const meRecipients = [];
|
|
625
|
+
const otherRecipients = [];
|
|
626
|
+
const { user: mePnUser } = jidDecode(meId);
|
|
627
|
+
const { user: meLidUser } = meLid ? jidDecode(meLid) : { user: null };
|
|
628
|
+
for (const { user, jid } of devices) {
|
|
629
|
+
const isExactSenderDevice = jid === meId || (meLid && jid === meLid);
|
|
630
|
+
if (isExactSenderDevice) {
|
|
631
|
+
logger.debug({ jid, meId, meLid }, 'Skipping exact sender device (whatsmeow pattern)');
|
|
632
|
+
continue;
|
|
633
|
+
}
|
|
634
|
+
// Check if this is our device (could match either PN or LID user)
|
|
635
|
+
const isMe = user === mePnUser || user === meLidUser;
|
|
636
|
+
if (isMe) {
|
|
637
|
+
meRecipients.push(jid);
|
|
638
|
+
}
|
|
639
|
+
else {
|
|
640
|
+
otherRecipients.push(jid);
|
|
641
|
+
}
|
|
642
|
+
allRecipients.push(jid);
|
|
643
|
+
}
|
|
644
|
+
await assertSessions(allRecipients);
|
|
645
|
+
const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
|
|
646
|
+
// For own devices: use DSM if available (1:1 chats only)
|
|
647
|
+
createParticipantNodes(meRecipients, meMsg || message, extraAttrs),
|
|
648
|
+
createParticipantNodes(otherRecipients, message, extraAttrs, meMsg)
|
|
649
|
+
]);
|
|
650
|
+
participants.push(...meNodes);
|
|
651
|
+
participants.push(...otherNodes);
|
|
652
|
+
if (meRecipients.length > 0 || otherRecipients.length > 0) {
|
|
653
|
+
extraAttrs['phash'] = generateParticipantHashV2([...meRecipients, ...otherRecipients]);
|
|
654
|
+
}
|
|
655
|
+
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
|
|
656
|
+
}
|
|
657
|
+
if (participants.length) {
|
|
658
|
+
if (additionalAttributes?.['category'] === 'peer') {
|
|
659
|
+
const peerNode = participants[0]?.content?.[0];
|
|
660
|
+
if (peerNode) {
|
|
661
|
+
binaryNodeContent.push(peerNode); // push only enc
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
else {
|
|
665
|
+
binaryNodeContent.push({
|
|
666
|
+
tag: 'participants',
|
|
667
|
+
attrs: {},
|
|
668
|
+
content: participants
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
const stanza = {
|
|
673
|
+
tag: 'message',
|
|
674
|
+
attrs: {
|
|
675
|
+
id: msgId,
|
|
676
|
+
to: destinationJid,
|
|
677
|
+
type: getMessageType(message),
|
|
678
|
+
...(additionalAttributes || {})
|
|
679
|
+
},
|
|
680
|
+
content: binaryNodeContent
|
|
681
|
+
};
|
|
682
|
+
// if the participant to send to is explicitly specified (generally retry recp)
|
|
683
|
+
// ensure the message is only sent to that person
|
|
684
|
+
// if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
|
|
685
|
+
if (participant) {
|
|
686
|
+
if (isJidGroup(destinationJid)) {
|
|
687
|
+
stanza.attrs.to = destinationJid;
|
|
688
|
+
stanza.attrs.participant = participant.jid;
|
|
689
|
+
}
|
|
690
|
+
else if (areJidsSameUser(participant.jid, meId)) {
|
|
691
|
+
stanza.attrs.to = participant.jid;
|
|
692
|
+
stanza.attrs.recipient = destinationJid;
|
|
693
|
+
}
|
|
694
|
+
else {
|
|
695
|
+
stanza.attrs.to = participant.jid;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
else {
|
|
699
|
+
stanza.attrs.to = destinationJid;
|
|
700
|
+
}
|
|
701
|
+
if (!isNewsletter && buttonType) {
|
|
702
|
+
const buttonsNode = getButtonArgs(messages)
|
|
703
|
+
const filteredButtons = WABinary_1.getBinaryFilteredButtons(additionalNodes ? additionalNodes : [])
|
|
704
|
+
if (filteredButtons) {
|
|
705
|
+
stanza.content.push(...additionalNodes)
|
|
706
|
+
additionalAlready = true
|
|
707
|
+
} else {
|
|
708
|
+
stanza.content.push(buttonsNode)
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
if (shouldIncludeDeviceIdentity) {
|
|
712
|
+
;
|
|
713
|
+
stanza.content.push({
|
|
714
|
+
tag: 'device-identity',
|
|
715
|
+
attrs: {},
|
|
716
|
+
content: encodeSignedDeviceIdentity(authState.creds.account, true)
|
|
717
|
+
});
|
|
718
|
+
logger.debug({ jid }, 'adding device identity');
|
|
719
|
+
}
|
|
720
|
+
if (additionalNodes && additionalNodes.length > 0) {
|
|
721
|
+
;
|
|
722
|
+
stanza.content.push(...additionalNodes);
|
|
723
|
+
}
|
|
724
|
+
logger.debug({ msgId }, `sending message to ${participants.length} devices`);
|
|
725
|
+
await sendNode(stanza);
|
|
726
|
+
// Add message to retry cache if enabled
|
|
727
|
+
if (messageRetryManager && !participant) {
|
|
728
|
+
messageRetryManager.addRecentMessage(destinationJid, msgId, message);
|
|
729
|
+
}
|
|
730
|
+
}, meId);
|
|
731
|
+
return msgId;
|
|
732
|
+
};
|
|
733
|
+
const getMessageType = (msg) => {
|
|
734
|
+
const message = Utils_1.normalizeMessageContent(msg)
|
|
735
|
+
if (message.pollCreationMessage || message.pollCreationMessageV2 || message.pollCreationMessageV3) {
|
|
736
|
+
return 'poll'
|
|
737
|
+
} else if (message.reactionMessage) {
|
|
738
|
+
return 'reaction'
|
|
739
|
+
} else if (message.eventMessage) {
|
|
740
|
+
return 'event'
|
|
741
|
+
} else if (getMediaType(message)) {
|
|
742
|
+
return 'media'
|
|
743
|
+
} else {
|
|
744
|
+
return 'text'
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
const getMediaType = (message) => {
|
|
749
|
+
if (message.imageMessage) {
|
|
750
|
+
return 'image'
|
|
751
|
+
} else if (message.stickerMessage) {
|
|
752
|
+
return message.stickerMessage.isLottie ? '1p_sticker' : message.stickerMessage.isAvatar ? 'avatar_sticker' : 'sticker'
|
|
753
|
+
} else if (message.videoMessage) {
|
|
754
|
+
return message.videoMessage.gifPlayback ? 'gif' : 'video'
|
|
755
|
+
} else if (message.audioMessage) {
|
|
756
|
+
return message.audioMessage.ptt ? 'ptt' : 'audio'
|
|
757
|
+
} else if (message.ptvMessage) {
|
|
758
|
+
return 'ptv'
|
|
759
|
+
} else if (message.albumMessage) {
|
|
760
|
+
return 'collection'
|
|
761
|
+
} else if (message.contactMessage) {
|
|
762
|
+
return 'vcard'
|
|
763
|
+
} else if (message.documentMessage) {
|
|
764
|
+
return 'document'
|
|
765
|
+
} else if (message.stickerPackMessage) {
|
|
766
|
+
return 'sticker_pack'
|
|
767
|
+
} else if (message.contactsArrayMessage) {
|
|
768
|
+
return 'contact_array'
|
|
769
|
+
} else if (message.locationMessage) {
|
|
770
|
+
return 'location'
|
|
771
|
+
} else if (message.liveLocationMessage) {
|
|
772
|
+
return 'livelocation'
|
|
773
|
+
} else if (message.listMessage) {
|
|
774
|
+
return 'list'
|
|
775
|
+
} else if (message.listResponseMessage) {
|
|
776
|
+
return 'list_response'
|
|
777
|
+
} else if (message.buttonsResponseMessage) {
|
|
778
|
+
return 'buttons_response'
|
|
779
|
+
} else if (message.orderMessage) {
|
|
780
|
+
return 'order'
|
|
781
|
+
} else if (message.productMessage) {
|
|
782
|
+
return 'product'
|
|
783
|
+
} else if (message.interactiveResponseMessage) {
|
|
784
|
+
return 'native_flow_response'
|
|
785
|
+
} else if (/https:\/\/wa\.me\/c\/\d+/.test(message.extendedTextMessage?.text)) {
|
|
786
|
+
return 'cataloglink'
|
|
787
|
+
} else if (/https:\/\/wa\.me\/p\/\d+\/\d+/.test(message.extendedTextMessage?.text)) {
|
|
788
|
+
return 'productlink'
|
|
789
|
+
} else if (message.extendedTextMessage?.matchedText || message.groupInviteMessage) {
|
|
790
|
+
return 'url'
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
const getButtonType = (message) => {
|
|
795
|
+
if (message.listMessage) {
|
|
796
|
+
return 'list'
|
|
797
|
+
}
|
|
798
|
+
else if (message.buttonsMessage) {
|
|
799
|
+
return 'buttons'
|
|
800
|
+
}
|
|
801
|
+
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'review_and_pay') {
|
|
802
|
+
return 'review_and_pay'
|
|
803
|
+
}
|
|
804
|
+
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'review_order') {
|
|
805
|
+
return 'review_order'
|
|
806
|
+
}
|
|
807
|
+
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_info') {
|
|
808
|
+
return 'payment_info'
|
|
809
|
+
}
|
|
810
|
+
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_status') {
|
|
811
|
+
return 'payment_status'
|
|
812
|
+
}
|
|
813
|
+
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_method') {
|
|
814
|
+
return 'payment_method'
|
|
815
|
+
}
|
|
816
|
+
else if (message.interactiveMessage && message.interactiveMessage?.nativeFlowMessage) {
|
|
817
|
+
return 'interactive'
|
|
818
|
+
}
|
|
819
|
+
else if (message.interactiveMessage?.nativeFlowMessage) {
|
|
820
|
+
return 'native_flow'
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
const getButtonArgs = (message) => {
|
|
825
|
+
const message_content = message.viewOnceMessage?.message || message;
|
|
826
|
+
const message_flow = message_content.interactiveMessage?.nativeFlowMessage;
|
|
827
|
+
const flow_buttons_first = message_flow?.buttons?.[0]?.name;
|
|
828
|
+
const flow_buttons_special = [ 'mpm', 'cta_catalog', 'send_location', 'call_permission_request', 'wa_payment_transaction_details', 'automated_greeting_message_view_catalog' ];
|
|
829
|
+
const baseArgs = {
|
|
830
|
+
tag: 'biz',
|
|
831
|
+
attrs: {
|
|
832
|
+
actual_actors: '2',
|
|
833
|
+
host_storage: '2',
|
|
834
|
+
privacy_mode_ts: Utils_1.unixTimestampSeconds().toString()
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
if (message_flow && (flow_buttons_first === 'review_and_pay' || flow_buttons_first === 'payment_info')) {
|
|
838
|
+
return {
|
|
839
|
+
tag: 'biz',
|
|
840
|
+
attrs: {
|
|
841
|
+
native_flow_name: flow_buttons_first === 'review_and_pay' ? 'order_details' : flow_buttons_first
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
if (message_flow && flow_buttons_special.includes(flow_buttons_first)) {
|
|
846
|
+
return {
|
|
847
|
+
...baseArgs,
|
|
848
|
+
content: [
|
|
849
|
+
{
|
|
850
|
+
tag: 'interactive',
|
|
851
|
+
attrs: { type: 'native_flow', v: '1' },
|
|
852
|
+
content: [{
|
|
853
|
+
tag: 'native_flow',
|
|
854
|
+
attrs: { v: '2', name: flow_buttons_first }
|
|
855
|
+
}]
|
|
856
|
+
},
|
|
857
|
+
{
|
|
858
|
+
tag: 'quality_control',
|
|
859
|
+
attrs: { source_type: 'third_party' }
|
|
860
|
+
}
|
|
861
|
+
]
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
if (message_flow || message_content.buttonsMessage) {
|
|
865
|
+
return {
|
|
866
|
+
...baseArgs,
|
|
867
|
+
content: [
|
|
868
|
+
{
|
|
869
|
+
tag: 'interactive',
|
|
870
|
+
attrs: { type: 'native_flow', v: '1' },
|
|
871
|
+
content: [{
|
|
872
|
+
tag: 'native_flow',
|
|
873
|
+
attrs: { v: '9', name: 'mixed' }
|
|
874
|
+
}]
|
|
875
|
+
},
|
|
876
|
+
{
|
|
877
|
+
tag: 'quality_control',
|
|
878
|
+
attrs: { source_type: 'third_party' }
|
|
879
|
+
}
|
|
880
|
+
]
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
if (message_content.listMessage) {
|
|
884
|
+
return {
|
|
885
|
+
...baseArgs,
|
|
886
|
+
content: [
|
|
887
|
+
{
|
|
888
|
+
tag: 'list',
|
|
889
|
+
attrs: { v: '2', type: 'product_list' }
|
|
890
|
+
},
|
|
891
|
+
{
|
|
892
|
+
tag: 'quality_control',
|
|
893
|
+
attrs: { source_type: 'third_party' }
|
|
894
|
+
}
|
|
895
|
+
]
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
return baseArgs;
|
|
899
|
+
};
|
|
900
|
+
|
|
901
|
+
const getPrivacyTokens = async (jids) => {
|
|
902
|
+
const t = Utils_1.unixTimestampSeconds().toString()
|
|
903
|
+
|
|
904
|
+
const result = await query({
|
|
905
|
+
tag: 'iq',
|
|
906
|
+
attrs: {
|
|
907
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
908
|
+
type: 'set',
|
|
909
|
+
xmlns: 'privacy'
|
|
910
|
+
},
|
|
911
|
+
content: [{
|
|
912
|
+
tag: 'tokens',
|
|
913
|
+
attrs: {},
|
|
914
|
+
content: jids.map(jid => ({
|
|
915
|
+
tag: 'token',
|
|
916
|
+
attrs: {
|
|
917
|
+
jid: WABinary_1.jidNormalizedUser(jid),
|
|
918
|
+
t,
|
|
919
|
+
type: 'trusted_contact'
|
|
920
|
+
}
|
|
921
|
+
}))
|
|
922
|
+
}]
|
|
923
|
+
})
|
|
924
|
+
|
|
925
|
+
return result
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
const getEphemeralGroup = (jid) => {
|
|
929
|
+
if (!WABinary_1.isJidGroup(jid)) throw new TypeError("Jid should originate from a group!")
|
|
930
|
+
|
|
931
|
+
return groupQuery(jid, 'get', [{
|
|
932
|
+
tag: 'query',
|
|
933
|
+
attrs: {
|
|
934
|
+
request: 'interactive'
|
|
935
|
+
}
|
|
936
|
+
}])
|
|
937
|
+
.then((groups) => WABinary_1.getBinaryNodeChild(groups, 'group'))
|
|
938
|
+
.then((metadata) => WABinary_1.getBinaryNodeChild(metadata, 'ephemeral')?.attrs?.expiration || 0)
|
|
939
|
+
}
|
|
940
|
+
const waUploadToServer = getWAUploadToServer(config, refreshMediaConn);
|
|
941
|
+
const kelvdra = new hydra(Utils_1, waUploadToServer, relayMessage)
|
|
942
|
+
const waitForMsgMediaUpdate = bindWaitForEvent(ev, 'messages.media-update');
|
|
943
|
+
return {
|
|
944
|
+
...sock,
|
|
945
|
+
getPrivacyTokens,
|
|
946
|
+
assertSessions,
|
|
947
|
+
relayMessage,
|
|
948
|
+
sendReceipt,
|
|
949
|
+
sendReceipts,
|
|
950
|
+
kelvdra,
|
|
951
|
+
readMessages,
|
|
952
|
+
refreshMediaConn,
|
|
953
|
+
waUploadToServer,
|
|
954
|
+
fetchPrivacySettings,
|
|
955
|
+
sendPeerDataOperationMessage,
|
|
956
|
+
createParticipantNodes,
|
|
957
|
+
getUSyncDevices,
|
|
958
|
+
messageRetryManager,
|
|
959
|
+
updateMediaMessage: async (message) => {
|
|
960
|
+
const content = assertMediaContent(message.message);
|
|
961
|
+
const mediaKey = content.mediaKey;
|
|
962
|
+
const meId = authState.creds.me.id;
|
|
963
|
+
const node = await encryptMediaRetryRequest(message.key, mediaKey, meId);
|
|
964
|
+
let error = undefined;
|
|
965
|
+
await Promise.all([
|
|
966
|
+
sendNode(node),
|
|
967
|
+
waitForMsgMediaUpdate(async (update) => {
|
|
968
|
+
const result = update.find(c => c.key.id === message.key.id);
|
|
969
|
+
if (result) {
|
|
970
|
+
if (result.error) {
|
|
971
|
+
error = result.error;
|
|
972
|
+
}
|
|
973
|
+
else {
|
|
974
|
+
try {
|
|
975
|
+
const media = await decryptMediaRetryData(result.media, mediaKey, result.key.id);
|
|
976
|
+
if (media.result !== proto.MediaRetryNotification.ResultType.SUCCESS) {
|
|
977
|
+
const resultStr = proto.MediaRetryNotification.ResultType[media.result];
|
|
978
|
+
throw new Boom(`Media re-upload failed by device (${resultStr})`, {
|
|
979
|
+
data: media,
|
|
980
|
+
statusCode: getStatusCodeForMediaRetry(media.result) || 404
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
content.directPath = media.directPath;
|
|
984
|
+
content.url = getUrlFromDirectPath(content.directPath);
|
|
985
|
+
logger.debug({ directPath: media.directPath, key: result.key }, 'media update successful');
|
|
986
|
+
}
|
|
987
|
+
catch (err) {
|
|
988
|
+
error = err;
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
return true;
|
|
992
|
+
}
|
|
993
|
+
})
|
|
994
|
+
]);
|
|
995
|
+
if (error) {
|
|
996
|
+
throw error;
|
|
997
|
+
}
|
|
998
|
+
ev.emit('messages.update', [{ key: message.key, update: { message: message.message } }]);
|
|
999
|
+
return message;
|
|
1000
|
+
},
|
|
1001
|
+
sendStatusMentions: async (content, jids = []) => {
|
|
1002
|
+
const userJid = WABinary_1.jidNormalizedUser(authState.creds.me.id)
|
|
1003
|
+
let allUsers = new Set()
|
|
1004
|
+
allUsers.add(userJid)
|
|
1005
|
+
|
|
1006
|
+
for (const id of jids) {
|
|
1007
|
+
const isGroup = WABinary_1.isJidGroup(id)
|
|
1008
|
+
const isPrivate = WABinary_1.isJidUser(id)
|
|
1009
|
+
|
|
1010
|
+
if (isGroup) {
|
|
1011
|
+
try {
|
|
1012
|
+
const metadata = await cachedGroupMetadata(id) || await global.groupMetadataCache(id)
|
|
1013
|
+
const participants = metadata.participants.map(p => WABinary_1.jidNormalizedUser(p.id))
|
|
1014
|
+
participants.forEach(jid => allUsers.add(jid))
|
|
1015
|
+
} catch (error) {
|
|
1016
|
+
logger.error(`Error getting metadata for group ${id}: ${error}`)
|
|
1017
|
+
}
|
|
1018
|
+
} else if (isPrivate) {
|
|
1019
|
+
allUsers.add(WABinary_1.jidNormalizedUser(id))
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
const uniqueUsers = Array.from(allUsers)
|
|
1024
|
+
const getRandomHexColor = () => "#" + Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0")
|
|
1025
|
+
|
|
1026
|
+
const isMedia = content.image || content.video || content.audio
|
|
1027
|
+
const isAudio = !!content.audio
|
|
1028
|
+
|
|
1029
|
+
const messageContent = {
|
|
1030
|
+
...content
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
if (isMedia && !isAudio) {
|
|
1034
|
+
if (messageContent.text) {
|
|
1035
|
+
messageContent.caption = messageContent.text
|
|
1036
|
+
|
|
1037
|
+
delete messageContent.text
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
delete messageContent.ptt
|
|
1041
|
+
delete messageContent.font
|
|
1042
|
+
delete messageContent.backgroundColor
|
|
1043
|
+
delete messageContent.textColor
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
if (isAudio) {
|
|
1047
|
+
delete messageContent.text
|
|
1048
|
+
delete messageContent.caption
|
|
1049
|
+
delete messageContent.font
|
|
1050
|
+
delete messageContent.textColor
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
const font = !isMedia ? (content.font || Math.floor(Math.random() * 9)) : undefined
|
|
1054
|
+
const textColor = !isMedia ? (content.textColor || getRandomHexColor()) : undefined
|
|
1055
|
+
const backgroundColor = (!isMedia || isAudio) ? (content.backgroundColor || getRandomHexColor()) : undefined
|
|
1056
|
+
const ptt = isAudio ? (typeof content.ptt === 'boolean' ? content.ptt : true) : undefined
|
|
1057
|
+
|
|
1058
|
+
let msg
|
|
1059
|
+
let mediaHandle
|
|
1060
|
+
try {
|
|
1061
|
+
msg = await Utils_1.generateWAMessage(WABinary_1.STORIES_JID, messageContent, {
|
|
1062
|
+
logger,
|
|
1063
|
+
userJid,
|
|
1064
|
+
getUrlInfo: text => link_preview_1.getUrlInfo(text, {
|
|
1065
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
1066
|
+
fetchOpts: {
|
|
1067
|
+
timeout: 3000,
|
|
1068
|
+
...axiosOptions || {}
|
|
1069
|
+
},
|
|
1070
|
+
logger,
|
|
1071
|
+
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
1072
|
+
}),
|
|
1073
|
+
upload: async (encFilePath, opts) => {
|
|
1074
|
+
const up = await waUploadToServer(encFilePath, {
|
|
1075
|
+
...opts
|
|
1076
|
+
})
|
|
1077
|
+
mediaHandle = up.handle
|
|
1078
|
+
return up
|
|
1079
|
+
},
|
|
1080
|
+
mediaCache: config.mediaCache,
|
|
1081
|
+
options: config.options,
|
|
1082
|
+
font,
|
|
1083
|
+
textColor,
|
|
1084
|
+
backgroundColor,
|
|
1085
|
+
ptt
|
|
1086
|
+
})
|
|
1087
|
+
} catch (error) {
|
|
1088
|
+
logger.error(`Error generating message: ${error}`)
|
|
1089
|
+
throw error
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
await relayMessage(WABinary_1.STORIES_JID, msg.message, {
|
|
1093
|
+
messageId: msg.key.id,
|
|
1094
|
+
statusJidList: uniqueUsers,
|
|
1095
|
+
additionalNodes: [{
|
|
1096
|
+
tag: 'meta',
|
|
1097
|
+
attrs: {},
|
|
1098
|
+
content: [{
|
|
1099
|
+
tag: 'mentioned_users',
|
|
1100
|
+
attrs: {},
|
|
1101
|
+
content: jids.map(jid => ({
|
|
1102
|
+
tag: 'to',
|
|
1103
|
+
attrs: {
|
|
1104
|
+
jid: WABinary_1.jidNormalizedUser(jid)
|
|
1105
|
+
}
|
|
1106
|
+
}))
|
|
1107
|
+
}]
|
|
1108
|
+
}]
|
|
1109
|
+
})
|
|
1110
|
+
|
|
1111
|
+
for (const id of jids) {
|
|
1112
|
+
try {
|
|
1113
|
+
const normalizedId = WABinary_1.jidNormalizedUser(id)
|
|
1114
|
+
const isPrivate = WABinary_1.isJidUser(normalizedId)
|
|
1115
|
+
const type = isPrivate ? 'statusMentionMessage' : 'groupStatusMentionMessage'
|
|
1116
|
+
|
|
1117
|
+
const protocolMessage = {
|
|
1118
|
+
[type]: {
|
|
1119
|
+
message: {
|
|
1120
|
+
protocolMessage: {
|
|
1121
|
+
key: msg.key,
|
|
1122
|
+
type: 25
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
},
|
|
1126
|
+
messageContextInfo: {
|
|
1127
|
+
messageSecret: crypto_1.randomBytes(32)
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
const statusMsg = await Utils_1.generateWAMessageFromContent(normalizedId,
|
|
1132
|
+
protocolMessage, {}
|
|
1133
|
+
)
|
|
1134
|
+
|
|
1135
|
+
await relayMessage(
|
|
1136
|
+
normalizedId,
|
|
1137
|
+
statusMsg.message, {
|
|
1138
|
+
additionalNodes: [{
|
|
1139
|
+
tag: 'meta',
|
|
1140
|
+
attrs: isPrivate ? {
|
|
1141
|
+
is_status_mention: 'true'
|
|
1142
|
+
} : {
|
|
1143
|
+
is_group_status_mention: 'true'
|
|
1144
|
+
}
|
|
1145
|
+
}]
|
|
1146
|
+
}
|
|
1147
|
+
)
|
|
1148
|
+
|
|
1149
|
+
await Utils_1.delay(2000)
|
|
1150
|
+
} catch (error) {
|
|
1151
|
+
logger.error(`Error sending to ${id}: ${error}`)
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
return msg
|
|
1156
|
+
},
|
|
1157
|
+
sendAlbumMessage: async (jid, medias, options = {}) => {
|
|
1158
|
+
const userJid = authState.creds.me.id
|
|
1159
|
+
for (const media of medias) {
|
|
1160
|
+
if (!media.image && !media.video) throw new TypeError(`medias[i] must have image or video property`)
|
|
1161
|
+
}
|
|
1162
|
+
if (medias.length < 2) throw new RangeError("Minimum 2 media")
|
|
1163
|
+
const time = options.delay || 500
|
|
1164
|
+
delete options.delay
|
|
1165
|
+
const album = await Utils_1.generateWAMessageFromContent(jid, {
|
|
1166
|
+
albumMessage: {
|
|
1167
|
+
expectedImageCount: medias.filter(media => media.image).length,
|
|
1168
|
+
expectedVideoCount: medias.filter(media => media.video).length,
|
|
1169
|
+
...options
|
|
1170
|
+
}
|
|
1171
|
+
}, {
|
|
1172
|
+
userJid,
|
|
1173
|
+
...options
|
|
1174
|
+
})
|
|
1175
|
+
await relayMessage(jid, album.message, {
|
|
1176
|
+
messageId: album.key.id
|
|
1177
|
+
})
|
|
1178
|
+
let mediaHandle
|
|
1179
|
+
let msg
|
|
1180
|
+
for (const i in medias) {
|
|
1181
|
+
const media = medias[i]
|
|
1182
|
+
if (media.image) {
|
|
1183
|
+
msg = await Utils_1.generateWAMessage(jid, {
|
|
1184
|
+
image: media.image,
|
|
1185
|
+
...media,
|
|
1186
|
+
...options
|
|
1187
|
+
}, {
|
|
1188
|
+
userJid,
|
|
1189
|
+
upload: async (readStream, opts) => {
|
|
1190
|
+
const up = await waUploadToServer(readStream, {
|
|
1191
|
+
...opts,
|
|
1192
|
+
newsletter: WABinary_1.isJidNewsletter(jid)
|
|
1193
|
+
})
|
|
1194
|
+
mediaHandle = up.handle
|
|
1195
|
+
return up
|
|
1196
|
+
},
|
|
1197
|
+
...options
|
|
1198
|
+
})
|
|
1199
|
+
} else if (media.video) {
|
|
1200
|
+
msg = await Utils_1.generateWAMessage(jid, {
|
|
1201
|
+
video: media.video,
|
|
1202
|
+
...media,
|
|
1203
|
+
...options
|
|
1204
|
+
}, {
|
|
1205
|
+
userJid,
|
|
1206
|
+
upload: async (readStream, opts) => {
|
|
1207
|
+
const up = await waUploadToServer(readStream, {
|
|
1208
|
+
...opts,
|
|
1209
|
+
newsletter: WABinary_1.isJidNewsletter(jid)
|
|
1210
|
+
})
|
|
1211
|
+
mediaHandle = up.handle
|
|
1212
|
+
return up
|
|
1213
|
+
},
|
|
1214
|
+
...options,
|
|
1215
|
+
})
|
|
1216
|
+
}
|
|
1217
|
+
if (msg) {
|
|
1218
|
+
msg.message.messageContextInfo = {
|
|
1219
|
+
messageSecret: crypto_1.randomBytes(32),
|
|
1220
|
+
messageAssociation: {
|
|
1221
|
+
associationType: 1,
|
|
1222
|
+
parentMessageKey: album.key
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
await relayMessage(jid, msg.message, {
|
|
1227
|
+
messageId: msg.key.id
|
|
1228
|
+
})
|
|
1229
|
+
await Utils_1.delay(time)
|
|
1230
|
+
}
|
|
1231
|
+
return album
|
|
1232
|
+
},
|
|
1233
|
+
sendMessage: async (jid, content, options = {}) => {
|
|
1234
|
+
const userJid = authState.creds.me.id
|
|
1235
|
+
const additionalAttributes = {}
|
|
1236
|
+
const { filter = false, quoted } = options;
|
|
1237
|
+
const getParticipantAttr = () => filter ? { participant: { jid } } : {};
|
|
1238
|
+
const messageType = kelvdra.detectType(content);
|
|
1239
|
+
if (messageType) {
|
|
1240
|
+
switch(messageType) {
|
|
1241
|
+
case 'PAYMENT':
|
|
1242
|
+
const paymentContent = await kelvdra.handlePayment(content, quoted);
|
|
1243
|
+
return await relayMessage(jid, paymentContent, {
|
|
1244
|
+
messageId: Utils_1.generateMessageID(),
|
|
1245
|
+
...getParticipantAttr()
|
|
1246
|
+
});
|
|
1247
|
+
|
|
1248
|
+
case 'PRODUCT':
|
|
1249
|
+
const productContent = await kelvdra.handleProduct(content, jid, quoted);
|
|
1250
|
+
const productMsg = await Utils_1.generateWAMessageFromContent(jid, productContent, { quoted });
|
|
1251
|
+
return await relayMessage(jid, productMsg.message, {
|
|
1252
|
+
messageId: productMsg.key.id,
|
|
1253
|
+
...getParticipantAttr()
|
|
1254
|
+
});
|
|
1255
|
+
|
|
1256
|
+
case 'INTERACTIVE':
|
|
1257
|
+
const interactiveContent = await kelvdra.handleInteractive(content, jid, quoted);
|
|
1258
|
+
const interactiveMsg = await Utils_1.generateWAMessageFromContent(jid, interactiveContent, { quoted });
|
|
1259
|
+
return await relayMessage(jid, interactiveMsg.message, {
|
|
1260
|
+
messageId: interactiveMsg.key.id,
|
|
1261
|
+
...getParticipantAttr()
|
|
1262
|
+
});
|
|
1263
|
+
case 'ALBUM':
|
|
1264
|
+
const albumContent = await kelvdra.handleAlbum(content, jid, quoted)
|
|
1265
|
+
return albumContent;
|
|
1266
|
+
|
|
1267
|
+
case 'EVENT':
|
|
1268
|
+
return await kelvdra.handleEvent(content, jid, quoted)
|
|
1269
|
+
|
|
1270
|
+
case 'POLL_RESULT':
|
|
1271
|
+
return await kelvdra.handlePollResult(content, jid, quoted)
|
|
1272
|
+
|
|
1273
|
+
case 'CAROUSEL':
|
|
1274
|
+
return await kelvdra.handleCarousel(content, jid, quoted);
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
if (typeof content === 'object' &&
|
|
1278
|
+
'disappearingMessagesInChat' in content &&
|
|
1279
|
+
typeof content['disappearingMessagesInChat'] !== 'undefined' &&
|
|
1280
|
+
isJidGroup(jid)) {
|
|
1281
|
+
const { disappearingMessagesInChat } = content;
|
|
1282
|
+
const value = typeof disappearingMessagesInChat === 'boolean'
|
|
1283
|
+
? disappearingMessagesInChat
|
|
1284
|
+
? WA_DEFAULT_EPHEMERAL
|
|
1285
|
+
: 0
|
|
1286
|
+
: disappearingMessagesInChat;
|
|
1287
|
+
await groupToggleEphemeral(jid, value);
|
|
1288
|
+
}
|
|
1289
|
+
else {
|
|
1290
|
+
const fullMsg = await generateWAMessage(jid, content, {
|
|
1291
|
+
logger,
|
|
1292
|
+
userJid,
|
|
1293
|
+
getUrlInfo: text => getUrlInfo(text, {
|
|
1294
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
1295
|
+
fetchOpts: {
|
|
1296
|
+
timeout: 3000,
|
|
1297
|
+
...(httpRequestOptions || {})
|
|
1298
|
+
},
|
|
1299
|
+
logger,
|
|
1300
|
+
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
1301
|
+
}),
|
|
1302
|
+
//TODO: CACHE
|
|
1303
|
+
getProfilePicUrl: sock.profilePictureUrl,
|
|
1304
|
+
getCallLink: sock.createCallLink,
|
|
1305
|
+
upload: waUploadToServer,
|
|
1306
|
+
mediaCache: config.mediaCache,
|
|
1307
|
+
options: config.options,
|
|
1308
|
+
messageId: generateMessageIDV2(sock.user?.id),
|
|
1309
|
+
...options
|
|
1310
|
+
});
|
|
1311
|
+
const isEventMsg = 'event' in content && !!content.event;
|
|
1312
|
+
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
1313
|
+
const isEditMsg = 'edit' in content && !!content.edit;
|
|
1314
|
+
const isPinMsg = 'pin' in content && !!content.pin;
|
|
1315
|
+
const isPollMessage = 'poll' in content && !!content.poll;
|
|
1316
|
+
const additionalAttributes = {};
|
|
1317
|
+
const additionalNodes = [];
|
|
1318
|
+
// required for delete
|
|
1319
|
+
if (isDeleteMsg) {
|
|
1320
|
+
// if the chat is a group, and I am not the author, then delete the message as an admin
|
|
1321
|
+
if (isJidGroup(content.delete?.remoteJid) && !content.delete?.fromMe) {
|
|
1322
|
+
additionalAttributes.edit = '8';
|
|
1323
|
+
}
|
|
1324
|
+
else {
|
|
1325
|
+
additionalAttributes.edit = '7';
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
else if (isEditMsg) {
|
|
1329
|
+
additionalAttributes.edit = '1';
|
|
1330
|
+
}
|
|
1331
|
+
else if (isPinMsg) {
|
|
1332
|
+
additionalAttributes.edit = '2';
|
|
1333
|
+
}
|
|
1334
|
+
else if (isPollMessage) {
|
|
1335
|
+
additionalNodes.push({
|
|
1336
|
+
tag: 'meta',
|
|
1337
|
+
attrs: {
|
|
1338
|
+
polltype: 'creation'
|
|
1339
|
+
}
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1342
|
+
else if (isEventMsg) {
|
|
1343
|
+
additionalNodes.push({
|
|
1344
|
+
tag: 'meta',
|
|
1345
|
+
attrs: {
|
|
1346
|
+
event_type: 'creation'
|
|
1347
|
+
}
|
|
1348
|
+
});
|
|
1349
|
+
}
|
|
1350
|
+
await relayMessage(jid, fullMsg.message, {
|
|
1351
|
+
messageId: fullMsg.key.id,
|
|
1352
|
+
useCachedGroupMetadata: options.useCachedGroupMetadata,
|
|
1353
|
+
additionalAttributes,
|
|
1354
|
+
statusJidList: options.statusJidList,
|
|
1355
|
+
additionalNodes
|
|
1356
|
+
});
|
|
1357
|
+
if (config.emitOwnEvents) {
|
|
1358
|
+
process.nextTick(() => {
|
|
1359
|
+
processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
return fullMsg;
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
};
|
|
1366
|
+
};
|
|
1367
|
+
//# sourceMappingURL=messages-send.js.map
|