@queenanya/baileys 8.2.7-beta → 8.3.1
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/WAProto/index.d.ts +1590 -6
- package/WAProto/index.js +4635 -3
- package/engine-requirements.js +1 -1
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +232 -1
- package/lib/Defaults/index.js +21 -6
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.js +3 -2
- package/lib/Socket/Client/mobile-socket-client.d.ts +12 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
- package/lib/Socket/Client/{websocket.js → web-socket-client.js} +3 -3
- package/lib/Socket/business.d.ts +4 -9
- package/lib/Socket/chats.d.ts +3 -9
- package/lib/Socket/chats.js +6 -89
- package/lib/Socket/groups.d.ts +3 -7
- package/lib/Socket/groups.js +13 -9
- package/lib/Socket/index.d.ts +6 -9
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.d.ts +4 -9
- package/lib/Socket/messages-recv.js +13 -23
- package/lib/Socket/messages-send.d.ts +3 -8
- package/lib/Socket/messages-send.js +55 -86
- package/lib/Socket/newsletter.d.ts +3 -7
- package/lib/Socket/newsletter.js +2 -4
- package/lib/Socket/registration.d.ts +266 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +1 -2
- package/lib/Socket/socket.js +15 -10
- package/lib/Socket/usync.d.ts +1 -1
- package/lib/Socket/usync.js +15 -10
- package/lib/Store/make-in-memory-store.js +10 -8
- package/lib/Types/Auth.d.ts +6 -0
- package/lib/Types/Chat.d.ts +2 -8
- package/lib/Types/Contact.d.ts +4 -5
- package/lib/Types/GroupMetadata.d.ts +4 -3
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Message.d.ts +5 -5
- package/lib/Types/Socket.d.ts +3 -5
- package/lib/Utils/auth-utils.js +7 -0
- package/lib/Utils/chat-utils.d.ts +8 -8
- package/lib/Utils/chat-utils.js +4 -30
- package/lib/Utils/crypto.d.ts +1 -1
- package/lib/Utils/crypto.js +1 -3
- package/lib/Utils/decode-wa-message.d.ts +2 -4
- package/lib/Utils/decode-wa-message.js +18 -161
- package/lib/Utils/event-buffer.js +6 -4
- package/lib/Utils/generics.d.ts +18 -8
- package/lib/Utils/generics.js +93 -7
- package/lib/Utils/history.js +1 -1
- package/lib/Utils/messages-media.d.ts +9 -16
- package/lib/Utils/messages-media.js +175 -88
- package/lib/Utils/messages.d.ts +1 -1
- package/lib/Utils/messages.js +17 -15
- package/lib/Utils/noise-handler.d.ts +2 -1
- package/lib/Utils/noise-handler.js +10 -5
- package/lib/Utils/validate-connection.d.ts +1 -0
- package/lib/Utils/validate-connection.js +50 -16
- package/lib/WABinary/constants.d.ts +4 -4
- package/lib/WABinary/constants.js +1271 -8
- package/lib/WABinary/encode.js +5 -7
- package/lib/WABinary/jid-utils.d.ts +4 -4
- package/lib/WABinary/jid-utils.js +19 -19
- package/lib/WAM/constants.d.ts +2 -3
- package/lib/WAM/encode.js +2 -2
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +3 -3
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +1 -1
- package/lib/WAUSync/USyncQuery.js +13 -17
- package/package.json +25 -23
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-cache-manager-store.js +0 -83
- /package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +0 -0
- /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.makeRegistrationSocket = void 0;
|
|
7
|
+
exports.registrationParams = registrationParams;
|
|
8
|
+
exports.mobileRegisterCode = mobileRegisterCode;
|
|
9
|
+
exports.mobileRegisterExists = mobileRegisterExists;
|
|
10
|
+
exports.mobileRegister = mobileRegister;
|
|
11
|
+
exports.mobileRegisterEncrypt = mobileRegisterEncrypt;
|
|
12
|
+
exports.mobileRegisterFetch = mobileRegisterFetch;
|
|
13
|
+
/* eslint-disable camelcase */
|
|
14
|
+
const axios_1 = __importDefault(require("axios"));
|
|
15
|
+
const Defaults_1 = require("../Defaults");
|
|
16
|
+
const crypto_1 = require("../Utils/crypto");
|
|
17
|
+
const WABinary_1 = require("../WABinary");
|
|
18
|
+
const business_1 = require("./business");
|
|
19
|
+
function urlencode(str) {
|
|
20
|
+
return str.replace(/-/g, '%2d').replace(/_/g, '%5f').replace(/~/g, '%7e');
|
|
21
|
+
}
|
|
22
|
+
const validRegistrationOptions = (config) => (config === null || config === void 0 ? void 0 : config.phoneNumberCountryCode) &&
|
|
23
|
+
config.phoneNumberNationalNumber &&
|
|
24
|
+
config.phoneNumberMobileCountryCode;
|
|
25
|
+
const makeRegistrationSocket = (config) => {
|
|
26
|
+
const sock = (0, business_1.makeBusinessSocket)(config);
|
|
27
|
+
const register = async (code) => {
|
|
28
|
+
if (!validRegistrationOptions(config.auth.creds.registration)) {
|
|
29
|
+
throw new Error('please specify the registration options');
|
|
30
|
+
}
|
|
31
|
+
const result = await mobileRegister({ ...sock.authState.creds, ...sock.authState.creds.registration, code }, config.options);
|
|
32
|
+
sock.authState.creds.me = {
|
|
33
|
+
id: (0, WABinary_1.jidEncode)(result.login, 's.whatsapp.net'),
|
|
34
|
+
name: '~'
|
|
35
|
+
};
|
|
36
|
+
sock.authState.creds.registered = true;
|
|
37
|
+
sock.ev.emit('creds.update', sock.authState.creds);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
const requestRegistrationCode = async (registrationOptions) => {
|
|
41
|
+
registrationOptions = registrationOptions || config.auth.creds.registration;
|
|
42
|
+
if (!validRegistrationOptions(registrationOptions)) {
|
|
43
|
+
throw new Error('Invalid registration options');
|
|
44
|
+
}
|
|
45
|
+
sock.authState.creds.registration = registrationOptions;
|
|
46
|
+
sock.ev.emit('creds.update', sock.authState.creds);
|
|
47
|
+
return mobileRegisterCode({ ...config.auth.creds, ...registrationOptions }, config.options);
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
...sock,
|
|
51
|
+
register,
|
|
52
|
+
requestRegistrationCode,
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
exports.makeRegistrationSocket = makeRegistrationSocket;
|
|
56
|
+
function convertBufferToUrlHex(buffer) {
|
|
57
|
+
var id = '';
|
|
58
|
+
buffer.forEach((x) => {
|
|
59
|
+
// encode random identity_id buffer as percentage url encoding
|
|
60
|
+
id += `%${x.toString(16).padStart(2, '0').toLowerCase()}`;
|
|
61
|
+
});
|
|
62
|
+
return id;
|
|
63
|
+
}
|
|
64
|
+
function registrationParams(params) {
|
|
65
|
+
const e_regid = Buffer.alloc(4);
|
|
66
|
+
e_regid.writeInt32BE(params.registrationId);
|
|
67
|
+
const e_skey_id = Buffer.alloc(3);
|
|
68
|
+
e_skey_id.writeInt16BE(params.signedPreKey.keyId);
|
|
69
|
+
params.phoneNumberCountryCode = params.phoneNumberCountryCode.replace('+', '').trim();
|
|
70
|
+
params.phoneNumberNationalNumber = params.phoneNumberNationalNumber.replace(/[/-\s)(]/g, '').trim();
|
|
71
|
+
return {
|
|
72
|
+
cc: params.phoneNumberCountryCode,
|
|
73
|
+
in: params.phoneNumberNationalNumber,
|
|
74
|
+
Rc: '0',
|
|
75
|
+
lg: 'en',
|
|
76
|
+
lc: 'GB',
|
|
77
|
+
mistyped: '6',
|
|
78
|
+
authkey: Buffer.from(params.noiseKey.public).toString('base64url'),
|
|
79
|
+
e_regid: e_regid.toString('base64url'),
|
|
80
|
+
e_keytype: 'BQ',
|
|
81
|
+
e_ident: Buffer.from(params.signedIdentityKey.public).toString('base64url'),
|
|
82
|
+
// e_skey_id: e_skey_id.toString('base64url'),
|
|
83
|
+
e_skey_id: 'AAAA',
|
|
84
|
+
e_skey_val: Buffer.from(params.signedPreKey.keyPair.public).toString('base64url'),
|
|
85
|
+
e_skey_sig: Buffer.from(params.signedPreKey.signature).toString('base64url'),
|
|
86
|
+
fdid: params.phoneId,
|
|
87
|
+
network_ratio_type: '1',
|
|
88
|
+
expid: params.deviceId,
|
|
89
|
+
simnum: '1',
|
|
90
|
+
hasinrc: '1',
|
|
91
|
+
pid: Math.floor(Math.random() * 1000).toString(),
|
|
92
|
+
id: convertBufferToUrlHex(params.identityId),
|
|
93
|
+
backup_token: convertBufferToUrlHex(params.backupToken),
|
|
94
|
+
token: (0, crypto_1.md5)(Buffer.concat([Defaults_1.MOBILE_TOKEN, Buffer.from(params.phoneNumberNationalNumber)])).toString('hex'),
|
|
95
|
+
fraud_checkpoint_code: params.captcha,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Requests a registration code for the given phone number.
|
|
100
|
+
*/
|
|
101
|
+
function mobileRegisterCode(params, fetchOptions) {
|
|
102
|
+
return mobileRegisterFetch('/code', {
|
|
103
|
+
params: {
|
|
104
|
+
...registrationParams(params),
|
|
105
|
+
mcc: `${params.phoneNumberMobileCountryCode}`.padStart(3, '0'),
|
|
106
|
+
mnc: `${params.phoneNumberMobileNetworkCode || '001'}`.padStart(3, '0'),
|
|
107
|
+
sim_mcc: '000',
|
|
108
|
+
sim_mnc: '000',
|
|
109
|
+
method: (params === null || params === void 0 ? void 0 : params.method) || 'sms',
|
|
110
|
+
reason: '',
|
|
111
|
+
hasav: '1'
|
|
112
|
+
},
|
|
113
|
+
...fetchOptions,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function mobileRegisterExists(params, fetchOptions) {
|
|
117
|
+
return mobileRegisterFetch('/exist', {
|
|
118
|
+
params: registrationParams(params),
|
|
119
|
+
...fetchOptions
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Registers the phone number on whatsapp with the received OTP code.
|
|
124
|
+
*/
|
|
125
|
+
async function mobileRegister(params, fetchOptions) {
|
|
126
|
+
//const result = await mobileRegisterFetch(`/reg_onboard_abprop?cc=${params.phoneNumberCountryCode}&in=${params.phoneNumberNationalNumber}&rc=0`)
|
|
127
|
+
return mobileRegisterFetch('/register', {
|
|
128
|
+
params: { ...registrationParams(params), code: params.code.replace('-', '') },
|
|
129
|
+
...fetchOptions,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Encrypts the given string as AEAD aes-256-gcm with the public whatsapp key and a random keypair.
|
|
134
|
+
*/
|
|
135
|
+
function mobileRegisterEncrypt(data) {
|
|
136
|
+
const keypair = crypto_1.Curve.generateKeyPair();
|
|
137
|
+
const key = crypto_1.Curve.sharedKey(keypair.private, Defaults_1.REGISTRATION_PUBLIC_KEY);
|
|
138
|
+
const buffer = (0, crypto_1.aesEncryptGCM)(Buffer.from(data), new Uint8Array(key), Buffer.alloc(12), Buffer.alloc(0));
|
|
139
|
+
return Buffer.concat([Buffer.from(keypair.public), buffer]).toString('base64url');
|
|
140
|
+
}
|
|
141
|
+
async function mobileRegisterFetch(path, opts = {}) {
|
|
142
|
+
let url = `${Defaults_1.MOBILE_REGISTRATION_ENDPOINT}${path}`;
|
|
143
|
+
if (opts.params) {
|
|
144
|
+
const parameter = [];
|
|
145
|
+
for (const param in opts.params) {
|
|
146
|
+
if (opts.params[param] !== null && opts.params[param] !== undefined) {
|
|
147
|
+
parameter.push(param + '=' + urlencode(opts.params[param]));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
url += `?${parameter.join('&')}`;
|
|
151
|
+
delete opts.params;
|
|
152
|
+
}
|
|
153
|
+
if (!opts.headers) {
|
|
154
|
+
opts.headers = {};
|
|
155
|
+
}
|
|
156
|
+
opts.headers['User-Agent'] = Defaults_1.MOBILE_USERAGENT;
|
|
157
|
+
const response = await (0, axios_1.default)(url, opts);
|
|
158
|
+
var json = response.data;
|
|
159
|
+
if (response.status > 300 || json.reason) {
|
|
160
|
+
throw json;
|
|
161
|
+
}
|
|
162
|
+
if (json.status && !['ok', 'sent'].includes(json.status)) {
|
|
163
|
+
throw json;
|
|
164
|
+
}
|
|
165
|
+
return json;
|
|
166
|
+
}
|
package/lib/Socket/socket.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Boom } from '@hapi/boom';
|
|
2
2
|
import { SocketConfig } from '../Types';
|
|
3
3
|
import { BinaryNode } from '../WABinary';
|
|
4
|
-
import { WebSocketClient } from './Client';
|
|
5
4
|
/**
|
|
6
5
|
* Connects to WA servers and performs:
|
|
7
6
|
* - simple queries (no retry mechanism, wait for connection establishment)
|
|
@@ -10,7 +9,7 @@ import { WebSocketClient } from './Client';
|
|
|
10
9
|
*/
|
|
11
10
|
export declare const makeSocket: (config: SocketConfig) => {
|
|
12
11
|
type: "md";
|
|
13
|
-
ws:
|
|
12
|
+
ws: any;
|
|
14
13
|
ev: import("../Types").BaileysEventEmitter & {
|
|
15
14
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
|
|
16
15
|
buffer(): void;
|
package/lib/Socket/socket.js
CHANGED
|
@@ -20,14 +20,15 @@ const Client_1 = require("./Client");
|
|
|
20
20
|
const makeSocket = (config) => {
|
|
21
21
|
var _a, _b;
|
|
22
22
|
const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, } = config;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
let url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
|
|
24
|
+
config.mobile = config.mobile || url.protocol === 'tcp:';
|
|
25
|
+
if (config.mobile && url.protocol !== 'tcp:') {
|
|
26
|
+
url = new url_1.URL(`tcp://${Defaults_1.MOBILE_ENDPOINT}:${Defaults_1.MOBILE_PORT}`);
|
|
26
27
|
}
|
|
27
|
-
if (url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
|
|
28
|
+
if (!config.mobile && url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
|
|
28
29
|
url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'));
|
|
29
30
|
}
|
|
30
|
-
const ws = new Client_1.WebSocketClient(url, config);
|
|
31
|
+
const ws = config.socket ? config.socket : config.mobile ? new Client_1.MobileSocketClient(url, config) : new Client_1.WebSocketClient(url, config);
|
|
31
32
|
ws.connect();
|
|
32
33
|
const ev = (0, Utils_1.makeEventBuffer)(logger);
|
|
33
34
|
/** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
|
|
@@ -35,7 +36,8 @@ const makeSocket = (config) => {
|
|
|
35
36
|
/** WA noise protocol wrapper */
|
|
36
37
|
const noise = (0, Utils_1.makeNoiseHandler)({
|
|
37
38
|
keyPair: ephemeralKeyPair,
|
|
38
|
-
NOISE_HEADER: Defaults_1.NOISE_WA_HEADER,
|
|
39
|
+
NOISE_HEADER: config.mobile ? Defaults_1.MOBILE_NOISE_HEADER : Defaults_1.NOISE_WA_HEADER,
|
|
40
|
+
mobile: config.mobile,
|
|
39
41
|
logger,
|
|
40
42
|
routingInfo: (_b = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _b === void 0 ? void 0 : _b.routingInfo
|
|
41
43
|
});
|
|
@@ -159,7 +161,10 @@ const makeSocket = (config) => {
|
|
|
159
161
|
logger.trace({ handshake }, 'handshake recv from WA');
|
|
160
162
|
const keyEnc = await noise.processHandshake(handshake, creds.noiseKey);
|
|
161
163
|
let node;
|
|
162
|
-
if (
|
|
164
|
+
if (config.mobile) {
|
|
165
|
+
node = (0, Utils_1.generateMobileNode)(config);
|
|
166
|
+
}
|
|
167
|
+
else if (!creds.me) {
|
|
163
168
|
node = (0, Utils_1.generateRegistrationNode)(creds, config);
|
|
164
169
|
logger.info({ node }, 'not logged in, attempting registration...');
|
|
165
170
|
}
|
|
@@ -229,11 +234,11 @@ const makeSocket = (config) => {
|
|
|
229
234
|
const l0 = frame.tag;
|
|
230
235
|
const l1 = frame.attrs || {};
|
|
231
236
|
const l2 = Array.isArray(frame.content) ? (_a = frame.content[0]) === null || _a === void 0 ? void 0 : _a.tag : '';
|
|
232
|
-
|
|
237
|
+
Object.keys(l1).forEach(key => {
|
|
233
238
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
|
|
234
239
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
|
|
235
240
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
|
|
236
|
-
}
|
|
241
|
+
});
|
|
237
242
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
|
|
238
243
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
|
|
239
244
|
if (!anyTriggered && logger.level === 'debug') {
|
|
@@ -371,7 +376,7 @@ const makeSocket = (config) => {
|
|
|
371
376
|
}
|
|
372
377
|
authState.creds.me = {
|
|
373
378
|
id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
|
374
|
-
name: '
|
|
379
|
+
name: '~'
|
|
375
380
|
};
|
|
376
381
|
ev.emit('creds.update', authState.creds);
|
|
377
382
|
await sendNode({
|
package/lib/Socket/usync.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { USyncQuery } from '../WAUSync';
|
|
|
5
5
|
export declare const makeUSyncSocket: (config: SocketConfig) => {
|
|
6
6
|
executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
|
|
7
7
|
type: "md";
|
|
8
|
-
ws:
|
|
8
|
+
ws: any;
|
|
9
9
|
ev: import("../Types").BaileysEventEmitter & {
|
|
10
10
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
|
|
11
11
|
buffer(): void;
|
package/lib/Socket/usync.js
CHANGED
|
@@ -6,7 +6,7 @@ const WABinary_1 = require("../WABinary");
|
|
|
6
6
|
const socket_1 = require("./socket");
|
|
7
7
|
const makeUSyncSocket = (config) => {
|
|
8
8
|
const sock = (0, socket_1.makeSocket)(config);
|
|
9
|
-
const { generateMessageTag, query } = sock;
|
|
9
|
+
const { generateMessageTag, query, } = sock;
|
|
10
10
|
const executeUSyncQuery = async (usyncQuery) => {
|
|
11
11
|
if (usyncQuery.protocols.length === 0) {
|
|
12
12
|
throw new boom_1.Boom('USyncQuery must have at least one protocol');
|
|
@@ -14,13 +14,15 @@ const makeUSyncSocket = (config) => {
|
|
|
14
14
|
// todo: validate users, throw WARNING on no valid users
|
|
15
15
|
// variable below has only validated users
|
|
16
16
|
const validUsers = usyncQuery.users;
|
|
17
|
-
const userNodes = validUsers.map(user => {
|
|
17
|
+
const userNodes = validUsers.map((user) => {
|
|
18
18
|
return {
|
|
19
19
|
tag: 'user',
|
|
20
20
|
attrs: {
|
|
21
|
-
jid: !user.phone ? user.id : undefined
|
|
21
|
+
jid: !user.phone ? user.id : undefined,
|
|
22
22
|
},
|
|
23
|
-
content: usyncQuery.protocols
|
|
23
|
+
content: usyncQuery.protocols
|
|
24
|
+
.map((a) => a.getUserElement(user))
|
|
25
|
+
.filter(a => a !== null)
|
|
24
26
|
};
|
|
25
27
|
});
|
|
26
28
|
const listNode = {
|
|
@@ -31,14 +33,14 @@ const makeUSyncSocket = (config) => {
|
|
|
31
33
|
const queryNode = {
|
|
32
34
|
tag: 'query',
|
|
33
35
|
attrs: {},
|
|
34
|
-
content: usyncQuery.protocols.map(a => a.getQueryElement())
|
|
36
|
+
content: usyncQuery.protocols.map((a) => a.getQueryElement())
|
|
35
37
|
};
|
|
36
38
|
const iq = {
|
|
37
39
|
tag: 'iq',
|
|
38
40
|
attrs: {
|
|
39
41
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
40
42
|
type: 'get',
|
|
41
|
-
xmlns: 'usync'
|
|
43
|
+
xmlns: 'usync',
|
|
42
44
|
},
|
|
43
45
|
content: [
|
|
44
46
|
{
|
|
@@ -48,18 +50,21 @@ const makeUSyncSocket = (config) => {
|
|
|
48
50
|
mode: usyncQuery.mode,
|
|
49
51
|
sid: generateMessageTag(),
|
|
50
52
|
last: 'true',
|
|
51
|
-
index: '0'
|
|
53
|
+
index: '0',
|
|
52
54
|
},
|
|
53
|
-
content: [
|
|
55
|
+
content: [
|
|
56
|
+
queryNode,
|
|
57
|
+
listNode
|
|
58
|
+
]
|
|
54
59
|
}
|
|
55
|
-
]
|
|
60
|
+
],
|
|
56
61
|
};
|
|
57
62
|
const result = await query(iq);
|
|
58
63
|
return usyncQuery.parseUSyncQueryResult(result);
|
|
59
64
|
};
|
|
60
65
|
return {
|
|
61
66
|
...sock,
|
|
62
|
-
executeUSyncQuery
|
|
67
|
+
executeUSyncQuery,
|
|
63
68
|
};
|
|
64
69
|
};
|
|
65
70
|
exports.makeUSyncSocket = makeUSyncSocket;
|
|
@@ -191,14 +191,16 @@ exports.default = (config) => {
|
|
|
191
191
|
const jid = (0, WABinary_1.jidNormalizedUser)(msg.key.remoteJid);
|
|
192
192
|
const list = assertMessageList(jid);
|
|
193
193
|
list.upsert(msg, 'append');
|
|
194
|
-
if (type === 'notify'
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
194
|
+
if (type === 'notify') {
|
|
195
|
+
if (!chats.get(jid)) {
|
|
196
|
+
ev.emit('chats.upsert', [
|
|
197
|
+
{
|
|
198
|
+
id: jid,
|
|
199
|
+
conversationTimestamp: (0, Utils_1.toNumber)(msg.messageTimestamp),
|
|
200
|
+
unreadCount: 1
|
|
201
|
+
}
|
|
202
|
+
]);
|
|
203
|
+
}
|
|
202
204
|
}
|
|
203
205
|
}
|
|
204
206
|
break;
|
package/lib/Types/Auth.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { proto } from '../../WAProto';
|
|
2
|
+
import { RegistrationOptions } from '../Socket/registration';
|
|
2
3
|
import type { Contact } from './Contact';
|
|
3
4
|
import type { MinimalMessage } from './Message';
|
|
4
5
|
export type KeyPair = {
|
|
@@ -55,7 +56,12 @@ export type AuthenticationCreds = SignalCreds & {
|
|
|
55
56
|
/** number of times history & app state has been synced */
|
|
56
57
|
accountSyncCounter: number;
|
|
57
58
|
accountSettings: AccountSettings;
|
|
59
|
+
deviceId: string;
|
|
60
|
+
phoneId: string;
|
|
61
|
+
identityId: Buffer;
|
|
58
62
|
registered: boolean;
|
|
63
|
+
backupToken: Buffer;
|
|
64
|
+
registration: RegistrationOptions;
|
|
59
65
|
pairingCode: string | undefined;
|
|
60
66
|
lastPropHash: string | undefined;
|
|
61
67
|
routingInfo: Buffer | undefined;
|
package/lib/Types/Chat.d.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import type { proto } from '../../WAProto';
|
|
2
2
|
import type { AccountSettings } from './Auth';
|
|
3
|
-
import type { ContactAction } from './Contact';
|
|
4
3
|
import type { BufferedEventData } from './Events';
|
|
5
|
-
import type { LabelActionBody } from './Label';
|
|
6
4
|
import type { ChatLabelAssociationActionBody } from './LabelAssociation';
|
|
7
5
|
import type { MessageLabelAssociationActionBody } from './LabelAssociation';
|
|
8
6
|
import type { MinimalMessage, WAMessageKey } from './Message';
|
|
9
7
|
/** privacy settings in WhatsApp Web */
|
|
10
8
|
export type WAPrivacyValue = 'all' | 'contacts' | 'contact_blacklist' | 'none';
|
|
9
|
+
export type WAPrivacyCallValue = 'all' | 'known';
|
|
10
|
+
export type WAPrivacyMessagesValue = 'all' | 'contacts';
|
|
11
11
|
export type WAPrivacyOnlineValue = 'all' | 'match_last_seen';
|
|
12
12
|
export type WAPrivacyGroupAddValue = 'all' | 'contacts' | 'contact_blacklist';
|
|
13
13
|
export type WAReadReceiptsValue = 'all' | 'none';
|
|
14
|
-
export type WAPrivacyCallValue = 'all' | 'known';
|
|
15
|
-
export type WAPrivacyMessagesValue = 'all' | 'contacts';
|
|
16
14
|
/** set of statuses visible to other people; see updatePresence() in WhatsAppWeb.Send */
|
|
17
15
|
export type WAPresence = 'unavailable' | 'available' | 'composing' | 'recording' | 'paused';
|
|
18
16
|
export declare const ALL_WA_PATCH_NAMES: readonly ["critical_block", "critical_unblock_low", "regular_high", "regular_low", "regular"];
|
|
@@ -89,10 +87,6 @@ export type ChatModification = {
|
|
|
89
87
|
} | {
|
|
90
88
|
delete: true;
|
|
91
89
|
lastMessages: LastMessageList;
|
|
92
|
-
} | {
|
|
93
|
-
contact: ContactAction | null;
|
|
94
|
-
} | {
|
|
95
|
-
addLabel: LabelActionBody;
|
|
96
90
|
} | {
|
|
97
91
|
addChatLabel: ChatLabelAssociationActionBody;
|
|
98
92
|
} | {
|
package/lib/Types/Contact.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export interface Contact {
|
|
2
|
+
/** ID either in lid or jid format **/
|
|
2
3
|
id: string;
|
|
4
|
+
/** ID in Lid (anonymous) format (@lid) **/
|
|
3
5
|
lid?: string;
|
|
6
|
+
/** ID in Phone Number format (@s.whatsapp.net) **/
|
|
7
|
+
jid?: string;
|
|
4
8
|
/** name of the contact, you have saved on your WA */
|
|
5
9
|
name?: string;
|
|
6
10
|
/** name of the contact, the contact has set on their own on WA */
|
|
@@ -17,8 +21,3 @@ export interface Contact {
|
|
|
17
21
|
imgUrl?: string | null;
|
|
18
22
|
status?: string;
|
|
19
23
|
}
|
|
20
|
-
export type ContactAction = {
|
|
21
|
-
fistName: string;
|
|
22
|
-
fullName: string;
|
|
23
|
-
saveOnPrimaryAddressbook: boolean;
|
|
24
|
-
};
|
|
@@ -3,6 +3,7 @@ export type GroupParticipant = (Contact & {
|
|
|
3
3
|
isAdmin?: boolean;
|
|
4
4
|
isSuperAdmin?: boolean;
|
|
5
5
|
admin?: 'admin' | 'superadmin' | null;
|
|
6
|
+
jid?: string;
|
|
6
7
|
lid?: string;
|
|
7
8
|
});
|
|
8
9
|
export type ParticipantAction = 'add' | 'remove' | 'promote' | 'demote' | 'modify';
|
|
@@ -13,17 +14,17 @@ export interface GroupMetadata {
|
|
|
13
14
|
/** group uses 'lid' or 'pn' to send messages */
|
|
14
15
|
addressingMode: 'pn' | 'lid';
|
|
15
16
|
owner: string | undefined;
|
|
16
|
-
|
|
17
|
+
ownerLid?: string | undefined;
|
|
17
18
|
subject: string;
|
|
18
19
|
/** group subject owner */
|
|
19
20
|
subjectOwner?: string;
|
|
20
|
-
|
|
21
|
+
subjectOwnerLid?: string;
|
|
21
22
|
/** group subject modification date */
|
|
22
23
|
subjectTime?: number;
|
|
23
24
|
creation?: number;
|
|
24
25
|
desc?: string;
|
|
25
26
|
descOwner?: string;
|
|
26
|
-
|
|
27
|
+
descOwnerLid?: string;
|
|
27
28
|
descId?: string;
|
|
28
29
|
descTime?: number;
|
|
29
30
|
/** if this group is part of a community, it returns the jid of the community to which it belongs */
|
package/lib/Types/Label.d.ts
CHANGED
|
@@ -10,17 +10,6 @@ export interface Label {
|
|
|
10
10
|
/** WhatsApp has 5 predefined labels (New customer, New order & etc) */
|
|
11
11
|
predefinedId?: string;
|
|
12
12
|
}
|
|
13
|
-
export interface LabelActionBody {
|
|
14
|
-
id: string;
|
|
15
|
-
/** Label name */
|
|
16
|
-
name?: string;
|
|
17
|
-
/** Label color ID */
|
|
18
|
-
color?: number;
|
|
19
|
-
/** Is label has been deleted */
|
|
20
|
-
deleted?: boolean;
|
|
21
|
-
/** WhatsApp has 5 predefined labels (New customer, New order & etc) */
|
|
22
|
-
predefinedId?: number;
|
|
23
|
-
}
|
|
24
13
|
/** WhatsApp has 20 predefined colors */
|
|
25
14
|
export declare enum LabelColor {
|
|
26
15
|
Color1 = 0,
|
package/lib/Types/Message.d.ts
CHANGED
|
@@ -13,7 +13,9 @@ export type WAMessageContent = proto.IMessage;
|
|
|
13
13
|
export type WAContactMessage = proto.Message.IContactMessage;
|
|
14
14
|
export type WAContactsArrayMessage = proto.Message.IContactsArrayMessage;
|
|
15
15
|
export type WAMessageKey = proto.IMessageKey & {
|
|
16
|
-
|
|
16
|
+
senderPn?: string;
|
|
17
|
+
senderLid?: string;
|
|
18
|
+
participantLid?: string;
|
|
17
19
|
server_id?: string;
|
|
18
20
|
};
|
|
19
21
|
export type WATextMessage = proto.Message.IExtendedTextMessage;
|
|
@@ -22,13 +24,11 @@ export type WALocationMessage = proto.Message.ILocationMessage;
|
|
|
22
24
|
export type WAGenericMediaMessage = proto.Message.IVideoMessage | proto.Message.IImageMessage | proto.Message.IAudioMessage | proto.Message.IDocumentMessage | proto.Message.IStickerMessage;
|
|
23
25
|
export declare const WAMessageStubType: typeof proto.WebMessageInfo.StubType;
|
|
24
26
|
export declare const WAMessageStatus: typeof proto.WebMessageInfo.Status;
|
|
25
|
-
export type
|
|
27
|
+
export type WAMediaUpload = Buffer | {
|
|
26
28
|
url: URL | string;
|
|
27
|
-
}
|
|
28
|
-
export type WAMediaPayloadStream = {
|
|
29
|
+
} | {
|
|
29
30
|
stream: Readable;
|
|
30
31
|
};
|
|
31
|
-
export type WAMediaUpload = Buffer | WAMediaPayloadStream | WAMediaPayloadURL;
|
|
32
32
|
/** Set of message types that are supported by the library */
|
|
33
33
|
export type MessageType = keyof proto.Message;
|
|
34
34
|
export type DownloadableMessage = {
|
package/lib/Types/Socket.d.ts
CHANGED
|
@@ -31,9 +31,7 @@ export type SocketConfig = {
|
|
|
31
31
|
defaultQueryTimeoutMs: number | undefined;
|
|
32
32
|
/** ping-pong interval for WS connection */
|
|
33
33
|
keepAliveIntervalMs: number;
|
|
34
|
-
/** should baileys use the mobile api instead of the multi device api
|
|
35
|
-
* @deprecated This feature has been removed
|
|
36
|
-
*/
|
|
34
|
+
/** should baileys use the mobile api instead of the multi device api */
|
|
37
35
|
mobile?: boolean;
|
|
38
36
|
/** proxy agent */
|
|
39
37
|
agent?: Agent;
|
|
@@ -83,8 +81,6 @@ export type SocketConfig = {
|
|
|
83
81
|
linkPreviewImageThumbnailWidth: number;
|
|
84
82
|
/** Should Baileys ask the phone for full history, will be received async */
|
|
85
83
|
syncFullHistory: boolean;
|
|
86
|
-
/** Ignore Message when offline, default is false */
|
|
87
|
-
ignoreMsgLoading: boolean;
|
|
88
84
|
/** Should baileys fire init queries automatically, default true */
|
|
89
85
|
fireInitQueries: boolean;
|
|
90
86
|
/**
|
|
@@ -118,4 +114,6 @@ export type SocketConfig = {
|
|
|
118
114
|
/** cached group metadata, use to prevent redundant requests to WA & speed up msg sending */
|
|
119
115
|
cachedGroupMetadata: (jid: string) => Promise<GroupMetadata | undefined>;
|
|
120
116
|
makeSignalRepository: (auth: SignalAuthState) => SignalRepository;
|
|
117
|
+
/** Socket passthrough */
|
|
118
|
+
socket?: any;
|
|
121
119
|
};
|
package/lib/Utils/auth-utils.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.initAuthCreds = exports.addTransactionCapability = void 0;
|
|
|
7
7
|
exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
|
|
8
8
|
const crypto_1 = require("crypto");
|
|
9
9
|
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
|
10
|
+
const uuid_1 = require("uuid");
|
|
10
11
|
const Defaults_1 = require("../Defaults");
|
|
11
12
|
const crypto_2 = require("./crypto");
|
|
12
13
|
const generics_1 = require("./generics");
|
|
@@ -190,7 +191,13 @@ const initAuthCreds = () => {
|
|
|
190
191
|
accountSettings: {
|
|
191
192
|
unarchiveChats: false
|
|
192
193
|
},
|
|
194
|
+
// mobile creds
|
|
195
|
+
deviceId: Buffer.from((0, uuid_1.v4)().replace(/-/g, ''), 'hex').toString('base64url'),
|
|
196
|
+
phoneId: (0, uuid_1.v4)(),
|
|
197
|
+
identityId: (0, crypto_1.randomBytes)(20),
|
|
193
198
|
registered: false,
|
|
199
|
+
backupToken: (0, crypto_1.randomBytes)(20),
|
|
200
|
+
registration: {},
|
|
194
201
|
pairingCode: undefined,
|
|
195
202
|
lastPropHash: undefined,
|
|
196
203
|
routingInfo: undefined,
|
|
@@ -28,23 +28,23 @@ export declare const decodeSyncdPatch: (msg: proto.ISyncdPatch, name: WAPatchNam
|
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
30
|
}>;
|
|
31
|
-
export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<
|
|
32
|
-
|
|
31
|
+
export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<any>) => Promise<{
|
|
32
|
+
critical_unblock_low: {
|
|
33
33
|
patches: proto.ISyncdPatch[];
|
|
34
34
|
hasMorePatches: boolean;
|
|
35
35
|
snapshot?: proto.ISyncdSnapshot;
|
|
36
36
|
};
|
|
37
|
-
|
|
37
|
+
regular_high: {
|
|
38
38
|
patches: proto.ISyncdPatch[];
|
|
39
39
|
hasMorePatches: boolean;
|
|
40
40
|
snapshot?: proto.ISyncdSnapshot;
|
|
41
41
|
};
|
|
42
|
-
|
|
42
|
+
regular_low: {
|
|
43
43
|
patches: proto.ISyncdPatch[];
|
|
44
44
|
hasMorePatches: boolean;
|
|
45
45
|
snapshot?: proto.ISyncdSnapshot;
|
|
46
46
|
};
|
|
47
|
-
|
|
47
|
+
critical_block: {
|
|
48
48
|
patches: proto.ISyncdPatch[];
|
|
49
49
|
hasMorePatches: boolean;
|
|
50
50
|
snapshot?: proto.ISyncdSnapshot;
|
|
@@ -55,13 +55,13 @@ export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosReq
|
|
|
55
55
|
snapshot?: proto.ISyncdSnapshot;
|
|
56
56
|
};
|
|
57
57
|
}>;
|
|
58
|
-
export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<
|
|
59
|
-
export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<
|
|
58
|
+
export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<any>) => Promise<Buffer<ArrayBuffer>>;
|
|
59
|
+
export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<any>) => Promise<proto.SyncdMutations>;
|
|
60
60
|
export declare const decodeSyncdSnapshot: (name: WAPatchName, snapshot: proto.ISyncdSnapshot, getAppStateSyncKey: FetchAppStateSyncKey, minimumVersionNumber: number | undefined, validateMacs?: boolean) => Promise<{
|
|
61
61
|
state: LTHashState;
|
|
62
62
|
mutationMap: ChatMutationMap;
|
|
63
63
|
}>;
|
|
64
|
-
export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<
|
|
64
|
+
export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<any>, minimumVersionNumber?: number, logger?: ILogger, validateMacs?: boolean) => Promise<{
|
|
65
65
|
state: LTHashState;
|
|
66
66
|
mutationMap: ChatMutationMap;
|
|
67
67
|
}>;
|