@alannxd/baileys 6.0.6 → 6.0.9
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/LICENSE +1 -1
- package/README.md +341 -286
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +6902 -0
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.d.ts +79257 -0
- package/WAProto/index.js +205861 -60565
- package/engine-requirements.js +1 -1
- package/lib/Defaults/index.js +119 -136
- package/lib/Signal/Group/ciphertext-message.js +2 -5
- package/lib/Signal/Group/group-session-builder.js +7 -41
- package/lib/Signal/Group/group_cipher.js +37 -51
- package/lib/Signal/Group/index.js +12 -57
- package/lib/Signal/Group/keyhelper.js +7 -44
- package/lib/Signal/Group/sender-chain-key.js +7 -15
- package/lib/Signal/Group/sender-key-distribution-message.js +8 -11
- package/lib/Signal/Group/sender-key-message.js +9 -12
- package/lib/Signal/Group/sender-key-name.js +2 -5
- package/lib/Signal/Group/sender-key-record.js +9 -21
- package/lib/Signal/Group/sender-key-state.js +27 -42
- package/lib/Signal/Group/sender-message-key.js +4 -7
- package/lib/Signal/libsignal.js +347 -90
- package/lib/Signal/lid-mapping.js +277 -0
- package/lib/Socket/Client/index.js +3 -19
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/websocket.js +54 -0
- package/lib/Socket/business.js +162 -43
- package/lib/Socket/chats.js +627 -427
- package/lib/Socket/communities.js +90 -80
- package/lib/Socket/groups.js +154 -161
- package/lib/Socket/index.js +11 -10
- package/lib/Socket/luxu.js +315 -469
- package/lib/Socket/messages-recv.js +1421 -615
- package/lib/Socket/messages-send.js +1150 -799
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/newsletter.js +152 -204
- package/lib/Socket/socket.js +544 -313
- package/lib/Store/index.js +10 -10
- package/lib/Store/keyed-db.js +108 -0
- package/lib/Store/make-cache-manager-store.js +43 -41
- package/lib/Store/make-in-memory-store.js +112 -341
- package/lib/Store/make-ordered-dictionary.js +14 -20
- package/lib/Store/object-repository.js +11 -6
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +8 -4
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +3 -5
- package/lib/Types/LabelAssociation.js +3 -5
- package/lib/Types/Message.js +11 -9
- package/lib/Types/Mex.js +37 -0
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/State.js +56 -2
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +15 -31
- package/lib/Utils/auth-utils.js +239 -143
- package/lib/Utils/browser-utils.js +48 -0
- package/lib/Utils/business.js +66 -69
- package/lib/Utils/chat-utils.js +396 -253
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/crypto.js +57 -90
- package/lib/Utils/decode-wa-message.js +236 -84
- package/lib/Utils/event-buffer.js +185 -77
- package/lib/Utils/generics.js +189 -209
- package/lib/Utils/history.js +93 -55
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/index.js +23 -33
- package/lib/Utils/link-preview.js +16 -24
- package/lib/Utils/logger.js +3 -7
- package/lib/Utils/lt-hash.js +3 -46
- package/lib/Utils/make-mutex.js +24 -34
- package/lib/Utils/message-composer.js +273 -0
- package/lib/Utils/message-retry-manager.js +265 -0
- package/lib/Utils/messages-media.js +451 -482
- package/lib/Utils/messages.js +795 -369
- package/lib/Utils/noise-handler.js +145 -99
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/process-message.js +459 -150
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/signal.js +120 -72
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/tc-token-utils.js +163 -0
- package/lib/Utils/use-multi-file-auth-state.js +29 -27
- package/lib/Utils/validate-connection.js +73 -99
- package/lib/WABinary/constants.js +1281 -20
- package/lib/WABinary/decode.js +52 -42
- package/lib/WABinary/encode.js +110 -155
- package/lib/WABinary/generic-utils.js +55 -49
- package/lib/WABinary/index.js +6 -21
- package/lib/WABinary/jid-utils.js +76 -40
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +2 -5
- package/lib/WAM/constants.js +19071 -11568
- package/lib/WAM/encode.js +17 -22
- package/lib/WAM/index.js +4 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +33 -13
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -14
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -13
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -22
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +13 -8
- package/lib/WAUSync/Protocols/index.js +6 -20
- package/lib/WAUSync/USyncQuery.js +44 -35
- package/lib/WAUSync/USyncUser.js +10 -5
- package/lib/WAUSync/index.js +4 -19
- package/lib/index.js +13 -36
- package/package.json +85 -51
- package/WAProto/fix-import.js +0 -29
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/index.d.ts +0 -53
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- 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/queue-job.js +0 -57
- 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/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/index.d.ts +0 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.d.ts +0 -12
- package/lib/Socket/Client/web-socket-client.js +0 -62
- 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/groups.d.ts +0 -115
- package/lib/Socket/index.d.ts +0 -173
- package/lib/Socket/luxu.d.ts +0 -266
- 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/registration.js +0 -166
- package/lib/Socket/socket.d.ts +0 -44
- package/lib/Socket/usync.d.ts +0 -36
- package/lib/Socket/usync.js +0 -70
- 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/Newsletter.js +0 -38
- 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/baileys-event-stream.js +0 -63
- 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
package/lib/Socket/groups.js
CHANGED
|
@@ -1,91 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const WAUSync_1 = require("../WAUSync");
|
|
10
|
-
const makeGroupsSocket = (config) => {
|
|
11
|
-
const sock = (0, chats_1.makeChatsSocket)(config);
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { proto } from '../../WAProto/index.js';
|
|
3
|
+
import { WAMessageAddressingMode, WAMessageStubType } from '../Types/index.js';
|
|
4
|
+
import { generateMessageIDV2, unixTimestampSeconds } from '../Utils/index.js';
|
|
5
|
+
import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString, isLidUser, isPnUser, jidEncode, jidNormalizedUser } from '../WABinary/index.js';
|
|
6
|
+
import { makeChatsSocket } from './chats.js';
|
|
7
|
+
export const makeGroupsSocket = (config) => {
|
|
8
|
+
const sock = makeChatsSocket(config);
|
|
12
9
|
const { authState, ev, query, upsertMessage } = sock;
|
|
13
|
-
const groupQuery = async (jid, type, content) =>
|
|
10
|
+
const groupQuery = async (jid, type, content, xlmns) => query({
|
|
14
11
|
tag: 'iq',
|
|
15
12
|
attrs: {
|
|
16
13
|
type,
|
|
17
|
-
xmlns: 'w:g2',
|
|
18
|
-
to: jid
|
|
14
|
+
xmlns: xlmns ? xlmns : 'w:g2',
|
|
15
|
+
to: jid
|
|
19
16
|
},
|
|
20
17
|
content
|
|
21
|
-
})
|
|
18
|
+
});
|
|
22
19
|
const groupMetadata = async (jid) => {
|
|
23
20
|
const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
|
|
24
|
-
return
|
|
25
|
-
};
|
|
26
|
-
const sendMessageMembers = async (jid, message, { additionalNodes, additionalAttributes, batchSize = 250, getMetadata = true, participants: participantsInput = [] } = {}) => {
|
|
27
|
-
let participants = [];
|
|
28
|
-
if (getMetadata) {
|
|
29
|
-
const groupInfo = await groupMetadata(jid);
|
|
30
|
-
participants = groupInfo.participants.filter(p => p && (p.admin === null || typeof p.admin === 'undefined' || p.admin === false)).map(p => p.phoneNumber || p.id).filter(id => id && typeof id === 'string' && !id.includes('@lid'));
|
|
31
|
-
} else {
|
|
32
|
-
participants = participantsInput.filter(id => id && typeof id === 'string' && !id.includes('@lid'));
|
|
33
|
-
}
|
|
34
|
-
if (!participants.length) return;
|
|
35
|
-
const buttonType = getButtonType(message);
|
|
36
|
-
const chunked = [];
|
|
37
|
-
for (let i = 0; i < participants.length; i += batchSize) {
|
|
38
|
-
chunked.push(participants.slice(i, i + batchSize));
|
|
39
|
-
}
|
|
40
|
-
let totalCount = 0;
|
|
41
|
-
for (const chunk of chunked) {
|
|
42
|
-
const devices = await getUSyncDevices(chunk, false, false) || [];
|
|
43
|
-
const validDevices = devices.filter(j => {
|
|
44
|
-
const raw = j.device;
|
|
45
|
-
const d = typeof raw === 'string' ? parseInt(raw, 10) : raw;
|
|
46
|
-
return j.user && (d == null || (Number.isInteger(d) && d >= 0 && d < 99));
|
|
47
|
-
});
|
|
48
|
-
const mappedDevices = validDevices.map(j => {
|
|
49
|
-
const raw = j.device;
|
|
50
|
-
const d = typeof raw === 'string' ? parseInt(raw, 10) : raw;
|
|
51
|
-
return (d == null || d === 0) ? `${j.user}@s.whatsapp.net` : `${j.user}:${d}@s.whatsapp.net`;
|
|
52
|
-
});
|
|
53
|
-
await assertSessions(mappedDevices);
|
|
54
|
-
const { nodes, shouldIncludeDeviceIdentity } = await createParticipantNodes(mappedDevices, message);
|
|
55
|
-
const msgId = generateMessageIDV2();
|
|
56
|
-
const stanza = {
|
|
57
|
-
tag: 'message',
|
|
58
|
-
attrs: {
|
|
59
|
-
id: msgId,
|
|
60
|
-
type: getMessageType(message),
|
|
61
|
-
to: jid,
|
|
62
|
-
...(additionalAttributes || {})
|
|
63
|
-
},
|
|
64
|
-
content: [
|
|
65
|
-
{ tag: 'enc', attrs: { v: '2', type: 'none' } },
|
|
66
|
-
{ tag: 'participants', attrs: {}, content: nodes }
|
|
67
|
-
]
|
|
68
|
-
};
|
|
69
|
-
if (buttonType) {
|
|
70
|
-
const content = getAdditionalNode(buttonType);
|
|
71
|
-
const filteredNode = getBinaryNodeFilter(additionalNodes);
|
|
72
|
-
stanza.content.push(...(filteredNode ? additionalNodes : content));
|
|
73
|
-
}
|
|
74
|
-
if (additionalNodes?.length) {
|
|
75
|
-
stanza.content.push(...additionalNodes);
|
|
76
|
-
}
|
|
77
|
-
if (shouldIncludeDeviceIdentity) {
|
|
78
|
-
stanza.content.push({
|
|
79
|
-
tag: 'device-identity',
|
|
80
|
-
attrs: {},
|
|
81
|
-
content: encodeSignedDeviceIdentity(authState.creds.account, true)
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
const res = await query(stanza);
|
|
85
|
-
const count = Number(res?.attrs?.count || 0);
|
|
86
|
-
totalCount += count;
|
|
87
|
-
}
|
|
88
|
-
return totalCount
|
|
21
|
+
return extractGroupMetadata(result);
|
|
89
22
|
};
|
|
90
23
|
const groupFetchAllParticipating = async () => {
|
|
91
24
|
const result = await query({
|
|
@@ -93,7 +26,7 @@ const makeGroupsSocket = (config) => {
|
|
|
93
26
|
attrs: {
|
|
94
27
|
to: '@g.us',
|
|
95
28
|
xmlns: 'w:g2',
|
|
96
|
-
type: 'get'
|
|
29
|
+
type: 'get'
|
|
97
30
|
},
|
|
98
31
|
content: [
|
|
99
32
|
{
|
|
@@ -107,11 +40,11 @@ const makeGroupsSocket = (config) => {
|
|
|
107
40
|
]
|
|
108
41
|
});
|
|
109
42
|
const data = {};
|
|
110
|
-
const groupsChild =
|
|
43
|
+
const groupsChild = getBinaryNodeChild(result, 'groups');
|
|
111
44
|
if (groupsChild) {
|
|
112
|
-
const groups =
|
|
45
|
+
const groups = getBinaryNodeChildren(groupsChild, 'group');
|
|
113
46
|
for (const groupNode of groups) {
|
|
114
|
-
const meta =
|
|
47
|
+
const meta = extractGroupMetadata({
|
|
115
48
|
tag: 'result',
|
|
116
49
|
attrs: {},
|
|
117
50
|
content: [groupNode]
|
|
@@ -119,11 +52,12 @@ const makeGroupsSocket = (config) => {
|
|
|
119
52
|
data[meta.id] = meta;
|
|
120
53
|
}
|
|
121
54
|
}
|
|
55
|
+
// TODO: properly parse LID / PN DATA
|
|
122
56
|
sock.ev.emit('groups.update', Object.values(data));
|
|
123
57
|
return data;
|
|
124
58
|
};
|
|
125
59
|
sock.ws.on('CB:ib,,dirty', async (node) => {
|
|
126
|
-
const { attrs } =
|
|
60
|
+
const { attrs } = getBinaryNodeChild(node, 'dirty');
|
|
127
61
|
if (attrs.type !== 'groups') {
|
|
128
62
|
return;
|
|
129
63
|
}
|
|
@@ -134,7 +68,7 @@ const makeGroupsSocket = (config) => {
|
|
|
134
68
|
...sock,
|
|
135
69
|
groupMetadata,
|
|
136
70
|
groupCreate: async (subject, participants) => {
|
|
137
|
-
const key = (
|
|
71
|
+
const key = generateMessageIDV2();
|
|
138
72
|
const result = await groupQuery('@g.us', 'set', [
|
|
139
73
|
{
|
|
140
74
|
tag: 'create',
|
|
@@ -148,16 +82,14 @@ const makeGroupsSocket = (config) => {
|
|
|
148
82
|
}))
|
|
149
83
|
}
|
|
150
84
|
]);
|
|
151
|
-
return
|
|
85
|
+
return extractGroupMetadata(result);
|
|
152
86
|
},
|
|
153
87
|
groupLeave: async (id) => {
|
|
154
88
|
await groupQuery('@g.us', 'set', [
|
|
155
89
|
{
|
|
156
90
|
tag: 'leave',
|
|
157
91
|
attrs: {},
|
|
158
|
-
content: [
|
|
159
|
-
{ tag: 'group', attrs: { id } }
|
|
160
|
-
]
|
|
92
|
+
content: [{ tag: 'group', attrs: { id } }]
|
|
161
93
|
}
|
|
162
94
|
]);
|
|
163
95
|
},
|
|
@@ -177,12 +109,13 @@ const makeGroupsSocket = (config) => {
|
|
|
177
109
|
attrs: {}
|
|
178
110
|
}
|
|
179
111
|
]);
|
|
180
|
-
const node =
|
|
181
|
-
const participants =
|
|
112
|
+
const node = getBinaryNodeChild(result, 'membership_approval_requests');
|
|
113
|
+
const participants = getBinaryNodeChildren(node, 'membership_approval_request');
|
|
182
114
|
return participants.map(v => v.attrs);
|
|
183
115
|
},
|
|
184
116
|
groupRequestParticipantsUpdate: async (jid, participants, action) => {
|
|
185
|
-
const result = await groupQuery(jid, 'set', [
|
|
117
|
+
const result = await groupQuery(jid, 'set', [
|
|
118
|
+
{
|
|
186
119
|
tag: 'membership_requests_action',
|
|
187
120
|
attrs: {},
|
|
188
121
|
content: [
|
|
@@ -195,10 +128,11 @@ const makeGroupsSocket = (config) => {
|
|
|
195
128
|
}))
|
|
196
129
|
}
|
|
197
130
|
]
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
const
|
|
131
|
+
}
|
|
132
|
+
]);
|
|
133
|
+
const node = getBinaryNodeChild(result, 'membership_requests_action');
|
|
134
|
+
const nodeAction = getBinaryNodeChild(node, action);
|
|
135
|
+
const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant');
|
|
202
136
|
return participantsAffected.map(p => {
|
|
203
137
|
return { status: p.attrs.error || '200', jid: p.attrs.jid };
|
|
204
138
|
});
|
|
@@ -214,43 +148,52 @@ const makeGroupsSocket = (config) => {
|
|
|
214
148
|
}))
|
|
215
149
|
}
|
|
216
150
|
]);
|
|
217
|
-
const node =
|
|
218
|
-
const participantsAffected =
|
|
151
|
+
const node = getBinaryNodeChild(result, action);
|
|
152
|
+
const participantsAffected = getBinaryNodeChildren(node, 'participant');
|
|
219
153
|
return participantsAffected.map(p => {
|
|
220
154
|
return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
|
|
221
155
|
});
|
|
222
156
|
},
|
|
223
157
|
groupUpdateDescription: async (jid, description) => {
|
|
224
|
-
var _a;
|
|
225
158
|
const metadata = await groupMetadata(jid);
|
|
226
|
-
const prev =
|
|
159
|
+
const prev = metadata.descId ?? null;
|
|
227
160
|
await groupQuery(jid, 'set', [
|
|
228
161
|
{
|
|
229
162
|
tag: 'description',
|
|
230
163
|
attrs: {
|
|
231
|
-
...(description ? { id: (
|
|
164
|
+
...(description ? { id: generateMessageIDV2() } : { delete: 'true' }),
|
|
232
165
|
...(prev ? { prev } : {})
|
|
233
166
|
},
|
|
234
|
-
content: description ? [
|
|
235
|
-
{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }
|
|
236
|
-
] : undefined
|
|
167
|
+
content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
|
|
237
168
|
}
|
|
238
169
|
]);
|
|
239
170
|
},
|
|
240
171
|
groupInviteCode: async (jid) => {
|
|
241
172
|
const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
|
|
242
|
-
const inviteNode =
|
|
243
|
-
return inviteNode
|
|
173
|
+
const inviteNode = getBinaryNodeChild(result, 'invite');
|
|
174
|
+
return inviteNode?.attrs.code;
|
|
244
175
|
},
|
|
245
176
|
groupRevokeInvite: async (jid) => {
|
|
246
177
|
const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
|
|
247
|
-
const inviteNode =
|
|
248
|
-
return inviteNode
|
|
178
|
+
const inviteNode = getBinaryNodeChild(result, 'invite');
|
|
179
|
+
return inviteNode?.attrs.code;
|
|
249
180
|
},
|
|
250
181
|
groupAcceptInvite: async (code) => {
|
|
251
182
|
const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
|
|
252
|
-
const result =
|
|
253
|
-
return result
|
|
183
|
+
const result = getBinaryNodeChild(results, 'group');
|
|
184
|
+
return result?.attrs.jid;
|
|
185
|
+
},
|
|
186
|
+
/**
|
|
187
|
+
* revoke a v4 invite for someone
|
|
188
|
+
* @param groupJid group jid
|
|
189
|
+
* @param invitedJid jid of person you invited
|
|
190
|
+
* @returns true if successful
|
|
191
|
+
*/
|
|
192
|
+
groupRevokeInviteV4: async (groupJid, invitedJid) => {
|
|
193
|
+
const result = await groupQuery(groupJid, 'set', [
|
|
194
|
+
{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
|
|
195
|
+
]);
|
|
196
|
+
return !!result;
|
|
254
197
|
},
|
|
255
198
|
/**
|
|
256
199
|
* accept a GroupInviteMessage
|
|
@@ -259,19 +202,21 @@ const makeGroupsSocket = (config) => {
|
|
|
259
202
|
*/
|
|
260
203
|
groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
261
204
|
key = typeof key === 'string' ? { remoteJid: key } : key;
|
|
262
|
-
const results = await groupQuery(inviteMessage.groupJid, 'set', [
|
|
205
|
+
const results = await groupQuery(inviteMessage.groupJid, 'set', [
|
|
206
|
+
{
|
|
263
207
|
tag: 'accept',
|
|
264
208
|
attrs: {
|
|
265
209
|
code: inviteMessage.inviteCode,
|
|
266
210
|
expiration: inviteMessage.inviteExpiration.toString(),
|
|
267
211
|
admin: key.remoteJid
|
|
268
212
|
}
|
|
269
|
-
}
|
|
213
|
+
}
|
|
214
|
+
]);
|
|
270
215
|
// if we have the full message key
|
|
271
216
|
// update the invite message to be expired
|
|
272
217
|
if (key.id) {
|
|
273
218
|
// create new invite message that is expired
|
|
274
|
-
inviteMessage =
|
|
219
|
+
inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage);
|
|
275
220
|
inviteMessage.inviteExpiration = 0;
|
|
276
221
|
inviteMessage.inviteCode = '';
|
|
277
222
|
ev.emit('messages.update', [
|
|
@@ -289,27 +234,25 @@ const makeGroupsSocket = (config) => {
|
|
|
289
234
|
await upsertMessage({
|
|
290
235
|
key: {
|
|
291
236
|
remoteJid: inviteMessage.groupJid,
|
|
292
|
-
id: (
|
|
237
|
+
id: generateMessageIDV2(sock.user?.id),
|
|
293
238
|
fromMe: false,
|
|
294
|
-
participant: key.remoteJid
|
|
239
|
+
participant: key.remoteJid
|
|
295
240
|
},
|
|
296
|
-
messageStubType:
|
|
297
|
-
messageStubParameters: [
|
|
298
|
-
authState.creds.me.id
|
|
299
|
-
],
|
|
241
|
+
messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
|
|
242
|
+
messageStubParameters: [JSON.stringify(authState.creds.me)],
|
|
300
243
|
participant: key.remoteJid,
|
|
301
|
-
messageTimestamp:
|
|
244
|
+
messageTimestamp: unixTimestampSeconds()
|
|
302
245
|
}, 'notify');
|
|
303
246
|
return results.attrs.from;
|
|
304
247
|
}),
|
|
305
248
|
groupGetInviteInfo: async (code) => {
|
|
306
249
|
const results = await groupQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
|
|
307
|
-
return
|
|
250
|
+
return extractGroupMetadata(results);
|
|
308
251
|
},
|
|
309
252
|
groupToggleEphemeral: async (jid, ephemeralExpiration) => {
|
|
310
|
-
const content = ephemeralExpiration
|
|
311
|
-
{ tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
|
|
312
|
-
{ tag: 'not_ephemeral', attrs: {} };
|
|
253
|
+
const content = ephemeralExpiration
|
|
254
|
+
? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
|
|
255
|
+
: { tag: 'not_ephemeral', attrs: {} };
|
|
313
256
|
await groupQuery(jid, 'set', [content]);
|
|
314
257
|
},
|
|
315
258
|
groupSettingUpdate: async (jid, setting) => {
|
|
@@ -319,63 +262,113 @@ const makeGroupsSocket = (config) => {
|
|
|
319
262
|
await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
|
|
320
263
|
},
|
|
321
264
|
groupJoinApprovalMode: async (jid, mode) => {
|
|
322
|
-
await groupQuery(jid, 'set', [
|
|
265
|
+
await groupQuery(jid, 'set', [
|
|
266
|
+
{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }
|
|
267
|
+
]);
|
|
268
|
+
},
|
|
269
|
+
groupToggleHistory: async (jid, enable = true) => {
|
|
270
|
+
const result = await query({
|
|
271
|
+
tag: "iq",
|
|
272
|
+
attrs: {
|
|
273
|
+
type: "get",
|
|
274
|
+
to: "s.whatsapp.net",
|
|
275
|
+
xmlns: "w:mex"
|
|
276
|
+
},
|
|
277
|
+
content: [
|
|
278
|
+
{
|
|
279
|
+
tag: "query",
|
|
280
|
+
attrs: {
|
|
281
|
+
query_id: "24688994337458819"
|
|
282
|
+
},
|
|
283
|
+
content: Buffer.from(JSON.stringify({
|
|
284
|
+
variables: {
|
|
285
|
+
group_id: jid,
|
|
286
|
+
input: {
|
|
287
|
+
member_share_group_history_mode: enable ? "ALL_MEMBER_SHARE" : "ADMIN_SHARE"
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}), "utf-8")
|
|
291
|
+
}
|
|
292
|
+
]
|
|
293
|
+
});
|
|
294
|
+
return result;
|
|
323
295
|
},
|
|
324
296
|
groupFetchAllParticipating
|
|
325
297
|
};
|
|
326
298
|
};
|
|
327
|
-
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
299
|
+
export const extractGroupMetadata = (result) => {
|
|
300
|
+
const group = getBinaryNodeChild(result, 'group');
|
|
301
|
+
if (!group) {
|
|
302
|
+
// Mirror WAWeb: surface server/client errors with their code+text instead of crashing.
|
|
303
|
+
const errorNode = getBinaryNodeChild(result, 'error');
|
|
304
|
+
if (errorNode) {
|
|
305
|
+
const code = errorNode.attrs.code ? +errorNode.attrs.code : 500;
|
|
306
|
+
const text = errorNode.attrs.text || 'group metadata query failed';
|
|
307
|
+
throw new Boom(text, { statusCode: code, data: errorNode });
|
|
308
|
+
}
|
|
309
|
+
throw new Boom('Invalid group metadata response: missing <group> node', { data: result });
|
|
310
|
+
}
|
|
311
|
+
if (!group.attrs.id) {
|
|
312
|
+
throw new Boom('Invalid group metadata response: missing group id', { data: group });
|
|
313
|
+
}
|
|
314
|
+
const descChild = getBinaryNodeChild(group, 'description');
|
|
332
315
|
let desc;
|
|
333
316
|
let descId;
|
|
334
317
|
let descOwner;
|
|
335
|
-
let
|
|
318
|
+
let descOwnerPn;
|
|
319
|
+
let descOwnerUsername;
|
|
336
320
|
let descTime;
|
|
337
321
|
if (descChild) {
|
|
338
|
-
desc =
|
|
339
|
-
descOwner =
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
322
|
+
desc = getBinaryNodeChildString(descChild, 'body');
|
|
323
|
+
descOwner = descChild.attrs.participant ? jidNormalizedUser(descChild.attrs.participant) : undefined;
|
|
324
|
+
descOwnerPn = descChild.attrs.participant_pn ? jidNormalizedUser(descChild.attrs.participant_pn) : undefined;
|
|
325
|
+
descOwnerUsername = descChild.attrs.participant_username || undefined;
|
|
326
|
+
descTime = +descChild.attrs.t;
|
|
343
327
|
descId = descChild.attrs.id;
|
|
344
|
-
descTime = descChild.attrs.t ? +descChild.attrs.t : undefined;
|
|
345
328
|
}
|
|
346
|
-
const
|
|
347
|
-
const
|
|
348
|
-
const
|
|
349
|
-
const memberAddMode = WABinary_1.getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add';
|
|
329
|
+
const groupId = group.attrs.id.includes('@') ? group.attrs.id : jidEncode(group.attrs.id, 'g.us');
|
|
330
|
+
const eph = getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration;
|
|
331
|
+
const memberAddMode = getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add';
|
|
350
332
|
const metadata = {
|
|
351
333
|
id: groupId,
|
|
352
|
-
|
|
334
|
+
notify: group.attrs.notify,
|
|
335
|
+
addressingMode: group.attrs.addressing_mode === 'lid' ? WAMessageAddressingMode.LID : WAMessageAddressingMode.PN,
|
|
353
336
|
subject: group.attrs.subject,
|
|
354
|
-
subjectOwner:
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
337
|
+
subjectOwner: group.attrs.s_o,
|
|
338
|
+
subjectOwnerPn: group.attrs.s_o_pn,
|
|
339
|
+
subjectOwnerUsername: group.attrs.s_o_username,
|
|
340
|
+
subjectTime: +group.attrs.s_t,
|
|
341
|
+
size: group.attrs.size ? +group.attrs.size : getBinaryNodeChildren(group, 'participant').length,
|
|
342
|
+
creation: +group.attrs.creation,
|
|
343
|
+
owner: group.attrs.creator ? jidNormalizedUser(group.attrs.creator) : undefined,
|
|
344
|
+
ownerPn: group.attrs.creator_pn ? jidNormalizedUser(group.attrs.creator_pn) : undefined,
|
|
345
|
+
ownerUsername: group.attrs.creator_username || undefined,
|
|
346
|
+
owner_country_code: group.attrs.creator_country_code,
|
|
347
|
+
desc,
|
|
348
|
+
descId,
|
|
361
349
|
descOwner,
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
350
|
+
descOwnerPn,
|
|
351
|
+
descOwnerUsername,
|
|
352
|
+
descTime,
|
|
353
|
+
linkedParent: getBinaryNodeChild(group, 'linked_parent')?.attrs.jid || undefined,
|
|
354
|
+
restrict: !!getBinaryNodeChild(group, 'locked'),
|
|
355
|
+
announce: !!getBinaryNodeChild(group, 'announcement'),
|
|
356
|
+
isCommunity: !!getBinaryNodeChild(group, 'parent'),
|
|
357
|
+
isCommunityAnnounce: !!getBinaryNodeChild(group, 'default_sub_group'),
|
|
358
|
+
joinApprovalMode: !!getBinaryNodeChild(group, 'membership_approval_mode'),
|
|
368
359
|
memberAddMode,
|
|
369
|
-
participants:
|
|
360
|
+
participants: getBinaryNodeChildren(group, 'participant').map(({ attrs }) => {
|
|
361
|
+
// TODO: Store LID MAPPINGS
|
|
370
362
|
return {
|
|
371
363
|
id: attrs.jid,
|
|
372
|
-
|
|
373
|
-
|
|
364
|
+
phoneNumber: isLidUser(attrs.jid) && isPnUser(attrs.phone_number) ? attrs.phone_number : undefined,
|
|
365
|
+
lid: isPnUser(attrs.jid) && isLidUser(attrs.lid) ? attrs.lid : undefined,
|
|
366
|
+
username: attrs.participant_username || attrs.username || undefined,
|
|
367
|
+
admin: (attrs.type || null)
|
|
374
368
|
};
|
|
375
369
|
}),
|
|
376
370
|
ephemeralDuration: eph ? +eph : undefined
|
|
377
371
|
};
|
|
378
372
|
return metadata;
|
|
379
373
|
};
|
|
380
|
-
|
|
381
|
-
|
|
374
|
+
//# sourceMappingURL=groups.js.map
|
package/lib/Socket/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const Defaults_1 = require("../Defaults");
|
|
4
|
-
const registration_1 = require("./registration");
|
|
1
|
+
import { DEFAULT_CONNECTION_CONFIG } from '../Defaults/index.js';
|
|
2
|
+
import { makeCommunitiesSocket } from './communities.js';
|
|
5
3
|
// export the last socket layer
|
|
6
|
-
const makeWASocket = (config) =>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
const makeWASocket = (config) => {
|
|
5
|
+
const newConfig = {
|
|
6
|
+
...DEFAULT_CONNECTION_CONFIG,
|
|
7
|
+
...config
|
|
8
|
+
};
|
|
9
|
+
return makeCommunitiesSocket(newConfig);
|
|
10
|
+
};
|
|
11
|
+
export default makeWASocket;
|
|
12
|
+
//# sourceMappingURL=index.js.map
|