@baileys-md/baileys 11.0.3 → 11.1.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/LICENSE +1 -1
- package/README.md +1 -1
- package/WAProto/index.js +4182 -13516
- package/WASignalGroup/GroupProtocol.js +1697 -0
- package/WASignalGroup/ciphertext_message.js +16 -0
- package/WASignalGroup/group_cipher.js +120 -0
- package/WASignalGroup/group_session_builder.js +46 -0
- package/WASignalGroup/index.js +5 -0
- package/WASignalGroup/keyhelper.js +21 -0
- package/WASignalGroup/protobufs.js +3 -0
- package/WASignalGroup/queue_job.js +69 -0
- package/WASignalGroup/sender_chain_key.js +50 -0
- package/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/WASignalGroup/sender_key_message.js +92 -0
- package/WASignalGroup/sender_key_name.js +70 -0
- package/WASignalGroup/sender_key_record.js +56 -0
- package/WASignalGroup/sender_key_state.js +129 -0
- package/{lib/Signal/Group/sender-message-key.js → WASignalGroup/sender_message_key.js} +16 -4
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.js +71 -52
- package/lib/Defaults/{phonenumber-mcc.js → phonenumber-mcc.json} +1 -1
- package/lib/Signal/libsignal.js +61 -41
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +19 -3
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.js +42 -37
- package/lib/Socket/chats.js +187 -194
- package/lib/Socket/groups.js +90 -87
- package/lib/Socket/index.js +8 -7
- package/lib/Socket/messages-recv.js +335 -360
- package/lib/Socket/messages-send.js +279 -156
- package/lib/Socket/newsletter.js +213 -144
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.js +161 -128
- package/lib/Socket/usync.js +26 -19
- package/lib/Store/index.js +8 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/{Utils → Store}/make-in-memory-store.js +27 -19
- package/lib/Store/make-mongo-store.js +567 -0
- package/lib/{Utils → Store}/make-ordered-dictionary.js +5 -2
- package/lib/{Utils → Store}/object-repository.js +4 -1
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +4 -8
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +5 -3
- package/lib/Types/LabelAssociation.js +5 -3
- package/lib/Types/Message.js +7 -7
- package/lib/Types/Newsletter.js +17 -30
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +2 -2
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.js +47 -31
- package/lib/Utils/baileys-event-stream.js +22 -15
- package/lib/Utils/business.js +69 -66
- package/lib/Utils/chat-utils.js +195 -200
- package/lib/Utils/crypto.js +85 -70
- package/lib/Utils/decode-wa-message.js +51 -46
- package/lib/Utils/event-buffer.js +46 -36
- package/lib/Utils/generics.js +188 -116
- package/lib/Utils/history.js +46 -37
- package/lib/Utils/index.js +33 -19
- package/lib/Utils/link-preview.js +55 -14
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.js +26 -23
- package/lib/Utils/make-mutex.js +10 -7
- package/lib/Utils/messages-media.js +368 -239
- package/lib/Utils/messages.js +510 -278
- package/lib/Utils/noise-handler.js +31 -22
- package/lib/Utils/process-message.js +148 -144
- package/lib/Utils/signal.js +64 -71
- package/lib/Utils/use-multi-file-auth-state.js +32 -14
- package/lib/Utils/validate-connection.js +115 -72
- package/lib/WABinary/constants.js +20 -1281
- package/lib/WABinary/decode.js +52 -15
- package/lib/WABinary/encode.js +48 -14
- package/lib/WABinary/generic-utils.js +39 -31
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.js +40 -23
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.js +2366 -2257
- package/lib/WAM/encode.js +21 -17
- package/lib/WAM/index.js +19 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -8
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -9
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +6 -3
- package/lib/WAUSync/Protocols/index.js +20 -5
- package/lib/WAUSync/USyncQuery.js +32 -34
- package/lib/WAUSync/USyncUser.js +5 -2
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.js +33 -11
- package/package.json +61 -21
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/WAProto.proto +0 -4633
- package/WAProto/fix-imports.js +0 -29
- package/lib/Defaults/baileys-version.js +0 -1
- package/lib/Signal/Group/ciphertext-message.js +0 -12
- package/lib/Signal/Group/group-session-builder.js +0 -30
- package/lib/Signal/Group/group_cipher.js +0 -94
- package/lib/Signal/Group/index.js +0 -12
- package/lib/Signal/Group/keyhelper.js +0 -19
- package/lib/Signal/Group/queue-job.js +0 -54
- package/lib/Signal/Group/sender-chain-key.js +0 -32
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
- package/lib/Signal/Group/sender-key-message.js +0 -67
- package/lib/Signal/Group/sender-key-name.js +0 -48
- package/lib/Signal/Group/sender-key-record.js +0 -50
- package/lib/Signal/Group/sender-key-state.js +0 -96
- package/lib/Socket/Client/types.js +0 -11
- package/lib/Socket/Client/websocket.js +0 -50
- package/lib/Socket/communities.js +0 -351
- package/lib/Socket/mex.js +0 -42
package/lib/Utils/generics.js
CHANGED
|
@@ -1,46 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.generateMessageID = exports.generateMessageIDV2 = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeNewsletterMessage = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browsers = void 0;
|
|
40
|
+
exports.promiseTimeout = promiseTimeout;
|
|
41
|
+
exports.bindWaitForEvent = bindWaitForEvent;
|
|
42
|
+
exports.trimUndefined = trimUndefined;
|
|
43
|
+
exports.bytesToCrockford = bytesToCrockford;
|
|
44
|
+
const boom_1 = require("@hapi/boom");
|
|
45
|
+
const axios_1 = __importDefault(require("axios"));
|
|
46
|
+
const crypto_1 = require("crypto");
|
|
47
|
+
const os_1 = require("os");
|
|
48
|
+
const WAProto_1 = require("../../WAProto");
|
|
49
|
+
const baileys_version_json_1 = require("../Defaults/baileys-version.json");
|
|
50
|
+
const Types_1 = require("../Types");
|
|
51
|
+
const WABinary_1 = require("../WABinary");
|
|
52
|
+
const COMPANION_PLATFORM_MAP = {
|
|
53
|
+
'Chrome': '49',
|
|
54
|
+
'Edge': '50',
|
|
55
|
+
'Firefox': '51',
|
|
56
|
+
'Opera': '53',
|
|
57
|
+
'Safari': '54'
|
|
58
|
+
};
|
|
10
59
|
const PLATFORM_MAP = {
|
|
11
|
-
aix: 'AIX',
|
|
12
|
-
darwin: 'Mac OS',
|
|
13
|
-
win32: 'Windows',
|
|
14
|
-
android: 'Android',
|
|
15
|
-
freebsd: 'FreeBSD',
|
|
16
|
-
openbsd: 'OpenBSD',
|
|
17
|
-
sunos: 'Solaris'
|
|
18
|
-
linux: undefined,
|
|
19
|
-
haiku: undefined,
|
|
20
|
-
cygwin: undefined,
|
|
21
|
-
netbsd: undefined
|
|
60
|
+
'aix': 'AIX',
|
|
61
|
+
'darwin': 'Mac OS',
|
|
62
|
+
'win32': 'Windows',
|
|
63
|
+
'android': 'Android',
|
|
64
|
+
'freebsd': 'FreeBSD',
|
|
65
|
+
'openbsd': 'OpenBSD',
|
|
66
|
+
'sunos': 'Solaris'
|
|
22
67
|
};
|
|
23
|
-
|
|
24
|
-
ubuntu: browser => ['Ubuntu', browser, '22.04.4'],
|
|
25
|
-
macOS: browser => ['Mac OS', browser, '14.4.1'],
|
|
26
|
-
baileys: browser => ['Baileys', browser, '6.5.0'],
|
|
27
|
-
windows: browser => ['Windows', browser, '10.0.22631'],
|
|
68
|
+
exports.Browsers = {
|
|
69
|
+
ubuntu: (browser) => ['Ubuntu', browser, '22.04.4'],
|
|
70
|
+
macOS: (browser) => ['Mac OS', browser, '14.4.1'],
|
|
71
|
+
baileys: (browser) => ['Baileys', browser, '6.5.0'],
|
|
72
|
+
windows: (browser) => ['Windows', browser, '10.0.22631'],
|
|
28
73
|
/** The appropriate browser based on your OS & release */
|
|
29
|
-
appropriate: browser => [PLATFORM_MAP[platform()] || 'Ubuntu', browser, release()]
|
|
74
|
+
appropriate: (browser) => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
|
|
30
75
|
};
|
|
31
|
-
|
|
32
|
-
const platformType = proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
33
|
-
return platformType ? platformType.toString() : '
|
|
76
|
+
const getPlatformId = (browser) => {
|
|
77
|
+
const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
78
|
+
return platformType ? platformType.toString() : '49'; //chrome
|
|
34
79
|
};
|
|
35
|
-
|
|
36
|
-
|
|
80
|
+
exports.getPlatformId = getPlatformId;
|
|
81
|
+
exports.BufferJSON = {
|
|
37
82
|
replacer: (k, value) => {
|
|
38
|
-
if (Buffer.isBuffer(value) || value instanceof Uint8Array || value
|
|
39
|
-
return { type: 'Buffer', data: Buffer.from(value
|
|
83
|
+
if (Buffer.isBuffer(value) || value instanceof Uint8Array || (value === null || value === void 0 ? void 0 : value.type) === 'Buffer') {
|
|
84
|
+
return { type: 'Buffer', data: Buffer.from((value === null || value === void 0 ? void 0 : value.data) || value).toString('base64') };
|
|
40
85
|
}
|
|
41
86
|
return value;
|
|
42
87
|
},
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
88
|
reviver: (_, value) => {
|
|
45
89
|
if (typeof value === 'object' && !!value && (value.buffer === true || value.type === 'Buffer')) {
|
|
46
90
|
const val = value.data || value.value;
|
|
@@ -49,18 +93,18 @@ export const BufferJSON = {
|
|
|
49
93
|
return value;
|
|
50
94
|
}
|
|
51
95
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
else {
|
|
96
|
+
const getKeyAuthor = (key, meId = 'me') => (((key === null || key === void 0 ? void 0 : key.fromMe) ? meId : (key === null || key === void 0 ? void 0 : key.participant) || (key === null || key === void 0 ? void 0 : key.remoteJid)) || '');
|
|
97
|
+
exports.getKeyAuthor = getKeyAuthor;
|
|
98
|
+
const writeRandomPadMax16 = (msg) => {
|
|
99
|
+
const pad = (0, crypto_1.randomBytes)(1);
|
|
100
|
+
pad[0] &= 0xf;
|
|
101
|
+
if (!pad[0]) {
|
|
59
102
|
pad[0] = 0xf;
|
|
60
103
|
}
|
|
61
104
|
return Buffer.concat([msg, Buffer.alloc(pad[0], pad[0])]);
|
|
62
105
|
};
|
|
63
|
-
|
|
106
|
+
exports.writeRandomPadMax16 = writeRandomPadMax16;
|
|
107
|
+
const unpadRandomMax16 = (e) => {
|
|
64
108
|
const t = new Uint8Array(e);
|
|
65
109
|
if (0 === t.length) {
|
|
66
110
|
throw new Error('unpadPkcs7 given empty bytes');
|
|
@@ -71,11 +115,16 @@ export const unpadRandomMax16 = (e) => {
|
|
|
71
115
|
}
|
|
72
116
|
return new Uint8Array(t.buffer, t.byteOffset, t.length - r);
|
|
73
117
|
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
118
|
+
exports.unpadRandomMax16 = unpadRandomMax16;
|
|
119
|
+
const encodeWAMessage = (message) => ((0, exports.writeRandomPadMax16)(WAProto_1.proto.Message.encode(message).finish()));
|
|
120
|
+
exports.encodeWAMessage = encodeWAMessage;
|
|
121
|
+
const encodeNewsletterMessage = (message) => (WAProto_1.proto.Message.encode(message).finish());
|
|
122
|
+
exports.encodeNewsletterMessage = encodeNewsletterMessage;
|
|
123
|
+
const generateRegistrationId = () => {
|
|
124
|
+
return Uint16Array.from((0, crypto_1.randomBytes)(2))[0] & 16383;
|
|
77
125
|
};
|
|
78
|
-
|
|
126
|
+
exports.generateRegistrationId = generateRegistrationId;
|
|
127
|
+
const encodeBigEndian = (e, t = 4) => {
|
|
79
128
|
let r = e;
|
|
80
129
|
const a = new Uint8Array(t);
|
|
81
130
|
for (let i = t - 1; i >= 0; i--) {
|
|
@@ -84,28 +133,33 @@ export const encodeBigEndian = (e, t = 4) => {
|
|
|
84
133
|
}
|
|
85
134
|
return a;
|
|
86
135
|
};
|
|
87
|
-
|
|
136
|
+
exports.encodeBigEndian = encodeBigEndian;
|
|
137
|
+
const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t || 0);
|
|
138
|
+
exports.toNumber = toNumber;
|
|
88
139
|
/** unix timestamp of a date in seconds */
|
|
89
|
-
|
|
90
|
-
|
|
140
|
+
const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
|
|
141
|
+
exports.unixTimestampSeconds = unixTimestampSeconds;
|
|
142
|
+
const debouncedTimeout = (intervalMs = 1000, task) => {
|
|
91
143
|
let timeout;
|
|
92
144
|
return {
|
|
93
145
|
start: (newIntervalMs, newTask) => {
|
|
94
146
|
task = newTask || task;
|
|
95
147
|
intervalMs = newIntervalMs || intervalMs;
|
|
96
148
|
timeout && clearTimeout(timeout);
|
|
97
|
-
timeout = setTimeout(() => task
|
|
149
|
+
timeout = setTimeout(() => task === null || task === void 0 ? void 0 : task(), intervalMs);
|
|
98
150
|
},
|
|
99
151
|
cancel: () => {
|
|
100
152
|
timeout && clearTimeout(timeout);
|
|
101
153
|
timeout = undefined;
|
|
102
154
|
},
|
|
103
|
-
setTask: (newTask) =>
|
|
104
|
-
setInterval: (newInterval) =>
|
|
155
|
+
setTask: (newTask) => task = newTask,
|
|
156
|
+
setInterval: (newInterval) => intervalMs = newInterval
|
|
105
157
|
};
|
|
106
158
|
};
|
|
107
|
-
|
|
108
|
-
|
|
159
|
+
exports.debouncedTimeout = debouncedTimeout;
|
|
160
|
+
const delay = (ms) => (0, exports.delayCancellable)(ms).delay;
|
|
161
|
+
exports.delay = delay;
|
|
162
|
+
const delayCancellable = (ms) => {
|
|
109
163
|
const stack = new Error().stack;
|
|
110
164
|
let timeout;
|
|
111
165
|
let reject;
|
|
@@ -115,7 +169,7 @@ export const delayCancellable = (ms) => {
|
|
|
115
169
|
});
|
|
116
170
|
const cancel = () => {
|
|
117
171
|
clearTimeout(timeout);
|
|
118
|
-
reject(new Boom('Cancelled', {
|
|
172
|
+
reject(new boom_1.Boom('Cancelled', {
|
|
119
173
|
statusCode: 500,
|
|
120
174
|
data: {
|
|
121
175
|
stack
|
|
@@ -124,53 +178,56 @@ export const delayCancellable = (ms) => {
|
|
|
124
178
|
};
|
|
125
179
|
return { delay, cancel };
|
|
126
180
|
};
|
|
127
|
-
|
|
181
|
+
exports.delayCancellable = delayCancellable;
|
|
182
|
+
async function promiseTimeout(ms, promise) {
|
|
128
183
|
if (!ms) {
|
|
129
184
|
return new Promise(promise);
|
|
130
185
|
}
|
|
131
186
|
const stack = new Error().stack;
|
|
132
187
|
// Create a promise that rejects in <ms> milliseconds
|
|
133
|
-
const { delay, cancel } = delayCancellable(ms);
|
|
188
|
+
const { delay, cancel } = (0, exports.delayCancellable)(ms);
|
|
134
189
|
const p = new Promise((resolve, reject) => {
|
|
135
190
|
delay
|
|
136
|
-
.then(() => reject(new Boom('Timed Out', {
|
|
137
|
-
statusCode: DisconnectReason.timedOut,
|
|
191
|
+
.then(() => reject(new boom_1.Boom('Timed Out', {
|
|
192
|
+
statusCode: Types_1.DisconnectReason.timedOut,
|
|
138
193
|
data: {
|
|
139
194
|
stack
|
|
140
195
|
}
|
|
141
196
|
})))
|
|
142
197
|
.catch(err => reject(err));
|
|
143
198
|
promise(resolve, reject);
|
|
144
|
-
})
|
|
199
|
+
})
|
|
200
|
+
.finally(cancel);
|
|
145
201
|
return p;
|
|
146
202
|
}
|
|
147
|
-
|
|
148
|
-
// https://github.com/tulir/whatsmeow/blob/64bc969fbe78d31ae0dd443b8d4c80a5d026d07a/send.go#L42
|
|
149
|
-
export const generateMessageIDV2 = (userId) => {
|
|
203
|
+
const generateMessageIDV2 = (userId) => {
|
|
150
204
|
const data = Buffer.alloc(8 + 20 + 16);
|
|
151
205
|
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
|
|
152
206
|
if (userId) {
|
|
153
|
-
const id = jidDecode(userId);
|
|
154
|
-
if (id
|
|
207
|
+
const id = (0, WABinary_1.jidDecode)(userId);
|
|
208
|
+
if (id === null || id === void 0 ? void 0 : id.user) {
|
|
155
209
|
data.write(id.user, 8);
|
|
156
210
|
data.write('@c.us', 8 + id.user.length);
|
|
157
211
|
}
|
|
158
212
|
}
|
|
159
|
-
const random = randomBytes(16);
|
|
213
|
+
const random = (0, crypto_1.randomBytes)(16);
|
|
160
214
|
random.copy(data, 28);
|
|
161
|
-
const hash = createHash('sha256').update(data).digest();
|
|
215
|
+
const hash = (0, crypto_1.createHash)('sha256').update(data).digest();
|
|
162
216
|
return 'BAE5' + hash.toString('hex').toUpperCase().substring(0, 12);
|
|
163
217
|
};
|
|
218
|
+
exports.generateMessageIDV2 = generateMessageIDV2;
|
|
164
219
|
// generate a random ID to attach to a message
|
|
165
|
-
|
|
166
|
-
|
|
220
|
+
const generateMessageID = () => 'BAE5' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
|
|
221
|
+
exports.generateMessageID = generateMessageID;
|
|
222
|
+
function bindWaitForEvent(ev, event) {
|
|
167
223
|
return async (check, timeoutMs) => {
|
|
168
224
|
let listener;
|
|
169
225
|
let closeListener;
|
|
170
|
-
await promiseTimeout(timeoutMs, (resolve, reject) => {
|
|
226
|
+
await (promiseTimeout(timeoutMs, (resolve, reject) => {
|
|
171
227
|
closeListener = ({ connection, lastDisconnect }) => {
|
|
172
228
|
if (connection === 'close') {
|
|
173
|
-
reject(lastDisconnect
|
|
229
|
+
reject((lastDisconnect === null || lastDisconnect === void 0 ? void 0 : lastDisconnect.error)
|
|
230
|
+
|| new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
|
174
231
|
}
|
|
175
232
|
};
|
|
176
233
|
ev.on('connection.update', closeListener);
|
|
@@ -180,21 +237,35 @@ export function bindWaitForEvent(ev, event) {
|
|
|
180
237
|
}
|
|
181
238
|
};
|
|
182
239
|
ev.on(event, listener);
|
|
183
|
-
})
|
|
240
|
+
})
|
|
241
|
+
.finally(() => {
|
|
184
242
|
ev.off(event, listener);
|
|
185
243
|
ev.off('connection.update', closeListener);
|
|
186
|
-
});
|
|
244
|
+
}));
|
|
187
245
|
};
|
|
188
246
|
}
|
|
189
|
-
|
|
247
|
+
const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
|
|
248
|
+
exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
|
|
249
|
+
const printQRIfNecessaryListener = (ev, logger) => {
|
|
250
|
+
ev.on('connection.update', async ({ qr }) => {
|
|
251
|
+
if (qr) {
|
|
252
|
+
const QR = await Promise.resolve().then(() => __importStar(require('qrcode-terminal'))).then(m => m.default || m)
|
|
253
|
+
.catch(() => {
|
|
254
|
+
logger.error('QR code terminal not added as dependency');
|
|
255
|
+
});
|
|
256
|
+
QR === null || QR === void 0 ? void 0 : QR.generate(qr, { small: true });
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
|
|
190
261
|
/**
|
|
191
262
|
* utility that fetches latest baileys version from the master branch.
|
|
192
263
|
* Use to ensure your WA connection is always on the latest version
|
|
193
264
|
*/
|
|
194
|
-
|
|
265
|
+
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
195
266
|
const URL = 'https://raw.githubusercontent.com/ruhend2001/apk-dl/refs/heads/master/version.json';
|
|
196
267
|
try {
|
|
197
|
-
const result = await
|
|
268
|
+
const result = await axios_1.default.get(URL, {
|
|
198
269
|
...options,
|
|
199
270
|
responseType: 'json'
|
|
200
271
|
});
|
|
@@ -205,27 +276,28 @@ export const fetchLatestBaileysVersion = async (options = {}) => {
|
|
|
205
276
|
}
|
|
206
277
|
catch (error) {
|
|
207
278
|
return {
|
|
208
|
-
version:
|
|
279
|
+
version: baileys_version_json_1.version,
|
|
209
280
|
isLatest: false,
|
|
210
281
|
error
|
|
211
282
|
};
|
|
212
283
|
}
|
|
213
284
|
};
|
|
285
|
+
exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
|
214
286
|
/**
|
|
215
287
|
* A utility that fetches the latest web version of whatsapp.
|
|
216
288
|
* Use to ensure your WA connection is always on the latest version
|
|
217
289
|
*/
|
|
218
|
-
|
|
290
|
+
const fetchLatestWaWebVersion = async (options) => {
|
|
219
291
|
try {
|
|
220
|
-
const { data } = await
|
|
292
|
+
const { data } = await axios_1.default.get('https://web.whatsapp.com/sw.js', {
|
|
221
293
|
...options,
|
|
222
294
|
responseType: 'json'
|
|
223
295
|
});
|
|
224
296
|
const regex = /\\?"client_revision\\?":\s*(\d+)/;
|
|
225
297
|
const match = data.match(regex);
|
|
226
|
-
if (!match
|
|
298
|
+
if (!(match === null || match === void 0 ? void 0 : match[1])) {
|
|
227
299
|
return {
|
|
228
|
-
version:
|
|
300
|
+
version: baileys_version_json_1.version,
|
|
229
301
|
isLatest: false,
|
|
230
302
|
error: {
|
|
231
303
|
message: 'Could not find client revision in the fetched content'
|
|
@@ -240,46 +312,49 @@ export const fetchLatestWaWebVersion = async (options) => {
|
|
|
240
312
|
}
|
|
241
313
|
catch (error) {
|
|
242
314
|
return {
|
|
243
|
-
version:
|
|
315
|
+
version: baileys_version_json_1.version,
|
|
244
316
|
isLatest: false,
|
|
245
317
|
error
|
|
246
318
|
};
|
|
247
319
|
}
|
|
248
320
|
};
|
|
321
|
+
exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
|
|
249
322
|
/** unique message tag prefix for MD clients */
|
|
250
|
-
|
|
251
|
-
const bytes = randomBytes(4);
|
|
323
|
+
const generateMdTagPrefix = () => {
|
|
324
|
+
const bytes = (0, crypto_1.randomBytes)(4);
|
|
252
325
|
return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`;
|
|
253
326
|
};
|
|
327
|
+
exports.generateMdTagPrefix = generateMdTagPrefix;
|
|
254
328
|
const STATUS_MAP = {
|
|
255
|
-
sender: proto.WebMessageInfo.Status.SERVER_ACK,
|
|
256
|
-
played: proto.WebMessageInfo.Status.PLAYED,
|
|
257
|
-
read: proto.WebMessageInfo.Status.READ,
|
|
258
|
-
'read-self': proto.WebMessageInfo.Status.READ
|
|
329
|
+
'sender': WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK,
|
|
330
|
+
'played': WAProto_1.proto.WebMessageInfo.Status.PLAYED,
|
|
331
|
+
'read': WAProto_1.proto.WebMessageInfo.Status.READ,
|
|
332
|
+
'read-self': WAProto_1.proto.WebMessageInfo.Status.READ
|
|
259
333
|
};
|
|
260
334
|
/**
|
|
261
335
|
* Given a type of receipt, returns what the new status of the message should be
|
|
262
336
|
* @param type type from receipt
|
|
263
337
|
*/
|
|
264
|
-
|
|
338
|
+
const getStatusFromReceiptType = (type) => {
|
|
265
339
|
const status = STATUS_MAP[type];
|
|
266
340
|
if (typeof type === 'undefined') {
|
|
267
|
-
return proto.WebMessageInfo.Status.DELIVERY_ACK;
|
|
341
|
+
return WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK;
|
|
268
342
|
}
|
|
269
343
|
return status;
|
|
270
344
|
};
|
|
345
|
+
exports.getStatusFromReceiptType = getStatusFromReceiptType;
|
|
271
346
|
const CODE_MAP = {
|
|
272
|
-
conflict: DisconnectReason.connectionReplaced
|
|
347
|
+
conflict: Types_1.DisconnectReason.connectionReplaced
|
|
273
348
|
};
|
|
274
349
|
/**
|
|
275
350
|
* Stream errors generally provide a reason, map that to a baileys DisconnectReason
|
|
276
351
|
* @param reason the string reason given, eg. "conflict"
|
|
277
352
|
*/
|
|
278
|
-
|
|
279
|
-
const [reasonNode] = getAllBinaryNodeChildren(node);
|
|
280
|
-
let reason = reasonNode
|
|
281
|
-
const statusCode = +(node.attrs.code || CODE_MAP[reason] || DisconnectReason.badSession);
|
|
282
|
-
if (statusCode === DisconnectReason.restartRequired) {
|
|
353
|
+
const getErrorCodeFromStreamError = (node) => {
|
|
354
|
+
const [reasonNode] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
|
|
355
|
+
let reason = (reasonNode === null || reasonNode === void 0 ? void 0 : reasonNode.tag) || 'unknown';
|
|
356
|
+
const statusCode = +(node.attrs.code || CODE_MAP[reason] || Types_1.DisconnectReason.badSession);
|
|
357
|
+
if (statusCode === Types_1.DisconnectReason.restartRequired) {
|
|
283
358
|
reason = 'restart required';
|
|
284
359
|
}
|
|
285
360
|
return {
|
|
@@ -287,7 +362,8 @@ export const getErrorCodeFromStreamError = (node) => {
|
|
|
287
362
|
statusCode
|
|
288
363
|
};
|
|
289
364
|
};
|
|
290
|
-
|
|
365
|
+
exports.getErrorCodeFromStreamError = getErrorCodeFromStreamError;
|
|
366
|
+
const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
291
367
|
let status;
|
|
292
368
|
switch (tag) {
|
|
293
369
|
case 'offer':
|
|
@@ -299,7 +375,7 @@ export const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
|
299
375
|
status = 'timeout';
|
|
300
376
|
}
|
|
301
377
|
else {
|
|
302
|
-
//fired when accepted/rejected/timeout/caller hangs up
|
|
378
|
+
// fired when accepted/rejected/timeout/caller hangs up
|
|
303
379
|
status = 'terminate';
|
|
304
380
|
}
|
|
305
381
|
break;
|
|
@@ -315,33 +391,33 @@ export const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
|
315
391
|
}
|
|
316
392
|
return status;
|
|
317
393
|
};
|
|
394
|
+
exports.getCallStatusFromNode = getCallStatusFromNode;
|
|
318
395
|
const UNEXPECTED_SERVER_CODE_TEXT = 'Unexpected server response: ';
|
|
319
|
-
|
|
396
|
+
const getCodeFromWSError = (error) => {
|
|
397
|
+
var _a, _b, _c;
|
|
320
398
|
let statusCode = 500;
|
|
321
|
-
if (error
|
|
322
|
-
const code = +error
|
|
399
|
+
if ((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
|
|
400
|
+
const code = +(error === null || error === void 0 ? void 0 : error.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length));
|
|
323
401
|
if (!Number.isNaN(code) && code >= 400) {
|
|
324
402
|
statusCode = code;
|
|
325
403
|
}
|
|
326
404
|
}
|
|
327
|
-
else if (
|
|
328
|
-
|
|
329
|
-
error?.code?.startsWith('E') ||
|
|
330
|
-
error?.message?.includes('timed out')) {
|
|
331
|
-
// handle ETIMEOUT, ENOTFOUND etc
|
|
405
|
+
else if (((_b = error === null || error === void 0 ? void 0 : error.code) === null || _b === void 0 ? void 0 : _b.startsWith('E'))
|
|
406
|
+
|| ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('timed out'))) { // handle ETIMEOUT, ENOTFOUND etc
|
|
332
407
|
statusCode = 408;
|
|
333
408
|
}
|
|
334
409
|
return statusCode;
|
|
335
410
|
};
|
|
411
|
+
exports.getCodeFromWSError = getCodeFromWSError;
|
|
336
412
|
/**
|
|
337
413
|
* Is the given platform WA business
|
|
338
414
|
* @param platform AuthenticationCreds.platform
|
|
339
415
|
*/
|
|
340
|
-
|
|
416
|
+
const isWABusinessPlatform = (platform) => {
|
|
341
417
|
return platform === 'smbi' || platform === 'smba';
|
|
342
418
|
};
|
|
343
|
-
|
|
344
|
-
|
|
419
|
+
exports.isWABusinessPlatform = isWABusinessPlatform;
|
|
420
|
+
function trimUndefined(obj) {
|
|
345
421
|
for (const key in obj) {
|
|
346
422
|
if (typeof obj[key] === 'undefined') {
|
|
347
423
|
delete obj[key];
|
|
@@ -350,12 +426,12 @@ export function trimUndefined(obj) {
|
|
|
350
426
|
return obj;
|
|
351
427
|
}
|
|
352
428
|
const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
|
|
353
|
-
|
|
429
|
+
function bytesToCrockford(buffer) {
|
|
354
430
|
let value = 0;
|
|
355
431
|
let bitCount = 0;
|
|
356
432
|
const crockford = [];
|
|
357
|
-
for (
|
|
358
|
-
value = (value << 8) | (
|
|
433
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
434
|
+
value = (value << 8) | (buffer[i] & 0xff);
|
|
359
435
|
bitCount += 8;
|
|
360
436
|
while (bitCount >= 5) {
|
|
361
437
|
crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
|
|
@@ -367,7 +443,3 @@ export function bytesToCrockford(buffer) {
|
|
|
367
443
|
}
|
|
368
444
|
return crockford.join('');
|
|
369
445
|
}
|
|
370
|
-
export function encodeNewsletterMessage(message) {
|
|
371
|
-
return proto.Message.encode(message).finish();
|
|
372
|
-
}
|
|
373
|
-
//# sourceMappingURL=generics.js.map
|
package/lib/Utils/history.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHistoryMsg = exports.downloadAndProcessHistorySyncNotification = exports.processHistoryMessage = exports.downloadHistory = void 0;
|
|
4
|
+
const util_1 = require("util");
|
|
5
|
+
const zlib_1 = require("zlib");
|
|
6
|
+
const WAProto_1 = require("../../WAProto");
|
|
7
|
+
const Types_1 = require("../Types");
|
|
8
|
+
const WABinary_1 = require("../WABinary");
|
|
9
|
+
const generics_1 = require("./generics");
|
|
10
|
+
const messages_1 = require("./messages");
|
|
11
|
+
const messages_media_1 = require("./messages-media");
|
|
12
|
+
const inflatePromise = (0, util_1.promisify)(zlib_1.inflate);
|
|
13
|
+
const downloadHistory = async (msg, options) => {
|
|
14
|
+
const stream = await (0, messages_media_1.downloadContentFromMessage)(msg, 'md-msg-hist', { options });
|
|
12
15
|
const bufferArray = [];
|
|
13
16
|
for await (const chunk of stream) {
|
|
14
17
|
bufferArray.push(chunk);
|
|
@@ -16,50 +19,53 @@ export const downloadHistory = async (msg, options) => {
|
|
|
16
19
|
let buffer = Buffer.concat(bufferArray);
|
|
17
20
|
// decompress buffer
|
|
18
21
|
buffer = await inflatePromise(buffer);
|
|
19
|
-
const syncData = proto.HistorySync.decode(buffer);
|
|
22
|
+
const syncData = WAProto_1.proto.HistorySync.decode(buffer);
|
|
20
23
|
return syncData;
|
|
21
24
|
};
|
|
22
|
-
|
|
25
|
+
exports.downloadHistory = downloadHistory;
|
|
26
|
+
const processHistoryMessage = (item) => {
|
|
27
|
+
var _a, _b, _c;
|
|
23
28
|
const messages = [];
|
|
24
29
|
const contacts = [];
|
|
25
30
|
const chats = [];
|
|
26
31
|
switch (item.syncType) {
|
|
27
|
-
case proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
28
|
-
case proto.HistorySync.HistorySyncType.RECENT:
|
|
29
|
-
case proto.HistorySync.HistorySyncType.FULL:
|
|
30
|
-
case proto.HistorySync.HistorySyncType.ON_DEMAND:
|
|
32
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
33
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.RECENT:
|
|
34
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
|
|
35
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
|
|
31
36
|
for (const chat of item.conversations) {
|
|
32
|
-
contacts.push({
|
|
33
|
-
id: chat.id,
|
|
34
|
-
name: chat.name || undefined,
|
|
35
|
-
lid: chat.lidJid || undefined,
|
|
36
|
-
jid: isJidUser(chat.id) ? chat.id : undefined
|
|
37
|
-
});
|
|
37
|
+
contacts.push({ id: chat.id, name: chat.name || undefined });
|
|
38
38
|
const msgs = chat.messages || [];
|
|
39
39
|
delete chat.messages;
|
|
40
|
+
delete chat.archived;
|
|
41
|
+
delete chat.muteEndTime;
|
|
42
|
+
delete chat.pinned;
|
|
40
43
|
for (const item of msgs) {
|
|
41
44
|
const message = item.message;
|
|
42
45
|
messages.push(message);
|
|
43
|
-
if (!chat.messages
|
|
46
|
+
if (!((_a = chat.messages) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
44
47
|
// keep only the most recent message in the chat array
|
|
45
48
|
chat.messages = [{ message }];
|
|
46
49
|
}
|
|
47
50
|
if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
|
|
48
|
-
chat.lastMessageRecvTimestamp = toNumber(message.messageTimestamp);
|
|
51
|
+
chat.lastMessageRecvTimestamp = (0, generics_1.toNumber)(message.messageTimestamp);
|
|
49
52
|
}
|
|
50
|
-
if ((message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP
|
|
51
|
-
message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB)
|
|
52
|
-
message.messageStubParameters
|
|
53
|
+
if ((message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP
|
|
54
|
+
|| message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB)
|
|
55
|
+
&& ((_b = message.messageStubParameters) === null || _b === void 0 ? void 0 : _b[0])) {
|
|
53
56
|
contacts.push({
|
|
54
57
|
id: message.key.participant || message.key.remoteJid,
|
|
55
|
-
verifiedName: message.messageStubParameters
|
|
58
|
+
verifiedName: (_c = message.messageStubParameters) === null || _c === void 0 ? void 0 : _c[0],
|
|
56
59
|
});
|
|
57
60
|
}
|
|
58
61
|
}
|
|
62
|
+
if ((0, WABinary_1.isJidUser)(chat.id) && chat.readOnly && chat.archived) {
|
|
63
|
+
delete chat.readOnly;
|
|
64
|
+
}
|
|
59
65
|
chats.push({ ...chat });
|
|
60
66
|
}
|
|
61
67
|
break;
|
|
62
|
-
case proto.HistorySync.HistorySyncType.PUSH_NAME:
|
|
68
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.PUSH_NAME:
|
|
63
69
|
for (const c of item.pushnames) {
|
|
64
70
|
contacts.push({ id: c.id, notify: c.pushname });
|
|
65
71
|
}
|
|
@@ -73,13 +79,16 @@ export const processHistoryMessage = (item) => {
|
|
|
73
79
|
progress: item.progress
|
|
74
80
|
};
|
|
75
81
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
82
|
+
exports.processHistoryMessage = processHistoryMessage;
|
|
83
|
+
const downloadAndProcessHistorySyncNotification = async (msg, options) => {
|
|
84
|
+
const historyMsg = await (0, exports.downloadHistory)(msg, options);
|
|
85
|
+
return (0, exports.processHistoryMessage)(historyMsg);
|
|
79
86
|
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
87
|
+
exports.downloadAndProcessHistorySyncNotification = downloadAndProcessHistorySyncNotification;
|
|
88
|
+
const getHistoryMsg = (message) => {
|
|
89
|
+
var _a;
|
|
90
|
+
const normalizedContent = !!message ? (0, messages_1.normalizeMessageContent)(message) : undefined;
|
|
91
|
+
const anyHistoryMsg = (_a = normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.protocolMessage) === null || _a === void 0 ? void 0 : _a.historySyncNotification;
|
|
83
92
|
return anyHistoryMsg;
|
|
84
93
|
};
|
|
85
|
-
|
|
94
|
+
exports.getHistoryMsg = getHistoryMsg;
|