lordceaser-baileys 3.3.8 → 3.4.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/WAProto/index.js +1 -2
- package/index.js +4 -16
- package/lib/Socket/Client/index.js +0 -1
- package/lib/Socket/Client/types.js +1 -2
- package/lib/Socket/Client/websocket.js +1 -2
- package/lib/Socket/business.js +70 -42
- package/lib/Socket/chats.js +731 -21
- package/lib/Socket/communities.js +1 -1
- package/lib/Socket/groups.js +207 -5
- package/lib/Socket/index.js +28 -3
- package/lib/Socket/messages-recv.js +381 -9
- package/lib/Socket/messages-send.js +2189 -157
- package/lib/Socket/mex.js +1 -2
- package/lib/Socket/newsletter.js +98 -19
- package/lib/Socket/socket.js +64 -17
- package/lib/Utils/crypto.js +6 -5
- package/lib/Utils/lt-hash.js +3 -8
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +7 -3
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +1 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +1 -2
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +2 -3
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -2
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +1 -2
- package/lib/WAUSync/Protocols/index.js +7 -1
- package/lib/WAUSync/USyncQuery.js +126 -23
- package/lib/WAUSync/USyncUser.js +24 -1
- package/lib/WAUSync/index.js +1 -2
- package/package.json +2 -6
- package/lib/Socket/Socket/Client/index.js +0 -2
- package/lib/Socket/Socket/Client/types.js +0 -10
- package/lib/Socket/Socket/Client/websocket.js +0 -53
- package/lib/Socket/Socket/business.js +0 -407
- package/lib/Socket/Socket/chats.js +0 -1908
- package/lib/Socket/Socket/communities.js +0 -431
- package/lib/Socket/Socket/groups.js +0 -549
- package/lib/Socket/Socket/index.js +0 -37
- package/lib/Socket/Socket/messages-recv.js +0 -2144
- package/lib/Socket/Socket/messages-send.js +0 -3177
- package/lib/Socket/Socket/mex.js +0 -41
- package/lib/Socket/Socket/newsletter.js +0 -260
- package/lib/Socket/Socket/socket.js +0 -1017
- package/lib/Utils/_crypto_orig.js +0 -118
- package/lib/WAUSync/WAUSync/Protocols/USyncContactProtocol.js +0 -56
- package/lib/WAUSync/WAUSync/Protocols/USyncDeviceProtocol.js +0 -53
- package/lib/WAUSync/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -26
- package/lib/WAUSync/WAUSync/Protocols/USyncStatusProtocol.js +0 -37
- package/lib/WAUSync/WAUSync/Protocols/USyncUsernameProtocol.js +0 -24
- package/lib/WAUSync/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -50
- package/lib/WAUSync/WAUSync/Protocols/UsyncLIDProtocol.js +0 -28
- package/lib/WAUSync/WAUSync/Protocols/index.js +0 -12
- package/lib/WAUSync/WAUSync/USyncQuery.js +0 -201
- package/lib/WAUSync/WAUSync/USyncUser.js +0 -54
- package/lib/WAUSync/WAUSync/index.js +0 -3
- /package/lib/Socket/{Socket/aigroups.js → aigroups.js} +0 -0
- /package/lib/Socket/{Socket/ban-checker.js → ban-checker.js} +0 -0
- /package/lib/Socket/{Socket/chats.js[old] → chats.js[old]} +0 -0
- /package/lib/Socket/{Socket/graphql.js → graphql.js} +0 -0
- /package/lib/Socket/{Socket/groups.js[old] → groups.js[old]} +0 -0
- /package/lib/Socket/{Socket/interactive-handler.js → interactive-handler.js} +0 -0
- /package/lib/Socket/{Socket/interop.js → interop.js} +0 -0
- /package/lib/Socket/{Socket/managed-account.js → managed-account.js} +0 -0
- /package/lib/Socket/{Socket/privacy.js → privacy.js} +0 -0
- /package/lib/Socket/{Socket/registration.js → registration.js} +0 -0
- /package/lib/Socket/{Socket/username.js → username.js} +0 -0
- /package/lib/WAUSync/{WAUSync/Protocols → Protocols}/USyncBusinessProtocol.js +0 -0
- /package/lib/WAUSync/{WAUSync/Protocols → Protocols}/USyncFeatureProtocol.js +0 -0
- /package/lib/WAUSync/{WAUSync/Protocols → Protocols}/USyncPictureProtocol.js +0 -0
- /package/lib/WAUSync/{WAUSync/Protocols → Protocols}/USyncSidelistProtocol.js +0 -0
- /package/lib/WAUSync/{WAUSync/Protocols → Protocols}/USyncTextStatusProtocol.js +0 -0
|
@@ -85,6 +85,7 @@ export const makeCommunitiesSocket = (config) => {
|
|
|
85
85
|
});
|
|
86
86
|
return {
|
|
87
87
|
...sock,
|
|
88
|
+
communityQuery,
|
|
88
89
|
communityMetadata,
|
|
89
90
|
communityCreate: async (subject, body) => {
|
|
90
91
|
const descriptionId = generateMessageID().substring(0, 12);
|
|
@@ -428,4 +429,3 @@ export const extractCommunityMetadata = (result) => {
|
|
|
428
429
|
};
|
|
429
430
|
return metadata;
|
|
430
431
|
};
|
|
431
|
-
//# sourceMappingURL=communities.js.map
|
package/lib/Socket/groups.js
CHANGED
|
@@ -2,11 +2,55 @@ import { Boom } from '@hapi/boom';
|
|
|
2
2
|
import { proto } from '../../WAProto/index.js';
|
|
3
3
|
import { WAMessageAddressingMode, WAMessageStubType } from '../Types/index.js';
|
|
4
4
|
import { generateMessageIDV2, unixTimestampSeconds } from '../Utils/index.js';
|
|
5
|
-
import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString, isLidUser, isPnUser, jidEncode, jidNormalizedUser } from '../WABinary/index.js';
|
|
5
|
+
import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString, isJidGroup, isLidUser, isPnUser, jidEncode, jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
6
6
|
import { makeChatsSocket } from './chats.js';
|
|
7
|
+
|
|
8
|
+
export const buildReportNode = (jid, messageKeys = []) => ({
|
|
9
|
+
tag: 'spam_list',
|
|
10
|
+
attrs: {},
|
|
11
|
+
content: [{
|
|
12
|
+
tag: 'spam',
|
|
13
|
+
attrs: { jid },
|
|
14
|
+
content: messageKeys.map(key => {
|
|
15
|
+
if (!key?.id) {
|
|
16
|
+
throw new Boom('Every reported message key must include an id', { statusCode: 400 });
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
tag: 'message',
|
|
20
|
+
attrs: {
|
|
21
|
+
id: key.id,
|
|
22
|
+
...(key.fromMe !== undefined ? { from_me: key.fromMe ? 'true' : 'false' } : {}),
|
|
23
|
+
...(key.participant ? { participant: jidNormalizedUser(key.participant) } : {})
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
})
|
|
27
|
+
}]
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const buildGroupStatusRevokeMessage = (jid, key) => ({
|
|
31
|
+
groupStatusMessageV2: {
|
|
32
|
+
message: {
|
|
33
|
+
protocolMessage: {
|
|
34
|
+
key: {
|
|
35
|
+
remoteJid: jid,
|
|
36
|
+
fromMe: key.fromMe ?? true,
|
|
37
|
+
id: key.id,
|
|
38
|
+
...(key.participant ? { participant: jidNormalizedUser(key.participant) } : {})
|
|
39
|
+
},
|
|
40
|
+
type: proto.Message.ProtocolMessage.Type.REVOKE
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
7
46
|
export const makeGroupsSocket = (config) => {
|
|
8
47
|
const sock = makeChatsSocket(config);
|
|
9
|
-
const { authState, ev, query, upsertMessage } = sock;
|
|
48
|
+
const { authState, ev, query, relayMessage, updateBlockStatus, upsertMessage } = sock;
|
|
49
|
+
const reportJid = async (jid, messageKeys = []) => query({
|
|
50
|
+
tag: 'iq',
|
|
51
|
+
attrs: { type: 'set', xmlns: 'spam', to: S_WHATSAPP_NET },
|
|
52
|
+
content: [buildReportNode(jid, messageKeys)]
|
|
53
|
+
});
|
|
10
54
|
const groupQuery = async (jid, type, content) => query({
|
|
11
55
|
tag: 'iq',
|
|
12
56
|
attrs: {
|
|
@@ -16,9 +60,121 @@ export const makeGroupsSocket = (config) => {
|
|
|
16
60
|
},
|
|
17
61
|
content
|
|
18
62
|
});
|
|
63
|
+
const persistParticipantLidMappings = async (participantLists) => {
|
|
64
|
+
const pairs = [];
|
|
65
|
+
for (const participants of participantLists) {
|
|
66
|
+
for (const p of participants || []) {
|
|
67
|
+
if (p.phoneNumber)
|
|
68
|
+
pairs.push({ lid: p.id, pn: p.phoneNumber });
|
|
69
|
+
else if (p.lid)
|
|
70
|
+
pairs.push({ lid: p.lid, pn: p.id });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (!pairs.length)
|
|
74
|
+
return;
|
|
75
|
+
try {
|
|
76
|
+
await sock.signalRepository.lidMapping.storeLIDPNMappings(pairs);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
sock.logger?.warn?.({ error }, 'failed to store LID/PN mappings from group metadata');
|
|
80
|
+
}
|
|
81
|
+
};
|
|
19
82
|
const groupMetadata = async (jid) => {
|
|
20
83
|
const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
|
|
21
|
-
|
|
84
|
+
const metadata = extractGroupMetadata(result);
|
|
85
|
+
persistParticipantLidMappings([metadata.participants]).catch(() => { });
|
|
86
|
+
return metadata;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Acknowledge a group. Ported from WhatsApp Web's WASmaxGroupsAcknowledgeGroupRPC
|
|
90
|
+
* (`<iq to=jid xmlns=w:g2 type=set><ack/></iq>`).
|
|
91
|
+
*/
|
|
92
|
+
const groupAcknowledge = async (jid) => {
|
|
93
|
+
await groupQuery(jid, 'set', [{ tag: 'ack', attrs: {} }]);
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Get the participants of a community's linked/sub groups. Ported from
|
|
97
|
+
* WhatsApp Web's WASmaxGroupsGetLinkedGroupsParticipantsRPC.
|
|
98
|
+
* @returns {Promise<Array<{ jid: string, phoneNumber?: string }>>}
|
|
99
|
+
*/
|
|
100
|
+
const groupGetLinkedParticipants = async (jid) => {
|
|
101
|
+
const result = await groupQuery(jid, 'get', [{ tag: 'linked_groups_participants', attrs: {} }]);
|
|
102
|
+
const node = getBinaryNodeChild(result, 'linked_groups_participants');
|
|
103
|
+
return getBinaryNodeChildren(node, 'participant').map(p => ({
|
|
104
|
+
jid: p.attrs.jid,
|
|
105
|
+
phoneNumber: p.attrs.phone_number || p.attrs.pn || undefined
|
|
106
|
+
}));
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Join a community's linked/sub group (may raise a membership approval request).
|
|
110
|
+
* Ported from WhatsApp Web's WASmaxGroupsJoinLinkedGroupRPC.
|
|
111
|
+
* @param {string} parentJid community/parent group to address
|
|
112
|
+
* @param {string} linkedGroupJid linked/sub group to join
|
|
113
|
+
* @param {string} [type]
|
|
114
|
+
*/
|
|
115
|
+
const groupJoinLinked = async (parentJid, linkedGroupJid, type) => {
|
|
116
|
+
const result = await groupQuery(parentJid, 'set', [
|
|
117
|
+
{ tag: 'join_linked_group', attrs: { jid: linkedGroupJid, ...(type ? { type } : {}) } }
|
|
118
|
+
]);
|
|
119
|
+
return { approvalRequested: !!getBinaryNodeChild(result, 'membership_approval_request') };
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Batch-fetch group profile pictures via w:g2. Ported from WhatsApp Web's
|
|
123
|
+
* WASmaxGroupsGetGroupProfilePicturesRPC.
|
|
124
|
+
* @param {string[]} jids group jids
|
|
125
|
+
* @param {'preview' | 'image'} [type]
|
|
126
|
+
*/
|
|
127
|
+
const getGroupProfilePictures = async (jids, type = 'preview') => {
|
|
128
|
+
const result = await groupQuery(S_WHATSAPP_NET, 'get', [
|
|
129
|
+
{
|
|
130
|
+
tag: 'pictures',
|
|
131
|
+
attrs: {},
|
|
132
|
+
content: jids.map(id => ({ tag: 'picture', attrs: { id, type } }))
|
|
133
|
+
}
|
|
134
|
+
]);
|
|
135
|
+
return getBinaryNodeChildren(result, 'picture').map(pic => ({
|
|
136
|
+
jid: pic.attrs.id || pic.attrs.jid,
|
|
137
|
+
type: pic.attrs.type,
|
|
138
|
+
directPath: pic.attrs['direct_path'],
|
|
139
|
+
url: pic.attrs.url
|
|
140
|
+
}));
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Create a sub-group suggestion for a community. Ported from WhatsApp Web's
|
|
144
|
+
* WASmaxGroupsCreateSubGroupSuggestionRPC. The suggestion body (new vs existing
|
|
145
|
+
* groups) is caller-provided.
|
|
146
|
+
* @param {string} parentJid community/parent group to address
|
|
147
|
+
* @param {Array<{ tag: string, attrs?: object, content?: any }>} suggestion child node(s)
|
|
148
|
+
*/
|
|
149
|
+
const groupCreateSubGroupSuggestion = async (parentJid, suggestion) => {
|
|
150
|
+
await groupQuery(parentJid, 'set', [{ tag: 'sub_group_suggestion', attrs: {}, content: suggestion }]);
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Approve, reject, or cancel sub-group suggestions for a community. Ported from
|
|
154
|
+
* WhatsApp Web's WASmaxGroupsSubGroupSuggestionsActionRPC.
|
|
155
|
+
* approve/reject address suggestions by creator jid; cancel addresses them by
|
|
156
|
+
* the suggested group's jid.
|
|
157
|
+
* @param {string} parentJid community/parent group to address
|
|
158
|
+
* @param {'approve' | 'reject' | 'cancel'} action
|
|
159
|
+
* @param {Array<{ creator?: string, jid?: string }>} suggestions
|
|
160
|
+
*/
|
|
161
|
+
const groupSubGroupSuggestionsAction = async (parentJid, action, suggestions) => {
|
|
162
|
+
await groupQuery(parentJid, 'set', [
|
|
163
|
+
{
|
|
164
|
+
tag: 'sub_group_suggestions_action',
|
|
165
|
+
attrs: {},
|
|
166
|
+
content: [
|
|
167
|
+
{
|
|
168
|
+
tag: action,
|
|
169
|
+
attrs: {},
|
|
170
|
+
content: suggestions.map(s => ({
|
|
171
|
+
tag: 'sub_group_suggestion',
|
|
172
|
+
attrs: action === 'cancel' ? { jid: s.jid } : { creator: s.creator }
|
|
173
|
+
}))
|
|
174
|
+
}
|
|
175
|
+
]
|
|
176
|
+
}
|
|
177
|
+
]);
|
|
22
178
|
};
|
|
23
179
|
const groupFetchAllParticipating = async () => {
|
|
24
180
|
const result = await query({
|
|
@@ -66,7 +222,14 @@ export const makeGroupsSocket = (config) => {
|
|
|
66
222
|
});
|
|
67
223
|
return {
|
|
68
224
|
...sock,
|
|
225
|
+
groupQuery,
|
|
69
226
|
groupMetadata,
|
|
227
|
+
groupAcknowledge,
|
|
228
|
+
groupGetLinkedParticipants,
|
|
229
|
+
groupJoinLinked,
|
|
230
|
+
getGroupProfilePictures,
|
|
231
|
+
groupCreateSubGroupSuggestion,
|
|
232
|
+
groupSubGroupSuggestionsAction,
|
|
70
233
|
groupCreate: async (subject, participants) => {
|
|
71
234
|
const key = generateMessageIDV2();
|
|
72
235
|
const result = await groupQuery('@g.us', 'set', [
|
|
@@ -266,7 +429,47 @@ export const makeGroupsSocket = (config) => {
|
|
|
266
429
|
{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }
|
|
267
430
|
]);
|
|
268
431
|
},
|
|
269
|
-
groupFetchAllParticipating
|
|
432
|
+
groupFetchAllParticipating,
|
|
433
|
+
/** Report a contact to WhatsApp, then block it after the report succeeds. */
|
|
434
|
+
reportContact: async (jid, messageKeys = []) => {
|
|
435
|
+
const normalizedJid = jidNormalizedUser(jid);
|
|
436
|
+
if (!isPnUser(normalizedJid) && !isLidUser(normalizedJid)) {
|
|
437
|
+
throw new Boom('reportContact requires a valid contact JID', { statusCode: 400 });
|
|
438
|
+
}
|
|
439
|
+
const reportResult = await reportJid(normalizedJid, messageKeys);
|
|
440
|
+
await updateBlockStatus(normalizedJid, 'block');
|
|
441
|
+
return reportResult;
|
|
442
|
+
},
|
|
443
|
+
/** Report a group to WhatsApp, then leave it after the report succeeds. */
|
|
444
|
+
reportGroup: async (jid, messageKeys = []) => {
|
|
445
|
+
if (!isJidGroup(jid)) {
|
|
446
|
+
throw new Boom('reportGroup requires a valid group JID', { statusCode: 400 });
|
|
447
|
+
}
|
|
448
|
+
const reportResult = await reportJid(jid, messageKeys);
|
|
449
|
+
await groupQuery('@g.us', 'set', [{
|
|
450
|
+
tag: 'leave',
|
|
451
|
+
attrs: {},
|
|
452
|
+
content: [{ tag: 'group', attrs: { id: jid } }]
|
|
453
|
+
}]);
|
|
454
|
+
return reportResult;
|
|
455
|
+
},
|
|
456
|
+
/** Revoke a previously sent group status using its original message key. */
|
|
457
|
+
deleteGroupStatus: async (jid, key) => {
|
|
458
|
+
if (!isJidGroup(jid)) {
|
|
459
|
+
throw new Boom('deleteGroupStatus requires a valid group JID', { statusCode: 400 });
|
|
460
|
+
}
|
|
461
|
+
if (!key?.id) {
|
|
462
|
+
throw new Boom('deleteGroupStatus requires a message key with an id', { statusCode: 400 });
|
|
463
|
+
}
|
|
464
|
+
if (key.remoteJid && key.remoteJid !== jid) {
|
|
465
|
+
throw new Boom('The group status key does not belong to the target group', { statusCode: 400 });
|
|
466
|
+
}
|
|
467
|
+
return relayMessage(
|
|
468
|
+
jid,
|
|
469
|
+
buildGroupStatusRevokeMessage(jid, key),
|
|
470
|
+
{ messageId: generateMessageIDV2(authState.creds.me?.id) }
|
|
471
|
+
);
|
|
472
|
+
}
|
|
270
473
|
};
|
|
271
474
|
};
|
|
272
475
|
export const extractGroupMetadata = (result) => {
|
|
@@ -344,4 +547,3 @@ export const extractGroupMetadata = (result) => {
|
|
|
344
547
|
};
|
|
345
548
|
return metadata;
|
|
346
549
|
};
|
|
347
|
-
//# sourceMappingURL=groups.js.map
|
package/lib/Socket/index.js
CHANGED
|
@@ -1,12 +1,37 @@
|
|
|
1
1
|
import { DEFAULT_CONNECTION_CONFIG } from '../Defaults/index.js';
|
|
2
2
|
import { makeCommunitiesSocket } from './communities.js';
|
|
3
|
+
import { makeInteropSocket } from './interop.js';
|
|
4
|
+
import { makePrivacySocket } from './privacy.js';
|
|
5
|
+
import { makeRegistrationSocket } from './registration.js';
|
|
6
|
+
import { makeManagedAccountSocket } from './managed-account.js';
|
|
7
|
+
import { makeGraphQLSocket } from './graphql.js';
|
|
8
|
+
import { checkStatusWA } from './ban-checker.js';
|
|
9
|
+
|
|
3
10
|
// export the last socket layer
|
|
4
11
|
const makeWASocket = (config) => {
|
|
12
|
+
const userExplicitSyncFlag = typeof config?.syncFullHistory === 'boolean';
|
|
13
|
+
const initialFullSyncDone = !!config?.auth?.creds?.initialFullSyncDone;
|
|
14
|
+
const effectiveSyncFullHistory = userExplicitSyncFlag ? config.syncFullHistory : !initialFullSyncDone;
|
|
5
15
|
const newConfig = {
|
|
6
16
|
...DEFAULT_CONNECTION_CONFIG,
|
|
7
|
-
...config
|
|
17
|
+
...config,
|
|
18
|
+
syncFullHistory: effectiveSyncFullHistory
|
|
8
19
|
};
|
|
9
|
-
|
|
20
|
+
newConfig.logger?.debug?.(
|
|
21
|
+
{ initialFullSyncDone, effectiveSyncFullHistory, userExplicitSyncFlag },
|
|
22
|
+
'computed syncFullHistory policy'
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const baseSock = makeCommunitiesSocket(newConfig);
|
|
26
|
+
const interopSock = makeInteropSocket(baseSock);
|
|
27
|
+
const privacySock = makePrivacySocket(interopSock);
|
|
28
|
+
const registrationSock = makeRegistrationSocket(privacySock);
|
|
29
|
+
const managedSock = makeManagedAccountSocket(registrationSock);
|
|
30
|
+
const sock = makeGraphQLSocket(managedSock);
|
|
31
|
+
sock.checkStatusWA = checkStatusWA;
|
|
32
|
+
|
|
33
|
+
return sock;
|
|
10
34
|
};
|
|
35
|
+
|
|
36
|
+
export { checkStatusWA };
|
|
11
37
|
export default makeWASocket;
|
|
12
|
-
//# sourceMappingURL=index.js.map
|