@alannxd/baileys 6.0.0 → 6.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/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 -39
- package/lib/Socket/dugong.js +637 -0
- package/lib/Socket/groups.js +0 -64
- package/lib/Socket/messages-send.js +157 -410
- package/lib/Socket/newsletter.js +133 -14
- package/lib/Socket/socket.js +2 -73
- package/lib/Utils/generics.js +80 -5
- package/lib/Utils/messages.js +5 -45
- package/lib/Utils/validate-connection.js +2 -2
- package/lib/index.js +1 -0
- package/package.json +105 -104
- 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/communities.d.ts +0 -180
- package/lib/Socket/communities.js +0 -421
- package/lib/Socket/groups.d.ts +0 -115
- package/lib/Socket/index.d.ts +0 -173
- package/lib/Socket/luxu.d.ts +0 -266
- package/lib/Socket/luxu.js +0 -541
- package/lib/Socket/messages-recv.d.ts +0 -161
- package/lib/Socket/messages-send.d.ts +0 -183
- 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,16 +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
|
-
const
|
|
15
|
+
const newsletter_1 = require("./newsletter");
|
|
17
16
|
const WAUSync_1 = require("../WAUSync");
|
|
18
|
-
const
|
|
19
|
-
const imup = require('./luxu');
|
|
20
|
-
var ListType = WAProto_1.proto.Message.ListMessage.ListType;
|
|
17
|
+
const kikyy = require('./dugong');
|
|
21
18
|
const makeMessagesSocket = (config) => {
|
|
22
19
|
const {
|
|
23
20
|
logger,
|
|
@@ -26,7 +23,7 @@ const makeMessagesSocket = (config) => {
|
|
|
26
23
|
options: axiosOptions,
|
|
27
24
|
patchMessageBeforeSending
|
|
28
25
|
} = config;
|
|
29
|
-
const sock = (0,
|
|
26
|
+
const sock = (0, newsletter_1.makeNewsletterSocket)(config);
|
|
30
27
|
const {
|
|
31
28
|
ev,
|
|
32
29
|
authState,
|
|
@@ -35,7 +32,6 @@ const makeMessagesSocket = (config) => {
|
|
|
35
32
|
upsertMessage,
|
|
36
33
|
query,
|
|
37
34
|
fetchPrivacySettings,
|
|
38
|
-
generateMessageTag,
|
|
39
35
|
sendNode,
|
|
40
36
|
groupMetadata,
|
|
41
37
|
groupToggleEphemeral,
|
|
@@ -75,10 +71,6 @@ const makeMessagesSocket = (config) => {
|
|
|
75
71
|
}
|
|
76
72
|
return mediaConn;
|
|
77
73
|
};
|
|
78
|
-
/**
|
|
79
|
-
* generic send receipt function
|
|
80
|
-
* used for receipts of phone call, read, delivery etc.
|
|
81
|
-
* */
|
|
82
74
|
const sendReceipt = async (jid, participant, messageIds, type) => {
|
|
83
75
|
const node = {
|
|
84
76
|
tag: 'receipt',
|
|
@@ -119,84 +111,63 @@ const makeMessagesSocket = (config) => {
|
|
|
119
111
|
logger.debug({ attrs: node.attrs, messageIds }, 'sending receipt for messages');
|
|
120
112
|
await sendNode(node);
|
|
121
113
|
};
|
|
122
|
-
/** Correctly bulk send receipts to multiple chats, participants */
|
|
123
114
|
const sendReceipts = async (keys, type) => {
|
|
124
115
|
const recps = (0, Utils_1.aggregateMessageKeysNotFromMe)(keys);
|
|
125
116
|
for (const { jid, participant, messageIds } of recps) {
|
|
126
117
|
await sendReceipt(jid, participant, messageIds, type);
|
|
127
118
|
}
|
|
128
119
|
};
|
|
129
|
-
/** Bulk read messages. Keys can be from different chats & participants */
|
|
130
120
|
const readMessages = async (keys) => {
|
|
131
121
|
const privacySettings = await fetchPrivacySettings();
|
|
132
|
-
// based on privacy settings, we have to change the read type
|
|
133
122
|
const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self';
|
|
134
123
|
await sendReceipts(keys, readType);
|
|
135
124
|
};
|
|
136
|
-
/** Fetch all the devices we've to send a message to */
|
|
137
125
|
const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
|
|
138
126
|
const deviceResults = []
|
|
139
|
-
|
|
140
127
|
if (!useCache) {
|
|
141
128
|
logger.debug('not using cache for devices')
|
|
142
129
|
}
|
|
143
|
-
|
|
144
130
|
const toFetch = []
|
|
145
|
-
|
|
146
131
|
jids = Array.from(new Set(jids))
|
|
147
|
-
|
|
148
132
|
for (let jid of jids) {
|
|
149
133
|
const user = WABinary_1.jidDecode(jid)?.user
|
|
150
|
-
|
|
151
134
|
jid = WABinary_1.jidNormalizedUser(jid)
|
|
152
|
-
|
|
153
135
|
if (useCache) {
|
|
154
136
|
const devices = userDevicesCache.get(user)
|
|
155
|
-
|
|
156
137
|
if (devices) {
|
|
157
138
|
deviceResults.push(...devices)
|
|
158
139
|
logger.trace({ user }, 'using cache for devices')
|
|
159
140
|
}
|
|
160
|
-
|
|
161
141
|
else {
|
|
162
142
|
toFetch.push(jid)
|
|
163
143
|
}
|
|
164
144
|
}
|
|
165
|
-
|
|
166
145
|
else {
|
|
167
146
|
toFetch.push(jid)
|
|
168
147
|
}
|
|
169
148
|
}
|
|
170
|
-
|
|
171
149
|
if (!toFetch.length) {
|
|
172
150
|
return deviceResults
|
|
173
151
|
}
|
|
174
|
-
|
|
175
152
|
const query = new WAUSync_1.USyncQuery()
|
|
176
153
|
.withContext('message')
|
|
177
154
|
.withDeviceProtocol()
|
|
178
|
-
|
|
179
155
|
for (const jid of toFetch) {
|
|
180
156
|
query.withUser(new WAUSync_1.USyncUser().withId(jid))
|
|
181
157
|
}
|
|
182
|
-
|
|
183
158
|
const result = await executeUSyncQuery(query)
|
|
184
|
-
|
|
185
159
|
if (result) {
|
|
186
160
|
const extracted = Utils_1.extractDeviceJids(result?.list, authState.creds.me.id, ignoreZeroDevices)
|
|
187
161
|
const deviceMap = {}
|
|
188
|
-
|
|
189
162
|
for (const item of extracted) {
|
|
190
163
|
deviceMap[item.user] = deviceMap[item.user] || []
|
|
191
164
|
deviceMap[item.user].push(item)
|
|
192
165
|
deviceResults.push(item)
|
|
193
166
|
}
|
|
194
|
-
|
|
195
167
|
for (const key in deviceMap) {
|
|
196
168
|
userDevicesCache.set(key, deviceMap[key])
|
|
197
169
|
}
|
|
198
170
|
}
|
|
199
|
-
|
|
200
171
|
return deviceResults
|
|
201
172
|
}
|
|
202
173
|
const assertSessions = async (jids, force) => {
|
|
@@ -242,13 +213,10 @@ const makeMessagesSocket = (config) => {
|
|
|
242
213
|
}
|
|
243
214
|
return didFetchNewSession;
|
|
244
215
|
};
|
|
245
|
-
|
|
246
|
-
|
|
247
216
|
const sendPeerDataOperationMessage = async (pdoMessage) => {
|
|
248
217
|
if (!authState.creds.me?.id) {
|
|
249
218
|
throw new boom_1.Boom('Not authenticated')
|
|
250
219
|
}
|
|
251
|
-
|
|
252
220
|
const protocolMessage = {
|
|
253
221
|
protocolMessage: {
|
|
254
222
|
peerDataOperationRequestMessage: pdoMessage,
|
|
@@ -259,7 +227,6 @@ const makeMessagesSocket = (config) => {
|
|
|
259
227
|
const msgId = await relayMessage(meJid, protocolMessage, {
|
|
260
228
|
additionalAttributes: {
|
|
261
229
|
category: 'peer',
|
|
262
|
-
// eslint-disable-next-line camelcase
|
|
263
230
|
push_priority: 'high_force',
|
|
264
231
|
},
|
|
265
232
|
});
|
|
@@ -292,7 +259,6 @@ const makeMessagesSocket = (config) => {
|
|
|
292
259
|
}));
|
|
293
260
|
return { nodes, shouldIncludeDeviceIdentity };
|
|
294
261
|
};
|
|
295
|
-
|
|
296
262
|
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, useCachedGroupMetadata, statusJidList, AI = true }) => {
|
|
297
263
|
const meId = authState.creds.me.id;
|
|
298
264
|
let shouldIncludeDeviceIdentity = false;
|
|
@@ -318,12 +284,9 @@ const makeMessagesSocket = (config) => {
|
|
|
318
284
|
}
|
|
319
285
|
};
|
|
320
286
|
const extraAttrs = {}
|
|
321
|
-
const messages = Utils_1.normalizeMessageContent(message)
|
|
287
|
+
const messages = Utils_1.normalizeMessageContent(message);
|
|
322
288
|
const buttonType = getButtonType(messages);
|
|
323
289
|
if (participant) {
|
|
324
|
-
// when the retry request is not for a group
|
|
325
|
-
// only send to the specific device that asked for a retry
|
|
326
|
-
// otherwise the message is sent out to every device that should be a recipient
|
|
327
290
|
if (!isGroup && !isStatus) {
|
|
328
291
|
additionalAttributes = { ...additionalAttributes, 'device_fanout': 'false' };
|
|
329
292
|
}
|
|
@@ -332,19 +295,15 @@ const makeMessagesSocket = (config) => {
|
|
|
332
295
|
}
|
|
333
296
|
await authState.keys.transaction(async () => {
|
|
334
297
|
const mediaType = getMediaType(messages);
|
|
335
|
-
|
|
336
298
|
if (mediaType) {
|
|
337
299
|
extraAttrs['mediatype'] = mediaType
|
|
338
300
|
}
|
|
339
|
-
|
|
340
301
|
if (messages.pinInChatMessage || messages.keepInChatMessage || message.reactionMessage || message.protocolMessage?.editedMessage) {
|
|
341
302
|
extraAttrs['decrypt-fail'] = 'hide'
|
|
342
|
-
}
|
|
343
|
-
|
|
303
|
+
}
|
|
344
304
|
if (messages.interactiveResponseMessage?.nativeFlowResponseMessage) {
|
|
345
305
|
extraAttrs['native_flow_name'] = messages.interactiveResponseMessage?.nativeFlowResponseMessage.name
|
|
346
306
|
}
|
|
347
|
-
|
|
348
307
|
if (isGroup || isStatus) {
|
|
349
308
|
const [groupData, senderKeyMap] = await Promise.all([
|
|
350
309
|
(async () => {
|
|
@@ -352,11 +311,9 @@ const makeMessagesSocket = (config) => {
|
|
|
352
311
|
if (groupData) {
|
|
353
312
|
logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
|
|
354
313
|
}
|
|
355
|
-
|
|
356
314
|
else if (!isStatus) {
|
|
357
315
|
groupData = await groupMetadata(jid)
|
|
358
316
|
}
|
|
359
|
-
|
|
360
317
|
return groupData;
|
|
361
318
|
})(),
|
|
362
319
|
(async () => {
|
|
@@ -364,51 +321,32 @@ const makeMessagesSocket = (config) => {
|
|
|
364
321
|
const result = await authState.keys.get('sender-key-memory', [jid])
|
|
365
322
|
return result[jid] || {}
|
|
366
323
|
}
|
|
367
|
-
|
|
368
324
|
return {}
|
|
369
|
-
|
|
370
|
-
})()
|
|
325
|
+
})()
|
|
371
326
|
]);
|
|
372
327
|
if (!participant) {
|
|
373
328
|
const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : []
|
|
374
|
-
|
|
375
329
|
if (isStatus && statusJidList) {
|
|
376
330
|
participantsList.push(...statusJidList)
|
|
377
331
|
}
|
|
378
|
-
|
|
379
|
-
// if (!isStatus) {
|
|
380
|
-
// const expiration = await getEphemeralGroup(jid)
|
|
381
|
-
// additionalAttributes = {
|
|
382
|
-
// ...additionalAttributes,
|
|
383
|
-
// addressing_mode: 'pn',
|
|
384
|
-
// ...expiration ? { expiration: expiration.toString() } : null
|
|
385
|
-
// }
|
|
386
|
-
// }
|
|
387
|
-
|
|
388
332
|
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false)
|
|
389
333
|
devices.push(...additionalDevices)
|
|
390
334
|
}
|
|
391
|
-
|
|
392
335
|
const patched = await patchMessageBeforeSending(message, devices.map(d => WABinary_1.jidEncode(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device)));
|
|
393
336
|
const bytes = Utils_1.encodeWAMessage(patched);
|
|
394
|
-
|
|
395
337
|
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
|
|
396
338
|
group: destinationJid,
|
|
397
339
|
data: bytes,
|
|
398
340
|
meId,
|
|
399
341
|
});
|
|
400
342
|
const senderKeyJids = [];
|
|
401
|
-
|
|
402
343
|
for (const { user, device } of devices) {
|
|
403
344
|
const jid = WABinary_1.jidEncode(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
|
|
404
345
|
if (!senderKeyMap[jid] || !!participant) {
|
|
405
346
|
senderKeyJids.push(jid);
|
|
406
|
-
// store that this person has had the sender keys sent to them
|
|
407
347
|
senderKeyMap[jid] = true;
|
|
408
348
|
}
|
|
409
349
|
}
|
|
410
|
-
// if there are some participants with whom the session has not been established
|
|
411
|
-
// if there are, we re-send the senderkey
|
|
412
350
|
if (senderKeyJids.length) {
|
|
413
351
|
logger.debug({ senderKeyJids }, 'sending new sender key');
|
|
414
352
|
const senderKeyMsg = {
|
|
@@ -430,21 +368,16 @@ const makeMessagesSocket = (config) => {
|
|
|
430
368
|
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
|
|
431
369
|
}
|
|
432
370
|
else if (isNewsletter) {
|
|
433
|
-
// Message edit
|
|
434
371
|
if (message.protocolMessage?.editedMessage) {
|
|
435
372
|
msgId = message.protocolMessage.key?.id
|
|
436
373
|
message = message.protocolMessage.editedMessage
|
|
437
374
|
}
|
|
438
|
-
|
|
439
|
-
// Message delete
|
|
440
375
|
if (message.protocolMessage?.type === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
|
|
441
376
|
msgId = message.protocolMessage.key?.id
|
|
442
377
|
message = {}
|
|
443
378
|
}
|
|
444
|
-
|
|
445
379
|
const patched = await patchMessageBeforeSending(message, [])
|
|
446
380
|
const bytes = Utils_1.encodeNewsletterMessage(patched)
|
|
447
|
-
|
|
448
381
|
binaryNodeContent.push({
|
|
449
382
|
tag: 'plaintext',
|
|
450
383
|
attrs: extraAttrs ? extraAttrs : {},
|
|
@@ -458,10 +391,8 @@ const makeMessagesSocket = (config) => {
|
|
|
458
391
|
if (user !== meUser) {
|
|
459
392
|
devices.push({ user: meUser })
|
|
460
393
|
}
|
|
461
|
-
|
|
462
394
|
if (additionalAttributes?.['category'] !== 'peer') {
|
|
463
395
|
const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true)
|
|
464
|
-
|
|
465
396
|
devices.push(...additionalDevices)
|
|
466
397
|
}
|
|
467
398
|
}
|
|
@@ -471,15 +402,12 @@ const makeMessagesSocket = (config) => {
|
|
|
471
402
|
for (const { user, device } of devices) {
|
|
472
403
|
const isMe = user === meUser
|
|
473
404
|
const jid = WABinary_1.jidEncode(isMe && isLid ? authState.creds?.me?.lid?.split(':')[0] || user : user, isLid ? 'lid' : 's.whatsapp.net', device)
|
|
474
|
-
|
|
475
405
|
if (isMe) {
|
|
476
406
|
meJids.push(jid)
|
|
477
407
|
}
|
|
478
|
-
|
|
479
408
|
else {
|
|
480
409
|
otherJids.push(jid)
|
|
481
410
|
}
|
|
482
|
-
|
|
483
411
|
allJids.push(jid)
|
|
484
412
|
}
|
|
485
413
|
await assertSessions(allJids, false);
|
|
@@ -494,12 +422,10 @@ const makeMessagesSocket = (config) => {
|
|
|
494
422
|
if (participants.length) {
|
|
495
423
|
if (additionalAttributes?.['category'] === 'peer') {
|
|
496
424
|
const peerNode = participants[0]?.content?.[0]
|
|
497
|
-
|
|
498
425
|
if (peerNode) {
|
|
499
|
-
binaryNodeContent.push(peerNode)
|
|
426
|
+
binaryNodeContent.push(peerNode)
|
|
500
427
|
}
|
|
501
428
|
}
|
|
502
|
-
|
|
503
429
|
else {
|
|
504
430
|
binaryNodeContent.push({
|
|
505
431
|
tag: 'participants',
|
|
@@ -508,19 +434,15 @@ const makeMessagesSocket = (config) => {
|
|
|
508
434
|
})
|
|
509
435
|
}
|
|
510
436
|
}
|
|
511
|
-
|
|
512
437
|
const stanza = {
|
|
513
438
|
tag: 'message',
|
|
514
439
|
attrs: {
|
|
515
440
|
id: msgId,
|
|
516
|
-
type: getTypeMessage(messages),
|
|
441
|
+
type: getTypeMessage(messages),
|
|
517
442
|
...(additionalAttributes || {})
|
|
518
443
|
},
|
|
519
444
|
content: binaryNodeContent
|
|
520
445
|
}
|
|
521
|
-
// if the participant to send to is explicitly specified (generally retry recp)
|
|
522
|
-
// ensure the message is only sent to that person
|
|
523
|
-
// if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
|
|
524
446
|
if (participant) {
|
|
525
447
|
if (WABinary_1.isJidGroup(destinationJid)) {
|
|
526
448
|
stanza.attrs.to = destinationJid;
|
|
@@ -545,112 +467,67 @@ const makeMessagesSocket = (config) => {
|
|
|
545
467
|
});
|
|
546
468
|
logger.debug({ jid }, 'adding device identity');
|
|
547
469
|
}
|
|
548
|
-
|
|
549
470
|
if (AI && isPrivate) {
|
|
550
471
|
const botNode = {
|
|
551
|
-
tag: 'bot',
|
|
472
|
+
tag: 'bot',
|
|
552
473
|
attrs: {
|
|
553
474
|
biz_bot: '1'
|
|
554
475
|
}
|
|
555
476
|
}
|
|
556
|
-
|
|
557
|
-
const filteredBizBot = WABinary_1.getBinaryNodeFilter(additionalNodes ? additionalNodes : [])
|
|
558
|
-
|
|
477
|
+
const filteredBizBot = WABinary_1.getBinaryNodeFilter(additionalNodes ? additionalNodes : [])
|
|
559
478
|
if (filteredBizBot) {
|
|
560
|
-
stanza.content.push(...additionalNodes)
|
|
479
|
+
stanza.content.push(...additionalNodes)
|
|
561
480
|
didPushAdditional = true
|
|
562
481
|
}
|
|
563
|
-
|
|
564
482
|
else {
|
|
565
|
-
stanza.content.push(botNode)
|
|
483
|
+
stanza.content.push(botNode)
|
|
566
484
|
}
|
|
567
485
|
}
|
|
568
|
-
|
|
569
|
-
if(!isNewsletter && buttonType && !isStatus) {
|
|
486
|
+
if (!isNewsletter && buttonType && !isStatus) {
|
|
570
487
|
const content = WABinary_1.getAdditionalNode(buttonType)
|
|
571
488
|
const filteredNode = WABinary_1.getBinaryNodeFilter(additionalNodes)
|
|
572
|
-
|
|
573
489
|
if (filteredNode) {
|
|
574
490
|
didPushAdditional = true
|
|
575
491
|
stanza.content.push(...additionalNodes)
|
|
576
|
-
}
|
|
492
|
+
}
|
|
577
493
|
else {
|
|
578
494
|
stanza.content.push(...content)
|
|
579
495
|
}
|
|
580
496
|
logger.debug({ jid }, 'adding business node')
|
|
581
|
-
}
|
|
582
|
-
|
|
497
|
+
}
|
|
583
498
|
if (!didPushAdditional && additionalNodes && additionalNodes.length > 0) {
|
|
584
499
|
stanza.content.push(...additionalNodes);
|
|
585
500
|
}
|
|
586
|
-
|
|
587
501
|
logger.debug({ msgId }, `sending message to ${participants.length} devices`);
|
|
588
502
|
await sendNode(stanza);
|
|
589
503
|
});
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
const { server } = WABinary_1.jidDecode(jid);
|
|
603
|
-
if (server !== "g.us") throw new Error("@g.us server required");
|
|
604
|
-
|
|
605
|
-
const meId = authState.creds.me.id;
|
|
606
|
-
const messages = Utils_1.normalizeMessageContent(message);
|
|
607
|
-
const groupData = cachedGroupMetadata? await cachedGroupMetadata(jid) : await groupMetadata(jid);
|
|
608
|
-
const isLid = groupData.addressingMode === "lid";
|
|
609
|
-
const participantJids = groupData.participants.map(p => p.id);
|
|
610
|
-
|
|
611
|
-
logger.info(`Sending message to ${participantJids.length} members from ${jid}`);
|
|
612
|
-
|
|
613
|
-
for (let i = 0; i < participantJids.length; i++) {
|
|
614
|
-
const jid = participantJids[i];
|
|
615
|
-
if (WABinary_1.areJidsSameUser(jid, meId)) continue;
|
|
616
|
-
|
|
617
|
-
try {
|
|
618
|
-
const msgId = `${idm || Utils_1.generateMessageID()}_${i}`;
|
|
619
|
-
const fullMsg = await Utils_1.generateWAMessageFromContent(jid, message, {
|
|
620
|
-
messageId: msgId,
|
|
621
|
-
quoted
|
|
622
|
-
})
|
|
623
|
-
await relayMessage(jid, fullMsg.message, {
|
|
624
|
-
messageId: fullMsg.key.id
|
|
625
|
-
});
|
|
626
|
-
|
|
627
|
-
logger.debug(`Message successfully sent to ${jid}`);
|
|
628
|
-
if (delayMs && i < participantJids.length - 1) {
|
|
629
|
-
await new Promise(z => setTimeout(z, delayMs));
|
|
630
|
-
}
|
|
631
|
-
} catch (e) {
|
|
632
|
-
logger.error({ jid, e }, "Error sending message to");
|
|
504
|
+
message = Types_1.WAProto.Message.fromObject(message)
|
|
505
|
+
const messageJSON = {
|
|
506
|
+
key: {
|
|
507
|
+
remoteJid: jid,
|
|
508
|
+
fromMe: true,
|
|
509
|
+
id: msgId
|
|
510
|
+
},
|
|
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
|
|
633
516
|
}
|
|
634
|
-
|
|
635
|
-
return JSON.stringify({
|
|
636
|
-
members_total: participantJids.length,
|
|
637
|
-
message
|
|
638
|
-
}, null, 4);
|
|
517
|
+
return Types_1.WAProto.WebMessageInfo.fromObject(messageJSON);
|
|
639
518
|
};
|
|
640
|
-
|
|
641
519
|
const getTypeMessage = (msg) => {
|
|
642
|
-
|
|
520
|
+
const message = Utils_1.normalizeMessageContent(msg);
|
|
643
521
|
if (message.reactionMessage) {
|
|
644
522
|
return 'reaction'
|
|
645
|
-
}
|
|
523
|
+
}
|
|
646
524
|
else if (getMediaType(message)) {
|
|
647
525
|
return 'media'
|
|
648
|
-
}
|
|
526
|
+
}
|
|
649
527
|
else {
|
|
650
528
|
return 'text'
|
|
651
529
|
}
|
|
652
530
|
}
|
|
653
|
-
|
|
654
531
|
const getMediaType = (message) => {
|
|
655
532
|
if (message.imageMessage) {
|
|
656
533
|
return 'image'
|
|
@@ -701,7 +578,6 @@ const makeMessagesSocket = (config) => {
|
|
|
701
578
|
return 'productlink'
|
|
702
579
|
}
|
|
703
580
|
}
|
|
704
|
-
|
|
705
581
|
const getButtonType = (message) => {
|
|
706
582
|
if (message.listMessage) {
|
|
707
583
|
return 'list'
|
|
@@ -717,9 +593,8 @@ const makeMessagesSocket = (config) => {
|
|
|
717
593
|
}
|
|
718
594
|
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_info') {
|
|
719
595
|
return 'payment_info'
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
} else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_status') {
|
|
596
|
+
}
|
|
597
|
+
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_status') {
|
|
723
598
|
return 'payment_status'
|
|
724
599
|
}
|
|
725
600
|
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_method') {
|
|
@@ -757,142 +632,18 @@ const makeMessagesSocket = (config) => {
|
|
|
757
632
|
]
|
|
758
633
|
});
|
|
759
634
|
return result;
|
|
760
|
-
}
|
|
635
|
+
}
|
|
761
636
|
const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
|
|
762
|
-
const
|
|
637
|
+
const rahmi = new kikyy(Utils_1, waUploadToServer, relayMessage, config, sock);
|
|
763
638
|
const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
|
|
764
|
-
const sendMessage = async (jid, content, options = {}) => {
|
|
765
|
-
const userJid = authState.creds.me.id;
|
|
766
|
-
delete options.ephemeralExpiration
|
|
767
|
-
const { ptcp = false, quoted } = options;
|
|
768
|
-
const getParticipantAttr = () => ptcp ? { participant: { jid } } : {};
|
|
769
|
-
const messageType = luki.detectType(content);
|
|
770
|
-
if (typeof content === 'object' && 'disappearingMessagesInChat' in content &&
|
|
771
|
-
typeof content['disappearingMessagesInChat'] !== 'undefined' && WABinary_1.isJidGroup(jid)) {
|
|
772
|
-
const { disappearingMessagesInChat } = content
|
|
773
|
-
|
|
774
|
-
const value = typeof disappearingMessagesInChat === 'boolean' ?
|
|
775
|
-
(disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
|
|
776
|
-
disappearingMessagesInChat
|
|
777
|
-
|
|
778
|
-
await groupToggleEphemeral(jid, value)
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
else {
|
|
782
|
-
let mediaHandle
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
if (messageType) {
|
|
786
|
-
switch(messageType) {
|
|
787
|
-
case 'PAYMENT':
|
|
788
|
-
const paymentContent = await luki.handlePayment(content, quoted);
|
|
789
|
-
return await relayMessage(jid, paymentContent, {
|
|
790
|
-
messageId: Utils_1.generateMessageID(),
|
|
791
|
-
...getParticipantAttr()
|
|
792
|
-
});
|
|
793
|
-
|
|
794
|
-
case 'PRODUCT':
|
|
795
|
-
const productContent = await luki.handleProduct(content, jid, quoted);
|
|
796
|
-
const productMsg = await Utils_1.generateWAMessageFromContent(jid, productContent, { quoted });
|
|
797
|
-
return await relayMessage(jid, productMsg.message, {
|
|
798
|
-
messageId: productMsg.key.id,
|
|
799
|
-
...getParticipantAttr()
|
|
800
|
-
});
|
|
801
|
-
|
|
802
|
-
case 'INTERACTIVE':
|
|
803
|
-
const interactiveContent = await luki.handleInteractive(content, jid, quoted);
|
|
804
|
-
const interactiveMsg = await Utils_1.generateWAMessageFromContent(jid, interactiveContent, { quoted });
|
|
805
|
-
return await relayMessage(jid, interactiveMsg.message, {
|
|
806
|
-
messageId: interactiveMsg.key.id,
|
|
807
|
-
...getParticipantAttr()
|
|
808
|
-
});
|
|
809
|
-
|
|
810
|
-
case 'ALBUM':
|
|
811
|
-
return await luki.handleAlbum(content, jid, quoted)
|
|
812
|
-
case 'EVENT':
|
|
813
|
-
return await luki.handleEvent(content, jid, quoted)
|
|
814
|
-
case 'POLL_RESULT':
|
|
815
|
-
return await luki.handlePollResult(content, jid, quoted)
|
|
816
|
-
case 'ORDER':
|
|
817
|
-
return await luki.handleOrderMessage(content, jid, quoted)
|
|
818
|
-
case 'GROUP_STATUS':
|
|
819
|
-
return await luki.handleGroupStory(content, jid, quoted)
|
|
820
|
-
case 'GROUP_LABEL':
|
|
821
|
-
return await luki.handleGbLabel(content, jid)
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
const fullMsg = await Utils_1.generateWAMessage(jid, content, {
|
|
825
|
-
logger,
|
|
826
|
-
userJid,
|
|
827
|
-
quoted,
|
|
828
|
-
getUrlInfo: text => link_preview_1.getUrlInfo(text, {
|
|
829
|
-
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
830
|
-
fetchOpts: {
|
|
831
|
-
timeout: 3000,
|
|
832
|
-
...axiosOptions || {}
|
|
833
|
-
},
|
|
834
|
-
logger,
|
|
835
|
-
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
836
|
-
}),
|
|
837
|
-
upload: async (readStream, opts) => {
|
|
838
|
-
const up = await waUploadToServer(readStream, {
|
|
839
|
-
...opts,
|
|
840
|
-
newsletter: WABinary_1.isJidNewsLetter(jid)
|
|
841
|
-
});
|
|
842
|
-
return up;
|
|
843
|
-
},
|
|
844
|
-
mediaCache: config.mediaCache,
|
|
845
|
-
options: config.options,
|
|
846
|
-
...options
|
|
847
|
-
});
|
|
848
|
-
|
|
849
|
-
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
850
|
-
const isEditMsg = 'edit' in content && !!content.edit;
|
|
851
|
-
const isAiMsg = 'ai' in content && !!content.ai;
|
|
852
|
-
|
|
853
|
-
const additionalAttributes = {};
|
|
854
|
-
const additionalNodes = [];
|
|
855
|
-
|
|
856
|
-
if (isDeleteMsg) {
|
|
857
|
-
const fromMe = content.delete?.fromMe;
|
|
858
|
-
const isGroup = WABinary_1.isJidGroup(content.delete?.remoteJid);
|
|
859
|
-
additionalAttributes.edit = (isGroup && !fromMe) || WABinary_1.isJidNewsLetter(jid) ? '8' : '7';
|
|
860
|
-
} else if (isEditMsg) {
|
|
861
|
-
additionalAttributes.edit = WABinary_1.isJidNewsLetter(jid) ? '3' : '1';
|
|
862
|
-
} else if (isAiMsg) {
|
|
863
|
-
additionalNodes.push({
|
|
864
|
-
attrs: {
|
|
865
|
-
biz_bot: '1'
|
|
866
|
-
}, tag: "bot"
|
|
867
|
-
});
|
|
868
|
-
}
|
|
869
|
-
|
|
870
|
-
await relayMessage(jid, fullMsg.message, {
|
|
871
|
-
messageId: fullMsg.key.id,
|
|
872
|
-
cachedGroupMetadata: options.cachedGroupMetadata,
|
|
873
|
-
additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes,
|
|
874
|
-
additionalAttributes,
|
|
875
|
-
statusJidList: options.statusJidList
|
|
876
|
-
});
|
|
877
|
-
|
|
878
|
-
if (config.emitOwnEvents) {
|
|
879
|
-
process.nextTick(() => {
|
|
880
|
-
processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
|
881
|
-
});
|
|
882
|
-
}
|
|
883
|
-
return fullMsg;
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
639
|
return {
|
|
887
640
|
...sock,
|
|
888
641
|
getPrivacyTokens,
|
|
889
642
|
assertSessions,
|
|
890
643
|
relayMessage,
|
|
891
|
-
sendMessageMembers,
|
|
892
644
|
sendReceipt,
|
|
893
645
|
sendReceipts,
|
|
894
|
-
|
|
895
|
-
sendMessage,
|
|
646
|
+
rahmi,
|
|
896
647
|
readMessages,
|
|
897
648
|
refreshMediaConn,
|
|
898
649
|
getUSyncDevices,
|
|
@@ -939,145 +690,141 @@ const makeMessagesSocket = (config) => {
|
|
|
939
690
|
ev.emit('messages.update', [
|
|
940
691
|
{
|
|
941
692
|
key: message.key,
|
|
942
|
-
update: {
|
|
693
|
+
update: {
|
|
943
694
|
message: message.message
|
|
944
695
|
}
|
|
945
696
|
}
|
|
946
697
|
]);
|
|
947
698
|
return message;
|
|
948
699
|
},
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
caption,
|
|
959
|
-
...options
|
|
960
|
-
}, { quoted })
|
|
961
|
-
},
|
|
962
|
-
sendVideo: async (jid, video, caption, options, quoted = null) => {
|
|
963
|
-
return sendMessage(jid, {
|
|
964
|
-
video,
|
|
965
|
-
caption,
|
|
966
|
-
...options
|
|
967
|
-
}, { quoted })
|
|
968
|
-
},
|
|
969
|
-
sendDocument: async (jid, document, caption, options, quoted = null) => {
|
|
970
|
-
return sendMessage(jid, {
|
|
971
|
-
document,
|
|
972
|
-
caption,
|
|
973
|
-
...options
|
|
974
|
-
}, { quoted })
|
|
975
|
-
},
|
|
976
|
-
sendAudio: async (jid, audio, options, quoted = null) => {
|
|
977
|
-
return sendMessage(jid, {
|
|
978
|
-
audio,
|
|
979
|
-
...options
|
|
980
|
-
}, { quoted })
|
|
981
|
-
},
|
|
982
|
-
sendLocation: async (jid, name, degreesLongitude, degreesLatitude, url, address, options, quoted = null) => {
|
|
983
|
-
return sendMessage(jid, {
|
|
984
|
-
location: {
|
|
985
|
-
degreesLongitude,
|
|
986
|
-
degreesLatitude,
|
|
987
|
-
name,
|
|
988
|
-
url,
|
|
989
|
-
address
|
|
990
|
-
},
|
|
991
|
-
...options
|
|
992
|
-
}, { quoted })
|
|
993
|
-
},
|
|
994
|
-
sendPoll: async (jid, name, pollVote = [], multiSelect = false, options, quoted = null) => {
|
|
995
|
-
const selectableCount = multiSelect ? pollVote.length : 1;
|
|
996
|
-
|
|
997
|
-
return sendMessage(jid, {
|
|
998
|
-
poll: {
|
|
999
|
-
name,
|
|
1000
|
-
values: pollVote,
|
|
1001
|
-
selectableCount
|
|
1002
|
-
},
|
|
1003
|
-
...options
|
|
1004
|
-
}, { quoted });
|
|
1005
|
-
},
|
|
1006
|
-
sendQuiz: (
|
|
1007
|
-
jid,
|
|
1008
|
-
name,
|
|
1009
|
-
pollVote = [],
|
|
1010
|
-
answer,
|
|
1011
|
-
options,
|
|
1012
|
-
quoted
|
|
1013
|
-
) => {
|
|
1014
|
-
const poll = {
|
|
1015
|
-
name,
|
|
1016
|
-
values: pollVote,
|
|
1017
|
-
selectableCount: 1,
|
|
1018
|
-
type: "QUIZ",
|
|
1019
|
-
answer: { optionName: answer }
|
|
1020
|
-
}
|
|
1021
|
-
return sendMessage(jid, {
|
|
1022
|
-
poll,
|
|
1023
|
-
...options
|
|
1024
|
-
}, { quoted })
|
|
1025
|
-
},
|
|
1026
|
-
sendPtv: (jid, ptv, options, quoted = null) => {
|
|
1027
|
-
return sendMessage(jid, {
|
|
1028
|
-
ptv,
|
|
1029
|
-
...options
|
|
1030
|
-
}, { quoted })
|
|
1031
|
-
},
|
|
1032
|
-
statusMention: async (jid, content) => {
|
|
1033
|
-
const msg = Utils_1.generateWAMessageFromContent("status@broadcast", content, {})
|
|
1034
|
-
|
|
1035
|
-
await relayMessage("status@broadcast", msg.message, {
|
|
1036
|
-
messageId: msg.key.id,
|
|
1037
|
-
statusJidList: [jid, authState.creds.me.id],
|
|
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
|
+
}, {
|
|
1038
709
|
additionalNodes: [
|
|
1039
710
|
{
|
|
1040
711
|
tag: "meta",
|
|
1041
|
-
attrs: {
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
content: [
|
|
1047
|
-
{
|
|
1048
|
-
tag: "to",
|
|
1049
|
-
attrs: { jid },
|
|
1050
|
-
content: undefined
|
|
1051
|
-
}
|
|
1052
|
-
]
|
|
1053
|
-
}
|
|
1054
|
-
]
|
|
712
|
+
attrs: {
|
|
713
|
+
tag_reason: "user_update",
|
|
714
|
+
appdata: "member_tag"
|
|
715
|
+
},
|
|
716
|
+
content: undefined
|
|
1055
717
|
}
|
|
1056
718
|
]
|
|
1057
719
|
})
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
720
|
+
},
|
|
721
|
+
sendStatusMention: async (content, jids = []) => {
|
|
722
|
+
return await rahmi.sendStatusWhatsApp(content, jids);
|
|
723
|
+
},
|
|
724
|
+
sendMessage: async (jid, content, options = {}) => {
|
|
725
|
+
const userJid = authState.creds.me.id;
|
|
726
|
+
delete options.ephemeralExpiration
|
|
727
|
+
const { filter = false, quoted } = options;
|
|
728
|
+
const getParticipantAttr = () => filter ? { participant: { jid } } : {};
|
|
729
|
+
const messageType = rahmi.detectType(content);
|
|
730
|
+
if (typeof content === 'object' && 'disappearingMessagesInChat' in content &&
|
|
731
|
+
typeof content['disappearingMessagesInChat'] !== 'undefined' && WABinary_1.isJidGroup(jid)) {
|
|
732
|
+
const { disappearingMessagesInChat } = content
|
|
733
|
+
const value = typeof disappearingMessagesInChat === 'boolean' ?
|
|
734
|
+
(disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
|
|
735
|
+
disappearingMessagesInChat
|
|
736
|
+
await groupToggleEphemeral(jid, value)
|
|
737
|
+
}
|
|
738
|
+
else {
|
|
739
|
+
let mediaHandle
|
|
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)
|
|
1067
770
|
}
|
|
1068
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)
|
|
789
|
+
});
|
|
790
|
+
return up;
|
|
791
|
+
},
|
|
792
|
+
mediaCache: config.mediaCache,
|
|
793
|
+
options: config.options,
|
|
794
|
+
...options
|
|
795
|
+
});
|
|
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
|
|
820
|
+
});
|
|
821
|
+
if (config.emitOwnEvents) {
|
|
822
|
+
process.nextTick(() => {
|
|
823
|
+
processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
return fullMsg;
|
|
1069
827
|
}
|
|
1070
|
-
|
|
1071
|
-
const x = Utils_1.generateWAMessageFromContent(jid, mentionMsg, {})
|
|
1072
|
-
return relayMessage(jid, x.message, {
|
|
1073
|
-
messageId: x.key.id,
|
|
1074
|
-
additionalNodes: [
|
|
1075
|
-
{
|
|
1076
|
-
tag: "meta",
|
|
1077
|
-
attrs: { is_status_mention: "true" }
|
|
1078
|
-
}
|
|
1079
|
-
]
|
|
1080
|
-
})
|
|
1081
828
|
}
|
|
1082
829
|
}
|
|
1083
830
|
};
|