@aseppxyzz12/baileys 1.1.8
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 +25 -0
- package/README.md +2579 -0
- package/WAProto/AICommon/AICommon.js +19396 -0
- package/WAProto/AICommon/AICommon.proto +820 -0
- package/WAProto/Adv/Adv.js +1137 -0
- package/WAProto/Adv/Adv.proto +42 -0
- package/WAProto/BotMetadata/BotMetadata.js +8975 -0
- package/WAProto/BotMetadata/BotMetadata.proto +484 -0
- package/WAProto/Cert/Cert.js +893 -0
- package/WAProto/Cert/Cert.proto +30 -0
- package/WAProto/ChatLockSettings/ChatLockSettings.js +673 -0
- package/WAProto/ChatLockSettings/ChatLockSettings.proto +9 -0
- package/WAProto/CompanionReg/CompanionReg.js +2457 -0
- package/WAProto/CompanionReg/CompanionReg.proto +103 -0
- package/WAProto/DeviceCapabilities/DeviceCapabilities.js +846 -0
- package/WAProto/DeviceCapabilities/DeviceCapabilities.proto +38 -0
- package/WAProto/E2E/E2E.js +78728 -0
- package/WAProto/E2E/E2E.proto +1970 -0
- package/WAProto/Ephemeral/Ephemeral.js +143 -0
- package/WAProto/Ephemeral/Ephemeral.proto +7 -0
- package/WAProto/HistorySync/HistorySync.js +95931 -0
- package/WAProto/HistorySync/HistorySync.proto +229 -0
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.js +414 -0
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.proto +13 -0
- package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.js +980 -0
- package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.proto +38 -0
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +81185 -0
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.proto +88 -0
- package/WAProto/MmsRetry/MmsRetry.js +310 -0
- package/WAProto/MmsRetry/MmsRetry.proto +19 -0
- package/WAProto/Protocol/Protocol.js +399 -0
- package/WAProto/Protocol/Protocol.proto +22 -0
- package/WAProto/Reporting/Reporting.js +535 -0
- package/WAProto/Reporting/Reporting.proto +22 -0
- package/WAProto/ServerSync/ServerSync.js +1830 -0
- package/WAProto/ServerSync/ServerSync.proto +70 -0
- package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.js +3267 -0
- package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.proto +95 -0
- package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.js +1140 -0
- package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.proto +44 -0
- package/WAProto/StatusAttributions/StatusAttributions.js +1604 -0
- package/WAProto/StatusAttributions/StatusAttributions.proto +89 -0
- package/WAProto/SyncAction/SyncAction.js +17424 -0
- package/WAProto/SyncAction/SyncAction.proto +663 -0
- package/WAProto/UserPassword/UserPassword.js +544 -0
- package/WAProto/UserPassword/UserPassword.proto +28 -0
- package/WAProto/VnameCert/VnameCert.js +1466 -0
- package/WAProto/VnameCert/VnameCert.proto +65 -0
- package/WAProto/Wa6/Wa6.js +4601 -0
- package/WAProto/Wa6/Wa6.proto +241 -0
- package/WAProto/Web/Web.js +90819 -0
- package/WAProto/Web/Web.proto +605 -0
- package/WAProto/index.js +30 -0
- package/engine-requirements.js +9 -0
- package/lib/Defaults/baileys-version.json +3 -0
- 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 -0
- package/lib/Defaults/media.js +43 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/prefix.js +12 -0
- package/lib/Function/Download/tiktok.js +19 -0
- package/lib/Function/Tools/bypass.js +19 -0
- package/lib/Function/index.js +13 -0
- package/lib/Signal/Group/ciphertext-message.js +14 -0
- package/lib/Signal/Group/group-session-builder.js +46 -0
- package/lib/Signal/Group/group_cipher.js +104 -0
- package/lib/Signal/Group/index.js +42 -0
- package/lib/Signal/Group/keyhelper.js +21 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.js +78 -0
- package/lib/Signal/Group/sender-key-name.js +49 -0
- package/lib/Signal/Group/sender-key-record.js +45 -0
- package/lib/Signal/Group/sender-key-state.js +100 -0
- package/lib/Signal/Group/sender-message-key.js +28 -0
- package/lib/Signal/libsignal.js +364 -0
- package/lib/Signal/lid-mapping.js +164 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +31 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/types.js +12 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/Client/websocket.js +67 -0
- package/lib/Socket/business.js +291 -0
- package/lib/Socket/chats.js +874 -0
- package/lib/Socket/community.js +454 -0
- package/lib/Socket/dugong.js +658 -0
- package/lib/Socket/groups.js +357 -0
- package/lib/Socket/index.js +13 -0
- package/lib/Socket/messages-recv.js +1509 -0
- package/lib/Socket/messages-send.js +1505 -0
- package/lib/Socket/mex.js +54 -0
- package/lib/Socket/newsletter.js +171 -0
- package/lib/Socket/registration.js +167 -0
- package/lib/Socket/rich-content.js +279 -0
- package/lib/Socket/socket.js +905 -0
- package/lib/Socket/username.js +157 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.js +37 -0
- package/lib/Store/keyed-db.js +114 -0
- package/lib/Store/make-cache-manager-store.js +77 -0
- package/lib/Store/make-in-memory-store.js +423 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.js +26 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +10 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/LabelAssociation.js +4 -0
- package/lib/Types/Message.js +11 -0
- package/lib/Types/Mex.js +40 -0
- package/lib/Types/MexUpdates.js +15 -0
- package/lib/Types/Newsletter.js +32 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +9 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +60 -0
- package/lib/Utils/auth-utils.js +256 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/bot-toolkit.js +455 -0
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/business.js +233 -0
- package/lib/Utils/chat-utils.js +904 -0
- package/lib/Utils/companion-reg-client-utils.js +41 -0
- package/lib/Utils/crypto.js +144 -0
- package/lib/Utils/decode-wa-message.js +305 -0
- package/lib/Utils/event-buffer.js +555 -0
- package/lib/Utils/generics.js +411 -0
- package/lib/Utils/history.js +100 -0
- package/lib/Utils/identity-change-handler.js +53 -0
- package/lib/Utils/index.js +57 -0
- package/lib/Utils/link-preview.js +76 -0
- package/lib/Utils/logger.js +4 -0
- package/lib/Utils/lt-hash.js +45 -0
- package/lib/Utils/make-mutex.js +33 -0
- package/lib/Utils/message-composer.js +289 -0
- package/lib/Utils/message-retry-manager.js +134 -0
- package/lib/Utils/messages-media.js +806 -0
- package/lib/Utils/messages.js +1908 -0
- package/lib/Utils/noise-handler.js +157 -0
- package/lib/Utils/offline-node-processor.js +42 -0
- package/lib/Utils/pre-key-manager.js +86 -0
- package/lib/Utils/process-message.js +814 -0
- package/lib/Utils/reporting-utils.js +264 -0
- package/lib/Utils/signal.js +183 -0
- package/lib/Utils/stanza-ack.js +36 -0
- package/lib/Utils/sync-action-utils.js +52 -0
- package/lib/Utils/tc-token-utils.js +167 -0
- package/lib/Utils/use-multi-file-auth-state.js +104 -0
- package/lib/Utils/validate-connection.js +229 -0
- package/lib/Utils/vialeys-event-stream.js +41 -0
- package/lib/WABinary/constants.js +1308 -0
- package/lib/WABinary/decode.js +233 -0
- package/lib/WABinary/encode.js +212 -0
- package/lib/WABinary/generic-utils.js +124 -0
- package/lib/WABinary/index.js +36 -0
- package/lib/WABinary/jid-utils.js +101 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +12 -0
- package/lib/WAM/constants.js +20491 -0
- package/lib/WAM/encode.js +148 -0
- package/lib/WAM/index.js +34 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +50 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +25 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.js +38 -0
- package/lib/WAUSync/USyncQuery.js +97 -0
- package/lib/WAUSync/USyncUser.js +33 -0
- package/lib/WAUSync/index.js +34 -0
- package/lib/index.js +113 -0
- package/lib/messages-send.js +1496 -0
- package/package.json +100 -0
|
@@ -0,0 +1,357 @@
|
|
|
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");
|
|
20
|
+
const makeGroupsSocket = (config) => {
|
|
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
|
+
});
|
|
35
|
+
const groupMetadata = async (jid) => {
|
|
36
|
+
const result = await groupQuery(jid, "get", [
|
|
37
|
+
{ tag: "query", attrs: { request: "interactive" } },
|
|
38
|
+
]);
|
|
39
|
+
return extractGroupMetadata(result);
|
|
40
|
+
};
|
|
41
|
+
const groupFetchAllParticipating = async () => {
|
|
42
|
+
const result = await query({
|
|
43
|
+
tag: "iq",
|
|
44
|
+
attrs: { to: "@g.us", xmlns: "w:g2", type: "get" },
|
|
45
|
+
content: [
|
|
46
|
+
{
|
|
47
|
+
tag: "participating",
|
|
48
|
+
attrs: {},
|
|
49
|
+
content: [
|
|
50
|
+
{ tag: "participants", attrs: {} },
|
|
51
|
+
{ tag: "description", attrs: {} },
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
});
|
|
56
|
+
const data = {};
|
|
57
|
+
const groupsChild = getBinaryNodeChild(result, "groups");
|
|
58
|
+
if (groupsChild) {
|
|
59
|
+
const groups = getBinaryNodeChildren(groupsChild, "group");
|
|
60
|
+
for (const groupNode of groups) {
|
|
61
|
+
const meta = extractGroupMetadata({
|
|
62
|
+
tag: "result",
|
|
63
|
+
attrs: {},
|
|
64
|
+
content: [groupNode],
|
|
65
|
+
});
|
|
66
|
+
data[meta.id] = meta;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
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;
|
|
76
|
+
}
|
|
77
|
+
await groupFetchAllParticipating();
|
|
78
|
+
await cleanDirtyBits("groups");
|
|
79
|
+
});
|
|
80
|
+
return {
|
|
81
|
+
...conn,
|
|
82
|
+
groupQuery: groupQuery,
|
|
83
|
+
groupMetadata: groupMetadata,
|
|
84
|
+
groupCreate: async (subject, participants) => {
|
|
85
|
+
const key = generateMessageID();
|
|
86
|
+
const result = await groupQuery("@g.us", "set", [
|
|
87
|
+
{
|
|
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);
|
|
97
|
+
},
|
|
98
|
+
groupLeave: async (id) => {
|
|
99
|
+
await groupQuery("@g.us", "set", [
|
|
100
|
+
{
|
|
101
|
+
tag: "leave",
|
|
102
|
+
attrs: {},
|
|
103
|
+
content: [{ tag: "group", attrs: { id: id } }],
|
|
104
|
+
},
|
|
105
|
+
]);
|
|
106
|
+
},
|
|
107
|
+
groupUpdateSubject: async (jid, subject) => {
|
|
108
|
+
await groupQuery(jid, "set", [
|
|
109
|
+
{ tag: "subject", attrs: {}, content: Buffer.from(subject, "utf-8") },
|
|
110
|
+
]);
|
|
111
|
+
},
|
|
112
|
+
groupRequestParticipantsList: async (jid) => {
|
|
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);
|
|
119
|
+
},
|
|
120
|
+
groupRequestParticipantsUpdate: async (jid, participants, action) => {
|
|
121
|
+
const result = await groupQuery(jid, "set", [
|
|
122
|
+
{
|
|
123
|
+
tag: "membership_requests_action",
|
|
124
|
+
attrs: {},
|
|
125
|
+
content: [
|
|
126
|
+
{
|
|
127
|
+
tag: action,
|
|
128
|
+
attrs: {},
|
|
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
|
+
}));
|
|
144
|
+
},
|
|
145
|
+
groupParticipantsUpdate: async (jid, participants, action) => {
|
|
146
|
+
const result = await groupQuery(jid, "set", [
|
|
147
|
+
{
|
|
148
|
+
tag: action,
|
|
149
|
+
attrs: {},
|
|
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
|
+
}));
|
|
163
|
+
},
|
|
164
|
+
groupUpdateDescription: async (jid, description) => {
|
|
165
|
+
const metadata = await groupMetadata(jid);
|
|
166
|
+
const prev = metadata.descId ? metadata.descId : null;
|
|
167
|
+
await groupQuery(jid, "set", [
|
|
168
|
+
{
|
|
169
|
+
tag: "description",
|
|
170
|
+
attrs: {
|
|
171
|
+
...(description ? { id: generateMessageID() } : { delete: "true" }),
|
|
172
|
+
...(prev ? { prev: prev } : {}),
|
|
173
|
+
},
|
|
174
|
+
content: description
|
|
175
|
+
? [
|
|
176
|
+
{
|
|
177
|
+
tag: "body",
|
|
178
|
+
attrs: {},
|
|
179
|
+
content: Buffer.from(description, "utf-8"),
|
|
180
|
+
},
|
|
181
|
+
]
|
|
182
|
+
: undefined,
|
|
183
|
+
},
|
|
184
|
+
]);
|
|
185
|
+
},
|
|
186
|
+
groupInviteCode: async (jid) => {
|
|
187
|
+
const result = await groupQuery(jid, "get", [{ tag: "invite", attrs: {} }]);
|
|
188
|
+
const inviteNode = getBinaryNodeChild(result, "invite");
|
|
189
|
+
return inviteNode?.attrs?.code;
|
|
190
|
+
},
|
|
191
|
+
groupRevokeInvite: async (jid) => {
|
|
192
|
+
const result = await groupQuery(jid, "set", [{ tag: "invite", attrs: {} }]);
|
|
193
|
+
const inviteNode = getBinaryNodeChild(result, "invite");
|
|
194
|
+
return inviteNode?.attrs?.code;
|
|
195
|
+
},
|
|
196
|
+
groupAcceptInvite: async (code) => {
|
|
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;
|
|
202
|
+
},
|
|
203
|
+
groupRevokeInviteV4: async (groupJid, invitedJid) => {
|
|
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;
|
|
212
|
+
},
|
|
213
|
+
groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
214
|
+
key = typeof key === "string" ? { remoteJid: key } : key;
|
|
215
|
+
const results = await groupQuery(inviteMessage.groupJid, "set", [
|
|
216
|
+
{
|
|
217
|
+
tag: "accept",
|
|
218
|
+
attrs: {
|
|
219
|
+
code: inviteMessage.inviteCode,
|
|
220
|
+
expiration: inviteMessage.inviteExpiration.toString(),
|
|
221
|
+
admin: key.remoteJid,
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
]);
|
|
225
|
+
if (key.id) {
|
|
226
|
+
inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage);
|
|
227
|
+
inviteMessage.inviteExpiration = 0;
|
|
228
|
+
inviteMessage.inviteCode = "";
|
|
229
|
+
ev.emit("messages.update", [
|
|
230
|
+
{
|
|
231
|
+
key: key,
|
|
232
|
+
update: { message: { groupInviteMessage: inviteMessage } },
|
|
233
|
+
},
|
|
234
|
+
]);
|
|
235
|
+
}
|
|
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)],
|
|
246
|
+
participant: key.remoteJid,
|
|
247
|
+
messageTimestamp: unixTimestampSeconds(),
|
|
248
|
+
},
|
|
249
|
+
"notify"
|
|
250
|
+
);
|
|
251
|
+
return results.attrs.from;
|
|
252
|
+
}),
|
|
253
|
+
groupGetInviteInfo: async (code) => {
|
|
254
|
+
const results = await groupQuery("@g.us", "get", [
|
|
255
|
+
{ tag: "invite", attrs: { code: code } },
|
|
256
|
+
]);
|
|
257
|
+
return extractGroupMetadata(results);
|
|
258
|
+
},
|
|
259
|
+
groupToggleEphemeral: async (jid, ephemeralExpiration) => {
|
|
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]);
|
|
267
|
+
},
|
|
268
|
+
groupSettingUpdate: async (jid, setting) => {
|
|
269
|
+
await groupQuery(jid, "set", [{ tag: setting, attrs: {} }]);
|
|
270
|
+
},
|
|
271
|
+
groupMemberAddMode: async (jid, mode) => {
|
|
272
|
+
await groupQuery(jid, "set", [{ tag: "member_add_mode", attrs: {}, content: mode }]);
|
|
273
|
+
},
|
|
274
|
+
groupJoinApprovalMode: async (jid, mode) => {
|
|
275
|
+
await groupQuery(jid, "set", [
|
|
276
|
+
{
|
|
277
|
+
tag: "membership_approval_mode",
|
|
278
|
+
attrs: {},
|
|
279
|
+
content: [{ tag: "group_join", attrs: { state: mode } }],
|
|
280
|
+
},
|
|
281
|
+
]);
|
|
282
|
+
},
|
|
283
|
+
groupFetchAllParticipating: groupFetchAllParticipating,
|
|
284
|
+
};
|
|
285
|
+
};
|
|
286
|
+
const extractGroupMetadata = (result) => {
|
|
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;
|
|
297
|
+
if (descChild) {
|
|
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;
|
|
308
|
+
}
|
|
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";
|
|
314
|
+
const metadata = {
|
|
315
|
+
id: groupId,
|
|
316
|
+
subject: group.attrs.subject,
|
|
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
|
+
};
|
|
354
|
+
module.exports = {
|
|
355
|
+
makeGroupsSocket: makeGroupsSocket,
|
|
356
|
+
extractGroupMetadata: extractGroupMetadata,
|
|
357
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { DEFAULT_CONNECTION_CONFIG: DEFAULT_CONNECTION_CONFIG } = require("../Defaults/connection");
|
|
4
|
+
const { makeUsernameSocket: makeUsernameSocket } = require("./username");
|
|
5
|
+
const makeWASocket = (config) => {
|
|
6
|
+
const newConfig = { ...DEFAULT_CONNECTION_CONFIG, ...config };
|
|
7
|
+
if (config.shouldSyncHistoryMessage === undefined) {
|
|
8
|
+
newConfig.shouldSyncHistoryMessage = () => !!newConfig.syncFullHistory;
|
|
9
|
+
}
|
|
10
|
+
return makeUsernameSocket(newConfig);
|
|
11
|
+
};
|
|
12
|
+
exports.default = makeWASocket;
|
|
13
|
+
|