@devil-fight/baileys 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/Defaults/index.d.ts +53 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/web-socket-client.d.ts +12 -0
- package/lib/Socket/business.d.ts +171 -0
- package/lib/Socket/chats.d.ts +267 -0
- package/lib/Socket/chats.js +1 -20
- package/lib/Socket/dugong.d.ts +254 -0
- package/lib/Socket/dugong.js +7 -160
- package/lib/Socket/groups.d.ts +115 -0
- package/lib/Socket/index.d.ts +173 -0
- package/lib/Socket/messages-recv.d.ts +161 -0
- package/lib/Socket/messages-send.d.ts +149 -0
- package/lib/Socket/messages-send.js +210 -132
- package/lib/Socket/newsletter.d.ts +134 -0
- package/lib/Socket/newsletter.js +31 -139
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/socket.d.ts +43 -0
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/make-cache-manager-store.d.ts +13 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Types/Auth.d.ts +110 -0
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Chat.d.ts +102 -0
- package/lib/Types/Contact.d.ts +19 -0
- package/lib/Types/Events.d.ts +157 -0
- package/lib/Types/GroupMetadata.d.ts +55 -0
- package/lib/Types/Label.d.ts +35 -0
- package/lib/Types/LabelAssociation.d.ts +29 -0
- package/lib/Types/Message.d.ts +273 -0
- package/lib/Types/Newsletter.d.ts +103 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/lib/Types/Socket.d.ts +111 -0
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/index.d.ts +57 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/chat-utils.d.ts +71 -0
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/decode-wa-message.d.ts +19 -0
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/generics.d.ts +92 -0
- package/lib/Utils/generics.js +4 -79
- package/lib/Utils/history.d.ts +15 -0
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/logger.d.ts +4 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/messages-media.d.ts +116 -0
- package/lib/Utils/messages.d.ts +77 -0
- package/lib/Utils/messages.js +1 -4
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/process-message.d.ts +41 -0
- package/lib/Utils/signal.d.ts +32 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/WABinary/constants.d.ts +30 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/generic-utils.d.ts +17 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/jid-utils.d.ts +31 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WAM/BinaryInfo.d.ts +17 -0
- package/lib/WAM/constants.d.ts +38 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/USyncQuery.d.ts +28 -0
- package/lib/WAUSync/USyncUser.d.ts +12 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +1 -1
- package/package.json +8 -6
- package/LICENSE +0 -21
- package/lib/Defaults/information.json +0 -1
|
@@ -8,13 +8,15 @@ 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
|
|
11
|
+
const axios_1 = require("axios")
|
|
12
|
+
const Types_1 = require("../Types")
|
|
12
13
|
const Utils_1 = require("../Utils");
|
|
13
14
|
const link_preview_1 = require("../Utils/link-preview");
|
|
14
15
|
const WABinary_1 = require("../WABinary");
|
|
15
16
|
const newsletter_1 = require("./newsletter");
|
|
16
|
-
const WAUSync_1 = require("../WAUSync")
|
|
17
|
+
const WAUSync_1 = require("../WAUSync")
|
|
17
18
|
const kikyy = require('./dugong');
|
|
19
|
+
var ListType = WAProto_1.proto.Message.ListMessage.ListType;
|
|
18
20
|
const makeMessagesSocket = (config) => {
|
|
19
21
|
const {
|
|
20
22
|
logger,
|
|
@@ -32,6 +34,7 @@ const makeMessagesSocket = (config) => {
|
|
|
32
34
|
upsertMessage,
|
|
33
35
|
query,
|
|
34
36
|
fetchPrivacySettings,
|
|
37
|
+
generateMessageTag,
|
|
35
38
|
sendNode,
|
|
36
39
|
groupMetadata,
|
|
37
40
|
groupToggleEphemeral,
|
|
@@ -71,6 +74,10 @@ const makeMessagesSocket = (config) => {
|
|
|
71
74
|
}
|
|
72
75
|
return mediaConn;
|
|
73
76
|
};
|
|
77
|
+
/**
|
|
78
|
+
* generic send receipt function
|
|
79
|
+
* used for receipts of phone call, read, delivery etc.
|
|
80
|
+
* */
|
|
74
81
|
const sendReceipt = async (jid, participant, messageIds, type) => {
|
|
75
82
|
const node = {
|
|
76
83
|
tag: 'receipt',
|
|
@@ -111,63 +118,84 @@ const makeMessagesSocket = (config) => {
|
|
|
111
118
|
logger.debug({ attrs: node.attrs, messageIds }, 'sending receipt for messages');
|
|
112
119
|
await sendNode(node);
|
|
113
120
|
};
|
|
121
|
+
/** Correctly bulk send receipts to multiple chats, participants */
|
|
114
122
|
const sendReceipts = async (keys, type) => {
|
|
115
123
|
const recps = (0, Utils_1.aggregateMessageKeysNotFromMe)(keys);
|
|
116
124
|
for (const { jid, participant, messageIds } of recps) {
|
|
117
125
|
await sendReceipt(jid, participant, messageIds, type);
|
|
118
126
|
}
|
|
119
127
|
};
|
|
128
|
+
/** Bulk read messages. Keys can be from different chats & participants */
|
|
120
129
|
const readMessages = async (keys) => {
|
|
121
130
|
const privacySettings = await fetchPrivacySettings();
|
|
131
|
+
// based on privacy settings, we have to change the read type
|
|
122
132
|
const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self';
|
|
123
133
|
await sendReceipts(keys, readType);
|
|
124
134
|
};
|
|
135
|
+
/** Fetch all the devices we've to send a message to */
|
|
125
136
|
const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
|
|
126
137
|
const deviceResults = []
|
|
138
|
+
|
|
127
139
|
if (!useCache) {
|
|
128
140
|
logger.debug('not using cache for devices')
|
|
129
141
|
}
|
|
142
|
+
|
|
130
143
|
const toFetch = []
|
|
144
|
+
|
|
131
145
|
jids = Array.from(new Set(jids))
|
|
146
|
+
|
|
132
147
|
for (let jid of jids) {
|
|
133
148
|
const user = WABinary_1.jidDecode(jid)?.user
|
|
149
|
+
|
|
134
150
|
jid = WABinary_1.jidNormalizedUser(jid)
|
|
151
|
+
|
|
135
152
|
if (useCache) {
|
|
136
153
|
const devices = userDevicesCache.get(user)
|
|
154
|
+
|
|
137
155
|
if (devices) {
|
|
138
156
|
deviceResults.push(...devices)
|
|
139
157
|
logger.trace({ user }, 'using cache for devices')
|
|
140
158
|
}
|
|
159
|
+
|
|
141
160
|
else {
|
|
142
161
|
toFetch.push(jid)
|
|
143
162
|
}
|
|
144
163
|
}
|
|
164
|
+
|
|
145
165
|
else {
|
|
146
166
|
toFetch.push(jid)
|
|
147
167
|
}
|
|
148
168
|
}
|
|
169
|
+
|
|
149
170
|
if (!toFetch.length) {
|
|
150
171
|
return deviceResults
|
|
151
172
|
}
|
|
173
|
+
|
|
152
174
|
const query = new WAUSync_1.USyncQuery()
|
|
153
175
|
.withContext('message')
|
|
154
176
|
.withDeviceProtocol()
|
|
177
|
+
|
|
155
178
|
for (const jid of toFetch) {
|
|
156
179
|
query.withUser(new WAUSync_1.USyncUser().withId(jid))
|
|
157
180
|
}
|
|
181
|
+
|
|
158
182
|
const result = await executeUSyncQuery(query)
|
|
183
|
+
|
|
159
184
|
if (result) {
|
|
160
185
|
const extracted = Utils_1.extractDeviceJids(result?.list, authState.creds.me.id, ignoreZeroDevices)
|
|
161
186
|
const deviceMap = {}
|
|
187
|
+
|
|
162
188
|
for (const item of extracted) {
|
|
163
189
|
deviceMap[item.user] = deviceMap[item.user] || []
|
|
164
190
|
deviceMap[item.user].push(item)
|
|
165
191
|
deviceResults.push(item)
|
|
166
192
|
}
|
|
193
|
+
|
|
167
194
|
for (const key in deviceMap) {
|
|
168
195
|
userDevicesCache.set(key, deviceMap[key])
|
|
169
196
|
}
|
|
170
197
|
}
|
|
198
|
+
|
|
171
199
|
return deviceResults
|
|
172
200
|
}
|
|
173
201
|
const assertSessions = async (jids, force) => {
|
|
@@ -213,10 +241,13 @@ const makeMessagesSocket = (config) => {
|
|
|
213
241
|
}
|
|
214
242
|
return didFetchNewSession;
|
|
215
243
|
};
|
|
244
|
+
|
|
245
|
+
|
|
216
246
|
const sendPeerDataOperationMessage = async (pdoMessage) => {
|
|
217
247
|
if (!authState.creds.me?.id) {
|
|
218
248
|
throw new boom_1.Boom('Not authenticated')
|
|
219
249
|
}
|
|
250
|
+
|
|
220
251
|
const protocolMessage = {
|
|
221
252
|
protocolMessage: {
|
|
222
253
|
peerDataOperationRequestMessage: pdoMessage,
|
|
@@ -227,6 +258,7 @@ const makeMessagesSocket = (config) => {
|
|
|
227
258
|
const msgId = await relayMessage(meJid, protocolMessage, {
|
|
228
259
|
additionalAttributes: {
|
|
229
260
|
category: 'peer',
|
|
261
|
+
// eslint-disable-next-line camelcase
|
|
230
262
|
push_priority: 'high_force',
|
|
231
263
|
},
|
|
232
264
|
});
|
|
@@ -258,7 +290,7 @@ const makeMessagesSocket = (config) => {
|
|
|
258
290
|
return node;
|
|
259
291
|
}));
|
|
260
292
|
return { nodes, shouldIncludeDeviceIdentity };
|
|
261
|
-
};
|
|
293
|
+
}; //apela
|
|
262
294
|
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, useCachedGroupMetadata, statusJidList, AI = true }) => {
|
|
263
295
|
const meId = authState.creds.me.id;
|
|
264
296
|
let shouldIncludeDeviceIdentity = false;
|
|
@@ -284,9 +316,12 @@ const makeMessagesSocket = (config) => {
|
|
|
284
316
|
}
|
|
285
317
|
};
|
|
286
318
|
const extraAttrs = {}
|
|
287
|
-
const messages = Utils_1.normalizeMessageContent(message)
|
|
319
|
+
const messages = Utils_1.normalizeMessageContent(message)
|
|
288
320
|
const buttonType = getButtonType(messages);
|
|
289
321
|
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
|
|
290
325
|
if (!isGroup && !isStatus) {
|
|
291
326
|
additionalAttributes = { ...additionalAttributes, 'device_fanout': 'false' };
|
|
292
327
|
}
|
|
@@ -295,15 +330,19 @@ const makeMessagesSocket = (config) => {
|
|
|
295
330
|
}
|
|
296
331
|
await authState.keys.transaction(async () => {
|
|
297
332
|
const mediaType = getMediaType(messages);
|
|
333
|
+
|
|
298
334
|
if (mediaType) {
|
|
299
335
|
extraAttrs['mediatype'] = mediaType
|
|
300
336
|
}
|
|
337
|
+
|
|
301
338
|
if (messages.pinInChatMessage || messages.keepInChatMessage || message.reactionMessage || message.protocolMessage?.editedMessage) {
|
|
302
339
|
extraAttrs['decrypt-fail'] = 'hide'
|
|
303
|
-
}
|
|
340
|
+
}
|
|
341
|
+
|
|
304
342
|
if (messages.interactiveResponseMessage?.nativeFlowResponseMessage) {
|
|
305
343
|
extraAttrs['native_flow_name'] = messages.interactiveResponseMessage?.nativeFlowResponseMessage.name
|
|
306
344
|
}
|
|
345
|
+
|
|
307
346
|
if (isGroup || isStatus) {
|
|
308
347
|
const [groupData, senderKeyMap] = await Promise.all([
|
|
309
348
|
(async () => {
|
|
@@ -311,9 +350,11 @@ const makeMessagesSocket = (config) => {
|
|
|
311
350
|
if (groupData) {
|
|
312
351
|
logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
|
|
313
352
|
}
|
|
353
|
+
|
|
314
354
|
else if (!isStatus) {
|
|
315
355
|
groupData = await groupMetadata(jid)
|
|
316
356
|
}
|
|
357
|
+
|
|
317
358
|
return groupData;
|
|
318
359
|
})(),
|
|
319
360
|
(async () => {
|
|
@@ -321,32 +362,51 @@ const makeMessagesSocket = (config) => {
|
|
|
321
362
|
const result = await authState.keys.get('sender-key-memory', [jid])
|
|
322
363
|
return result[jid] || {}
|
|
323
364
|
}
|
|
365
|
+
|
|
324
366
|
return {}
|
|
325
|
-
|
|
367
|
+
|
|
368
|
+
})()
|
|
326
369
|
]);
|
|
327
370
|
if (!participant) {
|
|
328
371
|
const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : []
|
|
372
|
+
|
|
329
373
|
if (isStatus && statusJidList) {
|
|
330
374
|
participantsList.push(...statusJidList)
|
|
331
375
|
}
|
|
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
|
+
|
|
332
386
|
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false)
|
|
333
387
|
devices.push(...additionalDevices)
|
|
334
388
|
}
|
|
389
|
+
|
|
335
390
|
const patched = await patchMessageBeforeSending(message, devices.map(d => WABinary_1.jidEncode(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device)));
|
|
336
391
|
const bytes = Utils_1.encodeWAMessage(patched);
|
|
392
|
+
|
|
337
393
|
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
|
|
338
394
|
group: destinationJid,
|
|
339
395
|
data: bytes,
|
|
340
396
|
meId,
|
|
341
397
|
});
|
|
342
398
|
const senderKeyJids = [];
|
|
399
|
+
|
|
343
400
|
for (const { user, device } of devices) {
|
|
344
401
|
const jid = WABinary_1.jidEncode(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
|
|
345
402
|
if (!senderKeyMap[jid] || !!participant) {
|
|
346
403
|
senderKeyJids.push(jid);
|
|
404
|
+
// store that this person has had the sender keys sent to them
|
|
347
405
|
senderKeyMap[jid] = true;
|
|
348
406
|
}
|
|
349
407
|
}
|
|
408
|
+
// if there are some participants with whom the session has not been established
|
|
409
|
+
// if there are, we re-send the senderkey
|
|
350
410
|
if (senderKeyJids.length) {
|
|
351
411
|
logger.debug({ senderKeyJids }, 'sending new sender key');
|
|
352
412
|
const senderKeyMsg = {
|
|
@@ -368,16 +428,21 @@ const makeMessagesSocket = (config) => {
|
|
|
368
428
|
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
|
|
369
429
|
}
|
|
370
430
|
else if (isNewsletter) {
|
|
431
|
+
// Message edit
|
|
371
432
|
if (message.protocolMessage?.editedMessage) {
|
|
372
433
|
msgId = message.protocolMessage.key?.id
|
|
373
434
|
message = message.protocolMessage.editedMessage
|
|
374
435
|
}
|
|
436
|
+
|
|
437
|
+
// Message delete
|
|
375
438
|
if (message.protocolMessage?.type === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
|
|
376
439
|
msgId = message.protocolMessage.key?.id
|
|
377
440
|
message = {}
|
|
378
441
|
}
|
|
442
|
+
|
|
379
443
|
const patched = await patchMessageBeforeSending(message, [])
|
|
380
444
|
const bytes = Utils_1.encodeNewsletterMessage(patched)
|
|
445
|
+
|
|
381
446
|
binaryNodeContent.push({
|
|
382
447
|
tag: 'plaintext',
|
|
383
448
|
attrs: extraAttrs ? extraAttrs : {},
|
|
@@ -391,8 +456,10 @@ const makeMessagesSocket = (config) => {
|
|
|
391
456
|
if (user !== meUser) {
|
|
392
457
|
devices.push({ user: meUser })
|
|
393
458
|
}
|
|
459
|
+
|
|
394
460
|
if (additionalAttributes?.['category'] !== 'peer') {
|
|
395
461
|
const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true)
|
|
462
|
+
|
|
396
463
|
devices.push(...additionalDevices)
|
|
397
464
|
}
|
|
398
465
|
}
|
|
@@ -402,12 +469,15 @@ const makeMessagesSocket = (config) => {
|
|
|
402
469
|
for (const { user, device } of devices) {
|
|
403
470
|
const isMe = user === meUser
|
|
404
471
|
const jid = WABinary_1.jidEncode(isMe && isLid ? authState.creds?.me?.lid?.split(':')[0] || user : user, isLid ? 'lid' : 's.whatsapp.net', device)
|
|
472
|
+
|
|
405
473
|
if (isMe) {
|
|
406
474
|
meJids.push(jid)
|
|
407
475
|
}
|
|
476
|
+
|
|
408
477
|
else {
|
|
409
478
|
otherJids.push(jid)
|
|
410
479
|
}
|
|
480
|
+
|
|
411
481
|
allJids.push(jid)
|
|
412
482
|
}
|
|
413
483
|
await assertSessions(allJids, false);
|
|
@@ -422,10 +492,12 @@ const makeMessagesSocket = (config) => {
|
|
|
422
492
|
if (participants.length) {
|
|
423
493
|
if (additionalAttributes?.['category'] === 'peer') {
|
|
424
494
|
const peerNode = participants[0]?.content?.[0]
|
|
495
|
+
|
|
425
496
|
if (peerNode) {
|
|
426
|
-
binaryNodeContent.push(peerNode)
|
|
497
|
+
binaryNodeContent.push(peerNode) // push only enc
|
|
427
498
|
}
|
|
428
499
|
}
|
|
500
|
+
|
|
429
501
|
else {
|
|
430
502
|
binaryNodeContent.push({
|
|
431
503
|
tag: 'participants',
|
|
@@ -434,15 +506,19 @@ const makeMessagesSocket = (config) => {
|
|
|
434
506
|
})
|
|
435
507
|
}
|
|
436
508
|
}
|
|
509
|
+
|
|
437
510
|
const stanza = {
|
|
438
511
|
tag: 'message',
|
|
439
512
|
attrs: {
|
|
440
513
|
id: msgId,
|
|
441
|
-
type: getTypeMessage(messages),
|
|
514
|
+
type: getTypeMessage(messages),
|
|
442
515
|
...(additionalAttributes || {})
|
|
443
516
|
},
|
|
444
517
|
content: binaryNodeContent
|
|
445
518
|
}
|
|
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
|
|
446
522
|
if (participant) {
|
|
447
523
|
if (WABinary_1.isJidGroup(destinationJid)) {
|
|
448
524
|
stanza.attrs.to = destinationJid;
|
|
@@ -467,46 +543,56 @@ const makeMessagesSocket = (config) => {
|
|
|
467
543
|
});
|
|
468
544
|
logger.debug({ jid }, 'adding device identity');
|
|
469
545
|
}
|
|
546
|
+
|
|
470
547
|
if (AI && isPrivate) {
|
|
471
548
|
const botNode = {
|
|
472
|
-
tag: 'bot',
|
|
549
|
+
tag: 'bot',
|
|
473
550
|
attrs: {
|
|
474
551
|
biz_bot: '1'
|
|
475
552
|
}
|
|
476
553
|
}
|
|
477
|
-
|
|
554
|
+
|
|
555
|
+
const filteredBizBot = WABinary_1.getBinaryNodeFilter(additionalNodes ? additionalNodes : [])
|
|
556
|
+
|
|
478
557
|
if (filteredBizBot) {
|
|
479
|
-
stanza.content.push(...additionalNodes)
|
|
558
|
+
stanza.content.push(...additionalNodes)
|
|
480
559
|
didPushAdditional = true
|
|
481
560
|
}
|
|
561
|
+
|
|
482
562
|
else {
|
|
483
|
-
stanza.content.push(botNode)
|
|
563
|
+
stanza.content.push(botNode)
|
|
484
564
|
}
|
|
485
565
|
}
|
|
486
|
-
|
|
566
|
+
|
|
567
|
+
if(!isNewsletter && buttonType && !isStatus) {
|
|
487
568
|
const content = WABinary_1.getAdditionalNode(buttonType)
|
|
488
569
|
const filteredNode = WABinary_1.getBinaryNodeFilter(additionalNodes)
|
|
570
|
+
|
|
489
571
|
if (filteredNode) {
|
|
490
572
|
didPushAdditional = true
|
|
491
573
|
stanza.content.push(...additionalNodes)
|
|
492
|
-
}
|
|
574
|
+
}
|
|
493
575
|
else {
|
|
494
576
|
stanza.content.push(...content)
|
|
495
577
|
}
|
|
496
578
|
logger.debug({ jid }, 'adding business node')
|
|
497
|
-
}
|
|
579
|
+
}
|
|
580
|
+
|
|
498
581
|
if (!didPushAdditional && additionalNodes && additionalNodes.length > 0) {
|
|
499
582
|
stanza.content.push(...additionalNodes);
|
|
500
583
|
}
|
|
584
|
+
|
|
501
585
|
logger.debug({ msgId }, `sending message to ${participants.length} devices`);
|
|
502
586
|
await sendNode(stanza);
|
|
503
587
|
});
|
|
588
|
+
|
|
504
589
|
message = Types_1.WAProto.Message.fromObject(message)
|
|
590
|
+
|
|
505
591
|
const messageJSON = {
|
|
506
592
|
key: {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
593
|
+
remoteJid: jid,
|
|
594
|
+
fromMe: true,
|
|
595
|
+
id: msgId
|
|
510
596
|
},
|
|
511
597
|
message: message,
|
|
512
598
|
messageTimestamp: Utils_1.unixTimestampSeconds(new Date()),
|
|
@@ -514,20 +600,23 @@ const makeMessagesSocket = (config) => {
|
|
|
514
600
|
participant: WABinary_1.isJidGroup(jid) || WABinary_1.isJidStatusBroadcast(jid) ? meId : undefined,
|
|
515
601
|
status: Types_1.WAMessageStatus.PENDING
|
|
516
602
|
}
|
|
517
|
-
|
|
603
|
+
|
|
604
|
+
return Types_1.WAProto.WebMessageInfo.fromObject(messageJSON)
|
|
605
|
+
// return msgId;
|
|
518
606
|
};
|
|
519
607
|
const getTypeMessage = (msg) => {
|
|
520
|
-
|
|
608
|
+
const message = Utils_1.normalizeMessageContent(msg)
|
|
521
609
|
if (message.reactionMessage) {
|
|
522
610
|
return 'reaction'
|
|
523
|
-
}
|
|
611
|
+
}
|
|
524
612
|
else if (getMediaType(message)) {
|
|
525
613
|
return 'media'
|
|
526
|
-
}
|
|
614
|
+
}
|
|
527
615
|
else {
|
|
528
616
|
return 'text'
|
|
529
617
|
}
|
|
530
618
|
}
|
|
619
|
+
|
|
531
620
|
const getMediaType = (message) => {
|
|
532
621
|
if (message.imageMessage) {
|
|
533
622
|
return 'image'
|
|
@@ -578,6 +667,7 @@ const makeMessagesSocket = (config) => {
|
|
|
578
667
|
return 'productlink'
|
|
579
668
|
}
|
|
580
669
|
}
|
|
670
|
+
|
|
581
671
|
const getButtonType = (message) => {
|
|
582
672
|
if (message.listMessage) {
|
|
583
673
|
return 'list'
|
|
@@ -632,9 +722,9 @@ const makeMessagesSocket = (config) => {
|
|
|
632
722
|
]
|
|
633
723
|
});
|
|
634
724
|
return result;
|
|
635
|
-
}
|
|
725
|
+
}
|
|
636
726
|
const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
|
|
637
|
-
const rahmi = new kikyy(Utils_1, waUploadToServer, relayMessage
|
|
727
|
+
const rahmi = new kikyy(Utils_1, waUploadToServer, relayMessage);
|
|
638
728
|
const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
|
|
639
729
|
return {
|
|
640
730
|
...sock,
|
|
@@ -690,37 +780,13 @@ const makeMessagesSocket = (config) => {
|
|
|
690
780
|
ev.emit('messages.update', [
|
|
691
781
|
{
|
|
692
782
|
key: message.key,
|
|
693
|
-
update: {
|
|
783
|
+
update: {
|
|
694
784
|
message: message.message
|
|
695
785
|
}
|
|
696
786
|
}
|
|
697
787
|
]);
|
|
698
788
|
return message;
|
|
699
789
|
},
|
|
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
|
-
},
|
|
724
790
|
sendMessage: async (jid, content, options = {}) => {
|
|
725
791
|
const userJid = authState.creds.me.id;
|
|
726
792
|
delete options.ephemeralExpiration
|
|
@@ -730,100 +796,112 @@ const makeMessagesSocket = (config) => {
|
|
|
730
796
|
if (typeof content === 'object' && 'disappearingMessagesInChat' in content &&
|
|
731
797
|
typeof content['disappearingMessagesInChat'] !== 'undefined' && WABinary_1.isJidGroup(jid)) {
|
|
732
798
|
const { disappearingMessagesInChat } = content
|
|
799
|
+
|
|
733
800
|
const value = typeof disappearingMessagesInChat === 'boolean' ?
|
|
734
801
|
(disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
|
|
735
802
|
disappearingMessagesInChat
|
|
803
|
+
|
|
736
804
|
await groupToggleEphemeral(jid, value)
|
|
737
805
|
}
|
|
806
|
+
|
|
738
807
|
else {
|
|
739
808
|
let mediaHandle
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
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
|
-
}
|
|
771
|
-
}
|
|
772
|
-
const fullMsg = await Utils_1.generateWAMessage(jid, content, {
|
|
773
|
-
logger,
|
|
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)
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
if (messageType) {
|
|
812
|
+
switch(messageType) {
|
|
813
|
+
case 'PAYMENT':
|
|
814
|
+
const paymentContent = await rahmi.handlePayment(content, quoted);
|
|
815
|
+
return await relayMessage(jid, paymentContent, {
|
|
816
|
+
messageId: Utils_1.generateMessageID(),
|
|
817
|
+
...getParticipantAttr()
|
|
818
|
+
});
|
|
819
|
+
|
|
820
|
+
case 'PRODUCT':
|
|
821
|
+
const productContent = await rahmi.handleProduct(content, jid, quoted);
|
|
822
|
+
const productMsg = await Utils_1.generateWAMessageFromContent(jid, productContent, { quoted });
|
|
823
|
+
return await relayMessage(jid, productMsg.message, {
|
|
824
|
+
messageId: productMsg.key.id,
|
|
825
|
+
...getParticipantAttr()
|
|
789
826
|
});
|
|
790
|
-
|
|
827
|
+
|
|
828
|
+
case 'INTERACTIVE':
|
|
829
|
+
const interactiveContent = await rahmi.handleInteractive(content, jid, quoted);
|
|
830
|
+
const interactiveMsg = await Utils_1.generateWAMessageFromContent(jid, interactiveContent, { quoted });
|
|
831
|
+
return await relayMessage(jid, interactiveMsg.message, {
|
|
832
|
+
messageId: interactiveMsg.key.id,
|
|
833
|
+
...getParticipantAttr()
|
|
834
|
+
});
|
|
835
|
+
case 'ALBUM':
|
|
836
|
+
return await rahmi.handleAlbum(content, jid, quoted)
|
|
837
|
+
case 'EVENT':
|
|
838
|
+
return await rahmi.handleEvent(content, jid, quoted)
|
|
839
|
+
case 'POLL_RESULT':
|
|
840
|
+
return await rahmi.handlePollResult(content, jid, quoted)
|
|
841
|
+
case 'GROUP_STORY':
|
|
842
|
+
return await rahmi.handleGroupStory(content, jid, quoted)
|
|
843
|
+
}
|
|
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 || {}
|
|
791
854
|
},
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
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"
|
|
855
|
+
logger,
|
|
856
|
+
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
857
|
+
}),
|
|
858
|
+
upload: async (readStream, opts) => {
|
|
859
|
+
const up = await waUploadToServer(readStream, {
|
|
860
|
+
...opts,
|
|
861
|
+
newsletter: WABinary_1.isJidNewsLetter(jid)
|
|
812
862
|
});
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
863
|
+
return up;
|
|
864
|
+
},
|
|
865
|
+
mediaCache: config.mediaCache,
|
|
866
|
+
options: config.options,
|
|
867
|
+
...options
|
|
868
|
+
});
|
|
869
|
+
|
|
870
|
+
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
871
|
+
const isEditMsg = 'edit' in content && !!content.edit;
|
|
872
|
+
const isAiMsg = 'ai' in content && !!content.ai;
|
|
873
|
+
|
|
874
|
+
const additionalAttributes = {};
|
|
875
|
+
const additionalNodes = [];
|
|
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"
|
|
820
888
|
});
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
await relayMessage(jid, fullMsg.message, {
|
|
892
|
+
messageId: fullMsg.key.id,
|
|
893
|
+
cachedGroupMetadata: options.cachedGroupMetadata,
|
|
894
|
+
additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes,
|
|
895
|
+
additionalAttributes,
|
|
896
|
+
statusJidList: options.statusJidList
|
|
897
|
+
});
|
|
898
|
+
|
|
899
|
+
if (config.emitOwnEvents) {
|
|
900
|
+
process.nextTick(() => {
|
|
901
|
+
processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
return fullMsg;
|
|
827
905
|
}
|
|
828
906
|
}
|
|
829
907
|
}
|