@kanaraa/baileys 3.1.9 → 3.3.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/lib/Socket/groups.js
CHANGED
|
@@ -16,9 +16,23 @@ export const makeGroupsSocket = (config) => {
|
|
|
16
16
|
},
|
|
17
17
|
content
|
|
18
18
|
});
|
|
19
|
-
const
|
|
19
|
+
const fetchJoinRequests = async (jid) => {
|
|
20
|
+
const req = await groupQuery(jid, 'get', [
|
|
21
|
+
{
|
|
22
|
+
tag: 'membership_approval_requests',
|
|
23
|
+
attrs: {}
|
|
24
|
+
}
|
|
25
|
+
]);
|
|
26
|
+
const node = getBinaryNodeChild(req, 'membership_approval_requests');
|
|
27
|
+
return getBinaryNodeChildren(node, 'membership_approval_request').map(v => v.attrs);
|
|
28
|
+
};
|
|
29
|
+
const groupMetadata = async (jid, opts = {}) => {
|
|
20
30
|
const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
|
|
21
|
-
|
|
31
|
+
const metadata = extractGroupMetadata(result);
|
|
32
|
+
if (opts.joinRequests) {
|
|
33
|
+
metadata.joinRequests = await fetchJoinRequests(jid).catch(() => []);
|
|
34
|
+
}
|
|
35
|
+
return metadata;
|
|
22
36
|
};
|
|
23
37
|
const groupFetchAllParticipating = async () => {
|
|
24
38
|
const result = await query({
|
|
@@ -103,15 +117,7 @@ export const makeGroupsSocket = (config) => {
|
|
|
103
117
|
]);
|
|
104
118
|
},
|
|
105
119
|
groupRequestParticipantsList: async (jid) => {
|
|
106
|
-
|
|
107
|
-
{
|
|
108
|
-
tag: 'membership_approval_requests',
|
|
109
|
-
attrs: {}
|
|
110
|
-
}
|
|
111
|
-
]);
|
|
112
|
-
const node = getBinaryNodeChild(result, 'membership_approval_requests');
|
|
113
|
-
const participants = getBinaryNodeChildren(node, 'membership_approval_request');
|
|
114
|
-
return participants.map(v => v.attrs);
|
|
120
|
+
return fetchJoinRequests(jid).catch(() => []);
|
|
115
121
|
},
|
|
116
122
|
groupRequestParticipantsUpdate: async (jid, participants, action) => {
|
|
117
123
|
const result = await groupQuery(jid, 'set', [
|
|
@@ -342,5 +348,6 @@ export const extractGroupMetadata = (result) => {
|
|
|
342
348
|
}),
|
|
343
349
|
ephemeralDuration: eph ? +eph : undefined
|
|
344
350
|
};
|
|
351
|
+
metadata.admins = metadata.participants.filter(p => p.admin);
|
|
345
352
|
return metadata;
|
|
346
353
|
};
|
|
@@ -1429,6 +1429,9 @@ export const makeMessagesRecvSocket = (config) => {
|
|
|
1429
1429
|
}
|
|
1430
1430
|
}
|
|
1431
1431
|
cleanMessage(msg, authState.creds.me.id, authState.creds.me.lid);
|
|
1432
|
+
if (isLidUser(msg.key.remoteJid) && msg.key.remoteJidAlt && isPnUser(msg.key.remoteJidAlt)) {
|
|
1433
|
+
msg.key.remoteJid = msg.key.remoteJidAlt;
|
|
1434
|
+
}
|
|
1432
1435
|
await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify');
|
|
1433
1436
|
});
|
|
1434
1437
|
}
|
|
@@ -7,7 +7,7 @@ import { getUrlInfo } from '../Utils/link-preview.js';
|
|
|
7
7
|
import { makeKeyedMutex, makeMutex } from '../Utils/make-mutex.js';
|
|
8
8
|
import { getMessageReportingToken, shouldIncludeReportingToken } from '../Utils/reporting-utils.js';
|
|
9
9
|
import { buildMergedTcTokenIndexWrite, isTcTokenExpired, resolveIssuanceJid, resolveTcTokenJid, shouldSendNewTcToken, storeTcTokensFromIqResult } from '../Utils/tc-token-utils.js';
|
|
10
|
-
import { areJidsSameUser, getBinaryNodeChild, getBinaryNodeChildren, isHostedLidUser, isHostedPnUser, isJidBot, isJidGroup, isJidMetaAI, isLidUser, isPnUser, jidDecode, jidEncode, jidNormalizedUser, PSA_WID, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
10
|
+
import { areJidsSameUser, getBinaryNodeChild, getBinaryNodeChildren, isHostedLidUser, isHostedPnUser, isJidBot, isJidGroup, isJidMetaAI, isJidNewsletter, isLidUser, isPnUser, jidDecode, jidEncode, jidNormalizedUser, PSA_WID, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
11
11
|
import { USyncQuery, USyncUser } from '../WAUSync/index.js';
|
|
12
12
|
import { makeNewsletterSocket } from './newsletter.js';
|
|
13
13
|
export const makeMessagesSocket = (config) => {
|
|
@@ -475,7 +475,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
475
475
|
const bytes = encodeNewsletterMessage(patched);
|
|
476
476
|
binaryNodeContent.push({
|
|
477
477
|
tag: 'plaintext',
|
|
478
|
-
attrs: {},
|
|
478
|
+
attrs: mediaType ? { mediatype: mediaType } : {},
|
|
479
479
|
content: bytes
|
|
480
480
|
});
|
|
481
481
|
const stanza = {
|
|
@@ -1110,7 +1110,10 @@ export const makeMessagesSocket = (config) => {
|
|
|
1110
1110
|
//TODO: CACHE
|
|
1111
1111
|
getProfilePicUrl: sock.profilePictureUrl,
|
|
1112
1112
|
getCallLink: sock.createCallLink,
|
|
1113
|
-
upload:
|
|
1113
|
+
upload: (readStream, opts) => {
|
|
1114
|
+
const up = waUploadToServer(readStream, { ...opts, newsletter: isJidNewsletter(jid) });
|
|
1115
|
+
return up;
|
|
1116
|
+
},
|
|
1114
1117
|
mediaCache: config.mediaCache,
|
|
1115
1118
|
options: config.options,
|
|
1116
1119
|
messageId: generateMessageIDV2(sock.user?.id),
|
package/lib/Socket/newsletter.js
CHANGED
|
@@ -4,21 +4,22 @@ import { getBinaryNodeChild } from '../WABinary/index.js';
|
|
|
4
4
|
import { makeGroupsSocket } from './groups.js';
|
|
5
5
|
import { executeWMexQuery as genericExecuteWMexQuery } from './mex.js';
|
|
6
6
|
const parseNewsletterCreateResponse = (response) => {
|
|
7
|
-
const { id, thread_metadata:
|
|
7
|
+
const { id, thread_metadata: rawThread, viewer_metadata: viewer } = response;
|
|
8
|
+
const thread = rawThread ?? {};
|
|
8
9
|
return {
|
|
9
10
|
id: id,
|
|
10
11
|
owner: undefined,
|
|
11
|
-
name: thread.name
|
|
12
|
-
creation_time: parseInt(thread.creation_time, 10),
|
|
13
|
-
description: thread.description
|
|
12
|
+
name: thread.name?.text ?? '',
|
|
13
|
+
creation_time: parseInt(thread.creation_time ?? 0, 10),
|
|
14
|
+
description: thread.description?.text ?? '',
|
|
14
15
|
invite: thread.invite,
|
|
15
|
-
subscribers: parseInt(thread.subscribers_count, 10),
|
|
16
|
+
subscribers: parseInt(thread.subscribers_count ?? 0, 10),
|
|
16
17
|
verification: thread.verification,
|
|
17
18
|
picture: {
|
|
18
|
-
id: thread.picture
|
|
19
|
-
directPath: thread.picture
|
|
19
|
+
id: thread.picture?.id,
|
|
20
|
+
directPath: thread.picture?.direct_path
|
|
20
21
|
},
|
|
21
|
-
mute_state: viewer
|
|
22
|
+
mute_state: viewer?.mute
|
|
22
23
|
};
|
|
23
24
|
};
|
|
24
25
|
const parseNewsletterMetadata = (result) => {
|
|
@@ -641,12 +641,16 @@ const uploadMedia = async (params, logger) => {
|
|
|
641
641
|
}
|
|
642
642
|
};
|
|
643
643
|
export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
|
|
644
|
-
return async (filePath, { mediaType, fileEncSha256B64, timeoutMs }) => {
|
|
644
|
+
return async (filePath, { mediaType, fileEncSha256B64, newsletter, timeoutMs }) => {
|
|
645
645
|
// send a query JSON to obtain the url & auth token to upload our media
|
|
646
646
|
let uploadInfo = await refreshMediaConn(false);
|
|
647
647
|
let urls;
|
|
648
648
|
const hosts = [...customUploadHosts, ...uploadInfo.hosts];
|
|
649
649
|
fileEncSha256B64 = encodeBase64EncodedStringForUpload(fileEncSha256B64);
|
|
650
|
+
let media = MEDIA_PATH_MAP[mediaType];
|
|
651
|
+
if (newsletter) {
|
|
652
|
+
media = media?.replace('/mms/', '/newsletter/newsletter-');
|
|
653
|
+
}
|
|
650
654
|
// Prepare common headers
|
|
651
655
|
const customHeaders = (() => {
|
|
652
656
|
const hdrs = options?.headers;
|
|
@@ -662,7 +666,7 @@ export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, opt
|
|
|
662
666
|
for (const { hostname } of hosts) {
|
|
663
667
|
logger.debug(`uploading to "${hostname}"`);
|
|
664
668
|
const auth = encodeURIComponent(uploadInfo.auth);
|
|
665
|
-
const url = `https://${hostname}${
|
|
669
|
+
const url = `https://${hostname}${media}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`;
|
|
666
670
|
let result;
|
|
667
671
|
try {
|
|
668
672
|
result = await uploadMedia({
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanaraa/baileys",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.3.0",
|
|
5
5
|
"description": "Modded Baileys v7, Rebuilt on top of official @whiskeysockets/baileys 7.0.0-rc13, with the interactive & rich-message content types (buttons, lists, carousel, cards, shop/collection, native flow, AI rich response, sticker packs, admin invite, payments, etc.).",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"whatsapp",
|