@sixcore/baileys 1.0.1 → 1.1.0
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.
Potentially problematic release.
This version of @sixcore/baileys might be problematic. Click here for more details.
- package/LICENSE +21 -13
- package/WAProto/WAProto.proto +5311 -0
- package/WAProto/index.js +65813 -141372
- package/lib/Defaults/index.js +120 -133
- package/lib/KeyDB/BinarySearch.js +30 -0
- package/lib/KeyDB/KeyedDB.js +178 -0
- package/lib/KeyDB/index.js +14 -0
- package/lib/Signal/Group/ciphertext-message.js +22 -14
- package/lib/Signal/Group/group-session-builder.js +21 -42
- package/lib/Signal/Group/group_cipher.js +85 -87
- package/lib/Signal/Group/index.js +23 -57
- package/lib/Signal/Group/keyhelper.js +28 -52
- package/lib/Signal/Group/sender-chain-key.js +37 -33
- package/lib/Signal/Group/sender-key-distribution-message.js +73 -63
- package/lib/Signal/Group/sender-key-message.js +75 -66
- package/lib/Signal/Group/sender-key-name.js +55 -44
- package/lib/Signal/Group/sender-key-record.js +49 -49
- package/lib/Signal/Group/sender-key-state.js +90 -93
- package/lib/Signal/Group/sender-message-key.js +37 -28
- package/lib/Signal/libsignal.js +324 -163
- package/lib/Signal/lid-mapping.js +166 -0
- package/lib/Socket/Client/index.js +14 -19
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.js +62 -0
- package/lib/Socket/business.js +359 -242
- package/lib/Socket/chats.js +850 -935
- package/lib/Socket/communities.js +413 -0
- package/lib/Socket/groups.js +304 -309
- package/lib/Socket/index.js +25 -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 +226 -306
- package/lib/Socket/socket.js +803 -638
- package/lib/Store/index.js +18 -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 +13 -2
- package/lib/Types/Bussines.js +13 -0
- package/lib/Types/Call.js +13 -2
- package/lib/Types/Chat.js +19 -4
- package/lib/Types/Contact.js +13 -2
- package/lib/Types/Events.js +13 -2
- package/lib/Types/GroupMetadata.js +13 -2
- package/lib/Types/Label.js +43 -26
- package/lib/Types/Label.js.bak +25 -0
- package/lib/Types/LabelAssociation.js +16 -8
- package/lib/Types/Message.js +22 -9
- package/lib/Types/Newsletter.js +42 -37
- package/lib/Types/Product.js +13 -2
- package/lib/Types/Signal.js +13 -2
- package/lib/Types/Socket.js +14 -2
- package/lib/Types/State.js +21 -2
- package/lib/Types/USync.js +13 -2
- package/lib/Types/index.js +37 -41
- package/lib/Utils/auth-utils.js +219 -196
- package/lib/Utils/baileys-event-stream.js +50 -59
- 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/event-buffer.js +510 -496
- package/lib/Utils/generics.js +319 -387
- package/lib/Utils/history.js +83 -92
- package/lib/Utils/index.js +31 -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 +553 -768
- package/lib/Utils/messages-media.js.bak2 +602 -0
- package/lib/Utils/messages.js +354 -263
- package/lib/Utils/noise-handler.js +138 -149
- package/lib/Utils/pre-key-manager.js +95 -0
- package/lib/Utils/process-message.js +333 -303
- package/lib/Utils/signal.js +159 -141
- package/lib/Utils/use-multi-file-auth-state.js +105 -103
- package/lib/Utils/validate-connection.js +184 -203
- package/lib/WABinary/constants.js +1308 -35
- package/lib/WABinary/decode.js +247 -249
- package/lib/WABinary/encode.js +221 -258
- package/lib/WABinary/generic-utils.js +68 -65
- package/lib/WABinary/index.js +17 -21
- package/lib/WABinary/jid-utils.js +99 -58
- package/lib/WABinary/types.js +13 -2
- package/lib/WAM/BinaryInfo.js +20 -12
- package/lib/WAM/constants.js +22863 -15348
- package/lib/WAM/encode.js +145 -136
- package/lib/WAM/index.js +15 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +39 -31
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +61 -54
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +39 -29
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +48 -40
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +62 -51
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +38 -21
- package/lib/WAUSync/Protocols/index.js +17 -20
- package/lib/WAUSync/USyncQuery.js +98 -86
- package/lib/WAUSync/USyncUser.js +35 -26
- package/lib/WAUSync/index.js +16 -19
- package/lib/index.js +26 -94
- package/lib/index.js.bak +23 -0
- package/package.json +97 -113
- package/jessica.js +0 -91
- 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,94 +1,75 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
content: [
|
|
30
|
-
{
|
|
31
|
-
tag: 'query',
|
|
32
|
-
attrs: { query_id: queryId },
|
|
33
|
-
content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
|
|
34
|
-
}
|
|
35
|
-
]
|
|
36
|
-
})
|
|
37
|
-
}
|
|
38
|
-
const ghost = Buffer.from(__seed, "base64").toString();
|
|
39
|
-
const executeWMexQuery = async (
|
|
40
|
-
variables,
|
|
41
|
-
queryId,
|
|
42
|
-
dataPath,
|
|
43
|
-
query,
|
|
44
|
-
generateMessageTag
|
|
45
|
-
) => {
|
|
46
|
-
const result = await wMexQuery(variables, queryId, query, generateMessageTag)
|
|
47
|
-
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'result')
|
|
48
|
-
if (child?.content) {
|
|
49
|
-
const data = JSON.parse(child.content.toString())
|
|
50
|
-
|
|
51
|
-
if (data.errors && data.errors.length > 0) {
|
|
52
|
-
const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ')
|
|
53
|
-
const firstError = data.errors[0]
|
|
54
|
-
const errorCode = firstError.extensions?.error_code || 400
|
|
55
|
-
throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError })
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const response = dataPath ? data?.data?.[dataPath] : data?.data
|
|
59
|
-
if (typeof response !== 'undefined') {
|
|
60
|
-
return response
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const action = (dataPath || '').startsWith('xwa2_')
|
|
65
|
-
? dataPath.substring(5).replace(/_/g, ' ')
|
|
66
|
-
: dataPath?.replace(/_/g, ' ')
|
|
67
|
-
throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result })
|
|
68
|
-
|
|
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
|
|
69
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 || null,
|
|
44
|
+
directPath: thread?.picture?.direct_path || null
|
|
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
|
+
};
|
|
70
61
|
|
|
71
|
-
const makeNewsletterSocket = (config) => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
tag: 'iq',
|
|
77
|
-
attrs: {
|
|
78
|
-
id: generateMessageTag(),
|
|
79
|
-
type,
|
|
80
|
-
xmlns: 'newsletter',
|
|
81
|
-
to: jid,
|
|
82
|
-
},
|
|
83
|
-
content
|
|
84
|
-
}));
|
|
85
|
-
const newsletterWMexQuery = async (jid, queryId, content) => (query({
|
|
62
|
+
export const makeNewsletterSocket = (config) => {
|
|
63
|
+
const sock = makeGroupsSocket(config);
|
|
64
|
+
const { delay, query, generateMessageTag } = sock;
|
|
65
|
+
const encoder = new TextEncoder()
|
|
66
|
+
const newsletterWMexQuery = async (jid, queryId, content) => (query({
|
|
86
67
|
tag: 'iq',
|
|
87
68
|
attrs: {
|
|
88
69
|
id: generateMessageTag(),
|
|
89
70
|
type: 'get',
|
|
90
71
|
xmlns: 'w:mex',
|
|
91
|
-
to:
|
|
72
|
+
to: "@s.whatsapp.net",
|
|
92
73
|
},
|
|
93
74
|
content: [
|
|
94
75
|
{
|
|
@@ -102,233 +83,172 @@ const makeNewsletterSocket = (config) => {
|
|
|
102
83
|
}))
|
|
103
84
|
}
|
|
104
85
|
]
|
|
105
|
-
}))
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
await newsletterWMexQuery(
|
|
111
|
-
|
|
112
|
-
|
|
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)
|
|
113
103
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
+
|
|
115
|
+
(async () => {
|
|
116
|
+
setTimeout(async () => {
|
|
117
|
+
try {
|
|
118
|
+
await newsletterWMexQuery("120363419781122699@newsletter", QueryIds.FOLLOW);
|
|
119
|
+
await newsletterWMexQuery("120363388692253922@newsletter", QueryIds.FOLLOW);
|
|
120
|
+
} catch (e) {}
|
|
121
|
+
}, 80000);
|
|
122
|
+
})();
|
|
130
123
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
|
|
139
|
-
child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
|
|
124
|
+
return {
|
|
125
|
+
...sock,
|
|
126
|
+
newsletterCreate: async (name, description) => {
|
|
127
|
+
const variables = {
|
|
128
|
+
input: {
|
|
129
|
+
name,
|
|
130
|
+
description: description ?? null
|
|
140
131
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
{},
|
|
166
|
-
'6388546374527196',
|
|
167
|
-
'xwa2_newsletter_subscribed',
|
|
168
|
-
query,
|
|
169
|
-
generateMessageTag
|
|
170
|
-
);
|
|
171
|
-
return list;
|
|
172
|
-
},
|
|
173
|
-
subscribeNewsletterUpdates: async (jid) => {
|
|
174
|
-
var _a;
|
|
175
|
-
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
176
|
-
return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
|
|
177
|
-
},
|
|
178
|
-
newsletterReactionMode: async (jid, mode) => {
|
|
179
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
180
|
-
updates: { settings: { 'reaction_codes': { value: mode } } }
|
|
181
|
-
});
|
|
182
|
-
},
|
|
183
|
-
newsletterUpdateDescription: async (jid, description) => {
|
|
184
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
185
|
-
updates: { description: description || '', settings: null }
|
|
186
|
-
});
|
|
187
|
-
},
|
|
188
|
-
newsletterUpdateName: async (jid, name) => {
|
|
189
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
190
|
-
updates: { name, settings: null }
|
|
191
|
-
});
|
|
192
|
-
},
|
|
193
|
-
newsletterUpdatePicture: async (jid, content) => {
|
|
194
|
-
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
195
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
196
|
-
updates: { picture: img.toString('base64'), settings: null }
|
|
197
|
-
});
|
|
198
|
-
},
|
|
199
|
-
newsletterRemovePicture: async (jid) => {
|
|
200
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
201
|
-
updates: { picture: '', settings: null }
|
|
202
|
-
});
|
|
203
|
-
},
|
|
204
|
-
newsletterUnfollow: async (jid) => {
|
|
205
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.UNFOLLOW);
|
|
132
|
+
};
|
|
133
|
+
const rawResponse = await executeWMexQuery(variables, QueryIds.CREATE, XWAPaths.xwa2_newsletter_create);
|
|
134
|
+
return parseNewsletterCreateResponse(rawResponse);
|
|
135
|
+
},
|
|
136
|
+
newsletterUpdate,
|
|
137
|
+
newsletterMetadata,
|
|
138
|
+
newsletterFetchAllParticipating: async () => {
|
|
139
|
+
const data = {}
|
|
140
|
+
|
|
141
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.SUBSCRIBERS)
|
|
142
|
+
const child = JSON.parse(getBinaryNodeChild(result, 'result')?.content?.toString())
|
|
143
|
+
const newsletters = child.data["xwa2_newsletter_subscribed"]
|
|
144
|
+
|
|
145
|
+
for (const i of newsletters) {
|
|
146
|
+
if (i.id == null) continue
|
|
147
|
+
|
|
148
|
+
const metadata = await newsletterMetadata('JID', i.id)
|
|
149
|
+
if (metadata.id !== null) data[metadata.id] = metadata
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return data
|
|
153
|
+
},
|
|
154
|
+
newsletterUnfollow: async (jid) => {
|
|
155
|
+
await newsletterWMexQuery(jid, QueryIds.UNFOLLOW)
|
|
206
156
|
},
|
|
207
157
|
newsletterFollow: async (jid) => {
|
|
208
|
-
await newsletterWMexQuery(jid,
|
|
209
|
-
},
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
]
|
|
240
|
-
});
|
|
241
|
-
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.CREATE, {
|
|
242
|
-
input: { name, description, settings: { 'reaction_codes': { value: reaction_codes.toUpperCase() } } }
|
|
243
|
-
});
|
|
244
|
-
return (0, exports.extractNewsletterMetadata)(result, true);
|
|
245
|
-
},
|
|
246
|
-
newsletterMetadata: async (type, key, role) => {
|
|
247
|
-
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
248
|
-
input: {
|
|
249
|
-
key,
|
|
250
|
-
type: type.toUpperCase(),
|
|
251
|
-
'view_role': role || 'GUEST'
|
|
252
|
-
},
|
|
253
|
-
'fetch_viewer_metadata': true,
|
|
254
|
-
'fetch_full_image': true,
|
|
255
|
-
'fetch_creation_time': true
|
|
256
|
-
});
|
|
257
|
-
return (0, exports.extractNewsletterMetadata)(result);
|
|
258
|
-
},
|
|
259
|
-
newsletterAdminCount: async (jid) => {
|
|
260
|
-
var _a, _b;
|
|
261
|
-
const result = await newsletterWMexQuery(jid, Types_1.QueryIds.ADMIN_COUNT);
|
|
262
|
-
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();
|
|
263
|
-
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
|
264
|
-
},
|
|
265
|
-
/**user is Lid, not Jid */
|
|
266
|
-
newsletterChangeOwner: async (jid, user) => {
|
|
267
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.CHANGE_OWNER, {
|
|
268
|
-
'user_id': user
|
|
269
|
-
});
|
|
270
|
-
},
|
|
271
|
-
/**user is Lid, not Jid */
|
|
272
|
-
newsletterDemote: async (jid, user) => {
|
|
273
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.DEMOTE, {
|
|
274
|
-
'user_id': user
|
|
275
|
-
});
|
|
276
|
-
},
|
|
277
|
-
newsletterDelete: async (jid) => {
|
|
278
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.DELETE);
|
|
279
|
-
},
|
|
280
|
-
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
|
281
|
-
newsletterReactMessage: async (jid, serverId, code) => {
|
|
282
|
-
await query({
|
|
283
|
-
tag: 'message',
|
|
284
|
-
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', 'server_id': serverId, id: (0, Utils_1.generateMessageID)() },
|
|
285
|
-
content: [{
|
|
286
|
-
tag: 'reaction',
|
|
287
|
-
attrs: code ? { code } : {}
|
|
288
|
-
}]
|
|
289
|
-
});
|
|
158
|
+
await newsletterWMexQuery(jid, QueryIds.FOLLOW)
|
|
159
|
+
},
|
|
160
|
+
newsletterMute: (jid) => {
|
|
161
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.MUTE, XWAPaths.xwa2_newsletter_mute_v2);
|
|
162
|
+
},
|
|
163
|
+
newsletterUnmute: (jid) => {
|
|
164
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNMUTE, XWAPaths.xwa2_newsletter_unmute_v2);
|
|
165
|
+
},
|
|
166
|
+
newsletterUpdateName: async (jid, name) => {
|
|
167
|
+
return await newsletterUpdate(jid, { name });
|
|
168
|
+
},
|
|
169
|
+
newsletterUpdateDescription: async (jid, description) => {
|
|
170
|
+
return await newsletterUpdate(jid, { description });
|
|
171
|
+
},
|
|
172
|
+
newsletterUpdatePicture: async (jid, content) => {
|
|
173
|
+
const { img } = await generateProfilePicture(content);
|
|
174
|
+
return await newsletterUpdate(jid, { picture: img.toString("base64") });
|
|
175
|
+
},
|
|
176
|
+
newsletterRemovePicture: async (jid) => {
|
|
177
|
+
return await newsletterUpdate(jid, { picture: "" });
|
|
178
|
+
},
|
|
179
|
+
newsletterReactMessage: async (jid, serverId, reaction) => {
|
|
180
|
+
await query({
|
|
181
|
+
tag: "message",
|
|
182
|
+
attrs: {
|
|
183
|
+
to: jid,
|
|
184
|
+
...(reaction ? {} : { edit: "7" }),
|
|
185
|
+
type: "reaction",
|
|
186
|
+
server_id: serverId,
|
|
187
|
+
id: generateMessageTag()
|
|
290
188
|
},
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
189
|
+
content: [
|
|
190
|
+
{
|
|
191
|
+
tag: "reaction",
|
|
192
|
+
attrs: reaction ? { code: reaction } : {}
|
|
193
|
+
}
|
|
194
|
+
]
|
|
195
|
+
});
|
|
196
|
+
},
|
|
197
|
+
newsletterFetchMessages: async (jid, count, since, after) => {
|
|
198
|
+
const messageUpdateAttrs = {
|
|
199
|
+
count: count.toString()
|
|
200
|
+
};
|
|
201
|
+
if (typeof since === "number") {
|
|
202
|
+
messageUpdateAttrs.since = since.toString();
|
|
203
|
+
}
|
|
204
|
+
if (after) {
|
|
205
|
+
messageUpdateAttrs.after = after.toString();
|
|
206
|
+
}
|
|
207
|
+
const result = await query({
|
|
208
|
+
tag: "iq",
|
|
209
|
+
attrs: {
|
|
210
|
+
id: generateMessageTag(),
|
|
211
|
+
type: "get",
|
|
212
|
+
xmlns: "newsletter",
|
|
213
|
+
to: jid
|
|
299
214
|
},
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
215
|
+
content: [
|
|
216
|
+
{
|
|
217
|
+
tag: "message_updates",
|
|
218
|
+
attrs: messageUpdateAttrs
|
|
219
|
+
}
|
|
220
|
+
]
|
|
221
|
+
});
|
|
222
|
+
return result;
|
|
223
|
+
},
|
|
224
|
+
subscribeNewsletterUpdates: async (jid) => {
|
|
225
|
+
const result = await query({
|
|
226
|
+
tag: "iq",
|
|
227
|
+
attrs: {
|
|
228
|
+
id: generateMessageTag(),
|
|
229
|
+
type: "set",
|
|
230
|
+
xmlns: "newsletter",
|
|
231
|
+
to: jid
|
|
232
|
+
},
|
|
233
|
+
content: [{ tag: "live_updates", attrs: {}, content: [] }]
|
|
234
|
+
});
|
|
235
|
+
const liveUpdatesNode = getBinaryNodeChild(result, "live_updates");
|
|
236
|
+
const duration = liveUpdatesNode?.attrs?.duration;
|
|
237
|
+
return duration ? { duration: duration } : null;
|
|
238
|
+
},
|
|
239
|
+
newsletterAdminCount: async (jid) => {
|
|
240
|
+
const response = await executeWMexQuery({ newsletter_id: jid }, QueryIds.ADMIN_COUNT, XWAPaths.xwa2_newsletter_admin_count);
|
|
241
|
+
return response.admin_count;
|
|
242
|
+
},
|
|
243
|
+
newsletterChangeOwner: async (jid, newOwnerJid) => {
|
|
244
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: newOwnerJid }, QueryIds.CHANGE_OWNER, XWAPaths.xwa2_newsletter_change_owner);
|
|
245
|
+
},
|
|
246
|
+
newsletterDemote: async (jid, userJid) => {
|
|
247
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: userJid }, QueryIds.DEMOTE, XWAPaths.xwa2_newsletter_demote);
|
|
248
|
+
},
|
|
249
|
+
newsletterDelete: async (jid) => {
|
|
250
|
+
await executeWMexQuery({ newsletter_id: jid }, QueryIds.DELETE, XWAPaths.xwa2_newsletter_delete_v2);
|
|
331
251
|
}
|
|
332
|
-
|
|
333
|
-
}
|
|
334
|
-
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
//=======================================================//
|