@d0v3riz/baileys 6.7.19 → 6.7.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 +1263 -4
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +4633 -0
- package/WAProto/fix-imports.js +29 -0
- package/WAProto/index.d.ts +3212 -122
- package/WAProto/index.js +13516 -4182
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +4 -3
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +50 -54
- 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 +3 -0
- package/lib/Signal/Group/queue-job.d.ts.map +1 -0
- package/lib/Signal/Group/queue-job.js +57 -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 +41 -61
- 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 +15 -27
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +92 -62
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +37 -42
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +31 -24
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +251 -198
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +219 -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 +47 -39
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +91 -82
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +128 -68
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +16 -9
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +79 -49
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +364 -200
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +76 -46
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +144 -120
- 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 +143 -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 +15 -14
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +153 -141
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Socket/usync.d.ts +17 -16
- package/lib/Socket/usync.d.ts.map +1 -0
- package/lib/Socket/usync.js +19 -26
- package/lib/Socket/usync.js.map +1 -0
- package/lib/Types/Auth.d.ts +5 -4
- 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 +14 -8
- package/lib/Types/Chat.d.ts.map +1 -0
- package/lib/Types/Chat.js +8 -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 +38 -11
- 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 +10 -4
- 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 +21 -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 +11 -10
- 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 +14 -2
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +13 -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 +30 -40
- 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 +64 -75
- 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 +195 -194
- 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 +40 -95
- 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 -41
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +6 -6
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +42 -59
- 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 +105 -130
- 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 +14 -55
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +8 -6
- 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 +23 -26
- 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 +6 -10
- 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 +215 -253
- 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 +259 -228
- 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 +6 -5
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +109 -123
- 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 +52 -55
- 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 -27
- 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 +64 -75
- 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 +1280 -19
- 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 +15 -52
- 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 +7 -43
- 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 +31 -39
- 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 -38
- 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 +2257 -2366
- 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 +15 -19
- 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 +8 -11
- 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 +11 -14
- 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 +9 -12
- 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 +9 -13
- 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 +20 -22
- 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 +3 -6
- 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 +34 -32
- 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 +36 -31
- 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,38 +1,36 @@
|
|
|
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, isLidUser, 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 =
|
|
21
|
-
const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, sendPeerDataOperationMessage
|
|
15
|
+
const sock = makeMessagesSocket(config);
|
|
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 =
|
|
24
|
-
const msgRetryCache = config.msgRetryCounterCache ||
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
18
|
+
const retryMutex = makeMutex();
|
|
19
|
+
const msgRetryCache = config.msgRetryCounterCache ||
|
|
20
|
+
new NodeCache({
|
|
21
|
+
stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
|
|
22
|
+
useClones: false
|
|
23
|
+
});
|
|
24
|
+
const callOfferCache = config.callOfferCache ||
|
|
25
|
+
new NodeCache({
|
|
26
|
+
stdTTL: DEFAULT_CACHE_TTLS.CALL_OFFER, // 5 mins
|
|
27
|
+
useClones: false
|
|
28
|
+
});
|
|
29
|
+
const placeholderResendCache = config.placeholderResendCache ||
|
|
30
|
+
new NodeCache({
|
|
31
|
+
stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
|
|
32
|
+
useClones: false
|
|
33
|
+
});
|
|
36
34
|
let sendActiveReceipts = false;
|
|
37
35
|
const sendMessageAck = async ({ tag, attrs, content }, errorCode) => {
|
|
38
36
|
const stanza = {
|
|
@@ -52,39 +50,42 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
52
50
|
if (!!attrs.recipient) {
|
|
53
51
|
stanza.attrs.recipient = attrs.recipient;
|
|
54
52
|
}
|
|
55
|
-
if (!!attrs.type &&
|
|
53
|
+
if (!!attrs.type &&
|
|
54
|
+
(tag !== 'message' || getBinaryNodeChild({ tag, attrs, content }, 'unavailable') || errorCode !== 0)) {
|
|
56
55
|
stanza.attrs.type = attrs.type;
|
|
57
56
|
}
|
|
58
|
-
if (tag === 'message' &&
|
|
57
|
+
if (tag === 'message' && getBinaryNodeChild({ tag, attrs, content }, 'unavailable')) {
|
|
59
58
|
stanza.attrs.from = authState.creds.me.id;
|
|
60
59
|
}
|
|
61
60
|
logger.debug({ recv: { tag, attrs }, sent: stanza.attrs }, 'sent ack');
|
|
62
61
|
await sendNode(stanza);
|
|
63
62
|
};
|
|
64
63
|
const rejectCall = async (callId, callFrom) => {
|
|
65
|
-
const stanza =
|
|
64
|
+
const stanza = {
|
|
66
65
|
tag: 'call',
|
|
67
66
|
attrs: {
|
|
68
67
|
from: authState.creds.me.id,
|
|
69
|
-
to: callFrom
|
|
68
|
+
to: callFrom
|
|
70
69
|
},
|
|
71
|
-
content: [
|
|
70
|
+
content: [
|
|
71
|
+
{
|
|
72
72
|
tag: 'reject',
|
|
73
73
|
attrs: {
|
|
74
74
|
'call-id': callId,
|
|
75
75
|
'call-creator': callFrom,
|
|
76
|
-
count: '0'
|
|
76
|
+
count: '0'
|
|
77
77
|
},
|
|
78
|
-
content: undefined
|
|
79
|
-
}
|
|
80
|
-
|
|
78
|
+
content: undefined
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
};
|
|
81
82
|
await query(stanza);
|
|
82
83
|
};
|
|
83
84
|
const sendRetryRequest = async (node, forceIncludeKeys = false) => {
|
|
84
|
-
const { fullMessage } =
|
|
85
|
+
const { fullMessage } = decodeMessageNode(node, authState.creds.me.id, authState.creds.me.lid || '');
|
|
85
86
|
const { key: msgKey } = fullMessage;
|
|
86
87
|
const msgId = msgKey.id;
|
|
87
|
-
const key = `${msgId}:${msgKey
|
|
88
|
+
const key = `${msgId}:${msgKey?.participant}`;
|
|
88
89
|
let retryCount = msgRetryCache.get(key) || 0;
|
|
89
90
|
if (retryCount >= maxMsgRetryCount) {
|
|
90
91
|
logger.debug({ retryCount, msgId }, 'reached retry limit, clearing');
|
|
@@ -99,7 +100,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
99
100
|
const msgId = await requestPlaceholderResend(msgKey);
|
|
100
101
|
logger.debug(`sendRetryRequest: requested placeholder resend for message ${msgId}`);
|
|
101
102
|
}
|
|
102
|
-
const deviceIdentity =
|
|
103
|
+
const deviceIdentity = encodeSignedDeviceIdentity(account, true);
|
|
103
104
|
await authState.keys.transaction(async () => {
|
|
104
105
|
const receipt = {
|
|
105
106
|
tag: 'receipt',
|
|
@@ -121,7 +122,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
121
122
|
{
|
|
122
123
|
tag: 'registration',
|
|
123
124
|
attrs: {},
|
|
124
|
-
content:
|
|
125
|
+
content: encodeBigEndian(authState.creds.registrationId)
|
|
125
126
|
}
|
|
126
127
|
]
|
|
127
128
|
};
|
|
@@ -132,7 +133,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
132
133
|
receipt.attrs.participant = node.attrs.participant;
|
|
133
134
|
}
|
|
134
135
|
if (retryCount > 1 || forceIncludeKeys) {
|
|
135
|
-
const { update, preKeys } = await
|
|
136
|
+
const { update, preKeys } = await getNextPreKeys(authState, 1);
|
|
136
137
|
const [keyId] = Object.keys(preKeys);
|
|
137
138
|
const key = preKeys[+keyId];
|
|
138
139
|
const content = receipt.content;
|
|
@@ -140,10 +141,10 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
140
141
|
tag: 'keys',
|
|
141
142
|
attrs: {},
|
|
142
143
|
content: [
|
|
143
|
-
{ tag: 'type', attrs: {}, content: Buffer.from(
|
|
144
|
+
{ tag: 'type', attrs: {}, content: Buffer.from(KEY_BUNDLE_TYPE) },
|
|
144
145
|
{ tag: 'identity', attrs: {}, content: identityKey.public },
|
|
145
|
-
|
|
146
|
-
|
|
146
|
+
xmppPreKey(key, +keyId),
|
|
147
|
+
xmppSignedPreKey(signedPreKey),
|
|
147
148
|
{ tag: 'device-identity', attrs: {}, content: deviceIdentity }
|
|
148
149
|
]
|
|
149
150
|
});
|
|
@@ -155,17 +156,17 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
155
156
|
};
|
|
156
157
|
const handleEncryptNotification = async (node) => {
|
|
157
158
|
const from = node.attrs.from;
|
|
158
|
-
if (from ===
|
|
159
|
-
const countChild =
|
|
159
|
+
if (from === S_WHATSAPP_NET) {
|
|
160
|
+
const countChild = getBinaryNodeChild(node, 'count');
|
|
160
161
|
const count = +countChild.attrs.value;
|
|
161
|
-
const shouldUploadMorePreKeys = count <
|
|
162
|
+
const shouldUploadMorePreKeys = count < MIN_PREKEY_COUNT;
|
|
162
163
|
logger.debug({ count, shouldUploadMorePreKeys }, 'recv pre-key count');
|
|
163
164
|
if (shouldUploadMorePreKeys) {
|
|
164
165
|
await uploadPreKeys();
|
|
165
166
|
}
|
|
166
167
|
}
|
|
167
168
|
else {
|
|
168
|
-
const identityNode =
|
|
169
|
+
const identityNode = getBinaryNodeChild(node, 'identity');
|
|
169
170
|
if (identityNode) {
|
|
170
171
|
logger.info({ jid: from }, 'identity changed');
|
|
171
172
|
// not handling right now
|
|
@@ -177,37 +178,40 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
177
178
|
}
|
|
178
179
|
};
|
|
179
180
|
const handleGroupNotification = (participant, child, msg) => {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
switch (child === null || child === void 0 ? void 0 : child.tag) {
|
|
181
|
+
const participantJid = getBinaryNodeChild(child, 'participant')?.attrs?.jid || participant;
|
|
182
|
+
switch (child?.tag) {
|
|
183
183
|
case 'create':
|
|
184
|
-
const metadata =
|
|
185
|
-
msg.messageStubType =
|
|
184
|
+
const metadata = extractGroupMetadata(child);
|
|
185
|
+
msg.messageStubType = WAMessageStubType.GROUP_CREATE;
|
|
186
186
|
msg.messageStubParameters = [metadata.subject];
|
|
187
187
|
msg.key = { participant: metadata.owner };
|
|
188
|
-
ev.emit('chats.upsert', [
|
|
188
|
+
ev.emit('chats.upsert', [
|
|
189
|
+
{
|
|
189
190
|
id: metadata.id,
|
|
190
191
|
name: metadata.subject,
|
|
191
|
-
conversationTimestamp: metadata.creation
|
|
192
|
-
}
|
|
193
|
-
|
|
192
|
+
conversationTimestamp: metadata.creation
|
|
193
|
+
}
|
|
194
|
+
]);
|
|
195
|
+
ev.emit('groups.upsert', [
|
|
196
|
+
{
|
|
194
197
|
...metadata,
|
|
195
198
|
author: participant
|
|
196
|
-
}
|
|
199
|
+
}
|
|
200
|
+
]);
|
|
197
201
|
break;
|
|
198
202
|
case 'ephemeral':
|
|
199
203
|
case 'not_ephemeral':
|
|
200
204
|
msg.message = {
|
|
201
205
|
protocolMessage: {
|
|
202
|
-
type:
|
|
206
|
+
type: proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING,
|
|
203
207
|
ephemeralExpiration: +(child.attrs.expiration || 0)
|
|
204
208
|
}
|
|
205
209
|
};
|
|
206
210
|
break;
|
|
207
211
|
case 'modify':
|
|
208
|
-
const oldNumber =
|
|
212
|
+
const oldNumber = getBinaryNodeChildren(child, 'participant').map(p => p.attrs.jid);
|
|
209
213
|
msg.messageStubParameters = oldNumber || [];
|
|
210
|
-
msg.messageStubType =
|
|
214
|
+
msg.messageStubType = WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER;
|
|
211
215
|
break;
|
|
212
216
|
case 'promote':
|
|
213
217
|
case 'demote':
|
|
@@ -215,74 +219,73 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
215
219
|
case 'add':
|
|
216
220
|
case 'leave':
|
|
217
221
|
const stubType = `GROUP_PARTICIPANT_${child.tag.toUpperCase()}`;
|
|
218
|
-
msg.messageStubType =
|
|
219
|
-
const participants =
|
|
222
|
+
msg.messageStubType = WAMessageStubType[stubType];
|
|
223
|
+
const participants = getBinaryNodeChildren(child, 'participant').map(p => p.attrs.jid);
|
|
220
224
|
if (participants.length === 1 &&
|
|
221
225
|
// if recv. "remove" message and sender removed themselves
|
|
222
226
|
// mark as left
|
|
223
|
-
|
|
227
|
+
areJidsSameUser(participants[0], participant) &&
|
|
224
228
|
child.tag === 'remove') {
|
|
225
|
-
msg.messageStubType =
|
|
229
|
+
msg.messageStubType = WAMessageStubType.GROUP_PARTICIPANT_LEAVE;
|
|
226
230
|
}
|
|
227
231
|
msg.messageStubParameters = participants;
|
|
228
232
|
break;
|
|
229
233
|
case 'subject':
|
|
230
|
-
msg.messageStubType =
|
|
234
|
+
msg.messageStubType = WAMessageStubType.GROUP_CHANGE_SUBJECT;
|
|
231
235
|
msg.messageStubParameters = [child.attrs.subject];
|
|
232
236
|
break;
|
|
233
237
|
case 'description':
|
|
234
|
-
const description =
|
|
235
|
-
msg.messageStubType =
|
|
238
|
+
const description = getBinaryNodeChild(child, 'body')?.content?.toString();
|
|
239
|
+
msg.messageStubType = WAMessageStubType.GROUP_CHANGE_DESCRIPTION;
|
|
236
240
|
msg.messageStubParameters = description ? [description] : undefined;
|
|
237
241
|
break;
|
|
238
242
|
case 'announcement':
|
|
239
243
|
case 'not_announcement':
|
|
240
|
-
msg.messageStubType =
|
|
241
|
-
msg.messageStubParameters = [
|
|
244
|
+
msg.messageStubType = WAMessageStubType.GROUP_CHANGE_ANNOUNCE;
|
|
245
|
+
msg.messageStubParameters = [child.tag === 'announcement' ? 'on' : 'off'];
|
|
242
246
|
break;
|
|
243
247
|
case 'locked':
|
|
244
248
|
case 'unlocked':
|
|
245
|
-
msg.messageStubType =
|
|
246
|
-
msg.messageStubParameters = [
|
|
249
|
+
msg.messageStubType = WAMessageStubType.GROUP_CHANGE_RESTRICT;
|
|
250
|
+
msg.messageStubParameters = [child.tag === 'locked' ? 'on' : 'off'];
|
|
247
251
|
break;
|
|
248
252
|
case 'invite':
|
|
249
|
-
msg.messageStubType =
|
|
253
|
+
msg.messageStubType = WAMessageStubType.GROUP_CHANGE_INVITE_LINK;
|
|
250
254
|
msg.messageStubParameters = [child.attrs.code];
|
|
251
255
|
break;
|
|
252
256
|
case 'member_add_mode':
|
|
253
257
|
const addMode = child.content;
|
|
254
258
|
if (addMode) {
|
|
255
|
-
msg.messageStubType =
|
|
259
|
+
msg.messageStubType = WAMessageStubType.GROUP_MEMBER_ADD_MODE;
|
|
256
260
|
msg.messageStubParameters = [addMode.toString()];
|
|
257
261
|
}
|
|
258
262
|
break;
|
|
259
263
|
case 'membership_approval_mode':
|
|
260
|
-
const approvalMode =
|
|
264
|
+
const approvalMode = getBinaryNodeChild(child, 'group_join');
|
|
261
265
|
if (approvalMode) {
|
|
262
|
-
msg.messageStubType =
|
|
266
|
+
msg.messageStubType = WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE;
|
|
263
267
|
msg.messageStubParameters = [approvalMode.attrs.state];
|
|
264
268
|
}
|
|
265
269
|
break;
|
|
266
270
|
case 'created_membership_requests':
|
|
267
|
-
msg.messageStubType =
|
|
271
|
+
msg.messageStubType = WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
|
|
268
272
|
msg.messageStubParameters = [participantJid, 'created', child.attrs.request_method];
|
|
269
273
|
break;
|
|
270
274
|
case 'revoked_membership_requests':
|
|
271
|
-
const isDenied =
|
|
272
|
-
msg.messageStubType =
|
|
275
|
+
const isDenied = areJidsSameUser(participantJid, participant);
|
|
276
|
+
msg.messageStubType = WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
|
|
273
277
|
msg.messageStubParameters = [participantJid, isDenied ? 'revoked' : 'rejected'];
|
|
274
278
|
break;
|
|
275
279
|
}
|
|
276
280
|
};
|
|
277
281
|
const processNotification = async (node) => {
|
|
278
|
-
var _a, _b, _c;
|
|
279
282
|
const result = {};
|
|
280
|
-
const [child] =
|
|
283
|
+
const [child] = getAllBinaryNodeChildren(node);
|
|
281
284
|
const nodeType = node.attrs.type;
|
|
282
|
-
const from =
|
|
285
|
+
const from = jidNormalizedUser(node.attrs.from);
|
|
283
286
|
switch (nodeType) {
|
|
284
287
|
case 'privacy_token':
|
|
285
|
-
const tokenList =
|
|
288
|
+
const tokenList = getBinaryNodeChildren(child, 'token');
|
|
286
289
|
for (const { attrs, content } of tokenList) {
|
|
287
290
|
const jid = attrs.jid;
|
|
288
291
|
ev.emit('chats.update', [
|
|
@@ -294,47 +297,55 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
294
297
|
logger.debug({ jid }, 'got privacy token update');
|
|
295
298
|
}
|
|
296
299
|
break;
|
|
300
|
+
case 'newsletter':
|
|
301
|
+
await handleNewsletterNotification(node);
|
|
302
|
+
break;
|
|
303
|
+
case 'mex':
|
|
304
|
+
await handleMexNewsletterNotification(node);
|
|
305
|
+
break;
|
|
297
306
|
case 'w:gp2':
|
|
298
307
|
handleGroupNotification(node.attrs.participant, child, result);
|
|
299
308
|
break;
|
|
300
309
|
case 'mediaretry':
|
|
301
|
-
const event =
|
|
310
|
+
const event = decodeMediaRetryNode(node);
|
|
302
311
|
ev.emit('messages.media-update', [event]);
|
|
303
312
|
break;
|
|
304
313
|
case 'encrypt':
|
|
305
314
|
await handleEncryptNotification(node);
|
|
306
315
|
break;
|
|
307
316
|
case 'devices':
|
|
308
|
-
const devices =
|
|
309
|
-
if (
|
|
317
|
+
const devices = getBinaryNodeChildren(child, 'device');
|
|
318
|
+
if (areJidsSameUser(child.attrs.jid, authState.creds.me.id)) {
|
|
310
319
|
const deviceJids = devices.map(d => d.attrs.jid);
|
|
311
320
|
logger.info({ deviceJids }, 'got my own devices');
|
|
312
321
|
}
|
|
313
322
|
break;
|
|
314
323
|
case 'server_sync':
|
|
315
|
-
const update =
|
|
324
|
+
const update = getBinaryNodeChild(node, 'collection');
|
|
316
325
|
if (update) {
|
|
317
326
|
const name = update.attrs.name;
|
|
318
327
|
await resyncAppState([name], false);
|
|
319
328
|
}
|
|
320
329
|
break;
|
|
321
330
|
case 'picture':
|
|
322
|
-
const setPicture =
|
|
323
|
-
const delPicture =
|
|
324
|
-
ev.emit('contacts.update', [
|
|
325
|
-
|
|
331
|
+
const setPicture = getBinaryNodeChild(node, 'set');
|
|
332
|
+
const delPicture = getBinaryNodeChild(node, 'delete');
|
|
333
|
+
ev.emit('contacts.update', [
|
|
334
|
+
{
|
|
335
|
+
id: jidNormalizedUser(node?.attrs?.from) || (setPicture || delPicture)?.attrs?.hash || '',
|
|
326
336
|
imgUrl: setPicture ? 'changed' : 'removed'
|
|
327
|
-
}
|
|
328
|
-
|
|
337
|
+
}
|
|
338
|
+
]);
|
|
339
|
+
if (isJidGroup(from)) {
|
|
329
340
|
const node = setPicture || delPicture;
|
|
330
|
-
result.messageStubType =
|
|
341
|
+
result.messageStubType = WAMessageStubType.GROUP_CHANGE_ICON;
|
|
331
342
|
if (setPicture) {
|
|
332
343
|
result.messageStubParameters = [setPicture.attrs.id];
|
|
333
344
|
}
|
|
334
|
-
result.participant = node
|
|
345
|
+
result.participant = node?.attrs.author;
|
|
335
346
|
result.key = {
|
|
336
|
-
...result.key || {},
|
|
337
|
-
participant: setPicture
|
|
347
|
+
...(result.key || {}),
|
|
348
|
+
participant: setPicture?.attrs.author
|
|
338
349
|
};
|
|
339
350
|
}
|
|
340
351
|
break;
|
|
@@ -348,44 +359,48 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
348
359
|
...authState.creds.accountSettings,
|
|
349
360
|
defaultDisappearingMode: {
|
|
350
361
|
ephemeralExpiration: newDuration,
|
|
351
|
-
ephemeralSettingTimestamp: timestamp
|
|
352
|
-
}
|
|
362
|
+
ephemeralSettingTimestamp: timestamp
|
|
363
|
+
}
|
|
353
364
|
}
|
|
354
365
|
});
|
|
355
366
|
}
|
|
356
367
|
else if (child.tag === 'blocklist') {
|
|
357
|
-
const blocklists =
|
|
368
|
+
const blocklists = getBinaryNodeChildren(child, 'item');
|
|
358
369
|
for (const { attrs } of blocklists) {
|
|
359
370
|
const blocklist = [attrs.jid];
|
|
360
|
-
const type =
|
|
371
|
+
const type = attrs.action === 'block' ? 'add' : 'remove';
|
|
361
372
|
ev.emit('blocklist.update', { blocklist, type });
|
|
362
373
|
}
|
|
363
374
|
}
|
|
364
375
|
break;
|
|
365
376
|
case 'link_code_companion_reg':
|
|
366
|
-
const linkCodeCompanionReg =
|
|
367
|
-
const ref = toRequiredBuffer(
|
|
368
|
-
const primaryIdentityPublicKey = toRequiredBuffer(
|
|
369
|
-
const primaryEphemeralPublicKeyWrapped = toRequiredBuffer(
|
|
377
|
+
const linkCodeCompanionReg = getBinaryNodeChild(node, 'link_code_companion_reg');
|
|
378
|
+
const ref = toRequiredBuffer(getBinaryNodeChildBuffer(linkCodeCompanionReg, 'link_code_pairing_ref'));
|
|
379
|
+
const primaryIdentityPublicKey = toRequiredBuffer(getBinaryNodeChildBuffer(linkCodeCompanionReg, 'primary_identity_pub'));
|
|
380
|
+
const primaryEphemeralPublicKeyWrapped = toRequiredBuffer(getBinaryNodeChildBuffer(linkCodeCompanionReg, 'link_code_pairing_wrapped_primary_ephemeral_pub'));
|
|
370
381
|
const codePairingPublicKey = await decipherLinkPublicKey(primaryEphemeralPublicKeyWrapped);
|
|
371
|
-
const companionSharedKey =
|
|
372
|
-
const random =
|
|
373
|
-
const linkCodeSalt =
|
|
374
|
-
const linkCodePairingExpanded = await
|
|
382
|
+
const companionSharedKey = Curve.sharedKey(authState.creds.pairingEphemeralKeyPair.private, codePairingPublicKey);
|
|
383
|
+
const random = randomBytes(32);
|
|
384
|
+
const linkCodeSalt = randomBytes(32);
|
|
385
|
+
const linkCodePairingExpanded = await hkdf(companionSharedKey, 32, {
|
|
375
386
|
salt: linkCodeSalt,
|
|
376
387
|
info: 'link_code_pairing_key_bundle_encryption_key'
|
|
377
388
|
});
|
|
378
|
-
const encryptPayload = Buffer.concat([
|
|
379
|
-
|
|
380
|
-
|
|
389
|
+
const encryptPayload = Buffer.concat([
|
|
390
|
+
Buffer.from(authState.creds.signedIdentityKey.public),
|
|
391
|
+
primaryIdentityPublicKey,
|
|
392
|
+
random
|
|
393
|
+
]);
|
|
394
|
+
const encryptIv = randomBytes(12);
|
|
395
|
+
const encrypted = aesEncryptGCM(encryptPayload, linkCodePairingExpanded, encryptIv, Buffer.alloc(0));
|
|
381
396
|
const encryptedPayload = Buffer.concat([linkCodeSalt, encryptIv, encrypted]);
|
|
382
|
-
const identitySharedKey =
|
|
397
|
+
const identitySharedKey = Curve.sharedKey(authState.creds.signedIdentityKey.private, primaryIdentityPublicKey);
|
|
383
398
|
const identityPayload = Buffer.concat([companionSharedKey, identitySharedKey, random]);
|
|
384
|
-
authState.creds.advSecretKey = (await
|
|
399
|
+
authState.creds.advSecretKey = (await hkdf(identityPayload, 32, { info: 'adv_secret' })).toString('base64');
|
|
385
400
|
await query({
|
|
386
401
|
tag: 'iq',
|
|
387
402
|
attrs: {
|
|
388
|
-
to:
|
|
403
|
+
to: S_WHATSAPP_NET,
|
|
389
404
|
type: 'set',
|
|
390
405
|
id: sock.generateMessageTag(),
|
|
391
406
|
xmlns: 'md'
|
|
@@ -395,7 +410,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
395
410
|
tag: 'link_code_companion_reg',
|
|
396
411
|
attrs: {
|
|
397
412
|
jid: authState.creds.me.id,
|
|
398
|
-
stage: 'companion_finish'
|
|
413
|
+
stage: 'companion_finish'
|
|
399
414
|
},
|
|
400
415
|
content: [
|
|
401
416
|
{
|
|
@@ -427,14 +442,14 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
427
442
|
async function decipherLinkPublicKey(data) {
|
|
428
443
|
const buffer = toRequiredBuffer(data);
|
|
429
444
|
const salt = buffer.slice(0, 32);
|
|
430
|
-
const secretKey = await
|
|
445
|
+
const secretKey = await derivePairingCodeKey(authState.creds.pairingCode, salt);
|
|
431
446
|
const iv = buffer.slice(32, 48);
|
|
432
447
|
const payload = buffer.slice(48, 80);
|
|
433
|
-
return
|
|
448
|
+
return aesDecryptCTR(payload, secretKey, iv);
|
|
434
449
|
}
|
|
435
450
|
function toRequiredBuffer(data) {
|
|
436
451
|
if (data === undefined) {
|
|
437
|
-
throw new
|
|
452
|
+
throw new Boom('Invalid buffer', { statusCode: 400 });
|
|
438
453
|
}
|
|
439
454
|
return data instanceof Buffer ? data : Buffer.from(data);
|
|
440
455
|
}
|
|
@@ -449,7 +464,6 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
449
464
|
msgRetryCache.set(key, newValue);
|
|
450
465
|
};
|
|
451
466
|
const sendMessagesAgain = async (key, ids, retryNode) => {
|
|
452
|
-
var _a;
|
|
453
467
|
// todo: implement a cache to store the last 256 sent messages (copy whatsmeow)
|
|
454
468
|
const msgs = await Promise.all(ids.map(id => getMessage({ ...key, id })));
|
|
455
469
|
const remoteJid = key.remoteJid;
|
|
@@ -457,9 +471,9 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
457
471
|
// if it's the primary jid sending the request
|
|
458
472
|
// just re-send the message to everyone
|
|
459
473
|
// prevents the first message decryption failure
|
|
460
|
-
const sendToAll = !
|
|
474
|
+
const sendToAll = !jidDecode(participant)?.device;
|
|
461
475
|
await assertSessions([participant], true);
|
|
462
|
-
if (
|
|
476
|
+
if (isJidGroup(remoteJid)) {
|
|
463
477
|
await authState.keys.set({ 'sender-key-memory': { [remoteJid]: null } });
|
|
464
478
|
}
|
|
465
479
|
logger.debug({ participant, sendToAll }, 'forced new session for retry recp');
|
|
@@ -484,12 +498,11 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
484
498
|
}
|
|
485
499
|
};
|
|
486
500
|
const handleReceipt = async (node) => {
|
|
487
|
-
var _a, _b;
|
|
488
501
|
const { attrs, content } = node;
|
|
489
502
|
const isLid = attrs.from.includes('lid');
|
|
490
|
-
const isNodeFromMe =
|
|
491
|
-
const remoteJid = !isNodeFromMe ||
|
|
492
|
-
const fromMe = !attrs.recipient || (attrs.type === 'retry' && isNodeFromMe);
|
|
503
|
+
const isNodeFromMe = areJidsSameUser(attrs.participant || attrs.from, isLid ? authState.creds.me?.lid : authState.creds.me?.id);
|
|
504
|
+
const remoteJid = !isNodeFromMe || isJidGroup(attrs.from) ? attrs.from : attrs.recipient;
|
|
505
|
+
const fromMe = !attrs.recipient || ((attrs.type === 'retry' || attrs.type === 'sender') && isNodeFromMe);
|
|
493
506
|
const key = {
|
|
494
507
|
remoteJid,
|
|
495
508
|
id: '',
|
|
@@ -503,26 +516,24 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
503
516
|
}
|
|
504
517
|
const ids = [attrs.id];
|
|
505
518
|
if (Array.isArray(content)) {
|
|
506
|
-
const items =
|
|
519
|
+
const items = getBinaryNodeChildren(content[0], 'item');
|
|
507
520
|
ids.push(...items.map(i => i.attrs.id));
|
|
508
521
|
}
|
|
509
522
|
try {
|
|
510
523
|
await Promise.all([
|
|
511
524
|
processingMutex.mutex(async () => {
|
|
512
|
-
const status =
|
|
525
|
+
const status = getStatusFromReceiptType(attrs.type);
|
|
513
526
|
if (typeof status !== 'undefined' &&
|
|
514
|
-
(
|
|
515
527
|
// basically, we only want to know when a message from us has been delivered to/read by the other person
|
|
516
528
|
// or another device of ours has read some messages
|
|
517
|
-
status >=
|
|
518
|
-
|
|
519
|
-
if ((0, WABinary_1.isJidGroup)(remoteJid) || (0, WABinary_1.isJidStatusBroadcast)(remoteJid)) {
|
|
529
|
+
(status >= proto.WebMessageInfo.Status.SERVER_ACK || !isNodeFromMe)) {
|
|
530
|
+
if (isJidGroup(remoteJid) || isJidStatusBroadcast(remoteJid)) {
|
|
520
531
|
if (attrs.participant) {
|
|
521
|
-
const updateKey = status ===
|
|
532
|
+
const updateKey = status === proto.WebMessageInfo.Status.DELIVERY_ACK ? 'receiptTimestamp' : 'readTimestamp';
|
|
522
533
|
ev.emit('message-receipt.update', ids.map(id => ({
|
|
523
534
|
key: { ...key, id },
|
|
524
535
|
receipt: {
|
|
525
|
-
userJid:
|
|
536
|
+
userJid: jidNormalizedUser(attrs.participant),
|
|
526
537
|
[updateKey]: +attrs.t
|
|
527
538
|
}
|
|
528
539
|
})));
|
|
@@ -538,7 +549,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
538
549
|
if (attrs.type === 'retry') {
|
|
539
550
|
// correctly set who is asking for the retry
|
|
540
551
|
key.participant = key.participant || attrs.from;
|
|
541
|
-
const retryNode =
|
|
552
|
+
const retryNode = getBinaryNodeChild(node, 'retry');
|
|
542
553
|
if (willSendMessageAgain(ids[0], key.participant)) {
|
|
543
554
|
if (key.fromMe) {
|
|
544
555
|
try {
|
|
@@ -574,10 +585,9 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
574
585
|
try {
|
|
575
586
|
await Promise.all([
|
|
576
587
|
processingMutex.mutex(async () => {
|
|
577
|
-
var _a;
|
|
578
588
|
const msg = await processNotification(node);
|
|
579
589
|
if (msg) {
|
|
580
|
-
const fromMe =
|
|
590
|
+
const fromMe = areJidsSameUser(node.attrs.participant || remoteJid, authState.creds.me.id);
|
|
581
591
|
msg.key = {
|
|
582
592
|
remoteJid,
|
|
583
593
|
fromMe,
|
|
@@ -585,9 +595,9 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
585
595
|
id: node.attrs.id,
|
|
586
596
|
...(msg.key || {})
|
|
587
597
|
};
|
|
588
|
-
|
|
598
|
+
msg.participant ?? (msg.participant = node.attrs.participant);
|
|
589
599
|
msg.messageTimestamp = +node.attrs.t;
|
|
590
|
-
const fullMsg =
|
|
600
|
+
const fullMsg = proto.WebMessageInfo.fromObject(msg);
|
|
591
601
|
await upsertMessage(fullMsg, 'append');
|
|
592
602
|
}
|
|
593
603
|
})
|
|
@@ -598,13 +608,12 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
598
608
|
}
|
|
599
609
|
};
|
|
600
610
|
const handleMessage = async (node) => {
|
|
601
|
-
var _a, _b, _c;
|
|
602
611
|
if (shouldIgnoreJid(node.attrs.from) && node.attrs.from !== '@s.whatsapp.net') {
|
|
603
612
|
logger.debug({ key: node.attrs.key }, 'ignored message');
|
|
604
613
|
await sendMessageAck(node);
|
|
605
614
|
return;
|
|
606
615
|
}
|
|
607
|
-
const encNode =
|
|
616
|
+
const encNode = getBinaryNodeChild(node, 'enc');
|
|
608
617
|
// TODO: temporary fix for crashes and issues resulting of failed msmsg decryption
|
|
609
618
|
if (encNode && encNode.attrs.type === 'msmsg') {
|
|
610
619
|
logger.debug({ key: node.attrs.key }, 'ignored msmsg');
|
|
@@ -612,9 +621,9 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
612
621
|
return;
|
|
613
622
|
}
|
|
614
623
|
let response;
|
|
615
|
-
if (
|
|
624
|
+
if (getBinaryNodeChild(node, 'unavailable') && !encNode) {
|
|
616
625
|
await sendMessageAck(node);
|
|
617
|
-
const { key } =
|
|
626
|
+
const { key } = decodeMessageNode(node, authState.creds.me.id, authState.creds.me.lid || '').fullMessage;
|
|
618
627
|
response = await requestPlaceholderResend(key);
|
|
619
628
|
if (response === 'RESOLVED') {
|
|
620
629
|
return;
|
|
@@ -626,32 +635,32 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
626
635
|
placeholderResendCache.del(node.attrs.id);
|
|
627
636
|
}
|
|
628
637
|
}
|
|
629
|
-
const { fullMessage: msg, category, author, decrypt } =
|
|
630
|
-
if (response &&
|
|
631
|
-
msg.messageStubParameters = [
|
|
638
|
+
const { fullMessage: msg, category, author, decrypt } = decryptMessageNode(node, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, logger);
|
|
639
|
+
if (response && msg?.messageStubParameters?.[0] === NO_MESSAGE_FOUND_ERROR_TEXT) {
|
|
640
|
+
msg.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT, response];
|
|
632
641
|
}
|
|
633
|
-
if (
|
|
642
|
+
if (msg.message?.protocolMessage?.type === proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER &&
|
|
643
|
+
node.attrs.sender_pn) {
|
|
634
644
|
ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn });
|
|
635
645
|
}
|
|
636
646
|
try {
|
|
637
647
|
await Promise.all([
|
|
638
648
|
processingMutex.mutex(async () => {
|
|
639
|
-
var _a;
|
|
640
649
|
await decrypt();
|
|
641
650
|
// message failed to decrypt
|
|
642
|
-
if (msg.messageStubType ===
|
|
643
|
-
if (
|
|
644
|
-
return sendMessageAck(node,
|
|
651
|
+
if (msg.messageStubType === proto.WebMessageInfo.StubType.CIPHERTEXT) {
|
|
652
|
+
if (msg?.messageStubParameters?.[0] === MISSING_KEYS_ERROR_TEXT) {
|
|
653
|
+
return sendMessageAck(node, NACK_REASONS.ParsingError);
|
|
645
654
|
}
|
|
646
655
|
retryMutex.mutex(async () => {
|
|
647
656
|
if (ws.isOpen) {
|
|
648
|
-
if (
|
|
657
|
+
if (getBinaryNodeChild(node, 'unavailable')) {
|
|
649
658
|
return;
|
|
650
659
|
}
|
|
651
|
-
const encNode =
|
|
660
|
+
const encNode = getBinaryNodeChild(node, 'enc');
|
|
652
661
|
await sendRetryRequest(node, !encNode);
|
|
653
662
|
if (retryRequestDelayMs) {
|
|
654
|
-
await
|
|
663
|
+
await delay(retryRequestDelayMs);
|
|
655
664
|
}
|
|
656
665
|
}
|
|
657
666
|
else {
|
|
@@ -663,13 +672,15 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
663
672
|
// no type in the receipt => message delivered
|
|
664
673
|
let type = undefined;
|
|
665
674
|
let participant = msg.key.participant;
|
|
666
|
-
if (category === 'peer') {
|
|
675
|
+
if (category === 'peer') {
|
|
676
|
+
// special peer message
|
|
667
677
|
type = 'peer_msg';
|
|
668
678
|
}
|
|
669
|
-
else if (msg.key.fromMe) {
|
|
679
|
+
else if (msg.key.fromMe) {
|
|
680
|
+
// message was sent by us from a different device
|
|
670
681
|
type = 'sender';
|
|
671
682
|
// need to specially handle this case
|
|
672
|
-
if (
|
|
683
|
+
if (isJidUser(msg.key.remoteJid)) {
|
|
673
684
|
participant = author;
|
|
674
685
|
}
|
|
675
686
|
}
|
|
@@ -678,13 +689,13 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
678
689
|
}
|
|
679
690
|
await sendReceipt(msg.key.remoteJid, participant, [msg.key.id], type);
|
|
680
691
|
// send ack for history message
|
|
681
|
-
const isAnyHistoryMsg =
|
|
692
|
+
const isAnyHistoryMsg = getHistoryMsg(msg.message);
|
|
682
693
|
if (isAnyHistoryMsg) {
|
|
683
|
-
const jid =
|
|
694
|
+
const jid = jidNormalizedUser(msg.key.remoteJid);
|
|
684
695
|
await sendReceipt(jid, undefined, [msg.key.id], 'hist_sync');
|
|
685
696
|
}
|
|
686
697
|
}
|
|
687
|
-
|
|
698
|
+
cleanMessage(msg, authState.creds.me.id);
|
|
688
699
|
await sendMessageAck(node);
|
|
689
700
|
await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify');
|
|
690
701
|
})
|
|
@@ -695,9 +706,8 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
695
706
|
}
|
|
696
707
|
};
|
|
697
708
|
const fetchMessageHistory = async (count, oldestMsgKey, oldestMsgTimestamp) => {
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
throw new boom_1.Boom('Not authenticated');
|
|
709
|
+
if (!authState.creds.me?.id) {
|
|
710
|
+
throw new Boom('Not authenticated');
|
|
701
711
|
}
|
|
702
712
|
const pdoMessage = {
|
|
703
713
|
historySyncOnDemandRequest: {
|
|
@@ -707,57 +717,77 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
707
717
|
oldestMsgTimestampMs: oldestMsgTimestamp,
|
|
708
718
|
onDemandMsgCount: count
|
|
709
719
|
},
|
|
710
|
-
peerDataOperationRequestType:
|
|
720
|
+
peerDataOperationRequestType: proto.Message.PeerDataOperationRequestType.HISTORY_SYNC_ON_DEMAND
|
|
711
721
|
};
|
|
712
722
|
return sendPeerDataOperationMessage(pdoMessage);
|
|
713
723
|
};
|
|
714
724
|
const requestPlaceholderResend = async (messageKey) => {
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
throw new boom_1.Boom('Not authenticated');
|
|
725
|
+
if (!authState.creds.me?.id) {
|
|
726
|
+
throw new Boom('Not authenticated');
|
|
718
727
|
}
|
|
719
|
-
if (placeholderResendCache.get(messageKey
|
|
728
|
+
if (placeholderResendCache.get(messageKey?.id)) {
|
|
720
729
|
logger.debug({ messageKey }, 'already requested resend');
|
|
721
730
|
return;
|
|
722
731
|
}
|
|
723
732
|
else {
|
|
724
|
-
placeholderResendCache.set(messageKey
|
|
733
|
+
placeholderResendCache.set(messageKey?.id, true);
|
|
725
734
|
}
|
|
726
|
-
await
|
|
727
|
-
if (!placeholderResendCache.get(messageKey
|
|
735
|
+
await delay(5000);
|
|
736
|
+
if (!placeholderResendCache.get(messageKey?.id)) {
|
|
728
737
|
logger.debug({ messageKey }, 'message received while resend requested');
|
|
729
738
|
return 'RESOLVED';
|
|
730
739
|
}
|
|
731
740
|
const pdoMessage = {
|
|
732
|
-
placeholderMessageResendRequest: [
|
|
741
|
+
placeholderMessageResendRequest: [
|
|
742
|
+
{
|
|
733
743
|
messageKey
|
|
734
|
-
}
|
|
735
|
-
|
|
744
|
+
}
|
|
745
|
+
],
|
|
746
|
+
peerDataOperationRequestType: proto.Message.PeerDataOperationRequestType.PLACEHOLDER_MESSAGE_RESEND
|
|
736
747
|
};
|
|
737
748
|
setTimeout(() => {
|
|
738
|
-
if (placeholderResendCache.get(messageKey
|
|
749
|
+
if (placeholderResendCache.get(messageKey?.id)) {
|
|
739
750
|
logger.debug({ messageKey }, 'PDO message without response after 15 seconds. Phone possibly offline');
|
|
740
|
-
placeholderResendCache.del(messageKey
|
|
751
|
+
placeholderResendCache.del(messageKey?.id);
|
|
741
752
|
}
|
|
742
753
|
}, 15000);
|
|
743
754
|
return sendPeerDataOperationMessage(pdoMessage);
|
|
744
755
|
};
|
|
745
756
|
const handleCall = async (node) => {
|
|
757
|
+
let status;
|
|
746
758
|
const { attrs } = node;
|
|
747
|
-
const [infoChild] =
|
|
759
|
+
const [infoChild] = getAllBinaryNodeChildren(node);
|
|
760
|
+
if (!infoChild) {
|
|
761
|
+
throw new Boom('Missing call info in call node');
|
|
762
|
+
}
|
|
748
763
|
const callId = infoChild.attrs['call-id'];
|
|
749
764
|
const from = infoChild.attrs.from || infoChild.attrs['call-creator'];
|
|
750
|
-
|
|
765
|
+
status = getCallStatusFromNode(infoChild);
|
|
766
|
+
if (isLidUser(from) && infoChild.tag === 'relaylatency') {
|
|
767
|
+
const verify = callOfferCache.get(callId);
|
|
768
|
+
if (!verify) {
|
|
769
|
+
status = 'offer';
|
|
770
|
+
const callLid = {
|
|
771
|
+
chatId: attrs.from,
|
|
772
|
+
from,
|
|
773
|
+
id: callId,
|
|
774
|
+
date: new Date(+attrs.t * 1000),
|
|
775
|
+
offline: !!attrs.offline,
|
|
776
|
+
status
|
|
777
|
+
};
|
|
778
|
+
callOfferCache.set(callId, callLid);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
751
781
|
const call = {
|
|
752
782
|
chatId: attrs.from,
|
|
753
783
|
from,
|
|
754
784
|
id: callId,
|
|
755
785
|
date: new Date(+attrs.t * 1000),
|
|
756
786
|
offline: !!attrs.offline,
|
|
757
|
-
status
|
|
787
|
+
status
|
|
758
788
|
};
|
|
759
789
|
if (status === 'offer') {
|
|
760
|
-
call.isVideo = !!
|
|
790
|
+
call.isVideo = !!getBinaryNodeChild(infoChild, 'video');
|
|
761
791
|
call.isGroup = infoChild.attrs.type === 'group' || !!infoChild.attrs['group-jid'];
|
|
762
792
|
call.groupJid = infoChild.attrs['group-jid'];
|
|
763
793
|
callOfferCache.set(call.id, call);
|
|
@@ -798,10 +828,8 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
798
828
|
{
|
|
799
829
|
key,
|
|
800
830
|
update: {
|
|
801
|
-
status:
|
|
802
|
-
messageStubParameters: [
|
|
803
|
-
attrs.error
|
|
804
|
-
]
|
|
831
|
+
status: WAMessageStatus.ERROR,
|
|
832
|
+
messageStubParameters: [attrs.error]
|
|
805
833
|
}
|
|
806
834
|
}
|
|
807
835
|
]);
|
|
@@ -814,8 +842,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
814
842
|
await execTask();
|
|
815
843
|
ev.flush();
|
|
816
844
|
function execTask() {
|
|
817
|
-
return exec(node, false)
|
|
818
|
-
.catch(err => onUnexpectedError(err, identifier));
|
|
845
|
+
return exec(node, false).catch(err => onUnexpectedError(err, identifier));
|
|
819
846
|
}
|
|
820
847
|
};
|
|
821
848
|
const makeOfflineNodeProcessor = () => {
|
|
@@ -859,6 +886,139 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
859
886
|
processNodeWithBuffer(node, identifier, exec);
|
|
860
887
|
}
|
|
861
888
|
};
|
|
889
|
+
// Handles newsletter notifications
|
|
890
|
+
async function handleNewsletterNotification(node) {
|
|
891
|
+
const from = node.attrs.from;
|
|
892
|
+
const child = getAllBinaryNodeChildren(node)[0];
|
|
893
|
+
const author = node.attrs.participant;
|
|
894
|
+
logger.info({ from, child }, 'got newsletter notification');
|
|
895
|
+
switch (child.tag) {
|
|
896
|
+
case 'reaction':
|
|
897
|
+
const reactionUpdate = {
|
|
898
|
+
id: from,
|
|
899
|
+
server_id: child.attrs.message_id,
|
|
900
|
+
reaction: {
|
|
901
|
+
code: getBinaryNodeChildString(child, 'reaction'),
|
|
902
|
+
count: 1
|
|
903
|
+
}
|
|
904
|
+
};
|
|
905
|
+
ev.emit('newsletter.reaction', reactionUpdate);
|
|
906
|
+
break;
|
|
907
|
+
case 'view':
|
|
908
|
+
const viewUpdate = {
|
|
909
|
+
id: from,
|
|
910
|
+
server_id: child.attrs.message_id,
|
|
911
|
+
count: parseInt(child.content?.toString() || '0', 10)
|
|
912
|
+
};
|
|
913
|
+
ev.emit('newsletter.view', viewUpdate);
|
|
914
|
+
break;
|
|
915
|
+
case 'participant':
|
|
916
|
+
const participantUpdate = {
|
|
917
|
+
id: from,
|
|
918
|
+
author,
|
|
919
|
+
user: child.attrs.jid,
|
|
920
|
+
action: child.attrs.action,
|
|
921
|
+
new_role: child.attrs.role
|
|
922
|
+
};
|
|
923
|
+
ev.emit('newsletter-participants.update', participantUpdate);
|
|
924
|
+
break;
|
|
925
|
+
case 'update':
|
|
926
|
+
const settingsNode = getBinaryNodeChild(child, 'settings');
|
|
927
|
+
if (settingsNode) {
|
|
928
|
+
const update = {};
|
|
929
|
+
const nameNode = getBinaryNodeChild(settingsNode, 'name');
|
|
930
|
+
if (nameNode?.content)
|
|
931
|
+
update.name = nameNode.content.toString();
|
|
932
|
+
const descriptionNode = getBinaryNodeChild(settingsNode, 'description');
|
|
933
|
+
if (descriptionNode?.content)
|
|
934
|
+
update.description = descriptionNode.content.toString();
|
|
935
|
+
ev.emit('newsletter-settings.update', {
|
|
936
|
+
id: from,
|
|
937
|
+
update
|
|
938
|
+
});
|
|
939
|
+
}
|
|
940
|
+
break;
|
|
941
|
+
case 'message':
|
|
942
|
+
const plaintextNode = getBinaryNodeChild(child, 'plaintext');
|
|
943
|
+
if (plaintextNode?.content) {
|
|
944
|
+
try {
|
|
945
|
+
const contentBuf = typeof plaintextNode.content === 'string'
|
|
946
|
+
? Buffer.from(plaintextNode.content, 'binary')
|
|
947
|
+
: Buffer.from(plaintextNode.content);
|
|
948
|
+
const messageProto = proto.Message.decode(contentBuf);
|
|
949
|
+
const fullMessage = proto.WebMessageInfo.fromObject({
|
|
950
|
+
key: {
|
|
951
|
+
remoteJid: from,
|
|
952
|
+
id: child.attrs.message_id || child.attrs.server_id,
|
|
953
|
+
fromMe: false
|
|
954
|
+
},
|
|
955
|
+
message: messageProto,
|
|
956
|
+
messageTimestamp: +child.attrs.t
|
|
957
|
+
});
|
|
958
|
+
await upsertMessage(fullMessage, 'append');
|
|
959
|
+
logger.info('Processed plaintext newsletter message');
|
|
960
|
+
}
|
|
961
|
+
catch (error) {
|
|
962
|
+
logger.error({ error }, 'Failed to decode plaintext newsletter message');
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
break;
|
|
966
|
+
default:
|
|
967
|
+
logger.warn({ node }, 'Unknown newsletter notification');
|
|
968
|
+
break;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
// Handles mex newsletter notifications
|
|
972
|
+
async function handleMexNewsletterNotification(node) {
|
|
973
|
+
const mexNode = getBinaryNodeChild(node, 'mex');
|
|
974
|
+
if (!mexNode?.content) {
|
|
975
|
+
logger.warn({ node }, 'Invalid mex newsletter notification');
|
|
976
|
+
return;
|
|
977
|
+
}
|
|
978
|
+
let data;
|
|
979
|
+
try {
|
|
980
|
+
data = JSON.parse(mexNode.content.toString());
|
|
981
|
+
}
|
|
982
|
+
catch (error) {
|
|
983
|
+
logger.error({ err: error, node }, 'Failed to parse mex newsletter notification');
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
const operation = data?.operation;
|
|
987
|
+
const updates = data?.updates;
|
|
988
|
+
if (!updates || !operation) {
|
|
989
|
+
logger.warn({ data }, 'Invalid mex newsletter notification content');
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
logger.info({ operation, updates }, 'got mex newsletter notification');
|
|
993
|
+
switch (operation) {
|
|
994
|
+
case 'NotificationNewsletterUpdate':
|
|
995
|
+
for (const update of updates) {
|
|
996
|
+
if (update.jid && update.settings && Object.keys(update.settings).length > 0) {
|
|
997
|
+
ev.emit('newsletter-settings.update', {
|
|
998
|
+
id: update.jid,
|
|
999
|
+
update: update.settings
|
|
1000
|
+
});
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
break;
|
|
1004
|
+
case 'NotificationNewsletterAdminPromote':
|
|
1005
|
+
for (const update of updates) {
|
|
1006
|
+
if (update.jid && update.user) {
|
|
1007
|
+
ev.emit('newsletter-participants.update', {
|
|
1008
|
+
id: update.jid,
|
|
1009
|
+
author: node.attrs.from,
|
|
1010
|
+
user: update.user,
|
|
1011
|
+
new_role: 'ADMIN',
|
|
1012
|
+
action: 'promote'
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
break;
|
|
1017
|
+
default:
|
|
1018
|
+
logger.info({ operation, data }, 'Unhandled mex newsletter notification');
|
|
1019
|
+
break;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
862
1022
|
// recv a message
|
|
863
1023
|
ws.on('CB:message', (node) => {
|
|
864
1024
|
processNode('message', node, 'processing message', handleMessage);
|
|
@@ -873,10 +1033,12 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
873
1033
|
processNode('notification', node, 'handling notification', handleNotification);
|
|
874
1034
|
});
|
|
875
1035
|
ws.on('CB:ack,class:message', (node) => {
|
|
876
|
-
handleBadAck(node)
|
|
877
|
-
.catch(error => onUnexpectedError(error, 'handling bad ack'));
|
|
1036
|
+
handleBadAck(node).catch(error => onUnexpectedError(error, 'handling bad ack'));
|
|
878
1037
|
});
|
|
879
1038
|
ev.on('call', ([call]) => {
|
|
1039
|
+
if (!call) {
|
|
1040
|
+
return;
|
|
1041
|
+
}
|
|
880
1042
|
// missed call + group call notification message generation
|
|
881
1043
|
if (call.status === 'timeout' || (call.status === 'offer' && call.isGroup)) {
|
|
882
1044
|
const msg = {
|
|
@@ -885,20 +1047,22 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
885
1047
|
id: call.id,
|
|
886
1048
|
fromMe: false
|
|
887
1049
|
},
|
|
888
|
-
messageTimestamp:
|
|
1050
|
+
messageTimestamp: unixTimestampSeconds(call.date)
|
|
889
1051
|
};
|
|
890
1052
|
if (call.status === 'timeout') {
|
|
891
1053
|
if (call.isGroup) {
|
|
892
|
-
msg.messageStubType = call.isVideo
|
|
1054
|
+
msg.messageStubType = call.isVideo
|
|
1055
|
+
? WAMessageStubType.CALL_MISSED_GROUP_VIDEO
|
|
1056
|
+
: WAMessageStubType.CALL_MISSED_GROUP_VOICE;
|
|
893
1057
|
}
|
|
894
1058
|
else {
|
|
895
|
-
msg.messageStubType = call.isVideo ?
|
|
1059
|
+
msg.messageStubType = call.isVideo ? WAMessageStubType.CALL_MISSED_VIDEO : WAMessageStubType.CALL_MISSED_VOICE;
|
|
896
1060
|
}
|
|
897
1061
|
}
|
|
898
1062
|
else {
|
|
899
1063
|
msg.message = { call: { callKey: Buffer.from(call.id) } };
|
|
900
1064
|
}
|
|
901
|
-
const protoMsg =
|
|
1065
|
+
const protoMsg = proto.WebMessageInfo.fromObject(msg);
|
|
902
1066
|
upsertMessage(protoMsg, call.offline ? 'append' : 'notify');
|
|
903
1067
|
}
|
|
904
1068
|
});
|
|
@@ -914,7 +1078,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
914
1078
|
sendRetryRequest,
|
|
915
1079
|
rejectCall,
|
|
916
1080
|
fetchMessageHistory,
|
|
917
|
-
requestPlaceholderResend
|
|
1081
|
+
requestPlaceholderResend
|
|
918
1082
|
};
|
|
919
1083
|
};
|
|
920
|
-
|
|
1084
|
+
//# sourceMappingURL=messages-recv.js.map
|