@baileys-md/baileys 12.0.0 → 12.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -13
- package/WAProto/WAProto.proto +769 -233
- package/WAProto/index.js +65813 -141372
- package/lib/Defaults/index.js +128 -113
- package/lib/KeyDB/BinarySearch.js +30 -0
- package/lib/KeyDB/KeyedDB.js +178 -0
- package/lib/KeyDB/index.js +14 -0
- package/lib/Signal/Group/ciphertext-message.js +22 -14
- package/lib/Signal/Group/group-session-builder.js +21 -42
- package/lib/Signal/Group/group_cipher.js +85 -87
- package/lib/Signal/Group/index.js +23 -57
- package/lib/Signal/Group/keyhelper.js +28 -52
- package/lib/Signal/Group/sender-chain-key.js +37 -33
- package/lib/Signal/Group/sender-key-distribution-message.js +73 -63
- package/lib/Signal/Group/sender-key-message.js +75 -66
- package/lib/Signal/Group/sender-key-name.js +55 -44
- package/lib/Signal/Group/sender-key-record.js +49 -49
- package/lib/Signal/Group/sender-key-state.js +90 -93
- package/lib/Signal/Group/sender-message-key.js +37 -28
- package/lib/Signal/libsignal.js +324 -163
- package/lib/Signal/lid-mapping.js +166 -0
- package/lib/Socket/Client/index.js +14 -18
- package/lib/Socket/Client/types.js +12 -12
- package/lib/Socket/Client/websocket.js +60 -109
- package/lib/Socket/business.js +359 -242
- package/lib/Socket/chats.js +857 -898
- package/lib/Socket/communities.js +413 -0
- package/lib/Socket/groups.js +304 -324
- package/lib/Socket/index.js +25 -9
- package/lib/Socket/messages-recv.js +1109 -1000
- package/lib/Socket/messages-send.js +615 -387
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.js +231 -227
- package/lib/Socket/socket.js +803 -628
- package/lib/Store/index.js +18 -8
- package/lib/Store/make-cache-manager-store.js +75 -0
- package/lib/Store/make-in-memory-store.js +286 -435
- package/lib/Store/make-ordered-dictionary.js +77 -79
- package/lib/Store/object-repository.js +24 -26
- package/lib/Types/Auth.js +13 -2
- package/lib/Types/Bussines.js +13 -0
- package/lib/Types/Call.js +13 -2
- package/lib/Types/Chat.js +19 -4
- package/lib/Types/Contact.js +13 -2
- package/lib/Types/Events.js +13 -2
- package/lib/Types/GroupMetadata.js +13 -2
- package/lib/Types/Label.js +43 -26
- package/lib/Types/LabelAssociation.js +16 -8
- package/lib/Types/Message.js +22 -7
- package/lib/Types/Newsletter.js +42 -17
- package/lib/Types/Product.js +13 -2
- package/lib/Types/Signal.js +13 -2
- package/lib/Types/Socket.js +14 -2
- package/lib/Types/State.js +21 -2
- package/lib/Types/USync.js +13 -2
- package/lib/Types/index.js +37 -41
- package/lib/Utils/auth-utils.js +219 -189
- package/lib/Utils/baileys-event-stream.js +54 -0
- package/lib/Utils/browser-utils.js +21 -31
- package/lib/Utils/business.js +213 -214
- package/lib/Utils/chat-utils.js +711 -689
- package/lib/Utils/crypto.js +112 -175
- package/lib/Utils/decode-wa-message.js +254 -194
- package/lib/Utils/event-buffer.js +510 -500
- package/lib/Utils/generics.js +318 -430
- package/lib/Utils/history.js +83 -90
- package/lib/Utils/index.js +31 -35
- package/lib/Utils/link-preview.js +71 -116
- package/lib/Utils/logger.js +5 -7
- package/lib/Utils/lt-hash.js +40 -46
- package/lib/Utils/make-mutex.js +34 -41
- package/lib/Utils/message-retry-manager.js +33 -48
- package/lib/Utils/messages-media.js +516 -784
- package/lib/Utils/messages.js +347 -489
- package/lib/Utils/noise-handler.js +138 -144
- package/lib/Utils/pre-key-manager.js +95 -0
- package/lib/Utils/process-message.js +331 -384
- package/lib/Utils/signal.js +157 -139
- package/lib/Utils/use-multi-file-auth-state.js +119 -91
- package/lib/Utils/validate-connection.js +184 -203
- package/lib/WABinary/constants.js +1308 -1298
- package/lib/WABinary/decode.js +241 -256
- package/lib/WABinary/encode.js +217 -239
- package/lib/WABinary/generic-utils.js +131 -40
- package/lib/WABinary/index.js +17 -21
- package/lib/WABinary/jid-utils.js +97 -79
- package/lib/WABinary/types.js +13 -2
- package/lib/WAM/BinaryInfo.js +20 -12
- package/lib/WAM/constants.js +22863 -15348
- package/lib/WAM/encode.js +145 -136
- package/lib/WAM/index.js +15 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +39 -31
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +61 -54
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +39 -29
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +48 -40
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +62 -51
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +38 -21
- package/lib/WAUSync/Protocols/index.js +17 -20
- package/lib/WAUSync/USyncQuery.js +98 -86
- package/lib/WAUSync/USyncUser.js +35 -26
- package/lib/WAUSync/index.js +16 -19
- package/lib/index.js +23 -41
- package/package.json +46 -56
- package/README.md +0 -113
- package/WAProto/GenerateStatics.sh +0 -4
- package/lib/Defaults/wileys-version.json +0 -3
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/usync.js +0 -70
- package/lib/Utils/wileys-event-stream.js +0 -63
|
@@ -1,404 +1,351 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
//========================================//
|
|
2
|
+
/**
|
|
3
|
+
* @project @sixcore/baileys
|
|
4
|
+
* @author Sixx.js </>🌿
|
|
5
|
+
* @version 1.0.3
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @country Mozambique 🇲🇿♥️
|
|
8
|
+
* @chamadas || sms +258860817689
|
|
9
|
+
* @whatsApp +55889616-2417 || +258851907875
|
|
10
|
+
* @description Biblioteca Node.js para integração e automação no WhatsApp usando Baileys
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { areJidsSameUser, isHostedLidUser, isHostedPnUser, isJidBroadcast, isJidStatusBroadcast, jidDecode, jidEncode, jidNormalizedUser } from "../WABinary/index.js";
|
|
14
|
+
import { getContentType, normalizeMessageContent } from "../Utils/messages.js";
|
|
15
|
+
import { downloadAndProcessHistorySyncNotification } from "./history.js";
|
|
16
|
+
import { WAMessageStubType } from "../Types/index.js";
|
|
17
|
+
import { aesDecryptGCM, hmacSign } from "./crypto.js";
|
|
18
|
+
import { proto } from "../../WAProto/index.js";
|
|
19
|
+
import { toNumber } from "./generics.js";
|
|
20
|
+
|
|
12
21
|
const REAL_MSG_STUB_TYPES = new Set([
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
]);
|
|
18
|
-
const REAL_MSG_REQ_ME_STUB_TYPES = new Set([
|
|
19
|
-
Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD
|
|
22
|
+
WAMessageStubType.CALL_MISSED_GROUP_VIDEO,
|
|
23
|
+
WAMessageStubType.CALL_MISSED_GROUP_VOICE,
|
|
24
|
+
WAMessageStubType.CALL_MISSED_VIDEO,
|
|
25
|
+
WAMessageStubType.CALL_MISSED_VOICE
|
|
20
26
|
]);
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
msgKey.fromMe = !msgKey.fromMe
|
|
54
|
-
? (0, WABinary_1.areJidsSameUser)(msgKey.participant || msgKey.remoteJid, meId)
|
|
55
|
-
// if the message being reacted to, was from them
|
|
56
|
-
// fromMe automatically becomes false
|
|
57
|
-
: false;
|
|
58
|
-
// set the remoteJid to being the same as the chat the message came from
|
|
59
|
-
msgKey.remoteJid = message.key.remoteJid;
|
|
60
|
-
// set participant of the message
|
|
61
|
-
msgKey.participant = msgKey.participant || message.key.participant;
|
|
62
|
-
}
|
|
27
|
+
|
|
28
|
+
const REAL_MSG_REQ_ME_STUB_TYPES = new Set([WAMessageStubType.GROUP_PARTICIPANT_ADD]);
|
|
29
|
+
|
|
30
|
+
export const cleanMessage = (message, meId, meLid) => {
|
|
31
|
+
if (isHostedPnUser(message.key.remoteJid) || isHostedLidUser(message.key.remoteJid)) {
|
|
32
|
+
message.key.remoteJid = jidEncode(jidDecode(message.key?.remoteJid)?.user, isHostedPnUser(message.key.remoteJid) ? "s.whatsapp.net" : "lid");
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
message.key.remoteJid = jidNormalizedUser(message.key.remoteJid);
|
|
36
|
+
}
|
|
37
|
+
if (isHostedPnUser(message.key.participant) || isHostedLidUser(message.key.participant)) {
|
|
38
|
+
message.key.participant = jidEncode(jidDecode(message.key.participant)?.user, isHostedPnUser(message.key.participant) ? "s.whatsapp.net" : "lid");
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
message.key.participant = jidNormalizedUser(message.key.participant);
|
|
42
|
+
}
|
|
43
|
+
const content = normalizeMessageContent(message.message);
|
|
44
|
+
if (content?.reactionMessage) {
|
|
45
|
+
normaliseKey(content.reactionMessage.key);
|
|
46
|
+
}
|
|
47
|
+
if (content?.pollUpdateMessage) {
|
|
48
|
+
normaliseKey(content.pollUpdateMessage.pollCreationMessageKey);
|
|
49
|
+
}
|
|
50
|
+
function normaliseKey(msgKey) {
|
|
51
|
+
if (!message.key.fromMe) {
|
|
52
|
+
msgKey.fromMe = !msgKey.fromMe
|
|
53
|
+
? areJidsSameUser(msgKey.participant || msgKey.remoteJid, meId) ||
|
|
54
|
+
areJidsSameUser(msgKey.participant || msgKey.remoteJid, meLid)
|
|
55
|
+
:
|
|
56
|
+
false;
|
|
57
|
+
msgKey.remoteJid = message.key.remoteJid;
|
|
58
|
+
msgKey.participant = msgKey.participant || message.key.participant;
|
|
63
59
|
}
|
|
60
|
+
}
|
|
64
61
|
};
|
|
65
|
-
|
|
66
|
-
const isRealMessage = (message
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
&& !(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.reactionMessage)
|
|
77
|
-
&& !(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.pollUpdateMessage);
|
|
62
|
+
|
|
63
|
+
export const isRealMessage = (message) => {
|
|
64
|
+
const normalizedContent = normalizeMessageContent(message.message);
|
|
65
|
+
const hasSomeContent = !!getContentType(normalizedContent);
|
|
66
|
+
return ((!!normalizedContent ||
|
|
67
|
+
REAL_MSG_STUB_TYPES.has(message.messageStubType) ||
|
|
68
|
+
REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType)) &&
|
|
69
|
+
hasSomeContent &&
|
|
70
|
+
!normalizedContent?.protocolMessage &&
|
|
71
|
+
!normalizedContent?.reactionMessage &&
|
|
72
|
+
!normalizedContent?.pollUpdateMessage);
|
|
78
73
|
};
|
|
79
|
-
|
|
80
|
-
const shouldIncrementChatUnread = (message) =>
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if ((0, WABinary_1.isJidBroadcast)(remoteJid)
|
|
88
|
-
&& !(0, WABinary_1.isJidStatusBroadcast)(remoteJid)
|
|
89
|
-
&& !fromMe) {
|
|
90
|
-
return participant;
|
|
91
|
-
}
|
|
92
|
-
return remoteJid;
|
|
74
|
+
|
|
75
|
+
export const shouldIncrementChatUnread = (message) => !message.key.fromMe && !message.messageStubType;
|
|
76
|
+
|
|
77
|
+
export const getChatId = ({ remoteJid, participant, fromMe }) => {
|
|
78
|
+
if (isJidBroadcast(remoteJid) && !isJidStatusBroadcast(remoteJid) && !fromMe) {
|
|
79
|
+
return participant;
|
|
80
|
+
}
|
|
81
|
+
return remoteJid;
|
|
93
82
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const aad = toBinary(`${pollMsgId}\u0000${voterJid}`);
|
|
112
|
-
const decrypted = (0, crypto_1.aesDecryptGCM)(encPayload, decKey, encIv, aad);
|
|
113
|
-
return WAProto_1.proto.Message.PollVoteMessage.decode(decrypted);
|
|
114
|
-
function toBinary(txt) {
|
|
115
|
-
return Buffer.from(txt);
|
|
116
|
-
}
|
|
83
|
+
|
|
84
|
+
export function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid }) {
|
|
85
|
+
const sign = Buffer.concat([
|
|
86
|
+
toBinary(pollMsgId),
|
|
87
|
+
toBinary(pollCreatorJid),
|
|
88
|
+
toBinary(voterJid),
|
|
89
|
+
toBinary("Poll Vote"),
|
|
90
|
+
new Uint8Array([1])
|
|
91
|
+
]);
|
|
92
|
+
const key0 = hmacSign(pollEncKey, new Uint8Array(32), "sha256");
|
|
93
|
+
const decKey = hmacSign(sign, key0, "sha256");
|
|
94
|
+
const aad = toBinary(`${pollMsgId}\u0000${voterJid}`);
|
|
95
|
+
const decrypted = aesDecryptGCM(encPayload, decKey, encIv, aad);
|
|
96
|
+
return proto.Message.PollVoteMessage.decode(decrypted);
|
|
97
|
+
function toBinary(txt) {
|
|
98
|
+
return Buffer.from(txt);
|
|
99
|
+
}
|
|
117
100
|
}
|
|
118
|
-
const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if ((0, exports.shouldIncrementChatUnread)(message)) {
|
|
129
|
-
chat.unreadCount = (chat.unreadCount || 0) + 1;
|
|
130
|
-
}
|
|
101
|
+
const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, signalRepository, keyStore, logger, options }) => {
|
|
102
|
+
const meId = creds.me.id;
|
|
103
|
+
const { accountSettings } = creds;
|
|
104
|
+
const chat = { id: jidNormalizedUser(getChatId(message.key)) };
|
|
105
|
+
const isRealMsg = isRealMessage(message);
|
|
106
|
+
if (isRealMsg) {
|
|
107
|
+
chat.messages = [{ message }];
|
|
108
|
+
chat.conversationTimestamp = toNumber(message.messageTimestamp);
|
|
109
|
+
if (shouldIncrementChatUnread(message)) {
|
|
110
|
+
chat.unreadCount = (chat.unreadCount || 0) + 1;
|
|
131
111
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
112
|
+
}
|
|
113
|
+
const content = normalizeMessageContent(message.message);
|
|
114
|
+
if ((isRealMsg || content?.reactionMessage?.key?.fromMe) && accountSettings?.unarchiveChats) {
|
|
115
|
+
chat.archived = false;
|
|
116
|
+
chat.readOnly = false;
|
|
117
|
+
}
|
|
118
|
+
const protocolMsg = content?.protocolMessage;
|
|
119
|
+
if (protocolMsg) {
|
|
120
|
+
switch (protocolMsg.type) {
|
|
121
|
+
case proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
|
|
122
|
+
const histNotification = protocolMsg.historySyncNotification;
|
|
123
|
+
const process = shouldProcessHistoryMsg;
|
|
124
|
+
const isLatest = !creds.processedHistoryMessages?.length;
|
|
125
|
+
logger?.info({
|
|
126
|
+
histNotification,
|
|
127
|
+
process,
|
|
128
|
+
id: message.key.id,
|
|
129
|
+
isLatest
|
|
130
|
+
}, "got history notification");
|
|
131
|
+
if (process) {
|
|
132
|
+
if (histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND) {
|
|
133
|
+
ev.emit("creds.update", {
|
|
134
|
+
processedHistoryMessages: [
|
|
135
|
+
...(creds.processedHistoryMessages || []),
|
|
136
|
+
{ key: message.key, messageTimestamp: message.messageTimestamp }
|
|
137
|
+
]
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
const data = await downloadAndProcessHistorySyncNotification(histNotification, options);
|
|
141
|
+
ev.emit("messaging-history.set", {
|
|
142
|
+
...data,
|
|
143
|
+
isLatest: histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND ? isLatest : undefined,
|
|
144
|
+
peerDataRequestSessionId: histNotification.peerDataRequestSessionId
|
|
145
|
+
});
|
|
138
146
|
}
|
|
139
|
-
|
|
140
|
-
|
|
147
|
+
break;
|
|
148
|
+
case proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
|
|
149
|
+
const keys = protocolMsg.appStateSyncKeyShare.keys;
|
|
150
|
+
if (keys?.length) {
|
|
151
|
+
let newAppStateSyncKeyId = "";
|
|
152
|
+
await keyStore.transaction(async () => {
|
|
153
|
+
const newKeys = [];
|
|
154
|
+
for (const { keyData, keyId } of keys) {
|
|
155
|
+
const strKeyId = Buffer.from(keyId.keyId).toString("base64");
|
|
156
|
+
newKeys.push(strKeyId);
|
|
157
|
+
await keyStore.set({ "app-state-sync-key": { [strKeyId]: keyData } });
|
|
158
|
+
newAppStateSyncKeyId = strKeyId;
|
|
159
|
+
}
|
|
160
|
+
logger?.info({ newAppStateSyncKeyId, newKeys }, "injecting new app state sync keys");
|
|
161
|
+
}, meId);
|
|
162
|
+
ev.emit("creds.update", { myAppStateKeyId: newAppStateSyncKeyId });
|
|
141
163
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
for (let i = 0; i < mJids.length; i++) {
|
|
145
|
-
if ((0, WABinary_1.isLidUser)(mJids[i])) {
|
|
146
|
-
mJids[i] = (0, WABinary_1.lidToJid)(mJids[i]);
|
|
164
|
+
else {
|
|
165
|
+
logger?.info({ protocolMsg }, "recv app state sync with 0 keys");
|
|
147
166
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
const data = await (0, history_1.downloadAndProcessHistorySyncNotification)(histNotification, options);
|
|
182
|
-
ev.emit('messaging-history.set', {
|
|
183
|
-
...data,
|
|
184
|
-
isLatest: histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND
|
|
185
|
-
? isLatest
|
|
186
|
-
: undefined,
|
|
187
|
-
peerDataRequestSessionId: histNotification.peerDataRequestSessionId
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
break;
|
|
191
|
-
case WAProto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
|
|
192
|
-
const keys = protocolMsg.appStateSyncKeyShare.keys;
|
|
193
|
-
if (keys === null || keys === void 0 ? void 0 : keys.length) {
|
|
194
|
-
let newAppStateSyncKeyId = '';
|
|
195
|
-
await keyStore.transaction(async () => {
|
|
196
|
-
const newKeys = [];
|
|
197
|
-
for (const { keyData, keyId } of keys) {
|
|
198
|
-
const strKeyId = Buffer.from(keyId.keyId).toString('base64');
|
|
199
|
-
newKeys.push(strKeyId);
|
|
200
|
-
await keyStore.set({ 'app-state-sync-key': { [strKeyId]: keyData } });
|
|
201
|
-
newAppStateSyncKeyId = strKeyId;
|
|
202
|
-
}
|
|
203
|
-
logger === null || logger === void 0 ? void 0 : logger.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys');
|
|
204
|
-
});
|
|
205
|
-
ev.emit('creds.update', { myAppStateKeyId: newAppStateSyncKeyId });
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
logger === null || logger === void 0 ? void 0 : logger.info({ protocolMsg }, 'recv app state sync with 0 keys');
|
|
209
|
-
}
|
|
210
|
-
break;
|
|
211
|
-
case WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE:
|
|
212
|
-
ev.emit('messages.update', [
|
|
213
|
-
{
|
|
214
|
-
key: {
|
|
215
|
-
...message.key,
|
|
216
|
-
id: protocolMsg.key.id
|
|
217
|
-
},
|
|
218
|
-
update: { message: null, messageStubType: Types_1.WAMessageStubType.REVOKE, key: message.key }
|
|
219
|
-
}
|
|
220
|
-
]);
|
|
221
|
-
break;
|
|
222
|
-
case WAProto_1.proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
|
|
223
|
-
Object.assign(chat, {
|
|
224
|
-
ephemeralSettingTimestamp: (0, generics_1.toNumber)(message.messageTimestamp),
|
|
225
|
-
ephemeralExpiration: protocolMsg.ephemeralExpiration || null
|
|
167
|
+
break;
|
|
168
|
+
case proto.Message.ProtocolMessage.Type.REVOKE:
|
|
169
|
+
ev.emit("messages.update", [
|
|
170
|
+
{
|
|
171
|
+
key: {
|
|
172
|
+
...message.key,
|
|
173
|
+
id: protocolMsg.key.id
|
|
174
|
+
},
|
|
175
|
+
update: { message: null, messageStubType: WAMessageStubType.REVOKE, key: message.key }
|
|
176
|
+
}
|
|
177
|
+
]);
|
|
178
|
+
break;
|
|
179
|
+
case proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
|
|
180
|
+
Object.assign(chat, {
|
|
181
|
+
ephemeralSettingTimestamp: toNumber(message.messageTimestamp),
|
|
182
|
+
ephemeralExpiration: protocolMsg.ephemeralExpiration || null
|
|
183
|
+
});
|
|
184
|
+
break;
|
|
185
|
+
case proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
|
|
186
|
+
const response = protocolMsg.peerDataOperationRequestResponseMessage;
|
|
187
|
+
if (response) {
|
|
188
|
+
await placeholderResendCache?.del(response.stanzaId);
|
|
189
|
+
const { peerDataOperationResult } = response;
|
|
190
|
+
for (const result of peerDataOperationResult) {
|
|
191
|
+
const { placeholderMessageResendResponse: retryResponse } = result;
|
|
192
|
+
if (retryResponse) {
|
|
193
|
+
const webMessageInfo = proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
|
|
194
|
+
setTimeout(() => {
|
|
195
|
+
ev.emit("messages.upsert", {
|
|
196
|
+
messages: [webMessageInfo],
|
|
197
|
+
type: "notify",
|
|
198
|
+
requestId: response.stanzaId
|
|
226
199
|
});
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
if (response) {
|
|
231
|
-
placeholderResendCache === null || placeholderResendCache === void 0 ? void 0 : placeholderResendCache.del(response.stanzaId);
|
|
232
|
-
// TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
|
|
233
|
-
const { peerDataOperationResult } = response;
|
|
234
|
-
for (const result of peerDataOperationResult) {
|
|
235
|
-
const { placeholderMessageResendResponse: retryResponse } = result;
|
|
236
|
-
if (retryResponse) {
|
|
237
|
-
const webMessageInfo = WAProto_1.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
|
|
238
|
-
// wait till another upsert event is available, don't want it to be part of the PDO response message
|
|
239
|
-
setTimeout(() => {
|
|
240
|
-
ev.emit('messages.upsert', {
|
|
241
|
-
messages: [webMessageInfo],
|
|
242
|
-
type: 'notify',
|
|
243
|
-
requestId: response.stanzaId
|
|
244
|
-
});
|
|
245
|
-
}, 500);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
case WAProto_1.proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
|
|
250
|
-
ev.emit('messages.update', [
|
|
251
|
-
{
|
|
252
|
-
// flip the sender / fromMe properties because they're in the perspective of the sender
|
|
253
|
-
key: { ...message.key, id: (_d = protocolMsg.key) === null || _d === void 0 ? void 0 : _d.id },
|
|
254
|
-
update: {
|
|
255
|
-
message: {
|
|
256
|
-
editedMessage: {
|
|
257
|
-
message: protocolMsg.editedMessage
|
|
258
|
-
}
|
|
259
|
-
},
|
|
260
|
-
messageTimestamp: protocolMsg.timestampMs
|
|
261
|
-
? Math.floor((0, generics_1.toNumber)(protocolMsg.timestampMs) / 1000)
|
|
262
|
-
: message.messageTimestamp
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
]);
|
|
266
|
-
break;
|
|
200
|
+
}, 500);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
267
203
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
key: message.key,
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}]);
|
|
278
|
-
}
|
|
279
|
-
else if (message.messageStubType) {
|
|
280
|
-
const jid = (_f = message.key) === null || _f === void 0 ? void 0 : _f.remoteJid;
|
|
281
|
-
//let actor = whatsappID (message.participant)
|
|
282
|
-
let participants;
|
|
283
|
-
const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }));
|
|
284
|
-
const emitGroupUpdate = (update) => {
|
|
285
|
-
var _a;
|
|
286
|
-
ev.emit('groups.update', [{ id: jid, ...update, author: (_a = message.participant) !== null && _a !== void 0 ? _a : undefined }]);
|
|
287
|
-
};
|
|
288
|
-
const emitGroupRequestJoin = (participant, action, method) => {
|
|
289
|
-
ev.emit('group.join-request', { id: jid, author: message.participant, participant, action, method: method });
|
|
290
|
-
};
|
|
291
|
-
const participantsIncludesMe = () => participants.find(jid => (0, WABinary_1.areJidsSameUser)(meId, jid));
|
|
292
|
-
switch (message.messageStubType) {
|
|
293
|
-
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
|
|
294
|
-
participants = message.messageStubParameters || [];
|
|
295
|
-
emitParticipantsUpdate('modify');
|
|
296
|
-
break;
|
|
297
|
-
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
|
|
298
|
-
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
|
|
299
|
-
participants = message.messageStubParameters || [];
|
|
300
|
-
emitParticipantsUpdate('remove');
|
|
301
|
-
// mark the chat read only if you left the group
|
|
302
|
-
if (participantsIncludesMe()) {
|
|
303
|
-
chat.readOnly = true;
|
|
304
|
-
}
|
|
305
|
-
break;
|
|
306
|
-
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD:
|
|
307
|
-
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_INVITE:
|
|
308
|
-
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
|
|
309
|
-
participants = message.messageStubParameters || [];
|
|
310
|
-
if (participantsIncludesMe()) {
|
|
311
|
-
chat.readOnly = false;
|
|
204
|
+
break;
|
|
205
|
+
case proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
|
|
206
|
+
ev.emit("messages.update", [
|
|
207
|
+
{
|
|
208
|
+
key: { ...message.key, id: protocolMsg.key?.id },
|
|
209
|
+
update: {
|
|
210
|
+
message: {
|
|
211
|
+
editedMessage: {
|
|
212
|
+
message: protocolMsg.editedMessage
|
|
312
213
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
emitParticipantsUpdate('demote');
|
|
318
|
-
break;
|
|
319
|
-
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
|
|
320
|
-
participants = message.messageStubParameters || [];
|
|
321
|
-
emitParticipantsUpdate('promote');
|
|
322
|
-
break;
|
|
323
|
-
case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
|
|
324
|
-
const announceValue = (_g = message.messageStubParameters) === null || _g === void 0 ? void 0 : _g[0];
|
|
325
|
-
emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
|
|
326
|
-
break;
|
|
327
|
-
case Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT:
|
|
328
|
-
const restrictValue = (_h = message.messageStubParameters) === null || _h === void 0 ? void 0 : _h[0];
|
|
329
|
-
emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
|
|
330
|
-
break;
|
|
331
|
-
case Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT:
|
|
332
|
-
const name = (_j = message.messageStubParameters) === null || _j === void 0 ? void 0 : _j[0];
|
|
333
|
-
chat.name = name;
|
|
334
|
-
emitGroupUpdate({ subject: name });
|
|
335
|
-
break;
|
|
336
|
-
case Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
|
|
337
|
-
const description = (_k = message.messageStubParameters) === null || _k === void 0 ? void 0 : _k[0];
|
|
338
|
-
chat.description = description;
|
|
339
|
-
emitGroupUpdate({ desc: description });
|
|
340
|
-
break;
|
|
341
|
-
case Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
|
|
342
|
-
const code = (_l = message.messageStubParameters) === null || _l === void 0 ? void 0 : _l[0];
|
|
343
|
-
emitGroupUpdate({ inviteCode: code });
|
|
344
|
-
break;
|
|
345
|
-
case Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
|
|
346
|
-
const memberAddValue = (_m = message.messageStubParameters) === null || _m === void 0 ? void 0 : _m[0];
|
|
347
|
-
emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
|
|
348
|
-
break;
|
|
349
|
-
case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
|
|
350
|
-
const approvalMode = (_o = message.messageStubParameters) === null || _o === void 0 ? void 0 : _o[0];
|
|
351
|
-
emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
|
|
352
|
-
break;
|
|
353
|
-
case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD:
|
|
354
|
-
const participant = (_p = message.messageStubParameters) === null || _p === void 0 ? void 0 : _p[0];
|
|
355
|
-
const action = (_q = message.messageStubParameters) === null || _q === void 0 ? void 0 : _q[1];
|
|
356
|
-
const method = (_r = message.messageStubParameters) === null || _r === void 0 ? void 0 : _r[2];
|
|
357
|
-
emitGroupRequestJoin(participant, action, method);
|
|
358
|
-
break;
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
else if (content === null || content === void 0 ? void 0 : content.pollUpdateMessage) {
|
|
362
|
-
const creationMsgKey = content.pollUpdateMessage.pollCreationMessageKey;
|
|
363
|
-
// we need to fetch the poll creation message to get the poll enc key
|
|
364
|
-
const pollMsg = await getMessage(creationMsgKey);
|
|
365
|
-
if (pollMsg) {
|
|
366
|
-
const meIdNormalised = (0, WABinary_1.jidNormalizedUser)(meId);
|
|
367
|
-
const pollCreatorJid = (0, generics_1.getKeyAuthor)(creationMsgKey, meIdNormalised);
|
|
368
|
-
const voterJid = (0, generics_1.getKeyAuthor)(message.key, meIdNormalised);
|
|
369
|
-
const pollEncKey = (_s = pollMsg.messageContextInfo) === null || _s === void 0 ? void 0 : _s.messageSecret;
|
|
370
|
-
try {
|
|
371
|
-
const voteMsg = decryptPollVote(content.pollUpdateMessage.vote, {
|
|
372
|
-
pollEncKey,
|
|
373
|
-
pollCreatorJid,
|
|
374
|
-
pollMsgId: creationMsgKey.id,
|
|
375
|
-
voterJid,
|
|
376
|
-
});
|
|
377
|
-
ev.emit('messages.update', [
|
|
378
|
-
{
|
|
379
|
-
key: creationMsgKey,
|
|
380
|
-
update: {
|
|
381
|
-
pollUpdates: [
|
|
382
|
-
{
|
|
383
|
-
pollUpdateMessageKey: message.key,
|
|
384
|
-
vote: voteMsg,
|
|
385
|
-
senderTimestampMs: content.pollUpdateMessage.senderTimestampMs.toNumber(),
|
|
386
|
-
}
|
|
387
|
-
]
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
]);
|
|
391
|
-
}
|
|
392
|
-
catch (err) {
|
|
393
|
-
logger === null || logger === void 0 ? void 0 : logger.warn({ err, creationMsgKey }, 'failed to decrypt poll vote');
|
|
214
|
+
},
|
|
215
|
+
messageTimestamp: protocolMsg.timestampMs
|
|
216
|
+
? Math.floor(toNumber(protocolMsg.timestampMs) / 1000)
|
|
217
|
+
: message.messageTimestamp
|
|
394
218
|
}
|
|
219
|
+
}
|
|
220
|
+
]);
|
|
221
|
+
break;
|
|
222
|
+
case proto.Message.ProtocolMessage.Type.LID_MIGRATION_MAPPING_SYNC:
|
|
223
|
+
const encodedPayload = protocolMsg.lidMigrationMappingSyncMessage?.encodedMappingPayload;
|
|
224
|
+
const { pnToLidMappings, chatDbMigrationTimestamp } = proto.LIDMigrationMappingSyncPayload.decode(encodedPayload);
|
|
225
|
+
logger?.debug({ pnToLidMappings, chatDbMigrationTimestamp }, "got lid mappings and chat db migration timestamp");
|
|
226
|
+
const pairs = [];
|
|
227
|
+
for (const { pn, latestLid, assignedLid } of pnToLidMappings) {
|
|
228
|
+
const lid = latestLid || assignedLid;
|
|
229
|
+
pairs.push({ lid: `${lid}@lid`, pn: `${pn}@s.whatsapp.net` });
|
|
395
230
|
}
|
|
396
|
-
|
|
397
|
-
|
|
231
|
+
await signalRepository.lidMapping.storeLIDPNMappings(pairs);
|
|
232
|
+
if (pairs.length) {
|
|
233
|
+
for (const { pn, lid } of pairs) {
|
|
234
|
+
await signalRepository.migrateSession(pn, lid);
|
|
235
|
+
}
|
|
398
236
|
}
|
|
399
237
|
}
|
|
400
|
-
|
|
401
|
-
|
|
238
|
+
}
|
|
239
|
+
else if (content?.reactionMessage) {
|
|
240
|
+
const reaction = {
|
|
241
|
+
...content.reactionMessage,
|
|
242
|
+
key: message.key
|
|
243
|
+
};
|
|
244
|
+
ev.emit("messages.reaction", [
|
|
245
|
+
{
|
|
246
|
+
reaction,
|
|
247
|
+
key: content.reactionMessage?.key
|
|
248
|
+
}
|
|
249
|
+
]);
|
|
250
|
+
}
|
|
251
|
+
else if (message.messageStubType) {
|
|
252
|
+
const jid = message.key?.remoteJid;
|
|
253
|
+
let participants;
|
|
254
|
+
const emitParticipantsUpdate = (action) => ev.emit("group-participants.update", {
|
|
255
|
+
id: jid,
|
|
256
|
+
author: message.key.participant,
|
|
257
|
+
authorPn: message.key.participantAlt,
|
|
258
|
+
participants,
|
|
259
|
+
action
|
|
260
|
+
});
|
|
261
|
+
const emitGroupUpdate = (update) => {
|
|
262
|
+
ev.emit("groups.update", [
|
|
263
|
+
{ id: jid, ...update, author: message.key.participant ?? undefined, authorPn: message.key.participantAlt }
|
|
264
|
+
]);
|
|
265
|
+
};
|
|
266
|
+
const emitGroupRequestJoin = (participant, action, method) => {
|
|
267
|
+
ev.emit("group.join-request", {
|
|
268
|
+
id: jid,
|
|
269
|
+
author: message.key.participant,
|
|
270
|
+
authorPn: message.key.participantAlt,
|
|
271
|
+
participant: participant.lid,
|
|
272
|
+
participantPn: participant.pn,
|
|
273
|
+
action,
|
|
274
|
+
method: method
|
|
275
|
+
});
|
|
276
|
+
};
|
|
277
|
+
const participantsIncludesMe = () => participants.find(jid => areJidsSameUser(meId, jid.phoneNumber));
|
|
278
|
+
switch (message.messageStubType) {
|
|
279
|
+
case WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
|
|
280
|
+
participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
|
|
281
|
+
emitParticipantsUpdate("modify");
|
|
282
|
+
break;
|
|
283
|
+
case WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
|
|
284
|
+
case WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
|
|
285
|
+
participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
|
|
286
|
+
emitParticipantsUpdate("remove");
|
|
287
|
+
if (participantsIncludesMe()) {
|
|
288
|
+
chat.readOnly = true;
|
|
289
|
+
}
|
|
290
|
+
break;
|
|
291
|
+
case WAMessageStubType.GROUP_PARTICIPANT_ADD:
|
|
292
|
+
case WAMessageStubType.GROUP_PARTICIPANT_INVITE:
|
|
293
|
+
case WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
|
|
294
|
+
participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
|
|
295
|
+
if (participantsIncludesMe()) {
|
|
296
|
+
chat.readOnly = false;
|
|
297
|
+
}
|
|
298
|
+
emitParticipantsUpdate("add");
|
|
299
|
+
break;
|
|
300
|
+
case WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
|
|
301
|
+
participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
|
|
302
|
+
emitParticipantsUpdate("demote");
|
|
303
|
+
break;
|
|
304
|
+
case WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
|
|
305
|
+
participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
|
|
306
|
+
emitParticipantsUpdate("promote");
|
|
307
|
+
break;
|
|
308
|
+
case WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
|
|
309
|
+
const announceValue = message.messageStubParameters?.[0];
|
|
310
|
+
emitGroupUpdate({ announce: announceValue === "true" || announceValue === "on" });
|
|
311
|
+
break;
|
|
312
|
+
case WAMessageStubType.GROUP_CHANGE_RESTRICT:
|
|
313
|
+
const restrictValue = message.messageStubParameters?.[0];
|
|
314
|
+
emitGroupUpdate({ restrict: restrictValue === "true" || restrictValue === "on" });
|
|
315
|
+
break;
|
|
316
|
+
case WAMessageStubType.GROUP_CHANGE_SUBJECT:
|
|
317
|
+
const name = message.messageStubParameters?.[0];
|
|
318
|
+
chat.name = name;
|
|
319
|
+
emitGroupUpdate({ subject: name });
|
|
320
|
+
break;
|
|
321
|
+
case WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
|
|
322
|
+
const description = message.messageStubParameters?.[0];
|
|
323
|
+
chat.description = description;
|
|
324
|
+
emitGroupUpdate({ desc: description });
|
|
325
|
+
break;
|
|
326
|
+
case WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
|
|
327
|
+
const code = message.messageStubParameters?.[0];
|
|
328
|
+
emitGroupUpdate({ inviteCode: code });
|
|
329
|
+
break;
|
|
330
|
+
case WAMessageStubType.GROUP_MEMBER_ADD_MODE:
|
|
331
|
+
const memberAddValue = message.messageStubParameters?.[0];
|
|
332
|
+
emitGroupUpdate({ memberAddMode: memberAddValue === "all_member_add" });
|
|
333
|
+
break;
|
|
334
|
+
case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
|
|
335
|
+
const approvalMode = message.messageStubParameters?.[0];
|
|
336
|
+
emitGroupUpdate({ joinApprovalMode: approvalMode === "on" });
|
|
337
|
+
break;
|
|
338
|
+
case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD:
|
|
339
|
+
const participant = JSON.parse(message.messageStubParameters?.[0]);
|
|
340
|
+
const action = message.messageStubParameters?.[1];
|
|
341
|
+
const method = message.messageStubParameters?.[2];
|
|
342
|
+
emitGroupRequestJoin(participant, action, method);
|
|
343
|
+
break;
|
|
402
344
|
}
|
|
345
|
+
}
|
|
346
|
+
if (Object.keys(chat).length > 1) {
|
|
347
|
+
ev.emit("chats.update", [chat]);
|
|
348
|
+
}
|
|
403
349
|
};
|
|
404
|
-
|
|
350
|
+
|
|
351
|
+
export default processMessage;
|