@devil-fight/baileys 1.0.3 → 1.0.4
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/README.md +18 -376
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/information.json +1 -0
- package/lib/Socket/chats.js +20 -1
- package/lib/Socket/dugong.js +160 -7
- package/lib/Socket/messages-send.js +132 -210
- package/lib/Socket/newsletter.js +175 -53
- package/lib/Utils/generics.js +79 -4
- package/lib/Utils/messages.js +4 -1
- package/lib/index.js +1 -7
- package/package.json +6 -9
- 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/dugong.d.ts +0 -254
- package/lib/Socket/groups.d.ts +0 -115
- package/lib/Socket/index.d.ts +0 -173
- 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 -43
- 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/WAUSync/index.d.ts +0 -3
- 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")
|
|
16
|
+
const WAUSync_1 = require("../WAUSync");
|
|
18
17
|
const kikyy = require('./dugong');
|
|
19
|
-
var ListType = WAProto_1.proto.Message.ListMessage.ListType;
|
|
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,7 +258,7 @@ const makeMessagesSocket = (config) => {
|
|
|
290
258
|
return node;
|
|
291
259
|
}));
|
|
292
260
|
return { nodes, shouldIncludeDeviceIdentity };
|
|
293
|
-
};
|
|
261
|
+
};
|
|
294
262
|
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, useCachedGroupMetadata, statusJidList, AI = true }) => {
|
|
295
263
|
const meId = authState.creds.me.id;
|
|
296
264
|
let shouldIncludeDeviceIdentity = 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,56 +467,46 @@ 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
504
|
message = Types_1.WAProto.Message.fromObject(message)
|
|
590
|
-
|
|
591
505
|
const messageJSON = {
|
|
592
506
|
key: {
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
507
|
+
remoteJid: jid,
|
|
508
|
+
fromMe: true,
|
|
509
|
+
id: msgId
|
|
596
510
|
},
|
|
597
511
|
message: message,
|
|
598
512
|
messageTimestamp: Utils_1.unixTimestampSeconds(new Date()),
|
|
@@ -600,23 +514,20 @@ const makeMessagesSocket = (config) => {
|
|
|
600
514
|
participant: WABinary_1.isJidGroup(jid) || WABinary_1.isJidStatusBroadcast(jid) ? meId : undefined,
|
|
601
515
|
status: Types_1.WAMessageStatus.PENDING
|
|
602
516
|
}
|
|
603
|
-
|
|
604
|
-
return Types_1.WAProto.WebMessageInfo.fromObject(messageJSON)
|
|
605
|
-
// return msgId;
|
|
517
|
+
return Types_1.WAProto.WebMessageInfo.fromObject(messageJSON);
|
|
606
518
|
};
|
|
607
519
|
const getTypeMessage = (msg) => {
|
|
608
|
-
|
|
520
|
+
const message = Utils_1.normalizeMessageContent(msg);
|
|
609
521
|
if (message.reactionMessage) {
|
|
610
522
|
return 'reaction'
|
|
611
|
-
}
|
|
523
|
+
}
|
|
612
524
|
else if (getMediaType(message)) {
|
|
613
525
|
return 'media'
|
|
614
|
-
}
|
|
526
|
+
}
|
|
615
527
|
else {
|
|
616
528
|
return 'text'
|
|
617
529
|
}
|
|
618
530
|
}
|
|
619
|
-
|
|
620
531
|
const getMediaType = (message) => {
|
|
621
532
|
if (message.imageMessage) {
|
|
622
533
|
return 'image'
|
|
@@ -667,7 +578,6 @@ const makeMessagesSocket = (config) => {
|
|
|
667
578
|
return 'productlink'
|
|
668
579
|
}
|
|
669
580
|
}
|
|
670
|
-
|
|
671
581
|
const getButtonType = (message) => {
|
|
672
582
|
if (message.listMessage) {
|
|
673
583
|
return 'list'
|
|
@@ -722,9 +632,9 @@ const makeMessagesSocket = (config) => {
|
|
|
722
632
|
]
|
|
723
633
|
});
|
|
724
634
|
return result;
|
|
725
|
-
}
|
|
635
|
+
}
|
|
726
636
|
const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
|
|
727
|
-
const rahmi = new kikyy(Utils_1, waUploadToServer, relayMessage);
|
|
637
|
+
const rahmi = new kikyy(Utils_1, waUploadToServer, relayMessage, config, sock);
|
|
728
638
|
const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
|
|
729
639
|
return {
|
|
730
640
|
...sock,
|
|
@@ -780,13 +690,37 @@ const makeMessagesSocket = (config) => {
|
|
|
780
690
|
ev.emit('messages.update', [
|
|
781
691
|
{
|
|
782
692
|
key: message.key,
|
|
783
|
-
update: {
|
|
693
|
+
update: {
|
|
784
694
|
message: message.message
|
|
785
695
|
}
|
|
786
696
|
}
|
|
787
697
|
]);
|
|
788
698
|
return message;
|
|
789
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
|
+
},
|
|
790
724
|
sendMessage: async (jid, content, options = {}) => {
|
|
791
725
|
const userJid = authState.creds.me.id;
|
|
792
726
|
delete options.ephemeralExpiration
|
|
@@ -796,112 +730,100 @@ const makeMessagesSocket = (config) => {
|
|
|
796
730
|
if (typeof content === 'object' && 'disappearingMessagesInChat' in content &&
|
|
797
731
|
typeof content['disappearingMessagesInChat'] !== 'undefined' && WABinary_1.isJidGroup(jid)) {
|
|
798
732
|
const { disappearingMessagesInChat } = content
|
|
799
|
-
|
|
800
733
|
const value = typeof disappearingMessagesInChat === 'boolean' ?
|
|
801
734
|
(disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
|
|
802
735
|
disappearingMessagesInChat
|
|
803
|
-
|
|
804
736
|
await groupToggleEphemeral(jid, value)
|
|
805
737
|
}
|
|
806
|
-
|
|
807
738
|
else {
|
|
808
739
|
let mediaHandle
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
return await rahmi.handlePollResult(content, jid, quoted)
|
|
841
|
-
case 'GROUP_STORY':
|
|
842
|
-
return await rahmi.handleGroupStory(content, jid, quoted)
|
|
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
|
+
}
|
|
843
771
|
}
|
|
844
|
-
|
|
845
|
-
const fullMsg = await Utils_1.generateWAMessage(jid, content, {
|
|
846
|
-
logger,
|
|
847
|
-
userJid,
|
|
848
|
-
quoted,
|
|
849
|
-
getUrlInfo: text => link_preview_1.getUrlInfo(text, {
|
|
850
|
-
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
851
|
-
fetchOpts: {
|
|
852
|
-
timeout: 3000,
|
|
853
|
-
...axiosOptions || {}
|
|
854
|
-
},
|
|
772
|
+
const fullMsg = await Utils_1.generateWAMessage(jid, content, {
|
|
855
773
|
logger,
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
if (isDeleteMsg) {
|
|
878
|
-
const fromMe = content.delete?.fromMe;
|
|
879
|
-
const isGroup = WABinary_1.isJidGroup(content.delete?.remoteJid);
|
|
880
|
-
additionalAttributes.edit = (isGroup && !fromMe) || WABinary_1.isJidNewsLetter(jid) ? '8' : '7';
|
|
881
|
-
} else if (isEditMsg) {
|
|
882
|
-
additionalAttributes.edit = WABinary_1.isJidNewsLetter(jid) ? '3' : '1';
|
|
883
|
-
} else if (isAiMsg) {
|
|
884
|
-
additionalNodes.push({
|
|
885
|
-
attrs: {
|
|
886
|
-
biz_bot: '1'
|
|
887
|
-
}, 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
|
|
888
795
|
});
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
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
|
|
902
820
|
});
|
|
903
|
-
|
|
904
|
-
|
|
821
|
+
if (config.emitOwnEvents) {
|
|
822
|
+
process.nextTick(() => {
|
|
823
|
+
processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
return fullMsg;
|
|
905
827
|
}
|
|
906
828
|
}
|
|
907
829
|
}
|