ell-bail 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +341 -93
- package/engine-requirements.js +1 -2
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +19 -2
- package/lib/Socket/chats.d.ts +215 -28
- package/lib/Socket/chats.js +155 -49
- package/lib/Socket/{luxu.d.ts → dugong.d.ts} +44 -41
- package/lib/Socket/dugong.js +484 -0
- package/lib/Socket/groups.js +1 -0
- package/lib/Socket/index.js +1 -0
- package/lib/Socket/messages-recv.js +5 -47
- package/lib/Socket/messages-send.d.ts +1 -1
- package/lib/Socket/messages-send.js +227 -320
- package/lib/Socket/newsletter.d.ts +130 -232
- package/lib/Socket/newsletter.js +101 -22
- package/lib/Socket/registration.d.ts +0 -1
- package/lib/Socket/registration.js +4 -627
- package/lib/Socket/socket.d.ts +1 -1
- package/lib/Socket/socket.js +66 -31
- package/lib/Types/Newsletter.d.ts +97 -86
- package/lib/Types/Newsletter.js +38 -32
- package/lib/Utils/auth-utils.js +0 -5
- package/lib/Utils/crypto.js +1 -18
- package/lib/Utils/generics.d.ts +0 -1
- package/lib/Utils/generics.js +64 -38
- package/lib/Utils/messages-media.js +145 -57
- package/lib/Utils/messages.js +54 -13
- package/lib/Utils/use-multi-file-auth-state.js +45 -6
- package/lib/Utils/validate-connection.js +89 -65
- package/lib/WABinary/constants.d.ts +27 -24
- package/lib/WABinary/encode.js +160 -123
- package/lib/WABinary/generic-utils.d.ts +2 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +7 -2
- package/package.json +15 -7
- package/WAProto/index.js +0 -130309
- package/lib/KeyDB/BinarySearch.js +0 -18
- package/lib/KeyDB/KeyedDB.js +0 -164
- package/lib/KeyDB/index.js +0 -2
- package/lib/Signal/Group/x +0 -1
- package/lib/Socket/luxu.js +0 -550
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function(mod) {
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
4
|
+
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.makeMessagesSocket = void 0;
|
|
7
7
|
const boom_1 = require("@hapi/boom");
|
|
@@ -15,27 +15,27 @@ const link_preview_1 = require("../Utils/link-preview");
|
|
|
15
15
|
const WABinary_1 = require("../WABinary");
|
|
16
16
|
const newsletter_1 = require("./newsletter");
|
|
17
17
|
const WAUSync_1 = require("../WAUSync")
|
|
18
|
-
const
|
|
18
|
+
const kikyy = require('./dugong');
|
|
19
19
|
var ListType = WAProto_1.proto.Message.ListMessage.ListType;
|
|
20
20
|
const makeMessagesSocket = (config) => {
|
|
21
21
|
const {
|
|
22
22
|
logger,
|
|
23
|
-
linkPreviewImageThumbnailWidth,
|
|
23
|
+
linkPreviewImageThumbnailWidth,
|
|
24
24
|
generateHighQualityLinkPreview,
|
|
25
25
|
options: axiosOptions,
|
|
26
26
|
patchMessageBeforeSending
|
|
27
27
|
} = config;
|
|
28
28
|
const sock = (0, newsletter_1.makeNewsletterSocket)(config);
|
|
29
29
|
const {
|
|
30
|
-
ev,
|
|
31
|
-
authState,
|
|
32
|
-
processingMutex,
|
|
33
|
-
signalRepository,
|
|
30
|
+
ev,
|
|
31
|
+
authState,
|
|
32
|
+
processingMutex,
|
|
33
|
+
signalRepository,
|
|
34
34
|
upsertMessage,
|
|
35
35
|
query,
|
|
36
36
|
fetchPrivacySettings,
|
|
37
37
|
generateMessageTag,
|
|
38
|
-
sendNode,
|
|
38
|
+
sendNode,
|
|
39
39
|
groupMetadata,
|
|
40
40
|
groupToggleEphemeral,
|
|
41
41
|
executeUSyncQuery
|
|
@@ -105,14 +105,15 @@ const makeMessagesSocket = (config) => {
|
|
|
105
105
|
const remainingMessageIds = messageIds.slice(1);
|
|
106
106
|
if (remainingMessageIds.length) {
|
|
107
107
|
node.content = [
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
108
|
+
{
|
|
109
|
+
tag: 'list',
|
|
110
|
+
attrs: {},
|
|
111
|
+
content: remainingMessageIds.map(id => ({
|
|
112
|
+
tag: 'item',
|
|
113
|
+
attrs: { id }
|
|
114
|
+
}))
|
|
115
|
+
}
|
|
116
|
+
];
|
|
116
117
|
}
|
|
117
118
|
logger.debug({ attrs: node.attrs, messageIds }, 'sending receipt for messages');
|
|
118
119
|
await sendNode(node);
|
|
@@ -134,67 +135,67 @@ const makeMessagesSocket = (config) => {
|
|
|
134
135
|
/** Fetch all the devices we've to send a message to */
|
|
135
136
|
const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
|
|
136
137
|
const deviceResults = []
|
|
137
|
-
|
|
138
|
+
|
|
138
139
|
if (!useCache) {
|
|
139
140
|
logger.debug('not using cache for devices')
|
|
140
141
|
}
|
|
141
|
-
|
|
142
|
+
|
|
142
143
|
const toFetch = []
|
|
143
|
-
|
|
144
|
+
|
|
144
145
|
jids = Array.from(new Set(jids))
|
|
145
|
-
|
|
146
|
+
|
|
146
147
|
for (let jid of jids) {
|
|
147
148
|
const user = WABinary_1.jidDecode(jid)?.user
|
|
148
|
-
|
|
149
|
+
|
|
149
150
|
jid = WABinary_1.jidNormalizedUser(jid)
|
|
150
|
-
|
|
151
|
+
|
|
151
152
|
if (useCache) {
|
|
152
153
|
const devices = userDevicesCache.get(user)
|
|
153
|
-
|
|
154
|
+
|
|
154
155
|
if (devices) {
|
|
155
156
|
deviceResults.push(...devices)
|
|
156
157
|
logger.trace({ user }, 'using cache for devices')
|
|
157
158
|
}
|
|
158
|
-
|
|
159
|
+
|
|
159
160
|
else {
|
|
160
161
|
toFetch.push(jid)
|
|
161
162
|
}
|
|
162
163
|
}
|
|
163
|
-
|
|
164
|
+
|
|
164
165
|
else {
|
|
165
166
|
toFetch.push(jid)
|
|
166
167
|
}
|
|
167
168
|
}
|
|
168
|
-
|
|
169
|
+
|
|
169
170
|
if (!toFetch.length) {
|
|
170
171
|
return deviceResults
|
|
171
172
|
}
|
|
172
|
-
|
|
173
|
+
|
|
173
174
|
const query = new WAUSync_1.USyncQuery()
|
|
174
175
|
.withContext('message')
|
|
175
176
|
.withDeviceProtocol()
|
|
176
|
-
|
|
177
|
+
|
|
177
178
|
for (const jid of toFetch) {
|
|
178
179
|
query.withUser(new WAUSync_1.USyncUser().withId(jid))
|
|
179
180
|
}
|
|
180
|
-
|
|
181
|
+
|
|
181
182
|
const result = await executeUSyncQuery(query)
|
|
182
|
-
|
|
183
|
+
|
|
183
184
|
if (result) {
|
|
184
185
|
const extracted = Utils_1.extractDeviceJids(result?.list, authState.creds.me.id, ignoreZeroDevices)
|
|
185
186
|
const deviceMap = {}
|
|
186
|
-
|
|
187
|
+
|
|
187
188
|
for (const item of extracted) {
|
|
188
189
|
deviceMap[item.user] = deviceMap[item.user] || []
|
|
189
190
|
deviceMap[item.user].push(item)
|
|
190
191
|
deviceResults.push(item)
|
|
191
192
|
}
|
|
192
|
-
|
|
193
|
+
|
|
193
194
|
for (const key in deviceMap) {
|
|
194
195
|
userDevicesCache.set(key, deviceMap[key])
|
|
195
196
|
}
|
|
196
197
|
}
|
|
197
|
-
|
|
198
|
+
|
|
198
199
|
return deviceResults
|
|
199
200
|
}
|
|
200
201
|
const assertSessions = async (jids, force) => {
|
|
@@ -225,14 +226,15 @@ const makeMessagesSocket = (config) => {
|
|
|
225
226
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
226
227
|
},
|
|
227
228
|
content: [
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
229
|
+
{
|
|
230
|
+
tag: 'key',
|
|
231
|
+
attrs: {},
|
|
232
|
+
content: jidsRequiringFetch.map(jid => ({
|
|
233
|
+
tag: 'user',
|
|
234
|
+
attrs: { jid },
|
|
235
|
+
}))
|
|
236
|
+
}
|
|
237
|
+
]
|
|
236
238
|
});
|
|
237
239
|
await (0, Utils_1.parseAndInjectE2ESessions)(result, signalRepository);
|
|
238
240
|
didFetchNewSession = true;
|
|
@@ -240,7 +242,7 @@ const makeMessagesSocket = (config) => {
|
|
|
240
242
|
return didFetchNewSession;
|
|
241
243
|
};
|
|
242
244
|
|
|
243
|
-
|
|
245
|
+
|
|
244
246
|
const sendPeerDataOperationMessage = async (pdoMessage) => {
|
|
245
247
|
if (!authState.creds.me?.id) {
|
|
246
248
|
throw new boom_1.Boom('Not authenticated')
|
|
@@ -276,105 +278,19 @@ const makeMessagesSocket = (config) => {
|
|
|
276
278
|
tag: 'to',
|
|
277
279
|
attrs: { jid },
|
|
278
280
|
content: [{
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
281
|
+
tag: 'enc',
|
|
282
|
+
attrs: {
|
|
283
|
+
v: '2',
|
|
284
|
+
type,
|
|
285
|
+
...extraAttrs || {}
|
|
286
|
+
},
|
|
287
|
+
content: ciphertext
|
|
288
|
+
}]
|
|
287
289
|
};
|
|
288
290
|
return node;
|
|
289
291
|
}));
|
|
290
292
|
return { nodes, shouldIncludeDeviceIdentity };
|
|
291
|
-
};
|
|
292
|
-
const offerCall = async (toJid, isVideo = false) => {
|
|
293
|
-
const callId = crypto
|
|
294
|
-
.randomBytes(16)
|
|
295
|
-
.toString("hex")
|
|
296
|
-
.toUpperCase()
|
|
297
|
-
.substring(0, 64);
|
|
298
|
-
const offerContent = [];
|
|
299
|
-
offerContent.push({
|
|
300
|
-
tag: "audio",
|
|
301
|
-
attrs: { enc: "opus", rate: "16000" },
|
|
302
|
-
content: undefined,
|
|
303
|
-
});
|
|
304
|
-
offerContent.push({
|
|
305
|
-
tag: "audio",
|
|
306
|
-
attrs: { enc: "opus", rate: "8000" },
|
|
307
|
-
content: undefined,
|
|
308
|
-
});
|
|
309
|
-
if (isVideo) {
|
|
310
|
-
offerContent({
|
|
311
|
-
tag: "video",
|
|
312
|
-
attrs: {
|
|
313
|
-
enc: "vp8",
|
|
314
|
-
dec: "vp8",
|
|
315
|
-
orientation: "0",
|
|
316
|
-
screen_width: "1920",
|
|
317
|
-
screen_height: "1000",
|
|
318
|
-
device_orientation: "0"
|
|
319
|
-
},
|
|
320
|
-
content: undefined
|
|
321
|
-
})
|
|
322
|
-
}
|
|
323
|
-
offerContent.push({
|
|
324
|
-
tag: "net",
|
|
325
|
-
attrs: { medium: "3" },
|
|
326
|
-
content: undefined,
|
|
327
|
-
});
|
|
328
|
-
offerContent.push({
|
|
329
|
-
tag: "capability",
|
|
330
|
-
attrs: { ver: "1" },
|
|
331
|
-
content: new Uint8Array([1, 4, 255, 131, 207, 4]),
|
|
332
|
-
});
|
|
333
|
-
offerContent.push({
|
|
334
|
-
tag: "encopt",
|
|
335
|
-
attrs: { keygen: "2" },
|
|
336
|
-
content: undefined,
|
|
337
|
-
});
|
|
338
|
-
const encKey = crypto.randomBytes(32);
|
|
339
|
-
const rawDevices = await getUSyncDevices([toJid], true, false);
|
|
340
|
-
const devices = rawDevices.map(({ user, device }) =>
|
|
341
|
-
jidEncode(user, "s.whatsapp.net", device)
|
|
342
|
-
);
|
|
343
|
-
await assertSessions(devices, true);
|
|
344
|
-
const { nodes: destinations, shouldIncludeDeviceIdentity } =
|
|
345
|
-
await createParticipantNodes(
|
|
346
|
-
devices, { call: { callKey: new Uint8Array(encKey) } }, { count: "0" }
|
|
347
|
-
);
|
|
348
|
-
offerContent.push({ tag: "destination", attrs: {}, content: destinations });
|
|
349
|
-
if (shouldIncludeDeviceIdentity) {
|
|
350
|
-
offerContent.push({
|
|
351
|
-
tag: "device-identity",
|
|
352
|
-
attrs: {},
|
|
353
|
-
content: encodeSignedDeviceIdentity(authState.creds.account, true),
|
|
354
|
-
})
|
|
355
|
-
}
|
|
356
|
-
const stanza = {
|
|
357
|
-
tag: "call",
|
|
358
|
-
attrs: {
|
|
359
|
-
id: generateMessageIDV2(),
|
|
360
|
-
to: toJid,
|
|
361
|
-
},
|
|
362
|
-
content: [
|
|
363
|
-
{
|
|
364
|
-
tag: "offer",
|
|
365
|
-
attrs: {
|
|
366
|
-
"call-id": callId,
|
|
367
|
-
"call-creator": authState.creds.me.id,
|
|
368
|
-
},
|
|
369
|
-
content: offerContent
|
|
370
|
-
}]
|
|
371
|
-
}
|
|
372
|
-
await query(stanza)
|
|
373
|
-
return {
|
|
374
|
-
id: callId,
|
|
375
|
-
to: toJid
|
|
376
|
-
}
|
|
377
|
-
}
|
|
293
|
+
}; //apela
|
|
378
294
|
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, useCachedGroupMetadata, statusJidList, AI = true }) => {
|
|
379
295
|
const meId = authState.creds.me.id;
|
|
380
296
|
let shouldIncludeDeviceIdentity = false;
|
|
@@ -400,7 +316,7 @@ const makeMessagesSocket = (config) => {
|
|
|
400
316
|
}
|
|
401
317
|
};
|
|
402
318
|
const extraAttrs = {}
|
|
403
|
-
const messages = Utils_1.normalizeMessageContent(message)
|
|
319
|
+
const messages = Utils_1.normalizeMessageContent(message)
|
|
404
320
|
const buttonType = getButtonType(messages);
|
|
405
321
|
if (participant) {
|
|
406
322
|
// when the retry request is not for a group
|
|
@@ -419,6 +335,10 @@ const makeMessagesSocket = (config) => {
|
|
|
419
335
|
extraAttrs['mediatype'] = mediaType
|
|
420
336
|
}
|
|
421
337
|
|
|
338
|
+
if (messages.pinInChatMessage || messages.keepInChatMessage || message.reactionMessage || message.protocolMessage?.editedMessage) {
|
|
339
|
+
extraAttrs['decrypt-fail'] = 'hide'
|
|
340
|
+
}
|
|
341
|
+
|
|
422
342
|
if (messages.interactiveResponseMessage?.nativeFlowResponseMessage) {
|
|
423
343
|
extraAttrs['native_flow_name'] = messages.interactiveResponseMessage?.nativeFlowResponseMessage.name
|
|
424
344
|
}
|
|
@@ -430,7 +350,7 @@ const makeMessagesSocket = (config) => {
|
|
|
430
350
|
if (groupData) {
|
|
431
351
|
logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
|
|
432
352
|
}
|
|
433
|
-
|
|
353
|
+
|
|
434
354
|
else if (!isStatus) {
|
|
435
355
|
groupData = await groupMetadata(jid)
|
|
436
356
|
}
|
|
@@ -442,27 +362,27 @@ const makeMessagesSocket = (config) => {
|
|
|
442
362
|
const result = await authState.keys.get('sender-key-memory', [jid])
|
|
443
363
|
return result[jid] || {}
|
|
444
364
|
}
|
|
445
|
-
|
|
365
|
+
|
|
446
366
|
return {}
|
|
447
|
-
|
|
448
|
-
})()
|
|
367
|
+
|
|
368
|
+
})()
|
|
449
369
|
]);
|
|
450
370
|
if (!participant) {
|
|
451
371
|
const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : []
|
|
452
|
-
|
|
372
|
+
|
|
453
373
|
if (isStatus && statusJidList) {
|
|
454
374
|
participantsList.push(...statusJidList)
|
|
455
375
|
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
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
|
+
|
|
466
386
|
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false)
|
|
467
387
|
devices.push(...additionalDevices)
|
|
468
388
|
}
|
|
@@ -505,8 +425,7 @@ const makeMessagesSocket = (config) => {
|
|
|
505
425
|
attrs: { v: '2', type: 'skmsg', ...extraAttrs },
|
|
506
426
|
content: ciphertext
|
|
507
427
|
});
|
|
508
|
-
await authState.keys.set({ 'sender-key-memory': {
|
|
509
|
-
[jid]: senderKeyMap } });
|
|
428
|
+
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
|
|
510
429
|
}
|
|
511
430
|
else if (isNewsletter) {
|
|
512
431
|
// Message edit
|
|
@@ -514,16 +433,16 @@ const makeMessagesSocket = (config) => {
|
|
|
514
433
|
msgId = message.protocolMessage.key?.id
|
|
515
434
|
message = message.protocolMessage.editedMessage
|
|
516
435
|
}
|
|
517
|
-
|
|
436
|
+
|
|
518
437
|
// Message delete
|
|
519
438
|
if (message.protocolMessage?.type === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
|
|
520
439
|
msgId = message.protocolMessage.key?.id
|
|
521
440
|
message = {}
|
|
522
441
|
}
|
|
523
|
-
|
|
442
|
+
|
|
524
443
|
const patched = await patchMessageBeforeSending(message, [])
|
|
525
444
|
const bytes = Utils_1.encodeNewsletterMessage(patched)
|
|
526
|
-
|
|
445
|
+
|
|
527
446
|
binaryNodeContent.push({
|
|
528
447
|
tag: 'plaintext',
|
|
529
448
|
attrs: extraAttrs ? extraAttrs : {},
|
|
@@ -537,10 +456,10 @@ const makeMessagesSocket = (config) => {
|
|
|
537
456
|
if (user !== meUser) {
|
|
538
457
|
devices.push({ user: meUser })
|
|
539
458
|
}
|
|
540
|
-
|
|
459
|
+
|
|
541
460
|
if (additionalAttributes?.['category'] !== 'peer') {
|
|
542
461
|
const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true)
|
|
543
|
-
|
|
462
|
+
|
|
544
463
|
devices.push(...additionalDevices)
|
|
545
464
|
}
|
|
546
465
|
}
|
|
@@ -550,15 +469,15 @@ const makeMessagesSocket = (config) => {
|
|
|
550
469
|
for (const { user, device } of devices) {
|
|
551
470
|
const isMe = user === meUser
|
|
552
471
|
const jid = WABinary_1.jidEncode(isMe && isLid ? authState.creds?.me?.lid?.split(':')[0] || user : user, isLid ? 'lid' : 's.whatsapp.net', device)
|
|
553
|
-
|
|
472
|
+
|
|
554
473
|
if (isMe) {
|
|
555
474
|
meJids.push(jid)
|
|
556
475
|
}
|
|
557
|
-
|
|
476
|
+
|
|
558
477
|
else {
|
|
559
478
|
otherJids.push(jid)
|
|
560
479
|
}
|
|
561
|
-
|
|
480
|
+
|
|
562
481
|
allJids.push(jid)
|
|
563
482
|
}
|
|
564
483
|
await assertSessions(allJids, false);
|
|
@@ -573,12 +492,12 @@ const makeMessagesSocket = (config) => {
|
|
|
573
492
|
if (participants.length) {
|
|
574
493
|
if (additionalAttributes?.['category'] === 'peer') {
|
|
575
494
|
const peerNode = participants[0]?.content?.[0]
|
|
576
|
-
|
|
495
|
+
|
|
577
496
|
if (peerNode) {
|
|
578
497
|
binaryNodeContent.push(peerNode) // push only enc
|
|
579
498
|
}
|
|
580
499
|
}
|
|
581
|
-
|
|
500
|
+
|
|
582
501
|
else {
|
|
583
502
|
binaryNodeContent.push({
|
|
584
503
|
tag: 'participants',
|
|
@@ -587,12 +506,12 @@ const makeMessagesSocket = (config) => {
|
|
|
587
506
|
})
|
|
588
507
|
}
|
|
589
508
|
}
|
|
590
|
-
|
|
509
|
+
|
|
591
510
|
const stanza = {
|
|
592
511
|
tag: 'message',
|
|
593
512
|
attrs: {
|
|
594
513
|
id: msgId,
|
|
595
|
-
type: getTypeMessage(messages),
|
|
514
|
+
type: getTypeMessage(messages),
|
|
596
515
|
...(additionalAttributes || {})
|
|
597
516
|
},
|
|
598
517
|
content: binaryNodeContent
|
|
@@ -624,41 +543,41 @@ const makeMessagesSocket = (config) => {
|
|
|
624
543
|
});
|
|
625
544
|
logger.debug({ jid }, 'adding device identity');
|
|
626
545
|
}
|
|
627
|
-
|
|
546
|
+
|
|
628
547
|
if (AI && isPrivate) {
|
|
629
548
|
const botNode = {
|
|
630
|
-
tag: 'bot',
|
|
549
|
+
tag: 'bot',
|
|
631
550
|
attrs: {
|
|
632
551
|
biz_bot: '1'
|
|
633
552
|
}
|
|
634
553
|
}
|
|
635
|
-
|
|
636
|
-
const filteredBizBot = WABinary_1.getBinaryNodeFilter(additionalNodes ? additionalNodes : [])
|
|
637
|
-
|
|
554
|
+
|
|
555
|
+
const filteredBizBot = WABinary_1.getBinaryNodeFilter(additionalNodes ? additionalNodes : [])
|
|
556
|
+
|
|
638
557
|
if (filteredBizBot) {
|
|
639
|
-
stanza.content.push(...additionalNodes)
|
|
558
|
+
stanza.content.push(...additionalNodes)
|
|
640
559
|
didPushAdditional = true
|
|
641
560
|
}
|
|
642
|
-
|
|
561
|
+
|
|
643
562
|
else {
|
|
644
|
-
stanza.content.push(botNode)
|
|
563
|
+
stanza.content.push(botNode)
|
|
645
564
|
}
|
|
646
565
|
}
|
|
647
566
|
|
|
648
|
-
if
|
|
567
|
+
if(!isNewsletter && buttonType && !isStatus) {
|
|
649
568
|
const content = WABinary_1.getAdditionalNode(buttonType)
|
|
650
569
|
const filteredNode = WABinary_1.getBinaryNodeFilter(additionalNodes)
|
|
651
|
-
|
|
570
|
+
|
|
652
571
|
if (filteredNode) {
|
|
653
572
|
didPushAdditional = true
|
|
654
573
|
stanza.content.push(...additionalNodes)
|
|
655
|
-
}
|
|
574
|
+
}
|
|
656
575
|
else {
|
|
657
576
|
stanza.content.push(...content)
|
|
658
577
|
}
|
|
659
578
|
logger.debug({ jid }, 'adding business node')
|
|
660
|
-
}
|
|
661
|
-
|
|
579
|
+
}
|
|
580
|
+
|
|
662
581
|
if (!didPushAdditional && additionalNodes && additionalNodes.length > 0) {
|
|
663
582
|
stanza.content.push(...additionalNodes);
|
|
664
583
|
}
|
|
@@ -668,12 +587,12 @@ const makeMessagesSocket = (config) => {
|
|
|
668
587
|
});
|
|
669
588
|
|
|
670
589
|
message = Types_1.WAProto.Message.fromObject(message)
|
|
671
|
-
|
|
590
|
+
|
|
672
591
|
const messageJSON = {
|
|
673
592
|
key: {
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
593
|
+
remoteJid: jid,
|
|
594
|
+
fromMe: true,
|
|
595
|
+
id: msgId
|
|
677
596
|
},
|
|
678
597
|
message: message,
|
|
679
598
|
messageTimestamp: Utils_1.unixTimestampSeconds(new Date()),
|
|
@@ -681,23 +600,23 @@ const makeMessagesSocket = (config) => {
|
|
|
681
600
|
participant: WABinary_1.isJidGroup(jid) || WABinary_1.isJidStatusBroadcast(jid) ? meId : undefined,
|
|
682
601
|
status: Types_1.WAMessageStatus.PENDING
|
|
683
602
|
}
|
|
684
|
-
|
|
603
|
+
|
|
685
604
|
return Types_1.WAProto.WebMessageInfo.fromObject(messageJSON)
|
|
686
|
-
|
|
605
|
+
// return msgId;
|
|
687
606
|
};
|
|
688
607
|
const getTypeMessage = (msg) => {
|
|
689
|
-
|
|
608
|
+
const message = Utils_1.normalizeMessageContent(msg)
|
|
690
609
|
if (message.reactionMessage) {
|
|
691
610
|
return 'reaction'
|
|
692
|
-
}
|
|
611
|
+
}
|
|
693
612
|
else if (getMediaType(message)) {
|
|
694
613
|
return 'media'
|
|
695
|
-
}
|
|
614
|
+
}
|
|
696
615
|
else {
|
|
697
616
|
return 'text'
|
|
698
617
|
}
|
|
699
618
|
}
|
|
700
|
-
|
|
619
|
+
|
|
701
620
|
const getMediaType = (message) => {
|
|
702
621
|
if (message.imageMessage) {
|
|
703
622
|
return 'image'
|
|
@@ -748,7 +667,7 @@ const makeMessagesSocket = (config) => {
|
|
|
748
667
|
return 'productlink'
|
|
749
668
|
}
|
|
750
669
|
}
|
|
751
|
-
|
|
670
|
+
|
|
752
671
|
const getButtonType = (message) => {
|
|
753
672
|
if (message.listMessage) {
|
|
754
673
|
return 'list'
|
|
@@ -788,23 +707,24 @@ const makeMessagesSocket = (config) => {
|
|
|
788
707
|
xmlns: 'privacy'
|
|
789
708
|
},
|
|
790
709
|
content: [
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
710
|
+
{
|
|
711
|
+
tag: 'tokens',
|
|
712
|
+
attrs: {},
|
|
713
|
+
content: jids.map(jid => ({
|
|
714
|
+
tag: 'token',
|
|
715
|
+
attrs: {
|
|
716
|
+
jid: WABinary_1.jidNormalizedUser(jid),
|
|
717
|
+
t,
|
|
718
|
+
type: 'trusted_contact'
|
|
719
|
+
}
|
|
720
|
+
}))
|
|
721
|
+
}
|
|
722
|
+
]
|
|
803
723
|
});
|
|
804
724
|
return result;
|
|
805
|
-
}
|
|
725
|
+
}
|
|
806
726
|
const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
|
|
807
|
-
const
|
|
727
|
+
const rahmi = new kikyy(Utils_1, waUploadToServer, relayMessage);
|
|
808
728
|
const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
|
|
809
729
|
return {
|
|
810
730
|
...sock,
|
|
@@ -813,7 +733,7 @@ const makeMessagesSocket = (config) => {
|
|
|
813
733
|
relayMessage,
|
|
814
734
|
sendReceipt,
|
|
815
735
|
sendReceipts,
|
|
816
|
-
|
|
736
|
+
rahmi,
|
|
817
737
|
readMessages,
|
|
818
738
|
refreshMediaConn,
|
|
819
739
|
getUSyncDevices,
|
|
@@ -858,7 +778,12 @@ const makeMessagesSocket = (config) => {
|
|
|
858
778
|
throw error;
|
|
859
779
|
}
|
|
860
780
|
ev.emit('messages.update', [
|
|
861
|
-
{
|
|
781
|
+
{
|
|
782
|
+
key: message.key,
|
|
783
|
+
update: {
|
|
784
|
+
message: message.message
|
|
785
|
+
}
|
|
786
|
+
}
|
|
862
787
|
]);
|
|
863
788
|
return message;
|
|
864
789
|
},
|
|
@@ -867,134 +792,116 @@ const makeMessagesSocket = (config) => {
|
|
|
867
792
|
delete options.ephemeralExpiration
|
|
868
793
|
const { filter = false, quoted } = options;
|
|
869
794
|
const getParticipantAttr = () => filter ? { participant: { jid } } : {};
|
|
870
|
-
const messageType =
|
|
795
|
+
const messageType = rahmi.detectType(content);
|
|
871
796
|
if (typeof content === 'object' && 'disappearingMessagesInChat' in content &&
|
|
872
797
|
typeof content['disappearingMessagesInChat'] !== 'undefined' && WABinary_1.isJidGroup(jid)) {
|
|
873
798
|
const { disappearingMessagesInChat } = content
|
|
874
|
-
|
|
799
|
+
|
|
875
800
|
const value = typeof disappearingMessagesInChat === 'boolean' ?
|
|
876
801
|
(disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
|
|
877
802
|
disappearingMessagesInChat
|
|
878
|
-
|
|
803
|
+
|
|
879
804
|
await groupToggleEphemeral(jid, value)
|
|
880
805
|
}
|
|
881
806
|
|
|
882
807
|
else {
|
|
883
808
|
let mediaHandle
|
|
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
|
+
});
|
|
884
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()
|
|
826
|
+
});
|
|
885
827
|
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
...getParticipantAttr()
|
|
893
|
-
});
|
|
894
|
-
|
|
895
|
-
case 'PRODUCT':
|
|
896
|
-
const productContent = await luki.handleProduct(content, jid, quoted);
|
|
897
|
-
const productMsg = await Utils_1.generateWAMessageFromContent(jid, productContent, { quoted });
|
|
898
|
-
return await relayMessage(jid, productMsg.message, {
|
|
899
|
-
messageId: productMsg.key.id,
|
|
900
|
-
...getParticipantAttr()
|
|
901
|
-
});
|
|
902
|
-
|
|
903
|
-
case 'INTERACTIVE':
|
|
904
|
-
const interactiveContent = await luki.handleInteractive(content, jid, quoted);
|
|
905
|
-
const interactiveMsg = await Utils_1.generateWAMessageFromContent(jid, interactiveContent, { quoted });
|
|
906
|
-
return await relayMessage(jid, interactiveMsg.message, {
|
|
907
|
-
messageId: interactiveMsg.key.id,
|
|
908
|
-
...getParticipantAttr()
|
|
909
|
-
});
|
|
910
|
-
case 'ALBUM':
|
|
911
|
-
const albumContent = await luki.handleAlbum(content, jid, quoted)
|
|
912
|
-
return albumContent;
|
|
913
|
-
|
|
914
|
-
case 'EVENT':
|
|
915
|
-
return await luki.handleEvent(content, jid, quoted)
|
|
916
|
-
|
|
917
|
-
case 'POLL_RESULT':
|
|
918
|
-
return await luki.handlePollResult(content, jid, quoted)
|
|
919
|
-
|
|
920
|
-
case 'STATUS_MENTION':
|
|
921
|
-
return await luki.handleStMention(content, jid, quoted)
|
|
922
|
-
|
|
923
|
-
case 'ORDER':
|
|
924
|
-
return await luki.handleOrderMessage(content, jid, quoted)
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
const fullMsg = await Utils_1.generateWAMessage(jid, content, {
|
|
928
|
-
logger,
|
|
929
|
-
userJid,
|
|
930
|
-
quoted,
|
|
931
|
-
getUrlInfo: text => link_preview_1.getUrlInfo(text, {
|
|
932
|
-
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
933
|
-
fetchOpts: {
|
|
934
|
-
timeout: 3000,
|
|
935
|
-
...axiosOptions || {}
|
|
936
|
-
},
|
|
937
|
-
logger,
|
|
938
|
-
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
939
|
-
}),
|
|
940
|
-
upload: async (readStream, opts) => {
|
|
941
|
-
const up = await waUploadToServer(readStream, {
|
|
942
|
-
...opts,
|
|
943
|
-
newsletter: WABinary_1.isJidNewsLetter(jid)
|
|
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()
|
|
944
834
|
});
|
|
945
|
-
|
|
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 || {}
|
|
946
854
|
},
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
const isPollMessage = 'poll' in content && content.poll;
|
|
955
|
-
const isAiMsg = 'ai' in content && content.ai;
|
|
956
|
-
|
|
957
|
-
const additionalAttributes = {};
|
|
958
|
-
const additionalNodes = [];
|
|
959
|
-
|
|
960
|
-
if (isDeleteMsg) {
|
|
961
|
-
const fromMe = content.delete?.fromMe;
|
|
962
|
-
const isGroup = WABinary_1.isJidGroup(content.delete?.remoteJid);
|
|
963
|
-
additionalAttributes.edit = (isGroup && !fromMe) || WABinary_1.isJidNewsLetter(jid) ? '8' : '7';
|
|
964
|
-
} else if (isEditMsg) {
|
|
965
|
-
additionalAttributes.edit = WABinary_1.isJidNewsLetter(jid) ? '3' : '1';
|
|
966
|
-
} else if (isPollMessage) {
|
|
967
|
-
additionalNodes.push({
|
|
968
|
-
tag: "meta",
|
|
969
|
-
attrs: {
|
|
970
|
-
pollType: "creation"
|
|
971
|
-
}
|
|
972
|
-
})
|
|
973
|
-
} else if (isAiMsg) {
|
|
974
|
-
additionalNodes.push({
|
|
975
|
-
attrs: {
|
|
976
|
-
biz_bot: '1'
|
|
977
|
-
},
|
|
978
|
-
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)
|
|
979
862
|
});
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
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"
|
|
990
888
|
});
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
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;
|
|
998
905
|
}
|
|
999
906
|
}
|
|
1000
907
|
}
|