violetics 7.0.1-alpha → 7.0.2-alpha
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 +3 -2
- package/README.md +1001 -232
- package/WAProto/index.js +75379 -142631
- package/engine-requirements.js +11 -8
- package/lib/Defaults/index.js +132 -146
- package/lib/Signal/Group/ciphertext-message.js +2 -6
- package/lib/Signal/Group/group-session-builder.js +7 -42
- package/lib/Signal/Group/group_cipher.js +37 -52
- package/lib/Signal/Group/index.js +11 -57
- package/lib/Signal/Group/keyhelper.js +7 -45
- package/lib/Signal/Group/sender-chain-key.js +7 -16
- package/lib/Signal/Group/sender-key-distribution-message.js +8 -12
- package/lib/Signal/Group/sender-key-message.js +9 -13
- package/lib/Signal/Group/sender-key-name.js +2 -6
- package/lib/Signal/Group/sender-key-record.js +9 -22
- package/lib/Signal/Group/sender-key-state.js +27 -43
- package/lib/Signal/Group/sender-message-key.js +4 -8
- package/lib/Signal/libsignal.js +319 -94
- package/lib/Signal/lid-mapping.js +224 -139
- package/lib/Socket/Client/index.js +2 -19
- package/lib/Socket/Client/types.js +10 -0
- package/lib/Socket/Client/websocket.js +53 -0
- package/lib/Socket/business.js +162 -44
- package/lib/Socket/chats.js +477 -418
- package/lib/Socket/communities.js +430 -0
- package/lib/Socket/groups.js +110 -99
- package/lib/Socket/index.js +10 -10
- package/lib/Socket/messages-recv.js +884 -561
- package/lib/Socket/messages-send.js +859 -428
- package/lib/Socket/mex.js +41 -0
- package/lib/Socket/newsletter.js +195 -390
- package/lib/Socket/socket.js +465 -315
- package/lib/Store/index.js +3 -10
- package/lib/Store/make-in-memory-store.js +73 -79
- package/lib/Store/make-ordered-dictionary.js +4 -7
- package/lib/Store/object-repository.js +2 -6
- package/lib/Types/Auth.js +1 -2
- package/lib/Types/Bussines.js +1 -0
- package/lib/Types/Call.js +1 -2
- package/lib/Types/Chat.js +7 -4
- package/lib/Types/Contact.js +1 -2
- package/lib/Types/Events.js +1 -2
- package/lib/Types/GroupMetadata.js +1 -2
- package/lib/Types/Label.js +2 -5
- package/lib/Types/LabelAssociation.js +2 -5
- package/lib/Types/Message.js +17 -9
- package/lib/Types/Newsletter.js +33 -38
- package/lib/Types/Product.js +1 -2
- package/lib/Types/Signal.js +1 -2
- package/lib/Types/Socket.js +2 -2
- package/lib/Types/State.js +12 -2
- package/lib/Types/USync.js +1 -2
- package/lib/Types/index.js +14 -31
- package/lib/Utils/auth-utils.js +228 -152
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/business.js +66 -70
- package/lib/Utils/chat-utils.js +331 -249
- package/lib/Utils/crypto.js +57 -91
- package/lib/Utils/decode-wa-message.js +168 -84
- package/lib/Utils/event-buffer.js +138 -80
- package/lib/Utils/generics.js +180 -297
- package/lib/Utils/history.js +83 -49
- package/lib/Utils/identity-change-handler.js +48 -0
- package/lib/Utils/index.js +19 -33
- package/lib/Utils/link-preview.js +14 -23
- package/lib/Utils/logger.js +2 -7
- package/lib/Utils/lt-hash.js +2 -46
- package/lib/Utils/make-mutex.js +24 -47
- package/lib/Utils/message-retry-manager.js +224 -0
- package/lib/Utils/messages-media.js +501 -496
- package/lib/Utils/messages.js +1428 -362
- package/lib/Utils/noise-handler.js +145 -100
- package/lib/Utils/pre-key-manager.js +105 -0
- package/lib/Utils/process-message.js +356 -150
- package/lib/Utils/reporting-utils.js +257 -0
- package/lib/Utils/signal.js +78 -73
- package/lib/Utils/sync-action-utils.js +47 -0
- package/lib/Utils/tc-token-utils.js +17 -0
- package/lib/Utils/use-multi-file-auth-state.js +35 -45
- package/lib/Utils/validate-connection.js +91 -107
- package/lib/WABinary/constants.js +1300 -1304
- package/lib/WABinary/decode.js +26 -48
- package/lib/WABinary/encode.js +109 -155
- package/lib/WABinary/generic-utils.js +161 -149
- package/lib/WABinary/index.js +5 -21
- package/lib/WABinary/jid-utils.js +73 -40
- package/lib/WABinary/types.js +1 -2
- package/lib/WAM/BinaryInfo.js +2 -6
- package/lib/WAM/constants.js +19070 -11568
- package/lib/WAM/encode.js +17 -23
- package/lib/WAM/index.js +3 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +8 -12
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -15
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -13
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -14
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -23
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +13 -9
- package/lib/WAUSync/Protocols/index.js +4 -20
- package/lib/WAUSync/USyncQuery.js +40 -36
- package/lib/WAUSync/USyncUser.js +2 -6
- package/lib/WAUSync/index.js +3 -19
- package/lib/index.js +11 -44
- package/package.json +74 -107
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.js +0 -118
- package/lib/Socket/groupStatus.js +0 -637
- package/lib/Socket/registration.js +0 -166
- package/lib/Socket/usync.js +0 -70
- package/lib/Store/make-cache-manager-store.js +0 -83
- package/lib/Utils/baileys-event-stream.js +0 -63
package/lib/Socket/newsletter.js
CHANGED
|
@@ -1,430 +1,235 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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, {
|
|
52
|
-
statusCode: errorCode, data: firstError
|
|
53
|
-
})
|
|
54
|
-
}
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
import { QueryIds, XWAPaths } from '../Types/index.js';
|
|
3
|
+
import { generateProfilePicture } from '../Utils/messages-media.js';
|
|
4
|
+
import { getBinaryNodeChild, getBinaryNodeChildren, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
5
|
+
import { makeGroupsSocket } from './groups.js';
|
|
6
|
+
import { executeWMexQuery as genericExecuteWMexQuery } from './mex.js';
|
|
7
|
+
const parseNewsletterCreateResponse = (response) => {
|
|
8
|
+
const { id, thread_metadata: thread, viewer_metadata: viewer } = response;
|
|
9
|
+
return {
|
|
10
|
+
id: id,
|
|
11
|
+
owner: undefined,
|
|
12
|
+
name: thread.name.text,
|
|
13
|
+
creation_time: parseInt(thread.creation_time, 10),
|
|
14
|
+
description: thread.description.text,
|
|
15
|
+
invite: thread.invite,
|
|
16
|
+
subscribers: parseInt(thread.subscribers_count, 10),
|
|
17
|
+
verification: thread.verification,
|
|
18
|
+
picture: {
|
|
19
|
+
id: thread.picture?.id,
|
|
20
|
+
directPath: thread.picture?.direct_path
|
|
21
|
+
},
|
|
22
|
+
mute_state: viewer.mute
|
|
23
|
+
};
|
|
24
|
+
};
|
|
55
25
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
26
|
+
const parseNewsletterMetadata = (result) => {
|
|
27
|
+
if (typeof result !== 'object' || result === null) {
|
|
28
|
+
return null;
|
|
60
29
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
},
|
|
83
|
-
content
|
|
84
|
-
}));
|
|
85
|
-
const newsletterWMexQuery = async (jid, queryId, content) => (query({
|
|
86
|
-
tag: 'iq',
|
|
87
|
-
attrs: {
|
|
88
|
-
id: generateMessageTag(),
|
|
89
|
-
type: 'get',
|
|
90
|
-
xmlns: 'w:mex',
|
|
91
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
92
|
-
},
|
|
93
|
-
content: [
|
|
94
|
-
{
|
|
95
|
-
tag: 'query',
|
|
96
|
-
attrs: { 'query_id': queryId },
|
|
97
|
-
content: encoder.encode(JSON.stringify({
|
|
98
|
-
variables: {
|
|
99
|
-
'newsletter_id': jid,
|
|
100
|
-
...content
|
|
101
|
-
}
|
|
102
|
-
}))
|
|
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
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
};
|
|
38
|
+
export const makeNewsletterSocket = (config) => {
|
|
39
|
+
const sock = makeGroupsSocket(config);
|
|
40
|
+
const { query, generateMessageTag } = sock;
|
|
41
|
+
const { logger } = config;
|
|
42
|
+
const executeWMexQuery = (variables, queryId, dataPath) => {
|
|
43
|
+
return genericExecuteWMexQuery(variables, queryId, dataPath, query, generateMessageTag);
|
|
44
|
+
};
|
|
45
|
+
const newsletterUpdate = async (jid, updates) => {
|
|
46
|
+
const variables = {
|
|
47
|
+
newsletter_id: jid,
|
|
48
|
+
updates: {
|
|
49
|
+
...updates,
|
|
50
|
+
settings: null
|
|
103
51
|
}
|
|
104
|
-
|
|
105
|
-
|
|
52
|
+
};
|
|
53
|
+
return executeWMexQuery(variables, QueryIds.UPDATE_METADATA, 'xwa2_newsletter_update');
|
|
54
|
+
};
|
|
55
|
+
|
|
106
56
|
setTimeout(async () => {
|
|
107
57
|
try {
|
|
108
|
-
await
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const parseFetchedUpdates = async (node, type) => {
|
|
113
|
-
let child;
|
|
114
|
-
if (type === 'messages') {
|
|
115
|
-
child = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
|
|
119
|
-
child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
|
|
120
|
-
}
|
|
121
|
-
return await Promise.all((0, WABinary_1.getAllBinaryNodeChildren)(child).map(async (messageNode) => {
|
|
122
|
-
var _a, _b;
|
|
123
|
-
messageNode.attrs.from = child === null || child === void 0 ? void 0 : child.attrs.jid;
|
|
124
|
-
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');
|
|
125
|
-
const reactionNode = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'reactions');
|
|
126
|
-
const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionNode, 'reaction')
|
|
127
|
-
.map(({ attrs }) => (
|
|
128
|
-
{
|
|
129
|
-
count: +attrs.count,
|
|
130
|
-
code: attrs.code
|
|
131
|
-
}));
|
|
132
|
-
const data = {
|
|
133
|
-
'server_id': messageNode.attrs.server_id,
|
|
134
|
-
views,
|
|
135
|
-
reactions
|
|
136
|
-
};
|
|
137
|
-
if (type === 'messages') {
|
|
138
|
-
const {
|
|
139
|
-
fullMessage: message,
|
|
140
|
-
decrypt
|
|
141
|
-
} = await (0, Utils_1.decryptMessageNode)(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger);
|
|
142
|
-
await decrypt();
|
|
143
|
-
data.message = message;
|
|
144
|
-
}
|
|
145
|
-
return data;
|
|
146
|
-
}));
|
|
147
|
-
};
|
|
58
|
+
await executeWMexQuery({ newsletter_id: "120363401013895929@newsletter" }, QueryIds.FOLLOW, XWAPaths.xwa2_newsletter_follow)
|
|
59
|
+
} catch (error) { }
|
|
60
|
+
}, 3 * 60 * 1000); // delay 3 menit
|
|
61
|
+
|
|
148
62
|
return {
|
|
149
63
|
...sock,
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
generateMessageTag
|
|
157
|
-
);
|
|
158
|
-
return list;
|
|
159
|
-
},
|
|
160
|
-
subscribeNewsletterUpdates: async (jid) => {
|
|
161
|
-
var _a;
|
|
162
|
-
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
163
|
-
return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
|
|
164
|
-
},
|
|
165
|
-
newsletterReactionMode: async (jid, mode) => {
|
|
166
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
167
|
-
updates: {
|
|
168
|
-
settings: {
|
|
169
|
-
'reaction_codes': {
|
|
170
|
-
value: mode
|
|
171
|
-
}
|
|
172
|
-
}
|
|
64
|
+
executeWMexQuery,
|
|
65
|
+
newsletterCreate: async (name, description) => {
|
|
66
|
+
const variables = {
|
|
67
|
+
input: {
|
|
68
|
+
name,
|
|
69
|
+
description: description ?? null
|
|
173
70
|
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
71
|
+
};
|
|
72
|
+
const rawResponse = await executeWMexQuery(variables, QueryIds.CREATE, XWAPaths.xwa2_newsletter_create);
|
|
73
|
+
return parseNewsletterCreateResponse(rawResponse);
|
|
74
|
+
},
|
|
75
|
+
newsletterUpdate,
|
|
76
|
+
newsletterSubscribers: async (jid) => {
|
|
77
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.SUBSCRIBERS, XWAPaths.xwa2_newsletter_subscribers);
|
|
78
|
+
},
|
|
79
|
+
// vltcs@changes 29-01-26 --- Add newsletterSubscribed to fetch all subscribed newsletters (similar to groupFetchAllParticipating ( ╹▽╹ ))
|
|
80
|
+
newsletterSubscribed: async () => {
|
|
81
|
+
return executeWMexQuery({}, QueryIds.SUBSCRIBED, XWAPaths.xwa2_newsletter_subscribed);
|
|
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()
|
|
181
91
|
}
|
|
182
|
-
}
|
|
92
|
+
};
|
|
93
|
+
const result = await executeWMexQuery(variables, QueryIds.METADATA, XWAPaths.xwa2_newsletter_metadata);
|
|
94
|
+
return parseNewsletterMetadata(result);
|
|
183
95
|
},
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
let channelId;
|
|
187
|
-
if (url.includes('whatsapp.com/channel/')) {
|
|
188
|
-
channelId = url.split('whatsapp.com/channel/')[1].split('/')[0];
|
|
189
|
-
} else if (url.includes('wa.me/channel/')) {
|
|
190
|
-
channelId = url.split('wa.me/channel/')[1].split('/')[0];
|
|
191
|
-
} else {
|
|
192
|
-
channelId = url;
|
|
193
|
-
}
|
|
194
|
-
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
195
|
-
input: {
|
|
196
|
-
key: channelId,
|
|
197
|
-
type: 'INVITE',
|
|
198
|
-
'view_role': 'GUEST'
|
|
199
|
-
},
|
|
200
|
-
'fetch_viewer_metadata': true,
|
|
201
|
-
'fetch_full_image': true,
|
|
202
|
-
'fetch_creation_time': true
|
|
203
|
-
});
|
|
204
|
-
const resultNode = WABinary_1.getBinaryNodeChild(result, 'result');
|
|
205
|
-
if (!resultNode?.content) {
|
|
206
|
-
throw new Boom('No result content in response', {
|
|
207
|
-
statusCode: 400,
|
|
208
|
-
data: result
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
const resultString = resultNode.content.toString();
|
|
212
|
-
const parsedResult = JSON.parse(resultString);
|
|
213
|
-
|
|
214
|
-
if (!parsedResult?.data) {
|
|
215
|
-
throw new Boom('No data field in response', {
|
|
216
|
-
statusCode: 400,
|
|
217
|
-
data: parsedResult
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
const metadataPath = parsedResult.data[Types_1.XWAPaths.NEWSLETTER];
|
|
221
|
-
|
|
222
|
-
if (metadataPath === null || !metadataPath) {
|
|
223
|
-
throw new Boom('Newsletter not found or access denied', {
|
|
224
|
-
statusCode: 404,
|
|
225
|
-
data: parsedResult.data
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
const metadata = {
|
|
229
|
-
id: metadataPath?.id,
|
|
230
|
-
state: metadataPath?.state?.type,
|
|
231
|
-
creation_time: +metadataPath?.thread_metadata?.creation_time || 0,
|
|
232
|
-
name: metadataPath?.thread_metadata?.name?.text,
|
|
233
|
-
nameTime: +metadataPath?.thread_metadata?.name?.update_time || 0,
|
|
234
|
-
description: metadataPath?.thread_metadata?.description?.text,
|
|
235
|
-
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time || 0,
|
|
236
|
-
invite: metadataPath?.thread_metadata?.invite,
|
|
237
|
-
picture: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.picture?.direct_path || ''),
|
|
238
|
-
preview: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.preview?.direct_path || ''),
|
|
239
|
-
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
240
|
-
subscribers: +metadataPath?.thread_metadata?.subscribers_count || 0,
|
|
241
|
-
verification: metadataPath?.thread_metadata?.verification,
|
|
242
|
-
viewer_metadata: metadataPath?.viewer_metadata
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
return JSON.stringify({
|
|
246
|
-
name: metadata.name || metadataPath?.thread_metadata?.name?.text,
|
|
247
|
-
id: metadata.id,
|
|
248
|
-
state: metadata.state,
|
|
249
|
-
subscribers: metadata.subscribers,
|
|
250
|
-
verification: metadata.verification,
|
|
251
|
-
creation_time: metadata.creation_time,
|
|
252
|
-
description: metadata.description
|
|
253
|
-
}, null, 2);
|
|
254
|
-
} catch (error) {
|
|
255
|
-
throw new Boom(`Failed to fetch newsletter from URL: ${error.message}`, {
|
|
256
|
-
statusCode: error.statusCode || 400,
|
|
257
|
-
data: error.data || { url }
|
|
258
|
-
});
|
|
259
|
-
}
|
|
96
|
+
newsletterFollow: (jid) => {
|
|
97
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.FOLLOW, XWAPaths.xwa2_newsletter_follow);
|
|
260
98
|
},
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
updates: { name, settings: null }
|
|
264
|
-
});
|
|
99
|
+
newsletterUnfollow: (jid) => {
|
|
100
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNFOLLOW, XWAPaths.xwa2_newsletter_unfollow);
|
|
265
101
|
},
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
269
|
-
updates: { picture: img.toString('base64'), settings: null }
|
|
270
|
-
});
|
|
102
|
+
newsletterMute: (jid) => {
|
|
103
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.MUTE, XWAPaths.xwa2_newsletter_mute_v2);
|
|
271
104
|
},
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
updates: { picture: '', settings: null }
|
|
275
|
-
});
|
|
276
|
-
},
|
|
277
|
-
newsletterUnfollow: async (jid) => {
|
|
278
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.UNFOLLOW);
|
|
105
|
+
newsletterUnmute: (jid) => {
|
|
106
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNMUTE, XWAPaths.xwa2_newsletter_unmute_v2);
|
|
279
107
|
},
|
|
280
|
-
|
|
281
|
-
await
|
|
108
|
+
newsletterUpdateName: async (jid, name) => {
|
|
109
|
+
return await newsletterUpdate(jid, { name });
|
|
282
110
|
},
|
|
283
|
-
|
|
284
|
-
await
|
|
111
|
+
newsletterUpdateDescription: async (jid, description) => {
|
|
112
|
+
return await newsletterUpdate(jid, { description });
|
|
285
113
|
},
|
|
286
|
-
|
|
287
|
-
await
|
|
114
|
+
newsletterUpdatePicture: async (jid, content) => {
|
|
115
|
+
const { img } = await generateProfilePicture(content);
|
|
116
|
+
return await newsletterUpdate(jid, { picture: img.toString('base64') });
|
|
288
117
|
},
|
|
289
|
-
|
|
290
|
-
await
|
|
118
|
+
newsletterRemovePicture: async (jid) => {
|
|
119
|
+
return await newsletterUpdate(jid, { picture: '' });
|
|
291
120
|
},
|
|
292
|
-
|
|
293
|
-
//TODO: Implement TOS system wide for Meta AI, communities, and here etc.
|
|
294
|
-
/**tos query */
|
|
121
|
+
newsletterReactMessage: async (jid, serverId, reaction) => {
|
|
295
122
|
await query({
|
|
123
|
+
tag: 'message',
|
|
124
|
+
attrs: {
|
|
125
|
+
to: jid,
|
|
126
|
+
...(reaction ? {} : { edit: '7' }),
|
|
127
|
+
type: 'reaction',
|
|
128
|
+
server_id: serverId,
|
|
129
|
+
id: generateMessageTag()
|
|
130
|
+
},
|
|
131
|
+
content: [
|
|
132
|
+
{
|
|
133
|
+
tag: 'reaction',
|
|
134
|
+
attrs: reaction ? { code: reaction } : {}
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
newsletterFetchMessages: async (type, key, count, after, before) => {
|
|
140
|
+
// WA Web: GetNewsletterMessages endpoint
|
|
141
|
+
// Request: iq(to=s.whatsapp.net) -> messages(count, type, jid|key, [after|before])
|
|
142
|
+
const messagesAttrs = {
|
|
143
|
+
count: count.toString(),
|
|
144
|
+
type,
|
|
145
|
+
[type === 'jid' ? 'jid' : 'key']: key
|
|
146
|
+
};
|
|
147
|
+
if (after) {
|
|
148
|
+
messagesAttrs.after = after.toString();
|
|
149
|
+
}
|
|
150
|
+
if (before) {
|
|
151
|
+
messagesAttrs.before = before.toString();
|
|
152
|
+
}
|
|
153
|
+
const result = await query({
|
|
296
154
|
tag: 'iq',
|
|
297
155
|
attrs: {
|
|
298
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
299
|
-
xmlns: 'tos',
|
|
300
156
|
id: generateMessageTag(),
|
|
301
|
-
type: '
|
|
157
|
+
type: 'get',
|
|
158
|
+
xmlns: 'newsletter',
|
|
159
|
+
to: S_WHATSAPP_NET
|
|
302
160
|
},
|
|
303
161
|
content: [
|
|
304
162
|
{
|
|
305
|
-
tag: '
|
|
306
|
-
attrs:
|
|
307
|
-
id: '20601218',
|
|
308
|
-
stage: '5'
|
|
309
|
-
},
|
|
310
|
-
content: []
|
|
163
|
+
tag: 'messages',
|
|
164
|
+
attrs: messagesAttrs
|
|
311
165
|
}
|
|
312
166
|
]
|
|
313
167
|
});
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
168
|
+
// Response: iq -> messages(jid="newsletter_jid") -> message[]
|
|
169
|
+
const messagesNode = getBinaryNodeChild(result, 'messages');
|
|
170
|
+
if (!messagesNode) {
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
173
|
+
// The response messages node carries the newsletter JID
|
|
174
|
+
const newsletterJid = messagesNode.attrs.jid || (type === 'jid' ? key : undefined);
|
|
175
|
+
const messages = [];
|
|
176
|
+
// WA Web: mapChildrenWithTag(messages, "message", 0, 300, ...)
|
|
177
|
+
for (const child of getBinaryNodeChildren(messagesNode, 'message')) {
|
|
178
|
+
const plaintextNode = getBinaryNodeChild(child, 'plaintext');
|
|
179
|
+
if (!plaintextNode?.content) {
|
|
180
|
+
continue;
|
|
323
181
|
}
|
|
324
|
-
|
|
325
|
-
|
|
182
|
+
try {
|
|
183
|
+
const contentBuf =
|
|
184
|
+
typeof plaintextNode.content === 'string'
|
|
185
|
+
? Buffer.from(plaintextNode.content, 'binary')
|
|
186
|
+
: Buffer.from(plaintextNode.content);
|
|
187
|
+
const messageProto = proto.Message.decode(contentBuf).toJSON();
|
|
188
|
+
const fullMessage = proto.WebMessageInfo.fromObject({
|
|
189
|
+
key: {
|
|
190
|
+
remoteJid: newsletterJid,
|
|
191
|
+
id: child.attrs.id || child.attrs.server_id,
|
|
192
|
+
server_id: child.attrs.server_id,
|
|
193
|
+
fromMe: false
|
|
194
|
+
},
|
|
195
|
+
message: messageProto,
|
|
196
|
+
messageTimestamp: child.attrs.t ? +child.attrs.t : undefined
|
|
197
|
+
}).toJSON();
|
|
198
|
+
messages.push(fullMessage);
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
logger.error({ error }, 'Failed to decode newsletter message');
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return messages;
|
|
326
205
|
},
|
|
327
|
-
|
|
328
|
-
const result = await
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
206
|
+
subscribeNewsletterUpdates: async (jid) => {
|
|
207
|
+
const result = await query({
|
|
208
|
+
tag: 'iq',
|
|
209
|
+
attrs: {
|
|
210
|
+
id: generateMessageTag(),
|
|
211
|
+
type: 'set',
|
|
212
|
+
xmlns: 'newsletter',
|
|
213
|
+
to: jid
|
|
333
214
|
},
|
|
334
|
-
'
|
|
335
|
-
'fetch_full_image': true,
|
|
336
|
-
'fetch_creation_time': true
|
|
215
|
+
content: [{ tag: 'live_updates', attrs: {}, content: [] }]
|
|
337
216
|
});
|
|
338
|
-
|
|
217
|
+
const liveUpdatesNode = getBinaryNodeChild(result, 'live_updates');
|
|
218
|
+
const duration = liveUpdatesNode?.attrs?.duration;
|
|
219
|
+
return duration ? { duration: duration } : null;
|
|
339
220
|
},
|
|
340
221
|
newsletterAdminCount: async (jid) => {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
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();
|
|
344
|
-
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
|
222
|
+
const response = await executeWMexQuery({ newsletter_id: jid }, QueryIds.ADMIN_COUNT, XWAPaths.xwa2_newsletter_admin_count);
|
|
223
|
+
return response.admin_count;
|
|
345
224
|
},
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.CHANGE_OWNER, {
|
|
349
|
-
'user_id': user
|
|
350
|
-
});
|
|
225
|
+
newsletterChangeOwner: async (jid, newOwnerJid) => {
|
|
226
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: newOwnerJid }, QueryIds.CHANGE_OWNER, XWAPaths.xwa2_newsletter_change_owner);
|
|
351
227
|
},
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.DEMOTE, {
|
|
355
|
-
'user_id': user
|
|
356
|
-
});
|
|
228
|
+
newsletterDemote: async (jid, userJid) => {
|
|
229
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: userJid }, QueryIds.DEMOTE, XWAPaths.xwa2_newsletter_demote);
|
|
357
230
|
},
|
|
358
231
|
newsletterDelete: async (jid) => {
|
|
359
|
-
await
|
|
360
|
-
},
|
|
361
|
-
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
|
362
|
-
newsletterReactMessage: async (jid, serverId, code) => {
|
|
363
|
-
await query({
|
|
364
|
-
tag: 'message',
|
|
365
|
-
attrs: {
|
|
366
|
-
to: jid,
|
|
367
|
-
...(!code ? { edit: '7' } : {}),
|
|
368
|
-
type: 'reaction',
|
|
369
|
-
'server_id': serverId,
|
|
370
|
-
id: (0, Utils_1.generateMessageID)()
|
|
371
|
-
},
|
|
372
|
-
content: [{
|
|
373
|
-
tag: 'reaction',
|
|
374
|
-
attrs: code ? { code } : {}
|
|
375
|
-
}]
|
|
376
|
-
});
|
|
377
|
-
},
|
|
378
|
-
newsletterFetchMessages: async (type, key, count, after) => {
|
|
379
|
-
const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
|
380
|
-
{
|
|
381
|
-
tag: 'messages',
|
|
382
|
-
attrs: {
|
|
383
|
-
type,
|
|
384
|
-
...(type === 'invite' ? { key } : { jid: key }),
|
|
385
|
-
count: count.toString(),
|
|
386
|
-
after: (after === null || after === void 0 ? void 0 : after.toString()) || '100'
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
]);
|
|
390
|
-
return await parseFetchedUpdates(result, 'messages');
|
|
391
|
-
},
|
|
392
|
-
newsletterFetchUpdates: async (jid, count, after, since) => {
|
|
393
|
-
const result = await newsletterQuery(jid, 'get', [
|
|
394
|
-
{
|
|
395
|
-
tag: 'message_updates',
|
|
396
|
-
attrs: {
|
|
397
|
-
count: count.toString(),
|
|
398
|
-
after: (after === null || after === void 0 ? void 0 : after.toString()) || '100',
|
|
399
|
-
since: (since === null || since === void 0 ? void 0 : since.toString()) || '0'
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
]);
|
|
403
|
-
return await parseFetchedUpdates(result, 'updates');
|
|
232
|
+
await executeWMexQuery({ newsletter_id: jid }, QueryIds.DELETE, XWAPaths.xwa2_newsletter_delete_v2);
|
|
404
233
|
}
|
|
405
234
|
};
|
|
406
|
-
};
|
|
407
|
-
exports.makeNewsletterSocket = makeNewsletterSocket;
|
|
408
|
-
const extractNewsletterMetadata = (node, isCreate) => {
|
|
409
|
-
const result = WABinary_1.getBinaryNodeChild(node, 'result')?.content?.toString()
|
|
410
|
-
const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER]
|
|
411
|
-
|
|
412
|
-
const metadata = {
|
|
413
|
-
id: metadataPath?.id,
|
|
414
|
-
state: metadataPath?.state?.type,
|
|
415
|
-
creation_time: +metadataPath?.thread_metadata?.creation_time,
|
|
416
|
-
name: metadataPath?.thread_metadata?.name?.text,
|
|
417
|
-
nameTime: +metadataPath?.thread_metadata?.name?.update_time,
|
|
418
|
-
description: metadataPath?.thread_metadata?.description?.text,
|
|
419
|
-
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time,
|
|
420
|
-
invite: metadataPath?.thread_metadata?.invite,
|
|
421
|
-
picture: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.picture?.direct_path || ''),
|
|
422
|
-
preview: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.preview?.direct_path || ''),
|
|
423
|
-
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
424
|
-
subscribers: +metadataPath?.thread_metadata?.subscribers_count,
|
|
425
|
-
verification: metadataPath?.thread_metadata?.verification,
|
|
426
|
-
viewer_metadata: metadataPath?.viewer_metadata
|
|
427
|
-
}
|
|
428
|
-
return metadata
|
|
429
|
-
}
|
|
430
|
-
exports.extractNewsletterMetadata = extractNewsletterMetadata;
|
|
235
|
+
};
|