@ostyado/baileys 1.1.9 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/WAProto/index.js +131281 -59270
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +6 -6
- package/lib/Socket/chats.js +48 -16
- package/lib/Socket/dugong.js +637 -0
- package/lib/Socket/groups.js +0 -64
- package/lib/Socket/messages-send.js +146 -301
- package/lib/Socket/newsletter.js +134 -16
- package/lib/Socket/socket.js +1 -72
- package/lib/Utils/generics.js +80 -5
- package/lib/Utils/messages.js +4 -33
- package/lib/Utils/validate-connection.js +2 -2
- package/lib/index.js +3 -1
- package/package.json +11 -13
- package/WAProto/fix-import.js +0 -29
- package/lib/Defaults/index.d.ts +0 -53
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/group-session-builder.d.ts +0 -14
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/keyhelper.d.ts +0 -10
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
- package/lib/Signal/Group/sender-key-message.d.ts +0 -18
- package/lib/Signal/Group/sender-key-name.d.ts +0 -17
- package/lib/Signal/Group/sender-key-record.d.ts +0 -30
- package/lib/Signal/Group/sender-key-state.d.ts +0 -38
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Signal/libsignal.d.ts +0 -3
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
- package/lib/Socket/Client/index.d.ts +0 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/web-socket-client.d.ts +0 -12
- package/lib/Socket/business.d.ts +0 -171
- package/lib/Socket/chats.d.ts +0 -267
- package/lib/Socket/groups.d.ts +0 -115
- package/lib/Socket/index.d.ts +0 -173
- package/lib/Socket/luxu.d.ts +0 -278
- package/lib/Socket/luxu.js +0 -620
- package/lib/Socket/messages-recv.d.ts +0 -161
- package/lib/Socket/messages-send.d.ts +0 -149
- package/lib/Socket/newsletter.d.ts +0 -134
- package/lib/Socket/registration.d.ts +0 -267
- package/lib/Socket/socket.d.ts +0 -44
- package/lib/Socket/usync.d.ts +0 -36
- package/lib/Store/index.d.ts +0 -3
- package/lib/Store/make-cache-manager-store.d.ts +0 -13
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-ordered-dictionary.d.ts +0 -13
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -110
- package/lib/Types/Call.d.ts +0 -13
- package/lib/Types/Chat.d.ts +0 -102
- package/lib/Types/Contact.d.ts +0 -19
- package/lib/Types/Events.d.ts +0 -157
- package/lib/Types/GroupMetadata.d.ts +0 -55
- package/lib/Types/Label.d.ts +0 -35
- package/lib/Types/LabelAssociation.d.ts +0 -29
- package/lib/Types/Message.d.ts +0 -273
- package/lib/Types/Newsletter.d.ts +0 -103
- package/lib/Types/Product.d.ts +0 -78
- package/lib/Types/Signal.d.ts +0 -57
- package/lib/Types/Socket.d.ts +0 -111
- package/lib/Types/State.d.ts +0 -27
- package/lib/Types/USync.d.ts +0 -25
- package/lib/Types/index.d.ts +0 -57
- package/lib/Utils/auth-utils.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.d.ts +0 -16
- package/lib/Utils/business.d.ts +0 -22
- package/lib/Utils/chat-utils.d.ts +0 -71
- package/lib/Utils/crypto.d.ts +0 -41
- package/lib/Utils/decode-wa-message.d.ts +0 -19
- package/lib/Utils/event-buffer.d.ts +0 -35
- package/lib/Utils/generics.d.ts +0 -92
- package/lib/Utils/history.d.ts +0 -15
- package/lib/Utils/index.d.ts +0 -17
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -4
- package/lib/Utils/lt-hash.d.ts +0 -12
- package/lib/Utils/make-mutex.d.ts +0 -7
- package/lib/Utils/messages-media.d.ts +0 -116
- package/lib/Utils/messages.d.ts +0 -77
- package/lib/Utils/noise-handler.d.ts +0 -21
- package/lib/Utils/process-message.d.ts +0 -41
- package/lib/Utils/signal.d.ts +0 -32
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/validate-connection.d.ts +0 -11
- package/lib/WABinary/constants.d.ts +0 -30
- package/lib/WABinary/decode.d.ts +0 -7
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -17
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -31
- package/lib/WABinary/types.d.ts +0 -18
- package/lib/WAM/BinaryInfo.d.ts +0 -17
- package/lib/WAM/constants.d.ts +0 -38
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
- package/lib/WAUSync/Protocols/index.d.ts +0 -4
- package/lib/WAUSync/USyncQuery.d.ts +0 -28
- package/lib/WAUSync/USyncUser.d.ts +0 -12
- package/lib/index.d.ts +0 -12
|
@@ -8,15 +8,13 @@ const boom_1 = require("@hapi/boom");
|
|
|
8
8
|
const node_cache_1 = __importDefault(require("node-cache"));
|
|
9
9
|
const WAProto_1 = require("../../WAProto");
|
|
10
10
|
const Defaults_1 = require("../Defaults");
|
|
11
|
-
const
|
|
12
|
-
const Types_1 = require("../Types")
|
|
11
|
+
const Types_1 = require("../Types");
|
|
13
12
|
const Utils_1 = require("../Utils");
|
|
14
13
|
const link_preview_1 = require("../Utils/link-preview");
|
|
15
14
|
const WABinary_1 = require("../WABinary");
|
|
16
15
|
const newsletter_1 = require("./newsletter");
|
|
17
|
-
const WAUSync_1 = require("../WAUSync")
|
|
18
|
-
const
|
|
19
|
-
var ListType = WAProto_1.proto.Message.ListMessage.ListType;
|
|
16
|
+
const WAUSync_1 = require("../WAUSync");
|
|
17
|
+
const kikyy = require('./dugong');
|
|
20
18
|
const makeMessagesSocket = (config) => {
|
|
21
19
|
const {
|
|
22
20
|
logger,
|
|
@@ -34,7 +32,6 @@ const makeMessagesSocket = (config) => {
|
|
|
34
32
|
upsertMessage,
|
|
35
33
|
query,
|
|
36
34
|
fetchPrivacySettings,
|
|
37
|
-
generateMessageTag,
|
|
38
35
|
sendNode,
|
|
39
36
|
groupMetadata,
|
|
40
37
|
groupToggleEphemeral,
|
|
@@ -74,10 +71,6 @@ const makeMessagesSocket = (config) => {
|
|
|
74
71
|
}
|
|
75
72
|
return mediaConn;
|
|
76
73
|
};
|
|
77
|
-
/**
|
|
78
|
-
* generic send receipt function
|
|
79
|
-
* used for receipts of phone call, read, delivery etc.
|
|
80
|
-
* */
|
|
81
74
|
const sendReceipt = async (jid, participant, messageIds, type) => {
|
|
82
75
|
const node = {
|
|
83
76
|
tag: 'receipt',
|
|
@@ -118,84 +111,63 @@ const makeMessagesSocket = (config) => {
|
|
|
118
111
|
logger.debug({ attrs: node.attrs, messageIds }, 'sending receipt for messages');
|
|
119
112
|
await sendNode(node);
|
|
120
113
|
};
|
|
121
|
-
/** Correctly bulk send receipts to multiple chats, participants */
|
|
122
114
|
const sendReceipts = async (keys, type) => {
|
|
123
115
|
const recps = (0, Utils_1.aggregateMessageKeysNotFromMe)(keys);
|
|
124
116
|
for (const { jid, participant, messageIds } of recps) {
|
|
125
117
|
await sendReceipt(jid, participant, messageIds, type);
|
|
126
118
|
}
|
|
127
119
|
};
|
|
128
|
-
/** Bulk read messages. Keys can be from different chats & participants */
|
|
129
120
|
const readMessages = async (keys) => {
|
|
130
121
|
const privacySettings = await fetchPrivacySettings();
|
|
131
|
-
// based on privacy settings, we have to change the read type
|
|
132
122
|
const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self';
|
|
133
123
|
await sendReceipts(keys, readType);
|
|
134
124
|
};
|
|
135
|
-
/** Fetch all the devices we've to send a message to */
|
|
136
125
|
const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
|
|
137
126
|
const deviceResults = []
|
|
138
|
-
|
|
139
127
|
if (!useCache) {
|
|
140
128
|
logger.debug('not using cache for devices')
|
|
141
129
|
}
|
|
142
|
-
|
|
143
130
|
const toFetch = []
|
|
144
|
-
|
|
145
131
|
jids = Array.from(new Set(jids))
|
|
146
|
-
|
|
147
132
|
for (let jid of jids) {
|
|
148
133
|
const user = WABinary_1.jidDecode(jid)?.user
|
|
149
|
-
|
|
150
134
|
jid = WABinary_1.jidNormalizedUser(jid)
|
|
151
|
-
|
|
152
135
|
if (useCache) {
|
|
153
136
|
const devices = userDevicesCache.get(user)
|
|
154
|
-
|
|
155
137
|
if (devices) {
|
|
156
138
|
deviceResults.push(...devices)
|
|
157
139
|
logger.trace({ user }, 'using cache for devices')
|
|
158
140
|
}
|
|
159
|
-
|
|
160
141
|
else {
|
|
161
142
|
toFetch.push(jid)
|
|
162
143
|
}
|
|
163
144
|
}
|
|
164
|
-
|
|
165
145
|
else {
|
|
166
146
|
toFetch.push(jid)
|
|
167
147
|
}
|
|
168
148
|
}
|
|
169
|
-
|
|
170
149
|
if (!toFetch.length) {
|
|
171
150
|
return deviceResults
|
|
172
151
|
}
|
|
173
|
-
|
|
174
152
|
const query = new WAUSync_1.USyncQuery()
|
|
175
153
|
.withContext('message')
|
|
176
154
|
.withDeviceProtocol()
|
|
177
|
-
|
|
178
155
|
for (const jid of toFetch) {
|
|
179
156
|
query.withUser(new WAUSync_1.USyncUser().withId(jid))
|
|
180
157
|
}
|
|
181
|
-
|
|
182
158
|
const result = await executeUSyncQuery(query)
|
|
183
|
-
|
|
184
159
|
if (result) {
|
|
185
160
|
const extracted = Utils_1.extractDeviceJids(result?.list, authState.creds.me.id, ignoreZeroDevices)
|
|
186
161
|
const deviceMap = {}
|
|
187
|
-
|
|
188
162
|
for (const item of extracted) {
|
|
189
163
|
deviceMap[item.user] = deviceMap[item.user] || []
|
|
190
164
|
deviceMap[item.user].push(item)
|
|
191
165
|
deviceResults.push(item)
|
|
192
166
|
}
|
|
193
|
-
|
|
194
167
|
for (const key in deviceMap) {
|
|
195
168
|
userDevicesCache.set(key, deviceMap[key])
|
|
196
169
|
}
|
|
197
170
|
}
|
|
198
|
-
|
|
199
171
|
return deviceResults
|
|
200
172
|
}
|
|
201
173
|
const assertSessions = async (jids, force) => {
|
|
@@ -241,13 +213,10 @@ const makeMessagesSocket = (config) => {
|
|
|
241
213
|
}
|
|
242
214
|
return didFetchNewSession;
|
|
243
215
|
};
|
|
244
|
-
|
|
245
|
-
|
|
246
216
|
const sendPeerDataOperationMessage = async (pdoMessage) => {
|
|
247
217
|
if (!authState.creds.me?.id) {
|
|
248
218
|
throw new boom_1.Boom('Not authenticated')
|
|
249
219
|
}
|
|
250
|
-
|
|
251
220
|
const protocolMessage = {
|
|
252
221
|
protocolMessage: {
|
|
253
222
|
peerDataOperationRequestMessage: pdoMessage,
|
|
@@ -258,7 +227,6 @@ const makeMessagesSocket = (config) => {
|
|
|
258
227
|
const msgId = await relayMessage(meJid, protocolMessage, {
|
|
259
228
|
additionalAttributes: {
|
|
260
229
|
category: 'peer',
|
|
261
|
-
// eslint-disable-next-line camelcase
|
|
262
230
|
push_priority: 'high_force',
|
|
263
231
|
},
|
|
264
232
|
});
|
|
@@ -290,8 +258,8 @@ const makeMessagesSocket = (config) => {
|
|
|
290
258
|
return node;
|
|
291
259
|
}));
|
|
292
260
|
return { nodes, shouldIncludeDeviceIdentity };
|
|
293
|
-
};
|
|
294
|
-
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, useCachedGroupMetadata, statusJidList, AI =
|
|
261
|
+
};
|
|
262
|
+
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, useCachedGroupMetadata, statusJidList, AI = false }) => {
|
|
295
263
|
const meId = authState.creds.me.id;
|
|
296
264
|
let shouldIncludeDeviceIdentity = false;
|
|
297
265
|
let didPushAdditional = false
|
|
@@ -316,12 +284,9 @@ const makeMessagesSocket = (config) => {
|
|
|
316
284
|
}
|
|
317
285
|
};
|
|
318
286
|
const extraAttrs = {}
|
|
319
|
-
const messages = Utils_1.normalizeMessageContent(message)
|
|
287
|
+
const messages = Utils_1.normalizeMessageContent(message);
|
|
320
288
|
const buttonType = getButtonType(messages);
|
|
321
289
|
if (participant) {
|
|
322
|
-
// when the retry request is not for a group
|
|
323
|
-
// only send to the specific device that asked for a retry
|
|
324
|
-
// otherwise the message is sent out to every device that should be a recipient
|
|
325
290
|
if (!isGroup && !isStatus) {
|
|
326
291
|
additionalAttributes = { ...additionalAttributes, 'device_fanout': 'false' };
|
|
327
292
|
}
|
|
@@ -330,19 +295,15 @@ const makeMessagesSocket = (config) => {
|
|
|
330
295
|
}
|
|
331
296
|
await authState.keys.transaction(async () => {
|
|
332
297
|
const mediaType = getMediaType(messages);
|
|
333
|
-
|
|
334
298
|
if (mediaType) {
|
|
335
299
|
extraAttrs['mediatype'] = mediaType
|
|
336
300
|
}
|
|
337
|
-
|
|
338
301
|
if (messages.pinInChatMessage || messages.keepInChatMessage || message.reactionMessage || message.protocolMessage?.editedMessage) {
|
|
339
302
|
extraAttrs['decrypt-fail'] = 'hide'
|
|
340
|
-
}
|
|
341
|
-
|
|
303
|
+
}
|
|
342
304
|
if (messages.interactiveResponseMessage?.nativeFlowResponseMessage) {
|
|
343
305
|
extraAttrs['native_flow_name'] = messages.interactiveResponseMessage?.nativeFlowResponseMessage.name
|
|
344
306
|
}
|
|
345
|
-
|
|
346
307
|
if (isGroup || isStatus) {
|
|
347
308
|
const [groupData, senderKeyMap] = await Promise.all([
|
|
348
309
|
(async () => {
|
|
@@ -350,11 +311,9 @@ const makeMessagesSocket = (config) => {
|
|
|
350
311
|
if (groupData) {
|
|
351
312
|
logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
|
|
352
313
|
}
|
|
353
|
-
|
|
354
314
|
else if (!isStatus) {
|
|
355
315
|
groupData = await groupMetadata(jid)
|
|
356
316
|
}
|
|
357
|
-
|
|
358
317
|
return groupData;
|
|
359
318
|
})(),
|
|
360
319
|
(async () => {
|
|
@@ -362,51 +321,32 @@ const makeMessagesSocket = (config) => {
|
|
|
362
321
|
const result = await authState.keys.get('sender-key-memory', [jid])
|
|
363
322
|
return result[jid] || {}
|
|
364
323
|
}
|
|
365
|
-
|
|
366
324
|
return {}
|
|
367
|
-
|
|
368
|
-
})()
|
|
325
|
+
})()
|
|
369
326
|
]);
|
|
370
327
|
if (!participant) {
|
|
371
328
|
const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : []
|
|
372
|
-
|
|
373
329
|
if (isStatus && statusJidList) {
|
|
374
330
|
participantsList.push(...statusJidList)
|
|
375
331
|
}
|
|
376
|
-
|
|
377
|
-
// if (!isStatus) {
|
|
378
|
-
// const expiration = await getEphemeralGroup(jid)
|
|
379
|
-
// additionalAttributes = {
|
|
380
|
-
// ...additionalAttributes,
|
|
381
|
-
// addressing_mode: 'pn',
|
|
382
|
-
// ...expiration ? { expiration: expiration.toString() } : null
|
|
383
|
-
// }
|
|
384
|
-
// }
|
|
385
|
-
|
|
386
332
|
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false)
|
|
387
333
|
devices.push(...additionalDevices)
|
|
388
334
|
}
|
|
389
|
-
|
|
390
335
|
const patched = await patchMessageBeforeSending(message, devices.map(d => WABinary_1.jidEncode(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device)));
|
|
391
336
|
const bytes = Utils_1.encodeWAMessage(patched);
|
|
392
|
-
|
|
393
337
|
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
|
|
394
338
|
group: destinationJid,
|
|
395
339
|
data: bytes,
|
|
396
340
|
meId,
|
|
397
341
|
});
|
|
398
342
|
const senderKeyJids = [];
|
|
399
|
-
|
|
400
343
|
for (const { user, device } of devices) {
|
|
401
344
|
const jid = WABinary_1.jidEncode(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
|
|
402
345
|
if (!senderKeyMap[jid] || !!participant) {
|
|
403
346
|
senderKeyJids.push(jid);
|
|
404
|
-
// store that this person has had the sender keys sent to them
|
|
405
347
|
senderKeyMap[jid] = true;
|
|
406
348
|
}
|
|
407
349
|
}
|
|
408
|
-
// if there are some participants with whom the session has not been established
|
|
409
|
-
// if there are, we re-send the senderkey
|
|
410
350
|
if (senderKeyJids.length) {
|
|
411
351
|
logger.debug({ senderKeyJids }, 'sending new sender key');
|
|
412
352
|
const senderKeyMsg = {
|
|
@@ -428,21 +368,16 @@ const makeMessagesSocket = (config) => {
|
|
|
428
368
|
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
|
|
429
369
|
}
|
|
430
370
|
else if (isNewsletter) {
|
|
431
|
-
// Message edit
|
|
432
371
|
if (message.protocolMessage?.editedMessage) {
|
|
433
372
|
msgId = message.protocolMessage.key?.id
|
|
434
373
|
message = message.protocolMessage.editedMessage
|
|
435
374
|
}
|
|
436
|
-
|
|
437
|
-
// Message delete
|
|
438
375
|
if (message.protocolMessage?.type === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
|
|
439
376
|
msgId = message.protocolMessage.key?.id
|
|
440
377
|
message = {}
|
|
441
378
|
}
|
|
442
|
-
|
|
443
379
|
const patched = await patchMessageBeforeSending(message, [])
|
|
444
380
|
const bytes = Utils_1.encodeNewsletterMessage(patched)
|
|
445
|
-
|
|
446
381
|
binaryNodeContent.push({
|
|
447
382
|
tag: 'plaintext',
|
|
448
383
|
attrs: extraAttrs ? extraAttrs : {},
|
|
@@ -456,10 +391,8 @@ const makeMessagesSocket = (config) => {
|
|
|
456
391
|
if (user !== meUser) {
|
|
457
392
|
devices.push({ user: meUser })
|
|
458
393
|
}
|
|
459
|
-
|
|
460
394
|
if (additionalAttributes?.['category'] !== 'peer') {
|
|
461
395
|
const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true)
|
|
462
|
-
|
|
463
396
|
devices.push(...additionalDevices)
|
|
464
397
|
}
|
|
465
398
|
}
|
|
@@ -469,15 +402,12 @@ const makeMessagesSocket = (config) => {
|
|
|
469
402
|
for (const { user, device } of devices) {
|
|
470
403
|
const isMe = user === meUser
|
|
471
404
|
const jid = WABinary_1.jidEncode(isMe && isLid ? authState.creds?.me?.lid?.split(':')[0] || user : user, isLid ? 'lid' : 's.whatsapp.net', device)
|
|
472
|
-
|
|
473
405
|
if (isMe) {
|
|
474
406
|
meJids.push(jid)
|
|
475
407
|
}
|
|
476
|
-
|
|
477
408
|
else {
|
|
478
409
|
otherJids.push(jid)
|
|
479
410
|
}
|
|
480
|
-
|
|
481
411
|
allJids.push(jid)
|
|
482
412
|
}
|
|
483
413
|
await assertSessions(allJids, false);
|
|
@@ -492,12 +422,10 @@ const makeMessagesSocket = (config) => {
|
|
|
492
422
|
if (participants.length) {
|
|
493
423
|
if (additionalAttributes?.['category'] === 'peer') {
|
|
494
424
|
const peerNode = participants[0]?.content?.[0]
|
|
495
|
-
|
|
496
425
|
if (peerNode) {
|
|
497
|
-
binaryNodeContent.push(peerNode)
|
|
426
|
+
binaryNodeContent.push(peerNode)
|
|
498
427
|
}
|
|
499
428
|
}
|
|
500
|
-
|
|
501
429
|
else {
|
|
502
430
|
binaryNodeContent.push({
|
|
503
431
|
tag: 'participants',
|
|
@@ -506,19 +434,15 @@ const makeMessagesSocket = (config) => {
|
|
|
506
434
|
})
|
|
507
435
|
}
|
|
508
436
|
}
|
|
509
|
-
|
|
510
437
|
const stanza = {
|
|
511
438
|
tag: 'message',
|
|
512
439
|
attrs: {
|
|
513
440
|
id: msgId,
|
|
514
|
-
type: getTypeMessage(messages),
|
|
441
|
+
type: getTypeMessage(messages),
|
|
515
442
|
...(additionalAttributes || {})
|
|
516
443
|
},
|
|
517
444
|
content: binaryNodeContent
|
|
518
445
|
}
|
|
519
|
-
// if the participant to send to is explicitly specified (generally retry recp)
|
|
520
|
-
// ensure the message is only sent to that person
|
|
521
|
-
// if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
|
|
522
446
|
if (participant) {
|
|
523
447
|
if (WABinary_1.isJidGroup(destinationJid)) {
|
|
524
448
|
stanza.attrs.to = destinationJid;
|
|
@@ -543,150 +467,67 @@ const makeMessagesSocket = (config) => {
|
|
|
543
467
|
});
|
|
544
468
|
logger.debug({ jid }, 'adding device identity');
|
|
545
469
|
}
|
|
546
|
-
|
|
547
470
|
if (AI && isPrivate) {
|
|
548
471
|
const botNode = {
|
|
549
|
-
tag: 'bot',
|
|
472
|
+
tag: 'bot',
|
|
550
473
|
attrs: {
|
|
551
474
|
biz_bot: '1'
|
|
552
475
|
}
|
|
553
476
|
}
|
|
554
|
-
|
|
555
|
-
const filteredBizBot = WABinary_1.getBinaryNodeFilter(additionalNodes ? additionalNodes : [])
|
|
556
|
-
|
|
477
|
+
const filteredBizBot = WABinary_1.getBinaryNodeFilter(additionalNodes ? additionalNodes : [])
|
|
557
478
|
if (filteredBizBot) {
|
|
558
|
-
stanza.content.push(...additionalNodes)
|
|
479
|
+
stanza.content.push(...additionalNodes)
|
|
559
480
|
didPushAdditional = true
|
|
560
481
|
}
|
|
561
|
-
|
|
562
482
|
else {
|
|
563
|
-
stanza.content.push(botNode)
|
|
483
|
+
stanza.content.push(botNode)
|
|
564
484
|
}
|
|
565
485
|
}
|
|
566
|
-
|
|
567
|
-
if(!isNewsletter && buttonType && !isStatus) {
|
|
486
|
+
if (!isNewsletter && buttonType && !isStatus) {
|
|
568
487
|
const content = WABinary_1.getAdditionalNode(buttonType)
|
|
569
488
|
const filteredNode = WABinary_1.getBinaryNodeFilter(additionalNodes)
|
|
570
|
-
|
|
571
489
|
if (filteredNode) {
|
|
572
490
|
didPushAdditional = true
|
|
573
491
|
stanza.content.push(...additionalNodes)
|
|
574
|
-
}
|
|
492
|
+
}
|
|
575
493
|
else {
|
|
576
494
|
stanza.content.push(...content)
|
|
577
495
|
}
|
|
578
496
|
logger.debug({ jid }, 'adding business node')
|
|
579
|
-
}
|
|
580
|
-
|
|
497
|
+
}
|
|
581
498
|
if (!didPushAdditional && additionalNodes && additionalNodes.length > 0) {
|
|
582
499
|
stanza.content.push(...additionalNodes);
|
|
583
500
|
}
|
|
584
|
-
|
|
585
501
|
logger.debug({ msgId }, `sending message to ${participants.length} devices`);
|
|
586
502
|
await sendNode(stanza);
|
|
587
503
|
});
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
const groupInfo = await groupMetadata(jid);
|
|
595
|
-
participants = groupInfo.participants.filter(p => !p?.admin).map(p => { if (p.id && p.id.includes('@lid')) { return p.id; } if (p.phoneNumber && p.phoneNumber.includes('@s.whatsapp.net')) { return p.phoneNumber; } return null; }).filter(Boolean);
|
|
596
|
-
} else {
|
|
597
|
-
participants = participantsInput.filter(id => typeof id === 'string');
|
|
598
|
-
}
|
|
599
|
-
if (!participants.length) return;
|
|
600
|
-
let idMsg = generateMessageIDV2()
|
|
601
|
-
const statusJid = 'status@broadcast';
|
|
602
|
-
const isStatus = jid === statusJid;
|
|
603
|
-
const finalJid = jid;
|
|
604
|
-
const destinationJid = !isStatus ? finalJid : statusJid;
|
|
605
|
-
const meMsg = {
|
|
606
|
-
deviceSentMessage: {
|
|
607
|
-
destinationJid,
|
|
608
|
-
message
|
|
504
|
+
message = Types_1.WAProto.Message.fromObject(message)
|
|
505
|
+
const messageJSON = {
|
|
506
|
+
key: {
|
|
507
|
+
remoteJid: jid,
|
|
508
|
+
fromMe: true,
|
|
509
|
+
id: msgId
|
|
609
510
|
},
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
for (let i = 0; i < participants.length; i += batchSize) {
|
|
616
|
-
chunked.push(participants.slice(i, i + batchSize));
|
|
617
|
-
}
|
|
618
|
-
for (const chunk of chunked) {
|
|
619
|
-
const devices = await getUSyncDevices(chunk, false, false) || [];
|
|
620
|
-
const allRecipients = [];
|
|
621
|
-
const meRecipients = [];
|
|
622
|
-
const otherRecipients = [];
|
|
623
|
-
const meId = authState.creds.me.id;
|
|
624
|
-
const meLid = authState.creds.me?.lid;
|
|
625
|
-
const { user: mePnUser } = jidDecode(meId);
|
|
626
|
-
const { user: meLidUser } = meLid ? jidDecode(meLid) : { user: null };
|
|
627
|
-
for (const { user, jid } of devices) {
|
|
628
|
-
const isExactSenderDevice = jid === meId || (meLid && jid === meLid);
|
|
629
|
-
if (isExactSenderDevice) {
|
|
630
|
-
continue;
|
|
631
|
-
}
|
|
632
|
-
const isMe = user === mePnUser || user === meLidUser;
|
|
633
|
-
if (isMe) {
|
|
634
|
-
meRecipients.push(jid);
|
|
635
|
-
}
|
|
636
|
-
else {
|
|
637
|
-
otherRecipients.push(jid);
|
|
638
|
-
}
|
|
639
|
-
allRecipients.push(jid);
|
|
640
|
-
}
|
|
641
|
-
try { await assertSessions(allRecipients); } catch (e) { }
|
|
642
|
-
allRecipients.push(meLid.split(":")[0] + "@lid");
|
|
643
|
-
const { nodes, shouldIncludeDeviceIdentity } = await createParticipantNodes(allRecipients, message, {}, meMsg);
|
|
644
|
-
const stanza = {
|
|
645
|
-
tag: 'message',
|
|
646
|
-
attrs: {
|
|
647
|
-
id: idMsg,
|
|
648
|
-
type: getMessageType(message),
|
|
649
|
-
to: jid,
|
|
650
|
-
...(additionalAttributes || {})
|
|
651
|
-
},
|
|
652
|
-
content: [
|
|
653
|
-
{ tag: 'enc', attrs: { v: '2', type: 'none' } },
|
|
654
|
-
{ tag: 'participants', attrs: {}, content: nodes }
|
|
655
|
-
]
|
|
656
|
-
};
|
|
657
|
-
if (buttonType) {
|
|
658
|
-
const content = getAdditionalNode(buttonType);
|
|
659
|
-
const filteredNode = getBinaryNodeFilter(additionalNodes);
|
|
660
|
-
stanza.content.push(...(filteredNode ? additionalNodes : content));
|
|
661
|
-
}
|
|
662
|
-
if (additionalNodes?.length) {
|
|
663
|
-
stanza.content.push(...additionalNodes);
|
|
664
|
-
}
|
|
665
|
-
if (shouldIncludeDeviceIdentity) {
|
|
666
|
-
stanza.content.push({
|
|
667
|
-
tag: 'device-identity',
|
|
668
|
-
attrs: {},
|
|
669
|
-
content: encodeSignedDeviceIdentity(authState.creds.account, true)
|
|
670
|
-
});
|
|
671
|
-
}
|
|
672
|
-
await sendNode(stanza);
|
|
511
|
+
message: message,
|
|
512
|
+
messageTimestamp: Utils_1.unixTimestampSeconds(new Date()),
|
|
513
|
+
messageStubParameters: [],
|
|
514
|
+
participant: WABinary_1.isJidGroup(jid) || WABinary_1.isJidStatusBroadcast(jid) ? meId : undefined,
|
|
515
|
+
status: Types_1.WAMessageStatus.PENDING
|
|
673
516
|
}
|
|
674
|
-
return
|
|
517
|
+
return Types_1.WAProto.WebMessageInfo.fromObject(messageJSON);
|
|
675
518
|
};
|
|
676
|
-
|
|
677
519
|
const getTypeMessage = (msg) => {
|
|
678
|
-
|
|
520
|
+
const message = Utils_1.normalizeMessageContent(msg);
|
|
679
521
|
if (message.reactionMessage) {
|
|
680
522
|
return 'reaction'
|
|
681
|
-
}
|
|
523
|
+
}
|
|
682
524
|
else if (getMediaType(message)) {
|
|
683
525
|
return 'media'
|
|
684
|
-
}
|
|
526
|
+
}
|
|
685
527
|
else {
|
|
686
528
|
return 'text'
|
|
687
529
|
}
|
|
688
530
|
}
|
|
689
|
-
|
|
690
531
|
const getMediaType = (message) => {
|
|
691
532
|
if (message.imageMessage) {
|
|
692
533
|
return 'image'
|
|
@@ -737,7 +578,6 @@ const makeMessagesSocket = (config) => {
|
|
|
737
578
|
return 'productlink'
|
|
738
579
|
}
|
|
739
580
|
}
|
|
740
|
-
|
|
741
581
|
const getButtonType = (message) => {
|
|
742
582
|
if (message.listMessage) {
|
|
743
583
|
return 'list'
|
|
@@ -753,9 +593,8 @@ const makeMessagesSocket = (config) => {
|
|
|
753
593
|
}
|
|
754
594
|
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_info') {
|
|
755
595
|
return 'payment_info'
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
} else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_status') {
|
|
596
|
+
}
|
|
597
|
+
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_status') {
|
|
759
598
|
return 'payment_status'
|
|
760
599
|
}
|
|
761
600
|
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_method') {
|
|
@@ -793,9 +632,9 @@ const makeMessagesSocket = (config) => {
|
|
|
793
632
|
]
|
|
794
633
|
});
|
|
795
634
|
return result;
|
|
796
|
-
}
|
|
635
|
+
}
|
|
797
636
|
const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
|
|
798
|
-
const
|
|
637
|
+
const rahmi = new kikyy(Utils_1, waUploadToServer, relayMessage, config, sock);
|
|
799
638
|
const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
|
|
800
639
|
return {
|
|
801
640
|
...sock,
|
|
@@ -804,7 +643,7 @@ const makeMessagesSocket = (config) => {
|
|
|
804
643
|
relayMessage,
|
|
805
644
|
sendReceipt,
|
|
806
645
|
sendReceipts,
|
|
807
|
-
|
|
646
|
+
rahmi,
|
|
808
647
|
readMessages,
|
|
809
648
|
refreshMediaConn,
|
|
810
649
|
getUSyncDevices,
|
|
@@ -851,134 +690,140 @@ const makeMessagesSocket = (config) => {
|
|
|
851
690
|
ev.emit('messages.update', [
|
|
852
691
|
{
|
|
853
692
|
key: message.key,
|
|
854
|
-
update: {
|
|
693
|
+
update: {
|
|
855
694
|
message: message.message
|
|
856
695
|
}
|
|
857
696
|
}
|
|
858
697
|
]);
|
|
859
698
|
return message;
|
|
860
699
|
},
|
|
700
|
+
setLabelGroup: async (id, text) => {
|
|
701
|
+
await relayMessage(id, {
|
|
702
|
+
protocolMessage: {
|
|
703
|
+
type: 30,
|
|
704
|
+
memberLabel: {
|
|
705
|
+
label: text.slice(0, 30)
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
}, {
|
|
709
|
+
additionalNodes: [
|
|
710
|
+
{
|
|
711
|
+
tag: "meta",
|
|
712
|
+
attrs: {
|
|
713
|
+
tag_reason: "user_update",
|
|
714
|
+
appdata: "member_tag"
|
|
715
|
+
},
|
|
716
|
+
content: undefined
|
|
717
|
+
}
|
|
718
|
+
]
|
|
719
|
+
})
|
|
720
|
+
},
|
|
721
|
+
sendStatusMention: async (content, jids = []) => {
|
|
722
|
+
return await rahmi.sendStatusWhatsApp(content, jids);
|
|
723
|
+
},
|
|
861
724
|
sendMessage: async (jid, content, options = {}) => {
|
|
862
725
|
const userJid = authState.creds.me.id;
|
|
863
726
|
delete options.ephemeralExpiration
|
|
864
727
|
const { filter = false, quoted } = options;
|
|
865
728
|
const getParticipantAttr = () => filter ? { participant: { jid } } : {};
|
|
866
|
-
const messageType =
|
|
729
|
+
const messageType = rahmi.detectType(content);
|
|
867
730
|
if (typeof content === 'object' && 'disappearingMessagesInChat' in content &&
|
|
868
731
|
typeof content['disappearingMessagesInChat'] !== 'undefined' && WABinary_1.isJidGroup(jid)) {
|
|
869
732
|
const { disappearingMessagesInChat } = content
|
|
870
|
-
|
|
871
733
|
const value = typeof disappearingMessagesInChat === 'boolean' ?
|
|
872
734
|
(disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
|
|
873
735
|
disappearingMessagesInChat
|
|
874
|
-
|
|
875
736
|
await groupToggleEphemeral(jid, value)
|
|
876
737
|
}
|
|
877
|
-
|
|
878
738
|
else {
|
|
879
739
|
let mediaHandle
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
return await luki.handlePollResult(content, jid, quoted)
|
|
912
|
-
case 'STATUS_MENTION':
|
|
913
|
-
return await luki.handleStMention(content, jid, quoted)
|
|
914
|
-
case 'ORDER':
|
|
915
|
-
return await luki.handleOrderMessage(content, jid, quoted)
|
|
916
|
-
case 'GROUP_STATUS':
|
|
917
|
-
return await luki.handleGroupStory(content, jid, quoted)
|
|
918
|
-
case 'GROUP_LABEL':
|
|
919
|
-
return await luki.handleGbLabel(content, jid)
|
|
740
|
+
if (messageType) {
|
|
741
|
+
switch (messageType) {
|
|
742
|
+
case 'PAYMENT':
|
|
743
|
+
const paymentContent = await rahmi.handlePayment(content, quoted);
|
|
744
|
+
return await relayMessage(jid, paymentContent, {
|
|
745
|
+
messageId: Utils_1.generateMessageID(),
|
|
746
|
+
...getParticipantAttr()
|
|
747
|
+
});
|
|
748
|
+
case 'PRODUCT':
|
|
749
|
+
const productContent = await rahmi.handleProduct(content, jid, quoted);
|
|
750
|
+
const productMsg = await Utils_1.generateWAMessageFromContent(jid, productContent, { quoted });
|
|
751
|
+
return await relayMessage(jid, productMsg.message, {
|
|
752
|
+
messageId: productMsg.key.id,
|
|
753
|
+
...getParticipantAttr()
|
|
754
|
+
});
|
|
755
|
+
case 'INTERACTIVE':
|
|
756
|
+
const interactiveContent = await rahmi.handleInteractive(content, jid, quoted);
|
|
757
|
+
const interactiveMsg = await Utils_1.generateWAMessageFromContent(jid, interactiveContent, { quoted });
|
|
758
|
+
return await relayMessage(jid, interactiveMsg.message, {
|
|
759
|
+
messageId: interactiveMsg.key.id,
|
|
760
|
+
...getParticipantAttr()
|
|
761
|
+
});
|
|
762
|
+
case 'ALBUM':
|
|
763
|
+
return await rahmi.handleAlbum(content, jid, quoted)
|
|
764
|
+
case 'EVENT':
|
|
765
|
+
return await rahmi.handleEvent(content, jid, quoted)
|
|
766
|
+
case 'POLL_RESULT':
|
|
767
|
+
return await rahmi.handlePollResult(content, jid, quoted)
|
|
768
|
+
case 'GROUP_STORY':
|
|
769
|
+
return await rahmi.handleGroupStory(content, jid, quoted)
|
|
770
|
+
}
|
|
920
771
|
}
|
|
921
|
-
|
|
922
|
-
const fullMsg = await Utils_1.generateWAMessage(jid, content, {
|
|
923
|
-
logger,
|
|
924
|
-
userJid,
|
|
925
|
-
quoted,
|
|
926
|
-
getUrlInfo: text => link_preview_1.getUrlInfo(text, {
|
|
927
|
-
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
928
|
-
fetchOpts: {
|
|
929
|
-
timeout: 3000,
|
|
930
|
-
...axiosOptions || {}
|
|
931
|
-
},
|
|
772
|
+
const fullMsg = await Utils_1.generateWAMessage(jid, content, {
|
|
932
773
|
logger,
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
if (isDeleteMsg) {
|
|
955
|
-
const fromMe = content.delete?.fromMe;
|
|
956
|
-
const isGroup = WABinary_1.isJidGroup(content.delete?.remoteJid);
|
|
957
|
-
additionalAttributes.edit = (isGroup && !fromMe) || WABinary_1.isJidNewsLetter(jid) ? '8' : '7';
|
|
958
|
-
} else if (isEditMsg) {
|
|
959
|
-
additionalAttributes.edit = WABinary_1.isJidNewsLetter(jid) ? '3' : '1';
|
|
960
|
-
} else if (isAiMsg) {
|
|
961
|
-
additionalNodes.push({
|
|
962
|
-
attrs: {
|
|
963
|
-
biz_bot: '1'
|
|
964
|
-
}, tag: "bot"
|
|
774
|
+
userJid,
|
|
775
|
+
quoted,
|
|
776
|
+
getUrlInfo: text => link_preview_1.getUrlInfo(text, {
|
|
777
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
778
|
+
fetchOpts: {
|
|
779
|
+
timeout: 3000,
|
|
780
|
+
...axiosOptions || {}
|
|
781
|
+
},
|
|
782
|
+
logger,
|
|
783
|
+
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
784
|
+
}),
|
|
785
|
+
upload: async (readStream, opts) => {
|
|
786
|
+
const up = await waUploadToServer(readStream, {
|
|
787
|
+
...opts,
|
|
788
|
+
newsletter: WABinary_1.isJidNewsLetter(jid)
|
|
789
|
+
});
|
|
790
|
+
return up;
|
|
791
|
+
},
|
|
792
|
+
mediaCache: config.mediaCache,
|
|
793
|
+
options: config.options,
|
|
794
|
+
...options
|
|
965
795
|
});
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
796
|
+
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
797
|
+
const isEditMsg = 'edit' in content && !!content.edit;
|
|
798
|
+
const isAiMsg = 'ai' in content && !!content.ai;
|
|
799
|
+
const additionalAttributes = {};
|
|
800
|
+
const additionalNodes = [];
|
|
801
|
+
if (isDeleteMsg) {
|
|
802
|
+
const fromMe = content.delete?.fromMe;
|
|
803
|
+
const isGroup = WABinary_1.isJidGroup(content.delete?.remoteJid);
|
|
804
|
+
additionalAttributes.edit = (isGroup && !fromMe) || WABinary_1.isJidNewsLetter(jid) ? '8' : '7';
|
|
805
|
+
} else if (isEditMsg) {
|
|
806
|
+
additionalAttributes.edit = WABinary_1.isJidNewsLetter(jid) ? '3' : '1';
|
|
807
|
+
} else if (isAiMsg) {
|
|
808
|
+
additionalNodes.push({
|
|
809
|
+
attrs: {
|
|
810
|
+
biz_bot: '1'
|
|
811
|
+
}, tag: "bot"
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
await relayMessage(jid, fullMsg.message, {
|
|
815
|
+
messageId: fullMsg.key.id,
|
|
816
|
+
cachedGroupMetadata: options.cachedGroupMetadata,
|
|
817
|
+
additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes,
|
|
818
|
+
additionalAttributes,
|
|
819
|
+
statusJidList: options.statusJidList
|
|
979
820
|
});
|
|
980
|
-
|
|
981
|
-
|
|
821
|
+
if (config.emitOwnEvents) {
|
|
822
|
+
process.nextTick(() => {
|
|
823
|
+
processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
return fullMsg;
|
|
982
827
|
}
|
|
983
828
|
}
|
|
984
829
|
}
|