sanka-baileyss 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Socket/groups.d.ts +123 -117
- package/lib/Socket/groups.js +305 -355
- package/lib/Socket/socket.js +1 -1
- package/package.json +1 -1
package/lib/Socket/groups.d.ts
CHANGED
|
@@ -1,122 +1,128 @@
|
|
|
1
1
|
import { proto } from '../../WAProto'
|
|
2
|
-
import { GroupMetadata, ParticipantAction, SocketConfig, ContactAction
|
|
2
|
+
import { GroupMetadata, ParticipantAction, SocketConfig, ContactAction } from '../Types'
|
|
3
3
|
import { BinaryNode } from '../WABinary'
|
|
4
|
-
import { BaileysEventEmitter, AuthenticationCreds, SignalKeyStoreWithTransaction, SignalRepository, Contact, ChatModification, LabelActionBody } from '../Types'
|
|
5
|
-
|
|
6
4
|
export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
5
|
+
groupQuery: (jid: string, type: string, content: BinaryNode) => Promise<BinaryNode>
|
|
6
|
+
groupMetadata: (jid: string) => Promise<GroupMetadata>
|
|
7
|
+
groupCreate: (subject: string, participants: string[]) => Promise<GroupMetadata>
|
|
8
|
+
groupLeave: (id: string) => Promise<void>
|
|
9
|
+
groupUpdateSubject: (jid: string, subject: string) => Promise<void>
|
|
10
|
+
groupRequestParticipantsList: (jid: string) => Promise<{
|
|
11
|
+
[key: string]: string
|
|
12
|
+
}[]>
|
|
13
|
+
groupRequestParticipantsUpdate: (jid: string, participants: string[], action: 'approve' | 'reject') => Promise<{
|
|
14
|
+
status: string
|
|
15
|
+
jid: string
|
|
16
|
+
}[]>
|
|
17
|
+
groupParticipantsUpdate: (jid: string, participants: string[], action: ParticipantAction) => Promise<{
|
|
18
|
+
status: string
|
|
19
|
+
jid: string
|
|
20
|
+
content: BinaryNode
|
|
21
|
+
}[]>
|
|
22
|
+
groupUpdateDescription: (jid: string, description?: string) => Promise<void>
|
|
23
|
+
groupInviteCode: (jid: string) => Promise<string | undefined>
|
|
24
|
+
groupRevokeInvite: (jid: string) => Promise<string | undefined>
|
|
25
|
+
groupAcceptInvite: (code: string) => Promise<string | undefined>
|
|
26
|
+
/**
|
|
27
|
+
* revoke a v4 invite for someone
|
|
28
|
+
* @param groupJid group jid
|
|
29
|
+
* @param invitedJid jid of person you invited
|
|
30
|
+
* @returns true if successful
|
|
31
|
+
*/
|
|
32
|
+
groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>
|
|
33
|
+
/**
|
|
34
|
+
* accept a GroupInviteMessage
|
|
35
|
+
* @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
|
|
36
|
+
* @param inviteMessage the message to accept
|
|
37
|
+
*/
|
|
38
|
+
groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>
|
|
39
|
+
groupGetInviteInfo: (code: string) => Promise<GroupMetadata>
|
|
40
|
+
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>
|
|
41
|
+
groupSettingUpdate: (jid: string, setting: 'announcement' | 'not_announcement' | 'locked' | 'unlocked') => Promise<void>
|
|
42
|
+
groupMemberAddMode: (jid: string, mode: 'admin_add' | 'all_member_add') => Promise<void>
|
|
43
|
+
groupJoinApprovalMode: (jid: string, mode: 'on' | 'off') => Promise<void>
|
|
44
|
+
groupFetchAllParticipating: () => Promise<{
|
|
45
|
+
[_: string]: GroupMetadata
|
|
46
|
+
}>
|
|
47
|
+
processingMutex: {
|
|
48
|
+
mutex<T>(code: () => T | Promise<T>): Promise<T>
|
|
49
|
+
}
|
|
50
|
+
fetchPrivacySettings: (force?: boolean) => Promise<{
|
|
51
|
+
[_: string]: string
|
|
52
|
+
}>
|
|
53
|
+
upsertMessage: (msg: proto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>
|
|
54
|
+
appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>
|
|
55
|
+
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>
|
|
56
|
+
presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>
|
|
57
|
+
getLidUser: (jid: string) => Promise<{
|
|
58
|
+
lid: string
|
|
59
|
+
id: string
|
|
60
|
+
}[] | undefined>
|
|
61
|
+
onWhatsApp: (...jids: string[]) => Promise<{
|
|
62
|
+
jid: string
|
|
63
|
+
exists: unknown
|
|
64
|
+
}[] | undefined>
|
|
65
|
+
fetchBlocklist: () => Promise<string[]>
|
|
66
|
+
fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>
|
|
67
|
+
fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>
|
|
68
|
+
updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>
|
|
69
|
+
removeProfilePicture: (jid: string) => Promise<void>
|
|
70
|
+
updateProfileStatus: (status: string) => Promise<void>
|
|
71
|
+
updateProfileName: (name: string) => Promise<void>
|
|
72
|
+
updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>
|
|
73
|
+
updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>
|
|
74
|
+
updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>
|
|
75
|
+
updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>
|
|
76
|
+
updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>
|
|
77
|
+
updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>
|
|
78
|
+
updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>
|
|
79
|
+
updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>
|
|
80
|
+
updateDefaultDisappearingMode: (duration: number) => Promise<void>
|
|
81
|
+
getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>
|
|
82
|
+
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>
|
|
83
|
+
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>
|
|
84
|
+
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>
|
|
85
|
+
addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>
|
|
86
|
+
addChatLabel: (jid: string, labelId: string) => Promise<void>
|
|
87
|
+
removeChatLabel: (jid: string, labelId: string) => Promise<void>
|
|
88
|
+
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>
|
|
89
|
+
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>
|
|
90
|
+
clearMessage: (jid: string, key: import("../Types").WAProto.IMessageKey, timeStamp: number | import("long").Long) => Promise<void>
|
|
91
|
+
star: (jid: string, messages: {
|
|
92
|
+
id: string
|
|
93
|
+
fromMe?: boolean | undefined
|
|
94
|
+
}[], star: boolean) => Promise<void>
|
|
95
|
+
addOrEditContact: (jid: string, contact: ContactAction) => Promise<void>
|
|
96
|
+
removeContact: (jid: string) => Promise<void>
|
|
97
|
+
executeUSyncQuery: (usyncQuery: import("..").USyncQuery) => Promise<import("..").USyncQueryResult | undefined>
|
|
98
|
+
type: "md"
|
|
99
|
+
ws: import("./Client").WebSocketClient
|
|
100
|
+
ev: import("../Types").BaileysEventEmitter & {
|
|
101
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void
|
|
102
|
+
buffer(): void
|
|
103
|
+
createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>
|
|
104
|
+
flush(force?: boolean | undefined): boolean
|
|
105
|
+
isBuffering(): boolean
|
|
106
|
+
}
|
|
107
|
+
authState: {
|
|
108
|
+
creds: import("../Types").AuthenticationCreds
|
|
109
|
+
keys: import("../Types").SignalKeyStoreWithTransaction
|
|
110
|
+
}
|
|
111
|
+
signalRepository: import("../Types").SignalRepository
|
|
112
|
+
user: import("../Types").Contact | undefined
|
|
113
|
+
generateMessageTag: () => string
|
|
114
|
+
query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>
|
|
115
|
+
waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>
|
|
116
|
+
waitForSocketOpen: () => Promise<void>
|
|
117
|
+
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>
|
|
118
|
+
sendNode: (frame: BinaryNode) => Promise<void>
|
|
119
|
+
logout: (msg?: string | undefined) => Promise<void>
|
|
120
|
+
end: (error: Error | undefined) => void
|
|
121
|
+
onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void
|
|
122
|
+
uploadPreKeys: (count?: number) => Promise<void>
|
|
123
|
+
uploadPreKeysToServerIfRequired: () => Promise<void>
|
|
124
|
+
requestPairingCode: (phoneNumber: string, code?: string) => Promise<string>
|
|
125
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>
|
|
126
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>
|
|
120
127
|
}
|
|
121
|
-
|
|
122
128
|
export declare const extractGroupMetadata: (result: BinaryNode) => GroupMetadata
|
package/lib/Socket/groups.js
CHANGED
|
@@ -1,359 +1,309 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true })
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const chats_1 = require("./chats");
|
|
9
|
-
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
3
|
+
const WAProto_1 = require("../../WAProto")
|
|
4
|
+
const Types_1 = require("../Types")
|
|
5
|
+
const Utils_1 = require("../Utils")
|
|
6
|
+
const WABinary_1 = require("../WABinary")
|
|
7
|
+
const chats_1 = require("./chats")
|
|
10
8
|
const makeGroupsSocket = (config) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
] : undefined
|
|
190
|
-
}
|
|
191
|
-
]);
|
|
192
|
-
},
|
|
193
|
-
groupInviteCode: async (jid) => {
|
|
194
|
-
const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
|
|
195
|
-
const inviteNode = WABinary_1.getBinaryNodeChild(result, 'invite');
|
|
196
|
-
|
|
197
|
-
return inviteNode?.attrs?.code;
|
|
198
|
-
},
|
|
199
|
-
groupRevokeInvite: async (jid) => {
|
|
200
|
-
const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
|
|
201
|
-
const inviteNode = WABinary_1.getBinaryNodeChild(result, 'invite');
|
|
202
|
-
|
|
203
|
-
return inviteNode?.attrs?.code;
|
|
204
|
-
},
|
|
205
|
-
groupAcceptInvite: async (code) => {
|
|
206
|
-
const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
|
|
207
|
-
const result = WABinary_1.getBinaryNodeChild(results, 'group');
|
|
208
|
-
|
|
209
|
-
return result?.attrs?.jid;
|
|
210
|
-
},
|
|
9
|
+
const sock = chats_1.makeChatsSocket(config)
|
|
10
|
+
const { authState, ev, query, upsertMessage } = sock
|
|
11
|
+
const groupQuery = async (jid, type, content) => (query({
|
|
12
|
+
tag: 'iq',
|
|
13
|
+
attrs: {
|
|
14
|
+
type,
|
|
15
|
+
xmlns: 'w:g2',
|
|
16
|
+
to: jid,
|
|
17
|
+
},
|
|
18
|
+
content
|
|
19
|
+
}))
|
|
20
|
+
const groupMetadata = async (jid) => {
|
|
21
|
+
const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }])
|
|
22
|
+
return extractGroupMetadata(result)
|
|
23
|
+
}
|
|
24
|
+
const groupFetchAllParticipating = async () => {
|
|
25
|
+
const result = await query({
|
|
26
|
+
tag: 'iq',
|
|
27
|
+
attrs: {
|
|
28
|
+
to: '@g.us',
|
|
29
|
+
xmlns: 'w:g2',
|
|
30
|
+
type: 'get',
|
|
31
|
+
},
|
|
32
|
+
content: [
|
|
33
|
+
{
|
|
34
|
+
tag: 'participating',
|
|
35
|
+
attrs: {},
|
|
36
|
+
content: [
|
|
37
|
+
{ tag: 'participants', attrs: {} },
|
|
38
|
+
{ tag: 'description', attrs: {} }
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
})
|
|
43
|
+
const data = {}
|
|
44
|
+
const groupsChild = WABinary_1.getBinaryNodeChild(result, 'groups')
|
|
45
|
+
if (groupsChild) {
|
|
46
|
+
const groups = WABinary_1.getBinaryNodeChildren(groupsChild, 'group')
|
|
47
|
+
for (const groupNode of groups) {
|
|
48
|
+
const meta = extractGroupMetadata({
|
|
49
|
+
tag: 'result',
|
|
50
|
+
attrs: {},
|
|
51
|
+
content: [groupNode]
|
|
52
|
+
})
|
|
53
|
+
data[meta.id] = meta
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
sock.ev.emit('groups.update', Object.values(data))
|
|
57
|
+
return data
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
...sock,
|
|
61
|
+
groupQuery,
|
|
62
|
+
groupMetadata,
|
|
63
|
+
groupCreate: async (subject, participants) => {
|
|
64
|
+
const key = Utils_1.generateMessageID()
|
|
65
|
+
const result = await groupQuery('@g.us', 'set', [
|
|
66
|
+
{
|
|
67
|
+
tag: 'create',
|
|
68
|
+
attrs: {
|
|
69
|
+
subject,
|
|
70
|
+
key
|
|
71
|
+
},
|
|
72
|
+
content: participants.map(jid => ({
|
|
73
|
+
tag: 'participant',
|
|
74
|
+
attrs: { jid }
|
|
75
|
+
}))
|
|
76
|
+
}
|
|
77
|
+
])
|
|
78
|
+
return extractGroupMetadata(result)
|
|
79
|
+
},
|
|
80
|
+
groupLeave: async (id) => {
|
|
81
|
+
await groupQuery('@g.us', 'set', [
|
|
82
|
+
{
|
|
83
|
+
tag: 'leave',
|
|
84
|
+
attrs: {},
|
|
85
|
+
content: [
|
|
86
|
+
{ tag: 'group', attrs: { id } }
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
])
|
|
90
|
+
},
|
|
91
|
+
groupUpdateSubject: async (jid, subject) => {
|
|
92
|
+
await groupQuery(jid, 'set', [
|
|
93
|
+
{
|
|
94
|
+
tag: 'subject',
|
|
95
|
+
attrs: {},
|
|
96
|
+
content: Buffer.from(subject, 'utf-8')
|
|
97
|
+
}
|
|
98
|
+
])
|
|
99
|
+
},
|
|
100
|
+
groupRequestParticipantsList: async (jid) => {
|
|
101
|
+
const result = await groupQuery(jid, 'get', [
|
|
102
|
+
{
|
|
103
|
+
tag: 'membership_approval_requests',
|
|
104
|
+
attrs: {}
|
|
105
|
+
}
|
|
106
|
+
])
|
|
107
|
+
const node = WABinary_1.getBinaryNodeChild(result, 'membership_approval_requests')
|
|
108
|
+
const participants = WABinary_1.getBinaryNodeChildren(node, 'membership_approval_request')
|
|
109
|
+
return participants.map(v => v.attrs)
|
|
110
|
+
},
|
|
111
|
+
groupRequestParticipantsUpdate: async (jid, participants, action) => {
|
|
112
|
+
const result = await groupQuery(jid, 'set', [{
|
|
113
|
+
tag: 'membership_requests_action',
|
|
114
|
+
attrs: {},
|
|
115
|
+
content: [
|
|
116
|
+
{
|
|
117
|
+
tag: action,
|
|
118
|
+
attrs: {},
|
|
119
|
+
content: participants.map(jid => ({
|
|
120
|
+
tag: 'participant',
|
|
121
|
+
attrs: { jid }
|
|
122
|
+
}))
|
|
123
|
+
}
|
|
124
|
+
]
|
|
125
|
+
}])
|
|
126
|
+
const node = WABinary_1.getBinaryNodeChild(result, 'membership_requests_action')
|
|
127
|
+
const nodeAction = WABinary_1.getBinaryNodeChild(node, action)
|
|
128
|
+
const participantsAffected = WABinary_1.getBinaryNodeChildren(nodeAction, 'participant')
|
|
129
|
+
return participantsAffected.map(p => {
|
|
130
|
+
return { status: p.attrs.error || '200', jid: p.attrs.jid }
|
|
131
|
+
})
|
|
132
|
+
},
|
|
133
|
+
groupParticipantsUpdate: async (jid, participants, action) => {
|
|
134
|
+
const result = await groupQuery(jid, 'set', [
|
|
135
|
+
{
|
|
136
|
+
tag: action,
|
|
137
|
+
attrs: {},
|
|
138
|
+
content: participants.map(jid => ({
|
|
139
|
+
tag: 'participant',
|
|
140
|
+
attrs: { jid }
|
|
141
|
+
}))
|
|
142
|
+
}
|
|
143
|
+
])
|
|
144
|
+
const node = WABinary_1.getBinaryNodeChild(result, action)
|
|
145
|
+
const participantsAffected = WABinary_1.getBinaryNodeChildren(node, 'participant')
|
|
146
|
+
return participantsAffected.map(p => {
|
|
147
|
+
return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p }
|
|
148
|
+
})
|
|
149
|
+
},
|
|
150
|
+
groupUpdateDescription: async (jid, description) => {
|
|
151
|
+
const metadata = await groupMetadata(jid)
|
|
152
|
+
const prev = metadata.descId ? metadata.descId : null
|
|
153
|
+
await groupQuery(jid, 'set', [
|
|
154
|
+
{
|
|
155
|
+
tag: 'description',
|
|
156
|
+
attrs: {
|
|
157
|
+
...(description ? { id: Utils_1.generateMessageID() } : { delete: 'true' }),
|
|
158
|
+
...(prev ? { prev } : {})
|
|
159
|
+
},
|
|
160
|
+
content: description ? [
|
|
161
|
+
{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }
|
|
162
|
+
] : undefined
|
|
163
|
+
}
|
|
164
|
+
])
|
|
165
|
+
},
|
|
166
|
+
groupInviteCode: async (jid) => {
|
|
167
|
+
const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }])
|
|
168
|
+
const inviteNode = WABinary_1.getBinaryNodeChild(result, 'invite')
|
|
169
|
+
return inviteNode?.attrs?.code
|
|
170
|
+
},
|
|
171
|
+
groupRevokeInvite: async (jid) => {
|
|
172
|
+
const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }])
|
|
173
|
+
const inviteNode = WABinary_1.getBinaryNodeChild(result, 'invite')
|
|
174
|
+
return inviteNode?.attrs?.code
|
|
175
|
+
},
|
|
176
|
+
groupAcceptInvite: async (code) => {
|
|
177
|
+
const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }])
|
|
178
|
+
const result = WABinary_1.getBinaryNodeChild(results, 'group')
|
|
179
|
+
return result?.attrs?.jid
|
|
180
|
+
},
|
|
181
|
+
/**
|
|
182
|
+
* revoke a v4 invite for someone
|
|
183
|
+
* @param groupJid group jid
|
|
184
|
+
* @param invitedJid jid of person you invited
|
|
185
|
+
* @returns true if successful
|
|
186
|
+
*/
|
|
211
187
|
groupRevokeInviteV4: async (groupJid, invitedJid) => {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
188
|
+
const result = await groupQuery(groupJid, 'set', [{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }])
|
|
189
|
+
return !!result
|
|
190
|
+
},
|
|
191
|
+
/**
|
|
192
|
+
* accept a GroupInviteMessage
|
|
193
|
+
* @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
|
|
194
|
+
* @param inviteMessage the message to accept
|
|
195
|
+
*/
|
|
196
|
+
groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
197
|
+
key = typeof key === 'string' ? { remoteJid: key } : key
|
|
198
|
+
const results = await groupQuery(inviteMessage.groupJid, 'set', [{
|
|
199
|
+
tag: 'accept',
|
|
200
|
+
attrs: {
|
|
201
|
+
code: inviteMessage.inviteCode,
|
|
202
|
+
expiration: inviteMessage.inviteExpiration.toString(),
|
|
203
|
+
admin: key.remoteJid
|
|
204
|
+
}
|
|
205
|
+
}])
|
|
206
|
+
// if we have the full message key
|
|
207
|
+
// update the invite message to be expired
|
|
208
|
+
if (key.id) {
|
|
209
|
+
// create new invite message that is expired
|
|
210
|
+
inviteMessage = WAProto_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage)
|
|
211
|
+
inviteMessage.inviteExpiration = 0
|
|
212
|
+
inviteMessage.inviteCode = ''
|
|
213
|
+
ev.emit('messages.update', [
|
|
214
|
+
{
|
|
215
|
+
key,
|
|
216
|
+
update: {
|
|
217
|
+
message: {
|
|
218
|
+
groupInviteMessage: inviteMessage
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
])
|
|
223
|
+
}
|
|
224
|
+
// generate the group add message
|
|
225
|
+
await upsertMessage({
|
|
226
|
+
key: {
|
|
227
|
+
remoteJid: inviteMessage.groupJid,
|
|
228
|
+
id: Utils_1.generateMessageID(authState.creds.me?.id),
|
|
229
|
+
fromMe: false,
|
|
230
|
+
participant: key.remoteJid,
|
|
231
|
+
},
|
|
232
|
+
messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
|
|
233
|
+
messageStubParameters: [
|
|
234
|
+
authState.creds.me.id
|
|
235
|
+
],
|
|
236
|
+
participant: key.remoteJid,
|
|
237
|
+
messageTimestamp: Utils_1.unixTimestampSeconds()
|
|
238
|
+
}, 'notify')
|
|
239
|
+
return results.attrs.from
|
|
240
|
+
}),
|
|
241
|
+
groupGetInviteInfo: async (code) => {
|
|
242
|
+
const results = await groupQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }])
|
|
243
|
+
return extractGroupMetadata(results)
|
|
244
|
+
},
|
|
245
|
+
groupToggleEphemeral: async (jid, ephemeralExpiration) => {
|
|
246
|
+
const content = ephemeralExpiration ?
|
|
247
|
+
{ tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } } :
|
|
248
|
+
{ tag: 'not_ephemeral', attrs: {} }
|
|
249
|
+
await groupQuery(jid, 'set', [content])
|
|
250
|
+
},
|
|
251
|
+
groupSettingUpdate: async (jid, setting) => {
|
|
252
|
+
await groupQuery(jid, 'set', [{ tag: setting, attrs: {} }])
|
|
253
|
+
},
|
|
254
|
+
groupMemberAddMode: async (jid, mode) => {
|
|
255
|
+
await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }])
|
|
256
|
+
},
|
|
257
|
+
groupJoinApprovalMode: async (jid, mode) => {
|
|
258
|
+
await groupQuery(jid, 'set', [{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }])
|
|
221
259
|
},
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
tag: 'accept',
|
|
226
|
-
attrs: {
|
|
227
|
-
code: inviteMessage.inviteCode,
|
|
228
|
-
expiration: inviteMessage.inviteExpiration.toString(),
|
|
229
|
-
admin: key.remoteJid
|
|
230
|
-
}
|
|
231
|
-
}]);
|
|
232
|
-
|
|
233
|
-
if (key.id) {
|
|
234
|
-
inviteMessage = WAProto_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage);
|
|
235
|
-
inviteMessage.inviteExpiration = 0;
|
|
236
|
-
inviteMessage.inviteCode = '';
|
|
237
|
-
ev.emit('messages.update', [
|
|
238
|
-
{
|
|
239
|
-
key,
|
|
240
|
-
update: {
|
|
241
|
-
message: {
|
|
242
|
-
groupInviteMessage: inviteMessage
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
]);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
await upsertMessage({
|
|
250
|
-
key: {
|
|
251
|
-
remoteJid: inviteMessage.groupJid,
|
|
252
|
-
id: Utils_1.generateMessageID(authState.creds.me?.id),
|
|
253
|
-
fromMe: false,
|
|
254
|
-
participant: key.remoteJid,
|
|
255
|
-
},
|
|
256
|
-
messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
|
|
257
|
-
messageStubParameters: [
|
|
258
|
-
authState.creds.me.id
|
|
259
|
-
],
|
|
260
|
-
participant: key.remoteJid,
|
|
261
|
-
messageTimestamp: Utils_1.unixTimestampSeconds()
|
|
262
|
-
}, 'notify');
|
|
263
|
-
|
|
264
|
-
return results.attrs.from;
|
|
265
|
-
}),
|
|
266
|
-
groupGetInviteInfo: async (code) => {
|
|
267
|
-
const results = await groupQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
|
|
268
|
-
|
|
269
|
-
return extractGroupMetadata(results);
|
|
270
|
-
},
|
|
271
|
-
groupToggleEphemeral: async (jid, ephemeralExpiration) => {
|
|
272
|
-
const content = ephemeralExpiration ?
|
|
273
|
-
{ tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } } :
|
|
274
|
-
{ tag: 'not_ephemeral', attrs: {} };
|
|
275
|
-
await groupQuery(jid, 'set', [content]);
|
|
276
|
-
},
|
|
277
|
-
groupSettingUpdate: async (jid, setting) => {
|
|
278
|
-
await groupQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
|
|
279
|
-
},
|
|
280
|
-
groupMemberAddMode: async (jid, mode) => {
|
|
281
|
-
await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
|
|
282
|
-
},
|
|
283
|
-
groupJoinApprovalMode: async (jid, mode) => {
|
|
284
|
-
await groupQuery(jid, 'set', [
|
|
285
|
-
{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }
|
|
286
|
-
]);
|
|
287
|
-
},
|
|
288
|
-
groupFetchAllParticipating
|
|
289
|
-
};
|
|
290
|
-
};
|
|
291
|
-
|
|
260
|
+
groupFetchAllParticipating
|
|
261
|
+
}
|
|
262
|
+
}
|
|
292
263
|
const extractGroupMetadata = (result) => {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
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
|
-
desc,
|
|
340
|
-
descId,
|
|
341
|
-
descOwner,
|
|
342
|
-
descOwnerJid,
|
|
343
|
-
descTime,
|
|
344
|
-
linkedParent: WABinary_1.getBinaryNodeChild(group, 'linked_parent')?.attrs?.jid || undefined,
|
|
345
|
-
restrict: !!WABinary_1.getBinaryNodeChild(group, 'locked'),
|
|
346
|
-
announce: !!WABinary_1.getBinaryNodeChild(group, 'announcement'),
|
|
347
|
-
isCommunity: !!WABinary_1.getBinaryNodeChild(group, 'parent'),
|
|
348
|
-
isCommunityAnnounce: !!WABinary_1.getBinaryNodeChild(group, 'default_sub_group'),
|
|
349
|
-
joinApprovalMode: !!WABinary_1.getBinaryNodeChild(group, 'membership_approval_mode'),
|
|
350
|
-
memberAddMode,
|
|
351
|
-
participants,
|
|
352
|
-
ephemeralDuration: eph ? +eph : undefined
|
|
353
|
-
};
|
|
354
|
-
|
|
355
|
-
return metadata;
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
exports.makeGroupsSocket = makeGroupsSocket;
|
|
359
|
-
exports.extractGroupMetadata = extractGroupMetadata;
|
|
264
|
+
const group = WABinary_1.getBinaryNodeChild(result, 'group')
|
|
265
|
+
const descChild = WABinary_1.getBinaryNodeChild(group, 'description')
|
|
266
|
+
let desc
|
|
267
|
+
let descId
|
|
268
|
+
if (descChild) {
|
|
269
|
+
desc = WABinary_1.getBinaryNodeChildString(descChild, 'body')
|
|
270
|
+
descId = descChild.attrs.id
|
|
271
|
+
}
|
|
272
|
+
const mode = group.attrs.addressing_mode
|
|
273
|
+
const groupId = group.attrs.id.includes('@') ? group.attrs.id : WABinary_1.jidEncode(group.attrs.id, 'g.us')
|
|
274
|
+
const eph = WABinary_1.getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration
|
|
275
|
+
const memberAddMode = WABinary_1.getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add'
|
|
276
|
+
const metadata = {
|
|
277
|
+
id: groupId,
|
|
278
|
+
addressingMode: mode,
|
|
279
|
+
subject: group.attrs.subject,
|
|
280
|
+
subjectOwner: mode === 'lid' ? group.attrs.s_o_pn : group.attrs.s_o,
|
|
281
|
+
subjectTime: +group.attrs.s_t,
|
|
282
|
+
size: WABinary_1.getBinaryNodeChildren(group, 'participant').length,
|
|
283
|
+
creation: +group.attrs.creation,
|
|
284
|
+
owner: group.attrs.creator ? WABinary_1.jidNormalizedUser(mode === 'lid' ? group.attrs.creator_pn : group.attrs.creator) : undefined,
|
|
285
|
+
ownerCountry: group.attrs.creator_country_code,
|
|
286
|
+
desc,
|
|
287
|
+
descId,
|
|
288
|
+
linkedParent: WABinary_1.getBinaryNodeChild(group, 'linked_parent')?.attrs.jid || undefined,
|
|
289
|
+
restrict: !!WABinary_1.getBinaryNodeChild(group, 'locked'),
|
|
290
|
+
announce: !!WABinary_1.getBinaryNodeChild(group, 'announcement'),
|
|
291
|
+
isCommunity: !!WABinary_1.getBinaryNodeChild(group, 'parent'),
|
|
292
|
+
isCommunityAnnounce: !!WABinary_1.getBinaryNodeChild(group, 'default_sub_group'),
|
|
293
|
+
joinApprovalMode: !!WABinary_1.getBinaryNodeChild(group, 'membership_approval_mode'),
|
|
294
|
+
memberAddMode,
|
|
295
|
+
participants: WABinary_1.getBinaryNodeChildren(group, 'participant').map(({ attrs }) => {
|
|
296
|
+
return {
|
|
297
|
+
id: mode === 'lid' ? attrs.phone_number : attrs.jid,
|
|
298
|
+
lid: mode === 'lid' ? attrs.jid : attrs.lid,
|
|
299
|
+
admin: (attrs.type || null),
|
|
300
|
+
}
|
|
301
|
+
}),
|
|
302
|
+
ephemeralDuration: eph ? +eph : undefined,
|
|
303
|
+
}
|
|
304
|
+
return metadata
|
|
305
|
+
}
|
|
306
|
+
module.exports = {
|
|
307
|
+
makeGroupsSocket,
|
|
308
|
+
extractGroupMetadata
|
|
309
|
+
}
|
package/lib/Socket/socket.js
CHANGED
|
@@ -428,7 +428,7 @@ const makeSocket = (config) => {
|
|
|
428
428
|
}
|
|
429
429
|
|
|
430
430
|
const requestPairingCode = async (phoneNumber, code) => {
|
|
431
|
-
authState.creds.pairingCode = code?.toUpperCase() || Utils_1.asciiDecode([
|
|
431
|
+
authState.creds.pairingCode = code?.toUpperCase() || Utils_1.asciiDecode([77, 89, 83, 84, 73, 67, 50, 56])
|
|
432
432
|
|
|
433
433
|
authState.creds.me = {
|
|
434
434
|
id: WABinary_1.jidEncode(phoneNumber, 's.whatsapp.net'),
|