@mrlegendbot/baileys 1.2.1 → 1.2.4
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.upstream.md +1312 -0
- package/WAProto/WAProto.json +1 -0
- package/WAProto/WAProto.proto +6275 -0
- package/WAProto/compiler.js +550 -0
- package/WAProto/index.js +2 -97691
- package/lib/Defaults/index.js +89 -92
- package/lib/Signal/Group/ciphertext-message.js +9 -10
- package/lib/Signal/Group/group-session-builder.js +21 -22
- package/lib/Signal/Group/group_cipher.js +75 -69
- package/lib/Signal/Group/index.js +0 -1
- package/lib/Signal/Group/keyhelper.js +9 -10
- package/lib/Signal/Group/sender-chain-key.js +21 -22
- package/lib/Signal/Group/sender-key-distribution-message.js +51 -60
- package/lib/Signal/Group/sender-key-message.js +56 -62
- package/lib/Signal/Group/sender-key-name.js +38 -40
- package/lib/Signal/Group/sender-key-record.js +33 -34
- package/lib/Signal/Group/sender-key-state.js +72 -76
- package/lib/Signal/Group/sender-message-key.js +22 -23
- package/lib/Signal/libsignal.js +506 -405
- package/lib/Signal/lid-mapping.js +276 -258
- package/lib/Socket/Client/index.js +0 -1
- package/lib/Socket/Client/types.js +6 -7
- package/lib/Socket/Client/websocket.js +48 -49
- package/lib/Socket/business.js +349 -369
- package/lib/Socket/chats.js +1172 -1148
- package/lib/Socket/communities.js +473 -413
- package/lib/Socket/groups.js +387 -331
- package/lib/Socket/index.js +6 -8
- package/lib/Socket/messages-recv.js +1782 -1719
- package/lib/Socket/messages-send.js +1503 -2450
- package/lib/Socket/mex.js +40 -35
- package/lib/Socket/newsletter.js +239 -191
- package/lib/Socket/socket.js +992 -923
- package/lib/Store/index.js +8 -0
- package/lib/Store/keyed-db.js +108 -0
- package/lib/Store/make-cache-manager-store.js +70 -0
- package/lib/Store/make-in-memory-store.js +417 -0
- package/lib/Store/make-ordered-dictionary.js +69 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.js +0 -1
- package/lib/Types/Bussines.js +0 -1
- package/lib/Types/Call.js +0 -1
- package/lib/Types/Chat.js +1 -8
- package/lib/Types/Contact.js +0 -1
- package/lib/Types/Events.js +1 -2
- package/lib/Types/GroupMetadata.js +0 -1
- package/lib/Types/Label.js +20 -22
- package/lib/Types/LabelAssociation.js +2 -4
- package/lib/Types/Message.js +3 -5
- package/lib/Types/Mex.js +26 -31
- package/lib/Types/Product.js +0 -1
- package/lib/Types/Signal.js +1 -2
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +4 -52
- package/lib/Types/USync.js +0 -1
- package/lib/Types/index.js +10 -11
- package/lib/Utils/auth-utils.js +240 -277
- package/lib/Utils/browser-utils.js +20 -23
- package/lib/Utils/business.js +200 -204
- package/lib/Utils/chat-utils.js +836 -810
- package/lib/Utils/companion-reg-client-utils.js +23 -25
- package/lib/Utils/crypto.js +70 -86
- package/lib/Utils/decode-wa-message.js +277 -284
- package/lib/Utils/event-buffer.js +592 -595
- package/lib/Utils/generics.js +312 -335
- package/lib/Utils/history.js +123 -115
- package/lib/Utils/index.js +1 -2
- package/lib/Utils/link-preview.js +74 -73
- package/lib/Utils/logger.js +3 -2
- package/lib/Utils/lt-hash.js +0 -6
- package/lib/Utils/make-mutex.js +27 -27
- package/lib/Utils/message-retry-manager.js +213 -254
- package/lib/Utils/messages-media.js +741 -715
- package/lib/Utils/messages.js +791 -827
- package/lib/Utils/noise-handler.js +215 -187
- package/lib/Utils/pre-key-manager.js +69 -98
- package/lib/Utils/process-message.js +617 -586
- package/lib/Utils/reporting-utils.js +553 -234
- package/lib/Utils/signal.js +217 -170
- package/lib/Utils/stanza-ack.js +27 -35
- package/lib/Utils/sync-action-utils.js +37 -41
- package/lib/Utils/tc-token-utils.js +120 -141
- package/lib/Utils/use-multi-file-auth-state.js +87 -105
- package/lib/Utils/use-sqlite-auth-state.js +162 -0
- package/lib/Utils/validate-connection.js +190 -188
- package/lib/WABinary/constants.js +28 -1294
- package/lib/WABinary/decode.js +245 -249
- package/lib/WABinary/encode.js +201 -206
- package/lib/WABinary/generic-utils.js +86 -89
- package/lib/WABinary/index.js +0 -1
- package/lib/WABinary/jid-utils.js +68 -77
- package/lib/WABinary/types.js +0 -1
- package/lib/WAM/BinaryInfo.js +7 -8
- package/lib/WAM/constants.js +19892 -22853
- package/lib/WAM/encode.js +121 -132
- package/lib/WAM/index.js +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +46 -43
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +47 -48
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -23
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -33
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -20
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -44
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -24
- package/lib/WAUSync/Protocols/index.js +0 -1
- package/lib/WAUSync/USyncQuery.js +79 -88
- package/lib/WAUSync/USyncUser.js +28 -29
- package/lib/WAUSync/index.js +0 -1
- package/lib/index.js +2 -2
- package/package.json +22 -86
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/fix-imports.js +0 -85
- package/WAProto/index.d.ts +0 -14017
- package/lib/Defaults/index.d.ts +0 -75
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -10
- package/lib/Signal/Group/group-session-builder.d.ts +0 -15
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/index.d.ts +0 -12
- package/lib/Signal/Group/keyhelper.d.ts +0 -11
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
- package/lib/Signal/Group/sender-key-message.d.ts +0 -19
- package/lib/Signal/Group/sender-key-name.d.ts +0 -18
- package/lib/Signal/Group/sender-key-record.d.ts +0 -31
- package/lib/Signal/Group/sender-key-state.d.ts +0 -39
- package/lib/Signal/Group/sender-message-key.d.ts +0 -12
- package/lib/Signal/libsignal.d.ts +0 -5
- package/lib/Signal/lid-mapping.d.ts +0 -23
- package/lib/Socket/Client/index.d.ts +0 -3
- package/lib/Socket/Client/types.d.ts +0 -16
- package/lib/Socket/Client/websocket.d.ts +0 -13
- package/lib/Socket/business.d.ts +0 -217
- package/lib/Socket/chats.d.ts +0 -125
- package/lib/Socket/communities.d.ts +0 -273
- package/lib/Socket/groups.d.ts +0 -161
- package/lib/Socket/index.d.ts +0 -260
- package/lib/Socket/messages-recv.d.ts +0 -203
- package/lib/Socket/messages-send.d.ts +0 -199
- package/lib/Socket/mex.d.ts +0 -3
- package/lib/Socket/newsletter.d.ts +0 -170
- package/lib/Socket/socket.d.ts +0 -59
- package/lib/Types/Auth.d.ts +0 -117
- package/lib/Types/Bussines.d.ts +0 -25
- package/lib/Types/Call.d.ts +0 -15
- package/lib/Types/Chat.d.ts +0 -124
- package/lib/Types/Contact.d.ts +0 -26
- package/lib/Types/Events.d.ts +0 -256
- package/lib/Types/GroupMetadata.d.ts +0 -71
- package/lib/Types/Label.d.ts +0 -47
- package/lib/Types/LabelAssociation.d.ts +0 -30
- package/lib/Types/Message.d.ts +0 -320
- package/lib/Types/Mex.d.ts +0 -141
- package/lib/Types/Product.d.ts +0 -79
- package/lib/Types/Signal.d.ts +0 -87
- package/lib/Types/Socket.d.ts +0 -136
- package/lib/Types/State.d.ts +0 -97
- package/lib/Types/USync.d.ts +0 -26
- package/lib/Types/index.d.ts +0 -66
- package/lib/Utils/auth-utils.d.ts +0 -24
- package/lib/Utils/browser-utils.d.ts +0 -4
- package/lib/Utils/business.d.ts +0 -23
- package/lib/Utils/chat-utils.d.ts +0 -100
- package/lib/Utils/companion-reg-client-utils.d.ts +0 -17
- package/lib/Utils/crypto.d.ts +0 -37
- package/lib/Utils/decode-wa-message.d.ts +0 -66
- package/lib/Utils/event-buffer.d.ts +0 -36
- package/lib/Utils/generics.d.ts +0 -92
- package/lib/Utils/history.d.ts +0 -24
- package/lib/Utils/identity-change-handler.d.ts +0 -44
- package/lib/Utils/identity-change-handler.js +0 -50
- package/lib/Utils/index.d.ts +0 -22
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -12
- package/lib/Utils/lt-hash.d.ts +0 -8
- package/lib/Utils/make-mutex.d.ts +0 -9
- package/lib/Utils/message-retry-manager.d.ts +0 -115
- package/lib/Utils/messages-media.d.ts +0 -133
- package/lib/Utils/messages.d.ts +0 -91
- package/lib/Utils/noise-handler.d.ts +0 -20
- package/lib/Utils/offline-node-processor.d.ts +0 -17
- package/lib/Utils/offline-node-processor.js +0 -40
- package/lib/Utils/pre-key-manager.d.ts +0 -28
- package/lib/Utils/process-message.d.ts +0 -60
- package/lib/Utils/reporting-utils.d.ts +0 -11
- package/lib/Utils/signal.d.ts +0 -47
- package/lib/Utils/stanza-ack.d.ts +0 -11
- package/lib/Utils/sync-action-utils.d.ts +0 -19
- package/lib/Utils/tc-token-utils.d.ts +0 -37
- 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 -28
- package/lib/WABinary/decode.d.ts +0 -7
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -15
- package/lib/WABinary/index.d.ts +0 -6
- package/lib/WABinary/jid-utils.d.ts +0 -48
- package/lib/WABinary/types.d.ts +0 -19
- package/lib/WAM/BinaryInfo.d.ts +0 -9
- package/lib/WAM/constants.d.ts +0 -40
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -23
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -13
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -13
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -26
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/index.d.ts +0 -6
- package/lib/WAUSync/USyncQuery.d.ts +0 -30
- package/lib/WAUSync/USyncUser.d.ts +0 -17
- package/lib/WAUSync/index.d.ts +0 -4
- package/lib/index.d.ts +0 -12
package/lib/Socket/groups.js
CHANGED
|
@@ -1,347 +1,403 @@
|
|
|
1
1
|
import { Boom } from '@hapi/boom';
|
|
2
|
-
import { proto } from '../../WAProto/
|
|
2
|
+
import { proto } from '../../WAProto/compiler.js';
|
|
3
3
|
import { WAMessageAddressingMode, WAMessageStubType } from '../Types/index.js';
|
|
4
4
|
import { generateMessageIDV2, unixTimestampSeconds } from '../Utils/index.js';
|
|
5
5
|
import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString, isLidUser, isPnUser, jidEncode, jidNormalizedUser } from '../WABinary/index.js';
|
|
6
6
|
import { makeChatsSocket } from './chats.js';
|
|
7
|
-
export const makeGroupsSocket =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
export const makeGroupsSocket = config => {
|
|
8
|
+
const sock = makeChatsSocket(config);
|
|
9
|
+
const {
|
|
10
|
+
authState,
|
|
11
|
+
ev,
|
|
12
|
+
query,
|
|
13
|
+
upsertMessage
|
|
14
|
+
} = sock;
|
|
15
|
+
const groupQuery = async (jid, type, content) => query({
|
|
16
|
+
tag: 'iq',
|
|
17
|
+
attrs: {
|
|
18
|
+
type,
|
|
19
|
+
xmlns: 'w:g2',
|
|
20
|
+
to: jid
|
|
21
|
+
},
|
|
22
|
+
content
|
|
23
|
+
});
|
|
24
|
+
const groupMetadata = async jid => {
|
|
25
|
+
const result = await groupQuery(jid, 'get', [{
|
|
26
|
+
tag: 'query',
|
|
27
|
+
attrs: {
|
|
28
|
+
request: 'interactive'
|
|
29
|
+
}
|
|
30
|
+
}]);
|
|
31
|
+
return extractGroupMetadata(result);
|
|
32
|
+
};
|
|
33
|
+
const groupFetchAllParticipating = async () => {
|
|
34
|
+
const result = await query({
|
|
35
|
+
tag: 'iq',
|
|
36
|
+
attrs: {
|
|
37
|
+
to: '@g.us',
|
|
38
|
+
xmlns: 'w:g2',
|
|
39
|
+
type: 'get'
|
|
40
|
+
},
|
|
41
|
+
content: [{
|
|
42
|
+
tag: 'participating',
|
|
43
|
+
attrs: {},
|
|
44
|
+
content: [{
|
|
45
|
+
tag: 'participants',
|
|
46
|
+
attrs: {}
|
|
47
|
+
}, {
|
|
48
|
+
tag: 'description',
|
|
49
|
+
attrs: {}
|
|
50
|
+
}]
|
|
51
|
+
}]
|
|
52
|
+
});
|
|
53
|
+
const data = {};
|
|
54
|
+
const groupsChild = getBinaryNodeChild(result, 'groups');
|
|
55
|
+
if (groupsChild) {
|
|
56
|
+
const groups = getBinaryNodeChildren(groupsChild, 'group');
|
|
57
|
+
for (const groupNode of groups) {
|
|
58
|
+
const meta = extractGroupMetadata({
|
|
59
|
+
tag: 'result',
|
|
60
|
+
attrs: {},
|
|
61
|
+
content: [groupNode]
|
|
62
|
+
});
|
|
63
|
+
data[meta.id] = meta;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
sock.ev.emit('groups.update', Object.values(data));
|
|
67
|
+
return data;
|
|
68
|
+
};
|
|
69
|
+
sock.ws.on('CB:ib,,dirty', async node => {
|
|
70
|
+
const {
|
|
71
|
+
attrs
|
|
72
|
+
} = getBinaryNodeChild(node, 'dirty');
|
|
73
|
+
if (attrs.type !== 'groups') {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
await groupFetchAllParticipating();
|
|
77
|
+
await sock.cleanDirtyBits('groups');
|
|
78
|
+
});
|
|
79
|
+
return {
|
|
80
|
+
...sock,
|
|
81
|
+
groupMetadata,
|
|
82
|
+
groupCreate: async (subject, participants) => {
|
|
83
|
+
const key = generateMessageIDV2();
|
|
84
|
+
const result = await groupQuery('@g.us', 'set', [{
|
|
85
|
+
tag: 'create',
|
|
12
86
|
attrs: {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
to: jid
|
|
87
|
+
subject,
|
|
88
|
+
key
|
|
16
89
|
},
|
|
17
|
-
content
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
90
|
+
content: participants.map(jid => ({
|
|
91
|
+
tag: 'participant',
|
|
92
|
+
attrs: {
|
|
93
|
+
jid
|
|
94
|
+
}
|
|
95
|
+
}))
|
|
96
|
+
}]);
|
|
97
|
+
return extractGroupMetadata(result);
|
|
98
|
+
},
|
|
99
|
+
groupLeave: async id => {
|
|
100
|
+
await groupQuery('@g.us', 'set', [{
|
|
101
|
+
tag: 'leave',
|
|
102
|
+
attrs: {},
|
|
103
|
+
content: [{
|
|
104
|
+
tag: 'group',
|
|
105
|
+
attrs: {
|
|
106
|
+
id
|
|
107
|
+
}
|
|
108
|
+
}]
|
|
109
|
+
}]);
|
|
110
|
+
},
|
|
111
|
+
groupUpdateSubject: async (jid, subject) => {
|
|
112
|
+
await groupQuery(jid, 'set', [{
|
|
113
|
+
tag: 'subject',
|
|
114
|
+
attrs: {},
|
|
115
|
+
content: Buffer.from(subject, 'utf-8')
|
|
116
|
+
}]);
|
|
117
|
+
},
|
|
118
|
+
groupRequestParticipantsList: async jid => {
|
|
119
|
+
const result = await groupQuery(jid, 'get', [{
|
|
120
|
+
tag: 'membership_approval_requests',
|
|
121
|
+
attrs: {}
|
|
122
|
+
}]);
|
|
123
|
+
const node = getBinaryNodeChild(result, 'membership_approval_requests');
|
|
124
|
+
const participants = getBinaryNodeChildren(node, 'membership_approval_request');
|
|
125
|
+
return participants.map(v => v.attrs);
|
|
126
|
+
},
|
|
127
|
+
groupRequestParticipantsUpdate: async (jid, participants, action) => {
|
|
128
|
+
const result = await groupQuery(jid, 'set', [{
|
|
129
|
+
tag: 'membership_requests_action',
|
|
130
|
+
attrs: {},
|
|
131
|
+
content: [{
|
|
132
|
+
tag: action,
|
|
133
|
+
attrs: {},
|
|
134
|
+
content: participants.map(jid => ({
|
|
135
|
+
tag: 'participant',
|
|
26
136
|
attrs: {
|
|
27
|
-
|
|
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 groupsChild = getBinaryNodeChild(result, 'groups');
|
|
44
|
-
if (groupsChild) {
|
|
45
|
-
const groups = getBinaryNodeChildren(groupsChild, 'group');
|
|
46
|
-
for (const groupNode of groups) {
|
|
47
|
-
const meta = extractGroupMetadata({
|
|
48
|
-
tag: 'result',
|
|
49
|
-
attrs: {},
|
|
50
|
-
content: [groupNode]
|
|
51
|
-
});
|
|
52
|
-
data[meta.id] = meta;
|
|
137
|
+
jid
|
|
53
138
|
}
|
|
139
|
+
}))
|
|
140
|
+
}]
|
|
141
|
+
}]);
|
|
142
|
+
const node = getBinaryNodeChild(result, 'membership_requests_action');
|
|
143
|
+
const nodeAction = getBinaryNodeChild(node, action);
|
|
144
|
+
const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant');
|
|
145
|
+
return participantsAffected.map(p => {
|
|
146
|
+
return {
|
|
147
|
+
status: p.attrs.error || '200',
|
|
148
|
+
jid: p.attrs.jid
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
groupParticipantsUpdate: async (jid, participants, action) => {
|
|
153
|
+
const result = await groupQuery(jid, 'set', [{
|
|
154
|
+
tag: action,
|
|
155
|
+
attrs: {},
|
|
156
|
+
content: participants.map(jid => ({
|
|
157
|
+
tag: 'participant',
|
|
158
|
+
attrs: {
|
|
159
|
+
jid
|
|
160
|
+
}
|
|
161
|
+
}))
|
|
162
|
+
}]);
|
|
163
|
+
const node = getBinaryNodeChild(result, action);
|
|
164
|
+
const participantsAffected = getBinaryNodeChildren(node, 'participant');
|
|
165
|
+
return participantsAffected.map(p => {
|
|
166
|
+
return {
|
|
167
|
+
status: p.attrs.error || '200',
|
|
168
|
+
jid: p.attrs.jid,
|
|
169
|
+
content: p
|
|
170
|
+
};
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
groupUpdateDescription: async (jid, description) => {
|
|
174
|
+
const metadata = await groupMetadata(jid);
|
|
175
|
+
const prev = metadata.descId ?? null;
|
|
176
|
+
await groupQuery(jid, 'set', [{
|
|
177
|
+
tag: 'description',
|
|
178
|
+
attrs: {
|
|
179
|
+
...(description ? {
|
|
180
|
+
id: generateMessageIDV2()
|
|
181
|
+
} : {
|
|
182
|
+
delete: 'true'
|
|
183
|
+
}),
|
|
184
|
+
...(prev ? {
|
|
185
|
+
prev
|
|
186
|
+
} : {})
|
|
187
|
+
},
|
|
188
|
+
content: description ? [{
|
|
189
|
+
tag: 'body',
|
|
190
|
+
attrs: {},
|
|
191
|
+
content: Buffer.from(description, 'utf-8')
|
|
192
|
+
}] : undefined
|
|
193
|
+
}]);
|
|
194
|
+
},
|
|
195
|
+
groupInviteCode: async jid => {
|
|
196
|
+
const result = await groupQuery(jid, 'get', [{
|
|
197
|
+
tag: 'invite',
|
|
198
|
+
attrs: {}
|
|
199
|
+
}]);
|
|
200
|
+
const inviteNode = getBinaryNodeChild(result, 'invite');
|
|
201
|
+
return inviteNode?.attrs.code;
|
|
202
|
+
},
|
|
203
|
+
groupRevokeInvite: async jid => {
|
|
204
|
+
const result = await groupQuery(jid, 'set', [{
|
|
205
|
+
tag: 'invite',
|
|
206
|
+
attrs: {}
|
|
207
|
+
}]);
|
|
208
|
+
const inviteNode = getBinaryNodeChild(result, 'invite');
|
|
209
|
+
return inviteNode?.attrs.code;
|
|
210
|
+
},
|
|
211
|
+
groupAcceptInvite: async code => {
|
|
212
|
+
const results = await groupQuery('@g.us', 'set', [{
|
|
213
|
+
tag: 'invite',
|
|
214
|
+
attrs: {
|
|
215
|
+
code
|
|
54
216
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
217
|
+
}]);
|
|
218
|
+
const result = getBinaryNodeChild(results, 'group');
|
|
219
|
+
return result?.attrs.jid;
|
|
220
|
+
},
|
|
221
|
+
groupRevokeInviteV4: async (groupJid, invitedJid) => {
|
|
222
|
+
const result = await groupQuery(groupJid, 'set', [{
|
|
223
|
+
tag: 'revoke',
|
|
224
|
+
attrs: {},
|
|
225
|
+
content: [{
|
|
226
|
+
tag: 'participant',
|
|
227
|
+
attrs: {
|
|
228
|
+
jid: invitedJid
|
|
229
|
+
}
|
|
230
|
+
}]
|
|
231
|
+
}]);
|
|
232
|
+
return !!result;
|
|
233
|
+
},
|
|
234
|
+
groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
235
|
+
key = typeof key === 'string' ? {
|
|
236
|
+
remoteJid: key
|
|
237
|
+
} : key;
|
|
238
|
+
const results = await groupQuery(inviteMessage.groupJid, 'set', [{
|
|
239
|
+
tag: 'accept',
|
|
240
|
+
attrs: {
|
|
241
|
+
code: inviteMessage.inviteCode,
|
|
242
|
+
expiration: inviteMessage.inviteExpiration.toString(),
|
|
243
|
+
admin: key.remoteJid
|
|
63
244
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
tag: 'create',
|
|
75
|
-
attrs: {
|
|
76
|
-
subject,
|
|
77
|
-
key
|
|
78
|
-
},
|
|
79
|
-
content: participants.map(jid => ({
|
|
80
|
-
tag: 'participant',
|
|
81
|
-
attrs: { jid }
|
|
82
|
-
}))
|
|
83
|
-
}
|
|
84
|
-
]);
|
|
85
|
-
return extractGroupMetadata(result);
|
|
86
|
-
},
|
|
87
|
-
groupLeave: async (id) => {
|
|
88
|
-
await groupQuery('@g.us', 'set', [
|
|
89
|
-
{
|
|
90
|
-
tag: 'leave',
|
|
91
|
-
attrs: {},
|
|
92
|
-
content: [{ tag: 'group', attrs: { id } }]
|
|
93
|
-
}
|
|
94
|
-
]);
|
|
95
|
-
},
|
|
96
|
-
groupUpdateSubject: async (jid, subject) => {
|
|
97
|
-
await groupQuery(jid, 'set', [
|
|
98
|
-
{
|
|
99
|
-
tag: 'subject',
|
|
100
|
-
attrs: {},
|
|
101
|
-
content: Buffer.from(subject, 'utf-8')
|
|
102
|
-
}
|
|
103
|
-
]);
|
|
104
|
-
},
|
|
105
|
-
groupRequestParticipantsList: async (jid) => {
|
|
106
|
-
const result = await groupQuery(jid, 'get', [
|
|
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);
|
|
115
|
-
},
|
|
116
|
-
groupRequestParticipantsUpdate: async (jid, participants, action) => {
|
|
117
|
-
const result = await groupQuery(jid, 'set', [
|
|
118
|
-
{
|
|
119
|
-
tag: 'membership_requests_action',
|
|
120
|
-
attrs: {},
|
|
121
|
-
content: [
|
|
122
|
-
{
|
|
123
|
-
tag: action,
|
|
124
|
-
attrs: {},
|
|
125
|
-
content: participants.map(jid => ({
|
|
126
|
-
tag: 'participant',
|
|
127
|
-
attrs: { jid }
|
|
128
|
-
}))
|
|
129
|
-
}
|
|
130
|
-
]
|
|
131
|
-
}
|
|
132
|
-
]);
|
|
133
|
-
const node = getBinaryNodeChild(result, 'membership_requests_action');
|
|
134
|
-
const nodeAction = getBinaryNodeChild(node, action);
|
|
135
|
-
const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant');
|
|
136
|
-
return participantsAffected.map(p => {
|
|
137
|
-
return { status: p.attrs.error || '200', jid: p.attrs.jid };
|
|
138
|
-
});
|
|
139
|
-
},
|
|
140
|
-
groupParticipantsUpdate: async (jid, participants, action) => {
|
|
141
|
-
const result = await groupQuery(jid, 'set', [
|
|
142
|
-
{
|
|
143
|
-
tag: action,
|
|
144
|
-
attrs: {},
|
|
145
|
-
content: participants.map(jid => ({
|
|
146
|
-
tag: 'participant',
|
|
147
|
-
attrs: { jid }
|
|
148
|
-
}))
|
|
149
|
-
}
|
|
150
|
-
]);
|
|
151
|
-
const node = getBinaryNodeChild(result, action);
|
|
152
|
-
const participantsAffected = getBinaryNodeChildren(node, 'participant');
|
|
153
|
-
return participantsAffected.map(p => {
|
|
154
|
-
return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
|
|
155
|
-
});
|
|
156
|
-
},
|
|
157
|
-
groupUpdateDescription: async (jid, description) => {
|
|
158
|
-
const metadata = await groupMetadata(jid);
|
|
159
|
-
const prev = metadata.descId ?? null;
|
|
160
|
-
await groupQuery(jid, 'set', [
|
|
161
|
-
{
|
|
162
|
-
tag: 'description',
|
|
163
|
-
attrs: {
|
|
164
|
-
...(description ? { id: generateMessageIDV2() } : { delete: 'true' }),
|
|
165
|
-
...(prev ? { prev } : {})
|
|
166
|
-
},
|
|
167
|
-
content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
|
|
168
|
-
}
|
|
169
|
-
]);
|
|
170
|
-
},
|
|
171
|
-
groupInviteCode: async (jid) => {
|
|
172
|
-
const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
|
|
173
|
-
const inviteNode = getBinaryNodeChild(result, 'invite');
|
|
174
|
-
return inviteNode?.attrs.code;
|
|
175
|
-
},
|
|
176
|
-
groupRevokeInvite: async (jid) => {
|
|
177
|
-
const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
|
|
178
|
-
const inviteNode = getBinaryNodeChild(result, 'invite');
|
|
179
|
-
return inviteNode?.attrs.code;
|
|
180
|
-
},
|
|
181
|
-
groupAcceptInvite: async (code) => {
|
|
182
|
-
const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
|
|
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;
|
|
197
|
-
},
|
|
198
|
-
/**
|
|
199
|
-
* accept a GroupInviteMessage
|
|
200
|
-
* @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
|
|
201
|
-
* @param inviteMessage the message to accept
|
|
202
|
-
*/
|
|
203
|
-
groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
204
|
-
key = typeof key === 'string' ? { remoteJid: key } : key;
|
|
205
|
-
const results = await groupQuery(inviteMessage.groupJid, 'set', [
|
|
206
|
-
{
|
|
207
|
-
tag: 'accept',
|
|
208
|
-
attrs: {
|
|
209
|
-
code: inviteMessage.inviteCode,
|
|
210
|
-
expiration: inviteMessage.inviteExpiration.toString(),
|
|
211
|
-
admin: key.remoteJid
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
]);
|
|
215
|
-
// if we have the full message key
|
|
216
|
-
// update the invite message to be expired
|
|
217
|
-
if (key.id) {
|
|
218
|
-
// create new invite message that is expired
|
|
219
|
-
inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage);
|
|
220
|
-
inviteMessage.inviteExpiration = 0;
|
|
221
|
-
inviteMessage.inviteCode = '';
|
|
222
|
-
ev.emit('messages.update', [
|
|
223
|
-
{
|
|
224
|
-
key,
|
|
225
|
-
update: {
|
|
226
|
-
message: {
|
|
227
|
-
groupInviteMessage: inviteMessage
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
]);
|
|
245
|
+
}]);
|
|
246
|
+
if (key.id) {
|
|
247
|
+
inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage);
|
|
248
|
+
inviteMessage.inviteExpiration = 0;
|
|
249
|
+
inviteMessage.inviteCode = '';
|
|
250
|
+
ev.emit('messages.update', [{
|
|
251
|
+
key,
|
|
252
|
+
update: {
|
|
253
|
+
message: {
|
|
254
|
+
groupInviteMessage: inviteMessage
|
|
232
255
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
messageStubParameters: [JSON.stringify(authState.creds.me)],
|
|
243
|
-
participant: key.remoteJid,
|
|
244
|
-
messageTimestamp: unixTimestampSeconds()
|
|
245
|
-
}, 'notify');
|
|
246
|
-
return results.attrs.from;
|
|
247
|
-
}),
|
|
248
|
-
groupGetInviteInfo: async (code) => {
|
|
249
|
-
const results = await groupQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
|
|
250
|
-
return extractGroupMetadata(results);
|
|
251
|
-
},
|
|
252
|
-
groupToggleEphemeral: async (jid, ephemeralExpiration) => {
|
|
253
|
-
const content = ephemeralExpiration
|
|
254
|
-
? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
|
|
255
|
-
: { tag: 'not_ephemeral', attrs: {} };
|
|
256
|
-
await groupQuery(jid, 'set', [content]);
|
|
256
|
+
}
|
|
257
|
+
}]);
|
|
258
|
+
}
|
|
259
|
+
await upsertMessage({
|
|
260
|
+
key: {
|
|
261
|
+
remoteJid: inviteMessage.groupJid,
|
|
262
|
+
id: generateMessageIDV2(sock.user?.id),
|
|
263
|
+
fromMe: false,
|
|
264
|
+
participant: key.remoteJid
|
|
257
265
|
},
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
};
|
|
271
|
-
};
|
|
272
|
-
export const extractGroupMetadata = (result) => {
|
|
273
|
-
const group = getBinaryNodeChild(result, 'group');
|
|
274
|
-
if (!group) {
|
|
275
|
-
// Mirror WAWeb: surface server/client errors with their code+text instead of crashing.
|
|
276
|
-
const errorNode = getBinaryNodeChild(result, 'error');
|
|
277
|
-
if (errorNode) {
|
|
278
|
-
const code = errorNode.attrs.code ? +errorNode.attrs.code : 500;
|
|
279
|
-
const text = errorNode.attrs.text || 'group metadata query failed';
|
|
280
|
-
throw new Boom(text, { statusCode: code, data: errorNode });
|
|
266
|
+
messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
|
|
267
|
+
messageStubParameters: [JSON.stringify(authState.creds.me)],
|
|
268
|
+
participant: key.remoteJid,
|
|
269
|
+
messageTimestamp: unixTimestampSeconds()
|
|
270
|
+
}, 'notify');
|
|
271
|
+
return results.attrs.from;
|
|
272
|
+
}),
|
|
273
|
+
groupGetInviteInfo: async code => {
|
|
274
|
+
const results = await groupQuery('@g.us', 'get', [{
|
|
275
|
+
tag: 'invite',
|
|
276
|
+
attrs: {
|
|
277
|
+
code
|
|
281
278
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
279
|
+
}]);
|
|
280
|
+
return extractGroupMetadata(results);
|
|
281
|
+
},
|
|
282
|
+
groupToggleEphemeral: async (jid, ephemeralExpiration) => {
|
|
283
|
+
const content = ephemeralExpiration ? {
|
|
284
|
+
tag: 'ephemeral',
|
|
285
|
+
attrs: {
|
|
286
|
+
expiration: ephemeralExpiration.toString()
|
|
287
|
+
}
|
|
288
|
+
} : {
|
|
289
|
+
tag: 'not_ephemeral',
|
|
290
|
+
attrs: {}
|
|
291
|
+
};
|
|
292
|
+
await groupQuery(jid, 'set', [content]);
|
|
293
|
+
},
|
|
294
|
+
groupSettingUpdate: async (jid, setting) => {
|
|
295
|
+
await groupQuery(jid, 'set', [{
|
|
296
|
+
tag: setting,
|
|
297
|
+
attrs: {}
|
|
298
|
+
}]);
|
|
299
|
+
},
|
|
300
|
+
groupMemberAddMode: async (jid, mode) => {
|
|
301
|
+
await groupQuery(jid, 'set', [{
|
|
302
|
+
tag: 'member_add_mode',
|
|
303
|
+
attrs: {},
|
|
304
|
+
content: mode
|
|
305
|
+
}]);
|
|
306
|
+
},
|
|
307
|
+
groupJoinApprovalMode: async (jid, mode) => {
|
|
308
|
+
await groupQuery(jid, 'set', [{
|
|
309
|
+
tag: 'membership_approval_mode',
|
|
310
|
+
attrs: {},
|
|
311
|
+
content: [{
|
|
312
|
+
tag: 'group_join',
|
|
313
|
+
attrs: {
|
|
314
|
+
state: mode
|
|
315
|
+
}
|
|
316
|
+
}]
|
|
317
|
+
}]);
|
|
318
|
+
},
|
|
319
|
+
groupFetchAllParticipating
|
|
320
|
+
};
|
|
321
|
+
};
|
|
322
|
+
export const extractGroupMetadata = result => {
|
|
323
|
+
const group = getBinaryNodeChild(result, 'group');
|
|
324
|
+
if (!group) {
|
|
325
|
+
const errorNode = getBinaryNodeChild(result, 'error');
|
|
326
|
+
if (errorNode) {
|
|
327
|
+
const code = errorNode.attrs.code ? +errorNode.attrs.code : 500;
|
|
328
|
+
const text = errorNode.attrs.text || 'group metadata query failed';
|
|
329
|
+
throw new Boom(text, {
|
|
330
|
+
statusCode: code,
|
|
331
|
+
data: errorNode
|
|
332
|
+
});
|
|
301
333
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
334
|
+
throw new Boom('Invalid group metadata response: missing <group> node', {
|
|
335
|
+
data: result
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
if (!group.attrs.id) {
|
|
339
|
+
throw new Boom('Invalid group metadata response: missing group id', {
|
|
340
|
+
data: group
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
const descChild = getBinaryNodeChild(group, 'description');
|
|
344
|
+
let desc;
|
|
345
|
+
let descId;
|
|
346
|
+
let descOwner;
|
|
347
|
+
let descOwnerPn;
|
|
348
|
+
let descOwnerUsername;
|
|
349
|
+
let descTime;
|
|
350
|
+
if (descChild) {
|
|
351
|
+
desc = getBinaryNodeChildString(descChild, 'body');
|
|
352
|
+
descOwner = descChild.attrs.participant ? jidNormalizedUser(descChild.attrs.participant) : undefined;
|
|
353
|
+
descOwnerPn = descChild.attrs.participant_pn ? jidNormalizedUser(descChild.attrs.participant_pn) : undefined;
|
|
354
|
+
descOwnerUsername = descChild.attrs.participant_username || undefined;
|
|
355
|
+
descTime = +descChild.attrs.t;
|
|
356
|
+
descId = descChild.attrs.id;
|
|
357
|
+
}
|
|
358
|
+
const groupId = group.attrs.id.includes('@') ? group.attrs.id : jidEncode(group.attrs.id, 'g.us');
|
|
359
|
+
const eph = getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration;
|
|
360
|
+
const memberAddMode = getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add';
|
|
361
|
+
const metadata = {
|
|
362
|
+
id: groupId,
|
|
363
|
+
notify: group.attrs.notify,
|
|
364
|
+
addressingMode: group.attrs.addressing_mode === 'lid' ? WAMessageAddressingMode.LID : WAMessageAddressingMode.PN,
|
|
365
|
+
subject: group.attrs.subject,
|
|
366
|
+
subjectOwner: group.attrs.s_o,
|
|
367
|
+
subjectOwnerPn: group.attrs.s_o_pn,
|
|
368
|
+
subjectOwnerUsername: group.attrs.s_o_username,
|
|
369
|
+
subjectTime: +group.attrs.s_t,
|
|
370
|
+
size: group.attrs.size ? +group.attrs.size : getBinaryNodeChildren(group, 'participant').length,
|
|
371
|
+
creation: +group.attrs.creation,
|
|
372
|
+
owner: group.attrs.creator ? jidNormalizedUser(group.attrs.creator) : undefined,
|
|
373
|
+
ownerPn: group.attrs.creator_pn ? jidNormalizedUser(group.attrs.creator_pn) : undefined,
|
|
374
|
+
ownerUsername: group.attrs.creator_username || undefined,
|
|
375
|
+
owner_country_code: group.attrs.creator_country_code,
|
|
376
|
+
desc,
|
|
377
|
+
descId,
|
|
378
|
+
descOwner,
|
|
379
|
+
descOwnerPn,
|
|
380
|
+
descOwnerUsername,
|
|
381
|
+
descTime,
|
|
382
|
+
linkedParent: getBinaryNodeChild(group, 'linked_parent')?.attrs.jid || undefined,
|
|
383
|
+
restrict: !!getBinaryNodeChild(group, 'locked'),
|
|
384
|
+
announce: !!getBinaryNodeChild(group, 'announcement'),
|
|
385
|
+
isCommunity: !!getBinaryNodeChild(group, 'parent'),
|
|
386
|
+
isCommunityAnnounce: !!getBinaryNodeChild(group, 'default_sub_group'),
|
|
387
|
+
joinApprovalMode: !!getBinaryNodeChild(group, 'membership_approval_mode'),
|
|
388
|
+
memberAddMode,
|
|
389
|
+
participants: getBinaryNodeChildren(group, 'participant').map(({
|
|
390
|
+
attrs
|
|
391
|
+
}) => {
|
|
392
|
+
return {
|
|
393
|
+
id: attrs.jid,
|
|
394
|
+
phoneNumber: isLidUser(attrs.jid) && isPnUser(attrs.phone_number) ? attrs.phone_number : undefined,
|
|
395
|
+
lid: isPnUser(attrs.jid) && isLidUser(attrs.lid) ? attrs.lid : undefined,
|
|
396
|
+
username: attrs.participant_username || attrs.username || undefined,
|
|
397
|
+
admin: attrs.type || null
|
|
398
|
+
};
|
|
399
|
+
}),
|
|
400
|
+
ephemeralDuration: eph ? +eph : undefined
|
|
401
|
+
};
|
|
402
|
+
return metadata;
|
|
346
403
|
};
|
|
347
|
-
//# sourceMappingURL=groups.js.map
|