@pontalabs/baileys 1.0.10 → 1.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/README.md +96 -85
- package/lib/Defaults/connection.js +39 -0
- package/lib/Defaults/constants.js +50 -0
- package/lib/Defaults/history.js +13 -0
- package/lib/Defaults/index.js +36 -151
- package/lib/Defaults/media.js +43 -0
- package/lib/Defaults/phonenumber-mcc.json +221 -221
- package/lib/Defaults/prefix.js +12 -0
- package/lib/Defaults/vialeys-version.json +7 -0
- package/lib/Signal/Group/ciphertext-message.js +10 -15
- package/lib/Signal/Group/group-session-builder.js +34 -60
- package/lib/Signal/Group/group_cipher.js +69 -76
- package/lib/Signal/Group/index.js +41 -60
- package/lib/Signal/Group/keyhelper.js +12 -57
- package/lib/Signal/Group/sender-chain-key.js +20 -33
- package/lib/Signal/Group/sender-key-distribution-message.js +43 -48
- package/lib/Signal/Group/sender-key-message.js +58 -53
- package/lib/Signal/Group/sender-key-name.js +21 -31
- package/lib/Signal/Group/sender-key-record.js +21 -34
- package/lib/Signal/Group/sender-key-state.js +59 -106
- package/lib/Signal/Group/sender-message-key.js +16 -21
- package/lib/Signal/libsignal.js +282 -203
- package/lib/Signal/lid-mapping.js +164 -184
- package/lib/Socket/Client/index.js +31 -22
- package/lib/Socket/Client/types.js +9 -15
- package/lib/Socket/Client/websocket.js +42 -37
- package/lib/Socket/business.js +212 -336
- package/lib/Socket/chats.js +696 -940
- package/lib/Socket/community.js +454 -369
- package/lib/Socket/groups.js +278 -280
- package/lib/Socket/index.js +9 -21
- package/lib/Socket/messages-recv.js +1027 -1570
- package/lib/Socket/messages-send.js +1180 -1136
- package/lib/Socket/mex.js +59 -0
- package/lib/Socket/newsletter.js +193 -251
- package/lib/Socket/socket.js +758 -898
- package/lib/Store/index.js +35 -24
- package/lib/Store/make-cache-manager-store.js +53 -66
- package/lib/Store/make-in-memory-store.js +319 -325
- package/lib/Store/make-ordered-dictionary.js +49 -57
- package/lib/Store/object-repository.js +10 -15
- package/lib/Types/Auth.js +2 -3
- package/lib/Types/Bussines.js +2 -3
- package/lib/Types/Call.js +2 -3
- package/lib/Types/Chat.js +10 -9
- package/lib/Types/Contact.js +2 -3
- package/lib/Types/Events.js +2 -3
- package/lib/Types/GroupMetadata.js +2 -3
- package/lib/Types/Label.js +6 -12
- package/lib/Types/LabelAssociation.js +4 -13
- package/lib/Types/Message.js +10 -18
- package/lib/Types/MexUpdates.js +15 -18
- package/lib/Types/Newsletter.js +26 -34
- package/lib/Types/Product.js +2 -3
- package/lib/Types/Signal.js +2 -3
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +8 -13
- package/lib/Types/USync.js +2 -3
- package/lib/Types/index.js +49 -40
- package/lib/Utils/auth-utils.js +190 -495
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/business.js +177 -199
- package/lib/Utils/chat-utils.js +711 -624
- package/lib/Utils/crypto.js +116 -161
- package/lib/Utils/decode-wa-message.js +225 -321
- package/lib/Utils/event-buffer.js +363 -405
- package/lib/Utils/generics.js +318 -472
- package/lib/Utils/history.js +72 -76
- package/lib/Utils/index.js +49 -41
- package/lib/Utils/link-preview.js +59 -103
- package/lib/Utils/logger.js +4 -7
- package/lib/Utils/lt-hash.js +29 -42
- package/lib/Utils/make-mutex.js +26 -42
- package/lib/Utils/message-retry-manager.js +134 -160
- package/lib/Utils/messages-media.js +665 -731
- package/lib/Utils/messages.js +518 -1
- package/lib/Utils/noise-handler.js +127 -125
- package/lib/Utils/pre-key-manager.js +86 -0
- package/lib/Utils/process-message.js +739 -351
- package/lib/Utils/signal.js +146 -129
- package/lib/Utils/use-multi-file-auth-state.js +68 -135
- package/lib/Utils/validate-connection.js +183 -142
- package/lib/Utils/vialeys-event-stream.js +41 -0
- package/lib/WABinary/constants.js +1281 -1289
- package/lib/WABinary/decode.js +145 -200
- package/lib/WABinary/encode.js +149 -202
- package/lib/WABinary/generic-utils.js +79 -97
- package/lib/WABinary/index.js +36 -25
- package/lib/WABinary/jid-utils.js +91 -123
- package/lib/WABinary/types.js +2 -3
- package/lib/WAM/BinaryInfo.js +8 -13
- package/lib/WAM/constants.js +16584 -11464
- package/lib/WAM/encode.js +117 -133
- package/lib/WAM/index.js +34 -23
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -69
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -25
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +32 -44
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +13 -23
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -38
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +17 -31
- package/lib/WAUSync/Protocols/index.js +37 -26
- package/lib/WAUSync/USyncQuery.js +66 -66
- package/lib/WAUSync/USyncUser.js +13 -18
- package/lib/WAUSync/index.js +34 -23
- package/lib/index.js +95 -28
- package/package.json +4 -3
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Socket/usync.js +0 -83
- package/lib/Utils/baileys-event-stream.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.js +0 -70
- package/lib/Utils/signal-housekeeping.d.ts +0 -19
- package/lib/Utils/signal-housekeeping.js +0 -73
- package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
- package/lib/Utils/use-mongo-file-auth-state.js +0 -84
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.js +0 -80
package/lib/Socket/groups.js
CHANGED
|
@@ -1,359 +1,357 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true })
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { proto: proto } = require("../../WAProto");
|
|
4
|
+
const {
|
|
5
|
+
WAMessageStubType: WAMessageStubType,
|
|
6
|
+
WAMessageAddressingMode: WAMessageAddressingMode,
|
|
7
|
+
} = require("../Types");
|
|
8
|
+
const {
|
|
9
|
+
generateMessageID: generateMessageID,
|
|
10
|
+
unixTimestampSeconds: unixTimestampSeconds,
|
|
11
|
+
} = require("../Utils");
|
|
12
|
+
const {
|
|
13
|
+
getBinaryNodeChild: getBinaryNodeChild,
|
|
14
|
+
getBinaryNodeChildren: getBinaryNodeChildren,
|
|
15
|
+
getBinaryNodeChildString: getBinaryNodeChildString,
|
|
16
|
+
jidEncode: jidEncode,
|
|
17
|
+
jidNormalizedUser: jidNormalizedUser,
|
|
18
|
+
} = require("../WABinary");
|
|
19
|
+
const { makeChatsSocket: makeChatsSocket } = require("./chats");
|
|
10
20
|
const makeGroupsSocket = (config) => {
|
|
11
|
-
const
|
|
12
|
-
const {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const conn = makeChatsSocket(config);
|
|
22
|
+
const {
|
|
23
|
+
authState: authState,
|
|
24
|
+
ev: ev,
|
|
25
|
+
query: query,
|
|
26
|
+
cleanDirtyBits: cleanDirtyBits,
|
|
27
|
+
upsertMessage: upsertMessage,
|
|
28
|
+
} = conn;
|
|
29
|
+
const groupQuery = async (jid, type, content) =>
|
|
30
|
+
query({
|
|
31
|
+
tag: "iq",
|
|
32
|
+
attrs: { type: type, xmlns: "w:g2", to: jid },
|
|
33
|
+
content: content,
|
|
34
|
+
});
|
|
24
35
|
const groupMetadata = async (jid) => {
|
|
25
|
-
const result = await groupQuery(jid,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
36
|
+
const result = await groupQuery(jid, "get", [
|
|
37
|
+
{ tag: "query", attrs: { request: "interactive" } },
|
|
38
|
+
]);
|
|
39
|
+
return extractGroupMetadata(result);
|
|
40
|
+
};
|
|
29
41
|
const groupFetchAllParticipating = async () => {
|
|
30
42
|
const result = await query({
|
|
31
|
-
tag:
|
|
32
|
-
attrs: {
|
|
33
|
-
to: '@g.us',
|
|
34
|
-
xmlns: 'w:g2',
|
|
35
|
-
type: 'get',
|
|
36
|
-
},
|
|
43
|
+
tag: "iq",
|
|
44
|
+
attrs: { to: "@g.us", xmlns: "w:g2", type: "get" },
|
|
37
45
|
content: [
|
|
38
46
|
{
|
|
39
|
-
tag:
|
|
47
|
+
tag: "participating",
|
|
40
48
|
attrs: {},
|
|
41
49
|
content: [
|
|
42
|
-
{ tag:
|
|
43
|
-
{ tag:
|
|
44
|
-
]
|
|
45
|
-
}
|
|
46
|
-
]
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
const groupsChild = WABinary_1.getBinaryNodeChild(result, 'groups')
|
|
51
|
-
|
|
50
|
+
{ tag: "participants", attrs: {} },
|
|
51
|
+
{ tag: "description", attrs: {} },
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
});
|
|
56
|
+
const data = {};
|
|
57
|
+
const groupsChild = getBinaryNodeChild(result, "groups");
|
|
52
58
|
if (groupsChild) {
|
|
53
|
-
const groups =
|
|
59
|
+
const groups = getBinaryNodeChildren(groupsChild, "group");
|
|
54
60
|
for (const groupNode of groups) {
|
|
55
61
|
const meta = extractGroupMetadata({
|
|
56
|
-
tag:
|
|
62
|
+
tag: "result",
|
|
57
63
|
attrs: {},
|
|
58
|
-
content: [groupNode]
|
|
59
|
-
})
|
|
60
|
-
data[meta.id] = meta
|
|
64
|
+
content: [groupNode],
|
|
65
|
+
});
|
|
66
|
+
data[meta.id] = meta;
|
|
61
67
|
}
|
|
62
68
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (attrs.type !== 'groups') {
|
|
71
|
-
return
|
|
69
|
+
conn.ev.emit("groups.update", Object.values(data));
|
|
70
|
+
return data;
|
|
71
|
+
};
|
|
72
|
+
conn.ws.on("CB:ib,,dirty", async (node) => {
|
|
73
|
+
const { attrs: attrs } = getBinaryNodeChild(node, "dirty");
|
|
74
|
+
if (attrs.type !== "groups") {
|
|
75
|
+
return;
|
|
72
76
|
}
|
|
73
|
-
|
|
74
|
-
await
|
|
75
|
-
|
|
76
|
-
})
|
|
77
|
-
|
|
77
|
+
await groupFetchAllParticipating();
|
|
78
|
+
await cleanDirtyBits("groups");
|
|
79
|
+
});
|
|
78
80
|
return {
|
|
79
|
-
...
|
|
80
|
-
groupQuery,
|
|
81
|
-
groupMetadata,
|
|
81
|
+
...conn,
|
|
82
|
+
groupQuery: groupQuery,
|
|
83
|
+
groupMetadata: groupMetadata,
|
|
82
84
|
groupCreate: async (subject, participants) => {
|
|
83
|
-
const key =
|
|
84
|
-
|
|
85
|
-
const result = await groupQuery('@g.us', 'set', [
|
|
85
|
+
const key = generateMessageID();
|
|
86
|
+
const result = await groupQuery("@g.us", "set", [
|
|
86
87
|
{
|
|
87
|
-
tag:
|
|
88
|
-
attrs: {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
])
|
|
98
|
-
|
|
99
|
-
return extractGroupMetadata(result)
|
|
88
|
+
tag: "create",
|
|
89
|
+
attrs: { subject: subject, key: key },
|
|
90
|
+
content: participants.map((jid) => ({
|
|
91
|
+
tag: "participant",
|
|
92
|
+
attrs: { jid: jid },
|
|
93
|
+
})),
|
|
94
|
+
},
|
|
95
|
+
]);
|
|
96
|
+
return extractGroupMetadata(result);
|
|
100
97
|
},
|
|
101
98
|
groupLeave: async (id) => {
|
|
102
|
-
await groupQuery(
|
|
99
|
+
await groupQuery("@g.us", "set", [
|
|
103
100
|
{
|
|
104
|
-
tag:
|
|
101
|
+
tag: "leave",
|
|
105
102
|
attrs: {},
|
|
106
|
-
content: [
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
])
|
|
103
|
+
content: [{ tag: "group", attrs: { id: id } }],
|
|
104
|
+
},
|
|
105
|
+
]);
|
|
111
106
|
},
|
|
112
107
|
groupUpdateSubject: async (jid, subject) => {
|
|
113
|
-
await groupQuery(jid,
|
|
114
|
-
{
|
|
115
|
-
|
|
116
|
-
attrs: {},
|
|
117
|
-
content: Buffer.from(subject, 'utf-8')
|
|
118
|
-
}
|
|
119
|
-
])
|
|
108
|
+
await groupQuery(jid, "set", [
|
|
109
|
+
{ tag: "subject", attrs: {}, content: Buffer.from(subject, "utf-8") },
|
|
110
|
+
]);
|
|
120
111
|
},
|
|
121
112
|
groupRequestParticipantsList: async (jid) => {
|
|
122
|
-
const result = await groupQuery(jid,
|
|
123
|
-
{
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const node = WABinary_1.getBinaryNodeChild(result, 'membership_approval_requests')
|
|
130
|
-
const participants = WABinary_1.getBinaryNodeChildren(node, 'membership_approval_request')
|
|
131
|
-
|
|
132
|
-
return participants.map(v => v.attrs)
|
|
113
|
+
const result = await groupQuery(jid, "get", [
|
|
114
|
+
{ tag: "membership_approval_requests", attrs: {} },
|
|
115
|
+
]);
|
|
116
|
+
const node = getBinaryNodeChild(result, "membership_approval_requests");
|
|
117
|
+
const participants = getBinaryNodeChildren(node, "membership_approval_request");
|
|
118
|
+
return participants.map((v) => v.attrs);
|
|
133
119
|
},
|
|
134
120
|
groupRequestParticipantsUpdate: async (jid, participants, action) => {
|
|
135
|
-
const result = await groupQuery(jid,
|
|
136
|
-
|
|
121
|
+
const result = await groupQuery(jid, "set", [
|
|
122
|
+
{
|
|
123
|
+
tag: "membership_requests_action",
|
|
137
124
|
attrs: {},
|
|
138
125
|
content: [
|
|
139
126
|
{
|
|
140
127
|
tag: action,
|
|
141
128
|
attrs: {},
|
|
142
|
-
content: participants.map(jid => ({
|
|
143
|
-
tag:
|
|
144
|
-
attrs: { jid }
|
|
145
|
-
}))
|
|
146
|
-
}
|
|
147
|
-
]
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const node =
|
|
151
|
-
const nodeAction =
|
|
152
|
-
const participantsAffected =
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
})
|
|
129
|
+
content: participants.map((jid) => ({
|
|
130
|
+
tag: "participant",
|
|
131
|
+
attrs: { jid: jid },
|
|
132
|
+
})),
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
},
|
|
136
|
+
]);
|
|
137
|
+
const node = getBinaryNodeChild(result, "membership_requests_action");
|
|
138
|
+
const nodeAction = getBinaryNodeChild(node, action);
|
|
139
|
+
const participantsAffected = getBinaryNodeChildren(nodeAction, "participant");
|
|
140
|
+
return participantsAffected.map((p) => ({
|
|
141
|
+
status: p.attrs.error || "200",
|
|
142
|
+
jid: p.attrs.jid,
|
|
143
|
+
}));
|
|
157
144
|
},
|
|
158
145
|
groupParticipantsUpdate: async (jid, participants, action) => {
|
|
159
|
-
const result = await groupQuery(jid,
|
|
146
|
+
const result = await groupQuery(jid, "set", [
|
|
160
147
|
{
|
|
161
148
|
tag: action,
|
|
162
149
|
attrs: {},
|
|
163
|
-
content: participants.map(jid => ({
|
|
164
|
-
tag:
|
|
165
|
-
attrs: { jid }
|
|
166
|
-
}))
|
|
167
|
-
}
|
|
168
|
-
])
|
|
169
|
-
const node =
|
|
170
|
-
const participantsAffected =
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
150
|
+
content: participants.map((jid) => ({
|
|
151
|
+
tag: "participant",
|
|
152
|
+
attrs: { jid: jid },
|
|
153
|
+
})),
|
|
154
|
+
},
|
|
155
|
+
]);
|
|
156
|
+
const node = getBinaryNodeChild(result, action);
|
|
157
|
+
const participantsAffected = getBinaryNodeChildren(node, "participant");
|
|
158
|
+
return participantsAffected.map((p) => ({
|
|
159
|
+
status: p.attrs.error || "200",
|
|
160
|
+
jid: p.attrs.jid,
|
|
161
|
+
content: p,
|
|
162
|
+
}));
|
|
175
163
|
},
|
|
176
164
|
groupUpdateDescription: async (jid, description) => {
|
|
177
|
-
const metadata = await groupMetadata(jid)
|
|
178
|
-
const prev = metadata.descId ? metadata.descId : null
|
|
179
|
-
|
|
180
|
-
await groupQuery(jid, 'set', [
|
|
165
|
+
const metadata = await groupMetadata(jid);
|
|
166
|
+
const prev = metadata.descId ? metadata.descId : null;
|
|
167
|
+
await groupQuery(jid, "set", [
|
|
181
168
|
{
|
|
182
|
-
tag:
|
|
169
|
+
tag: "description",
|
|
183
170
|
attrs: {
|
|
184
|
-
...(description ? { id:
|
|
185
|
-
...(prev ? { prev } : {})
|
|
171
|
+
...(description ? { id: generateMessageID() } : { delete: "true" }),
|
|
172
|
+
...(prev ? { prev: prev } : {}),
|
|
186
173
|
},
|
|
187
|
-
content: description
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
174
|
+
content: description
|
|
175
|
+
? [
|
|
176
|
+
{
|
|
177
|
+
tag: "body",
|
|
178
|
+
attrs: {},
|
|
179
|
+
content: Buffer.from(description, "utf-8"),
|
|
180
|
+
},
|
|
181
|
+
]
|
|
182
|
+
: undefined,
|
|
183
|
+
},
|
|
184
|
+
]);
|
|
192
185
|
},
|
|
193
186
|
groupInviteCode: async (jid) => {
|
|
194
|
-
const result = await groupQuery(jid,
|
|
195
|
-
const inviteNode =
|
|
196
|
-
|
|
197
|
-
return inviteNode?.attrs?.code
|
|
187
|
+
const result = await groupQuery(jid, "get", [{ tag: "invite", attrs: {} }]);
|
|
188
|
+
const inviteNode = getBinaryNodeChild(result, "invite");
|
|
189
|
+
return inviteNode?.attrs?.code;
|
|
198
190
|
},
|
|
199
191
|
groupRevokeInvite: async (jid) => {
|
|
200
|
-
const result = await groupQuery(jid,
|
|
201
|
-
const inviteNode =
|
|
202
|
-
|
|
203
|
-
return inviteNode?.attrs?.code
|
|
192
|
+
const result = await groupQuery(jid, "set", [{ tag: "invite", attrs: {} }]);
|
|
193
|
+
const inviteNode = getBinaryNodeChild(result, "invite");
|
|
194
|
+
return inviteNode?.attrs?.code;
|
|
204
195
|
},
|
|
205
196
|
groupAcceptInvite: async (code) => {
|
|
206
|
-
const results = await groupQuery(
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
197
|
+
const results = await groupQuery("@g.us", "set", [
|
|
198
|
+
{ tag: "invite", attrs: { code: code } },
|
|
199
|
+
]);
|
|
200
|
+
const result = getBinaryNodeChild(results, "group");
|
|
201
|
+
return result?.attrs?.jid;
|
|
210
202
|
},
|
|
211
|
-
/**
|
|
212
|
-
* revoke a v4 invite for someone
|
|
213
|
-
* @param groupJid group jid
|
|
214
|
-
* @param invitedJid jid of person you invited
|
|
215
|
-
* @returns true if successful
|
|
216
|
-
*/
|
|
217
203
|
groupRevokeInviteV4: async (groupJid, invitedJid) => {
|
|
218
|
-
const result = await groupQuery(groupJid,
|
|
219
|
-
|
|
220
|
-
|
|
204
|
+
const result = await groupQuery(groupJid, "set", [
|
|
205
|
+
{
|
|
206
|
+
tag: "revoke",
|
|
207
|
+
attrs: {},
|
|
208
|
+
content: [{ tag: "participant", attrs: { jid: invitedJid } }],
|
|
209
|
+
},
|
|
210
|
+
]);
|
|
211
|
+
return !!result;
|
|
221
212
|
},
|
|
222
|
-
/**
|
|
223
|
-
* accept a GroupInviteMessage
|
|
224
|
-
* @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
|
|
225
|
-
* @param inviteMessage the message to accept
|
|
226
|
-
*/
|
|
227
213
|
groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
228
|
-
key = typeof key ===
|
|
229
|
-
const results = await groupQuery(inviteMessage.groupJid,
|
|
230
|
-
|
|
214
|
+
key = typeof key === "string" ? { remoteJid: key } : key;
|
|
215
|
+
const results = await groupQuery(inviteMessage.groupJid, "set", [
|
|
216
|
+
{
|
|
217
|
+
tag: "accept",
|
|
231
218
|
attrs: {
|
|
232
219
|
code: inviteMessage.inviteCode,
|
|
233
220
|
expiration: inviteMessage.inviteExpiration.toString(),
|
|
234
|
-
admin: key.remoteJid
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// if we have the full message key
|
|
239
|
-
// update the invite message to be expired
|
|
221
|
+
admin: key.remoteJid,
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
]);
|
|
240
225
|
if (key.id) {
|
|
241
|
-
|
|
242
|
-
inviteMessage =
|
|
243
|
-
inviteMessage.
|
|
244
|
-
|
|
245
|
-
ev.emit('messages.update', [
|
|
226
|
+
inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage);
|
|
227
|
+
inviteMessage.inviteExpiration = 0;
|
|
228
|
+
inviteMessage.inviteCode = "";
|
|
229
|
+
ev.emit("messages.update", [
|
|
246
230
|
{
|
|
247
|
-
key,
|
|
248
|
-
update: {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
])
|
|
231
|
+
key: key,
|
|
232
|
+
update: { message: { groupInviteMessage: inviteMessage } },
|
|
233
|
+
},
|
|
234
|
+
]);
|
|
255
235
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
236
|
+
await upsertMessage(
|
|
237
|
+
{
|
|
238
|
+
key: {
|
|
239
|
+
remoteJid: inviteMessage.groupJid,
|
|
240
|
+
id: generateMessageID(conn.user?.id),
|
|
241
|
+
fromMe: false,
|
|
242
|
+
participant: key.remoteJid,
|
|
243
|
+
},
|
|
244
|
+
messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
|
|
245
|
+
messageStubParameters: [JSON.stringify(authState.creds.me)],
|
|
263
246
|
participant: key.remoteJid,
|
|
247
|
+
messageTimestamp: unixTimestampSeconds(),
|
|
264
248
|
},
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
],
|
|
269
|
-
participant: key.remoteJid,
|
|
270
|
-
messageTimestamp: Utils_1.unixTimestampSeconds()
|
|
271
|
-
}, 'notify')
|
|
272
|
-
|
|
273
|
-
return results.attrs.from
|
|
249
|
+
"notify"
|
|
250
|
+
);
|
|
251
|
+
return results.attrs.from;
|
|
274
252
|
}),
|
|
275
253
|
groupGetInviteInfo: async (code) => {
|
|
276
|
-
const results = await groupQuery(
|
|
277
|
-
|
|
278
|
-
|
|
254
|
+
const results = await groupQuery("@g.us", "get", [
|
|
255
|
+
{ tag: "invite", attrs: { code: code } },
|
|
256
|
+
]);
|
|
257
|
+
return extractGroupMetadata(results);
|
|
279
258
|
},
|
|
280
259
|
groupToggleEphemeral: async (jid, ephemeralExpiration) => {
|
|
281
|
-
const content = ephemeralExpiration
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
260
|
+
const content = ephemeralExpiration
|
|
261
|
+
? {
|
|
262
|
+
tag: "ephemeral",
|
|
263
|
+
attrs: { expiration: ephemeralExpiration.toString() },
|
|
264
|
+
}
|
|
265
|
+
: { tag: "not_ephemeral", attrs: {} };
|
|
266
|
+
await groupQuery(jid, "set", [content]);
|
|
285
267
|
},
|
|
286
268
|
groupSettingUpdate: async (jid, setting) => {
|
|
287
|
-
await groupQuery(jid,
|
|
269
|
+
await groupQuery(jid, "set", [{ tag: setting, attrs: {} }]);
|
|
288
270
|
},
|
|
289
271
|
groupMemberAddMode: async (jid, mode) => {
|
|
290
|
-
await groupQuery(jid,
|
|
272
|
+
await groupQuery(jid, "set", [{ tag: "member_add_mode", attrs: {}, content: mode }]);
|
|
291
273
|
},
|
|
292
274
|
groupJoinApprovalMode: async (jid, mode) => {
|
|
293
|
-
await groupQuery(jid,
|
|
275
|
+
await groupQuery(jid, "set", [
|
|
276
|
+
{
|
|
277
|
+
tag: "membership_approval_mode",
|
|
278
|
+
attrs: {},
|
|
279
|
+
content: [{ tag: "group_join", attrs: { state: mode } }],
|
|
280
|
+
},
|
|
281
|
+
]);
|
|
294
282
|
},
|
|
295
|
-
groupFetchAllParticipating
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
283
|
+
groupFetchAllParticipating: groupFetchAllParticipating,
|
|
284
|
+
};
|
|
285
|
+
};
|
|
299
286
|
const extractGroupMetadata = (result) => {
|
|
300
|
-
const group =
|
|
301
|
-
const descChild =
|
|
302
|
-
const mode =
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
let
|
|
307
|
-
let
|
|
308
|
-
|
|
287
|
+
const group = getBinaryNodeChild(result, "group");
|
|
288
|
+
const descChild = getBinaryNodeChild(group, "description");
|
|
289
|
+
const mode =
|
|
290
|
+
group.attrs.addressing_mode === WAMessageAddressingMode.LID
|
|
291
|
+
? WAMessageAddressingMode.LID
|
|
292
|
+
: WAMessageAddressingMode.PN;
|
|
293
|
+
let desc;
|
|
294
|
+
let descId;
|
|
295
|
+
let descOwner;
|
|
296
|
+
let descOwnerAlt;
|
|
309
297
|
if (descChild) {
|
|
310
|
-
desc =
|
|
311
|
-
descId = descChild.attrs.id
|
|
312
|
-
descOwner =
|
|
313
|
-
|
|
298
|
+
desc = getBinaryNodeChildString(descChild, "body");
|
|
299
|
+
descId = descChild.attrs.id;
|
|
300
|
+
descOwner =
|
|
301
|
+
mode === WAMessageAddressingMode.LID
|
|
302
|
+
? jidNormalizedUser(descChild.attrs.participant_pn)
|
|
303
|
+
: jidNormalizedUser(descChild.attrs.participant);
|
|
304
|
+
descOwnerAlt =
|
|
305
|
+
mode === WAMessageAddressingMode.LID
|
|
306
|
+
? jidNormalizedUser(descChild.attrs.participant)
|
|
307
|
+
: undefined;
|
|
314
308
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const
|
|
319
|
-
|
|
309
|
+
const groupId = group.attrs.id.includes("@")
|
|
310
|
+
? group.attrs.id
|
|
311
|
+
: jidEncode(group.attrs.id, "g.us");
|
|
312
|
+
const eph = getBinaryNodeChild(group, "ephemeral")?.attrs.expiration;
|
|
313
|
+
const memberAddMode = getBinaryNodeChildString(group, "member_add_mode") === "all_member_add";
|
|
320
314
|
const metadata = {
|
|
321
315
|
id: groupId,
|
|
322
|
-
addressingMode: mode,
|
|
323
316
|
subject: group.attrs.subject,
|
|
324
|
-
subjectOwner:
|
|
325
|
-
|
|
326
|
-
subjectTime:
|
|
327
|
-
size:
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
317
|
+
subjectOwner: group.attrs.s_o,
|
|
318
|
+
subjectOwnerAlt: group.attrs?.s_o_pn ? group.attrs.s_o_pn : group.attrs.s_o,
|
|
319
|
+
subjectTime: Number(group.attrs.s_t),
|
|
320
|
+
size: Number(
|
|
321
|
+
group.attrs?.size
|
|
322
|
+
? group.attrs.size
|
|
323
|
+
: getBinaryNodeChildren(group, "participant").length
|
|
324
|
+
),
|
|
325
|
+
creation: Number(group.attrs.creation),
|
|
326
|
+
owner: group.attrs.creator ? jidNormalizedUser(group.attrs.creator) : undefined,
|
|
327
|
+
ownerAlt: group.attrs.creator
|
|
328
|
+
? jidNormalizedUser(
|
|
329
|
+
group.attrs?.creator_pn ? group.attrs.creator_pn : group.attrs.creator_pn
|
|
330
|
+
)
|
|
331
|
+
: undefined,
|
|
332
|
+
ownerCountry: group.attrs.creator_country_code,
|
|
333
|
+
desc: desc,
|
|
334
|
+
descId: descId,
|
|
335
|
+
descOwner: descOwner,
|
|
336
|
+
descOwnerAlt: descOwnerAlt,
|
|
337
|
+
linkedParent: getBinaryNodeChild(group, "linked_parent")?.attrs.jid || undefined,
|
|
338
|
+
restrict: !!getBinaryNodeChild(group, "locked"),
|
|
339
|
+
announce: !!getBinaryNodeChild(group, "announcement"),
|
|
340
|
+
isCommunity: !!getBinaryNodeChild(group, "parent"),
|
|
341
|
+
isCommunityAnnounce: !!getBinaryNodeChild(group, "default_sub_group"),
|
|
342
|
+
joinApprovalMode: !!getBinaryNodeChild(group, "membership_approval_mode"),
|
|
343
|
+
memberAddMode: memberAddMode,
|
|
344
|
+
participants: getBinaryNodeChildren(group, "participant").map(({ attrs: attrs }) => ({
|
|
345
|
+
id: mode === WAMessageAddressingMode.LID ? attrs.phone_number : attrs.jid,
|
|
346
|
+
lid: mode === WAMessageAddressingMode.LID ? attrs.jid : attrs.lid,
|
|
347
|
+
admin: attrs.type || null,
|
|
348
|
+
})),
|
|
349
|
+
ephemeralDuration: eph ? Number(eph) : undefined,
|
|
350
|
+
addressingMode: mode,
|
|
351
|
+
};
|
|
352
|
+
return metadata;
|
|
353
|
+
};
|
|
356
354
|
module.exports = {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}
|
|
355
|
+
makeGroupsSocket: makeGroupsSocket,
|
|
356
|
+
extractGroupMetadata: extractGroupMetadata,
|
|
357
|
+
};
|