@baileys-md/baileys 11.0.3 → 11.1.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/LICENSE +1 -1
- package/README.md +1 -1
- package/WAProto/index.js +4182 -13516
- package/WASignalGroup/GroupProtocol.js +1697 -0
- package/WASignalGroup/ciphertext_message.js +16 -0
- package/WASignalGroup/group_cipher.js +120 -0
- package/WASignalGroup/group_session_builder.js +46 -0
- package/WASignalGroup/index.js +5 -0
- package/WASignalGroup/keyhelper.js +21 -0
- package/WASignalGroup/protobufs.js +3 -0
- package/WASignalGroup/queue_job.js +69 -0
- package/WASignalGroup/sender_chain_key.js +50 -0
- package/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/WASignalGroup/sender_key_message.js +92 -0
- package/WASignalGroup/sender_key_name.js +70 -0
- package/WASignalGroup/sender_key_record.js +56 -0
- package/WASignalGroup/sender_key_state.js +129 -0
- package/{lib/Signal/Group/sender-message-key.js → WASignalGroup/sender_message_key.js} +16 -4
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.js +71 -52
- package/lib/Defaults/{phonenumber-mcc.js → phonenumber-mcc.json} +1 -1
- package/lib/Signal/libsignal.js +61 -41
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +19 -3
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.js +42 -37
- package/lib/Socket/chats.js +187 -194
- package/lib/Socket/groups.js +90 -87
- package/lib/Socket/index.js +8 -7
- package/lib/Socket/messages-recv.js +335 -360
- package/lib/Socket/messages-send.js +279 -156
- package/lib/Socket/newsletter.js +213 -144
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.js +161 -128
- package/lib/Socket/usync.js +26 -19
- package/lib/Store/index.js +8 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/{Utils → Store}/make-in-memory-store.js +27 -19
- package/lib/Store/make-mongo-store.js +567 -0
- package/lib/{Utils → Store}/make-ordered-dictionary.js +5 -2
- package/lib/{Utils → Store}/object-repository.js +4 -1
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +4 -8
- 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 +5 -3
- package/lib/Types/LabelAssociation.js +5 -3
- package/lib/Types/Message.js +7 -7
- package/lib/Types/Newsletter.js +17 -30
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +2 -2
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.js +47 -31
- package/lib/Utils/baileys-event-stream.js +22 -15
- package/lib/Utils/business.js +69 -66
- package/lib/Utils/chat-utils.js +195 -200
- package/lib/Utils/crypto.js +85 -70
- package/lib/Utils/decode-wa-message.js +51 -46
- package/lib/Utils/event-buffer.js +46 -36
- package/lib/Utils/generics.js +188 -116
- package/lib/Utils/history.js +46 -37
- package/lib/Utils/index.js +33 -19
- package/lib/Utils/link-preview.js +55 -14
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.js +26 -23
- package/lib/Utils/make-mutex.js +10 -7
- package/lib/Utils/messages-media.js +368 -239
- package/lib/Utils/messages.js +510 -278
- package/lib/Utils/noise-handler.js +31 -22
- package/lib/Utils/process-message.js +148 -144
- package/lib/Utils/signal.js +64 -71
- package/lib/Utils/use-multi-file-auth-state.js +32 -14
- package/lib/Utils/validate-connection.js +115 -72
- package/lib/WABinary/constants.js +20 -1281
- package/lib/WABinary/decode.js +52 -15
- package/lib/WABinary/encode.js +48 -14
- package/lib/WABinary/generic-utils.js +39 -31
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.js +40 -23
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.js +2366 -2257
- package/lib/WAM/encode.js +21 -17
- package/lib/WAM/index.js +19 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -8
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -9
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +6 -3
- package/lib/WAUSync/Protocols/index.js +20 -5
- package/lib/WAUSync/USyncQuery.js +32 -34
- package/lib/WAUSync/USyncUser.js +5 -2
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.js +33 -11
- package/package.json +61 -21
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/WAProto.proto +0 -4633
- package/WAProto/fix-imports.js +0 -29
- package/lib/Defaults/baileys-version.js +0 -1
- package/lib/Signal/Group/ciphertext-message.js +0 -12
- package/lib/Signal/Group/group-session-builder.js +0 -30
- package/lib/Signal/Group/group_cipher.js +0 -94
- package/lib/Signal/Group/index.js +0 -12
- package/lib/Signal/Group/keyhelper.js +0 -19
- package/lib/Signal/Group/queue-job.js +0 -54
- package/lib/Signal/Group/sender-chain-key.js +0 -32
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
- package/lib/Signal/Group/sender-key-message.js +0 -67
- package/lib/Signal/Group/sender-key-name.js +0 -48
- package/lib/Signal/Group/sender-key-record.js +0 -50
- package/lib/Signal/Group/sender-key-state.js +0 -96
- package/lib/Socket/Client/types.js +0 -11
- package/lib/Socket/Client/websocket.js +0 -50
- package/lib/Socket/communities.js +0 -351
- package/lib/Socket/mex.js +0 -42
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import WebSocket from 'ws';
|
|
2
|
-
import { DEFAULT_ORIGIN } from '../../Defaults/index.js';
|
|
3
|
-
import { AbstractSocketClient } from './types.js';
|
|
4
|
-
export class WebSocketClient extends AbstractSocketClient {
|
|
5
|
-
constructor() {
|
|
6
|
-
super(...arguments);
|
|
7
|
-
this.socket = null;
|
|
8
|
-
}
|
|
9
|
-
get isOpen() {
|
|
10
|
-
return this.socket?.readyState === WebSocket.OPEN;
|
|
11
|
-
}
|
|
12
|
-
get isClosed() {
|
|
13
|
-
return this.socket === null || this.socket?.readyState === WebSocket.CLOSED;
|
|
14
|
-
}
|
|
15
|
-
get isClosing() {
|
|
16
|
-
return this.socket === null || this.socket?.readyState === WebSocket.CLOSING;
|
|
17
|
-
}
|
|
18
|
-
get isConnecting() {
|
|
19
|
-
return this.socket?.readyState === WebSocket.CONNECTING;
|
|
20
|
-
}
|
|
21
|
-
async connect() {
|
|
22
|
-
if (this.socket) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
this.socket = new WebSocket(this.url, {
|
|
26
|
-
origin: DEFAULT_ORIGIN,
|
|
27
|
-
headers: this.config.options?.headers,
|
|
28
|
-
handshakeTimeout: this.config.connectTimeoutMs,
|
|
29
|
-
timeout: this.config.connectTimeoutMs,
|
|
30
|
-
agent: this.config.agent
|
|
31
|
-
});
|
|
32
|
-
this.socket.setMaxListeners(0);
|
|
33
|
-
const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response'];
|
|
34
|
-
for (const event of events) {
|
|
35
|
-
this.socket?.on(event, (...args) => this.emit(event, ...args));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
async close() {
|
|
39
|
-
if (!this.socket) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
this.socket.close();
|
|
43
|
-
this.socket = null;
|
|
44
|
-
}
|
|
45
|
-
send(str, cb) {
|
|
46
|
-
this.socket?.send(str, cb);
|
|
47
|
-
return Boolean(this.socket);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=websocket.js.map
|
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
import { proto } from '../../WAProto/index.js';
|
|
2
|
-
import { WAMessageStubType } from '../Types/index.js';
|
|
3
|
-
import { generateMessageID, generateMessageIDV2, unixTimestampSeconds } from '../Utils/index.js';
|
|
4
|
-
import logger from '../Utils/logger.js';
|
|
5
|
-
import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString, jidEncode, jidNormalizedUser } from '../WABinary/index.js';
|
|
6
|
-
import { makeBusinessSocket } from './business.js';
|
|
7
|
-
export const makeCommunitiesSocket = (config) => {
|
|
8
|
-
const sock = makeBusinessSocket(config);
|
|
9
|
-
const { authState, ev, query, upsertMessage } = sock;
|
|
10
|
-
const communityQuery = async (jid, type, content) => query({
|
|
11
|
-
tag: 'iq',
|
|
12
|
-
attrs: {
|
|
13
|
-
type,
|
|
14
|
-
xmlns: 'w:g2',
|
|
15
|
-
to: jid
|
|
16
|
-
},
|
|
17
|
-
content
|
|
18
|
-
});
|
|
19
|
-
const communityMetadata = async (jid) => {
|
|
20
|
-
const result = await communityQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
|
|
21
|
-
return extractCommunityMetadata(result);
|
|
22
|
-
};
|
|
23
|
-
const communityFetchAllParticipating = async () => {
|
|
24
|
-
const result = await query({
|
|
25
|
-
tag: 'iq',
|
|
26
|
-
attrs: {
|
|
27
|
-
to: '@g.us',
|
|
28
|
-
xmlns: 'w:g2',
|
|
29
|
-
type: 'get'
|
|
30
|
-
},
|
|
31
|
-
content: [
|
|
32
|
-
{
|
|
33
|
-
tag: 'participating',
|
|
34
|
-
attrs: {},
|
|
35
|
-
content: [
|
|
36
|
-
{ tag: 'participants', attrs: {} },
|
|
37
|
-
{ tag: 'description', attrs: {} }
|
|
38
|
-
]
|
|
39
|
-
}
|
|
40
|
-
]
|
|
41
|
-
});
|
|
42
|
-
const data = {};
|
|
43
|
-
const communitiesChild = getBinaryNodeChild(result, 'communities');
|
|
44
|
-
if (communitiesChild) {
|
|
45
|
-
const communities = getBinaryNodeChildren(communitiesChild, 'community');
|
|
46
|
-
for (const communityNode of communities) {
|
|
47
|
-
const meta = extractCommunityMetadata({
|
|
48
|
-
tag: 'result',
|
|
49
|
-
attrs: {},
|
|
50
|
-
content: [communityNode]
|
|
51
|
-
});
|
|
52
|
-
data[meta.id] = meta;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
sock.ev.emit('groups.update', Object.values(data));
|
|
56
|
-
return data;
|
|
57
|
-
};
|
|
58
|
-
async function parseGroupResult(node) {
|
|
59
|
-
logger.info({ node }, 'parseGroupResult');
|
|
60
|
-
const groupNode = getBinaryNodeChild(node, 'group');
|
|
61
|
-
if (groupNode) {
|
|
62
|
-
try {
|
|
63
|
-
logger.info({ groupNode }, 'groupNode');
|
|
64
|
-
const metadata = await sock.groupMetadata(`${groupNode.attrs.id}@g.us`);
|
|
65
|
-
return metadata ? metadata : Optional.empty();
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
console.error('Error parsing group metadata:', error);
|
|
69
|
-
return Optional.empty();
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return Optional.empty();
|
|
73
|
-
}
|
|
74
|
-
const Optional = {
|
|
75
|
-
empty: () => null,
|
|
76
|
-
of: (value) => (value !== null ? { value } : null)
|
|
77
|
-
};
|
|
78
|
-
sock.ws.on('CB:ib,,dirty', async (node) => {
|
|
79
|
-
const { attrs } = getBinaryNodeChild(node, 'dirty');
|
|
80
|
-
if (attrs.type !== 'communities') {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
await communityFetchAllParticipating();
|
|
84
|
-
await sock.cleanDirtyBits('groups');
|
|
85
|
-
});
|
|
86
|
-
return {
|
|
87
|
-
...sock,
|
|
88
|
-
communityMetadata,
|
|
89
|
-
communityCreate: async (subject, body) => {
|
|
90
|
-
const descriptionId = generateMessageID().substring(0, 12);
|
|
91
|
-
const result = await communityQuery('@g.us', 'set', [
|
|
92
|
-
{
|
|
93
|
-
tag: 'create',
|
|
94
|
-
attrs: { subject },
|
|
95
|
-
content: [
|
|
96
|
-
{
|
|
97
|
-
tag: 'description',
|
|
98
|
-
attrs: { id: descriptionId },
|
|
99
|
-
content: [
|
|
100
|
-
{
|
|
101
|
-
tag: 'body',
|
|
102
|
-
attrs: {},
|
|
103
|
-
content: Buffer.from(body || '', 'utf-8')
|
|
104
|
-
}
|
|
105
|
-
]
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
tag: 'parent',
|
|
109
|
-
attrs: { default_membership_approval_mode: 'request_required' }
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
tag: 'allow_non_admin_sub_group_creation',
|
|
113
|
-
attrs: {}
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
tag: 'create_general_chat',
|
|
117
|
-
attrs: {}
|
|
118
|
-
}
|
|
119
|
-
]
|
|
120
|
-
}
|
|
121
|
-
]);
|
|
122
|
-
return await parseGroupResult(result);
|
|
123
|
-
},
|
|
124
|
-
communityLeave: async (id) => {
|
|
125
|
-
await communityQuery('@g.us', 'set', [
|
|
126
|
-
{
|
|
127
|
-
tag: 'leave',
|
|
128
|
-
attrs: {},
|
|
129
|
-
content: [{ tag: 'community', attrs: { id } }]
|
|
130
|
-
}
|
|
131
|
-
]);
|
|
132
|
-
},
|
|
133
|
-
communityUpdateSubject: async (jid, subject) => {
|
|
134
|
-
await communityQuery(jid, 'set', [
|
|
135
|
-
{
|
|
136
|
-
tag: 'subject',
|
|
137
|
-
attrs: {},
|
|
138
|
-
content: Buffer.from(subject, 'utf-8')
|
|
139
|
-
}
|
|
140
|
-
]);
|
|
141
|
-
},
|
|
142
|
-
communityRequestParticipantsList: async (jid) => {
|
|
143
|
-
const result = await communityQuery(jid, 'get', [
|
|
144
|
-
{
|
|
145
|
-
tag: 'membership_approval_requests',
|
|
146
|
-
attrs: {}
|
|
147
|
-
}
|
|
148
|
-
]);
|
|
149
|
-
const node = getBinaryNodeChild(result, 'membership_approval_requests');
|
|
150
|
-
const participants = getBinaryNodeChildren(node, 'membership_approval_request');
|
|
151
|
-
return participants.map(v => v.attrs);
|
|
152
|
-
},
|
|
153
|
-
communityRequestParticipantsUpdate: async (jid, participants, action) => {
|
|
154
|
-
const result = await communityQuery(jid, 'set', [
|
|
155
|
-
{
|
|
156
|
-
tag: 'membership_requests_action',
|
|
157
|
-
attrs: {},
|
|
158
|
-
content: [
|
|
159
|
-
{
|
|
160
|
-
tag: action,
|
|
161
|
-
attrs: {},
|
|
162
|
-
content: participants.map(jid => ({
|
|
163
|
-
tag: 'participant',
|
|
164
|
-
attrs: { jid }
|
|
165
|
-
}))
|
|
166
|
-
}
|
|
167
|
-
]
|
|
168
|
-
}
|
|
169
|
-
]);
|
|
170
|
-
const node = getBinaryNodeChild(result, 'membership_requests_action');
|
|
171
|
-
const nodeAction = getBinaryNodeChild(node, action);
|
|
172
|
-
const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant');
|
|
173
|
-
return participantsAffected.map(p => {
|
|
174
|
-
return { status: p.attrs.error || '200', jid: p.attrs.jid };
|
|
175
|
-
});
|
|
176
|
-
},
|
|
177
|
-
communityParticipantsUpdate: async (jid, participants, action) => {
|
|
178
|
-
const result = await communityQuery(jid, 'set', [
|
|
179
|
-
{
|
|
180
|
-
tag: action,
|
|
181
|
-
attrs: {},
|
|
182
|
-
content: participants.map(jid => ({
|
|
183
|
-
tag: 'participant',
|
|
184
|
-
attrs: { jid }
|
|
185
|
-
}))
|
|
186
|
-
}
|
|
187
|
-
]);
|
|
188
|
-
const node = getBinaryNodeChild(result, action);
|
|
189
|
-
const participantsAffected = getBinaryNodeChildren(node, 'participant');
|
|
190
|
-
return participantsAffected.map(p => {
|
|
191
|
-
return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
|
|
192
|
-
});
|
|
193
|
-
},
|
|
194
|
-
communityUpdateDescription: async (jid, description) => {
|
|
195
|
-
const metadata = await communityMetadata(jid);
|
|
196
|
-
const prev = metadata.descId ?? null;
|
|
197
|
-
await communityQuery(jid, 'set', [
|
|
198
|
-
{
|
|
199
|
-
tag: 'description',
|
|
200
|
-
attrs: {
|
|
201
|
-
...(description ? { id: generateMessageID() } : { delete: 'true' }),
|
|
202
|
-
...(prev ? { prev } : {})
|
|
203
|
-
},
|
|
204
|
-
content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
|
|
205
|
-
}
|
|
206
|
-
]);
|
|
207
|
-
},
|
|
208
|
-
communityInviteCode: async (jid) => {
|
|
209
|
-
const result = await communityQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
|
|
210
|
-
const inviteNode = getBinaryNodeChild(result, 'invite');
|
|
211
|
-
return inviteNode?.attrs.code;
|
|
212
|
-
},
|
|
213
|
-
communityRevokeInvite: async (jid) => {
|
|
214
|
-
const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
|
|
215
|
-
const inviteNode = getBinaryNodeChild(result, 'invite');
|
|
216
|
-
return inviteNode?.attrs.code;
|
|
217
|
-
},
|
|
218
|
-
communityAcceptInvite: async (code) => {
|
|
219
|
-
const results = await communityQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
|
|
220
|
-
const result = getBinaryNodeChild(results, 'community');
|
|
221
|
-
return result?.attrs.jid;
|
|
222
|
-
},
|
|
223
|
-
/**
|
|
224
|
-
* revoke a v4 invite for someone
|
|
225
|
-
* @param communityJid community jid
|
|
226
|
-
* @param invitedJid jid of person you invited
|
|
227
|
-
* @returns true if successful
|
|
228
|
-
*/
|
|
229
|
-
communityRevokeInviteV4: async (communityJid, invitedJid) => {
|
|
230
|
-
const result = await communityQuery(communityJid, 'set', [
|
|
231
|
-
{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
|
|
232
|
-
]);
|
|
233
|
-
return !!result;
|
|
234
|
-
},
|
|
235
|
-
/**
|
|
236
|
-
* accept a CommunityInviteMessage
|
|
237
|
-
* @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
|
|
238
|
-
* @param inviteMessage the message to accept
|
|
239
|
-
*/
|
|
240
|
-
communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
241
|
-
key = typeof key === 'string' ? { remoteJid: key } : key;
|
|
242
|
-
const results = await communityQuery(inviteMessage.groupJid, 'set', [
|
|
243
|
-
{
|
|
244
|
-
tag: 'accept',
|
|
245
|
-
attrs: {
|
|
246
|
-
code: inviteMessage.inviteCode,
|
|
247
|
-
expiration: inviteMessage.inviteExpiration.toString(),
|
|
248
|
-
admin: key.remoteJid
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
]);
|
|
252
|
-
// if we have the full message key
|
|
253
|
-
// update the invite message to be expired
|
|
254
|
-
if (key.id) {
|
|
255
|
-
// create new invite message that is expired
|
|
256
|
-
inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage);
|
|
257
|
-
inviteMessage.inviteExpiration = 0;
|
|
258
|
-
inviteMessage.inviteCode = '';
|
|
259
|
-
ev.emit('messages.update', [
|
|
260
|
-
{
|
|
261
|
-
key,
|
|
262
|
-
update: {
|
|
263
|
-
message: {
|
|
264
|
-
groupInviteMessage: inviteMessage
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
]);
|
|
269
|
-
}
|
|
270
|
-
// generate the community add message
|
|
271
|
-
await upsertMessage({
|
|
272
|
-
key: {
|
|
273
|
-
remoteJid: inviteMessage.groupJid,
|
|
274
|
-
id: generateMessageIDV2(sock.user?.id),
|
|
275
|
-
fromMe: false,
|
|
276
|
-
participant: key.remoteJid
|
|
277
|
-
},
|
|
278
|
-
messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
|
|
279
|
-
messageStubParameters: [authState.creds.me.id],
|
|
280
|
-
participant: key.remoteJid,
|
|
281
|
-
messageTimestamp: unixTimestampSeconds()
|
|
282
|
-
}, 'notify');
|
|
283
|
-
return results.attrs.from;
|
|
284
|
-
}),
|
|
285
|
-
communityGetInviteInfo: async (code) => {
|
|
286
|
-
const results = await communityQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
|
|
287
|
-
return extractCommunityMetadata(results);
|
|
288
|
-
},
|
|
289
|
-
communityToggleEphemeral: async (jid, ephemeralExpiration) => {
|
|
290
|
-
const content = ephemeralExpiration
|
|
291
|
-
? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
|
|
292
|
-
: { tag: 'not_ephemeral', attrs: {} };
|
|
293
|
-
await communityQuery(jid, 'set', [content]);
|
|
294
|
-
},
|
|
295
|
-
communitySettingUpdate: async (jid, setting) => {
|
|
296
|
-
await communityQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
|
|
297
|
-
},
|
|
298
|
-
communityMemberAddMode: async (jid, mode) => {
|
|
299
|
-
await communityQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
|
|
300
|
-
},
|
|
301
|
-
communityJoinApprovalMode: async (jid, mode) => {
|
|
302
|
-
await communityQuery(jid, 'set', [
|
|
303
|
-
{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'community_join', attrs: { state: mode } }] }
|
|
304
|
-
]);
|
|
305
|
-
},
|
|
306
|
-
communityFetchAllParticipating
|
|
307
|
-
};
|
|
308
|
-
};
|
|
309
|
-
export const extractCommunityMetadata = (result) => {
|
|
310
|
-
const community = getBinaryNodeChild(result, 'community');
|
|
311
|
-
const descChild = getBinaryNodeChild(community, 'description');
|
|
312
|
-
let desc;
|
|
313
|
-
let descId;
|
|
314
|
-
if (descChild) {
|
|
315
|
-
desc = getBinaryNodeChildString(descChild, 'body');
|
|
316
|
-
descId = descChild.attrs.id;
|
|
317
|
-
}
|
|
318
|
-
const communityId = community.attrs.id?.includes('@')
|
|
319
|
-
? community.attrs.id
|
|
320
|
-
: jidEncode(community.attrs.id || '', 'g.us');
|
|
321
|
-
const eph = getBinaryNodeChild(community, 'ephemeral')?.attrs.expiration;
|
|
322
|
-
const memberAddMode = getBinaryNodeChildString(community, 'member_add_mode') === 'all_member_add';
|
|
323
|
-
const metadata = {
|
|
324
|
-
id: communityId,
|
|
325
|
-
subject: community.attrs.subject || '',
|
|
326
|
-
subjectOwner: community.attrs.s_o,
|
|
327
|
-
subjectTime: Number(community.attrs.s_t || 0),
|
|
328
|
-
size: getBinaryNodeChildren(community, 'participant').length,
|
|
329
|
-
creation: Number(community.attrs.creation || 0),
|
|
330
|
-
owner: community.attrs.creator ? jidNormalizedUser(community.attrs.creator) : undefined,
|
|
331
|
-
desc,
|
|
332
|
-
descId,
|
|
333
|
-
linkedParent: getBinaryNodeChild(community, 'linked_parent')?.attrs.jid || undefined,
|
|
334
|
-
restrict: !!getBinaryNodeChild(community, 'locked'),
|
|
335
|
-
announce: !!getBinaryNodeChild(community, 'announcement'),
|
|
336
|
-
isCommunity: !!getBinaryNodeChild(community, 'parent'),
|
|
337
|
-
isCommunityAnnounce: !!getBinaryNodeChild(community, 'default_sub_community'),
|
|
338
|
-
joinApprovalMode: !!getBinaryNodeChild(community, 'membership_approval_mode'),
|
|
339
|
-
memberAddMode,
|
|
340
|
-
participants: getBinaryNodeChildren(community, 'participant').map(({ attrs }) => {
|
|
341
|
-
return {
|
|
342
|
-
id: attrs.jid,
|
|
343
|
-
admin: (attrs.type || null)
|
|
344
|
-
};
|
|
345
|
-
}),
|
|
346
|
-
ephemeralDuration: eph ? +eph : undefined,
|
|
347
|
-
addressingMode: getBinaryNodeChildString(community, 'addressing_mode')
|
|
348
|
-
};
|
|
349
|
-
return metadata;
|
|
350
|
-
};
|
|
351
|
-
//# sourceMappingURL=communities.js.map
|
package/lib/Socket/mex.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Boom } from '@hapi/boom';
|
|
2
|
-
import { getBinaryNodeChild, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
3
|
-
const wMexQuery = (variables, queryId, query, generateMessageTag) => {
|
|
4
|
-
return query({
|
|
5
|
-
tag: 'iq',
|
|
6
|
-
attrs: {
|
|
7
|
-
id: generateMessageTag(),
|
|
8
|
-
type: 'get',
|
|
9
|
-
to: S_WHATSAPP_NET,
|
|
10
|
-
xmlns: 'w:mex'
|
|
11
|
-
},
|
|
12
|
-
content: [
|
|
13
|
-
{
|
|
14
|
-
tag: 'query',
|
|
15
|
-
attrs: { query_id: queryId },
|
|
16
|
-
content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
export const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
|
|
22
|
-
const result = await wMexQuery(variables, queryId, query, generateMessageTag);
|
|
23
|
-
const child = getBinaryNodeChild(result, 'result');
|
|
24
|
-
if (child?.content) {
|
|
25
|
-
const data = JSON.parse(child.content.toString());
|
|
26
|
-
if (data.errors && data.errors.length > 0) {
|
|
27
|
-
const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ');
|
|
28
|
-
const firstError = data.errors[0];
|
|
29
|
-
const errorCode = firstError.extensions?.error_code || 400;
|
|
30
|
-
throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError });
|
|
31
|
-
}
|
|
32
|
-
const response = dataPath ? data?.data?.[dataPath] : data?.data;
|
|
33
|
-
if (typeof response !== 'undefined') {
|
|
34
|
-
return response;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
const action = (dataPath || '').startsWith('xwa2_')
|
|
38
|
-
? dataPath.substring(5).replace(/_/g, ' ')
|
|
39
|
-
: dataPath?.replace(/_/g, ' ');
|
|
40
|
-
throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result });
|
|
41
|
-
};
|
|
42
|
-
//# sourceMappingURL=mex.js.map
|