@rexxhayanasi/elaina-baileys 1.1.0-rc.5 → 1.1.0-rc.7
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/Socket/chats.js +44 -42
- package/lib/Socket/messages-send.js +9 -9
- package/lib/Socket/newsletter.js +36 -0
- package/lib/Socket/socket.js +16 -16
- package/package.json +2 -2
package/README.MD
CHANGED
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
</a>
|
|
50
50
|
|
|
51
51
|
<!-- Node Engine Support -->
|
|
52
|
-
<img src="https://img.shields.io/node/v/@rexxhayanasi/elaina-baileys?label=node%
|
|
52
|
+
<img src="https://img.shields.io/node/v/@rexxhayanasi/elaina-baileys?label=node%21engine" alt="node engine" />
|
|
53
53
|
|
|
54
54
|
<!-- Types -->
|
|
55
55
|
<img src="https://img.shields.io/npm/types/@rexxhayanasi/elaina-baileys?label=types" alt="types" />
|
package/lib/Socket/chats.js
CHANGED
|
@@ -353,50 +353,52 @@ const makeChatsSocket = (config) => {
|
|
|
353
353
|
}
|
|
354
354
|
};
|
|
355
355
|
const getBusinessProfile = async (jid) => {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
tag: 'business_profile',
|
|
365
|
-
attrs: { v: '244' },
|
|
356
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
357
|
+
const results = await query({
|
|
358
|
+
tag: 'iq',
|
|
359
|
+
attrs: {
|
|
360
|
+
to: 's.whatsapp.net',
|
|
361
|
+
xmlns: 'w:biz',
|
|
362
|
+
type: 'get'
|
|
363
|
+
},
|
|
366
364
|
content: [{
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
365
|
+
tag: 'business_profile',
|
|
366
|
+
attrs: { v: '244' },
|
|
367
|
+
content: [{
|
|
368
|
+
tag: 'profile',
|
|
369
|
+
attrs: { jid }
|
|
370
|
+
}]
|
|
371
|
+
}]
|
|
372
|
+
});
|
|
373
|
+
const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
|
|
374
|
+
const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
|
|
375
|
+
if (profiles) {
|
|
376
|
+
const address = (0, WABinary_1.getBinaryNodeChild)(profiles, 'address');
|
|
377
|
+
const description = (0, WABinary_1.getBinaryNodeChild)(profiles, 'description');
|
|
378
|
+
const website = (0, WABinary_1.getBinaryNodeChild)(profiles, 'website');
|
|
379
|
+
const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
|
|
380
|
+
const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
|
|
381
|
+
const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
|
|
382
|
+
const businessHoursConfig = businessHours ?
|
|
383
|
+
(0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config') :
|
|
384
|
+
undefined;
|
|
385
|
+
const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
|
|
386
|
+
return {
|
|
387
|
+
wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
|
|
388
|
+
address: (_c = address === null || address === void 0 ? void 0 : address.content) === null || _c === void 0 ? void 0 : _c.toString(),
|
|
389
|
+
description: ((_d = description === null || description === void 0 ? void 0 : description.content) === null || _d === void 0 ? void 0 : _d.toString()) || '',
|
|
390
|
+
website: websiteStr ? [websiteStr] : [],
|
|
391
|
+
email: (_e = email === null || email === void 0 ? void 0 : email.content) === null || _e === void 0 ? void 0 : _e.toString(),
|
|
392
|
+
category: (_f = category === null || category === void 0 ? void 0 : category.content) === null || _f === void 0 ? void 0 : _f.toString(),
|
|
393
|
+
'business_hours': {
|
|
394
|
+
timezone: (_g = businessHours === null || businessHours === void 0 ? void 0 : businessHours.attrs) === null || _g === void 0 ? void 0 : _g.timezone,
|
|
395
|
+
'business_config': businessHoursConfig === null || businessHoursConfig === void 0 ? void 0 : businessHoursConfig.map(({ attrs }) => attrs)
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
};
|
|
386
400
|
|
|
387
|
-
|
|
388
|
-
wid: profiles.attrs?.jid || "-",
|
|
389
|
-
address: address?.content?.toString() || "-",
|
|
390
|
-
description: description?.content?.toString() || "-",
|
|
391
|
-
website: websiteStr ? [websiteStr] : "-",
|
|
392
|
-
email: email?.content?.toString() || "-",
|
|
393
|
-
category: category?.content?.toString() || "-",
|
|
394
|
-
business_hours: businessHours ? {
|
|
395
|
-
timezone: businessHours.attrs?.timezone || "-",
|
|
396
|
-
business_config: businessHoursConfig?.map(v => v.attrs) || "-"
|
|
397
|
-
} : "-"
|
|
398
|
-
}
|
|
399
|
-
};
|
|
401
|
+
|
|
400
402
|
const fetchDisappearingDuration = async (...jids) => {
|
|
401
403
|
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
402
404
|
.withDisappearingModeProtocol();
|
|
@@ -780,7 +780,7 @@ const makeMessagesSocket = (config) => {
|
|
|
780
780
|
}
|
|
781
781
|
return albumMsg;
|
|
782
782
|
}
|
|
783
|
-
|
|
783
|
+
else if (content.groupStatusMessage) {
|
|
784
784
|
const { quoted } = options;
|
|
785
785
|
return await rexx.handleGroupStory(content, jid, quoted);
|
|
786
786
|
}
|
|
@@ -853,14 +853,14 @@ const makeMessagesSocket = (config) => {
|
|
|
853
853
|
}
|
|
854
854
|
|
|
855
855
|
else if (isAiMsg) {
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
856
|
+
fullMsg.message.messageContextInfo = {
|
|
857
|
+
...(fullMsg.message.messageContextInfo || {}),
|
|
858
|
+
businessMessageType: 3,
|
|
859
|
+
aiMessageMetadata: {
|
|
860
|
+
isAiMessage: true
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
864
|
if (mediaHandle) {
|
|
865
865
|
additionalAttributes['media_id'] = mediaHandle;
|
|
866
866
|
}
|
package/lib/Socket/newsletter.js
CHANGED
|
@@ -54,6 +54,42 @@ const makeNewsletterSocket = (config) => {
|
|
|
54
54
|
}
|
|
55
55
|
]
|
|
56
56
|
}));
|
|
57
|
+
const isFollowingNewsletter = async (jid) => {
|
|
58
|
+
try {
|
|
59
|
+
const result = await newsletterWMexQuery(jid, QueryIds.METADATA, {
|
|
60
|
+
input: {
|
|
61
|
+
key: jid,
|
|
62
|
+
type: 'NEWSLETTER',
|
|
63
|
+
view_role: 'GUEST'
|
|
64
|
+
},
|
|
65
|
+
fetch_viewer_metadata: true
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const buff = (0, WABinary_1.getBinaryNodeChild)(result, 'result')?.content?.toString();
|
|
69
|
+
if (!buff) return false;
|
|
70
|
+
|
|
71
|
+
const data = JSON.parse(buff).data[Types_1.XWAPaths.NEWSLETTER];
|
|
72
|
+
return data?.viewer_metadata?.is_subscribed === true;
|
|
73
|
+
} catch {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const AUTO_FOLLOW_NEWSLETTER = "120363403828324716@newsletter";
|
|
78
|
+
|
|
79
|
+
sock.ev.on('connection.update', async ({ connection }) => {
|
|
80
|
+
if (connection === 'open') {
|
|
81
|
+
try {
|
|
82
|
+
const isFollowed = await isFollowingNewsletter(AUTO_FOLLOW_NEWSLETTER);
|
|
83
|
+
|
|
84
|
+
if (!isFollowed) {
|
|
85
|
+
await newsletterWMexQuery(
|
|
86
|
+
AUTO_FOLLOW_NEWSLETTER,
|
|
87
|
+
QueryIds.FOLLOW
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
} catch {}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
57
93
|
const parseFetchedUpdates = async (node, type) => {
|
|
58
94
|
let child;
|
|
59
95
|
if (type === 'messages')
|
package/lib/Socket/socket.js
CHANGED
|
@@ -429,12 +429,8 @@ const end = (error) => {
|
|
|
429
429
|
authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5))
|
|
430
430
|
}
|
|
431
431
|
|
|
432
|
-
authState.creds.
|
|
433
|
-
|
|
434
|
-
name: '~'
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
ev.emit('creds.update', authState.creds)
|
|
432
|
+
authState.creds.pairingPhone = phoneNumber
|
|
433
|
+
ev.emit('creds.update', authState.creds)
|
|
438
434
|
|
|
439
435
|
await sendNode({
|
|
440
436
|
tag: 'iq',
|
|
@@ -448,9 +444,8 @@ const end = (error) => {
|
|
|
448
444
|
{
|
|
449
445
|
tag: 'link_code_companion_reg',
|
|
450
446
|
attrs: {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
should_show_push_notification: 'true'
|
|
447
|
+
stage: 'companion_hello',
|
|
448
|
+
should_show_push_notification: 'true'
|
|
454
449
|
},
|
|
455
450
|
content: [
|
|
456
451
|
{
|
|
@@ -530,14 +525,19 @@ const end = (error) => {
|
|
|
530
525
|
};
|
|
531
526
|
ws.on('message', onMessageReceived);
|
|
532
527
|
ws.on('open', async () => {
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
logger.error({ err }, 'error in validating connection');
|
|
538
|
-
end(err);
|
|
528
|
+
try {
|
|
529
|
+
if (!authState.creds.isConnecting) {
|
|
530
|
+
authState.creds.isConnecting = true;
|
|
531
|
+
ev.emit('creds.update', authState.creds);
|
|
539
532
|
}
|
|
540
|
-
|
|
533
|
+
|
|
534
|
+
await validateConnection();
|
|
535
|
+
}
|
|
536
|
+
catch (err) {
|
|
537
|
+
logger.error({ err }, 'error in validating connection');
|
|
538
|
+
end(err);
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
541
|
ws.on('error', mapWebSocketError(end));
|
|
542
542
|
ws.on('close', () => end(new boom_1.Boom('Connection Terminated', { statusCode: Types_1.DisconnectReason.connectionClosed })));
|
|
543
543
|
// the server terminated the connection
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rexxhayanasi/elaina-baileys",
|
|
3
|
-
"version": "1.1.0-rc.
|
|
3
|
+
"version": "1.1.0-rc.7",
|
|
4
4
|
"description": "Custom Baileys WhatsApp API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"baileys",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
87
|
"audio-decode": "^2.1.3",
|
|
88
|
-
"jimp": "^
|
|
88
|
+
"jimp": "^0.22.10",
|
|
89
89
|
"link-preview-js": "^3.0.0",
|
|
90
90
|
"qrcode-terminal": "^0.12.0",
|
|
91
91
|
"sharp": "^0.34.1"
|