@hbmodsofc/baileys 1.7.7 → 2.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/LICENSE +1 -1
- package/WAProto/index.js +157084 -24729
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +8 -12
- package/lib/Defaults/index.js +124 -90
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/group_cipher.d.ts +1 -0
- package/lib/Signal/Group/group_cipher.js +39 -28
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +1 -1
- package/lib/Signal/Group/sender-chain-key.js +2 -9
- package/lib/Signal/Group/sender-key-distribution-message.js +3 -3
- package/lib/Signal/Group/sender-key-message.js +3 -3
- package/lib/Signal/Group/sender-key-state.d.ts +4 -4
- package/lib/Signal/Group/sender-key-state.js +16 -47
- package/lib/Signal/libsignal.d.ts +3 -7
- package/lib/Signal/libsignal.js +39 -224
- package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +3 -1
- 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 +13 -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} +16 -10
- package/lib/Socket/business.d.ts +78 -94
- package/lib/Socket/business.js +11 -130
- package/lib/Socket/chats.d.ts +233 -63
- package/lib/Socket/chats.js +184 -234
- package/lib/Socket/groups.d.ts +41 -62
- package/lib/Socket/groups.js +64 -76
- package/lib/Socket/hbmods.d.ts +253 -0
- package/lib/Socket/hbmods.js +1 -0
- package/lib/Socket/index.d.ts +83 -129
- package/lib/Socket/index.js +6 -13
- package/lib/Socket/messages-recv.d.ts +48 -59
- package/lib/Socket/messages-recv.js +371 -516
- package/lib/Socket/messages-send.d.ts +67 -86
- package/lib/Socket/messages-send.js +1 -1091
- package/lib/Socket/newsletter.d.ts +64 -76
- package/lib/Socket/newsletter.js +1 -184
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +13 -19
- package/lib/Socket/socket.js +1 -805
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Types/Auth.d.ts +10 -4
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +9 -29
- package/lib/Types/Chat.js +1 -7
- package/lib/Types/Contact.d.ts +1 -5
- package/lib/Types/Events.d.ts +14 -55
- package/lib/Types/GroupMetadata.d.ts +5 -15
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +49 -75
- package/lib/Types/Message.js +7 -10
- package/lib/Types/Newsletter.d.ts +98 -129
- package/lib/Types/Newsletter.js +38 -33
- package/lib/Types/Product.d.ts +1 -1
- package/lib/Types/Signal.d.ts +1 -29
- package/lib/Types/Socket.d.ts +22 -48
- package/lib/Types/State.d.ts +2 -13
- package/lib/Types/State.js +0 -12
- package/lib/Types/USync.d.ts +1 -1
- package/lib/Types/index.d.ts +3 -10
- package/lib/Types/index.js +2 -2
- package/lib/Utils/auth-utils.d.ts +3 -3
- package/lib/Utils/auth-utils.js +102 -378
- package/lib/Utils/baileys-event-stream.js +1 -1
- package/lib/Utils/business.d.ts +2 -2
- package/lib/Utils/business.js +13 -19
- package/lib/Utils/chat-utils.d.ts +22 -21
- package/lib/Utils/chat-utils.js +154 -201
- package/lib/Utils/crypto.d.ts +19 -18
- package/lib/Utils/crypto.js +37 -78
- package/lib/Utils/decode-wa-message.d.ts +7 -34
- package/lib/Utils/decode-wa-message.js +66 -138
- package/lib/Utils/event-buffer.d.ts +8 -6
- package/lib/Utils/event-buffer.js +43 -81
- package/lib/Utils/generics.d.ts +27 -27
- package/lib/Utils/generics.js +133 -128
- package/lib/Utils/history.d.ts +5 -9
- package/lib/Utils/history.js +23 -17
- package/lib/Utils/index.d.ts +0 -2
- package/lib/Utils/index.js +0 -2
- package/lib/Utils/link-preview.d.ts +4 -4
- package/lib/Utils/link-preview.js +12 -40
- package/lib/Utils/logger.d.ts +3 -11
- package/lib/Utils/lt-hash.d.ts +8 -8
- package/lib/Utils/lt-hash.js +24 -23
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/make-mutex.js +2 -3
- package/lib/Utils/messages-media.d.ts +41 -37
- package/lib/Utils/messages-media.js +368 -252
- package/lib/Utils/messages.d.ts +15 -13
- package/lib/Utils/messages.js +261 -274
- package/lib/Utils/noise-handler.d.ts +15 -13
- package/lib/Utils/noise-handler.js +26 -20
- package/lib/Utils/process-message.d.ts +8 -9
- package/lib/Utils/process-message.js +93 -157
- package/lib/Utils/signal.d.ts +5 -6
- package/lib/Utils/signal.js +29 -37
- package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
- package/lib/Utils/use-multi-file-auth-state.js +7 -12
- package/lib/Utils/validate-connection.d.ts +6 -5
- package/lib/Utils/validate-connection.js +97 -39
- package/lib/WABinary/constants.d.ts +27 -24
- package/lib/WABinary/constants.js +13 -1276
- package/lib/WABinary/decode.d.ts +4 -3
- package/lib/WABinary/decode.js +14 -28
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +147 -134
- package/lib/WABinary/generic-utils.d.ts +7 -4
- package/lib/WABinary/generic-utils.js +125 -40
- package/lib/WABinary/jid-utils.d.ts +8 -13
- package/lib/WABinary/jid-utils.js +16 -27
- package/lib/WAM/BinaryInfo.d.ts +11 -2
- package/lib/WAM/constants.d.ts +2 -3
- package/lib/WAM/constants.js +2359 -2252
- package/lib/WAM/encode.d.ts +2 -1
- package/lib/WAM/encode.js +11 -8
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +4 -3
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +5 -5
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +5 -5
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +6 -5
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +3 -11
- package/lib/WAUSync/USyncQuery.d.ts +2 -2
- package/lib/WAUSync/USyncQuery.js +15 -19
- package/lib/WAUSync/USyncUser.d.ts +5 -5
- package/lib/WAUSync/index.d.ts +1 -1
- package/lib/WAUSync/index.js +1 -1
- package/package.json +102 -102
- package/lib/Signal/lid-mapping.d.ts +0 -26
- package/lib/Signal/lid-mapping.js +0 -146
- package/lib/Socket/communities.d.ts +0 -232
- package/lib/Socket/communities.js +0 -402
- package/lib/Socket/mex.d.ts +0 -2
- package/lib/Socket/mex.js +0 -45
- package/lib/Types/Bussines.d.ts +0 -24
- package/lib/Types/Bussines.js +0 -2
- package/lib/Utils/lidToJid-test.d.ts +0 -11
- package/lib/Utils/lidToJid-test.js +0 -27
- package/lib/Utils/message-retry-manager.d.ts +0 -81
- package/lib/Utils/message-retry-manager.js +0 -152
- /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
package/lib/Utils/generics.js
CHANGED
|
@@ -1,58 +1,50 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.bindWaitForConnectionUpdate = exports.generateMessageID = exports.generateMessageIDV2 = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeWAMessage = exports.
|
|
7
|
-
exports.promiseTimeout = promiseTimeout;
|
|
8
|
-
exports.bindWaitForEvent = bindWaitForEvent;
|
|
9
|
-
exports.trimUndefined = trimUndefined;
|
|
10
|
-
exports.bytesToCrockford = bytesToCrockford;
|
|
11
|
-
exports.encodeNewsletterMessage = encodeNewsletterMessage;
|
|
6
|
+
exports.bytesToCrockford = exports.trimUndefined = exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.bindWaitForEvent = exports.generateMessageID = exports.generateMessageIDV2 = exports.promiseTimeout = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.Browsers = void 0;
|
|
12
7
|
const boom_1 = require("@hapi/boom");
|
|
13
8
|
const axios_1 = __importDefault(require("axios"));
|
|
14
9
|
const crypto_1 = require("crypto");
|
|
15
10
|
const os_1 = require("os");
|
|
16
|
-
const
|
|
17
|
-
const
|
|
11
|
+
const fetch_1 = require("node-fetch")
|
|
12
|
+
const WAProto_1 = require("../../WAProto");
|
|
13
|
+
const baileys_version_json_1 = require("../Defaults/baileys-version.json");
|
|
18
14
|
const Types_1 = require("../Types");
|
|
19
15
|
const WABinary_1 = require("../WABinary");
|
|
20
|
-
const
|
|
16
|
+
const baileysVersion = [2, 3000, 1027934701]
|
|
21
17
|
const PLATFORM_MAP = {
|
|
22
|
-
aix: 'AIX',
|
|
23
|
-
darwin: 'Mac OS',
|
|
24
|
-
win32: 'Windows',
|
|
25
|
-
android: 'Android',
|
|
26
|
-
freebsd: 'FreeBSD',
|
|
27
|
-
openbsd: 'OpenBSD',
|
|
28
|
-
sunos: 'Solaris',
|
|
29
|
-
linux: undefined,
|
|
30
|
-
haiku: undefined,
|
|
31
|
-
cygwin: undefined,
|
|
32
|
-
netbsd: undefined
|
|
18
|
+
'aix': 'AIX',
|
|
19
|
+
'darwin': 'Mac OS',
|
|
20
|
+
'win32': 'Windows',
|
|
21
|
+
'android': 'Android',
|
|
22
|
+
'freebsd': 'FreeBSD',
|
|
23
|
+
'openbsd': 'OpenBSD',
|
|
24
|
+
'sunos': 'Solaris',
|
|
25
|
+
'linux': undefined,
|
|
26
|
+
'haiku': undefined,
|
|
27
|
+
'cygwin': undefined,
|
|
28
|
+
'netbsd': undefined
|
|
33
29
|
};
|
|
34
|
-
exports.Browsers = {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
windows: browser => ['Windows', browser, '10.0.22631'],
|
|
39
|
-
/** The appropriate browser based on your OS & release */
|
|
40
|
-
appropriate: browser => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
|
|
30
|
+
exports.Browsers = (browser) => {
|
|
31
|
+
const osName = PLATFORM_MAP[os_1.platform()] || 'Ubuntu';
|
|
32
|
+
const osRelease = os_1.release();
|
|
33
|
+
return [osName, browser, osRelease];
|
|
41
34
|
};
|
|
35
|
+
|
|
42
36
|
const getPlatformId = (browser) => {
|
|
43
|
-
const platformType =
|
|
37
|
+
const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
44
38
|
return platformType ? platformType.toString() : '1'; //chrome
|
|
45
39
|
};
|
|
46
40
|
exports.getPlatformId = getPlatformId;
|
|
47
41
|
exports.BufferJSON = {
|
|
48
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
42
|
replacer: (k, value) => {
|
|
50
|
-
if (Buffer.isBuffer(value) || value instanceof Uint8Array || value
|
|
51
|
-
return { type: 'Buffer', data: Buffer.from(value
|
|
43
|
+
if (Buffer.isBuffer(value) || value instanceof Uint8Array || (value === null || value === void 0 ? void 0 : value.type) === 'Buffer') {
|
|
44
|
+
return { type: 'Buffer', data: Buffer.from((value === null || value === void 0 ? void 0 : value.data) || value).toString('base64') };
|
|
52
45
|
}
|
|
53
46
|
return value;
|
|
54
47
|
},
|
|
55
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
48
|
reviver: (_, value) => {
|
|
57
49
|
if (typeof value === 'object' && !!value && (value.buffer === true || value.type === 'Buffer')) {
|
|
58
50
|
const val = value.data || value.value;
|
|
@@ -61,12 +53,15 @@ exports.BufferJSON = {
|
|
|
61
53
|
return value;
|
|
62
54
|
}
|
|
63
55
|
};
|
|
64
|
-
const getKeyAuthor = (key, meId = 'me') => (key
|
|
56
|
+
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)) || '');
|
|
65
57
|
exports.getKeyAuthor = getKeyAuthor;
|
|
66
58
|
const writeRandomPadMax16 = (msg) => {
|
|
67
59
|
const pad = (0, crypto_1.randomBytes)(1);
|
|
68
|
-
|
|
69
|
-
|
|
60
|
+
pad[0] &= 0xf;
|
|
61
|
+
if (!pad[0]) {
|
|
62
|
+
pad[0] = 0xf;
|
|
63
|
+
}
|
|
64
|
+
return Buffer.concat([msg, Buffer.alloc(pad[0], pad[0])]);
|
|
70
65
|
};
|
|
71
66
|
exports.writeRandomPadMax16 = writeRandomPadMax16;
|
|
72
67
|
const unpadRandomMax16 = (e) => {
|
|
@@ -81,14 +76,7 @@ const unpadRandomMax16 = (e) => {
|
|
|
81
76
|
return new Uint8Array(t.buffer, t.byteOffset, t.length - r);
|
|
82
77
|
};
|
|
83
78
|
exports.unpadRandomMax16 = unpadRandomMax16;
|
|
84
|
-
|
|
85
|
-
const generateParticipantHashV2 = (participants) => {
|
|
86
|
-
participants.sort();
|
|
87
|
-
const sha256Hash = (0, crypto_2.sha256)(Buffer.from(participants.join(''))).toString('base64');
|
|
88
|
-
return '2:' + sha256Hash.slice(0, 6);
|
|
89
|
-
};
|
|
90
|
-
exports.generateParticipantHashV2 = generateParticipantHashV2;
|
|
91
|
-
const encodeWAMessage = (message) => (0, exports.writeRandomPadMax16)(index_js_1.proto.Message.encode(message).finish());
|
|
79
|
+
const encodeWAMessage = (message) => ((0, exports.writeRandomPadMax16)(WAProto_1.proto.Message.encode(message).finish()));
|
|
92
80
|
exports.encodeWAMessage = encodeWAMessage;
|
|
93
81
|
const generateRegistrationId = () => {
|
|
94
82
|
return Uint16Array.from((0, crypto_1.randomBytes)(2))[0] & 16383;
|
|
@@ -104,7 +92,7 @@ const encodeBigEndian = (e, t = 4) => {
|
|
|
104
92
|
return a;
|
|
105
93
|
};
|
|
106
94
|
exports.encodeBigEndian = encodeBigEndian;
|
|
107
|
-
const toNumber = (t) => typeof t === 'object' && t ? ('toNumber' in t ? t.toNumber() : t.low) : t
|
|
95
|
+
const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t);
|
|
108
96
|
exports.toNumber = toNumber;
|
|
109
97
|
/** unix timestamp of a date in seconds */
|
|
110
98
|
const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
|
|
@@ -116,14 +104,14 @@ const debouncedTimeout = (intervalMs = 1000, task) => {
|
|
|
116
104
|
task = newTask || task;
|
|
117
105
|
intervalMs = newIntervalMs || intervalMs;
|
|
118
106
|
timeout && clearTimeout(timeout);
|
|
119
|
-
timeout = setTimeout(() => task
|
|
107
|
+
timeout = setTimeout(() => task === null || task === void 0 ? void 0 : task(), intervalMs);
|
|
120
108
|
},
|
|
121
109
|
cancel: () => {
|
|
122
110
|
timeout && clearTimeout(timeout);
|
|
123
111
|
timeout = undefined;
|
|
124
112
|
},
|
|
125
|
-
setTask: (newTask) =>
|
|
126
|
-
setInterval: (newInterval) =>
|
|
113
|
+
setTask: (newTask) => task = newTask,
|
|
114
|
+
setInterval: (newInterval) => intervalMs = newInterval
|
|
127
115
|
};
|
|
128
116
|
};
|
|
129
117
|
exports.debouncedTimeout = debouncedTimeout;
|
|
@@ -166,17 +154,17 @@ async function promiseTimeout(ms, promise) {
|
|
|
166
154
|
})))
|
|
167
155
|
.catch(err => reject(err));
|
|
168
156
|
promise(resolve, reject);
|
|
169
|
-
})
|
|
157
|
+
})
|
|
158
|
+
.finally(cancel);
|
|
170
159
|
return p;
|
|
171
160
|
}
|
|
172
|
-
|
|
173
|
-
// https://github.com/tulir/whatsmeow/blob/64bc969fbe78d31ae0dd443b8d4c80a5d026d07a/send.go#L42
|
|
161
|
+
exports.promiseTimeout = promiseTimeout;
|
|
174
162
|
const generateMessageIDV2 = (userId) => {
|
|
175
163
|
const data = Buffer.alloc(8 + 20 + 16);
|
|
176
164
|
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
|
|
177
165
|
if (userId) {
|
|
178
166
|
const id = (0, WABinary_1.jidDecode)(userId);
|
|
179
|
-
if (id
|
|
167
|
+
if (id === null || id === void 0 ? void 0 : id.user) {
|
|
180
168
|
data.write(id.user, 8);
|
|
181
169
|
data.write('@c.us', 8 + id.user.length);
|
|
182
170
|
}
|
|
@@ -188,104 +176,123 @@ const generateMessageIDV2 = (userId) => {
|
|
|
188
176
|
};
|
|
189
177
|
exports.generateMessageIDV2 = generateMessageIDV2;
|
|
190
178
|
// generate a random ID to attach to a message
|
|
191
|
-
const generateMessageID = () => '
|
|
179
|
+
const generateMessageID = () => 'ILSYM-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
|
|
192
180
|
exports.generateMessageID = generateMessageID;
|
|
193
181
|
function bindWaitForEvent(ev, event) {
|
|
194
182
|
return async (check, timeoutMs) => {
|
|
195
183
|
let listener;
|
|
196
184
|
let closeListener;
|
|
197
|
-
await promiseTimeout(timeoutMs, (resolve, reject) => {
|
|
185
|
+
await (promiseTimeout(timeoutMs, (resolve, reject) => {
|
|
198
186
|
closeListener = ({ connection, lastDisconnect }) => {
|
|
199
187
|
if (connection === 'close') {
|
|
200
|
-
reject(lastDisconnect
|
|
188
|
+
reject((lastDisconnect === null || lastDisconnect === void 0 ? void 0 : lastDisconnect.error)
|
|
189
|
+
|| new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
|
201
190
|
}
|
|
202
191
|
};
|
|
203
192
|
ev.on('connection.update', closeListener);
|
|
204
|
-
listener =
|
|
205
|
-
if (
|
|
193
|
+
listener = (update) => {
|
|
194
|
+
if (check(update)) {
|
|
206
195
|
resolve();
|
|
207
196
|
}
|
|
208
197
|
};
|
|
209
198
|
ev.on(event, listener);
|
|
210
|
-
})
|
|
199
|
+
})
|
|
200
|
+
.finally(() => {
|
|
211
201
|
ev.off(event, listener);
|
|
212
202
|
ev.off('connection.update', closeListener);
|
|
213
|
-
});
|
|
203
|
+
}));
|
|
214
204
|
};
|
|
215
205
|
}
|
|
206
|
+
exports.bindWaitForEvent = bindWaitForEvent;
|
|
216
207
|
const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
|
|
217
208
|
exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
|
|
209
|
+
const printQRIfNecessaryListener = (ev, logger) => {
|
|
210
|
+
ev.on('connection.update', async ({ qr }) => {
|
|
211
|
+
if (qr) {
|
|
212
|
+
const QR = await import('qrcode-terminal')
|
|
213
|
+
.then(m => m.default || m)
|
|
214
|
+
.catch(() => {
|
|
215
|
+
logger.error('QR code terminal not added as dependency');
|
|
216
|
+
});
|
|
217
|
+
QR === null || QR === void 0 ? void 0 : QR.generate(qr, { small: true });
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
};
|
|
221
|
+
exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
|
|
218
222
|
/**
|
|
219
223
|
* utility that fetches latest baileys version from the master branch.
|
|
220
224
|
* Use to ensure your WA connection is always on the latest version
|
|
221
225
|
*/
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
|
|
226
|
+
const fetchLatestWaWebVersion = async (options = {}) => {
|
|
227
|
+
try {
|
|
228
|
+
const defaultHeaders = {
|
|
229
|
+
'User-Agent':
|
|
230
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
|
231
|
+
'Accept': '*/*'
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const headers = { ...defaultHeaders, ...options.headers }
|
|
235
|
+
|
|
236
|
+
const response = await fetch_1('https://web.whatsapp.com/sw.js', {
|
|
237
|
+
method: 'GET',
|
|
238
|
+
headers
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
if (!response.ok) {
|
|
242
|
+
throw new Error(`Failed to fetch sw.js: ${response.status} ${response.statusText}`)
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const data = await response.text()
|
|
246
|
+
const regex = /"client_revision":\s*(\d+)/ // regex cukup begini untuk Node
|
|
247
|
+
const match = data.match(regex)
|
|
248
|
+
|
|
249
|
+
if (!match || !match[1]) {
|
|
250
|
+
return {
|
|
251
|
+
version: baileysVersion,
|
|
252
|
+
isLatest: false,
|
|
253
|
+
error: { message: 'Client revision not found' }
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const clientRevision = match[1]
|
|
258
|
+
return {
|
|
259
|
+
version: [2, 3000, +clientRevision],
|
|
260
|
+
isLatest: true
|
|
261
|
+
}
|
|
262
|
+
} catch (error) {
|
|
263
|
+
return {
|
|
264
|
+
version: baileysVersion,
|
|
265
|
+
isLatest: false,
|
|
266
|
+
error
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
|
|
253
271
|
/**
|
|
254
|
-
*
|
|
272
|
+
* utility that fetches latest baileys version from the master branch.
|
|
255
273
|
* Use to ensure your WA connection is always on the latest version
|
|
256
274
|
*/
|
|
257
|
-
const
|
|
275
|
+
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
276
|
+
const URL = 'https://raw.githubusercontent.com/kiuur/bails/master/src/Defaults/baileys-version.json';
|
|
258
277
|
try {
|
|
259
|
-
const
|
|
278
|
+
const result = await axios_1.default.get(URL, {
|
|
260
279
|
...options,
|
|
261
280
|
responseType: 'json'
|
|
262
281
|
});
|
|
263
|
-
const regex = /\\?"client_revision\\?":\s*(\d+)/;
|
|
264
|
-
const match = data.match(regex);
|
|
265
|
-
if (!match?.[1]) {
|
|
266
|
-
return {
|
|
267
|
-
version: baileysVersion,
|
|
268
|
-
isLatest: false,
|
|
269
|
-
error: {
|
|
270
|
-
message: 'Could not find client revision in the fetched content'
|
|
271
|
-
}
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
const clientRevision = match[1];
|
|
275
282
|
return {
|
|
276
|
-
version:
|
|
283
|
+
version: result.data.version,
|
|
277
284
|
isLatest: true
|
|
278
285
|
};
|
|
279
286
|
}
|
|
280
287
|
catch (error) {
|
|
281
288
|
return {
|
|
282
|
-
version:
|
|
289
|
+
version: baileys_version_json_1.version,
|
|
283
290
|
isLatest: false,
|
|
284
291
|
error
|
|
285
292
|
};
|
|
286
293
|
}
|
|
287
294
|
};
|
|
288
|
-
exports.
|
|
295
|
+
exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
|
289
296
|
/** unique message tag prefix for MD clients */
|
|
290
297
|
const generateMdTagPrefix = () => {
|
|
291
298
|
const bytes = (0, crypto_1.randomBytes)(4);
|
|
@@ -293,10 +300,9 @@ const generateMdTagPrefix = () => {
|
|
|
293
300
|
};
|
|
294
301
|
exports.generateMdTagPrefix = generateMdTagPrefix;
|
|
295
302
|
const STATUS_MAP = {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
read:
|
|
299
|
-
'read-self': index_js_1.proto.WebMessageInfo.Status.READ
|
|
303
|
+
'played': WAProto_1.proto.WebMessageInfo.Status.PLAYED,
|
|
304
|
+
'read': WAProto_1.proto.WebMessageInfo.Status.READ,
|
|
305
|
+
'read-self': WAProto_1.proto.WebMessageInfo.Status.READ
|
|
300
306
|
};
|
|
301
307
|
/**
|
|
302
308
|
* Given a type of receipt, returns what the new status of the message should be
|
|
@@ -305,7 +311,7 @@ const STATUS_MAP = {
|
|
|
305
311
|
const getStatusFromReceiptType = (type) => {
|
|
306
312
|
const status = STATUS_MAP[type];
|
|
307
313
|
if (typeof type === 'undefined') {
|
|
308
|
-
return
|
|
314
|
+
return WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK;
|
|
309
315
|
}
|
|
310
316
|
return status;
|
|
311
317
|
};
|
|
@@ -319,7 +325,7 @@ const CODE_MAP = {
|
|
|
319
325
|
*/
|
|
320
326
|
const getErrorCodeFromStreamError = (node) => {
|
|
321
327
|
const [reasonNode] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
|
|
322
|
-
let reason = reasonNode
|
|
328
|
+
let reason = (reasonNode === null || reasonNode === void 0 ? void 0 : reasonNode.tag) || 'unknown';
|
|
323
329
|
const statusCode = +(node.attrs.code || CODE_MAP[reason] || Types_1.DisconnectReason.badSession);
|
|
324
330
|
if (statusCode === Types_1.DisconnectReason.restartRequired) {
|
|
325
331
|
reason = 'restart required';
|
|
@@ -342,8 +348,7 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
|
342
348
|
status = 'timeout';
|
|
343
349
|
}
|
|
344
350
|
else {
|
|
345
|
-
|
|
346
|
-
status = 'terminate';
|
|
351
|
+
status = 'reject';
|
|
347
352
|
}
|
|
348
353
|
break;
|
|
349
354
|
case 'reject':
|
|
@@ -361,18 +366,16 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
|
361
366
|
exports.getCallStatusFromNode = getCallStatusFromNode;
|
|
362
367
|
const UNEXPECTED_SERVER_CODE_TEXT = 'Unexpected server response: ';
|
|
363
368
|
const getCodeFromWSError = (error) => {
|
|
369
|
+
var _a, _b, _c;
|
|
364
370
|
let statusCode = 500;
|
|
365
|
-
if (error
|
|
366
|
-
const code = +error
|
|
371
|
+
if ((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
|
|
372
|
+
const code = +(error === null || error === void 0 ? void 0 : error.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length));
|
|
367
373
|
if (!Number.isNaN(code) && code >= 400) {
|
|
368
374
|
statusCode = code;
|
|
369
375
|
}
|
|
370
376
|
}
|
|
371
|
-
else if (
|
|
372
|
-
|
|
373
|
-
error?.code?.startsWith('E') ||
|
|
374
|
-
error?.message?.includes('timed out')) {
|
|
375
|
-
// handle ETIMEOUT, ENOTFOUND etc
|
|
377
|
+
else if (((_b = error === null || error === void 0 ? void 0 : error.code) === null || _b === void 0 ? void 0 : _b.startsWith('E'))
|
|
378
|
+
|| ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('timed out'))) { // handle ETIMEOUT, ENOTFOUND etc
|
|
376
379
|
statusCode = 408;
|
|
377
380
|
}
|
|
378
381
|
return statusCode;
|
|
@@ -386,7 +389,6 @@ const isWABusinessPlatform = (platform) => {
|
|
|
386
389
|
return platform === 'smbi' || platform === 'smba';
|
|
387
390
|
};
|
|
388
391
|
exports.isWABusinessPlatform = isWABusinessPlatform;
|
|
389
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
390
392
|
function trimUndefined(obj) {
|
|
391
393
|
for (const key in obj) {
|
|
392
394
|
if (typeof obj[key] === 'undefined') {
|
|
@@ -395,13 +397,14 @@ function trimUndefined(obj) {
|
|
|
395
397
|
}
|
|
396
398
|
return obj;
|
|
397
399
|
}
|
|
400
|
+
exports.trimUndefined = trimUndefined;
|
|
398
401
|
const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
|
|
399
402
|
function bytesToCrockford(buffer) {
|
|
400
403
|
let value = 0;
|
|
401
404
|
let bitCount = 0;
|
|
402
405
|
const crockford = [];
|
|
403
|
-
for (
|
|
404
|
-
value = (value << 8) | (
|
|
406
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
407
|
+
value = (value << 8) | (buffer[i] & 0xff);
|
|
405
408
|
bitCount += 8;
|
|
406
409
|
while (bitCount >= 5) {
|
|
407
410
|
crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
|
|
@@ -413,6 +416,8 @@ function bytesToCrockford(buffer) {
|
|
|
413
416
|
}
|
|
414
417
|
return crockford.join('');
|
|
415
418
|
}
|
|
416
|
-
|
|
417
|
-
|
|
419
|
+
exports.bytesToCrockford = bytesToCrockford;
|
|
420
|
+
const encodeNewsletterMessage = (message) => {
|
|
421
|
+
return WAProto_1.proto.Message.encode(message).finish()
|
|
418
422
|
}
|
|
423
|
+
exports.encodeNewsletterMessage = encodeNewsletterMessage;
|
package/lib/Utils/history.d.ts
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { proto } from '../../WAProto
|
|
3
|
-
import
|
|
4
|
-
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { proto } from '../../WAProto';
|
|
3
|
+
import { Chat, Contact } from '../Types';
|
|
4
|
+
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<proto.HistorySync>;
|
|
5
5
|
export declare const processHistoryMessage: (item: proto.IHistorySync) => {
|
|
6
6
|
chats: Chat[];
|
|
7
7
|
contacts: Contact[];
|
|
8
8
|
messages: proto.IWebMessageInfo[];
|
|
9
|
-
syncType: proto.HistorySync.HistorySyncType;
|
|
10
|
-
progress: number | null | undefined;
|
|
11
9
|
};
|
|
12
|
-
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<
|
|
10
|
+
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<{
|
|
13
11
|
chats: Chat[];
|
|
14
12
|
contacts: Contact[];
|
|
15
13
|
messages: proto.IWebMessageInfo[];
|
|
16
|
-
syncType: proto.HistorySync.HistorySyncType;
|
|
17
|
-
progress: number | null | undefined;
|
|
18
14
|
}>;
|
|
19
15
|
export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined;
|
package/lib/Utils/history.js
CHANGED
|
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getHistoryMsg = exports.downloadAndProcessHistorySyncNotification = exports.processHistoryMessage = exports.downloadHistory = void 0;
|
|
4
4
|
const util_1 = require("util");
|
|
5
5
|
const zlib_1 = require("zlib");
|
|
6
|
-
const
|
|
6
|
+
const WAProto_1 = require("../../WAProto");
|
|
7
7
|
const Types_1 = require("../Types");
|
|
8
|
+
const WABinary_1 = require("../WABinary");
|
|
8
9
|
const generics_1 = require("./generics");
|
|
9
10
|
const messages_1 = require("./messages");
|
|
10
11
|
const messages_media_1 = require("./messages-media");
|
|
@@ -18,51 +19,57 @@ const downloadHistory = async (msg, options) => {
|
|
|
18
19
|
let buffer = Buffer.concat(bufferArray);
|
|
19
20
|
// decompress buffer
|
|
20
21
|
buffer = await inflatePromise(buffer);
|
|
21
|
-
const syncData =
|
|
22
|
+
const syncData = WAProto_1.proto.HistorySync.decode(buffer);
|
|
22
23
|
return syncData;
|
|
23
24
|
};
|
|
24
25
|
exports.downloadHistory = downloadHistory;
|
|
25
26
|
const processHistoryMessage = (item) => {
|
|
27
|
+
var _a, _b, _c;
|
|
26
28
|
const messages = [];
|
|
27
29
|
const contacts = [];
|
|
28
30
|
const chats = [];
|
|
29
31
|
switch (item.syncType) {
|
|
30
|
-
case
|
|
31
|
-
case
|
|
32
|
-
case
|
|
33
|
-
case index_js_1.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:
|
|
34
35
|
for (const chat of item.conversations) {
|
|
35
|
-
contacts.push({
|
|
36
|
+
contacts.push({
|
|
36
37
|
id: chat.id,
|
|
37
38
|
name: chat.name || undefined,
|
|
38
39
|
lid: chat.lidJid || undefined,
|
|
39
|
-
|
|
40
|
+
jid: (0, WABinary_1.isJidUser)(chat.id) ? chat.id : undefined
|
|
40
41
|
});
|
|
41
42
|
const msgs = chat.messages || [];
|
|
42
43
|
delete chat.messages;
|
|
44
|
+
delete chat.archived;
|
|
45
|
+
delete chat.muteEndTime;
|
|
46
|
+
delete chat.pinned;
|
|
43
47
|
for (const item of msgs) {
|
|
44
48
|
const message = item.message;
|
|
45
49
|
messages.push(message);
|
|
46
|
-
if (!chat.messages
|
|
50
|
+
if (!((_a = chat.messages) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
47
51
|
// keep only the most recent message in the chat array
|
|
48
52
|
chat.messages = [{ message }];
|
|
49
53
|
}
|
|
50
54
|
if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
|
|
51
55
|
chat.lastMessageRecvTimestamp = (0, generics_1.toNumber)(message.messageTimestamp);
|
|
52
56
|
}
|
|
53
|
-
if ((message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP
|
|
54
|
-
message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB)
|
|
55
|
-
message.messageStubParameters
|
|
57
|
+
if ((message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP
|
|
58
|
+
|| message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB)
|
|
59
|
+
&& ((_b = message.messageStubParameters) === null || _b === void 0 ? void 0 : _b[0])) {
|
|
56
60
|
contacts.push({
|
|
57
61
|
id: message.key.participant || message.key.remoteJid,
|
|
58
|
-
verifiedName: message.messageStubParameters
|
|
62
|
+
verifiedName: (_c = message.messageStubParameters) === null || _c === void 0 ? void 0 : _c[0],
|
|
59
63
|
});
|
|
60
64
|
}
|
|
61
65
|
}
|
|
66
|
+
if ((0, WABinary_1.isJidUser)(chat.id) && chat.readOnly && chat.archived) {
|
|
67
|
+
delete chat.readOnly;
|
|
68
|
+
}
|
|
62
69
|
chats.push({ ...chat });
|
|
63
70
|
}
|
|
64
71
|
break;
|
|
65
|
-
case
|
|
72
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.PUSH_NAME:
|
|
66
73
|
for (const c of item.pushnames) {
|
|
67
74
|
contacts.push({ id: c.id, notify: c.pushname });
|
|
68
75
|
}
|
|
@@ -72,8 +79,6 @@ const processHistoryMessage = (item) => {
|
|
|
72
79
|
chats,
|
|
73
80
|
contacts,
|
|
74
81
|
messages,
|
|
75
|
-
syncType: item.syncType,
|
|
76
|
-
progress: item.progress
|
|
77
82
|
};
|
|
78
83
|
};
|
|
79
84
|
exports.processHistoryMessage = processHistoryMessage;
|
|
@@ -83,8 +88,9 @@ const downloadAndProcessHistorySyncNotification = async (msg, options) => {
|
|
|
83
88
|
};
|
|
84
89
|
exports.downloadAndProcessHistorySyncNotification = downloadAndProcessHistorySyncNotification;
|
|
85
90
|
const getHistoryMsg = (message) => {
|
|
91
|
+
var _a;
|
|
86
92
|
const normalizedContent = !!message ? (0, messages_1.normalizeMessageContent)(message) : undefined;
|
|
87
|
-
const anyHistoryMsg = normalizedContent
|
|
93
|
+
const anyHistoryMsg = (_a = normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.protocolMessage) === null || _a === void 0 ? void 0 : _a.historySyncNotification;
|
|
88
94
|
return anyHistoryMsg;
|
|
89
95
|
};
|
|
90
96
|
exports.getHistoryMsg = getHistoryMsg;
|
package/lib/Utils/index.d.ts
CHANGED
package/lib/Utils/index.js
CHANGED
|
@@ -31,5 +31,3 @@ __exportStar(require("./use-multi-file-auth-state"), exports);
|
|
|
31
31
|
__exportStar(require("./link-preview"), exports);
|
|
32
32
|
__exportStar(require("./event-buffer"), exports);
|
|
33
33
|
__exportStar(require("./process-message"), exports);
|
|
34
|
-
__exportStar(require("./message-retry-manager"), exports);
|
|
35
|
-
__exportStar(require("./lidToJid-test"), exports);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { Logger } from 'pino';
|
|
3
|
+
import { WAMediaUploadFunction, WAUrlInfo } from '../Types';
|
|
4
4
|
export type URLGenerationOptions = {
|
|
5
5
|
thumbnailWidth: number;
|
|
6
6
|
fetchOpts: {
|
|
@@ -10,7 +10,7 @@ export type URLGenerationOptions = {
|
|
|
10
10
|
headers?: AxiosRequestConfig<{}>['headers'];
|
|
11
11
|
};
|
|
12
12
|
uploadImage?: WAMediaUploadFunction;
|
|
13
|
-
logger?:
|
|
13
|
+
logger?: Logger;
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
16
|
* Given a piece of text, checks for any URL present, generates link preview for the same and returns it
|