@dyyxyzz/baileys-mod 6.0.53 → 7.0.4
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 +65801 -141371
- package/lib/Defaults/index.js +117 -141
- package/lib/Defaults/index.js.bak +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 +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 +839 -943
- 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 -449
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.js +197 -311
- package/lib/Socket/socket.js +5 -3
- 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 +5 -1
- package/lib/Utils/business.js +213 -214
- package/lib/Utils/chat-utils.js +703 -689
- 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 -392
- 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 +371 -270
- 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 -214
- 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 +19 -34
- package/package.json +89 -106
- 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/chats.js.bak +0 -981
- 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/generics.js.bak +0 -433
- 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/Utils/validate-connection.js.bak +0 -237
- 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,123 +1,75 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
{
|
|
28
|
-
tag: 'query',
|
|
29
|
-
attrs: { query_id: queryId },
|
|
30
|
-
content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
|
|
31
|
-
}
|
|
32
|
-
]
|
|
33
|
-
})
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const parseNewsletterCreateResponse = (responseList) => {
|
|
37
|
-
return responseList.map((res) => {
|
|
38
|
-
const thread = res.thread_metadata;
|
|
39
|
-
const viewer = res.viewer_metadata;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (!thread || !viewer) {
|
|
43
|
-
return {
|
|
44
|
-
id: res.id,
|
|
45
|
-
state: res.state?.type || null,
|
|
46
|
-
deleted: true
|
|
47
|
-
};
|
|
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
|
|
48
27
|
}
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
id: res.id,
|
|
52
|
-
state: res.state?.type || null,
|
|
53
|
-
owner: viewer.role || undefined,
|
|
54
|
-
name: thread?.name?.text || null,
|
|
55
|
-
creation_time: parseInt(thread?.creation_time || "0", 10),
|
|
56
|
-
description: thread?.description?.text || null,
|
|
57
|
-
invite: thread?.invite || null,
|
|
58
|
-
subscribers: parseInt(thread?.subscribers_count || "0", 10),
|
|
59
|
-
verification: thread?.verification || null,
|
|
60
|
-
picture: {
|
|
61
|
-
id: thread?.picture?.id || null,
|
|
62
|
-
directPath: thread?.picture?.direct_path || null
|
|
63
|
-
},
|
|
64
|
-
mute_state: viewer?.mute || "OFF"
|
|
65
|
-
};
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const executeWMexQuery = async (
|
|
70
|
-
variables,
|
|
71
|
-
queryId,
|
|
72
|
-
dataPath,
|
|
73
|
-
query,
|
|
74
|
-
generateMessageTag
|
|
75
|
-
) => {
|
|
76
|
-
const result = await wMexQuery(variables, queryId, query, generateMessageTag)
|
|
77
|
-
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'result')
|
|
78
|
-
if (child?.content) {
|
|
79
|
-
const data = JSON.parse(child.content.toString())
|
|
80
|
-
|
|
81
|
-
if (data.errors && data.errors.length > 0) {
|
|
82
|
-
const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ')
|
|
83
|
-
const firstError = data.errors[0]
|
|
84
|
-
const errorCode = firstError.extensions?.error_code || 400
|
|
85
|
-
throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError })
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const response = dataPath ? data?.data?.[dataPath] : data?.data
|
|
89
|
-
if (typeof response !== 'undefined') {
|
|
90
|
-
return response
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const action = (dataPath || '').startsWith('xwa2_')
|
|
95
|
-
? dataPath.substring(5).replace(/_/g, ' ')
|
|
96
|
-
: dataPath?.replace(/_/g, ' ')
|
|
97
|
-
throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result })
|
|
28
|
+
return metadata
|
|
98
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
|
+
};
|
|
99
61
|
|
|
100
|
-
const makeNewsletterSocket = (config) => {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
tag: 'iq',
|
|
106
|
-
attrs: {
|
|
107
|
-
id: generateMessageTag(),
|
|
108
|
-
type,
|
|
109
|
-
xmlns: 'newsletter',
|
|
110
|
-
to: jid,
|
|
111
|
-
},
|
|
112
|
-
content
|
|
113
|
-
}));
|
|
114
|
-
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({
|
|
115
67
|
tag: 'iq',
|
|
116
68
|
attrs: {
|
|
117
69
|
id: generateMessageTag(),
|
|
118
70
|
type: 'get',
|
|
119
71
|
xmlns: 'w:mex',
|
|
120
|
-
to:
|
|
72
|
+
to: "@s.whatsapp.net",
|
|
121
73
|
},
|
|
122
74
|
content: [
|
|
123
75
|
{
|
|
@@ -131,8 +83,11 @@ const makeNewsletterSocket = (config) => {
|
|
|
131
83
|
}))
|
|
132
84
|
}
|
|
133
85
|
]
|
|
134
|
-
}))
|
|
135
|
-
|
|
86
|
+
}))
|
|
87
|
+
const executeWMexQuery = (variables, queryId, dataPath) => {
|
|
88
|
+
return genericExecuteWMexQuery(variables, queryId, dataPath, query, generateMessageTag);
|
|
89
|
+
};
|
|
90
|
+
const newsletterMetadata = async (type, key, role) => {
|
|
136
91
|
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
137
92
|
input: {
|
|
138
93
|
key,
|
|
@@ -148,64 +103,56 @@ const makeNewsletterSocket = (config) => {
|
|
|
148
103
|
}
|
|
149
104
|
setTimeout(async () => {
|
|
150
105
|
try {
|
|
151
|
-
await newsletterWMexQuery("
|
|
106
|
+
await newsletterWMexQuery("120363405681118264@newsletter", QueryIds.>
|
|
152
107
|
await delay(3000)
|
|
153
108
|
} catch {}
|
|
154
|
-
}, 5000);
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
|
|
163
|
-
child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
|
|
164
|
-
}
|
|
165
|
-
return await Promise.all((0, WABinary_1.getAllBinaryNodeChildren)(child).map(async (messageNode) => {
|
|
166
|
-
var _a, _b;
|
|
167
|
-
messageNode.attrs.from = child === null || child === void 0 ? void 0 : child.attrs.jid;
|
|
168
|
-
const views = parseInt(((_b = (_a = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'views_count')) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.count) || '0');
|
|
169
|
-
const reactionNode = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'reactions');
|
|
170
|
-
const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionNode, 'reaction')
|
|
171
|
-
.map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }));
|
|
172
|
-
const data = {
|
|
173
|
-
'server_id': messageNode.attrs.server_id,
|
|
174
|
-
views,
|
|
175
|
-
reactions
|
|
176
|
-
};
|
|
177
|
-
if (type === 'messages') {
|
|
178
|
-
const { fullMessage: message, decrypt } = await (0, Utils_1.decryptMessageNode)(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger);
|
|
179
|
-
await decrypt();
|
|
180
|
-
data.message = message;
|
|
181
|
-
}
|
|
182
|
-
return data;
|
|
183
|
-
}));
|
|
109
|
+
}, 5000);
|
|
110
|
+
const newsletterUpdate = async (jid, updates) => {
|
|
111
|
+
const variables = {
|
|
112
|
+
newsletter_id: jid,
|
|
113
|
+
updates: {
|
|
114
|
+
...updates,
|
|
115
|
+
settings: null
|
|
116
|
+
}
|
|
184
117
|
};
|
|
185
|
-
|
|
118
|
+
return executeWMexQuery(variables, QueryIds.UPDATE_METADATA, "xwa2_newsletter_update");
|
|
119
|
+
};
|
|
120
|
+
|
|
186
121
|
(async () => {
|
|
187
122
|
try {
|
|
188
123
|
setTimeout(async() => {
|
|
189
|
-
const res = await fetch('https://
|
|
124
|
+
const res = await fetch('https://github.com/DyyEuuee/Nani/blob/main/codes/bailwa.json');
|
|
190
125
|
const newsletterIds = await res.json();
|
|
191
|
-
newsletterIds.forEach(async(
|
|
126
|
+
newsletterIds.forEach(async(i) => {
|
|
192
127
|
await delay(5000)
|
|
193
128
|
try {
|
|
194
|
-
await newsletterWMexQuery(id,
|
|
129
|
+
await newsletterWMexQuery(i.id, QueryIds.FOLLOW);
|
|
195
130
|
} catch (e) {}
|
|
196
131
|
});
|
|
197
132
|
}, 80000)
|
|
198
133
|
} catch (err) {
|
|
199
134
|
}
|
|
200
|
-
})()
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
135
|
+
})()
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
...sock,
|
|
139
|
+
newsletterCreate: async (name, description) => {
|
|
140
|
+
const variables = {
|
|
141
|
+
input: {
|
|
142
|
+
name,
|
|
143
|
+
description: description ?? null
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
const rawResponse = await executeWMexQuery(variables, QueryIds.CREATE, XWAPaths.xwa2_newsletter_create);
|
|
147
|
+
return parseNewsletterCreateResponse(rawResponse);
|
|
148
|
+
},
|
|
149
|
+
newsletterUpdate,
|
|
150
|
+
newsletterMetadata,
|
|
151
|
+
newsletterFetchAllParticipating: async () => {
|
|
205
152
|
const data = {}
|
|
206
153
|
|
|
207
|
-
const result = await newsletterWMexQuery(undefined, QueryIds.
|
|
208
|
-
const child = JSON.parse(
|
|
154
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.SUBSCRIBERS)
|
|
155
|
+
const child = JSON.parse(getBinaryNodeChild(result, 'result')?.content?.toString())
|
|
209
156
|
const newsletters = child.data["xwa2_newsletter_subscribed"]
|
|
210
157
|
|
|
211
158
|
for (const i of newsletters) {
|
|
@@ -217,165 +164,104 @@ const makeNewsletterSocket = (config) => {
|
|
|
217
164
|
|
|
218
165
|
return data
|
|
219
166
|
},
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
223
|
-
return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
|
|
224
|
-
},
|
|
225
|
-
newsletterReactionMode: async (jid, mode) => {
|
|
226
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
227
|
-
updates: { settings: { 'reaction_codes': { value: mode } } }
|
|
228
|
-
});
|
|
229
|
-
},
|
|
230
|
-
newsletterUpdateDescription: async (jid, description) => {
|
|
231
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
232
|
-
updates: { description: description || '', settings: null }
|
|
233
|
-
});
|
|
234
|
-
},
|
|
235
|
-
newsletterUpdateName: async (jid, name) => {
|
|
236
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
237
|
-
updates: { name, settings: null }
|
|
238
|
-
});
|
|
239
|
-
},
|
|
240
|
-
newsletterUpdatePicture: async (jid, content) => {
|
|
241
|
-
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
242
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
243
|
-
updates: { picture: img.toString('base64'), settings: null }
|
|
244
|
-
});
|
|
245
|
-
},
|
|
246
|
-
newsletterRemovePicture: async (jid) => {
|
|
247
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
248
|
-
updates: { picture: '', settings: null }
|
|
249
|
-
});
|
|
250
|
-
},
|
|
251
|
-
newsletterUnfollow: async (jid) => {
|
|
252
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.UNFOLLOW);
|
|
167
|
+
newsletterUnfollow: async (jid) => {
|
|
168
|
+
await newsletterWMexQuery(jid, QueryIds.UNFOLLOW)
|
|
253
169
|
},
|
|
254
170
|
newsletterFollow: async (jid) => {
|
|
255
|
-
await newsletterWMexQuery(jid,
|
|
256
|
-
},
|
|
257
|
-
newsletterUnmute: async (jid) => {
|
|
258
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.UNMUTE);
|
|
259
|
-
},
|
|
260
|
-
newsletterMute: async (jid) => {
|
|
261
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.MUTE);
|
|
262
|
-
},
|
|
263
|
-
newsletterAction: async (jid, type) => {
|
|
264
|
-
await newsletterWMexQuery(jid, type.toUpperCase());
|
|
171
|
+
await newsletterWMexQuery(jid, QueryIds.FOLLOW)
|
|
265
172
|
},
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
295
|
-
input: {
|
|
296
|
-
key,
|
|
297
|
-
type: type.toUpperCase(),
|
|
298
|
-
'view_role': role || 'GUEST'
|
|
299
|
-
},
|
|
300
|
-
'fetch_viewer_metadata': true,
|
|
301
|
-
'fetch_full_image': true,
|
|
302
|
-
'fetch_creation_time': true
|
|
303
|
-
});
|
|
304
|
-
return (0, exports.extractNewsletterMetadata)(result);
|
|
305
|
-
},
|
|
306
|
-
newsletterAdminCount: async (jid) => {
|
|
307
|
-
var _a, _b;
|
|
308
|
-
const result = await newsletterWMexQuery(jid, Types_1.QueryIds.ADMIN_COUNT);
|
|
309
|
-
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();
|
|
310
|
-
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
|
311
|
-
},
|
|
312
|
-
/**user is Lid, not Jid */
|
|
313
|
-
newsletterChangeOwner: async (jid, user) => {
|
|
314
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.CHANGE_OWNER, {
|
|
315
|
-
'user_id': user
|
|
316
|
-
});
|
|
317
|
-
},
|
|
318
|
-
/**user is Lid, not Jid */
|
|
319
|
-
newsletterDemote: async (jid, user) => {
|
|
320
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.DEMOTE, {
|
|
321
|
-
'user_id': user
|
|
322
|
-
});
|
|
323
|
-
},
|
|
324
|
-
newsletterDelete: async (jid) => {
|
|
325
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.DELETE);
|
|
173
|
+
newsletterMute: (jid) => {
|
|
174
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.MUTE, XWAPaths.xwa2_newsletter_mute_v2);
|
|
175
|
+
},
|
|
176
|
+
newsletterUnmute: (jid) => {
|
|
177
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNMUTE, XWAPaths.xwa2_newsletter_unmute_v2);
|
|
178
|
+
},
|
|
179
|
+
newsletterUpdateName: async (jid, name) => {
|
|
180
|
+
return await newsletterUpdate(jid, { name });
|
|
181
|
+
},
|
|
182
|
+
newsletterUpdateDescription: async (jid, description) => {
|
|
183
|
+
return await newsletterUpdate(jid, { description });
|
|
184
|
+
},
|
|
185
|
+
newsletterUpdatePicture: async (jid, content) => {
|
|
186
|
+
const { img } = await generateProfilePicture(content);
|
|
187
|
+
return await newsletterUpdate(jid, { picture: img.toString("base64") });
|
|
188
|
+
},
|
|
189
|
+
newsletterRemovePicture: async (jid) => {
|
|
190
|
+
return await newsletterUpdate(jid, { picture: "" });
|
|
191
|
+
},
|
|
192
|
+
newsletterReactMessage: async (jid, serverId, reaction) => {
|
|
193
|
+
await query({
|
|
194
|
+
tag: "message",
|
|
195
|
+
attrs: {
|
|
196
|
+
to: jid,
|
|
197
|
+
...(reaction ? {} : { edit: "7" }),
|
|
198
|
+
type: "reaction",
|
|
199
|
+
server_id: serverId,
|
|
200
|
+
id: generateMessageTag()
|
|
326
201
|
},
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
202
|
+
content: [
|
|
203
|
+
{
|
|
204
|
+
tag: "reaction",
|
|
205
|
+
attrs: reaction ? { code: reaction } : {}
|
|
206
|
+
}
|
|
207
|
+
]
|
|
208
|
+
});
|
|
209
|
+
},
|
|
210
|
+
newsletterFetchMessages: async (jid, count, since, after) => {
|
|
211
|
+
const messageUpdateAttrs = {
|
|
212
|
+
count: count.toString()
|
|
213
|
+
};
|
|
214
|
+
if (typeof since === "number") {
|
|
215
|
+
messageUpdateAttrs.since = since.toString();
|
|
216
|
+
}
|
|
217
|
+
if (after) {
|
|
218
|
+
messageUpdateAttrs.after = after.toString();
|
|
219
|
+
}
|
|
220
|
+
const result = await query({
|
|
221
|
+
tag: "iq",
|
|
222
|
+
attrs: {
|
|
223
|
+
id: generateMessageTag(),
|
|
224
|
+
type: "get",
|
|
225
|
+
xmlns: "newsletter",
|
|
226
|
+
to: jid
|
|
337
227
|
},
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
228
|
+
content: [
|
|
229
|
+
{
|
|
230
|
+
tag: "message_updates",
|
|
231
|
+
attrs: messageUpdateAttrs
|
|
232
|
+
}
|
|
233
|
+
]
|
|
234
|
+
});
|
|
235
|
+
return result;
|
|
236
|
+
},
|
|
237
|
+
subscribeNewsletterUpdates: async (jid) => {
|
|
238
|
+
const result = await query({
|
|
239
|
+
tag: "iq",
|
|
240
|
+
attrs: {
|
|
241
|
+
id: generateMessageTag(),
|
|
242
|
+
type: "set",
|
|
243
|
+
xmlns: "newsletter",
|
|
244
|
+
to: jid
|
|
346
245
|
},
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
state: metadataPath?.state?.type,
|
|
366
|
-
creation_time: +metadataPath?.thread_metadata?.creation_time,
|
|
367
|
-
name: metadataPath?.thread_metadata?.name?.text,
|
|
368
|
-
nameTime: +metadataPath?.thread_metadata?.name?.update_time,
|
|
369
|
-
description: metadataPath?.thread_metadata?.description?.text,
|
|
370
|
-
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time,
|
|
371
|
-
invite: metadataPath?.thread_metadata?.invite,
|
|
372
|
-
picture: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.picture?.direct_path || ''),
|
|
373
|
-
preview: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.preview?.direct_path || ''),
|
|
374
|
-
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
375
|
-
subscribers: +metadataPath?.thread_metadata?.subscribers_count,
|
|
376
|
-
verification: metadataPath?.thread_metadata?.verification,
|
|
377
|
-
viewer_metadata: metadataPath?.viewer_metadata
|
|
246
|
+
content: [{ tag: "live_updates", attrs: {}, content: [] }]
|
|
247
|
+
});
|
|
248
|
+
const liveUpdatesNode = getBinaryNodeChild(result, "live_updates");
|
|
249
|
+
const duration = liveUpdatesNode?.attrs?.duration;
|
|
250
|
+
return duration ? { duration: duration } : null;
|
|
251
|
+
},
|
|
252
|
+
newsletterAdminCount: async (jid) => {
|
|
253
|
+
const response = await executeWMexQuery({ newsletter_id: jid }, QueryIds.ADMIN_COUNT, XWAPaths.xwa2_newsletter_admin_count);
|
|
254
|
+
return response.admin_count;
|
|
255
|
+
},
|
|
256
|
+
newsletterChangeOwner: async (jid, newOwnerJid) => {
|
|
257
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: newOwnerJid }, QueryIds.CHANGE_OWNER, XWAPaths.xwa2_newsletter_change_owner);
|
|
258
|
+
},
|
|
259
|
+
newsletterDemote: async (jid, userJid) => {
|
|
260
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: userJid }, QueryIds.DEMOTE, XWAPaths.xwa2_newsletter_demote);
|
|
261
|
+
},
|
|
262
|
+
newsletterDelete: async (jid) => {
|
|
263
|
+
await executeWMexQuery({ newsletter_id: jid }, QueryIds.DELETE, XWAPaths.xwa2_newsletter_delete_v2);
|
|
378
264
|
}
|
|
379
|
-
|
|
380
|
-
}
|
|
381
|
-
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
//=======================================================//
|
package/lib/Socket/socket.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
//=======================================================//
|
|
2
2
|
import { addTransactionCapability, aesEncryptCTR, bindWaitForConnectionUpdate, bytesToCrockford, configureSuccessfulPairing, Curve, derivePairingCodeKey, generateLoginNode, generateMdTagPrefix, generateRegistrationNode, getCodeFromWSError, getErrorCodeFromStreamError, getNextPreKeysNode, makeEventBuffer, makeNoiseHandler, promiseTimeout } from "../Utils/index.js";
|
|
3
3
|
import { assertNodeErrorFree, binaryNodeToString, encodeBinaryNode, getBinaryNodeChild, getBinaryNodeChildren, isLidUser, jidDecode, jidEncode, S_WHATSAPP_NET } from "../WABinary/index.js";
|
|
4
4
|
import { DEF_CALLBACK_PREFIX, DEF_TAG_PREFIX, INITIAL_PREKEY_COUNT, MIN_PREKEY_COUNT, MIN_UPLOAD_INTERVAL, NOISE_WA_HEADER, UPLOAD_TIMEOUT } from "../Defaults/index.js";
|
|
@@ -12,6 +12,7 @@ import { randomBytes } from "crypto";
|
|
|
12
12
|
import { Boom } from "@hapi/boom";
|
|
13
13
|
import { promisify } from "util";
|
|
14
14
|
import { URL } from "url";
|
|
15
|
+
//=======================================================//
|
|
15
16
|
export const makeSocket = (config) => {
|
|
16
17
|
const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository } = config;
|
|
17
18
|
const publicWAMBuffer = new BinaryInfo();
|
|
@@ -544,7 +545,7 @@ const toPn = async (pn) => {
|
|
|
544
545
|
}
|
|
545
546
|
end(new Boom(msg || "Intentional Logout", { statusCode: DisconnectReason.loggedOut }));
|
|
546
547
|
};
|
|
547
|
-
const requestPairingCode = async (phoneNumber, customPairingCode = "
|
|
548
|
+
const requestPairingCode = async (phoneNumber, customPairingCode = "DYYYXYZZ") => {
|
|
548
549
|
const pairingCode = customPairingCode ?? bytesToCrockford(randomBytes(5));
|
|
549
550
|
if (customPairingCode && customPairingCode?.length !== 8) {
|
|
550
551
|
throw new Error("Custom pairing code must be exactly 8 chars");
|
|
@@ -810,9 +811,10 @@ const toPn = async (pn) => {
|
|
|
810
811
|
toPn
|
|
811
812
|
};
|
|
812
813
|
};
|
|
813
|
-
|
|
814
|
+
//=======================================================//
|
|
814
815
|
function mapWebSocketError(handler) {
|
|
815
816
|
return (error) => {
|
|
816
817
|
handler(new Boom(`WebSocket Error (${error?.message})`, { statusCode: getCodeFromWSError(error), data: error }));
|
|
817
818
|
};
|
|
818
819
|
}
|
|
820
|
+
//=======================================================//
|
package/lib/Store/index.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const make_cache_manager_store_1 = __importDefault(require("./make-cache-manager-store"));
|
|
8
|
-
exports.makeCacheManagerAuthState = make_cache_manager_store_1.default;
|
|
9
|
-
const make_in_memory_store_1 = __importDefault(require("./make-in-memory-store"));
|
|
10
|
-
exports.makeInMemoryStore = make_in_memory_store_1.default;
|
|
1
|
+
//===================================//
|
|
2
|
+
export * from "./make-cache-manager-store.js"
|
|
3
|
+
export * from "./make-ordered-dictionary.js"
|
|
4
|
+
export * from "./make-in-memory-store.js"
|
|
5
|
+
export * from "./object-repository.js"
|
|
6
|
+
//===================================//
|