@skyzopedia/baileys-mod 3.0.2
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 +21 -0
- package/WAProto/WAProto.proto +5311 -0
- package/WAProto/index.js +94091 -0
- package/lib/Defaults/index.js +123 -0
- package/lib/KeyDB/BinarySearch.js +20 -0
- package/lib/KeyDB/KeyedDB.js +167 -0
- package/lib/KeyDB/index.js +4 -0
- package/lib/Signal/Group/ciphertext-message.js +13 -0
- package/lib/Signal/Group/group-session-builder.js +32 -0
- package/lib/Signal/Group/group_cipher.js +84 -0
- package/lib/Signal/Group/index.js +13 -0
- package/lib/Signal/Group/keyhelper.js +20 -0
- package/lib/Signal/Group/sender-chain-key.js +28 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +65 -0
- package/lib/Signal/Group/sender-key-message.js +68 -0
- package/lib/Signal/Group/sender-key-name.js +52 -0
- package/lib/Signal/Group/sender-key-record.js +43 -0
- package/lib/Signal/Group/sender-key-state.js +86 -0
- package/lib/Signal/Group/sender-message-key.js +28 -0
- package/lib/Signal/libsignal.js +324 -0
- package/lib/Signal/lid-mapping.js +155 -0
- package/lib/Socket/Client/index.js +4 -0
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.js +52 -0
- package/lib/Socket/business.js +377 -0
- package/lib/Socket/chats.js +881 -0
- package/lib/Socket/communities.js +413 -0
- package/lib/Socket/groups.js +312 -0
- package/lib/Socket/index.js +16 -0
- package/lib/Socket/messages-recv.js +1163 -0
- package/lib/Socket/messages-send.js +1082 -0
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.js +259 -0
- package/lib/Socket/socket.js +781 -0
- package/lib/Store/index.js +6 -0
- package/lib/Store/make-cache-manager-store.js +75 -0
- package/lib/Store/make-in-memory-store.js +290 -0
- package/lib/Store/make-ordered-dictionary.js +79 -0
- package/lib/Store/object-repository.js +25 -0
- package/lib/Types/Auth.js +3 -0
- package/lib/Types/Bussines.js +3 -0
- package/lib/Types/Call.js +3 -0
- package/lib/Types/Chat.js +9 -0
- package/lib/Types/Contact.js +3 -0
- package/lib/Types/Events.js +3 -0
- package/lib/Types/GroupMetadata.js +3 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/Message.js +12 -0
- package/lib/Types/Newsletter.js +33 -0
- package/lib/Types/Newsletter.js.bak +33 -0
- package/lib/Types/Product.js +3 -0
- package/lib/Types/Signal.js +3 -0
- package/lib/Types/Socket.js +4 -0
- package/lib/Types/State.js +11 -0
- package/lib/Types/USync.js +3 -0
- package/lib/Types/index.js +28 -0
- package/lib/Utils/auth-utils.js +219 -0
- package/lib/Utils/baileys-event-stream.js +44 -0
- package/lib/Utils/browser-utils.js +17 -0
- package/lib/Utils/business.js +233 -0
- package/lib/Utils/chat-utils.js +752 -0
- package/lib/Utils/crypto.js +130 -0
- package/lib/Utils/decode-wa-message.js +267 -0
- package/lib/Utils/event-buffer.js +528 -0
- package/lib/Utils/generics.js +355 -0
- package/lib/Utils/history.js +87 -0
- package/lib/Utils/index.js +21 -0
- package/lib/Utils/link-preview.js +81 -0
- package/lib/Utils/logger.js +5 -0
- package/lib/Utils/lt-hash.js +45 -0
- package/lib/Utils/make-mutex.js +36 -0
- package/lib/Utils/message-retry-manager.js +113 -0
- package/lib/Utils/messages-media.js +601 -0
- package/lib/Utils/messages.js +776 -0
- package/lib/Utils/noise-handler.js +144 -0
- package/lib/Utils/pre-key-manager.js +85 -0
- package/lib/Utils/process-message.js +341 -0
- package/lib/Utils/signal.js +161 -0
- package/lib/Utils/use-multi-file-auth-state.js +111 -0
- package/lib/Utils/validate-connection.js +200 -0
- package/lib/WABinary/constants.js +1303 -0
- package/lib/WABinary/decode.js +240 -0
- package/lib/WABinary/encode.js +218 -0
- package/lib/WABinary/generic-utils.js +113 -0
- package/lib/WABinary/index.js +7 -0
- package/lib/WABinary/jid-utils.js +93 -0
- package/lib/WABinary/types.js +3 -0
- package/lib/WAM/BinaryInfo.js +11 -0
- package/lib/WAM/constants.js +22853 -0
- package/lib/WAM/encode.js +154 -0
- package/lib/WAM/index.js +5 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +29 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +39 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +30 -0
- package/lib/WAUSync/Protocols/index.js +6 -0
- package/lib/WAUSync/USyncQuery.js +90 -0
- package/lib/WAUSync/USyncUser.js +24 -0
- package/lib/WAUSync/index.js +5 -0
- package/lib/index.js +15 -0
- package/package.json +102 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//=======================================================//
|
|
2
|
+
import { getBinaryNodeChild, S_WHATSAPP_NET } from "../WABinary/index.js";
|
|
3
|
+
import { Boom } from "@hapi/boom";
|
|
4
|
+
//=======================================================//
|
|
5
|
+
const wMexQuery = (variables, queryId, query, generateMessageTag) => {
|
|
6
|
+
return query({
|
|
7
|
+
tag: "iq",
|
|
8
|
+
attrs: {
|
|
9
|
+
id: generateMessageTag(),
|
|
10
|
+
type: "get",
|
|
11
|
+
to: S_WHATSAPP_NET,
|
|
12
|
+
xmlns: "w:mex"
|
|
13
|
+
},
|
|
14
|
+
content: [
|
|
15
|
+
{
|
|
16
|
+
tag: "query",
|
|
17
|
+
attrs: { query_id: queryId },
|
|
18
|
+
content: Buffer.from(JSON.stringify({ variables }), "utf-8")
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
//=======================================================//
|
|
24
|
+
export const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
|
|
25
|
+
const result = await wMexQuery(variables, queryId, query, generateMessageTag);
|
|
26
|
+
const child = getBinaryNodeChild(result, "result");
|
|
27
|
+
if (child?.content) {
|
|
28
|
+
const data = JSON.parse(child.content.toString());
|
|
29
|
+
if (data.errors && data.errors.length > 0) {
|
|
30
|
+
const errorMessages = data.errors.map((err) => err.message || "Unknown error").join(", ");
|
|
31
|
+
const firstError = data.errors[0];
|
|
32
|
+
const errorCode = firstError.extensions?.error_code || 400;
|
|
33
|
+
throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError });
|
|
34
|
+
}
|
|
35
|
+
const response = dataPath ? data?.data?.[dataPath] : data?.data;
|
|
36
|
+
if (typeof response !== "undefined") {
|
|
37
|
+
return response;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const action = (dataPath || "").startsWith("xwa2_")
|
|
41
|
+
? dataPath.substring(5).replace(/_/g, " ")
|
|
42
|
+
: dataPath?.replace(/_/g, " ");
|
|
43
|
+
throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result });
|
|
44
|
+
};
|
|
45
|
+
//=======================================================//
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
//=======================================================//
|
|
2
|
+
import { executeWMexQuery as genericExecuteWMexQuery } from "./mex.js";
|
|
3
|
+
import { generateProfilePicture } from "../Utils/messages-media.js";
|
|
4
|
+
import { getBinaryNodeChild } from "../WABinary/index.js";
|
|
5
|
+
import { QueryIds, XWAPaths } from "../Types/index.js";
|
|
6
|
+
import { makeGroupsSocket } from "./groups.js";
|
|
7
|
+
//=======================================================//
|
|
8
|
+
|
|
9
|
+
const extractNewsletterMetadata = (node, isCreate) => {
|
|
10
|
+
const result = getBinaryNodeChild(node, 'result')?.content?.toString()
|
|
11
|
+
const metadataPath = JSON.parse(result).data[isCreate ? XWAPaths.xwa2_newsletter_create : "xwa2_newsletter"]
|
|
12
|
+
|
|
13
|
+
const metadata = {
|
|
14
|
+
id: metadataPath?.id,
|
|
15
|
+
state: metadataPath?.state?.type,
|
|
16
|
+
creation_time: +metadataPath?.thread_metadata?.creation_time,
|
|
17
|
+
name: metadataPath?.thread_metadata?.name?.text,
|
|
18
|
+
nameTime: +metadataPath?.thread_metadata?.name?.update_time,
|
|
19
|
+
description: metadataPath?.thread_metadata?.description?.text,
|
|
20
|
+
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time,
|
|
21
|
+
invite: metadataPath?.thread_metadata?.invite,
|
|
22
|
+
handle: metadataPath?.thread_metadata?.handle,
|
|
23
|
+
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
24
|
+
subscribers: +metadataPath?.thread_metadata?.subscribers_count,
|
|
25
|
+
verification: metadataPath?.thread_metadata?.verification,
|
|
26
|
+
viewer_metadata: metadataPath?.viewer_metadata
|
|
27
|
+
}
|
|
28
|
+
return metadata
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const parseNewsletterCreateResponse = (response) => {
|
|
32
|
+
const { id, thread_metadata: thread, viewer_metadata: viewer } = response;
|
|
33
|
+
return {
|
|
34
|
+
id: id,
|
|
35
|
+
owner: undefined,
|
|
36
|
+
name: thread.name.text,
|
|
37
|
+
creation_time: parseInt(thread.creation_time, 10),
|
|
38
|
+
description: thread.description.text,
|
|
39
|
+
invite: thread.invite,
|
|
40
|
+
subscribers: parseInt(thread.subscribers_count, 10),
|
|
41
|
+
verification: thread.verification,
|
|
42
|
+
picture: {
|
|
43
|
+
id: thread.picture.id,
|
|
44
|
+
directPath: thread.picture.direct_path
|
|
45
|
+
},
|
|
46
|
+
mute_state: viewer.mute
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
const parseNewsletterMetadata = (result) => {
|
|
50
|
+
if (typeof result !== "object" || result === null) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
if ("id" in result && typeof result.id === "string") {
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
if ("result" in result && typeof result.result === "object" && result.result !== null && "id" in result.result) {
|
|
57
|
+
return result.result;
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const makeNewsletterSocket = (config) => {
|
|
63
|
+
const sock = makeGroupsSocket(config);
|
|
64
|
+
const { query, generateMessageTag } = sock;
|
|
65
|
+
const encoder = new TextEncoder()
|
|
66
|
+
const newsletterWMexQuery = async (jid, queryId, content) => (query({
|
|
67
|
+
tag: 'iq',
|
|
68
|
+
attrs: {
|
|
69
|
+
id: generateMessageTag(),
|
|
70
|
+
type: 'get',
|
|
71
|
+
xmlns: 'w:mex',
|
|
72
|
+
to: "@s.whatsapp.net",
|
|
73
|
+
},
|
|
74
|
+
content: [
|
|
75
|
+
{
|
|
76
|
+
tag: 'query',
|
|
77
|
+
attrs: { 'query_id': queryId },
|
|
78
|
+
content: encoder.encode(JSON.stringify({
|
|
79
|
+
variables: {
|
|
80
|
+
'newsletter_id': jid,
|
|
81
|
+
...content
|
|
82
|
+
}
|
|
83
|
+
}))
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
}))
|
|
87
|
+
const executeWMexQuery = (variables, queryId, dataPath) => {
|
|
88
|
+
return genericExecuteWMexQuery(variables, queryId, dataPath, query, generateMessageTag);
|
|
89
|
+
};
|
|
90
|
+
const newsletterMetadata = async (type, key, role) => {
|
|
91
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
92
|
+
input: {
|
|
93
|
+
key,
|
|
94
|
+
type: type.toUpperCase(),
|
|
95
|
+
view_role: role || 'GUEST'
|
|
96
|
+
},
|
|
97
|
+
fetch_viewer_metadata: true,
|
|
98
|
+
fetch_full_image: true,
|
|
99
|
+
fetch_creation_time: true
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
return extractNewsletterMetadata(result)
|
|
103
|
+
}
|
|
104
|
+
const newsletterUpdate = async (jid, updates) => {
|
|
105
|
+
const variables = {
|
|
106
|
+
newsletter_id: jid,
|
|
107
|
+
updates: {
|
|
108
|
+
...updates,
|
|
109
|
+
settings: null
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
return executeWMexQuery(variables, QueryIds.UPDATE_METADATA, "xwa2_newsletter_update");
|
|
113
|
+
};
|
|
114
|
+
return {
|
|
115
|
+
...sock,
|
|
116
|
+
newsletterCreate: async (name, description) => {
|
|
117
|
+
const variables = {
|
|
118
|
+
input: {
|
|
119
|
+
name,
|
|
120
|
+
description: description ?? null
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const rawResponse = await executeWMexQuery(variables, QueryIds.CREATE, XWAPaths.xwa2_newsletter_create);
|
|
124
|
+
return parseNewsletterCreateResponse(rawResponse);
|
|
125
|
+
},
|
|
126
|
+
newsletterUpdate,
|
|
127
|
+
newsletterSubscribers: async (jid) => {
|
|
128
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.SUBSCRIBERS, XWAPaths.xwa2_newsletter_subscribers);
|
|
129
|
+
},
|
|
130
|
+
newsletterMetadata: async (type, key) => {
|
|
131
|
+
const variables = {
|
|
132
|
+
fetch_creation_time: true,
|
|
133
|
+
fetch_full_image: true,
|
|
134
|
+
fetch_viewer_metadata: true,
|
|
135
|
+
input: {
|
|
136
|
+
key,
|
|
137
|
+
type: type.toUpperCase()
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
const result = await executeWMexQuery(variables, QueryIds.METADATA, XWAPaths.xwa2_newsletter_metadata);
|
|
141
|
+
return parseNewsletterMetadata(result);
|
|
142
|
+
},
|
|
143
|
+
newsletterFetchAllParticipating: async () => {
|
|
144
|
+
const data = {}
|
|
145
|
+
|
|
146
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.SUBSCRIBERS)
|
|
147
|
+
const child = JSON.parse(getBinaryNodeChild(result, 'result')?.content?.toString())
|
|
148
|
+
const newsletters = child.data["xwa2_newsletter_subscribed"]
|
|
149
|
+
|
|
150
|
+
for (const i of newsletters) {
|
|
151
|
+
if (i.id == null) continue
|
|
152
|
+
|
|
153
|
+
const metadata = await newsletterMetadata('JID', i.id)
|
|
154
|
+
if (metadata.id !== null) data[metadata.id] = metadata
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return data
|
|
158
|
+
},
|
|
159
|
+
newsletterFollow: (jid) => {
|
|
160
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.FOLLOW, XWAPaths.xwa2_newsletter_follow);
|
|
161
|
+
},
|
|
162
|
+
newsletterUnfollow: (jid) => {
|
|
163
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNFOLLOW, XWAPaths.xwa2_newsletter_unfollow);
|
|
164
|
+
},
|
|
165
|
+
newsletterMute: (jid) => {
|
|
166
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.MUTE, XWAPaths.xwa2_newsletter_mute_v2);
|
|
167
|
+
},
|
|
168
|
+
newsletterUnmute: (jid) => {
|
|
169
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNMUTE, XWAPaths.xwa2_newsletter_unmute_v2);
|
|
170
|
+
},
|
|
171
|
+
newsletterUpdateName: async (jid, name) => {
|
|
172
|
+
return await newsletterUpdate(jid, { name });
|
|
173
|
+
},
|
|
174
|
+
newsletterUpdateDescription: async (jid, description) => {
|
|
175
|
+
return await newsletterUpdate(jid, { description });
|
|
176
|
+
},
|
|
177
|
+
newsletterUpdatePicture: async (jid, content) => {
|
|
178
|
+
const { img } = await generateProfilePicture(content);
|
|
179
|
+
return await newsletterUpdate(jid, { picture: img.toString("base64") });
|
|
180
|
+
},
|
|
181
|
+
newsletterRemovePicture: async (jid) => {
|
|
182
|
+
return await newsletterUpdate(jid, { picture: "" });
|
|
183
|
+
},
|
|
184
|
+
newsletterReactMessage: async (jid, serverId, reaction) => {
|
|
185
|
+
await query({
|
|
186
|
+
tag: "message",
|
|
187
|
+
attrs: {
|
|
188
|
+
to: jid,
|
|
189
|
+
...(reaction ? {} : { edit: "7" }),
|
|
190
|
+
type: "reaction",
|
|
191
|
+
server_id: serverId,
|
|
192
|
+
id: generateMessageTag()
|
|
193
|
+
},
|
|
194
|
+
content: [
|
|
195
|
+
{
|
|
196
|
+
tag: "reaction",
|
|
197
|
+
attrs: reaction ? { code: reaction } : {}
|
|
198
|
+
}
|
|
199
|
+
]
|
|
200
|
+
});
|
|
201
|
+
},
|
|
202
|
+
newsletterFetchMessages: async (jid, count, since, after) => {
|
|
203
|
+
const messageUpdateAttrs = {
|
|
204
|
+
count: count.toString()
|
|
205
|
+
};
|
|
206
|
+
if (typeof since === "number") {
|
|
207
|
+
messageUpdateAttrs.since = since.toString();
|
|
208
|
+
}
|
|
209
|
+
if (after) {
|
|
210
|
+
messageUpdateAttrs.after = after.toString();
|
|
211
|
+
}
|
|
212
|
+
const result = await query({
|
|
213
|
+
tag: "iq",
|
|
214
|
+
attrs: {
|
|
215
|
+
id: generateMessageTag(),
|
|
216
|
+
type: "get",
|
|
217
|
+
xmlns: "newsletter",
|
|
218
|
+
to: jid
|
|
219
|
+
},
|
|
220
|
+
content: [
|
|
221
|
+
{
|
|
222
|
+
tag: "message_updates",
|
|
223
|
+
attrs: messageUpdateAttrs
|
|
224
|
+
}
|
|
225
|
+
]
|
|
226
|
+
});
|
|
227
|
+
return result;
|
|
228
|
+
},
|
|
229
|
+
subscribeNewsletterUpdates: async (jid) => {
|
|
230
|
+
const result = await query({
|
|
231
|
+
tag: "iq",
|
|
232
|
+
attrs: {
|
|
233
|
+
id: generateMessageTag(),
|
|
234
|
+
type: "set",
|
|
235
|
+
xmlns: "newsletter",
|
|
236
|
+
to: jid
|
|
237
|
+
},
|
|
238
|
+
content: [{ tag: "live_updates", attrs: {}, content: [] }]
|
|
239
|
+
});
|
|
240
|
+
const liveUpdatesNode = getBinaryNodeChild(result, "live_updates");
|
|
241
|
+
const duration = liveUpdatesNode?.attrs?.duration;
|
|
242
|
+
return duration ? { duration: duration } : null;
|
|
243
|
+
},
|
|
244
|
+
newsletterAdminCount: async (jid) => {
|
|
245
|
+
const response = await executeWMexQuery({ newsletter_id: jid }, QueryIds.ADMIN_COUNT, XWAPaths.xwa2_newsletter_admin_count);
|
|
246
|
+
return response.admin_count;
|
|
247
|
+
},
|
|
248
|
+
newsletterChangeOwner: async (jid, newOwnerJid) => {
|
|
249
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: newOwnerJid }, QueryIds.CHANGE_OWNER, XWAPaths.xwa2_newsletter_change_owner);
|
|
250
|
+
},
|
|
251
|
+
newsletterDemote: async (jid, userJid) => {
|
|
252
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: userJid }, QueryIds.DEMOTE, XWAPaths.xwa2_newsletter_demote);
|
|
253
|
+
},
|
|
254
|
+
newsletterDelete: async (jid) => {
|
|
255
|
+
await executeWMexQuery({ newsletter_id: jid }, QueryIds.DELETE, XWAPaths.xwa2_newsletter_delete_v2);
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
};
|
|
259
|
+
//=======================================================//
|