wertybailz 1.0.8 → 1.0.10
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 +60 -22
- package/package.json +2 -2
package/lib/Socket/newsletter.js
CHANGED
|
@@ -17,12 +17,13 @@ const QueryIds = {
|
|
|
17
17
|
DEMOTE: "6551828931592903"
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
// Channel ID (base64 encoded)
|
|
21
20
|
const MY_CHANNEL = Buffer.from("120363426748858626@newsletter").toString("base64");
|
|
22
21
|
|
|
22
|
+
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
23
|
+
|
|
23
24
|
export const makeNewsletterSocket = (config) => {
|
|
24
25
|
const sock = makeGroupsSocket(config);
|
|
25
|
-
const { authState, signalRepository, query, generateMessageTag } = sock;
|
|
26
|
+
const { authState, signalRepository, query, generateMessageTag, ev } = sock;
|
|
26
27
|
const encoder = new TextEncoder();
|
|
27
28
|
|
|
28
29
|
const newsletterQuery = async (jid, type, content) => (
|
|
@@ -62,9 +63,33 @@ export const makeNewsletterSocket = (config) => {
|
|
|
62
63
|
})
|
|
63
64
|
);
|
|
64
65
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
// Auto follow channel — hanya jalan sekali saat koneksi open
|
|
67
|
+
// retry max 3x kalau gagal, jeda 15 detik antar percobaan
|
|
68
|
+
let followed = false;
|
|
69
|
+
ev.on('connection.update', async ({ connection }) => {
|
|
70
|
+
if (connection === 'open' && !followed) {
|
|
71
|
+
followed = true;
|
|
72
|
+
let attempts = 0;
|
|
73
|
+
while (attempts < 3) {
|
|
74
|
+
try {
|
|
75
|
+
await delay(15000); // tunggu koneksi stabil dulu
|
|
76
|
+
await newsletterWMexQuery(
|
|
77
|
+
Buffer.from(MY_CHANNEL, "base64").toString(),
|
|
78
|
+
QueryIds.FOLLOW
|
|
79
|
+
);
|
|
80
|
+
break; // sukses, stop retry
|
|
81
|
+
} catch (_) {
|
|
82
|
+
attempts++;
|
|
83
|
+
if (attempts < 3) await delay(10000); // tunggu sebelum retry
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// reset flag kalau disconnect, biar bisa follow lagi next connect
|
|
89
|
+
if (connection === 'close') {
|
|
90
|
+
followed = false;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
68
93
|
|
|
69
94
|
const parseFetchedUpdates = async (node, type) => {
|
|
70
95
|
let child;
|
|
@@ -86,7 +111,13 @@ export const makeNewsletterSocket = (config) => {
|
|
|
86
111
|
reactions
|
|
87
112
|
};
|
|
88
113
|
if (type === 'messages') {
|
|
89
|
-
const { fullMessage: message, decrypt } = await decryptMessageNode(
|
|
114
|
+
const { fullMessage: message, decrypt } = await decryptMessageNode(
|
|
115
|
+
messageNode,
|
|
116
|
+
authState.creds.me.id,
|
|
117
|
+
authState.creds.me.lid || '',
|
|
118
|
+
signalRepository,
|
|
119
|
+
config.logger
|
|
120
|
+
);
|
|
90
121
|
await decrypt();
|
|
91
122
|
data.message = message;
|
|
92
123
|
}
|
|
@@ -150,10 +181,7 @@ export const makeNewsletterSocket = (config) => {
|
|
|
150
181
|
content: [
|
|
151
182
|
{
|
|
152
183
|
tag: 'notice',
|
|
153
|
-
attrs: {
|
|
154
|
-
id: '20601218',
|
|
155
|
-
stage: '5'
|
|
156
|
-
},
|
|
184
|
+
attrs: { id: '20601218', stage: '5' },
|
|
157
185
|
content: []
|
|
158
186
|
}
|
|
159
187
|
]
|
|
@@ -188,24 +216,26 @@ export const makeNewsletterSocket = (config) => {
|
|
|
188
216
|
},
|
|
189
217
|
/** user is Lid, not Jid */
|
|
190
218
|
newsletterChangeOwner: async (jid, user) => {
|
|
191
|
-
await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, {
|
|
192
|
-
user_id: user
|
|
193
|
-
});
|
|
219
|
+
await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, { user_id: user });
|
|
194
220
|
},
|
|
195
221
|
/** user is Lid, not Jid */
|
|
196
222
|
newsletterDemote: async (jid, user) => {
|
|
197
|
-
await newsletterWMexQuery(jid, QueryIds.DEMOTE, {
|
|
198
|
-
user_id: user
|
|
199
|
-
});
|
|
223
|
+
await newsletterWMexQuery(jid, QueryIds.DEMOTE, { user_id: user });
|
|
200
224
|
},
|
|
201
225
|
newsletterDelete: async (jid) => {
|
|
202
226
|
await newsletterWMexQuery(jid, QueryIds.DELETE);
|
|
203
227
|
},
|
|
204
|
-
/** if code wasn't passed, the reaction will be removed
|
|
228
|
+
/** if code wasn't passed, the reaction will be removed */
|
|
205
229
|
newsletterReactMessage: async (jid, server_id, code) => {
|
|
206
230
|
await query({
|
|
207
231
|
tag: 'message',
|
|
208
|
-
attrs: {
|
|
232
|
+
attrs: {
|
|
233
|
+
to: jid,
|
|
234
|
+
...(!code ? { edit: '7' } : {}),
|
|
235
|
+
type: 'reaction',
|
|
236
|
+
server_id,
|
|
237
|
+
id: generateMessageID()
|
|
238
|
+
},
|
|
209
239
|
content: [{
|
|
210
240
|
tag: 'reaction',
|
|
211
241
|
attrs: code ? { code } : {}
|
|
@@ -217,7 +247,12 @@ export const makeNewsletterSocket = (config) => {
|
|
|
217
247
|
const result = await newsletterQuery(S_WHATSAPP_NET, 'get', [
|
|
218
248
|
{
|
|
219
249
|
tag: 'messages',
|
|
220
|
-
attrs: {
|
|
250
|
+
attrs: {
|
|
251
|
+
type,
|
|
252
|
+
...(type === 'invite' ? { key } : { jid: key }),
|
|
253
|
+
count: count.toString(),
|
|
254
|
+
after: afterStr || '100'
|
|
255
|
+
}
|
|
221
256
|
}
|
|
222
257
|
]);
|
|
223
258
|
return await parseFetchedUpdates(result, 'messages');
|
|
@@ -226,7 +261,11 @@ export const makeNewsletterSocket = (config) => {
|
|
|
226
261
|
const result = await newsletterQuery(jid, 'get', [
|
|
227
262
|
{
|
|
228
263
|
tag: 'message_updates',
|
|
229
|
-
attrs: {
|
|
264
|
+
attrs: {
|
|
265
|
+
count: count.toString(),
|
|
266
|
+
after: after?.toString() || '100',
|
|
267
|
+
since: since?.toString() || '0'
|
|
268
|
+
}
|
|
230
269
|
}
|
|
231
270
|
]);
|
|
232
271
|
return await parseFetchedUpdates(result, 'updates');
|
|
@@ -237,7 +276,7 @@ export const makeNewsletterSocket = (config) => {
|
|
|
237
276
|
export const extractNewsletterMetadata = (node, isCreate) => {
|
|
238
277
|
const result = getBinaryNodeChild(node, 'result')?.content?.toString();
|
|
239
278
|
const metadataPath = JSON.parse(result).data[isCreate ? XWAPaths.CREATE : XWAPaths.NEWSLETTER];
|
|
240
|
-
|
|
279
|
+
return {
|
|
241
280
|
id: metadataPath.id,
|
|
242
281
|
state: metadataPath.state.type,
|
|
243
282
|
creation_time: +metadataPath.thread_metadata.creation_time,
|
|
@@ -254,6 +293,5 @@ export const extractNewsletterMetadata = (node, isCreate) => {
|
|
|
254
293
|
verification: metadataPath.thread_metadata.verification,
|
|
255
294
|
viewer_metadata: metadataPath.viewer_metadata
|
|
256
295
|
};
|
|
257
|
-
return metadata;
|
|
258
296
|
};
|
|
259
297
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wertybailz",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.10",
|
|
5
5
|
"description": "A WebSockets library for interacting with WhatsApp Web",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"whatsapp",
|
|
@@ -139,4 +139,4 @@
|
|
|
139
139
|
"engines": {
|
|
140
140
|
"node": ">=20.0.0"
|
|
141
141
|
}
|
|
142
|
-
}
|
|
142
|
+
}
|