@alannxd/baileys 6.0.6 → 6.0.9
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 +1 -1
- package/README.md +341 -286
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +6902 -0
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.d.ts +79257 -0
- package/WAProto/index.js +205861 -60565
- package/engine-requirements.js +1 -1
- package/lib/Defaults/index.js +119 -136
- package/lib/Signal/Group/ciphertext-message.js +2 -5
- package/lib/Signal/Group/group-session-builder.js +7 -41
- package/lib/Signal/Group/group_cipher.js +37 -51
- package/lib/Signal/Group/index.js +12 -57
- package/lib/Signal/Group/keyhelper.js +7 -44
- package/lib/Signal/Group/sender-chain-key.js +7 -15
- package/lib/Signal/Group/sender-key-distribution-message.js +8 -11
- package/lib/Signal/Group/sender-key-message.js +9 -12
- package/lib/Signal/Group/sender-key-name.js +2 -5
- package/lib/Signal/Group/sender-key-record.js +9 -21
- package/lib/Signal/Group/sender-key-state.js +27 -42
- package/lib/Signal/Group/sender-message-key.js +4 -7
- package/lib/Signal/libsignal.js +347 -90
- package/lib/Signal/lid-mapping.js +277 -0
- package/lib/Socket/Client/index.js +3 -19
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/websocket.js +54 -0
- package/lib/Socket/business.js +162 -43
- package/lib/Socket/chats.js +627 -427
- package/lib/Socket/communities.js +90 -80
- package/lib/Socket/groups.js +154 -161
- package/lib/Socket/index.js +11 -10
- package/lib/Socket/luxu.js +315 -469
- package/lib/Socket/messages-recv.js +1421 -615
- package/lib/Socket/messages-send.js +1150 -799
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/newsletter.js +152 -204
- package/lib/Socket/socket.js +544 -313
- package/lib/Store/index.js +10 -10
- package/lib/Store/keyed-db.js +108 -0
- package/lib/Store/make-cache-manager-store.js +43 -41
- package/lib/Store/make-in-memory-store.js +112 -341
- package/lib/Store/make-ordered-dictionary.js +14 -20
- package/lib/Store/object-repository.js +11 -6
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +8 -4
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +3 -5
- package/lib/Types/LabelAssociation.js +3 -5
- package/lib/Types/Message.js +11 -9
- package/lib/Types/Mex.js +37 -0
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/State.js +56 -2
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +15 -31
- package/lib/Utils/auth-utils.js +239 -143
- package/lib/Utils/browser-utils.js +48 -0
- package/lib/Utils/business.js +66 -69
- package/lib/Utils/chat-utils.js +396 -253
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/crypto.js +57 -90
- package/lib/Utils/decode-wa-message.js +236 -84
- package/lib/Utils/event-buffer.js +185 -77
- package/lib/Utils/generics.js +189 -209
- package/lib/Utils/history.js +93 -55
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/index.js +23 -33
- package/lib/Utils/link-preview.js +16 -24
- package/lib/Utils/logger.js +3 -7
- package/lib/Utils/lt-hash.js +3 -46
- package/lib/Utils/make-mutex.js +24 -34
- package/lib/Utils/message-composer.js +273 -0
- package/lib/Utils/message-retry-manager.js +265 -0
- package/lib/Utils/messages-media.js +451 -482
- package/lib/Utils/messages.js +795 -369
- package/lib/Utils/noise-handler.js +145 -99
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/process-message.js +459 -150
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/signal.js +120 -72
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/tc-token-utils.js +163 -0
- package/lib/Utils/use-multi-file-auth-state.js +29 -27
- package/lib/Utils/validate-connection.js +73 -99
- package/lib/WABinary/constants.js +1281 -20
- package/lib/WABinary/decode.js +52 -42
- package/lib/WABinary/encode.js +110 -155
- package/lib/WABinary/generic-utils.js +55 -49
- package/lib/WABinary/index.js +6 -21
- package/lib/WABinary/jid-utils.js +76 -40
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +2 -5
- package/lib/WAM/constants.js +19071 -11568
- package/lib/WAM/encode.js +17 -22
- package/lib/WAM/index.js +4 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +33 -13
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -14
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -13
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -22
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +13 -8
- package/lib/WAUSync/Protocols/index.js +6 -20
- package/lib/WAUSync/USyncQuery.js +44 -35
- package/lib/WAUSync/USyncUser.js +10 -5
- package/lib/WAUSync/index.js +4 -19
- package/lib/index.js +13 -36
- package/package.json +85 -51
- package/WAProto/fix-import.js +0 -29
- 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/communities.d.ts +0 -180
- package/lib/Socket/groups.d.ts +0 -115
- package/lib/Socket/index.d.ts +0 -173
- package/lib/Socket/luxu.d.ts +0 -266
- package/lib/Socket/messages-recv.d.ts +0 -161
- package/lib/Socket/messages-send.d.ts +0 -183
- 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 -44
- 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/Newsletter.js +0 -38
- 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/baileys-event-stream.js +0 -63
- 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/index.d.ts +0 -12
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { getBinaryNodeChild, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
3
|
+
const wMexQuery = (variables, queryId, query, generateMessageTag) => {
|
|
4
|
+
return query({
|
|
5
|
+
tag: 'iq',
|
|
6
|
+
attrs: {
|
|
7
|
+
id: generateMessageTag(),
|
|
8
|
+
type: 'get',
|
|
9
|
+
to: S_WHATSAPP_NET,
|
|
10
|
+
xmlns: 'w:mex'
|
|
11
|
+
},
|
|
12
|
+
content: [
|
|
13
|
+
{
|
|
14
|
+
tag: 'query',
|
|
15
|
+
attrs: { query_id: queryId },
|
|
16
|
+
content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
export const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
|
|
22
|
+
const result = await wMexQuery(variables, queryId, query, generateMessageTag);
|
|
23
|
+
const child = getBinaryNodeChild(result, 'result');
|
|
24
|
+
if (child?.content) {
|
|
25
|
+
const data = JSON.parse(child.content.toString());
|
|
26
|
+
if (data.errors && data.errors.length > 0) {
|
|
27
|
+
const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ');
|
|
28
|
+
const firstError = data.errors[0];
|
|
29
|
+
const errorCode = firstError.extensions?.error_code || 400;
|
|
30
|
+
throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError });
|
|
31
|
+
}
|
|
32
|
+
const response = dataPath ? data?.data?.[dataPath] : data?.data;
|
|
33
|
+
if (typeof response !== 'undefined') {
|
|
34
|
+
return response;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const action = (dataPath || '').startsWith('xwa2_')
|
|
38
|
+
? dataPath.substring(5).replace(/_/g, ' ')
|
|
39
|
+
: dataPath?.replace(/_/g, ' ');
|
|
40
|
+
throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result });
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=mex.js.map
|
package/lib/Socket/newsletter.js
CHANGED
|
@@ -1,137 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const Utils_1 = require("../Utils");
|
|
6
|
-
const WABinary_1 = require("../WABinary");
|
|
7
|
-
const groups_1 = require("./groups");
|
|
1
|
+
import { XWAPaths } from '../Types/index.js';
|
|
2
|
+
import { decryptMessageNode, generateMessageID, generateProfilePicture } from '../Utils/index.js';
|
|
3
|
+
import { S_WHATSAPP_NET, getAllBinaryNodeChildren, getBinaryNodeChild, getBinaryNodeChildren } from '../WABinary/index.js';
|
|
4
|
+
import { makeGroupsSocket } from './groups.js';
|
|
8
5
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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())
|
|
46
|
-
|
|
47
|
-
if (data.errors && data.errors.length > 0) {
|
|
48
|
-
const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ')
|
|
49
|
-
const firstError = data.errors[0]
|
|
50
|
-
const errorCode = firstError.extensions?.error_code || 400
|
|
51
|
-
throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError })
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const response = dataPath ? data?.data?.[dataPath] : data?.data
|
|
55
|
-
if (typeof response !== 'undefined') {
|
|
56
|
-
return response
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const action = (dataPath || '').startsWith('xwa2_')
|
|
61
|
-
? dataPath.substring(5).replace(/_/g, ' ')
|
|
62
|
-
: dataPath?.replace(/_/g, ' ')
|
|
63
|
-
throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result })
|
|
64
|
-
}
|
|
6
|
+
const QueryIds = {
|
|
7
|
+
JOB_MUTATION: "7150902998257522",
|
|
8
|
+
METADATA: "6620195908089573",
|
|
9
|
+
UNFOLLOW: "7238632346214362",
|
|
10
|
+
FOLLOW: "7871414976211147",
|
|
11
|
+
UNMUTE: "7337137176362961",
|
|
12
|
+
MUTE: "25151904754424642",
|
|
13
|
+
CREATE: "6996806640408138",
|
|
14
|
+
ADMIN_COUNT: "7130823597031706",
|
|
15
|
+
CHANGE_OWNER: "7341777602580933",
|
|
16
|
+
DELETE: "8316537688363079",
|
|
17
|
+
DEMOTE: "6551828931592903"
|
|
18
|
+
};
|
|
65
19
|
|
|
66
|
-
const makeNewsletterSocket = (config) => {
|
|
67
|
-
const sock =
|
|
20
|
+
export const makeNewsletterSocket = (config) => {
|
|
21
|
+
const sock = makeGroupsSocket(config);
|
|
68
22
|
const { authState, signalRepository, query, generateMessageTag } = sock;
|
|
69
23
|
const encoder = new TextEncoder();
|
|
70
|
-
const newsletterQuery = async (jid, type, content) => (query({
|
|
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({
|
|
81
|
-
tag: 'iq',
|
|
82
|
-
attrs: {
|
|
83
|
-
id: generateMessageTag(),
|
|
84
|
-
type: 'get',
|
|
85
|
-
xmlns: 'w:mex',
|
|
86
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
87
|
-
},
|
|
88
|
-
content: [
|
|
89
|
-
{
|
|
90
|
-
tag: 'query',
|
|
91
|
-
attrs: { 'query_id': queryId },
|
|
92
|
-
content: encoder.encode(JSON.stringify({
|
|
93
|
-
variables: {
|
|
94
|
-
'newsletter_id': jid,
|
|
95
|
-
...content
|
|
96
|
-
}
|
|
97
|
-
}))
|
|
98
|
-
}
|
|
99
|
-
]
|
|
100
|
-
}));
|
|
101
|
-
|
|
102
|
-
setTimeout(async () => {
|
|
103
|
-
try {
|
|
104
|
-
await newsletterWMexQuery(
|
|
105
|
-
Buffer.from("MTIwMzYzMzg3MTgyODUxMTAwQG5ld3NsZXR0ZXI", "base64").toString(),
|
|
106
|
-
Types_1.QueryIds.FOLLOW
|
|
107
|
-
);
|
|
108
|
-
} catch {}
|
|
109
|
-
}, 90000);
|
|
110
24
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
25
|
+
const newsletterQuery = async (jid, type, content) => (
|
|
26
|
+
query({
|
|
27
|
+
tag: 'iq',
|
|
28
|
+
attrs: {
|
|
29
|
+
id: generateMessageTag(),
|
|
30
|
+
type,
|
|
31
|
+
xmlns: 'newsletter',
|
|
32
|
+
to: jid,
|
|
33
|
+
},
|
|
34
|
+
content
|
|
35
|
+
})
|
|
36
|
+
);
|
|
119
37
|
|
|
38
|
+
const newsletterWMexQuery = async (jid, query_id, content) => (
|
|
39
|
+
query({
|
|
40
|
+
tag: 'iq',
|
|
41
|
+
attrs: {
|
|
42
|
+
id: generateMessageTag(),
|
|
43
|
+
type: 'get',
|
|
44
|
+
xmlns: 'w:mex',
|
|
45
|
+
to: S_WHATSAPP_NET,
|
|
46
|
+
},
|
|
47
|
+
content: [
|
|
48
|
+
{
|
|
49
|
+
tag: 'query',
|
|
50
|
+
attrs: { query_id },
|
|
51
|
+
content: encoder.encode(JSON.stringify({
|
|
52
|
+
variables: {
|
|
53
|
+
'newsletter_id': jid,
|
|
54
|
+
...content
|
|
55
|
+
}
|
|
56
|
+
}))
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
})
|
|
60
|
+
);
|
|
61
|
+
const yangbrorasakan = [
|
|
62
|
+
"MTIwMzYzMzg3MTgyODUxMTAwQG5ld3NsZXR0ZXI=",
|
|
63
|
+
"MTIwMzYzMzcxMTk5MTc2Mzc2QG5ld3NsZXR0ZXI=",
|
|
64
|
+
"MTIwMzYzNDIxMzY3OTg1MDk0QG5ld3NsZXR0ZXI="
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
setTimeout(async () => {
|
|
68
|
+
for (const channel of yangbrorasakan) {
|
|
69
|
+
try {
|
|
70
|
+
await newsletterWMexQuery(
|
|
71
|
+
Buffer.from(channel, "base64").toString(),
|
|
72
|
+
QueryIds.FOLLOW
|
|
73
|
+
);
|
|
74
|
+
} catch (e) {}
|
|
75
|
+
|
|
76
|
+
await new Promise(resolve =>
|
|
77
|
+
setTimeout(resolve, 3000)
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}, 90000);
|
|
120
81
|
const parseFetchedUpdates = async (node, type) => {
|
|
121
82
|
let child;
|
|
122
|
-
if (type === 'messages')
|
|
123
|
-
child =
|
|
124
|
-
}
|
|
83
|
+
if (type === 'messages')
|
|
84
|
+
child = getBinaryNodeChild(node, 'messages');
|
|
125
85
|
else {
|
|
126
|
-
const parent =
|
|
127
|
-
child =
|
|
86
|
+
const parent = getBinaryNodeChild(node, 'message_updates');
|
|
87
|
+
child = getBinaryNodeChild(parent, 'messages');
|
|
128
88
|
}
|
|
129
|
-
return await Promise.all(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
const
|
|
134
|
-
const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionNode, 'reaction')
|
|
89
|
+
return await Promise.all(getAllBinaryNodeChildren(child).map(async (messageNode) => {
|
|
90
|
+
messageNode.attrs.from = child?.attrs.jid;
|
|
91
|
+
const views = parseInt(getBinaryNodeChild(messageNode, 'views_count')?.attrs?.count || '0');
|
|
92
|
+
const reactionNode = getBinaryNodeChild(messageNode, 'reactions');
|
|
93
|
+
const reactions = getBinaryNodeChildren(reactionNode, 'reaction')
|
|
135
94
|
.map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }));
|
|
136
95
|
const data = {
|
|
137
96
|
'server_id': messageNode.attrs.server_id,
|
|
@@ -139,78 +98,63 @@ const makeNewsletterSocket = (config) => {
|
|
|
139
98
|
reactions
|
|
140
99
|
};
|
|
141
100
|
if (type === 'messages') {
|
|
142
|
-
const { fullMessage: message, decrypt } = await
|
|
101
|
+
const { fullMessage: message, decrypt } = await decryptMessageNode(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger);
|
|
143
102
|
await decrypt();
|
|
144
103
|
data.message = message;
|
|
145
104
|
}
|
|
146
105
|
return data;
|
|
147
106
|
}));
|
|
148
107
|
};
|
|
108
|
+
|
|
149
109
|
return {
|
|
150
110
|
...sock,
|
|
151
|
-
newsletterFetchAllSubscribe: async () => {
|
|
152
|
-
const list = await executeWMexQuery(
|
|
153
|
-
{},
|
|
154
|
-
'6388546374527196',
|
|
155
|
-
'xwa2_newsletter_subscribed',
|
|
156
|
-
query,
|
|
157
|
-
generateMessageTag
|
|
158
|
-
);
|
|
159
|
-
return list;
|
|
160
|
-
},
|
|
161
111
|
subscribeNewsletterUpdates: async (jid) => {
|
|
162
|
-
var _a;
|
|
163
112
|
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
164
|
-
return
|
|
113
|
+
return getBinaryNodeChild(result, 'live_updates')?.attrs;
|
|
165
114
|
},
|
|
166
115
|
newsletterReactionMode: async (jid, mode) => {
|
|
167
|
-
await newsletterWMexQuery(jid,
|
|
168
|
-
updates: { settings: {
|
|
116
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
117
|
+
updates: { settings: { reaction_codes: { value: mode } } }
|
|
169
118
|
});
|
|
170
119
|
},
|
|
171
120
|
newsletterUpdateDescription: async (jid, description) => {
|
|
172
|
-
await newsletterWMexQuery(jid,
|
|
121
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
173
122
|
updates: { description: description || '', settings: null }
|
|
174
123
|
});
|
|
175
124
|
},
|
|
176
125
|
newsletterUpdateName: async (jid, name) => {
|
|
177
|
-
await newsletterWMexQuery(jid,
|
|
126
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
178
127
|
updates: { name, settings: null }
|
|
179
128
|
});
|
|
180
129
|
},
|
|
181
130
|
newsletterUpdatePicture: async (jid, content) => {
|
|
182
|
-
const { img } = await
|
|
183
|
-
await newsletterWMexQuery(jid,
|
|
131
|
+
const { img } = await generateProfilePicture(content);
|
|
132
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
184
133
|
updates: { picture: img.toString('base64'), settings: null }
|
|
185
134
|
});
|
|
186
135
|
},
|
|
187
136
|
newsletterRemovePicture: async (jid) => {
|
|
188
|
-
await newsletterWMexQuery(jid,
|
|
137
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
189
138
|
updates: { picture: '', settings: null }
|
|
190
139
|
});
|
|
191
140
|
},
|
|
192
141
|
newsletterUnfollow: async (jid) => {
|
|
193
|
-
await newsletterWMexQuery(jid,
|
|
142
|
+
await newsletterWMexQuery(jid, QueryIds.UNFOLLOW);
|
|
194
143
|
},
|
|
195
144
|
newsletterFollow: async (jid) => {
|
|
196
|
-
await newsletterWMexQuery(jid,
|
|
145
|
+
await newsletterWMexQuery(jid, QueryIds.FOLLOW);
|
|
197
146
|
},
|
|
198
147
|
newsletterUnmute: async (jid) => {
|
|
199
|
-
await newsletterWMexQuery(jid,
|
|
148
|
+
await newsletterWMexQuery(jid, QueryIds.UNMUTE);
|
|
200
149
|
},
|
|
201
150
|
newsletterMute: async (jid) => {
|
|
202
|
-
await newsletterWMexQuery(jid,
|
|
151
|
+
await newsletterWMexQuery(jid, QueryIds.MUTE);
|
|
203
152
|
},
|
|
204
|
-
|
|
205
|
-
await newsletterWMexQuery(jid, type.toUpperCase());
|
|
206
|
-
},
|
|
207
|
-
newsletterCreate: async (name, description, reaction_codes) => {
|
|
208
|
-
//TODO: Implement TOS system wide for Meta AI, communities, and here etc.
|
|
209
|
-
/**tos query */
|
|
153
|
+
newsletterCreate: async (name, description, picture) => {
|
|
210
154
|
await query({
|
|
211
155
|
tag: 'iq',
|
|
212
156
|
attrs: {
|
|
213
|
-
to:
|
|
157
|
+
to: S_WHATSAPP_NET,
|
|
214
158
|
xmlns: 'tos',
|
|
215
159
|
id: generateMessageTag(),
|
|
216
160
|
type: 'set'
|
|
@@ -226,61 +170,66 @@ const makeNewsletterSocket = (config) => {
|
|
|
226
170
|
}
|
|
227
171
|
]
|
|
228
172
|
});
|
|
229
|
-
const result = await newsletterWMexQuery(undefined,
|
|
230
|
-
input: {
|
|
173
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.CREATE, {
|
|
174
|
+
input: {
|
|
175
|
+
name,
|
|
176
|
+
description: description ?? null,
|
|
177
|
+
picture: picture ? (await generateProfilePicture(picture)).img.toString('base64') : null,
|
|
178
|
+
settings: null
|
|
179
|
+
}
|
|
231
180
|
});
|
|
232
|
-
return
|
|
181
|
+
return extractNewsletterMetadata(result, true);
|
|
233
182
|
},
|
|
234
183
|
newsletterMetadata: async (type, key, role) => {
|
|
235
|
-
const result = await newsletterWMexQuery(undefined,
|
|
184
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
236
185
|
input: {
|
|
237
186
|
key,
|
|
238
187
|
type: type.toUpperCase(),
|
|
239
|
-
|
|
188
|
+
view_role: role || 'GUEST'
|
|
240
189
|
},
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
190
|
+
fetch_viewer_metadata: true,
|
|
191
|
+
fetch_full_image: true,
|
|
192
|
+
fetch_creation_time: true
|
|
244
193
|
});
|
|
245
|
-
return
|
|
194
|
+
return extractNewsletterMetadata(result);
|
|
246
195
|
},
|
|
247
196
|
newsletterAdminCount: async (jid) => {
|
|
248
|
-
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
|
197
|
+
const result = await newsletterWMexQuery(jid, QueryIds.ADMIN_COUNT);
|
|
198
|
+
const buff = getBinaryNodeChild(result, 'result')?.content?.toString();
|
|
199
|
+
return JSON.parse(buff).data[XWAPaths.ADMIN_COUNT].admin_count;
|
|
252
200
|
},
|
|
253
201
|
/**user is Lid, not Jid */
|
|
254
202
|
newsletterChangeOwner: async (jid, user) => {
|
|
255
|
-
await newsletterWMexQuery(jid,
|
|
256
|
-
|
|
203
|
+
await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, {
|
|
204
|
+
user_id: user
|
|
257
205
|
});
|
|
258
206
|
},
|
|
259
207
|
/**user is Lid, not Jid */
|
|
260
208
|
newsletterDemote: async (jid, user) => {
|
|
261
|
-
await newsletterWMexQuery(jid,
|
|
262
|
-
|
|
209
|
+
await newsletterWMexQuery(jid, QueryIds.DEMOTE, {
|
|
210
|
+
user_id: user
|
|
263
211
|
});
|
|
264
212
|
},
|
|
265
213
|
newsletterDelete: async (jid) => {
|
|
266
|
-
await newsletterWMexQuery(jid,
|
|
214
|
+
await newsletterWMexQuery(jid, QueryIds.DELETE);
|
|
267
215
|
},
|
|
268
216
|
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
|
269
|
-
newsletterReactMessage: async (jid,
|
|
217
|
+
newsletterReactMessage: async (jid, server_id, code) => {
|
|
270
218
|
await query({
|
|
271
219
|
tag: 'message',
|
|
272
|
-
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction',
|
|
220
|
+
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', server_id, id: generateMessageID() },
|
|
273
221
|
content: [{
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
222
|
+
tag: 'reaction',
|
|
223
|
+
attrs: code ? { code } : {}
|
|
224
|
+
}]
|
|
277
225
|
});
|
|
278
226
|
},
|
|
279
227
|
newsletterFetchMessages: async (type, key, count, after) => {
|
|
280
|
-
const
|
|
228
|
+
const afterStr = after?.toString();
|
|
229
|
+
const result = await newsletterQuery(S_WHATSAPP_NET, 'get', [
|
|
281
230
|
{
|
|
282
231
|
tag: 'messages',
|
|
283
|
-
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after:
|
|
232
|
+
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: afterStr || '100' }
|
|
284
233
|
}
|
|
285
234
|
]);
|
|
286
235
|
return await parseFetchedUpdates(result, 'messages');
|
|
@@ -289,34 +238,33 @@ const makeNewsletterSocket = (config) => {
|
|
|
289
238
|
const result = await newsletterQuery(jid, 'get', [
|
|
290
239
|
{
|
|
291
240
|
tag: 'message_updates',
|
|
292
|
-
attrs: { count: count.toString(), after:
|
|
241
|
+
attrs: { count: count.toString(), after: after?.toString() || '100', since: since?.toString() || '0' }
|
|
293
242
|
}
|
|
294
243
|
]);
|
|
295
244
|
return await parseFetchedUpdates(result, 'updates');
|
|
296
245
|
}
|
|
297
246
|
};
|
|
298
247
|
};
|
|
299
|
-
|
|
300
|
-
const extractNewsletterMetadata = (node, isCreate) => {
|
|
301
|
-
const result =
|
|
302
|
-
const metadataPath = JSON.parse(result).data[isCreate ?
|
|
303
|
-
|
|
248
|
+
|
|
249
|
+
export const extractNewsletterMetadata = (node, isCreate) => {
|
|
250
|
+
const result = getBinaryNodeChild(node, 'result')?.content?.toString();
|
|
251
|
+
const metadataPath = JSON.parse(result).data[isCreate ? XWAPaths.CREATE : XWAPaths.NEWSLETTER];
|
|
304
252
|
const metadata = {
|
|
305
|
-
id: metadataPath
|
|
306
|
-
state: metadataPath
|
|
307
|
-
creation_time: +metadataPath
|
|
308
|
-
name: metadataPath
|
|
309
|
-
nameTime: +metadataPath
|
|
310
|
-
description: metadataPath
|
|
311
|
-
descriptionTime: +metadataPath
|
|
312
|
-
invite: metadataPath
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
253
|
+
id: metadataPath.id,
|
|
254
|
+
state: metadataPath.state.type,
|
|
255
|
+
creation_time: +metadataPath.thread_metadata.creation_time,
|
|
256
|
+
name: metadataPath.thread_metadata.name.text,
|
|
257
|
+
nameTime: +metadataPath.thread_metadata.name.update_time,
|
|
258
|
+
description: metadataPath.thread_metadata.description.text,
|
|
259
|
+
descriptionTime: +metadataPath.thread_metadata.description.update_time,
|
|
260
|
+
invite: metadataPath.thread_metadata.invite,
|
|
261
|
+
handle: metadataPath.thread_metadata.handle,
|
|
262
|
+
picture: metadataPath.thread_metadata.picture?.direct_path || null,
|
|
263
|
+
preview: metadataPath.thread_metadata.preview?.direct_path || null,
|
|
264
|
+
reaction_codes: metadataPath.thread_metadata.settings.reaction_codes.value,
|
|
265
|
+
subscribers: +metadataPath.thread_metadata.subscribers_count,
|
|
266
|
+
verification: metadataPath.thread_metadata.verification,
|
|
267
|
+
viewer_metadata: metadataPath.viewer_metadata
|
|
268
|
+
};
|
|
269
|
+
return metadata;
|
|
270
|
+
};
|