@alannxd/baileys 2.1.4 → 3.0.0
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 +9 -4
- package/WAProto/index.js +56886 -17506
- package/lib/Defaults/index.js +3 -2
- package/lib/Socket/chats.js +85 -48
- package/lib/Socket/dugong.d.ts +41 -6
- package/lib/Socket/dugong.js +380 -337
- package/lib/Socket/messages-send.js +3 -4
- package/lib/Socket/newsletter.js +114 -21
- package/lib/Socket/socket.js +66 -31
- package/lib/Types/Newsletter.d.ts +97 -86
- package/lib/Types/Newsletter.js +38 -32
- package/lib/Utils/generics.js +10 -8
- package/lib/Utils/messages-media.js +145 -57
- package/lib/Utils/messages.js +26 -14
- package/lib/Utils/use-multi-file-auth-state.js +45 -6
- package/lib/Utils/validate-connection.js +89 -65
- package/lib/index.js +1 -0
- package/package.json +3 -2
package/lib/Defaults/index.js
CHANGED
|
@@ -31,10 +31,11 @@ const WAProto_1 = require("../../WAProto"),
|
|
|
31
31
|
libsignal_1 = require("../Signal/libsignal"),
|
|
32
32
|
Utils_1 = require("../Utils"),
|
|
33
33
|
logger_1 = __importDefault(require("../Utils/logger")),
|
|
34
|
-
baileys_version_json_1 = require("./baileys-version.json")
|
|
34
|
+
baileys_version_json_1 = require("./baileys-version.json"),
|
|
35
35
|
phonenumber_mcc_json_1 = __importDefault(require("./phonenumber-mcc.json"));
|
|
36
36
|
|
|
37
37
|
exports.UNAUTHORIZED_CODES = [401, 403, 419];
|
|
38
|
+
exports.version = [2, 3000, 1027934701];
|
|
38
39
|
exports.PHONENUMBER_MCC = phonenumber_mcc_json_1.default;
|
|
39
40
|
exports.DEFAULT_ORIGIN = "https://web.whatsapp.com";
|
|
40
41
|
exports.MOBILE_ENDPOINT = 'g.whatsapp.net';
|
|
@@ -72,7 +73,7 @@ exports.PROCESSABLE_HISTORY_TYPES = [
|
|
|
72
73
|
|
|
73
74
|
exports.DEFAULT_CONNECTION_CONFIG = {
|
|
74
75
|
version: baileys_version_json_1.version,
|
|
75
|
-
browser: Utils_1.Browsers
|
|
76
|
+
browser: Utils_1.Browsers("Chrome"),
|
|
76
77
|
waWebSocketUrl: "wss://web.whatsapp.com/ws/chat",
|
|
77
78
|
connectTimeoutMs: 2E4,
|
|
78
79
|
keepAliveIntervalMs: 3E4,
|
package/lib/Socket/chats.js
CHANGED
|
@@ -209,17 +209,99 @@ const makeChatsSocket = (config) => {
|
|
|
209
209
|
const users = (0, WABinary_1.getBinaryNodeChildren)(listNode, 'user');
|
|
210
210
|
return users;
|
|
211
211
|
};
|
|
212
|
+
const getBusinessProfile = async (jid) => {
|
|
213
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
214
|
+
const results = await query({
|
|
215
|
+
tag: 'iq',
|
|
216
|
+
attrs: {
|
|
217
|
+
to: 's.whatsapp.net',
|
|
218
|
+
xmlns: 'w:biz',
|
|
219
|
+
type: 'get'
|
|
220
|
+
},
|
|
221
|
+
content: [{
|
|
222
|
+
tag: 'business_profile',
|
|
223
|
+
attrs: { v: '244' },
|
|
224
|
+
content: [{
|
|
225
|
+
tag: 'profile',
|
|
226
|
+
attrs: { jid }
|
|
227
|
+
}]
|
|
228
|
+
}]
|
|
229
|
+
});
|
|
230
|
+
const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
|
|
231
|
+
const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
|
|
232
|
+
if (profiles) {
|
|
233
|
+
const address = (0, WABinary_1.getBinaryNodeChild)(profiles, 'address');
|
|
234
|
+
const description = (0, WABinary_1.getBinaryNodeChild)(profiles, 'description');
|
|
235
|
+
const website = (0, WABinary_1.getBinaryNodeChild)(profiles, 'website');
|
|
236
|
+
const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
|
|
237
|
+
const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
|
|
238
|
+
const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
|
|
239
|
+
const businessHoursConfig = businessHours ?
|
|
240
|
+
(0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config') :
|
|
241
|
+
undefined;
|
|
242
|
+
const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
|
|
243
|
+
return {
|
|
244
|
+
wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
|
|
245
|
+
address: (_c = address === null || address === void 0 ? void 0 : address.content) === null || _c === void 0 ? void 0 : _c.toString(),
|
|
246
|
+
description: ((_d = description === null || description === void 0 ? void 0 : description.content) === null || _d === void 0 ? void 0 : _d.toString()) || '',
|
|
247
|
+
website: websiteStr ? [websiteStr] : [],
|
|
248
|
+
email: (_e = email === null || email === void 0 ? void 0 : email.content) === null || _e === void 0 ? void 0 : _e.toString(),
|
|
249
|
+
category: (_f = category === null || category === void 0 ? void 0 : category.content) === null || _f === void 0 ? void 0 : _f.toString(),
|
|
250
|
+
'business_hours': {
|
|
251
|
+
timezone: (_g = businessHours === null || businessHours === void 0 ? void 0 : businessHours.attrs) === null || _g === void 0 ? void 0 : _g.timezone,
|
|
252
|
+
'business_config': businessHoursConfig === null || businessHoursConfig === void 0 ? void 0 : businessHoursConfig.map(({ attrs }) => attrs)
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
};
|
|
212
257
|
const onWhatsApp = async (...jids) => {
|
|
213
258
|
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
214
|
-
|
|
215
|
-
|
|
259
|
+
.withContactProtocol()
|
|
260
|
+
.withLIDProtocol();
|
|
261
|
+
|
|
216
262
|
for (const jid of jids) {
|
|
217
263
|
const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
|
|
218
264
|
usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
|
|
219
265
|
}
|
|
266
|
+
|
|
220
267
|
const results = await sock.executeUSyncQuery(usyncQuery);
|
|
221
268
|
if (results) {
|
|
222
|
-
|
|
269
|
+
const verifiedResults = await Promise.all(
|
|
270
|
+
results.list
|
|
271
|
+
.filter((a) => !!a.contact)
|
|
272
|
+
.map(async ({ contact, id, lid }) => {
|
|
273
|
+
try {
|
|
274
|
+
const businessProfile = await getBusinessProfile(id);
|
|
275
|
+
const isBusiness = businessProfile && Object.keys(businessProfile).length > 0;
|
|
276
|
+
if (isBusiness) {
|
|
277
|
+
const { wid, ...businessInfo } = businessProfile;
|
|
278
|
+
|
|
279
|
+
return {
|
|
280
|
+
jid: id,
|
|
281
|
+
exists: true,
|
|
282
|
+
lid: lid,
|
|
283
|
+
status: 'business',
|
|
284
|
+
businessInfo: businessInfo
|
|
285
|
+
};
|
|
286
|
+
} else {
|
|
287
|
+
return {
|
|
288
|
+
jid: id,
|
|
289
|
+
exists: true,
|
|
290
|
+
lid: lid,
|
|
291
|
+
status: 'regular'
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
} catch (error) {
|
|
295
|
+
return {
|
|
296
|
+
jid: id,
|
|
297
|
+
exists: true,
|
|
298
|
+
lid: lid,
|
|
299
|
+
status: error
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
})
|
|
303
|
+
);
|
|
304
|
+
return verifiedResults;
|
|
223
305
|
}
|
|
224
306
|
};
|
|
225
307
|
const fetchStatus = async (jid) => {
|
|
@@ -331,51 +413,6 @@ const makeChatsSocket = (config) => {
|
|
|
331
413
|
]
|
|
332
414
|
});
|
|
333
415
|
};
|
|
334
|
-
const getBusinessProfile = async (jid) => {
|
|
335
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
336
|
-
const results = await query({
|
|
337
|
-
tag: 'iq',
|
|
338
|
-
attrs: {
|
|
339
|
-
to: 's.whatsapp.net',
|
|
340
|
-
xmlns: 'w:biz',
|
|
341
|
-
type: 'get'
|
|
342
|
-
},
|
|
343
|
-
content: [{
|
|
344
|
-
tag: 'business_profile',
|
|
345
|
-
attrs: { v: '244' },
|
|
346
|
-
content: [{
|
|
347
|
-
tag: 'profile',
|
|
348
|
-
attrs: { jid }
|
|
349
|
-
}]
|
|
350
|
-
}]
|
|
351
|
-
});
|
|
352
|
-
const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
|
|
353
|
-
const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
|
|
354
|
-
if (profiles) {
|
|
355
|
-
const address = (0, WABinary_1.getBinaryNodeChild)(profiles, 'address');
|
|
356
|
-
const description = (0, WABinary_1.getBinaryNodeChild)(profiles, 'description');
|
|
357
|
-
const website = (0, WABinary_1.getBinaryNodeChild)(profiles, 'website');
|
|
358
|
-
const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
|
|
359
|
-
const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
|
|
360
|
-
const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
|
|
361
|
-
const businessHoursConfig = businessHours ?
|
|
362
|
-
(0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config') :
|
|
363
|
-
undefined;
|
|
364
|
-
const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
|
|
365
|
-
return {
|
|
366
|
-
wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
|
|
367
|
-
address: (_c = address === null || address === void 0 ? void 0 : address.content) === null || _c === void 0 ? void 0 : _c.toString(),
|
|
368
|
-
description: ((_d = description === null || description === void 0 ? void 0 : description.content) === null || _d === void 0 ? void 0 : _d.toString()) || '',
|
|
369
|
-
website: websiteStr ? [websiteStr] : [],
|
|
370
|
-
email: (_e = email === null || email === void 0 ? void 0 : email.content) === null || _e === void 0 ? void 0 : _e.toString(),
|
|
371
|
-
category: (_f = category === null || category === void 0 ? void 0 : category.content) === null || _f === void 0 ? void 0 : _f.toString(),
|
|
372
|
-
'business_hours': {
|
|
373
|
-
timezone: (_g = businessHours === null || businessHours === void 0 ? void 0 : businessHours.attrs) === null || _g === void 0 ? void 0 : _g.timezone,
|
|
374
|
-
'business_config': businessHoursConfig === null || businessHoursConfig === void 0 ? void 0 : businessHoursConfig.map(({ attrs }) => attrs)
|
|
375
|
-
}
|
|
376
|
-
};
|
|
377
|
-
}
|
|
378
|
-
};
|
|
379
416
|
const cleanDirtyBits = async (type, fromTimestamp) => {
|
|
380
417
|
logger.info({ fromTimestamp }, 'clean dirty bits ' + type);
|
|
381
418
|
await sendNode({
|
package/lib/Socket/dugong.d.ts
CHANGED
|
@@ -70,15 +70,16 @@ declare namespace kikyy {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
interface InteractiveMessage {
|
|
73
|
+
header?: string;
|
|
73
74
|
title: string;
|
|
74
75
|
footer?: string;
|
|
75
76
|
thumbnail?: string;
|
|
76
77
|
image?: string | Buffer | { url: string };
|
|
77
78
|
video?: string | Buffer | { url: string };
|
|
78
|
-
document?: Buffer;
|
|
79
|
+
document?: string | Buffer | { url: string };
|
|
79
80
|
mimetype?: string;
|
|
80
81
|
fileName?: string;
|
|
81
|
-
jpegThumbnail?: Buffer
|
|
82
|
+
jpegThumbnail?: string | Buffer | { url: string };
|
|
82
83
|
contextInfo?: {
|
|
83
84
|
mentionedJid?: string[];
|
|
84
85
|
forwardingScore?: number;
|
|
@@ -116,8 +117,8 @@ declare namespace kikyy {
|
|
|
116
117
|
}
|
|
117
118
|
|
|
118
119
|
interface AlbumItem {
|
|
119
|
-
image?: { url: string; caption?: string };
|
|
120
|
-
video?: { url: string; caption?: string };
|
|
120
|
+
image?: string | Buffer | { url: string; caption?: string };
|
|
121
|
+
video?: string | Buffer | { url: string; caption?: string };
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
interface EventMessageLocation {
|
|
@@ -146,6 +147,16 @@ declare namespace kikyy {
|
|
|
146
147
|
name: string;
|
|
147
148
|
pollVotes: PollVote[];
|
|
148
149
|
}
|
|
150
|
+
|
|
151
|
+
interface GroupStatusMessage {
|
|
152
|
+
message?: any;
|
|
153
|
+
image?: string | Buffer | { url: string };
|
|
154
|
+
video?: string | Buffer | { url: string };
|
|
155
|
+
text?: string;
|
|
156
|
+
caption?: string;
|
|
157
|
+
document?: string | Buffer | { url: string };
|
|
158
|
+
[key: string]: any;
|
|
159
|
+
}
|
|
149
160
|
|
|
150
161
|
interface MessageContent {
|
|
151
162
|
requestPaymentMessage?: PaymentMessage;
|
|
@@ -154,6 +165,7 @@ declare namespace kikyy {
|
|
|
154
165
|
albumMessage?: AlbumItem[];
|
|
155
166
|
eventMessage?: EventMessage;
|
|
156
167
|
pollResultMessage?: PollResultMessage;
|
|
168
|
+
groupStatusMessage?: GroupStatusMessage;
|
|
157
169
|
sender?: string;
|
|
158
170
|
}
|
|
159
171
|
|
|
@@ -168,6 +180,13 @@ declare namespace kikyy {
|
|
|
168
180
|
generateWAMessageFromContent: (jid: string, content: any, options?: any) => Promise<any>;
|
|
169
181
|
generateWAMessage: (jid: string, content: any, options?: any) => Promise<any>;
|
|
170
182
|
generateMessageID: () => string;
|
|
183
|
+
prepareMessageContent?: (content: any, options?: any) => Promise<any>;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
interface BailUtils {
|
|
187
|
+
generateWAMessageContent?: (content: any, options: WAMessageContentGenerationOptions) => Promise<any>;
|
|
188
|
+
generateMessageID: () => string;
|
|
189
|
+
getContentType: (msg: any) => string;
|
|
171
190
|
}
|
|
172
191
|
}
|
|
173
192
|
|
|
@@ -178,7 +197,7 @@ declare class kikyy {
|
|
|
178
197
|
relayMessageFn?: (jid: string, content: any, options?: any) => Promise<any>
|
|
179
198
|
);
|
|
180
199
|
|
|
181
|
-
detectType(content: kikyy.MessageContent): 'PAYMENT' | 'PRODUCT' | 'INTERACTIVE' | 'ALBUM' | 'EVENT' | 'POLL_RESULT' | null;
|
|
200
|
+
detectType(content: kikyy.MessageContent): 'PAYMENT' | 'PRODUCT' | 'INTERACTIVE' | 'ALBUM' | 'EVENT' | 'POLL_RESULT' | 'GROUP_STORY' | null;
|
|
182
201
|
|
|
183
202
|
handlePayment(
|
|
184
203
|
content: { requestPaymentMessage: kikyy.PaymentMessage },
|
|
@@ -214,6 +233,22 @@ declare class kikyy {
|
|
|
214
233
|
jid: string,
|
|
215
234
|
quoted?: proto.IWebMessageInfo
|
|
216
235
|
): Promise<any>;
|
|
236
|
+
|
|
237
|
+
handleGroupStory(
|
|
238
|
+
content: { groupStatusMessage: kikyy.GroupStatusMessage },
|
|
239
|
+
jid: string,
|
|
240
|
+
quoted?: proto.IWebMessageInfo
|
|
241
|
+
): Promise<any>;
|
|
242
|
+
|
|
243
|
+
buildMessageContent(
|
|
244
|
+
content: any,
|
|
245
|
+
opts?: kikyy.WAMessageContentGenerationOptions
|
|
246
|
+
): Promise<any>;
|
|
247
|
+
|
|
248
|
+
utils: kikyy.Utils;
|
|
249
|
+
relayMessage: (jid: string, content: any, options?: any) => Promise<any>;
|
|
250
|
+
waUploadToServer: kikyy.WAMediaUploadFunction;
|
|
251
|
+
bail: kikyy.BailUtils;
|
|
217
252
|
}
|
|
218
253
|
|
|
219
|
-
export = kikyy;
|
|
254
|
+
export = kikyy;
|