@periskope/baileys 6.7.18-alpha.2 → 6.7.18-alpha.21
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/README.md +1 -1
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +4633 -0
- package/WAProto/fix-imports.js +29 -0
- package/WAProto/index.js +4136 -4138
- package/lib/Defaults/index.d.ts +4 -3
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +36 -40
- 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 +18 -0
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
- package/lib/Signal/Group/group_cipher.js +94 -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 +19 -0
- package/lib/Signal/Group/keyhelper.js.map +1 -0
- package/lib/Signal/Group/queue-job.d.ts +2 -0
- package/lib/Signal/Group/queue-job.d.ts.map +1 -0
- package/lib/Signal/Group/queue-job.js +54 -0
- package/lib/Signal/Group/queue-job.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 +32 -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 +67 -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 +50 -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 +96 -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/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +27 -39
- package/lib/Signal/Group/sender-message-key.js.map +1 -0
- package/lib/Signal/libsignal.d.ts +3 -2
- package/lib/Signal/libsignal.d.ts.map +1 -0
- package/lib/Signal/libsignal.js +37 -57
- package/lib/Signal/libsignal.js.map +1 -0
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.d.ts.map +1 -0
- package/lib/Socket/Client/index.js +3 -18
- package/lib/Socket/Client/index.js.map +1 -0
- package/lib/Socket/Client/types.d.ts +2 -1
- package/lib/Socket/Client/types.d.ts.map +1 -0
- package/lib/Socket/Client/types.js +4 -6
- package/lib/Socket/Client/types.js.map +1 -0
- package/lib/Socket/Client/websocket.d.ts +2 -1
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +14 -26
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +88 -59
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +32 -37
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +27 -21
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +132 -119
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +218 -0
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +351 -0
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/groups.d.ts +42 -35
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +57 -63
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +124 -65
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +6 -7
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +74 -45
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +294 -164
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +71 -42
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +100 -83
- 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 +142 -0
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +179 -0
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +12 -11
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +100 -106
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Socket/usync.d.ts +14 -13
- package/lib/Socket/usync.d.ts.map +1 -0
- package/lib/Socket/usync.js +9 -11
- package/lib/Socket/usync.js.map +1 -0
- package/lib/Types/Auth.d.ts +4 -3
- package/lib/Types/Auth.d.ts.map +1 -0
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Auth.js.map +1 -0
- package/lib/Types/Call.d.ts +1 -0
- package/lib/Types/Call.d.ts.map +1 -0
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Call.js.map +1 -0
- package/lib/Types/Chat.d.ts +11 -7
- package/lib/Types/Chat.d.ts.map +1 -0
- package/lib/Types/Chat.js +2 -4
- package/lib/Types/Chat.js.map +1 -0
- package/lib/Types/Contact.d.ts +5 -0
- package/lib/Types/Contact.d.ts.map +1 -0
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Contact.js.map +1 -0
- package/lib/Types/Events.d.ts +44 -10
- package/lib/Types/Events.d.ts.map +1 -0
- package/lib/Types/Events.js +2 -2
- package/lib/Types/Events.js.map +1 -0
- package/lib/Types/GroupMetadata.d.ts +3 -1
- package/lib/Types/GroupMetadata.d.ts.map +1 -0
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/GroupMetadata.js.map +1 -0
- package/lib/Types/Label.d.ts +1 -0
- package/lib/Types/Label.d.ts.map +1 -0
- package/lib/Types/Label.js +3 -5
- package/lib/Types/Label.js.map +1 -0
- package/lib/Types/LabelAssociation.d.ts +1 -0
- package/lib/Types/LabelAssociation.d.ts.map +1 -0
- package/lib/Types/LabelAssociation.js +3 -5
- package/lib/Types/LabelAssociation.js.map +1 -0
- package/lib/Types/Message.d.ts +17 -9
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +7 -7
- 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 +2 -1
- package/lib/Types/Product.d.ts.map +1 -0
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Product.js.map +1 -0
- package/lib/Types/Signal.d.ts +2 -1
- package/lib/Types/Signal.d.ts.map +1 -0
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Signal.js.map +1 -0
- package/lib/Types/Socket.d.ts +8 -7
- package/lib/Types/Socket.d.ts.map +1 -0
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/Socket.js.map +1 -0
- package/lib/Types/State.d.ts +4 -2
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +2 -2
- package/lib/Types/State.js.map +1 -0
- package/lib/Types/USync.d.ts +3 -2
- package/lib/Types/USync.d.ts.map +1 -0
- package/lib/Types/USync.js +2 -2
- package/lib/Types/USync.js.map +1 -0
- package/lib/Types/index.d.ts +15 -13
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +15 -30
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/auth-utils.d.ts +3 -2
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +24 -33
- package/lib/Utils/auth-utils.js.map +1 -0
- package/lib/Utils/baileys-event-stream.d.ts +2 -1
- package/lib/Utils/baileys-event-stream.d.ts.map +1 -0
- package/lib/Utils/baileys-event-stream.js +15 -22
- package/lib/Utils/baileys-event-stream.js.map +1 -0
- package/lib/Utils/business.d.ts +3 -2
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +61 -70
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +12 -11
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +141 -139
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +2 -1
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +37 -86
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +7 -7
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +43 -43
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +3 -2
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +24 -30
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +11 -9
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +88 -111
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts +4 -3
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +37 -46
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/index.d.ts +18 -17
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +18 -33
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/link-preview.d.ts +4 -3
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +11 -48
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +6 -5
- package/lib/Utils/logger.d.ts.map +1 -0
- package/lib/Utils/logger.js +3 -7
- package/lib/Utils/logger.js.map +1 -0
- package/lib/Utils/lt-hash.d.ts +9 -8
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +21 -24
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts +1 -0
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +5 -9
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +20 -11
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +200 -234
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +9 -8
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +217 -199
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts +5 -4
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +22 -26
- package/lib/Utils/noise-handler.js.map +1 -0
- package/lib/Utils/process-message.d.ts +5 -4
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +125 -130
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/signal.d.ts +5 -4
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +47 -52
- package/lib/Utils/signal.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +23 -26
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts +4 -3
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +55 -61
- package/lib/Utils/validate-connection.js.map +1 -0
- package/lib/WABinary/constants.d.ts +5 -4
- package/lib/WABinary/constants.d.ts.map +1 -0
- package/lib/WABinary/constants.js +1174 -1176
- package/lib/WABinary/constants.js.map +1 -0
- package/lib/WABinary/decode.d.ts +2 -1
- package/lib/WABinary/decode.d.ts.map +1 -0
- package/lib/WABinary/decode.js +13 -51
- package/lib/WABinary/decode.js.map +1 -0
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.d.ts.map +1 -0
- package/lib/WABinary/encode.js +5 -41
- package/lib/WABinary/encode.js.map +1 -0
- package/lib/WABinary/generic-utils.d.ts +4 -3
- package/lib/WABinary/generic-utils.d.ts.map +1 -0
- package/lib/WABinary/generic-utils.js +30 -38
- package/lib/WABinary/generic-utils.js.map +1 -0
- package/lib/WABinary/index.d.ts +6 -5
- package/lib/WABinary/index.d.ts.map +1 -0
- package/lib/WABinary/index.js +6 -21
- package/lib/WABinary/index.js.map +1 -0
- package/lib/WABinary/jid-utils.d.ts +1 -0
- package/lib/WABinary/jid-utils.d.ts.map +1 -0
- package/lib/WABinary/jid-utils.js +21 -35
- package/lib/WABinary/jid-utils.js.map +1 -0
- package/lib/WABinary/types.d.ts +2 -1
- package/lib/WABinary/types.d.ts.map +1 -0
- package/lib/WABinary/types.js +2 -2
- package/lib/WABinary/types.js.map +1 -0
- package/lib/WAM/BinaryInfo.d.ts +2 -1
- package/lib/WAM/BinaryInfo.d.ts.map +1 -0
- package/lib/WAM/BinaryInfo.js +2 -5
- package/lib/WAM/BinaryInfo.js.map +1 -0
- package/lib/WAM/constants.d.ts +1 -0
- package/lib/WAM/constants.d.ts.map +1 -0
- package/lib/WAM/constants.js +4 -6
- package/lib/WAM/constants.js.map +1 -0
- package/lib/WAM/encode.d.ts +2 -1
- package/lib/WAM/encode.d.ts.map +1 -0
- package/lib/WAM/encode.js +12 -14
- package/lib/WAM/encode.js.map +1 -0
- package/lib/WAM/index.d.ts +4 -3
- package/lib/WAM/index.d.ts.map +1 -0
- package/lib/WAM/index.js +4 -19
- package/lib/WAM/index.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +4 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +6 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +9 -12
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +7 -10
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -11
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +4 -3
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +19 -21
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +2 -5
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/index.d.ts +5 -4
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/index.js +5 -20
- package/lib/WAUSync/Protocols/index.js.map +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +4 -3
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
- package/lib/WAUSync/USyncQuery.js +18 -20
- package/lib/WAUSync/USyncQuery.js.map +1 -0
- package/lib/WAUSync/USyncUser.d.ts +6 -5
- package/lib/WAUSync/USyncUser.d.ts.map +1 -0
- package/lib/WAUSync/USyncUser.js +2 -5
- package/lib/WAUSync/USyncUser.js.map +1 -0
- package/lib/WAUSync/index.d.ts +4 -3
- package/lib/WAUSync/index.d.ts.map +1 -0
- package/lib/WAUSync/index.js +4 -19
- package/lib/WAUSync/index.js.map +1 -0
- package/lib/index.d.ts +9 -8
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -30
- package/lib/index.js.map +1 -0
- package/package.json +26 -28
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_name.js +0 -70
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
|
@@ -1,44 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const make_mutex_1 = require("../Utils/make-mutex");
|
|
15
|
-
const WABinary_1 = require("../WABinary");
|
|
16
|
-
const groups_1 = require("./groups");
|
|
17
|
-
const messages_send_1 = require("./messages-send");
|
|
18
|
-
const makeMessagesRecvSocket = (config) => {
|
|
1
|
+
import NodeCache from '@cacheable/node-cache';
|
|
2
|
+
import { Boom } from '@hapi/boom';
|
|
3
|
+
import { randomBytes } from 'crypto';
|
|
4
|
+
import Long from 'long';
|
|
5
|
+
import { proto } from '../../WAProto/index.js';
|
|
6
|
+
import { DEFAULT_CACHE_TTLS, KEY_BUNDLE_TYPE, MIN_PREKEY_COUNT } from '../Defaults/index.js';
|
|
7
|
+
import { WAMessageStatus, WAMessageStubType } from '../Types/index.js';
|
|
8
|
+
import { aesDecryptCTR, aesEncryptGCM, cleanMessage, Curve, decodeMediaRetryNode, decodeMessageNode, decryptMessageNode, delay, derivePairingCodeKey, encodeBigEndian, encodeSignedDeviceIdentity, getCallStatusFromNode, getHistoryMsg, getNextPreKeys, getStatusFromReceiptType, hkdf, MISSING_KEYS_ERROR_TEXT, NACK_REASONS, NO_MESSAGE_FOUND_ERROR_TEXT, unixTimestampSeconds, xmppPreKey, xmppSignedPreKey } from '../Utils/index.js';
|
|
9
|
+
import { makeMutex } from '../Utils/make-mutex.js';
|
|
10
|
+
import { areJidsSameUser, getAllBinaryNodeChildren, getBinaryNodeChild, getBinaryNodeChildBuffer, getBinaryNodeChildren, getBinaryNodeChildString, isJidGroup, isJidStatusBroadcast, isJidUser, jidDecode, jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
11
|
+
import { extractGroupMetadata } from './groups.js';
|
|
12
|
+
import { makeMessagesSocket } from './messages-send.js';
|
|
13
|
+
export const makeMessagesRecvSocket = (config) => {
|
|
19
14
|
const { logger, retryRequestDelayMs, maxMsgRetryCount, getMessage, shouldIgnoreJid } = config;
|
|
20
|
-
const sock =
|
|
15
|
+
const sock = makeMessagesSocket(config);
|
|
21
16
|
const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, sendPeerDataOperationMessage } = sock;
|
|
22
17
|
/** this mutex ensures that each retryRequest will wait for the previous one to finish */
|
|
23
|
-
const retryMutex =
|
|
18
|
+
const retryMutex = makeMutex();
|
|
24
19
|
const msgRetryCache = config.msgRetryCounterCache ||
|
|
25
|
-
new
|
|
26
|
-
stdTTL:
|
|
20
|
+
new NodeCache({
|
|
21
|
+
stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
|
|
27
22
|
useClones: false
|
|
28
23
|
});
|
|
29
24
|
const callOfferCache = config.callOfferCache ||
|
|
30
|
-
new
|
|
31
|
-
stdTTL:
|
|
25
|
+
new NodeCache({
|
|
26
|
+
stdTTL: DEFAULT_CACHE_TTLS.CALL_OFFER, // 5 mins
|
|
32
27
|
useClones: false
|
|
33
28
|
});
|
|
34
29
|
const placeholderResendCache = config.placeholderResendCache ||
|
|
35
|
-
new
|
|
36
|
-
stdTTL:
|
|
30
|
+
new NodeCache({
|
|
31
|
+
stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
|
|
37
32
|
useClones: false
|
|
38
33
|
});
|
|
39
34
|
let sendActiveReceipts = false;
|
|
40
35
|
const sendMessageAck = async ({ tag, attrs, content }, errorCode) => {
|
|
41
|
-
var _a, _b, _c, _d, _e;
|
|
42
36
|
const stanza = {
|
|
43
37
|
tag: 'ack',
|
|
44
38
|
attrs: {
|
|
@@ -57,13 +51,13 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
57
51
|
stanza.attrs.recipient = attrs.recipient;
|
|
58
52
|
}
|
|
59
53
|
if (!!attrs.type &&
|
|
60
|
-
(tag !== 'message' ||
|
|
54
|
+
(tag !== 'message' || getBinaryNodeChild({ tag, attrs, content }, 'unavailable') || errorCode !== 0)) {
|
|
61
55
|
stanza.attrs.type = attrs.type;
|
|
62
56
|
}
|
|
63
|
-
if (tag === 'message' &&
|
|
57
|
+
if (tag === 'message' && getBinaryNodeChild({ tag, attrs, content }, 'unavailable')) {
|
|
64
58
|
stanza.attrs.from = authState.creds.me.id;
|
|
65
59
|
}
|
|
66
|
-
if (tag === 'receipt' &&
|
|
60
|
+
if (tag === 'receipt' && attrs.from?.includes('broadcast')) {
|
|
67
61
|
ev.emit('broadcast-receipt.update', {
|
|
68
62
|
id: attrs.id,
|
|
69
63
|
participant: attrs.participant,
|
|
@@ -73,13 +67,13 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
73
67
|
});
|
|
74
68
|
if (content) {
|
|
75
69
|
for (const child of content) {
|
|
76
|
-
for (const c of child
|
|
70
|
+
for (const c of child?.content) {
|
|
77
71
|
ev.emit('broadcast-receipt.update', {
|
|
78
|
-
id:
|
|
79
|
-
participant:
|
|
80
|
-
timestamp: Number(
|
|
72
|
+
id: child?.attrs?.key,
|
|
73
|
+
participant: c?.attrs?.jid,
|
|
74
|
+
timestamp: Number(c?.attrs?.t),
|
|
81
75
|
broadcast: attrs.from,
|
|
82
|
-
type:
|
|
76
|
+
type: c?.attrs?.type === 'read' ? 'read' : 'delivered'
|
|
83
77
|
});
|
|
84
78
|
}
|
|
85
79
|
}
|
|
@@ -110,10 +104,10 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
110
104
|
await query(stanza);
|
|
111
105
|
};
|
|
112
106
|
const sendRetryRequest = async (node, forceIncludeKeys = false) => {
|
|
113
|
-
const { fullMessage } =
|
|
107
|
+
const { fullMessage } = decodeMessageNode(node, authState.creds.me.id, authState.creds.me.lid || '');
|
|
114
108
|
const { key: msgKey } = fullMessage;
|
|
115
109
|
const msgId = msgKey.id;
|
|
116
|
-
const key = `${msgId}:${msgKey
|
|
110
|
+
const key = `${msgId}:${msgKey?.participant}`;
|
|
117
111
|
let retryCount = msgRetryCache.get(key) || 0;
|
|
118
112
|
if (retryCount >= maxMsgRetryCount) {
|
|
119
113
|
logger.debug({ retryCount, msgId }, 'reached retry limit, clearing');
|
|
@@ -128,7 +122,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
128
122
|
const msgId = await requestPlaceholderResend(msgKey);
|
|
129
123
|
logger.debug(`sendRetryRequest: requested placeholder resend for message ${msgId}`);
|
|
130
124
|
}
|
|
131
|
-
const deviceIdentity =
|
|
125
|
+
const deviceIdentity = encodeSignedDeviceIdentity(account, true);
|
|
132
126
|
await authState.keys.transaction(async () => {
|
|
133
127
|
const receipt = {
|
|
134
128
|
tag: 'receipt',
|
|
@@ -150,7 +144,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
150
144
|
{
|
|
151
145
|
tag: 'registration',
|
|
152
146
|
attrs: {},
|
|
153
|
-
content:
|
|
147
|
+
content: encodeBigEndian(authState.creds.registrationId)
|
|
154
148
|
}
|
|
155
149
|
]
|
|
156
150
|
};
|
|
@@ -161,7 +155,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
161
155
|
receipt.attrs.participant = node.attrs.participant;
|
|
162
156
|
}
|
|
163
157
|
if (retryCount > 1 || forceIncludeKeys) {
|
|
164
|
-
const { update, preKeys } = await
|
|
158
|
+
const { update, preKeys } = await getNextPreKeys(authState, 1);
|
|
165
159
|
const [keyId] = Object.keys(preKeys);
|
|
166
160
|
const key = preKeys[+keyId];
|
|
167
161
|
const content = receipt.content;
|
|
@@ -169,10 +163,10 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
169
163
|
tag: 'keys',
|
|
170
164
|
attrs: {},
|
|
171
165
|
content: [
|
|
172
|
-
{ tag: 'type', attrs: {}, content: Buffer.from(
|
|
166
|
+
{ tag: 'type', attrs: {}, content: Buffer.from(KEY_BUNDLE_TYPE) },
|
|
173
167
|
{ tag: 'identity', attrs: {}, content: identityKey.public },
|
|
174
|
-
|
|
175
|
-
|
|
168
|
+
xmppPreKey(key, +keyId),
|
|
169
|
+
xmppSignedPreKey(signedPreKey),
|
|
176
170
|
{ tag: 'device-identity', attrs: {}, content: deviceIdentity }
|
|
177
171
|
]
|
|
178
172
|
});
|
|
@@ -184,17 +178,17 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
184
178
|
};
|
|
185
179
|
const handleEncryptNotification = async (node) => {
|
|
186
180
|
const from = node.attrs.from;
|
|
187
|
-
if (from ===
|
|
188
|
-
const countChild =
|
|
181
|
+
if (from === S_WHATSAPP_NET) {
|
|
182
|
+
const countChild = getBinaryNodeChild(node, 'count');
|
|
189
183
|
const count = +countChild.attrs.value;
|
|
190
|
-
const shouldUploadMorePreKeys = count <
|
|
184
|
+
const shouldUploadMorePreKeys = count < MIN_PREKEY_COUNT;
|
|
191
185
|
logger.debug({ count, shouldUploadMorePreKeys }, 'recv pre-key count');
|
|
192
186
|
if (shouldUploadMorePreKeys) {
|
|
193
187
|
await uploadPreKeys();
|
|
194
188
|
}
|
|
195
189
|
}
|
|
196
190
|
else {
|
|
197
|
-
const identityNode =
|
|
191
|
+
const identityNode = getBinaryNodeChild(node, 'identity');
|
|
198
192
|
if (identityNode) {
|
|
199
193
|
logger.info({ jid: from }, 'identity changed');
|
|
200
194
|
// not handling right now
|
|
@@ -206,12 +200,11 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
206
200
|
}
|
|
207
201
|
};
|
|
208
202
|
const handleGroupNotification = (participant, child, msg) => {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
switch (child === null || child === void 0 ? void 0 : child.tag) {
|
|
203
|
+
const participantJid = getBinaryNodeChild(child, 'participant')?.attrs?.jid || participant;
|
|
204
|
+
switch (child?.tag) {
|
|
212
205
|
case 'create':
|
|
213
|
-
const metadata =
|
|
214
|
-
msg.messageStubType =
|
|
206
|
+
const metadata = extractGroupMetadata(child);
|
|
207
|
+
msg.messageStubType = WAMessageStubType.GROUP_CREATE;
|
|
215
208
|
msg.messageStubParameters = [metadata.subject];
|
|
216
209
|
msg.key = { participant: metadata.owner };
|
|
217
210
|
ev.emit('chats.upsert', [
|
|
@@ -232,15 +225,15 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
232
225
|
case 'not_ephemeral':
|
|
233
226
|
msg.message = {
|
|
234
227
|
protocolMessage: {
|
|
235
|
-
type:
|
|
228
|
+
type: proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING,
|
|
236
229
|
ephemeralExpiration: +(child.attrs.expiration || 0)
|
|
237
230
|
}
|
|
238
231
|
};
|
|
239
232
|
break;
|
|
240
233
|
case 'modify':
|
|
241
|
-
const oldNumber =
|
|
234
|
+
const oldNumber = getBinaryNodeChildren(child, 'participant').map(p => p.attrs.jid);
|
|
242
235
|
msg.messageStubParameters = oldNumber || [];
|
|
243
|
-
msg.messageStubType =
|
|
236
|
+
msg.messageStubType = WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER;
|
|
244
237
|
break;
|
|
245
238
|
case 'promote':
|
|
246
239
|
case 'demote':
|
|
@@ -248,74 +241,73 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
248
241
|
case 'add':
|
|
249
242
|
case 'leave':
|
|
250
243
|
const stubType = `GROUP_PARTICIPANT_${child.tag.toUpperCase()}`;
|
|
251
|
-
msg.messageStubType =
|
|
252
|
-
const participants =
|
|
244
|
+
msg.messageStubType = WAMessageStubType[stubType];
|
|
245
|
+
const participants = getBinaryNodeChildren(child, 'participant').map(p => p.attrs.jid);
|
|
253
246
|
if (participants.length === 1 &&
|
|
254
247
|
// if recv. "remove" message and sender removed themselves
|
|
255
248
|
// mark as left
|
|
256
|
-
|
|
249
|
+
areJidsSameUser(participants[0], participant) &&
|
|
257
250
|
child.tag === 'remove') {
|
|
258
|
-
msg.messageStubType =
|
|
251
|
+
msg.messageStubType = WAMessageStubType.GROUP_PARTICIPANT_LEAVE;
|
|
259
252
|
}
|
|
260
253
|
msg.messageStubParameters = participants;
|
|
261
254
|
break;
|
|
262
255
|
case 'subject':
|
|
263
|
-
msg.messageStubType =
|
|
256
|
+
msg.messageStubType = WAMessageStubType.GROUP_CHANGE_SUBJECT;
|
|
264
257
|
msg.messageStubParameters = [child.attrs.subject];
|
|
265
258
|
break;
|
|
266
259
|
case 'description':
|
|
267
|
-
const description =
|
|
268
|
-
msg.messageStubType =
|
|
260
|
+
const description = getBinaryNodeChild(child, 'body')?.content?.toString();
|
|
261
|
+
msg.messageStubType = WAMessageStubType.GROUP_CHANGE_DESCRIPTION;
|
|
269
262
|
msg.messageStubParameters = description ? [description] : undefined;
|
|
270
263
|
break;
|
|
271
264
|
case 'announcement':
|
|
272
265
|
case 'not_announcement':
|
|
273
|
-
msg.messageStubType =
|
|
266
|
+
msg.messageStubType = WAMessageStubType.GROUP_CHANGE_ANNOUNCE;
|
|
274
267
|
msg.messageStubParameters = [child.tag === 'announcement' ? 'on' : 'off'];
|
|
275
268
|
break;
|
|
276
269
|
case 'locked':
|
|
277
270
|
case 'unlocked':
|
|
278
|
-
msg.messageStubType =
|
|
271
|
+
msg.messageStubType = WAMessageStubType.GROUP_CHANGE_RESTRICT;
|
|
279
272
|
msg.messageStubParameters = [child.tag === 'locked' ? 'on' : 'off'];
|
|
280
273
|
break;
|
|
281
274
|
case 'invite':
|
|
282
|
-
msg.messageStubType =
|
|
275
|
+
msg.messageStubType = WAMessageStubType.GROUP_CHANGE_INVITE_LINK;
|
|
283
276
|
msg.messageStubParameters = [child.attrs.code];
|
|
284
277
|
break;
|
|
285
278
|
case 'member_add_mode':
|
|
286
279
|
const addMode = child.content;
|
|
287
280
|
if (addMode) {
|
|
288
|
-
msg.messageStubType =
|
|
281
|
+
msg.messageStubType = WAMessageStubType.GROUP_MEMBER_ADD_MODE;
|
|
289
282
|
msg.messageStubParameters = [addMode.toString()];
|
|
290
283
|
}
|
|
291
284
|
break;
|
|
292
285
|
case 'membership_approval_mode':
|
|
293
|
-
const approvalMode =
|
|
286
|
+
const approvalMode = getBinaryNodeChild(child, 'group_join');
|
|
294
287
|
if (approvalMode) {
|
|
295
|
-
msg.messageStubType =
|
|
288
|
+
msg.messageStubType = WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE;
|
|
296
289
|
msg.messageStubParameters = [approvalMode.attrs.state];
|
|
297
290
|
}
|
|
298
291
|
break;
|
|
299
292
|
case 'created_membership_requests':
|
|
300
|
-
msg.messageStubType =
|
|
293
|
+
msg.messageStubType = WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
|
|
301
294
|
msg.messageStubParameters = [participantJid, 'created', child.attrs.request_method];
|
|
302
295
|
break;
|
|
303
296
|
case 'revoked_membership_requests':
|
|
304
|
-
const isDenied =
|
|
305
|
-
msg.messageStubType =
|
|
297
|
+
const isDenied = areJidsSameUser(participantJid, participant);
|
|
298
|
+
msg.messageStubType = WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
|
|
306
299
|
msg.messageStubParameters = [participantJid, isDenied ? 'revoked' : 'rejected'];
|
|
307
300
|
break;
|
|
308
301
|
}
|
|
309
302
|
};
|
|
310
303
|
const processNotification = async (node) => {
|
|
311
|
-
var _a, _b, _c;
|
|
312
304
|
const result = {};
|
|
313
|
-
const [child] =
|
|
305
|
+
const [child] = getAllBinaryNodeChildren(node);
|
|
314
306
|
const nodeType = node.attrs.type;
|
|
315
|
-
const from =
|
|
307
|
+
const from = jidNormalizedUser(node.attrs.from);
|
|
316
308
|
switch (nodeType) {
|
|
317
309
|
case 'privacy_token':
|
|
318
|
-
const tokenList =
|
|
310
|
+
const tokenList = getBinaryNodeChildren(child, 'token');
|
|
319
311
|
for (const { attrs, content } of tokenList) {
|
|
320
312
|
const jid = attrs.jid;
|
|
321
313
|
ev.emit('chats.update', [
|
|
@@ -327,49 +319,55 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
327
319
|
logger.debug({ jid }, 'got privacy token update');
|
|
328
320
|
}
|
|
329
321
|
break;
|
|
322
|
+
case 'newsletter':
|
|
323
|
+
await handleNewsletterNotification(node);
|
|
324
|
+
break;
|
|
325
|
+
case 'mex':
|
|
326
|
+
await handleMexNewsletterNotification(node);
|
|
327
|
+
break;
|
|
330
328
|
case 'w:gp2':
|
|
331
329
|
handleGroupNotification(node.attrs.participant, child, result);
|
|
332
330
|
break;
|
|
333
331
|
case 'mediaretry':
|
|
334
|
-
const event =
|
|
332
|
+
const event = decodeMediaRetryNode(node);
|
|
335
333
|
ev.emit('messages.media-update', [event]);
|
|
336
334
|
break;
|
|
337
335
|
case 'encrypt':
|
|
338
336
|
await handleEncryptNotification(node);
|
|
339
337
|
break;
|
|
340
338
|
case 'devices':
|
|
341
|
-
const devices =
|
|
342
|
-
if (
|
|
339
|
+
const devices = getBinaryNodeChildren(child, 'device');
|
|
340
|
+
if (areJidsSameUser(child.attrs.jid, authState.creds.me.id)) {
|
|
343
341
|
const deviceJids = devices.map(d => d.attrs.jid);
|
|
344
342
|
logger.info({ deviceJids }, 'got my own devices');
|
|
345
343
|
}
|
|
346
344
|
break;
|
|
347
345
|
case 'server_sync':
|
|
348
|
-
const update =
|
|
346
|
+
const update = getBinaryNodeChild(node, 'collection');
|
|
349
347
|
if (update) {
|
|
350
348
|
const name = update.attrs.name;
|
|
351
349
|
await resyncAppState([name], false);
|
|
352
350
|
}
|
|
353
351
|
break;
|
|
354
352
|
case 'picture':
|
|
355
|
-
const setPicture =
|
|
356
|
-
const delPicture =
|
|
353
|
+
const setPicture = getBinaryNodeChild(node, 'set');
|
|
354
|
+
const delPicture = getBinaryNodeChild(node, 'delete');
|
|
357
355
|
ev.emit('contacts.update', [
|
|
358
356
|
{
|
|
359
|
-
id:
|
|
357
|
+
id: jidNormalizedUser(node?.attrs?.from) || (setPicture || delPicture)?.attrs?.hash || '',
|
|
360
358
|
imgUrl: setPicture ? 'changed' : 'removed'
|
|
361
359
|
}
|
|
362
360
|
]);
|
|
363
|
-
if (
|
|
361
|
+
if (isJidGroup(from)) {
|
|
364
362
|
const node = setPicture || delPicture;
|
|
365
|
-
result.messageStubType =
|
|
363
|
+
result.messageStubType = WAMessageStubType.GROUP_CHANGE_ICON;
|
|
366
364
|
if (setPicture) {
|
|
367
365
|
result.messageStubParameters = [setPicture.attrs.id];
|
|
368
366
|
}
|
|
369
|
-
result.participant = node
|
|
367
|
+
result.participant = node?.attrs.author;
|
|
370
368
|
result.key = {
|
|
371
369
|
...(result.key || {}),
|
|
372
|
-
participant: setPicture
|
|
370
|
+
participant: setPicture?.attrs.author
|
|
373
371
|
};
|
|
374
372
|
}
|
|
375
373
|
break;
|
|
@@ -389,7 +387,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
389
387
|
});
|
|
390
388
|
}
|
|
391
389
|
else if (child.tag === 'blocklist') {
|
|
392
|
-
const blocklists =
|
|
390
|
+
const blocklists = getBinaryNodeChildren(child, 'item');
|
|
393
391
|
for (const { attrs } of blocklists) {
|
|
394
392
|
const blocklist = [attrs.jid];
|
|
395
393
|
const type = attrs.action === 'block' ? 'add' : 'remove';
|
|
@@ -398,15 +396,15 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
398
396
|
}
|
|
399
397
|
break;
|
|
400
398
|
case 'link_code_companion_reg':
|
|
401
|
-
const linkCodeCompanionReg =
|
|
402
|
-
const ref = toRequiredBuffer(
|
|
403
|
-
const primaryIdentityPublicKey = toRequiredBuffer(
|
|
404
|
-
const primaryEphemeralPublicKeyWrapped = toRequiredBuffer(
|
|
399
|
+
const linkCodeCompanionReg = getBinaryNodeChild(node, 'link_code_companion_reg');
|
|
400
|
+
const ref = toRequiredBuffer(getBinaryNodeChildBuffer(linkCodeCompanionReg, 'link_code_pairing_ref'));
|
|
401
|
+
const primaryIdentityPublicKey = toRequiredBuffer(getBinaryNodeChildBuffer(linkCodeCompanionReg, 'primary_identity_pub'));
|
|
402
|
+
const primaryEphemeralPublicKeyWrapped = toRequiredBuffer(getBinaryNodeChildBuffer(linkCodeCompanionReg, 'link_code_pairing_wrapped_primary_ephemeral_pub'));
|
|
405
403
|
const codePairingPublicKey = await decipherLinkPublicKey(primaryEphemeralPublicKeyWrapped);
|
|
406
|
-
const companionSharedKey =
|
|
407
|
-
const random =
|
|
408
|
-
const linkCodeSalt =
|
|
409
|
-
const linkCodePairingExpanded = await
|
|
404
|
+
const companionSharedKey = Curve.sharedKey(authState.creds.pairingEphemeralKeyPair.private, codePairingPublicKey);
|
|
405
|
+
const random = randomBytes(32);
|
|
406
|
+
const linkCodeSalt = randomBytes(32);
|
|
407
|
+
const linkCodePairingExpanded = await hkdf(companionSharedKey, 32, {
|
|
410
408
|
salt: linkCodeSalt,
|
|
411
409
|
info: 'link_code_pairing_key_bundle_encryption_key'
|
|
412
410
|
});
|
|
@@ -415,16 +413,16 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
415
413
|
primaryIdentityPublicKey,
|
|
416
414
|
random
|
|
417
415
|
]);
|
|
418
|
-
const encryptIv =
|
|
419
|
-
const encrypted =
|
|
416
|
+
const encryptIv = randomBytes(12);
|
|
417
|
+
const encrypted = aesEncryptGCM(encryptPayload, linkCodePairingExpanded, encryptIv, Buffer.alloc(0));
|
|
420
418
|
const encryptedPayload = Buffer.concat([linkCodeSalt, encryptIv, encrypted]);
|
|
421
|
-
const identitySharedKey =
|
|
419
|
+
const identitySharedKey = Curve.sharedKey(authState.creds.signedIdentityKey.private, primaryIdentityPublicKey);
|
|
422
420
|
const identityPayload = Buffer.concat([companionSharedKey, identitySharedKey, random]);
|
|
423
|
-
authState.creds.advSecretKey = (await
|
|
421
|
+
authState.creds.advSecretKey = (await hkdf(identityPayload, 32, { info: 'adv_secret' })).toString('base64');
|
|
424
422
|
await query({
|
|
425
423
|
tag: 'iq',
|
|
426
424
|
attrs: {
|
|
427
|
-
to:
|
|
425
|
+
to: S_WHATSAPP_NET,
|
|
428
426
|
type: 'set',
|
|
429
427
|
id: sock.generateMessageTag(),
|
|
430
428
|
xmlns: 'md'
|
|
@@ -466,14 +464,14 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
466
464
|
async function decipherLinkPublicKey(data) {
|
|
467
465
|
const buffer = toRequiredBuffer(data);
|
|
468
466
|
const salt = buffer.slice(0, 32);
|
|
469
|
-
const secretKey = await
|
|
467
|
+
const secretKey = await derivePairingCodeKey(authState.creds.pairingCode, salt);
|
|
470
468
|
const iv = buffer.slice(32, 48);
|
|
471
469
|
const payload = buffer.slice(48, 80);
|
|
472
|
-
return
|
|
470
|
+
return aesDecryptCTR(payload, secretKey, iv);
|
|
473
471
|
}
|
|
474
472
|
function toRequiredBuffer(data) {
|
|
475
473
|
if (data === undefined) {
|
|
476
|
-
throw new
|
|
474
|
+
throw new Boom('Invalid buffer', { statusCode: 400 });
|
|
477
475
|
}
|
|
478
476
|
return data instanceof Buffer ? data : Buffer.from(data);
|
|
479
477
|
}
|
|
@@ -487,8 +485,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
487
485
|
const newValue = (msgRetryCache.get(key) || 0) + 1;
|
|
488
486
|
msgRetryCache.set(key, newValue);
|
|
489
487
|
};
|
|
490
|
-
const sendMessagesAgain = async (key, ids, retryNode) => {
|
|
491
|
-
var _a;
|
|
488
|
+
const sendMessagesAgain = async (key, ids, retryNode, all = false) => {
|
|
492
489
|
// todo: implement a cache to store the last 256 sent messages (copy whatsmeow)
|
|
493
490
|
const msgs = await Promise.all(ids.map(id => getMessage({ ...key, id })));
|
|
494
491
|
const remoteJid = key.remoteJid;
|
|
@@ -496,9 +493,9 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
496
493
|
// if it's the primary jid sending the request
|
|
497
494
|
// just re-send the message to everyone
|
|
498
495
|
// prevents the first message decryption failure
|
|
499
|
-
const sendToAll = !
|
|
496
|
+
const sendToAll = !jidDecode(participant)?.device || all;
|
|
500
497
|
await assertSessions([participant], true);
|
|
501
|
-
if (
|
|
498
|
+
if (isJidGroup(remoteJid)) {
|
|
502
499
|
await authState.keys.set({ 'sender-key-memory': { [remoteJid]: null } });
|
|
503
500
|
}
|
|
504
501
|
logger.debug({ participant, sendToAll }, 'forced new session for retry recp');
|
|
@@ -523,11 +520,10 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
523
520
|
}
|
|
524
521
|
};
|
|
525
522
|
const handleReceipt = async (node) => {
|
|
526
|
-
var _a, _b;
|
|
527
523
|
const { attrs, content } = node;
|
|
528
524
|
const isLid = attrs.from.includes('lid');
|
|
529
|
-
const isNodeFromMe =
|
|
530
|
-
const remoteJid = !isNodeFromMe ||
|
|
525
|
+
const isNodeFromMe = areJidsSameUser(attrs.participant || attrs.from, isLid ? authState.creds.me?.lid : authState.creds.me?.id);
|
|
526
|
+
const remoteJid = !isNodeFromMe || isJidGroup(attrs.from) ? attrs.from : attrs.recipient;
|
|
531
527
|
const fromMe = !attrs.recipient || ((attrs.type === 'retry' || attrs.type === 'sender') && isNodeFromMe);
|
|
532
528
|
const key = {
|
|
533
529
|
remoteJid,
|
|
@@ -542,24 +538,24 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
542
538
|
}
|
|
543
539
|
const ids = [attrs.id];
|
|
544
540
|
if (Array.isArray(content)) {
|
|
545
|
-
const items =
|
|
541
|
+
const items = getBinaryNodeChildren(content[0], 'item');
|
|
546
542
|
ids.push(...items.map(i => i.attrs.id));
|
|
547
543
|
}
|
|
548
544
|
try {
|
|
549
545
|
await Promise.all([
|
|
550
546
|
processingMutex.mutex(async () => {
|
|
551
|
-
const status =
|
|
547
|
+
const status = getStatusFromReceiptType(attrs.type);
|
|
552
548
|
if (typeof status !== 'undefined' &&
|
|
553
549
|
// basically, we only want to know when a message from us has been delivered to/read by the other person
|
|
554
550
|
// or another device of ours has read some messages
|
|
555
|
-
(status >=
|
|
556
|
-
if ((
|
|
551
|
+
(status >= proto.WebMessageInfo.Status.SERVER_ACK)) {
|
|
552
|
+
if ((isJidGroup(remoteJid) || isJidStatusBroadcast(remoteJid))) {
|
|
557
553
|
if (attrs.participant) {
|
|
558
|
-
const updateKey = status ===
|
|
554
|
+
const updateKey = status === proto.WebMessageInfo.Status.DELIVERY_ACK ? 'receiptTimestamp' : 'readTimestamp';
|
|
559
555
|
ev.emit('message-receipt.update', ids.map(id => ({
|
|
560
556
|
key: { ...key, id },
|
|
561
557
|
receipt: {
|
|
562
|
-
userJid:
|
|
558
|
+
userJid: jidNormalizedUser(attrs.participant),
|
|
563
559
|
[updateKey]: +attrs.t
|
|
564
560
|
}
|
|
565
561
|
})));
|
|
@@ -580,7 +576,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
580
576
|
if (attrs.type === 'retry') {
|
|
581
577
|
// correctly set who is asking for the retry
|
|
582
578
|
key.participant = key.participant || attrs.from;
|
|
583
|
-
const retryNode =
|
|
579
|
+
const retryNode = getBinaryNodeChild(node, 'retry');
|
|
584
580
|
if (willSendMessageAgain(ids[0], key.participant)) {
|
|
585
581
|
if (key.fromMe) {
|
|
586
582
|
try {
|
|
@@ -616,10 +612,9 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
616
612
|
try {
|
|
617
613
|
await Promise.all([
|
|
618
614
|
processingMutex.mutex(async () => {
|
|
619
|
-
var _a;
|
|
620
615
|
const msg = await processNotification(node);
|
|
621
616
|
if (msg) {
|
|
622
|
-
const fromMe =
|
|
617
|
+
const fromMe = areJidsSameUser(node.attrs.participant || remoteJid, authState.creds.me.id);
|
|
623
618
|
msg.key = {
|
|
624
619
|
remoteJid,
|
|
625
620
|
fromMe,
|
|
@@ -627,9 +622,9 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
627
622
|
id: node.attrs.id,
|
|
628
623
|
...(msg.key || {})
|
|
629
624
|
};
|
|
630
|
-
|
|
625
|
+
msg.participant ?? (msg.participant = node.attrs.participant);
|
|
631
626
|
msg.messageTimestamp = +node.attrs.t;
|
|
632
|
-
const fullMsg =
|
|
627
|
+
const fullMsg = proto.WebMessageInfo.fromObject(msg);
|
|
633
628
|
await upsertMessage(fullMsg, 'append');
|
|
634
629
|
}
|
|
635
630
|
})
|
|
@@ -640,13 +635,12 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
640
635
|
}
|
|
641
636
|
};
|
|
642
637
|
const handleMessage = async (node) => {
|
|
643
|
-
var _a, _b, _c;
|
|
644
638
|
if (shouldIgnoreJid(node.attrs.from) && node.attrs.from !== '@s.whatsapp.net') {
|
|
645
639
|
logger.debug({ key: node.attrs.key }, 'ignored message');
|
|
646
640
|
await sendMessageAck(node);
|
|
647
641
|
return;
|
|
648
642
|
}
|
|
649
|
-
const encNode =
|
|
643
|
+
const encNode = getBinaryNodeChild(node, 'enc');
|
|
650
644
|
// TODO: temporary fix for crashes and issues resulting of failed msmsg decryption
|
|
651
645
|
if (encNode && encNode.attrs.type === 'msmsg') {
|
|
652
646
|
logger.debug({ key: node.attrs.key }, 'ignored msmsg');
|
|
@@ -654,9 +648,9 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
654
648
|
return;
|
|
655
649
|
}
|
|
656
650
|
let response;
|
|
657
|
-
if (
|
|
651
|
+
if (getBinaryNodeChild(node, 'unavailable') && !encNode) {
|
|
658
652
|
await sendMessageAck(node);
|
|
659
|
-
const { key } =
|
|
653
|
+
const { key } = decodeMessageNode(node, authState.creds.me.id, authState.creds.me.lid || '').fullMessage;
|
|
660
654
|
response = await requestPlaceholderResend(key);
|
|
661
655
|
if (response === 'RESOLVED') {
|
|
662
656
|
return;
|
|
@@ -668,33 +662,32 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
668
662
|
placeholderResendCache.del(node.attrs.id);
|
|
669
663
|
}
|
|
670
664
|
}
|
|
671
|
-
const { fullMessage: msg, category, author, decrypt } =
|
|
672
|
-
if (response &&
|
|
673
|
-
msg.messageStubParameters = [
|
|
665
|
+
const { fullMessage: msg, category, author, decrypt } = decryptMessageNode(node, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, logger);
|
|
666
|
+
if (response && msg?.messageStubParameters?.[0] === NO_MESSAGE_FOUND_ERROR_TEXT) {
|
|
667
|
+
msg.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT, response];
|
|
674
668
|
}
|
|
675
|
-
if (
|
|
669
|
+
if (msg.message?.protocolMessage?.type === proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER &&
|
|
676
670
|
node.attrs.sender_pn) {
|
|
677
671
|
ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn });
|
|
678
672
|
}
|
|
679
673
|
try {
|
|
680
674
|
await Promise.all([
|
|
681
675
|
processingMutex.mutex(async () => {
|
|
682
|
-
var _a;
|
|
683
676
|
await decrypt();
|
|
684
677
|
// message failed to decrypt
|
|
685
|
-
if (msg.messageStubType ===
|
|
686
|
-
if (
|
|
687
|
-
return sendMessageAck(node,
|
|
678
|
+
if (msg.messageStubType === proto.WebMessageInfo.StubType.CIPHERTEXT) {
|
|
679
|
+
if (msg?.messageStubParameters?.[0] === MISSING_KEYS_ERROR_TEXT) {
|
|
680
|
+
return sendMessageAck(node, NACK_REASONS.ParsingError);
|
|
688
681
|
}
|
|
689
682
|
retryMutex.mutex(async () => {
|
|
690
683
|
if (ws.isOpen) {
|
|
691
|
-
if (
|
|
684
|
+
if (getBinaryNodeChild(node, 'unavailable')) {
|
|
692
685
|
return;
|
|
693
686
|
}
|
|
694
|
-
const encNode =
|
|
687
|
+
const encNode = getBinaryNodeChild(node, 'enc');
|
|
695
688
|
await sendRetryRequest(node, !encNode);
|
|
696
689
|
if (retryRequestDelayMs) {
|
|
697
|
-
await
|
|
690
|
+
await delay(retryRequestDelayMs);
|
|
698
691
|
}
|
|
699
692
|
}
|
|
700
693
|
else {
|
|
@@ -714,7 +707,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
714
707
|
// message was sent by us from a different device
|
|
715
708
|
type = 'sender';
|
|
716
709
|
// need to specially handle this case
|
|
717
|
-
if (
|
|
710
|
+
if (isJidUser(msg.key.remoteJid)) {
|
|
718
711
|
participant = author;
|
|
719
712
|
}
|
|
720
713
|
}
|
|
@@ -723,13 +716,13 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
723
716
|
}
|
|
724
717
|
await sendReceipt(msg.key.remoteJid, participant, [msg.key.id], type);
|
|
725
718
|
// send ack for history message
|
|
726
|
-
const isAnyHistoryMsg =
|
|
719
|
+
const isAnyHistoryMsg = getHistoryMsg(msg.message);
|
|
727
720
|
if (isAnyHistoryMsg) {
|
|
728
|
-
const jid =
|
|
721
|
+
const jid = jidNormalizedUser(msg.key.remoteJid);
|
|
729
722
|
await sendReceipt(jid, undefined, [msg.key.id], 'hist_sync');
|
|
730
723
|
}
|
|
731
724
|
}
|
|
732
|
-
|
|
725
|
+
cleanMessage(msg, authState.creds.me.id);
|
|
733
726
|
await sendMessageAck(node);
|
|
734
727
|
await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify');
|
|
735
728
|
})
|
|
@@ -740,9 +733,8 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
740
733
|
}
|
|
741
734
|
};
|
|
742
735
|
const fetchMessageHistory = async (count, oldestMsgKey, oldestMsgTimestamp) => {
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
throw new boom_1.Boom('Not authenticated');
|
|
736
|
+
if (!authState.creds.me?.id) {
|
|
737
|
+
throw new Boom('Not authenticated');
|
|
746
738
|
}
|
|
747
739
|
const pdoMessage = {
|
|
748
740
|
historySyncOnDemandRequest: {
|
|
@@ -752,24 +744,23 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
752
744
|
oldestMsgTimestampMs: oldestMsgTimestamp,
|
|
753
745
|
onDemandMsgCount: count
|
|
754
746
|
},
|
|
755
|
-
peerDataOperationRequestType:
|
|
747
|
+
peerDataOperationRequestType: proto.Message.PeerDataOperationRequestType.HISTORY_SYNC_ON_DEMAND
|
|
756
748
|
};
|
|
757
749
|
return sendPeerDataOperationMessage(pdoMessage);
|
|
758
750
|
};
|
|
759
751
|
const requestPlaceholderResend = async (messageKey) => {
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
throw new boom_1.Boom('Not authenticated');
|
|
752
|
+
if (!authState.creds.me?.id) {
|
|
753
|
+
throw new Boom('Not authenticated');
|
|
763
754
|
}
|
|
764
|
-
if (placeholderResendCache.get(messageKey
|
|
755
|
+
if (placeholderResendCache.get(messageKey?.id)) {
|
|
765
756
|
logger.debug({ messageKey }, 'already requested resend');
|
|
766
757
|
return;
|
|
767
758
|
}
|
|
768
759
|
else {
|
|
769
|
-
placeholderResendCache.set(messageKey
|
|
760
|
+
placeholderResendCache.set(messageKey?.id, true);
|
|
770
761
|
}
|
|
771
|
-
await
|
|
772
|
-
if (!placeholderResendCache.get(messageKey
|
|
762
|
+
await delay(5000);
|
|
763
|
+
if (!placeholderResendCache.get(messageKey?.id)) {
|
|
773
764
|
logger.debug({ messageKey }, 'message received while resend requested');
|
|
774
765
|
return 'RESOLVED';
|
|
775
766
|
}
|
|
@@ -779,22 +770,25 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
779
770
|
messageKey
|
|
780
771
|
}
|
|
781
772
|
],
|
|
782
|
-
peerDataOperationRequestType:
|
|
773
|
+
peerDataOperationRequestType: proto.Message.PeerDataOperationRequestType.PLACEHOLDER_MESSAGE_RESEND
|
|
783
774
|
};
|
|
784
775
|
setTimeout(() => {
|
|
785
|
-
if (placeholderResendCache.get(messageKey
|
|
776
|
+
if (placeholderResendCache.get(messageKey?.id)) {
|
|
786
777
|
logger.debug({ messageKey }, 'PDO message without response after 15 seconds. Phone possibly offline');
|
|
787
|
-
placeholderResendCache.del(messageKey
|
|
778
|
+
placeholderResendCache.del(messageKey?.id);
|
|
788
779
|
}
|
|
789
780
|
}, 15000);
|
|
790
781
|
return sendPeerDataOperationMessage(pdoMessage);
|
|
791
782
|
};
|
|
792
783
|
const handleCall = async (node) => {
|
|
793
784
|
const { attrs } = node;
|
|
794
|
-
const [infoChild] =
|
|
785
|
+
const [infoChild] = getAllBinaryNodeChildren(node);
|
|
786
|
+
if (!infoChild) {
|
|
787
|
+
throw new Boom('Missing call info in call node');
|
|
788
|
+
}
|
|
795
789
|
const callId = infoChild.attrs['call-id'];
|
|
796
790
|
const from = infoChild.attrs.from || infoChild.attrs['call-creator'];
|
|
797
|
-
const status =
|
|
791
|
+
const status = getCallStatusFromNode(infoChild);
|
|
798
792
|
const call = {
|
|
799
793
|
chatId: attrs.from,
|
|
800
794
|
from,
|
|
@@ -804,7 +798,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
804
798
|
status
|
|
805
799
|
};
|
|
806
800
|
if (status === 'offer') {
|
|
807
|
-
call.isVideo = !!
|
|
801
|
+
call.isVideo = !!getBinaryNodeChild(infoChild, 'video');
|
|
808
802
|
call.isGroup = infoChild.attrs.type === 'group' || !!infoChild.attrs['group-jid'];
|
|
809
803
|
call.groupJid = infoChild.attrs['group-jid'];
|
|
810
804
|
callOfferCache.set(call.id, call);
|
|
@@ -845,7 +839,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
845
839
|
{
|
|
846
840
|
key,
|
|
847
841
|
update: {
|
|
848
|
-
status:
|
|
842
|
+
status: WAMessageStatus.ERROR,
|
|
849
843
|
messageStubParameters: [attrs.error]
|
|
850
844
|
}
|
|
851
845
|
}
|
|
@@ -903,6 +897,139 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
903
897
|
processNodeWithBuffer(node, identifier, exec);
|
|
904
898
|
}
|
|
905
899
|
};
|
|
900
|
+
// Handles newsletter notifications
|
|
901
|
+
async function handleNewsletterNotification(node) {
|
|
902
|
+
const from = node.attrs.from;
|
|
903
|
+
const child = getAllBinaryNodeChildren(node)[0];
|
|
904
|
+
const author = node.attrs.participant;
|
|
905
|
+
logger.info({ from, child }, 'got newsletter notification');
|
|
906
|
+
switch (child.tag) {
|
|
907
|
+
case 'reaction':
|
|
908
|
+
const reactionUpdate = {
|
|
909
|
+
id: from,
|
|
910
|
+
server_id: child.attrs.message_id,
|
|
911
|
+
reaction: {
|
|
912
|
+
code: getBinaryNodeChildString(child, 'reaction'),
|
|
913
|
+
count: 1
|
|
914
|
+
}
|
|
915
|
+
};
|
|
916
|
+
ev.emit('newsletter.reaction', reactionUpdate);
|
|
917
|
+
break;
|
|
918
|
+
case 'view':
|
|
919
|
+
const viewUpdate = {
|
|
920
|
+
id: from,
|
|
921
|
+
server_id: child.attrs.message_id,
|
|
922
|
+
count: parseInt(child.content?.toString() || '0', 10)
|
|
923
|
+
};
|
|
924
|
+
ev.emit('newsletter.view', viewUpdate);
|
|
925
|
+
break;
|
|
926
|
+
case 'participant':
|
|
927
|
+
const participantUpdate = {
|
|
928
|
+
id: from,
|
|
929
|
+
author,
|
|
930
|
+
user: child.attrs.jid,
|
|
931
|
+
action: child.attrs.action,
|
|
932
|
+
new_role: child.attrs.role
|
|
933
|
+
};
|
|
934
|
+
ev.emit('newsletter-participants.update', participantUpdate);
|
|
935
|
+
break;
|
|
936
|
+
case 'update':
|
|
937
|
+
const settingsNode = getBinaryNodeChild(child, 'settings');
|
|
938
|
+
if (settingsNode) {
|
|
939
|
+
const update = {};
|
|
940
|
+
const nameNode = getBinaryNodeChild(settingsNode, 'name');
|
|
941
|
+
if (nameNode?.content)
|
|
942
|
+
update.name = nameNode.content.toString();
|
|
943
|
+
const descriptionNode = getBinaryNodeChild(settingsNode, 'description');
|
|
944
|
+
if (descriptionNode?.content)
|
|
945
|
+
update.description = descriptionNode.content.toString();
|
|
946
|
+
ev.emit('newsletter-settings.update', {
|
|
947
|
+
id: from,
|
|
948
|
+
update
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
break;
|
|
952
|
+
case 'message':
|
|
953
|
+
const plaintextNode = getBinaryNodeChild(child, 'plaintext');
|
|
954
|
+
if (plaintextNode?.content) {
|
|
955
|
+
try {
|
|
956
|
+
const contentBuf = typeof plaintextNode.content === 'string'
|
|
957
|
+
? Buffer.from(plaintextNode.content, 'binary')
|
|
958
|
+
: Buffer.from(plaintextNode.content);
|
|
959
|
+
const messageProto = proto.Message.decode(contentBuf);
|
|
960
|
+
const fullMessage = proto.WebMessageInfo.fromObject({
|
|
961
|
+
key: {
|
|
962
|
+
remoteJid: from,
|
|
963
|
+
id: child.attrs.message_id || child.attrs.server_id,
|
|
964
|
+
fromMe: false
|
|
965
|
+
},
|
|
966
|
+
message: messageProto,
|
|
967
|
+
messageTimestamp: +child.attrs.t
|
|
968
|
+
});
|
|
969
|
+
await upsertMessage(fullMessage, 'append');
|
|
970
|
+
logger.info('Processed plaintext newsletter message');
|
|
971
|
+
}
|
|
972
|
+
catch (error) {
|
|
973
|
+
logger.error({ error }, 'Failed to decode plaintext newsletter message');
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
break;
|
|
977
|
+
default:
|
|
978
|
+
logger.warn({ node }, 'Unknown newsletter notification');
|
|
979
|
+
break;
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
// Handles mex newsletter notifications
|
|
983
|
+
async function handleMexNewsletterNotification(node) {
|
|
984
|
+
const mexNode = getBinaryNodeChild(node, 'mex');
|
|
985
|
+
if (!mexNode?.content) {
|
|
986
|
+
logger.warn({ node }, 'Invalid mex newsletter notification');
|
|
987
|
+
return;
|
|
988
|
+
}
|
|
989
|
+
let data;
|
|
990
|
+
try {
|
|
991
|
+
data = JSON.parse(mexNode.content.toString());
|
|
992
|
+
}
|
|
993
|
+
catch (error) {
|
|
994
|
+
logger.error({ err: error, node }, 'Failed to parse mex newsletter notification');
|
|
995
|
+
return;
|
|
996
|
+
}
|
|
997
|
+
const operation = data?.operation;
|
|
998
|
+
const updates = data?.updates;
|
|
999
|
+
if (!updates || !operation) {
|
|
1000
|
+
logger.warn({ data }, 'Invalid mex newsletter notification content');
|
|
1001
|
+
return;
|
|
1002
|
+
}
|
|
1003
|
+
logger.info({ operation, updates }, 'got mex newsletter notification');
|
|
1004
|
+
switch (operation) {
|
|
1005
|
+
case 'NotificationNewsletterUpdate':
|
|
1006
|
+
for (const update of updates) {
|
|
1007
|
+
if (update.jid && update.settings && Object.keys(update.settings).length > 0) {
|
|
1008
|
+
ev.emit('newsletter-settings.update', {
|
|
1009
|
+
id: update.jid,
|
|
1010
|
+
update: update.settings
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
break;
|
|
1015
|
+
case 'NotificationNewsletterAdminPromote':
|
|
1016
|
+
for (const update of updates) {
|
|
1017
|
+
if (update.jid && update.user) {
|
|
1018
|
+
ev.emit('newsletter-participants.update', {
|
|
1019
|
+
id: update.jid,
|
|
1020
|
+
author: node.attrs.from,
|
|
1021
|
+
user: update.user,
|
|
1022
|
+
new_role: 'ADMIN',
|
|
1023
|
+
action: 'promote'
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
break;
|
|
1028
|
+
default:
|
|
1029
|
+
logger.info({ operation, data }, 'Unhandled mex newsletter notification');
|
|
1030
|
+
break;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
906
1033
|
// recv a message
|
|
907
1034
|
ws.on('CB:message', (node) => {
|
|
908
1035
|
processNode('message', node, 'processing message', handleMessage);
|
|
@@ -920,6 +1047,9 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
920
1047
|
handleBadAck(node).catch(error => onUnexpectedError(error, 'handling bad ack'));
|
|
921
1048
|
});
|
|
922
1049
|
ev.on('call', ([call]) => {
|
|
1050
|
+
if (!call) {
|
|
1051
|
+
return;
|
|
1052
|
+
}
|
|
923
1053
|
// missed call + group call notification message generation
|
|
924
1054
|
if (call.status === 'timeout' || (call.status === 'offer' && call.isGroup)) {
|
|
925
1055
|
const msg = {
|
|
@@ -928,22 +1058,22 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
928
1058
|
id: call.id,
|
|
929
1059
|
fromMe: false
|
|
930
1060
|
},
|
|
931
|
-
messageTimestamp:
|
|
1061
|
+
messageTimestamp: unixTimestampSeconds(call.date)
|
|
932
1062
|
};
|
|
933
1063
|
if (call.status === 'timeout') {
|
|
934
1064
|
if (call.isGroup) {
|
|
935
1065
|
msg.messageStubType = call.isVideo
|
|
936
|
-
?
|
|
937
|
-
:
|
|
1066
|
+
? WAMessageStubType.CALL_MISSED_GROUP_VIDEO
|
|
1067
|
+
: WAMessageStubType.CALL_MISSED_GROUP_VOICE;
|
|
938
1068
|
}
|
|
939
1069
|
else {
|
|
940
|
-
msg.messageStubType = call.isVideo ?
|
|
1070
|
+
msg.messageStubType = call.isVideo ? WAMessageStubType.CALL_MISSED_VIDEO : WAMessageStubType.CALL_MISSED_VOICE;
|
|
941
1071
|
}
|
|
942
1072
|
}
|
|
943
1073
|
else {
|
|
944
1074
|
msg.message = { call: { callKey: Buffer.from(call.id) } };
|
|
945
1075
|
}
|
|
946
|
-
const protoMsg =
|
|
1076
|
+
const protoMsg = proto.WebMessageInfo.fromObject(msg);
|
|
947
1077
|
upsertMessage(protoMsg, call.offline ? 'append' : 'notify');
|
|
948
1078
|
}
|
|
949
1079
|
});
|
|
@@ -962,4 +1092,4 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
962
1092
|
requestPlaceholderResend
|
|
963
1093
|
};
|
|
964
1094
|
};
|
|
965
|
-
|
|
1095
|
+
//# sourceMappingURL=messages-recv.js.map
|