lordceaser-baileys 3.3.5 → 3.3.7
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/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/fix-imports.js +85 -0
- package/index.js +15 -6
- package/lib/Defaults/index.d.ts +75 -0
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +15 -44
- 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 +2 -1
- package/lib/Signal/Group/ciphertext-message.js.map +1 -0
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
- package/lib/Signal/Group/group-session-builder.js +2 -1
- package/lib/Signal/Group/group-session-builder.js.map +1 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
- package/lib/Signal/Group/group_cipher.js +2 -1
- package/lib/Signal/Group/group_cipher.js.map +1 -0
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.d.ts.map +1 -0
- package/lib/Signal/Group/index.js +1 -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 +2 -1
- package/lib/Signal/Group/keyhelper.js.map +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-chain-key.js +2 -1
- package/lib/Signal/Group/sender-chain-key.js.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +2 -1
- package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-message.js +2 -1
- package/lib/Signal/Group/sender-key-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-name.js +2 -1
- package/lib/Signal/Group/sender-key-name.js.map +1 -0
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-record.js +2 -1
- package/lib/Signal/Group/sender-key-record.js.map +1 -0
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-state.js +2 -1
- package/lib/Signal/Group/sender-key-state.js.map +1 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-message-key.js +2 -1
- package/lib/Signal/Group/sender-message-key.js.map +1 -0
- package/lib/Signal/libsignal.d.ts +5 -0
- package/lib/Signal/libsignal.d.ts.map +1 -0
- package/lib/Signal/libsignal.js +4 -1
- 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 +6 -9
- 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 +1 -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 +2 -1
- package/lib/Socket/Client/types.js.map +1 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +2 -1
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/Socket/Client/index.js +2 -0
- package/lib/Socket/Socket/Client/types.js +10 -0
- package/lib/Socket/Socket/Client/websocket.js +53 -0
- package/lib/Socket/Socket/business.js +407 -0
- package/lib/Socket/Socket/chats.js +1908 -0
- package/lib/Socket/Socket/communities.js +431 -0
- package/lib/Socket/Socket/groups.js +549 -0
- package/lib/Socket/Socket/index.js +37 -0
- package/lib/Socket/Socket/messages-recv.js +2144 -0
- package/lib/Socket/Socket/messages-send.js +3177 -0
- package/lib/Socket/Socket/mex.js +41 -0
- package/lib/Socket/Socket/newsletter.js +260 -0
- package/lib/Socket/Socket/socket.js +1017 -0
- package/lib/Socket/business.d.ts +217 -0
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +42 -70
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +125 -0
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +21 -731
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +273 -0
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +1 -1
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/groups.d.ts +161 -0
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +5 -207
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +260 -0
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +3 -28
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +203 -0
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +9 -381
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +199 -0
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +157 -2189
- package/lib/Socket/messages-send.js.map +1 -0
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.d.ts.map +1 -0
- package/lib/Socket/mex.js +2 -1
- package/lib/Socket/mex.js.map +1 -0
- package/lib/Socket/newsletter.d.ts +170 -0
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +19 -98
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +59 -0
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +17 -64
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Types/Auth.d.ts +117 -0
- package/lib/Types/Auth.d.ts.map +1 -0
- package/lib/Types/Auth.js +2 -1
- package/lib/Types/Auth.js.map +1 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.d.ts.map +1 -0
- package/lib/Types/Bussines.js +2 -1
- package/lib/Types/Bussines.js.map +1 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Call.d.ts.map +1 -0
- package/lib/Types/Call.js +2 -1
- package/lib/Types/Call.js.map +1 -0
- package/lib/Types/Chat.d.ts +124 -0
- package/lib/Types/Chat.d.ts.map +1 -0
- package/lib/Types/Chat.js +2 -1
- package/lib/Types/Chat.js.map +1 -0
- package/lib/Types/Contact.d.ts +26 -0
- package/lib/Types/Contact.d.ts.map +1 -0
- package/lib/Types/Contact.js +2 -1
- package/lib/Types/Contact.js.map +1 -0
- package/lib/Types/Events.d.ts +256 -0
- package/lib/Types/Events.d.ts.map +1 -0
- package/lib/Types/Events.js +2 -1
- package/lib/Types/Events.js.map +1 -0
- package/lib/Types/GroupMetadata.d.ts +71 -0
- package/lib/Types/GroupMetadata.d.ts.map +1 -0
- package/lib/Types/GroupMetadata.js +2 -1
- package/lib/Types/GroupMetadata.js.map +1 -0
- package/lib/Types/Label.d.ts +47 -0
- package/lib/Types/Label.d.ts.map +1 -0
- package/lib/Types/Label.js +2 -1
- package/lib/Types/Label.js.map +1 -0
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/LabelAssociation.d.ts.map +1 -0
- package/lib/Types/LabelAssociation.js +2 -1
- package/lib/Types/LabelAssociation.js.map +1 -0
- package/lib/Types/Message.d.ts +320 -0
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +1 -8
- package/lib/Types/Message.js.map +1 -0
- package/lib/Types/Mex.d.ts +141 -0
- package/lib/Types/Mex.d.ts.map +1 -0
- package/lib/Types/Mex.js +1 -3
- package/lib/Types/Mex.js.map +1 -0
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Product.d.ts.map +1 -0
- package/lib/Types/Product.js +2 -1
- package/lib/Types/Product.js.map +1 -0
- package/lib/Types/Signal.d.ts +87 -0
- package/lib/Types/Signal.d.ts.map +1 -0
- package/lib/Types/Signal.js +2 -1
- package/lib/Types/Signal.js.map +1 -0
- package/lib/Types/Socket.d.ts +136 -0
- package/lib/Types/Socket.d.ts.map +1 -0
- package/lib/Types/Socket.js +2 -1
- package/lib/Types/Socket.js.map +1 -0
- package/lib/Types/State.d.ts +97 -0
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +8 -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 -1
- package/lib/Types/USync.js.map +1 -0
- package/lib/Types/index.d.ts +66 -0
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +2 -1
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/_crypto_orig.js +118 -0
- package/lib/Utils/auth-utils.d.ts +24 -0
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +1 -0
- package/lib/Utils/auth-utils.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 +3 -2
- package/lib/Utils/browser-utils.js.map +1 -0
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +2 -1
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +100 -0
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +1 -22
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
- package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
- package/lib/Utils/companion-reg-client-utils.js +17 -14
- package/lib/Utils/companion-reg-client-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +37 -0
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +8 -117
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +66 -0
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +2 -169
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +36 -0
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +34 -1
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +92 -0
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +30 -27
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts +24 -0
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +13 -29
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/identity-change-handler.d.ts +44 -0
- package/lib/Utils/identity-change-handler.d.ts.map +1 -0
- package/lib/Utils/identity-change-handler.js +3 -1
- package/lib/Utils/identity-change-handler.js.map +1 -0
- package/lib/Utils/index.d.ts +22 -0
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +1 -17
- 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 +4 -3
- 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 +2 -1
- package/lib/Utils/logger.js.map +1 -0
- package/lib/Utils/lt-hash.d.ts +8 -0
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +2 -1
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts +9 -0
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +2 -1
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/message-retry-manager.d.ts +115 -0
- package/lib/Utils/message-retry-manager.d.ts.map +1 -0
- package/lib/Utils/message-retry-manager.js +26 -2
- package/lib/Utils/message-retry-manager.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +133 -0
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +33 -251
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +91 -0
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +69 -1328
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +2 -1
- package/lib/Utils/noise-handler.js.map +1 -0
- package/lib/Utils/offline-node-processor.d.ts +17 -0
- package/lib/Utils/offline-node-processor.d.ts.map +1 -0
- package/lib/Utils/offline-node-processor.js +2 -1
- package/lib/Utils/offline-node-processor.js.map +1 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.d.ts.map +1 -0
- package/lib/Utils/pre-key-manager.js +2 -1
- package/lib/Utils/pre-key-manager.js.map +1 -0
- package/lib/Utils/process-message.d.ts +60 -0
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +151 -114
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.d.ts.map +1 -0
- package/lib/Utils/reporting-utils.js +2 -1
- package/lib/Utils/reporting-utils.js.map +1 -0
- package/lib/Utils/signal.d.ts +47 -0
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +1 -0
- package/lib/Utils/signal.js.map +1 -0
- package/lib/Utils/stanza-ack.d.ts +11 -0
- package/lib/Utils/stanza-ack.d.ts.map +1 -0
- package/lib/Utils/stanza-ack.js +2 -1
- package/lib/Utils/stanza-ack.js.map +1 -0
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.d.ts.map +1 -0
- package/lib/Utils/sync-action-utils.js +3 -1
- package/lib/Utils/sync-action-utils.js.map +1 -0
- package/lib/Utils/tc-token-utils.d.ts +37 -0
- package/lib/Utils/tc-token-utils.d.ts.map +1 -0
- package/lib/Utils/tc-token-utils.js +4 -2
- package/lib/Utils/tc-token-utils.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 +2 -1
- 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 +6 -4
- 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 +1 -163
- package/lib/WABinary/constants.js.map +1 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.d.ts.map +1 -0
- package/lib/WABinary/decode.js +2 -1
- package/lib/WABinary/decode.js.map +1 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.d.ts.map +1 -0
- package/lib/WABinary/encode.js +2 -1
- package/lib/WABinary/encode.js.map +1 -0
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/generic-utils.d.ts.map +1 -0
- package/lib/WABinary/generic-utils.js +1 -115
- package/lib/WABinary/generic-utils.js.map +1 -0
- package/{WABinary/index.js → lib/WABinary/index.d.ts} +1 -0
- package/lib/WABinary/index.d.ts.map +1 -0
- package/lib/WABinary/index.js +1 -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 +3 -2
- package/lib/WABinary/jid-utils.js.map +1 -0
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.d.ts.map +1 -0
- package/lib/WABinary/types.js +2 -1
- package/lib/WABinary/types.js.map +1 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/BinaryInfo.d.ts.map +1 -0
- package/lib/WAM/BinaryInfo.js +2 -1
- package/lib/WAM/BinaryInfo.js.map +1 -0
- package/lib/WAM/constants.d.ts +40 -0
- package/lib/WAM/constants.d.ts.map +1 -0
- package/lib/WAM/constants.js +2 -1
- package/lib/WAM/constants.js.map +1 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.d.ts.map +1 -0
- package/lib/WAM/encode.js +2 -1
- package/lib/WAM/encode.js.map +1 -0
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.d.ts.map +1 -0
- package/lib/WAM/index.js +1 -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 +3 -7
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +3 -2
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +2 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +2 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/index.d.ts +6 -0
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/index.js +1 -7
- package/lib/WAUSync/Protocols/index.js.map +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +30 -0
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
- package/lib/WAUSync/USyncQuery.js +23 -126
- package/lib/WAUSync/USyncQuery.js.map +1 -0
- package/lib/WAUSync/USyncUser.d.ts +17 -0
- package/lib/WAUSync/USyncUser.d.ts.map +1 -0
- package/lib/WAUSync/USyncUser.js +1 -24
- package/lib/WAUSync/USyncUser.js.map +1 -0
- package/lib/WAUSync/WAUSync/Protocols/USyncContactProtocol.js +56 -0
- package/lib/WAUSync/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
- package/lib/WAUSync/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
- package/lib/WAUSync/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
- package/lib/WAUSync/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
- package/lib/WAUSync/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
- package/lib/WAUSync/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
- package/lib/WAUSync/WAUSync/Protocols/index.js +12 -0
- package/lib/WAUSync/WAUSync/USyncQuery.js +201 -0
- package/lib/WAUSync/WAUSync/USyncUser.js +54 -0
- package/lib/WAUSync/WAUSync/index.js +3 -0
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.d.ts.map +1 -0
- package/lib/WAUSync/index.js +2 -1
- package/lib/WAUSync/index.js.map +1 -0
- package/lib/index.d.ts +10 -648
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +3 -3
- package/lib/index.js.map +1 -0
- package/package.json +4 -3
- package/WABinary/constants.js +0 -1463
- package/WABinary/decode.js +0 -261
- package/WABinary/encode.js +0 -219
- package/WABinary/generic-utils.js +0 -227
- package/WABinary/jid-utils.js +0 -95
- package/WABinary/types.js +0 -1
- package/lib/Defaults/ban-checker.js +0 -44
- package/lib/Store/index.js +0 -4
- package/lib/Store/make-cache-manager-store.js +0 -89
- package/lib/Store/make-in-memory-store.js +0 -420
- package/lib/Store/make-ordered-dictionary.js +0 -78
- package/lib/Store/object-repository.js +0 -23
- package/lib/Types/RichType.js +0 -22
- package/lib/Utils/bot-capabilities.js +0 -84
- package/lib/Utils/bot-planning-replay.js +0 -165
- package/lib/Utils/channel-policy.js +0 -25
- package/lib/Utils/chat-utils.js[old] +0 -871
- package/lib/Utils/consumer-application.js +0 -102
- package/lib/Utils/games/miniapp.js +0 -5
- package/lib/Utils/games/slot-machine.js +0 -258
- package/lib/Utils/games/website-preview.js +0 -294
- package/lib/Utils/games/website-preview.js[bug] +0 -293
- package/lib/Utils/generics.js@old +0 -385
- package/lib/Utils/group-history.js +0 -56
- package/lib/Utils/jid-display-normalization.js +0 -209
- package/lib/Utils/message-composer.js +0 -467
- package/lib/Utils/message-inspect.js +0 -67
- package/lib/Utils/messages-media.js[old] +0 -916
- package/lib/Utils/messages.js[old] +0 -1902
- package/lib/Utils/meta-ai-msmsg.js +0 -203
- package/lib/Utils/meta-compositing.js +0 -227
- package/lib/Utils/native-flow.js +0 -100
- package/lib/Utils/rich-message-utils.js +0 -1895
- package/lib/Utils/rich-message-utils.js[Old] +0 -387
- package/lib/Utils/source-grep.js +0 -45
- package/lib/Utils/use-single-file-auth-state.js +0 -96
- package/lib/Utils/use-sqlite-auth-state.js +0 -108
- package/lib/Utils/view-once-utils.js +0 -206
- package/lib/Utils/voip-rekey.js +0 -20
- package/lib/Utils/welcome-flow.js +0 -216
- /package/lib/Socket/{aigroups.js → Socket/aigroups.js} +0 -0
- /package/lib/Socket/{ban-checker.js → Socket/ban-checker.js} +0 -0
- /package/lib/Socket/{chats.js[old] → Socket/chats.js[old]} +0 -0
- /package/lib/Socket/{graphql.js → Socket/graphql.js} +0 -0
- /package/lib/Socket/{groups.js[old] → Socket/groups.js[old]} +0 -0
- /package/lib/Socket/{interactive-handler.js → Socket/interactive-handler.js} +0 -0
- /package/lib/Socket/{interop.js → Socket/interop.js} +0 -0
- /package/lib/Socket/{managed-account.js → Socket/managed-account.js} +0 -0
- /package/lib/Socket/{privacy.js → Socket/privacy.js} +0 -0
- /package/lib/Socket/{registration.js → Socket/registration.js} +0 -0
- /package/lib/Socket/{username.js → Socket/username.js} +0 -0
- /package/lib/WAUSync/{Protocols → WAUSync/Protocols}/USyncBusinessProtocol.js +0 -0
- /package/lib/WAUSync/{Protocols → WAUSync/Protocols}/USyncFeatureProtocol.js +0 -0
- /package/lib/WAUSync/{Protocols → WAUSync/Protocols}/USyncPictureProtocol.js +0 -0
- /package/lib/WAUSync/{Protocols → WAUSync/Protocols}/USyncSidelistProtocol.js +0 -0
- /package/lib/WAUSync/{Protocols → WAUSync/Protocols}/USyncTextStatusProtocol.js +0 -0
package/WABinary/jid-utils.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
export const S_WHATSAPP_NET = '@s.whatsapp.net';
|
|
2
|
-
export const OFFICIAL_BIZ_JID = '16505361212@c.us';
|
|
3
|
-
export const SERVER_JID = 'server@c.us';
|
|
4
|
-
export const PSA_WID = '0@c.us';
|
|
5
|
-
export const STORIES_JID = 'status@broadcast';
|
|
6
|
-
export const META_AI_JID = '13135550002@c.us';
|
|
7
|
-
export var WAJIDDomains;
|
|
8
|
-
(function (WAJIDDomains) {
|
|
9
|
-
WAJIDDomains[WAJIDDomains["WHATSAPP"] = 0] = "WHATSAPP";
|
|
10
|
-
WAJIDDomains[WAJIDDomains["LID"] = 1] = "LID";
|
|
11
|
-
WAJIDDomains[WAJIDDomains["HOSTED"] = 128] = "HOSTED";
|
|
12
|
-
WAJIDDomains[WAJIDDomains["HOSTED_LID"] = 129] = "HOSTED_LID";
|
|
13
|
-
})(WAJIDDomains || (WAJIDDomains = {}));
|
|
14
|
-
export const getServerFromDomainType = (initialServer, domainType) => {
|
|
15
|
-
switch (domainType) {
|
|
16
|
-
case WAJIDDomains.LID:
|
|
17
|
-
return 'lid';
|
|
18
|
-
case WAJIDDomains.HOSTED:
|
|
19
|
-
return 'hosted';
|
|
20
|
-
case WAJIDDomains.HOSTED_LID:
|
|
21
|
-
return 'hosted.lid';
|
|
22
|
-
case WAJIDDomains.WHATSAPP:
|
|
23
|
-
default:
|
|
24
|
-
return initialServer;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
export const jidEncode = (user, server, device, agent) => {
|
|
28
|
-
return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server || 'lid'}`;
|
|
29
|
-
};
|
|
30
|
-
export const jidDecode = (jid) => {
|
|
31
|
-
// todo: investigate how to implement hosted ids in this case
|
|
32
|
-
const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1;
|
|
33
|
-
if (sepIdx < 0) {
|
|
34
|
-
return undefined;
|
|
35
|
-
}
|
|
36
|
-
const server = jid.slice(sepIdx + 1);
|
|
37
|
-
const userCombined = jid.slice(0, sepIdx);
|
|
38
|
-
const [userAgent, device] = userCombined.split(':');
|
|
39
|
-
const [user, agent] = userAgent.split('_');
|
|
40
|
-
let domainType = WAJIDDomains.WHATSAPP;
|
|
41
|
-
if (server === 'lid') {
|
|
42
|
-
domainType = WAJIDDomains.LID;
|
|
43
|
-
}
|
|
44
|
-
else if (server === 'hosted') {
|
|
45
|
-
domainType = WAJIDDomains.HOSTED;
|
|
46
|
-
}
|
|
47
|
-
else if (server === 'hosted.lid') {
|
|
48
|
-
domainType = WAJIDDomains.HOSTED_LID;
|
|
49
|
-
}
|
|
50
|
-
else if (agent) {
|
|
51
|
-
domainType = parseInt(agent);
|
|
52
|
-
}
|
|
53
|
-
return {
|
|
54
|
-
server: server,
|
|
55
|
-
user: user,
|
|
56
|
-
domainType,
|
|
57
|
-
device: device ? +device : undefined
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
/** is the jid a user */
|
|
61
|
-
export const areJidsSameUser = (jid1, jid2) => jidDecode(jid1)?.user === jidDecode(jid2)?.user;
|
|
62
|
-
/** is the jid Meta AI */
|
|
63
|
-
export const isJidMetaAI = (jid) => jid?.endsWith('@bot');
|
|
64
|
-
/** is the jid a PN user */
|
|
65
|
-
export const isPnUser = (jid) => jid?.endsWith('@s.whatsapp.net');
|
|
66
|
-
/** is the jid a LID */
|
|
67
|
-
export const isLidUser = (jid) => jid?.endsWith('@lid');
|
|
68
|
-
/** is the jid a broadcast */
|
|
69
|
-
export const isJidBroadcast = (jid) => jid?.endsWith('@broadcast');
|
|
70
|
-
/** is the jid a group */
|
|
71
|
-
export const isJidGroup = (jid) => jid?.endsWith('@g.us');
|
|
72
|
-
/** is the jid the status broadcast */
|
|
73
|
-
export const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
|
|
74
|
-
/** is the jid a newsletter */
|
|
75
|
-
export const isJidNewsletter = (jid) => jid?.endsWith('@newsletter');
|
|
76
|
-
/** is the jid a hosted PN */
|
|
77
|
-
export const isHostedPnUser = (jid) => jid?.endsWith('@hosted');
|
|
78
|
-
/** is the jid a hosted LID */
|
|
79
|
-
export const isHostedLidUser = (jid) => jid?.endsWith('@hosted.lid');
|
|
80
|
-
const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/;
|
|
81
|
-
export const isJidBot = (jid) => jid && botRegexp.test(jid.split('@')[0]) && jid.endsWith('@c.us');
|
|
82
|
-
export const jidNormalizedUser = (jid) => {
|
|
83
|
-
const result = jidDecode(jid);
|
|
84
|
-
if (!result) {
|
|
85
|
-
return '';
|
|
86
|
-
}
|
|
87
|
-
const { user, server } = result;
|
|
88
|
-
return jidEncode(user, server === 'c.us' ? 's.whatsapp.net' : server);
|
|
89
|
-
};
|
|
90
|
-
export const transferDevice = (fromJid, toJid) => {
|
|
91
|
-
const fromDecoded = jidDecode(fromJid);
|
|
92
|
-
const deviceId = fromDecoded?.device || 0;
|
|
93
|
-
const { server, user } = jidDecode(toJid);
|
|
94
|
-
return jidEncode(user, server, deviceId);
|
|
95
|
-
};
|
package/WABinary/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import * as constants from './constants.js';
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'crypto';
|
|
2
|
-
|
|
3
|
-
export const MOBILE_ENDPOINT =
|
|
4
|
-
process.env.CRYSNOVAX_MOBILE_ENDPOINT || 'g.whatsapp.net';
|
|
5
|
-
|
|
6
|
-
export const MOBILE_PORT = Number(
|
|
7
|
-
process.env.CRYSNOVAX_MOBILE_PORT || 443
|
|
8
|
-
);
|
|
9
|
-
|
|
10
|
-
export const WA_VERSION =
|
|
11
|
-
process.env.CRYSNOVAX_WA_VERSION || '2.2413.51';
|
|
12
|
-
|
|
13
|
-
// Must be declared before MOBILE_TOKEN.
|
|
14
|
-
export const WA_VERSION_HASH = createHash('md5')
|
|
15
|
-
.update(WA_VERSION)
|
|
16
|
-
.digest('hex');
|
|
17
|
-
|
|
18
|
-
// Supply only the private prefix through the runtime environment.
|
|
19
|
-
export const MOBILE_TOKEN = Buffer.from(
|
|
20
|
-
`${process.env.CRYSNOVAX_MOBILE_TOKEN_PREFIX || '0a1mLfGUIBVrMKF1RdvLI5lkRBvof6vn0fD2QRSM'}${WA_VERSION_HASH}`
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
export const MOBILE_REGISTRATION_ENDPOINT =
|
|
24
|
-
process.env.CRYSNOVAX_MOBILE_REGISTRATION_ENDPOINT ||
|
|
25
|
-
'https://v.whatsapp.net/v2';
|
|
26
|
-
|
|
27
|
-
export const MOBILE_USERAGENT =
|
|
28
|
-
process.env.CRYSNOVAX_MOBILE_USERAGENT ||
|
|
29
|
-
`WhatsApp/${WA_VERSION} iOS/17.5.1 Device/Apple-iPhone_13`;
|
|
30
|
-
|
|
31
|
-
export const GRAPHQL_ENDPOINT =
|
|
32
|
-
process.env.CRYSNOVAX_GRAPHQL_ENDPOINT ||
|
|
33
|
-
'https://graph.whatsapp.com/graphql';
|
|
34
|
-
|
|
35
|
-
export const GRAPHQL_ACCESS_TOKEN =
|
|
36
|
-
process.env.CRYSNOVAX_GRAPHQL_ACCESS_TOKEN ||
|
|
37
|
-
'WA|1015890928915437|3201f239340c1c8ec6262a6dad04200e';
|
|
38
|
-
|
|
39
|
-
export const GRAPHQL_BAN_STATUS_DOC_ID =
|
|
40
|
-
process.env.CRYSNOVAX_GRAPHQL_BAN_STATUS_DOC_ID ||
|
|
41
|
-
'25573756098908502';
|
|
42
|
-
|
|
43
|
-
export const MOBILE_COUNTRY_CODE =
|
|
44
|
-
process.env.CRYSNOVAX_PHONE_COUNTRY_CODE || '';
|
package/lib/Store/index.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { createCache } from 'cache-manager';
|
|
2
|
-
import { proto } from '../../WAProto/index.js';
|
|
3
|
-
import { BufferJSON, initAuthCreds } from '../Utils/index.js';
|
|
4
|
-
import logger from '../Utils/logger.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Cache-manager backed auth state.
|
|
8
|
-
*
|
|
9
|
-
* `store` accepts anything cache-manager v7's createCache({ stores: [...] }) accepts:
|
|
10
|
-
* a Keyv-compatible store instance (e.g. keyv/redis, keyv/sqlite) or a store factory.
|
|
11
|
-
* Keys are namespaced under `${sessionKey}:` so multiple sessions can share one store.
|
|
12
|
-
*/
|
|
13
|
-
export const makeCacheManagerAuthState = async (store, sessionKey) => {
|
|
14
|
-
const defaultKey = file => `${sessionKey}:${file}`;
|
|
15
|
-
const databaseConn = createCache({ stores: [store], ttl: 0 });
|
|
16
|
-
const writeData = async (file, data) => {
|
|
17
|
-
let ttl = undefined;
|
|
18
|
-
if (file === 'creds') {
|
|
19
|
-
ttl = 63115200; // 2 years
|
|
20
|
-
}
|
|
21
|
-
await databaseConn.set(defaultKey(file), JSON.stringify(data, BufferJSON.replacer), ttl);
|
|
22
|
-
};
|
|
23
|
-
const readData = async (file) => {
|
|
24
|
-
try {
|
|
25
|
-
const data = await databaseConn.get(defaultKey(file));
|
|
26
|
-
if (data) {
|
|
27
|
-
return JSON.parse(data, BufferJSON.reviver);
|
|
28
|
-
}
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
logger.error(error);
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
const removeData = async (file) => {
|
|
37
|
-
try {
|
|
38
|
-
return await databaseConn.del(defaultKey(file));
|
|
39
|
-
}
|
|
40
|
-
catch (err) {
|
|
41
|
-
logger.error({ err }, `Error removing ${file} from session ${sessionKey}`);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const clearState = async () => {
|
|
45
|
-
try {
|
|
46
|
-
// Keyv-compatible stores expose keys(pattern); tolerate stores that don't.
|
|
47
|
-
const keyed = typeof store?.keys === 'function' ? store : databaseConn;
|
|
48
|
-
const keys = typeof keyed.keys === 'function' ? await keyed.keys(`${sessionKey}*`) : [];
|
|
49
|
-
await Promise.all(keys.map(async key => await databaseConn.del(key)));
|
|
50
|
-
}
|
|
51
|
-
catch (err) {
|
|
52
|
-
logger.warn({ err }, 'clearState failed');
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
const creds = (await readData('creds')) || initAuthCreds();
|
|
56
|
-
return {
|
|
57
|
-
clearState,
|
|
58
|
-
saveCreds: () => writeData('creds', creds),
|
|
59
|
-
state: {
|
|
60
|
-
creds,
|
|
61
|
-
keys: {
|
|
62
|
-
get: async (type, ids) => {
|
|
63
|
-
const data = {};
|
|
64
|
-
await Promise.all(
|
|
65
|
-
ids.map(async id => {
|
|
66
|
-
let value = await readData(`${type}-${id}`);
|
|
67
|
-
if (type === 'app-state-sync-key' && value) {
|
|
68
|
-
value = proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
69
|
-
}
|
|
70
|
-
data[id] = value;
|
|
71
|
-
})
|
|
72
|
-
);
|
|
73
|
-
return data;
|
|
74
|
-
},
|
|
75
|
-
set: async (data) => {
|
|
76
|
-
const tasks = [];
|
|
77
|
-
for (const category in data) {
|
|
78
|
-
for (const id in data[category]) {
|
|
79
|
-
const value = data[category][id];
|
|
80
|
-
const key = `${category}-${id}`;
|
|
81
|
-
tasks.push(value ? writeData(key, value) : removeData(key));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
await Promise.all(tasks);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
};
|
|
@@ -1,420 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lia@Note 03-02-26 [WIP]
|
|
3
|
-
* Manually converted to ESM and modified by me
|
|
4
|
-
* Originally based on @whiskeysockets/baileys v6.7.16
|
|
5
|
-
* Minor adjustments for compatibility with baileys v7 (つ≧▽≦)つ
|
|
6
|
-
*/
|
|
7
|
-
import keyedDB from '@adiwajshing/keyed-db';
|
|
8
|
-
import { writeFileSync, readFileSync, existsSync } from 'fs';
|
|
9
|
-
import { WAProto } from '../Types/index.js';
|
|
10
|
-
import { LabelAssociationType } from '../Types/LabelAssociation.js';
|
|
11
|
-
import { DEFAULT_CONNECTION_CONFIG } from '../Defaults/index.js';
|
|
12
|
-
import { md5, toNumber, updateMessageWithReceipt, updateMessageWithReaction } from '../Utils/index.js';
|
|
13
|
-
import { jidDecode, jidNormalizedUser } from '../WABinary/index.js';
|
|
14
|
-
import { makeOrderedDictionary } from './make-ordered-dictionary.js';
|
|
15
|
-
import { ObjectRepository } from './object-repository.js';
|
|
16
|
-
export const waChatKey = (pin) => ({
|
|
17
|
-
key: (c) => (pin ? (c.pinned ? '1' : '0') : '') + (c.archived ? '0' : '1') + (c.conversationTimestamp ? c.conversationTimestamp.toString(16).padStart(8, '0') : '') + c.id,
|
|
18
|
-
compare: (k1, k2) => k2.localeCompare(k1)
|
|
19
|
-
});
|
|
20
|
-
export const waMessageID = (m) => m.key.id || '';
|
|
21
|
-
export const waLabelAssociationKey = {
|
|
22
|
-
key: (la) => (la.type === LabelAssociationType.Chat ? la.chatId + la.labelId : la.chatId + la.messageId + la.labelId),
|
|
23
|
-
compare: (k1, k2) => k2.localeCompare(k1)
|
|
24
|
-
};
|
|
25
|
-
const makeMessagesDictionary = () => makeOrderedDictionary(waMessageID);
|
|
26
|
-
export const makeInMemoryStore = (config = {}) => {
|
|
27
|
-
const socket = config.socket;
|
|
28
|
-
const chatKey = config.chatKey || waChatKey(true);
|
|
29
|
-
const labelAssociationKey = config.labelAssociationKey || waLabelAssociationKey;
|
|
30
|
-
const logger = config.logger || DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' });
|
|
31
|
-
const KeyedDB = keyedDB?.default ?? keyedDB; // Lia@Note 03-02-26 --- Handle CJS ↔ ESM default export differences ⊂(・ω・*⊂)
|
|
32
|
-
const chats = new KeyedDB(chatKey, c => c.id);
|
|
33
|
-
const messages = {};
|
|
34
|
-
const contacts = {};
|
|
35
|
-
const groupMetadata = {};
|
|
36
|
-
const presences = {};
|
|
37
|
-
const state = { connection: 'close' };
|
|
38
|
-
const labels = new ObjectRepository();
|
|
39
|
-
const labelAssociations = new KeyedDB(labelAssociationKey, labelAssociationKey.key);
|
|
40
|
-
const assertMessageList = (jid) => {
|
|
41
|
-
if (!messages[jid]) {
|
|
42
|
-
messages[jid] = makeMessagesDictionary();
|
|
43
|
-
}
|
|
44
|
-
return messages[jid];
|
|
45
|
-
};
|
|
46
|
-
const contactsUpsert = (newContacts) => {
|
|
47
|
-
const oldContacts = new Set(Object.keys(contacts));
|
|
48
|
-
for (const contact of newContacts) {
|
|
49
|
-
oldContacts.delete(contact.id);
|
|
50
|
-
contacts[contact.id] = Object.assign(contacts[contact.id] || {}, contact);
|
|
51
|
-
}
|
|
52
|
-
return oldContacts;
|
|
53
|
-
};
|
|
54
|
-
const labelsUpsert = (newLabels) => {
|
|
55
|
-
for (const label of newLabels) {
|
|
56
|
-
labels.upsertById(label.id, label);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* binds to a BaileysEventEmitter.
|
|
61
|
-
* It listens to all events and constructs a state that you can query accurate data from.
|
|
62
|
-
* Eg. can use the store to fetch chats, contacts, messages etc.
|
|
63
|
-
* @param ev typically the event emitter from the socket connection
|
|
64
|
-
*/
|
|
65
|
-
const bind = (ev) => {
|
|
66
|
-
ev.on('connection.update', update => {
|
|
67
|
-
Object.assign(state, update);
|
|
68
|
-
});
|
|
69
|
-
ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest, syncType }) => {
|
|
70
|
-
if (syncType === WAProto.HistorySync.HistorySyncType.ON_DEMAND) {
|
|
71
|
-
return; // FOR NOW,
|
|
72
|
-
//TODO: HANDLE
|
|
73
|
-
}
|
|
74
|
-
if (isLatest) {
|
|
75
|
-
chats.clear();
|
|
76
|
-
for (const id in messages) {
|
|
77
|
-
delete messages[id];
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
const chatsAdded = chats.insertIfAbsent(...newChats).length;
|
|
81
|
-
logger.debug({ chatsAdded }, 'synced chats');
|
|
82
|
-
const oldContacts = contactsUpsert(newContacts);
|
|
83
|
-
if (isLatest) {
|
|
84
|
-
for (const jid of oldContacts) {
|
|
85
|
-
delete contacts[jid];
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
logger.debug({ deletedContacts: isLatest ? oldContacts.size : 0, newContacts }, 'synced contacts');
|
|
89
|
-
for (const msg of newMessages) {
|
|
90
|
-
const jid = msg.key.remoteJidAlt || msg.key.remoteJid;
|
|
91
|
-
const list = assertMessageList(jid);
|
|
92
|
-
list.upsert(msg, 'prepend');
|
|
93
|
-
}
|
|
94
|
-
logger.debug({ messages: newMessages.length }, 'synced messages');
|
|
95
|
-
});
|
|
96
|
-
ev.on('contacts.upsert', contacts => {
|
|
97
|
-
contactsUpsert(contacts);
|
|
98
|
-
});
|
|
99
|
-
ev.on('contacts.update', async (updates) => {
|
|
100
|
-
var _a;
|
|
101
|
-
for (const update of updates) {
|
|
102
|
-
let contact;
|
|
103
|
-
if (contacts[update.id]) {
|
|
104
|
-
contact = contacts[update.id];
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
const contactHashes = await Promise.all(Object.keys(contacts).map(async (contactId) => {
|
|
108
|
-
const { user } = jidDecode(contactId);
|
|
109
|
-
return [contactId, (await md5(Buffer.from(user + 'WA_ADD_NOTIF', 'utf8'))).toString('base64').slice(0, 3)];
|
|
110
|
-
}));
|
|
111
|
-
contact = contacts[((_a = contactHashes.find(([, b]) => b === update.id)) === null || _a === void 0 ? void 0 : _a[0]) || '']; // find contact by attrs.hash, when user is not saved as a contact
|
|
112
|
-
}
|
|
113
|
-
if (contact) {
|
|
114
|
-
if (update.imgUrl === 'changed') {
|
|
115
|
-
contact.imgUrl = socket ? await (socket === null || socket === void 0 ? void 0 : socket.profilePictureUrl(contact.id)) : undefined;
|
|
116
|
-
}
|
|
117
|
-
else if (update.imgUrl === 'removed') {
|
|
118
|
-
delete contact.imgUrl;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
return logger.debug({ update }, 'got update for non-existant contact');
|
|
123
|
-
}
|
|
124
|
-
Object.assign(contacts[contact.id], contact);
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
ev.on('chats.upsert', newChats => {
|
|
128
|
-
chats.upsert(...newChats);
|
|
129
|
-
});
|
|
130
|
-
ev.on('chats.update', updates => {
|
|
131
|
-
for (let update of updates) {
|
|
132
|
-
const result = chats.update(update.id, chat => {
|
|
133
|
-
if (update.unreadCount > 0) {
|
|
134
|
-
update = { ...update };
|
|
135
|
-
update.unreadCount = (chat.unreadCount || 0) + update.unreadCount;
|
|
136
|
-
}
|
|
137
|
-
Object.assign(chat, update);
|
|
138
|
-
});
|
|
139
|
-
if (!result) {
|
|
140
|
-
logger.debug({ update }, 'got update for non-existant chat');
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
ev.on('labels.edit', (label) => {
|
|
145
|
-
if (label.deleted) {
|
|
146
|
-
return labels.deleteById(label.id);
|
|
147
|
-
}
|
|
148
|
-
// WhatsApp can store only up to 20 labels
|
|
149
|
-
if (labels.count() < 20) {
|
|
150
|
-
return labels.upsertById(label.id, label);
|
|
151
|
-
}
|
|
152
|
-
logger.error('Labels count exceed');
|
|
153
|
-
});
|
|
154
|
-
ev.on('labels.association', ({ type, association }) => {
|
|
155
|
-
switch (type) {
|
|
156
|
-
case 'add':
|
|
157
|
-
labelAssociations.upsert(association);
|
|
158
|
-
break;
|
|
159
|
-
case 'remove':
|
|
160
|
-
labelAssociations.delete(association);
|
|
161
|
-
break;
|
|
162
|
-
default:
|
|
163
|
-
console.error(`unknown operation type [${type}]`);
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
ev.on('presence.update', ({ id, presences: update }) => {
|
|
167
|
-
presences[id] = presences[id] || {};
|
|
168
|
-
Object.assign(presences[id], update);
|
|
169
|
-
});
|
|
170
|
-
ev.on('chats.delete', deletions => {
|
|
171
|
-
for (const item of deletions) {
|
|
172
|
-
if (chats.get(item)) {
|
|
173
|
-
chats.deleteById(item);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
ev.on('messages.upsert', ({ messages: newMessages, type }) => {
|
|
178
|
-
switch (type) {
|
|
179
|
-
case 'append':
|
|
180
|
-
case 'notify':
|
|
181
|
-
for (const msg of newMessages) {
|
|
182
|
-
const jid = jidNormalizedUser(msg.key.remoteJidAlt || msg.key.remoteJid);
|
|
183
|
-
const list = assertMessageList(jid);
|
|
184
|
-
list.upsert(msg, 'append');
|
|
185
|
-
if (type === 'notify' && !chats.get(jid)) {
|
|
186
|
-
ev.emit('chats.upsert', [
|
|
187
|
-
{
|
|
188
|
-
id: jid,
|
|
189
|
-
conversationTimestamp: toNumber(msg.messageTimestamp),
|
|
190
|
-
unreadCount: 1
|
|
191
|
-
}
|
|
192
|
-
]);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
break;
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
ev.on('messages.update', updates => {
|
|
199
|
-
var _a;
|
|
200
|
-
for (const { update, key } of updates) {
|
|
201
|
-
const list = assertMessageList(jidNormalizedUser(key.remoteJid));
|
|
202
|
-
if (update === null || update === void 0 ? void 0 : update.status) {
|
|
203
|
-
const listStatus = (_a = list.get(key.id)) === null || _a === void 0 ? void 0 : _a.status;
|
|
204
|
-
if (listStatus && (update === null || update === void 0 ? void 0 : update.status) <= listStatus) {
|
|
205
|
-
logger.debug({ update, storedStatus: listStatus }, 'status stored newer then update');
|
|
206
|
-
delete update.status;
|
|
207
|
-
logger.debug({ update }, 'new update object');
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
const result = list.updateAssign(key.id, update);
|
|
211
|
-
if (!result) {
|
|
212
|
-
logger.debug({ update }, 'got update for non-existent message');
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
ev.on('messages.delete', item => {
|
|
217
|
-
if ('all' in item) {
|
|
218
|
-
const list = messages[item.jid];
|
|
219
|
-
list === null || list === void 0 ? void 0 : list.clear();
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
const jid = item.keys[0].remoteJidAlt || item.keys[0].remoteJid;
|
|
223
|
-
const list = messages[jid];
|
|
224
|
-
if (list) {
|
|
225
|
-
const idSet = new Set(item.keys.map(k => k.id));
|
|
226
|
-
list.filter(m => !idSet.has(m.key.id));
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
ev.on('groups.update', updates => {
|
|
231
|
-
for (const update of updates) {
|
|
232
|
-
const id = update.id;
|
|
233
|
-
if (groupMetadata[id]) {
|
|
234
|
-
Object.assign(groupMetadata[id], update);
|
|
235
|
-
}
|
|
236
|
-
else {
|
|
237
|
-
logger.debug({ update }, 'got update for non-existant group metadata');
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
ev.on('group-participants.update', ({ id, participants, action }) => {
|
|
242
|
-
const metadata = groupMetadata[id];
|
|
243
|
-
if (metadata) {
|
|
244
|
-
switch (action) {
|
|
245
|
-
case 'add':
|
|
246
|
-
metadata.participants.push(...participants.map(participant => ({ id: participant.id, phoneNumber: participant.phoneNumber, admin: participant.admin })));
|
|
247
|
-
break;
|
|
248
|
-
case 'demote':
|
|
249
|
-
case 'promote':
|
|
250
|
-
for (const participant of metadata.participants) {
|
|
251
|
-
for (const participantData of participants) {
|
|
252
|
-
if (participantData.id === participant.id || participantData.phoneNumber === participant.phoneNumber) {
|
|
253
|
-
participant.admin = action === 'promote' && 'admin';
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
break;
|
|
258
|
-
case 'remove':
|
|
259
|
-
const removeSet = new Set();
|
|
260
|
-
for (const p of participants) {
|
|
261
|
-
if (p.id)
|
|
262
|
-
removeSet.add(p.id);
|
|
263
|
-
if (p.phoneNumber)
|
|
264
|
-
removeSet.add(p.phoneNumber);
|
|
265
|
-
}
|
|
266
|
-
metadata.participants = metadata.participants.reduce((acc, p) => {
|
|
267
|
-
if (!removeSet.has(p.id) && !removeSet.has(p.phoneNumber))
|
|
268
|
-
acc.push(p);
|
|
269
|
-
return acc;
|
|
270
|
-
}, []);
|
|
271
|
-
break;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
ev.on('message-receipt.update', updates => {
|
|
276
|
-
for (const { key, receipt } of updates) {
|
|
277
|
-
const obj = messages[key.remoteJidAlt || key.remoteJid];
|
|
278
|
-
const msg = obj === null || obj === void 0 ? void 0 : obj.get(key.id);
|
|
279
|
-
if (msg) {
|
|
280
|
-
updateMessageWithReceipt(msg, receipt);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
ev.on('messages.reaction', (reactions) => {
|
|
285
|
-
for (const { key, reaction } of reactions) {
|
|
286
|
-
const obj = messages[key.remoteJidAlt || key.remoteJid];
|
|
287
|
-
const msg = obj === null || obj === void 0 ? void 0 : obj.get(key.id);
|
|
288
|
-
if (msg) {
|
|
289
|
-
updateMessageWithReaction(msg, reaction);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
};
|
|
294
|
-
const toJSON = () => ({
|
|
295
|
-
chats,
|
|
296
|
-
contacts,
|
|
297
|
-
messages,
|
|
298
|
-
labels,
|
|
299
|
-
labelAssociations
|
|
300
|
-
});
|
|
301
|
-
const fromJSON = (json) => {
|
|
302
|
-
chats.upsert(...json.chats);
|
|
303
|
-
labelAssociations.upsert(...json.labelAssociations || []);
|
|
304
|
-
contactsUpsert(Object.values(json.contacts));
|
|
305
|
-
labelsUpsert(Object.values(json.labels || {}));
|
|
306
|
-
for (const jid in json.messages) {
|
|
307
|
-
const list = assertMessageList(jid);
|
|
308
|
-
for (const msg of json.messages[jid]) {
|
|
309
|
-
list.upsert(WAProto.WebMessageInfo.fromObject(msg), 'append');
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
};
|
|
313
|
-
return {
|
|
314
|
-
chats,
|
|
315
|
-
contacts,
|
|
316
|
-
messages,
|
|
317
|
-
groupMetadata,
|
|
318
|
-
state,
|
|
319
|
-
presences,
|
|
320
|
-
labels,
|
|
321
|
-
labelAssociations,
|
|
322
|
-
bind,
|
|
323
|
-
/** loads messages from the store, if not found -- uses the legacy connection */
|
|
324
|
-
loadMessages: async (jid, count, cursor) => {
|
|
325
|
-
const list = assertMessageList(jid);
|
|
326
|
-
const mode = !cursor || 'before' in cursor ? 'before' : 'after';
|
|
327
|
-
const cursorKey = !!cursor ? ('before' in cursor ? cursor.before : cursor.after) : undefined;
|
|
328
|
-
const cursorValue = cursorKey ? list.get(cursorKey.id) : undefined;
|
|
329
|
-
let messages;
|
|
330
|
-
if (list && mode === 'before' && (!cursorKey || cursorValue)) {
|
|
331
|
-
if (cursorValue) {
|
|
332
|
-
const msgIdx = list.array.findIndex(m => m.key.id === (cursorKey === null || cursorKey === void 0 ? void 0 : cursorKey.id));
|
|
333
|
-
messages = list.array.slice(0, msgIdx);
|
|
334
|
-
}
|
|
335
|
-
else {
|
|
336
|
-
messages = list.array;
|
|
337
|
-
}
|
|
338
|
-
const diff = count - messages.length;
|
|
339
|
-
if (diff < 0) {
|
|
340
|
-
messages = messages.slice(-count); // get the last X messages
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
else {
|
|
344
|
-
messages = [];
|
|
345
|
-
}
|
|
346
|
-
return messages;
|
|
347
|
-
},
|
|
348
|
-
/**
|
|
349
|
-
* Get all available labels for profile
|
|
350
|
-
*
|
|
351
|
-
* Keep in mind that the list is formed from predefined tags and tags
|
|
352
|
-
* that were "caught" during their editing.
|
|
353
|
-
*/
|
|
354
|
-
getLabels: () => {
|
|
355
|
-
return labels;
|
|
356
|
-
},
|
|
357
|
-
/**
|
|
358
|
-
* Get labels for chat
|
|
359
|
-
*
|
|
360
|
-
* @returns Label IDs
|
|
361
|
-
**/
|
|
362
|
-
getChatLabels: (chatId) => {
|
|
363
|
-
return labelAssociations.filter((la) => la.chatId === chatId).all();
|
|
364
|
-
},
|
|
365
|
-
/**
|
|
366
|
-
* Get labels for message
|
|
367
|
-
*
|
|
368
|
-
* @returns Label IDs
|
|
369
|
-
**/
|
|
370
|
-
getMessageLabels: (messageId) => {
|
|
371
|
-
const associations = labelAssociations
|
|
372
|
-
.filter((la) => la.messageId === messageId)
|
|
373
|
-
.all();
|
|
374
|
-
return associations.map(({ labelId }) => labelId);
|
|
375
|
-
},
|
|
376
|
-
loadMessage: async (jid, id) => { var _a; return (_a = messages[jid]) === null || _a === void 0 ? void 0 : _a.get(id); },
|
|
377
|
-
mostRecentMessage: async (jid) => {
|
|
378
|
-
var _a;
|
|
379
|
-
const message = (_a = messages[jid]) === null || _a === void 0 ? void 0 : _a.array.slice(-1)[0];
|
|
380
|
-
return message;
|
|
381
|
-
},
|
|
382
|
-
fetchImageUrl: async (jid, sock) => {
|
|
383
|
-
const contact = contacts[jid];
|
|
384
|
-
if (!contact) {
|
|
385
|
-
return sock === null || sock === void 0 ? void 0 : sock.profilePictureUrl(jid);
|
|
386
|
-
}
|
|
387
|
-
if (typeof contact.imgUrl === 'undefined') {
|
|
388
|
-
contact.imgUrl = await (sock === null || sock === void 0 ? void 0 : sock.profilePictureUrl(jid));
|
|
389
|
-
}
|
|
390
|
-
return contact.imgUrl;
|
|
391
|
-
},
|
|
392
|
-
fetchGroupMetadata: async (jid, sock) => {
|
|
393
|
-
if (!groupMetadata[jid]) {
|
|
394
|
-
const metadata = await (sock === null || sock === void 0 ? void 0 : sock.groupMetadata(jid));
|
|
395
|
-
if (metadata) {
|
|
396
|
-
groupMetadata[jid] = metadata;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
return groupMetadata[jid];
|
|
400
|
-
},
|
|
401
|
-
fetchMessageReceipts: async ({ remoteJid, id }) => {
|
|
402
|
-
const list = messages[remoteJid];
|
|
403
|
-
const msg = list === null || list === void 0 ? void 0 : list.get(id);
|
|
404
|
-
return msg === null || msg === void 0 ? void 0 : msg.userReceipt;
|
|
405
|
-
},
|
|
406
|
-
toJSON,
|
|
407
|
-
fromJSON,
|
|
408
|
-
writeToFile: (path) => {
|
|
409
|
-
writeFileSync(path, JSON.stringify(toJSON()));
|
|
410
|
-
},
|
|
411
|
-
readFromFile: (path) => {
|
|
412
|
-
if (existsSync(path)) {
|
|
413
|
-
logger.debug({ path }, 'reading from file');
|
|
414
|
-
const jsonStr = readFileSync(path, { encoding: 'utf-8' });
|
|
415
|
-
const json = JSON.parse(jsonStr);
|
|
416
|
-
fromJSON(json);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
};
|
|
420
|
-
};
|