@skyzopedia/baileys-mod 3.0.2 → 3.0.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/lib/Socket/newsletter.js +7 -22
- package/lib/Socket/newsletter.js.bak +247 -0
- package/lib/Types/Newsletter.js.bak +1 -1
- package/lib/index.js +9 -0
- package/package.json +2 -1
package/lib/Socket/newsletter.js
CHANGED
|
@@ -124,22 +124,7 @@ export const makeNewsletterSocket = (config) => {
|
|
|
124
124
|
return parseNewsletterCreateResponse(rawResponse);
|
|
125
125
|
},
|
|
126
126
|
newsletterUpdate,
|
|
127
|
-
|
|
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
|
-
},
|
|
127
|
+
newsletterMetadata,
|
|
143
128
|
newsletterFetchAllParticipating: async () => {
|
|
144
129
|
const data = {}
|
|
145
130
|
|
|
@@ -156,12 +141,12 @@ export const makeNewsletterSocket = (config) => {
|
|
|
156
141
|
|
|
157
142
|
return data
|
|
158
143
|
},
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
144
|
+
newsletterUnfollow: async (jid) => {
|
|
145
|
+
await newsletterWMexQuery(jid, QueryIds.UNFOLLOW)
|
|
146
|
+
},
|
|
147
|
+
newsletterFollow: async (jid) => {
|
|
148
|
+
await newsletterWMexQuery(jid, QueryIds.FOLLOW)
|
|
149
|
+
},
|
|
165
150
|
newsletterMute: (jid) => {
|
|
166
151
|
return executeWMexQuery({ newsletter_id: jid }, QueryIds.MUTE, XWAPaths.xwa2_newsletter_mute_v2);
|
|
167
152
|
},
|
|
@@ -0,0 +1,247 @@
|
|
|
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,
|
|
131
|
+
newsletterFetchAllParticipating: async () => {
|
|
132
|
+
const data = {}
|
|
133
|
+
|
|
134
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.SUBSCRIBERS)
|
|
135
|
+
const child = JSON.parse(getBinaryNodeChild(result, 'result')?.content?.toString())
|
|
136
|
+
const newsletters = child.data["xwa2_newsletter_subscribed"]
|
|
137
|
+
|
|
138
|
+
for (const i of newsletters) {
|
|
139
|
+
if (i.id == null) continue
|
|
140
|
+
|
|
141
|
+
const metadata = await newsletterMetadata('JID', i.id)
|
|
142
|
+
if (metadata.id !== null) data[metadata.id] = metadata
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return data
|
|
146
|
+
},
|
|
147
|
+
newsletterUnfollow: async (jid) => {
|
|
148
|
+
await newsletterWMexQuery(jid, QueryIds.UNFOLLOW)
|
|
149
|
+
},
|
|
150
|
+
newsletterFollow: async (jid) => {
|
|
151
|
+
await newsletterWMexQuery(jid, QueryIds.FOLLOW)
|
|
152
|
+
},
|
|
153
|
+
newsletterMute: (jid) => {
|
|
154
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.MUTE, XWAPaths.xwa2_newsletter_mute_v2);
|
|
155
|
+
},
|
|
156
|
+
newsletterUnmute: (jid) => {
|
|
157
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNMUTE, XWAPaths.xwa2_newsletter_unmute_v2);
|
|
158
|
+
},
|
|
159
|
+
newsletterUpdateName: async (jid, name) => {
|
|
160
|
+
return await newsletterUpdate(jid, { name });
|
|
161
|
+
},
|
|
162
|
+
newsletterUpdateDescription: async (jid, description) => {
|
|
163
|
+
return await newsletterUpdate(jid, { description });
|
|
164
|
+
},
|
|
165
|
+
newsletterUpdatePicture: async (jid, content) => {
|
|
166
|
+
const { img } = await generateProfilePicture(content);
|
|
167
|
+
return await newsletterUpdate(jid, { picture: img.toString("base64") });
|
|
168
|
+
},
|
|
169
|
+
newsletterRemovePicture: async (jid) => {
|
|
170
|
+
return await newsletterUpdate(jid, { picture: "" });
|
|
171
|
+
},
|
|
172
|
+
newsletterReactMessage: async (jid, serverId, reaction) => {
|
|
173
|
+
await query({
|
|
174
|
+
tag: "message",
|
|
175
|
+
attrs: {
|
|
176
|
+
to: jid,
|
|
177
|
+
...(reaction ? {} : { edit: "7" }),
|
|
178
|
+
type: "reaction",
|
|
179
|
+
server_id: serverId,
|
|
180
|
+
id: generateMessageTag()
|
|
181
|
+
},
|
|
182
|
+
content: [
|
|
183
|
+
{
|
|
184
|
+
tag: "reaction",
|
|
185
|
+
attrs: reaction ? { code: reaction } : {}
|
|
186
|
+
}
|
|
187
|
+
]
|
|
188
|
+
});
|
|
189
|
+
},
|
|
190
|
+
newsletterFetchMessages: async (jid, count, since, after) => {
|
|
191
|
+
const messageUpdateAttrs = {
|
|
192
|
+
count: count.toString()
|
|
193
|
+
};
|
|
194
|
+
if (typeof since === "number") {
|
|
195
|
+
messageUpdateAttrs.since = since.toString();
|
|
196
|
+
}
|
|
197
|
+
if (after) {
|
|
198
|
+
messageUpdateAttrs.after = after.toString();
|
|
199
|
+
}
|
|
200
|
+
const result = await query({
|
|
201
|
+
tag: "iq",
|
|
202
|
+
attrs: {
|
|
203
|
+
id: generateMessageTag(),
|
|
204
|
+
type: "get",
|
|
205
|
+
xmlns: "newsletter",
|
|
206
|
+
to: jid
|
|
207
|
+
},
|
|
208
|
+
content: [
|
|
209
|
+
{
|
|
210
|
+
tag: "message_updates",
|
|
211
|
+
attrs: messageUpdateAttrs
|
|
212
|
+
}
|
|
213
|
+
]
|
|
214
|
+
});
|
|
215
|
+
return result;
|
|
216
|
+
},
|
|
217
|
+
subscribeNewsletterUpdates: async (jid) => {
|
|
218
|
+
const result = await query({
|
|
219
|
+
tag: "iq",
|
|
220
|
+
attrs: {
|
|
221
|
+
id: generateMessageTag(),
|
|
222
|
+
type: "set",
|
|
223
|
+
xmlns: "newsletter",
|
|
224
|
+
to: jid
|
|
225
|
+
},
|
|
226
|
+
content: [{ tag: "live_updates", attrs: {}, content: [] }]
|
|
227
|
+
});
|
|
228
|
+
const liveUpdatesNode = getBinaryNodeChild(result, "live_updates");
|
|
229
|
+
const duration = liveUpdatesNode?.attrs?.duration;
|
|
230
|
+
return duration ? { duration: duration } : null;
|
|
231
|
+
},
|
|
232
|
+
newsletterAdminCount: async (jid) => {
|
|
233
|
+
const response = await executeWMexQuery({ newsletter_id: jid }, QueryIds.ADMIN_COUNT, XWAPaths.xwa2_newsletter_admin_count);
|
|
234
|
+
return response.admin_count;
|
|
235
|
+
},
|
|
236
|
+
newsletterChangeOwner: async (jid, newOwnerJid) => {
|
|
237
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: newOwnerJid }, QueryIds.CHANGE_OWNER, XWAPaths.xwa2_newsletter_change_owner);
|
|
238
|
+
},
|
|
239
|
+
newsletterDemote: async (jid, userJid) => {
|
|
240
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: userJid }, QueryIds.DEMOTE, XWAPaths.xwa2_newsletter_demote);
|
|
241
|
+
},
|
|
242
|
+
newsletterDelete: async (jid) => {
|
|
243
|
+
await executeWMexQuery({ newsletter_id: jid }, QueryIds.DELETE, XWAPaths.xwa2_newsletter_delete_v2);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
};
|
|
247
|
+
//=======================================================//
|
|
@@ -19,7 +19,7 @@ export var QueryIds;
|
|
|
19
19
|
(function (QueryIds) {
|
|
20
20
|
QueryIds["CREATE"] = "8823471724422422";
|
|
21
21
|
QueryIds["UPDATE_METADATA"] = "24250201037901610";
|
|
22
|
-
QueryIds["METADATA"] = "
|
|
22
|
+
QueryIds["METADATA"] = "6620195908089573";
|
|
23
23
|
QueryIds["SUBSCRIBERS"] = "6388546374527196";
|
|
24
24
|
QueryIds["FOLLOW"] = "7871414976211147";
|
|
25
25
|
QueryIds["UNFOLLOW"] = "7238632346214362";
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
//=======================================================//
|
|
2
|
+
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
|
|
5
|
+
console.log();
|
|
6
|
+
console.log(chalk.white("## Baileys Mod by Skyzopedia"));
|
|
7
|
+
console.log(chalk.blue("• https://t.me/Xskycode"));
|
|
8
|
+
console.log(chalk.blue("• https://whatsapp.com/channel/0029Vb6gF6kGU3BM8hcDW322"));
|
|
9
|
+
console.log();
|
|
10
|
+
|
|
2
11
|
import makeWASocket from "./Socket/index.js";
|
|
3
12
|
//=======================================================//
|
|
4
13
|
export * from "./Defaults/index.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skyzopedia/baileys-mod",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.8",
|
|
4
4
|
"description": "Websocket Whatsapp API for Node.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"whatsapp",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"moment-timezone": "*",
|
|
44
44
|
"music-metadata": "*",
|
|
45
45
|
"cache-manager": "*",
|
|
46
|
+
"chalk": "^4.1.2",
|
|
46
47
|
"async-mutex": "*",
|
|
47
48
|
"@hapi/boom": "*",
|
|
48
49
|
"pbjs": "^0.0.14",
|