@langitdeveloper/baileys 2.0.3
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 +13 -0
- package/WAProto/index.js +97650 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +1 -0
- package/lib/Defaults/index.d.ts +53 -0
- package/lib/Defaults/index.js +147 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/Group/sender-message-key.js +29 -0
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Signal/libsignal.js +174 -0
- package/lib/Signal/lid-mapping.js +164 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +19 -0
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -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.d.ts +12 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/Client/websocket.js +67 -0
- package/lib/Socket/business.d.ts +171 -0
- package/lib/Socket/business.js +260 -0
- package/lib/Socket/chats.d.ts +267 -0
- package/lib/Socket/chats.js +970 -0
- package/lib/Socket/community.js +454 -0
- package/lib/Socket/dugong.d.ts +254 -0
- package/lib/Socket/dugong.js +484 -0
- package/lib/Socket/groups.d.ts +115 -0
- package/lib/Socket/groups.js +317 -0
- package/lib/Socket/index.d.ts +173 -0
- package/lib/Socket/index.js +11 -0
- package/lib/Socket/messages-recv.d.ts +161 -0
- package/lib/Socket/messages-recv.js +1110 -0
- package/lib/Socket/messages-send.d.ts +149 -0
- package/lib/Socket/messages-send.js +923 -0
- package/lib/Socket/mex.js +54 -0
- package/lib/Socket/newsletter.d.ts +134 -0
- package/lib/Socket/newsletter.js +341 -0
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +43 -0
- package/lib/Socket/socket.js +665 -0
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +10 -0
- package/lib/Store/make-cache-manager-store.d.ts +13 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-in-memory-store.js +427 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.d.ts +110 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.d.ts +102 -0
- package/lib/Types/Chat.js +4 -0
- package/lib/Types/Contact.d.ts +19 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.d.ts +157 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.d.ts +55 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.d.ts +35 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.d.ts +29 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.d.ts +273 -0
- package/lib/Types/Message.js +9 -0
- package/lib/Types/MexUpdates.js +15 -0
- package/lib/Types/Newsletter.d.ts +103 -0
- package/lib/Types/Newsletter.js +38 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.d.ts +111 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.d.ts +57 -0
- package/lib/Types/index.js +44 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/auth-utils.js +206 -0
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/business.js +234 -0
- package/lib/Utils/chat-utils.d.ts +71 -0
- package/lib/Utils/chat-utils.js +729 -0
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/crypto.js +151 -0
- package/lib/Utils/decode-wa-message.d.ts +19 -0
- package/lib/Utils/decode-wa-message.js +198 -0
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/event-buffer.js +514 -0
- package/lib/Utils/generics.d.ts +92 -0
- package/lib/Utils/generics.js +423 -0
- package/lib/Utils/history.d.ts +15 -0
- package/lib/Utils/history.js +96 -0
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/index.js +37 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +93 -0
- package/lib/Utils/logger.d.ts +4 -0
- package/lib/Utils/logger.js +7 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +51 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +43 -0
- package/lib/Utils/message-retry-manager.js +134 -0
- package/lib/Utils/messages-media.d.ts +116 -0
- package/lib/Utils/messages-media.js +819 -0
- package/lib/Utils/messages.d.ts +77 -0
- package/lib/Utils/messages.js +816 -0
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/noise-handler.js +155 -0
- package/lib/Utils/pre-key-manager.js +86 -0
- package/lib/Utils/process-message.d.ts +41 -0
- package/lib/Utils/process-message.js +321 -0
- package/lib/Utils/signal.d.ts +32 -0
- package/lib/Utils/signal.js +153 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +119 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +229 -0
- package/lib/Utils/vialeys-event-stream.js +41 -0
- package/lib/WABinary/constants.d.ts +30 -0
- package/lib/WABinary/constants.js +40 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.js +252 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +265 -0
- package/lib/WABinary/generic-utils.d.ts +17 -0
- package/lib/WABinary/generic-utils.js +198 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +21 -0
- package/lib/WABinary/jid-utils.d.ts +31 -0
- package/lib/WABinary/jid-utils.js +62 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.d.ts +17 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.d.ts +38 -0
- package/lib/WAM/constants.js +15350 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.js +155 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +19 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/index.js +22 -0
- package/lib/WAUSync/USyncQuery.d.ts +28 -0
- package/lib/WAUSync/USyncQuery.js +89 -0
- package/lib/WAUSync/USyncUser.d.ts +12 -0
- package/lib/WAUSync/USyncUser.js +26 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +48 -0
- package/package.json +104 -0
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { proto: proto } = require("../../WAProto");
|
|
4
|
+
const { default: logger } = require("../Utils/logger");
|
|
5
|
+
const {
|
|
6
|
+
WAMessageStubType: WAMessageStubType,
|
|
7
|
+
WAMessageAddressingMode: WAMessageAddressingMode,
|
|
8
|
+
} = require("../Types");
|
|
9
|
+
const {
|
|
10
|
+
generateMessageID: generateMessageID,
|
|
11
|
+
unixTimestampSeconds: unixTimestampSeconds,
|
|
12
|
+
} = require("../Utils");
|
|
13
|
+
const {
|
|
14
|
+
getBinaryNodeChild: getBinaryNodeChild,
|
|
15
|
+
getBinaryNodeChildren: getBinaryNodeChildren,
|
|
16
|
+
getBinaryNodeChildString: getBinaryNodeChildString,
|
|
17
|
+
jidEncode: jidEncode,
|
|
18
|
+
jidNormalizedUser: jidNormalizedUser,
|
|
19
|
+
} = require("../WABinary");
|
|
20
|
+
const { makeBusinessSocket: makeBusinessSocket } = require("./business");
|
|
21
|
+
const makeCommunitiesSocket = (config) => {
|
|
22
|
+
const conn = makeBusinessSocket(config);
|
|
23
|
+
const {
|
|
24
|
+
authState: authState,
|
|
25
|
+
ev: ev,
|
|
26
|
+
query: query,
|
|
27
|
+
groupMetadata: groupMetadata,
|
|
28
|
+
upsertMessage: upsertMessage,
|
|
29
|
+
cleanDirtyBits: cleanDirtyBits,
|
|
30
|
+
} = conn;
|
|
31
|
+
const communityQuery = async (jid, type, content) =>
|
|
32
|
+
query({
|
|
33
|
+
tag: "iq",
|
|
34
|
+
attrs: { type: type, xmlns: "w:g2", to: jid },
|
|
35
|
+
content: content,
|
|
36
|
+
});
|
|
37
|
+
const communityMetadata = async (jid) => {
|
|
38
|
+
const result = await communityQuery(jid, "get", [
|
|
39
|
+
{ tag: "query", attrs: { request: "interactive" } },
|
|
40
|
+
]);
|
|
41
|
+
return extractCommunityMetadata(result);
|
|
42
|
+
};
|
|
43
|
+
const communityFetchAllParticipating = async () => {
|
|
44
|
+
const result = await query({
|
|
45
|
+
tag: "iq",
|
|
46
|
+
attrs: { to: "@g.us", xmlns: "w:g2", type: "get" },
|
|
47
|
+
content: [
|
|
48
|
+
{
|
|
49
|
+
tag: "participating",
|
|
50
|
+
attrs: {},
|
|
51
|
+
content: [
|
|
52
|
+
{ tag: "participants", attrs: {} },
|
|
53
|
+
{ tag: "description", attrs: {} },
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
});
|
|
58
|
+
const data = {};
|
|
59
|
+
const communitiesChild = getBinaryNodeChild(result, "communities");
|
|
60
|
+
if (communitiesChild) {
|
|
61
|
+
const communities = getBinaryNodeChildren(communitiesChild, "community");
|
|
62
|
+
for (const communityNode of communities) {
|
|
63
|
+
const meta = extractCommunityMetadata({
|
|
64
|
+
tag: "result",
|
|
65
|
+
attrs: {},
|
|
66
|
+
content: [communityNode],
|
|
67
|
+
});
|
|
68
|
+
data[meta.id] = meta;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
conn.ev.emit("groups.update", Object.values(data));
|
|
72
|
+
return data;
|
|
73
|
+
};
|
|
74
|
+
async function parseGroupResult(node) {
|
|
75
|
+
logger.info({ node: node }, "parseGroupResult");
|
|
76
|
+
const groupNode = getBinaryNodeChild(node, "group");
|
|
77
|
+
if (groupNode) {
|
|
78
|
+
try {
|
|
79
|
+
logger.info({ groupNode: groupNode }, "groupNode");
|
|
80
|
+
const metadata = await groupMetadata(`${groupNode.attrs.id}@g.us`);
|
|
81
|
+
return metadata ? metadata : null;
|
|
82
|
+
} catch (error) {
|
|
83
|
+
logger.warn({ error: error }, "Error parsing group metadata");
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
conn.ws.on("CB:ib,,dirty", async (node) => {
|
|
90
|
+
const { attrs: attrs } = getBinaryNodeChild(node, "dirty");
|
|
91
|
+
if (attrs.type !== "communities") {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
await communityFetchAllParticipating();
|
|
95
|
+
await cleanDirtyBits("groups");
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
...conn,
|
|
99
|
+
communityQuery: communityQuery,
|
|
100
|
+
communityMetadata: communityMetadata,
|
|
101
|
+
communityCreate: async (subject, body) => {
|
|
102
|
+
const descriptionId = generateMessageID().substring(0, 12);
|
|
103
|
+
const result = await communityQuery("@g.us", "set", [
|
|
104
|
+
{
|
|
105
|
+
tag: "create",
|
|
106
|
+
attrs: { subject: subject },
|
|
107
|
+
content: [
|
|
108
|
+
{
|
|
109
|
+
tag: "description",
|
|
110
|
+
attrs: { id: descriptionId },
|
|
111
|
+
content: [
|
|
112
|
+
{
|
|
113
|
+
tag: "body",
|
|
114
|
+
attrs: {},
|
|
115
|
+
content: Buffer.from(body || "", "utf-8"),
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
tag: "parent",
|
|
121
|
+
attrs: { default_membership_approval_mode: "request_required" },
|
|
122
|
+
},
|
|
123
|
+
{ tag: "allow_non_admin_sub_group_creation", attrs: {} },
|
|
124
|
+
{ tag: "create_general_chat", attrs: {} },
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
]);
|
|
128
|
+
return await parseGroupResult(result);
|
|
129
|
+
},
|
|
130
|
+
communityCreateGroup: async (subject, participants, parentCommunityJid) => {
|
|
131
|
+
const key = generateMessageID();
|
|
132
|
+
const result = await communityQuery("@g.us", "set", [
|
|
133
|
+
{
|
|
134
|
+
tag: "create",
|
|
135
|
+
attrs: { subject: subject, key: key },
|
|
136
|
+
content: [
|
|
137
|
+
...participants.map((jid) => ({
|
|
138
|
+
tag: "participant",
|
|
139
|
+
attrs: { jid: jid },
|
|
140
|
+
})),
|
|
141
|
+
{ tag: "linked_parent", attrs: { jid: parentCommunityJid } },
|
|
142
|
+
],
|
|
143
|
+
},
|
|
144
|
+
]);
|
|
145
|
+
return await parseGroupResult(result);
|
|
146
|
+
},
|
|
147
|
+
communityLeave: async (id) => {
|
|
148
|
+
await communityQuery("@g.us", "set", [
|
|
149
|
+
{
|
|
150
|
+
tag: "leave",
|
|
151
|
+
attrs: {},
|
|
152
|
+
content: [{ tag: "community", attrs: { id: id } }],
|
|
153
|
+
},
|
|
154
|
+
]);
|
|
155
|
+
},
|
|
156
|
+
communityUpdateSubject: async (jid, subject) => {
|
|
157
|
+
await communityQuery(jid, "set", [
|
|
158
|
+
{ tag: "subject", attrs: {}, content: Buffer.from(subject, "utf-8") },
|
|
159
|
+
]);
|
|
160
|
+
},
|
|
161
|
+
communityLinkGroup: async (groupJid, parentCommunityJid) => {
|
|
162
|
+
await communityQuery(parentCommunityJid, "set", [
|
|
163
|
+
{
|
|
164
|
+
tag: "links",
|
|
165
|
+
attrs: {},
|
|
166
|
+
content: [
|
|
167
|
+
{
|
|
168
|
+
tag: "link",
|
|
169
|
+
attrs: { link_type: "sub_group" },
|
|
170
|
+
content: [{ tag: "group", attrs: { jid: groupJid } }],
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
},
|
|
174
|
+
]);
|
|
175
|
+
},
|
|
176
|
+
communityUnlinkGroup: async (groupJid, parentCommunityJid) => {
|
|
177
|
+
await communityQuery(parentCommunityJid, "set", [
|
|
178
|
+
{
|
|
179
|
+
tag: "unlink",
|
|
180
|
+
attrs: { unlink_type: "sub_group" },
|
|
181
|
+
content: [{ tag: "group", attrs: { jid: groupJid } }],
|
|
182
|
+
},
|
|
183
|
+
]);
|
|
184
|
+
},
|
|
185
|
+
communityFetchLinkedGroups: async (jid) => {
|
|
186
|
+
let communityJid = jid;
|
|
187
|
+
let isCommunity = false;
|
|
188
|
+
const metadata = await groupMetadata(jid);
|
|
189
|
+
if (metadata.linkedParent) {
|
|
190
|
+
communityJid = metadata.linkedParent;
|
|
191
|
+
} else {
|
|
192
|
+
isCommunity = true;
|
|
193
|
+
}
|
|
194
|
+
const result = await communityQuery(communityJid, "get", [
|
|
195
|
+
{ tag: "sub_groups", attrs: {} },
|
|
196
|
+
]);
|
|
197
|
+
const linkedGroupsData = [];
|
|
198
|
+
const subGroupsNode = getBinaryNodeChild(result, "sub_groups");
|
|
199
|
+
if (subGroupsNode) {
|
|
200
|
+
const groupNodes = getBinaryNodeChildren(subGroupsNode, "group");
|
|
201
|
+
for (const groupNode of groupNodes) {
|
|
202
|
+
linkedGroupsData.push({
|
|
203
|
+
id: groupNode.attrs.id ? jidEncode(groupNode.attrs.id, "g.us") : undefined,
|
|
204
|
+
subject: groupNode.attrs.subject || "",
|
|
205
|
+
creation: groupNode.attrs.creation
|
|
206
|
+
? Number(groupNode.attrs.creation)
|
|
207
|
+
: undefined,
|
|
208
|
+
owner: groupNode.attrs.creator
|
|
209
|
+
? jidNormalizedUser(groupNode.attrs.creator)
|
|
210
|
+
: undefined,
|
|
211
|
+
size: groupNode.attrs.size ? Number(groupNode.attrs.size) : undefined,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
communityJid: communityJid,
|
|
217
|
+
isCommunity: isCommunity,
|
|
218
|
+
linkedGroups: linkedGroupsData,
|
|
219
|
+
};
|
|
220
|
+
},
|
|
221
|
+
communityRequestParticipantsList: async (jid) => {
|
|
222
|
+
const result = await communityQuery(jid, "get", [
|
|
223
|
+
{ tag: "membership_approval_requests", attrs: {} },
|
|
224
|
+
]);
|
|
225
|
+
const node = getBinaryNodeChild(result, "membership_approval_requests");
|
|
226
|
+
const participants = getBinaryNodeChildren(node, "membership_approval_request");
|
|
227
|
+
return participants.map((v) => v.attrs);
|
|
228
|
+
},
|
|
229
|
+
communityRequestParticipantsUpdate: async (jid, participants, action) => {
|
|
230
|
+
const result = await communityQuery(jid, "set", [
|
|
231
|
+
{
|
|
232
|
+
tag: "membership_requests_action",
|
|
233
|
+
attrs: {},
|
|
234
|
+
content: [
|
|
235
|
+
{
|
|
236
|
+
tag: action,
|
|
237
|
+
attrs: {},
|
|
238
|
+
content: participants.map((jid) => ({
|
|
239
|
+
tag: "participant",
|
|
240
|
+
attrs: { jid: jid },
|
|
241
|
+
})),
|
|
242
|
+
},
|
|
243
|
+
],
|
|
244
|
+
},
|
|
245
|
+
]);
|
|
246
|
+
const node = getBinaryNodeChild(result, "membership_requests_action");
|
|
247
|
+
const nodeAction = getBinaryNodeChild(node, action);
|
|
248
|
+
const participantsAffected = getBinaryNodeChildren(nodeAction, "participant");
|
|
249
|
+
return participantsAffected.map((p) => ({
|
|
250
|
+
status: p.attrs.error || "200",
|
|
251
|
+
jid: p.attrs.jid,
|
|
252
|
+
}));
|
|
253
|
+
},
|
|
254
|
+
communityParticipantsUpdate: async (jid, participants, action) => {
|
|
255
|
+
const result = await communityQuery(jid, "set", [
|
|
256
|
+
{
|
|
257
|
+
tag: action,
|
|
258
|
+
attrs: action === "remove" ? { linked_groups: "true" } : {},
|
|
259
|
+
content: participants.map((jid) => ({
|
|
260
|
+
tag: "participant",
|
|
261
|
+
attrs: { jid: jid },
|
|
262
|
+
})),
|
|
263
|
+
},
|
|
264
|
+
]);
|
|
265
|
+
const node = getBinaryNodeChild(result, action);
|
|
266
|
+
const participantsAffected = getBinaryNodeChildren(node, "participant");
|
|
267
|
+
return participantsAffected.map((p) => ({
|
|
268
|
+
status: p.attrs.error || "200",
|
|
269
|
+
jid: p.attrs.jid,
|
|
270
|
+
content: p,
|
|
271
|
+
}));
|
|
272
|
+
},
|
|
273
|
+
communityUpdateDescription: async (jid, description) => {
|
|
274
|
+
const metadata = await communityMetadata(jid);
|
|
275
|
+
const prev = metadata.descId ?? null;
|
|
276
|
+
await communityQuery(jid, "set", [
|
|
277
|
+
{
|
|
278
|
+
tag: "description",
|
|
279
|
+
attrs: {
|
|
280
|
+
...(description ? { id: generateMessageID() } : { delete: "true" }),
|
|
281
|
+
...(prev ? { prev: prev } : {}),
|
|
282
|
+
},
|
|
283
|
+
content: description
|
|
284
|
+
? [
|
|
285
|
+
{
|
|
286
|
+
tag: "body",
|
|
287
|
+
attrs: {},
|
|
288
|
+
content: Buffer.from(description, "utf-8"),
|
|
289
|
+
},
|
|
290
|
+
]
|
|
291
|
+
: undefined,
|
|
292
|
+
},
|
|
293
|
+
]);
|
|
294
|
+
},
|
|
295
|
+
communityInviteCode: async (jid) => {
|
|
296
|
+
const result = await communityQuery(jid, "get", [{ tag: "invite", attrs: {} }]);
|
|
297
|
+
const inviteNode = getBinaryNodeChild(result, "invite");
|
|
298
|
+
return inviteNode?.attrs.code;
|
|
299
|
+
},
|
|
300
|
+
communityRevokeInvite: async (jid) => {
|
|
301
|
+
const result = await communityQuery(jid, "set", [{ tag: "invite", attrs: {} }]);
|
|
302
|
+
const inviteNode = getBinaryNodeChild(result, "invite");
|
|
303
|
+
return inviteNode?.attrs.code;
|
|
304
|
+
},
|
|
305
|
+
communityAcceptInvite: async (code) => {
|
|
306
|
+
const results = await communityQuery("@g.us", "set", [
|
|
307
|
+
{ tag: "invite", attrs: { code: code } },
|
|
308
|
+
]);
|
|
309
|
+
const result = getBinaryNodeChild(results, "community");
|
|
310
|
+
return result?.attrs.jid;
|
|
311
|
+
},
|
|
312
|
+
communityRevokeInviteV4: async (communityJid, invitedJid) => {
|
|
313
|
+
const result = await communityQuery(communityJid, "set", [
|
|
314
|
+
{
|
|
315
|
+
tag: "revoke",
|
|
316
|
+
attrs: {},
|
|
317
|
+
content: [{ tag: "participant", attrs: { jid: invitedJid } }],
|
|
318
|
+
},
|
|
319
|
+
]);
|
|
320
|
+
return !!result;
|
|
321
|
+
},
|
|
322
|
+
communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
323
|
+
key = typeof key === "string" ? { remoteJid: key } : key;
|
|
324
|
+
const results = await communityQuery(inviteMessage.groupJid, "set", [
|
|
325
|
+
{
|
|
326
|
+
tag: "accept",
|
|
327
|
+
attrs: {
|
|
328
|
+
code: inviteMessage.inviteCode,
|
|
329
|
+
expiration: inviteMessage.inviteExpiration.toString(),
|
|
330
|
+
admin: key.remoteJid,
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
]);
|
|
334
|
+
if (key.id) {
|
|
335
|
+
inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage);
|
|
336
|
+
inviteMessage.inviteExpiration = 0;
|
|
337
|
+
inviteMessage.inviteCode = "";
|
|
338
|
+
ev.emit("messages.update", [
|
|
339
|
+
{
|
|
340
|
+
key: key,
|
|
341
|
+
update: { message: { groupInviteMessage: inviteMessage } },
|
|
342
|
+
},
|
|
343
|
+
]);
|
|
344
|
+
}
|
|
345
|
+
await upsertMessage(
|
|
346
|
+
{
|
|
347
|
+
key: {
|
|
348
|
+
remoteJid: inviteMessage.groupJid,
|
|
349
|
+
id: generateMessageID(conn.user?.id),
|
|
350
|
+
fromMe: false,
|
|
351
|
+
participant: key.remoteJid,
|
|
352
|
+
},
|
|
353
|
+
messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
|
|
354
|
+
messageStubParameters: [JSON.stringify(authState.creds.me)],
|
|
355
|
+
participant: key.remoteJid,
|
|
356
|
+
messageTimestamp: unixTimestampSeconds(),
|
|
357
|
+
},
|
|
358
|
+
"notify"
|
|
359
|
+
);
|
|
360
|
+
return results.attrs.from;
|
|
361
|
+
}),
|
|
362
|
+
communityGetInviteInfo: async (code) => {
|
|
363
|
+
const results = await communityQuery("@g.us", "get", [
|
|
364
|
+
{ tag: "invite", attrs: { code: code } },
|
|
365
|
+
]);
|
|
366
|
+
return extractCommunityMetadata(results);
|
|
367
|
+
},
|
|
368
|
+
communityToggleEphemeral: async (jid, ephemeralExpiration) => {
|
|
369
|
+
const content = ephemeralExpiration
|
|
370
|
+
? {
|
|
371
|
+
tag: "ephemeral",
|
|
372
|
+
attrs: { expiration: ephemeralExpiration.toString() },
|
|
373
|
+
}
|
|
374
|
+
: { tag: "not_ephemeral", attrs: {} };
|
|
375
|
+
await communityQuery(jid, "set", [content]);
|
|
376
|
+
},
|
|
377
|
+
communitySettingUpdate: async (jid, setting) => {
|
|
378
|
+
await communityQuery(jid, "set", [{ tag: setting, attrs: {} }]);
|
|
379
|
+
},
|
|
380
|
+
communityMemberAddMode: async (jid, mode) => {
|
|
381
|
+
await communityQuery(jid, "set", [
|
|
382
|
+
{ tag: "member_add_mode", attrs: {}, content: mode },
|
|
383
|
+
]);
|
|
384
|
+
},
|
|
385
|
+
communityJoinApprovalMode: async (jid, mode) => {
|
|
386
|
+
await communityQuery(jid, "set", [
|
|
387
|
+
{
|
|
388
|
+
tag: "membership_approval_mode",
|
|
389
|
+
attrs: {},
|
|
390
|
+
content: [{ tag: "community_join", attrs: { state: mode } }],
|
|
391
|
+
},
|
|
392
|
+
]);
|
|
393
|
+
},
|
|
394
|
+
communityFetchAllParticipating: communityFetchAllParticipating,
|
|
395
|
+
};
|
|
396
|
+
};
|
|
397
|
+
const extractCommunityMetadata = (result) => {
|
|
398
|
+
const community = getBinaryNodeChild(result, "group");
|
|
399
|
+
const descChild = getBinaryNodeChild(community, "description");
|
|
400
|
+
let desc;
|
|
401
|
+
let descId;
|
|
402
|
+
if (descChild) {
|
|
403
|
+
desc = getBinaryNodeChildString(descChild, "body");
|
|
404
|
+
descId = descChild.attrs.id;
|
|
405
|
+
}
|
|
406
|
+
const mode = community.attrs.addressing_mode;
|
|
407
|
+
const communityId = community.attrs.id.includes("@")
|
|
408
|
+
? community.attrs.id
|
|
409
|
+
: jidEncode(community.attrs.id, "g.us");
|
|
410
|
+
const eph = getBinaryNodeChild(community, "ephemeral")?.attrs.expiration;
|
|
411
|
+
const memberAddMode =
|
|
412
|
+
getBinaryNodeChildString(community, "member_add_mode") === "all_member_add";
|
|
413
|
+
const metadata = {
|
|
414
|
+
id: communityId,
|
|
415
|
+
subject: community.attrs.subject,
|
|
416
|
+
subjectOwner: community.attrs.s_o,
|
|
417
|
+
subjectOwnerAlt: community.attrs?.s_o_pn ? community.attrs.s_o_pn : community.attrs.s_o,
|
|
418
|
+
subjectTime: Number(community.attrs.s_t || 0),
|
|
419
|
+
size: Number(
|
|
420
|
+
community.attrs?.size
|
|
421
|
+
? community.attrs.size
|
|
422
|
+
: getBinaryNodeChildren(community, "participant").length
|
|
423
|
+
),
|
|
424
|
+
creation: Number(community.attrs.creation || 0),
|
|
425
|
+
owner: community.attrs.creator ? jidNormalizedUser(community.attrs.creator) : undefined,
|
|
426
|
+
ownerAlt: community.attrs.creator
|
|
427
|
+
? jidNormalizedUser(
|
|
428
|
+
community.attrs?.creator_pn ? community.attrs.creator_pn : community.attrs.creator
|
|
429
|
+
)
|
|
430
|
+
: undefined,
|
|
431
|
+
ownerCountry: community.attrs.creator_country_code,
|
|
432
|
+
desc: desc,
|
|
433
|
+
descId: descId,
|
|
434
|
+
linkedParent: getBinaryNodeChild(community, "linked_parent")?.attrs.jid || undefined,
|
|
435
|
+
restrict: !!getBinaryNodeChild(community, "locked"),
|
|
436
|
+
announce: !!getBinaryNodeChild(community, "announcement"),
|
|
437
|
+
isCommunity: !!getBinaryNodeChild(community, "parent"),
|
|
438
|
+
isCommunityAnnounce: !!getBinaryNodeChild(community, "default_sub_group"),
|
|
439
|
+
joinApprovalMode: !!getBinaryNodeChild(community, "membership_approval_mode"),
|
|
440
|
+
memberAddMode: memberAddMode,
|
|
441
|
+
participants: getBinaryNodeChildren(community, "participant").map(({ attrs: attrs }) => ({
|
|
442
|
+
id: mode === WAMessageAddressingMode.LID ? community.phone_number : attrs.jid,
|
|
443
|
+
lid: mode === WAMessageAddressingMode.LID ? community.jid : attrs.lid,
|
|
444
|
+
admin: attrs.type || null,
|
|
445
|
+
})),
|
|
446
|
+
ephemeralDuration: eph ? Number(ph) : undefined,
|
|
447
|
+
addressingMode: mode,
|
|
448
|
+
};
|
|
449
|
+
return metadata;
|
|
450
|
+
};
|
|
451
|
+
module.exports = {
|
|
452
|
+
makeCommunitiesSocket: makeCommunitiesSocket,
|
|
453
|
+
extractCommunityMetadata: extractCommunityMetadata,
|
|
454
|
+
};
|