@yemo-dev/yebail 1.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/EXAMPLES.md +641 -0
- package/LICENSE +21 -0
- package/README.md +141 -0
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +4775 -0
- package/WAProto/index.js +116311 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/index.js +142 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/yebail-version.json +7 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.js +29 -0
- package/lib/Signal/libsignal.js +196 -0
- package/lib/Signal/lid-mapping.js +148 -0
- package/lib/Socket/Client/index.js +18 -0
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.js +72 -0
- package/lib/Socket/business.js +368 -0
- package/lib/Socket/chats.js +992 -0
- package/lib/Socket/communities.js +430 -0
- package/lib/Socket/groups.js +323 -0
- package/lib/Socket/index.js +10 -0
- package/lib/Socket/messages-recv.js +1133 -0
- package/lib/Socket/messages-send.js +992 -0
- package/lib/Socket/newsletter.js +250 -0
- package/lib/Socket/socket.js +631 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.js +8 -0
- package/lib/Store/make-in-memory-store.js +421 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +4 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.js +7 -0
- package/lib/Types/Newsletter.js +18 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +42 -0
- package/lib/Utils/auth-utils.js +188 -0
- package/lib/Utils/browser-utils.js +35 -0
- package/lib/Utils/business.js +230 -0
- package/lib/Utils/chat-utils.js +763 -0
- package/lib/Utils/crypto.js +187 -0
- package/lib/Utils/decode-wa-message.js +293 -0
- package/lib/Utils/event-buffer.js +514 -0
- package/lib/Utils/generics.js +453 -0
- package/lib/Utils/history.js +94 -0
- package/lib/Utils/index.js +37 -0
- package/lib/Utils/link-preview.js +121 -0
- package/lib/Utils/logger.js +7 -0
- package/lib/Utils/lt-hash.js +47 -0
- package/lib/Utils/make-mutex.js +43 -0
- package/lib/Utils/message-retry-manager.js +128 -0
- package/lib/Utils/messages-media.js +910 -0
- package/lib/Utils/messages.js +1129 -0
- package/lib/Utils/noise-handler.js +150 -0
- package/lib/Utils/process-message.js +448 -0
- package/lib/Utils/signal.js +150 -0
- package/lib/Utils/use-custom-auth-state.js +110 -0
- package/lib/Utils/use-multi-file-auth-state.js +43 -0
- package/lib/Utils/use-sqlite-auth-state.js +39 -0
- package/lib/Utils/validate-connection.js +237 -0
- package/lib/Utils/yebail-event-stream.js +55 -0
- package/lib/WABinary/constants.js +1303 -0
- package/lib/WABinary/decode.js +275 -0
- package/lib/WABinary/encode.js +250 -0
- package/lib/WABinary/generic-utils.js +110 -0
- package/lib/WABinary/index.js +21 -0
- package/lib/WABinary/jid-utils.js +136 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.js +15350 -0
- package/lib/WAM/encode.js +155 -0
- package/lib/WAM/index.js +19 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.js +20 -0
- package/lib/WAUSync/USyncQuery.js +89 -0
- package/lib/WAUSync/USyncUser.js +26 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/index.js +46 -0
- package/package.json +114 -0
|
@@ -0,0 +1,453 @@
|
|
|
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.fetchLatestYebailVersion = 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 yebail_version_json_1 = require("../Defaults/yebail-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
|
+
};
|
|
59
|
+
const PLATFORM_MAP = {
|
|
60
|
+
'aix': 'AIX',
|
|
61
|
+
'darwin': 'Mac OS',
|
|
62
|
+
'win32': 'Windows',
|
|
63
|
+
'android': 'Android',
|
|
64
|
+
'freebsd': 'FreeBSD',
|
|
65
|
+
'openbsd': 'OpenBSD',
|
|
66
|
+
'sunos': 'Solaris'
|
|
67
|
+
};
|
|
68
|
+
exports.Browsers = {
|
|
69
|
+
ubuntu: (browser) => ['Ubuntu', browser, '22.04.4'],
|
|
70
|
+
macOS: (browser) => ['Mac OS', browser, '14.4.1'],
|
|
71
|
+
yebail: (browser) => ['Yebail', browser, '6.5.0'],
|
|
72
|
+
windows: (browser) => ['Windows', browser, '10.0.22631'],
|
|
73
|
+
|
|
74
|
+
appropriate: (browser) => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
|
|
75
|
+
};
|
|
76
|
+
const getPlatformId = (browser) => {
|
|
77
|
+
const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
78
|
+
return platformType ? platformType.toString() : '49'; //chrome
|
|
79
|
+
};
|
|
80
|
+
exports.getPlatformId = getPlatformId;
|
|
81
|
+
exports.BufferJSON = {
|
|
82
|
+
replacer: (k, 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') };
|
|
85
|
+
}
|
|
86
|
+
return value;
|
|
87
|
+
},
|
|
88
|
+
reviver: (_, value) => {
|
|
89
|
+
if (typeof value === 'object' && !!value && (value.buffer === true || value.type === 'Buffer')) {
|
|
90
|
+
const val = value.data || value.value;
|
|
91
|
+
return typeof val === 'string' ? Buffer.from(val, 'base64') : Buffer.from(val || []);
|
|
92
|
+
}
|
|
93
|
+
return value;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
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]) {
|
|
102
|
+
pad[0] = 0xf;
|
|
103
|
+
}
|
|
104
|
+
return Buffer.concat([msg, Buffer.alloc(pad[0], pad[0])]);
|
|
105
|
+
};
|
|
106
|
+
exports.writeRandomPadMax16 = writeRandomPadMax16;
|
|
107
|
+
const unpadRandomMax16 = (e) => {
|
|
108
|
+
const t = new Uint8Array(e);
|
|
109
|
+
if (0 === t.length) {
|
|
110
|
+
throw new Error('unpadPkcs7 given empty bytes');
|
|
111
|
+
}
|
|
112
|
+
var r = t[t.length - 1];
|
|
113
|
+
if (r > t.length) {
|
|
114
|
+
throw new Error(`unpad given ${t.length} bytes, but pad is ${r}`);
|
|
115
|
+
}
|
|
116
|
+
return new Uint8Array(t.buffer, t.byteOffset, t.length - r);
|
|
117
|
+
};
|
|
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;
|
|
125
|
+
};
|
|
126
|
+
exports.generateRegistrationId = generateRegistrationId;
|
|
127
|
+
const encodeBigEndian = (e, t = 4) => {
|
|
128
|
+
let r = e;
|
|
129
|
+
const a = new Uint8Array(t);
|
|
130
|
+
for (let i = t - 1; i >= 0; i--) {
|
|
131
|
+
a[i] = 255 & r;
|
|
132
|
+
r >>>= 8;
|
|
133
|
+
}
|
|
134
|
+
return a;
|
|
135
|
+
};
|
|
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;
|
|
139
|
+
|
|
140
|
+
const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
|
|
141
|
+
exports.unixTimestampSeconds = unixTimestampSeconds;
|
|
142
|
+
const debouncedTimeout = (intervalMs = 1000, task) => {
|
|
143
|
+
let timeout;
|
|
144
|
+
return {
|
|
145
|
+
start: (newIntervalMs, newTask) => {
|
|
146
|
+
task = newTask || task;
|
|
147
|
+
intervalMs = newIntervalMs || intervalMs;
|
|
148
|
+
timeout && clearTimeout(timeout);
|
|
149
|
+
timeout = setTimeout(() => task === null || task === void 0 ? void 0 : task(), intervalMs);
|
|
150
|
+
},
|
|
151
|
+
cancel: () => {
|
|
152
|
+
timeout && clearTimeout(timeout);
|
|
153
|
+
timeout = undefined;
|
|
154
|
+
},
|
|
155
|
+
setTask: (newTask) => task = newTask,
|
|
156
|
+
setInterval: (newInterval) => intervalMs = newInterval
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
exports.debouncedTimeout = debouncedTimeout;
|
|
160
|
+
const delay = (ms) => (0, exports.delayCancellable)(ms).delay;
|
|
161
|
+
exports.delay = delay;
|
|
162
|
+
const delayCancellable = (ms) => {
|
|
163
|
+
const stack = new Error().stack;
|
|
164
|
+
let timeout;
|
|
165
|
+
let reject;
|
|
166
|
+
const delay = new Promise((resolve, _reject) => {
|
|
167
|
+
timeout = setTimeout(resolve, ms);
|
|
168
|
+
reject = _reject;
|
|
169
|
+
});
|
|
170
|
+
const cancel = () => {
|
|
171
|
+
clearTimeout(timeout);
|
|
172
|
+
reject(new boom_1.Boom('Cancelled', {
|
|
173
|
+
statusCode: 500,
|
|
174
|
+
data: {
|
|
175
|
+
stack
|
|
176
|
+
}
|
|
177
|
+
}));
|
|
178
|
+
};
|
|
179
|
+
return { delay, cancel };
|
|
180
|
+
};
|
|
181
|
+
exports.delayCancellable = delayCancellable;
|
|
182
|
+
async function promiseTimeout(ms, promise) {
|
|
183
|
+
if (!ms) {
|
|
184
|
+
return new Promise(promise);
|
|
185
|
+
}
|
|
186
|
+
const stack = new Error().stack;
|
|
187
|
+
// Create a promise that rejects in <ms> milliseconds
|
|
188
|
+
const { delay, cancel } = (0, exports.delayCancellable)(ms);
|
|
189
|
+
const p = new Promise((resolve, reject) => {
|
|
190
|
+
delay
|
|
191
|
+
.then(() => reject(new boom_1.Boom('Timed Out', {
|
|
192
|
+
statusCode: Types_1.DisconnectReason.timedOut,
|
|
193
|
+
data: {
|
|
194
|
+
stack
|
|
195
|
+
}
|
|
196
|
+
})))
|
|
197
|
+
.catch(err => reject(err));
|
|
198
|
+
promise(resolve, reject);
|
|
199
|
+
})
|
|
200
|
+
.finally(cancel);
|
|
201
|
+
return p;
|
|
202
|
+
}
|
|
203
|
+
const generateMessageIDV2 = (userId) => {
|
|
204
|
+
const data = Buffer.alloc(8 + 20 + 16);
|
|
205
|
+
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
|
|
206
|
+
if (userId) {
|
|
207
|
+
const id = (0, WABinary_1.jidDecode)(userId);
|
|
208
|
+
if (id === null || id === void 0 ? void 0 : id.user) {
|
|
209
|
+
data.write(id.user, 8);
|
|
210
|
+
data.write('@c.us', 8 + id.user.length);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
const random = (0, crypto_1.randomBytes)(16);
|
|
214
|
+
random.copy(data, 28);
|
|
215
|
+
const hash = (0, crypto_1.createHash)('sha256').update(data).digest();
|
|
216
|
+
return '3EB0' + hash.toString('hex').toUpperCase().substring(0, 18);
|
|
217
|
+
};
|
|
218
|
+
exports.generateMessageIDV2 = generateMessageIDV2;
|
|
219
|
+
// generate a random ID to attach to a message
|
|
220
|
+
const generateMessageID = () => '3EB0' + (0, crypto_1.randomBytes)(18).toString('hex').toUpperCase();
|
|
221
|
+
exports.generateMessageID = generateMessageID;
|
|
222
|
+
function bindWaitForEvent(ev, event) {
|
|
223
|
+
return async (check, timeoutMs) => {
|
|
224
|
+
let listener;
|
|
225
|
+
let closeListener;
|
|
226
|
+
await (promiseTimeout(timeoutMs, (resolve, reject) => {
|
|
227
|
+
closeListener = ({ connection, lastDisconnect }) => {
|
|
228
|
+
if (connection === 'close') {
|
|
229
|
+
reject((lastDisconnect === null || lastDisconnect === void 0 ? void 0 : lastDisconnect.error)
|
|
230
|
+
|| new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
ev.on('connection.update', closeListener);
|
|
234
|
+
listener = async (update) => {
|
|
235
|
+
if (await check(update)) {
|
|
236
|
+
resolve();
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
ev.on(event, listener);
|
|
240
|
+
})
|
|
241
|
+
.finally(() => {
|
|
242
|
+
ev.off(event, listener);
|
|
243
|
+
ev.off('connection.update', closeListener);
|
|
244
|
+
}));
|
|
245
|
+
};
|
|
246
|
+
}
|
|
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;
|
|
261
|
+
|
|
262
|
+
const fetchLatestYebailVersion = async (options = {}) => {
|
|
263
|
+
try {
|
|
264
|
+
const { data } = await axios_1.default.get('https://registry.npmjs.org/yebail', {
|
|
265
|
+
params: options.params,
|
|
266
|
+
timeout: options.timeout || 5000
|
|
267
|
+
});
|
|
268
|
+
return {
|
|
269
|
+
version: data['dist-tags'].latest,
|
|
270
|
+
info: data.versions[data['dist-tags'].latest]
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
catch (error) {
|
|
274
|
+
return {
|
|
275
|
+
version: yebail_version_json_1.version,
|
|
276
|
+
info: undefined
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
exports.fetchLatestYebailVersion = fetchLatestYebailVersion;
|
|
281
|
+
|
|
282
|
+
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
283
|
+
try {
|
|
284
|
+
const { data } = await axios_1.default.get('https://registry.npmjs.org/yebail', {
|
|
285
|
+
...options,
|
|
286
|
+
responseType: 'json'
|
|
287
|
+
});
|
|
288
|
+
const versionStr = data.version;
|
|
289
|
+
const [major, minor, patch] = versionStr.split('.').map(Number);
|
|
290
|
+
return {
|
|
291
|
+
version: [major, minor, patch],
|
|
292
|
+
isLatest: true
|
|
293
|
+
};
|
|
294
|
+
} catch (error) {
|
|
295
|
+
return {
|
|
296
|
+
version: yebails_version_json_1.version,
|
|
297
|
+
isLatest: false,
|
|
298
|
+
error
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
const fetchLatestWaWebVersion = async (options) => {
|
|
306
|
+
try {
|
|
307
|
+
const { data } = await axios_1.default.get('https://web.whatsapp.com/sw.js', {
|
|
308
|
+
...options,
|
|
309
|
+
responseType: 'text'
|
|
310
|
+
});
|
|
311
|
+
const regex = /"client_revision":\s*(\d+)/;
|
|
312
|
+
const match = data.match(regex);
|
|
313
|
+
if (!(match === null || match === void 0 ? void 0 : match[1])) {
|
|
314
|
+
return {
|
|
315
|
+
version: yebails_version_json_1.version,
|
|
316
|
+
isLatest: false,
|
|
317
|
+
error: {
|
|
318
|
+
message: 'Could not find client revision in the fetched content'
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
const clientRevision = match[1];
|
|
323
|
+
return {
|
|
324
|
+
version: [2, 3000, +clientRevision],
|
|
325
|
+
isLatest: true
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
catch (error) {
|
|
329
|
+
return {
|
|
330
|
+
version: yebails_version_json_1.version,
|
|
331
|
+
isLatest: false,
|
|
332
|
+
error
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
|
|
337
|
+
|
|
338
|
+
const generateMdTagPrefix = () => {
|
|
339
|
+
const bytes = (0, crypto_1.randomBytes)(4);
|
|
340
|
+
return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`;
|
|
341
|
+
};
|
|
342
|
+
exports.generateMdTagPrefix = generateMdTagPrefix;
|
|
343
|
+
const STATUS_MAP = {
|
|
344
|
+
'sender': WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK,
|
|
345
|
+
'played': WAProto_1.proto.WebMessageInfo.Status.PLAYED,
|
|
346
|
+
'read': WAProto_1.proto.WebMessageInfo.Status.READ,
|
|
347
|
+
'read-self': WAProto_1.proto.WebMessageInfo.Status.READ
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
const getStatusFromReceiptType = (type) => {
|
|
351
|
+
const status = STATUS_MAP[type];
|
|
352
|
+
if (typeof type === 'undefined') {
|
|
353
|
+
return WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK;
|
|
354
|
+
}
|
|
355
|
+
return status;
|
|
356
|
+
};
|
|
357
|
+
exports.getStatusFromReceiptType = getStatusFromReceiptType;
|
|
358
|
+
const CODE_MAP = {
|
|
359
|
+
conflict: Types_1.DisconnectReason.connectionReplaced
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
const getErrorCodeFromStreamError = (node) => {
|
|
363
|
+
const [reasonNode] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
|
|
364
|
+
let reason = (reasonNode === null || reasonNode === void 0 ? void 0 : reasonNode.tag) || 'unknown';
|
|
365
|
+
const statusCode = +(node.attrs.code || CODE_MAP[reason] || Types_1.DisconnectReason.badSession);
|
|
366
|
+
if (statusCode === Types_1.DisconnectReason.restartRequired) {
|
|
367
|
+
reason = 'restart required';
|
|
368
|
+
}
|
|
369
|
+
return {
|
|
370
|
+
reason,
|
|
371
|
+
statusCode
|
|
372
|
+
};
|
|
373
|
+
};
|
|
374
|
+
exports.getErrorCodeFromStreamError = getErrorCodeFromStreamError;
|
|
375
|
+
const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
376
|
+
let status;
|
|
377
|
+
switch (tag) {
|
|
378
|
+
case 'offer':
|
|
379
|
+
case 'offer_notice':
|
|
380
|
+
status = 'offer';
|
|
381
|
+
break;
|
|
382
|
+
case 'terminate':
|
|
383
|
+
if (attrs.reason === 'timeout') {
|
|
384
|
+
status = 'timeout';
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
// fired when accepted/rejected/timeout/caller hangs up
|
|
388
|
+
status = 'terminate';
|
|
389
|
+
}
|
|
390
|
+
break;
|
|
391
|
+
case 'reject':
|
|
392
|
+
status = 'reject';
|
|
393
|
+
break;
|
|
394
|
+
case 'accept':
|
|
395
|
+
status = 'accept';
|
|
396
|
+
break;
|
|
397
|
+
default:
|
|
398
|
+
status = 'ringing';
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
return status;
|
|
402
|
+
};
|
|
403
|
+
exports.getCallStatusFromNode = getCallStatusFromNode;
|
|
404
|
+
const UNEXPECTED_SERVER_CODE_TEXT = 'Unexpected server response: ';
|
|
405
|
+
const getCodeFromWSError = (error) => {
|
|
406
|
+
var _a, _b, _c;
|
|
407
|
+
let statusCode = 500;
|
|
408
|
+
if ((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
|
|
409
|
+
const code = +(error === null || error === void 0 ? void 0 : error.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length));
|
|
410
|
+
if (!Number.isNaN(code) && code >= 400) {
|
|
411
|
+
statusCode = code;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
else if (((_b = error === null || error === void 0 ? void 0 : error.code) === null || _b === void 0 ? void 0 : _b.startsWith('E'))
|
|
415
|
+
|| ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('timed out'))) { // handle ETIMEOUT, ENOTFOUND etc
|
|
416
|
+
statusCode = 408;
|
|
417
|
+
}
|
|
418
|
+
return statusCode;
|
|
419
|
+
};
|
|
420
|
+
exports.getCodeFromWSError = getCodeFromWSError;
|
|
421
|
+
|
|
422
|
+
const isWABusinessPlatform = (platform) => {
|
|
423
|
+
return platform === 'smbi' || platform === 'smba';
|
|
424
|
+
};
|
|
425
|
+
exports.isWABusinessPlatform = isWABusinessPlatform;
|
|
426
|
+
function trimUndefined(obj) {
|
|
427
|
+
for (const key in obj) {
|
|
428
|
+
if (typeof obj[key] === 'undefined') {
|
|
429
|
+
delete obj[key];
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
return obj;
|
|
433
|
+
}
|
|
434
|
+
const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
|
|
435
|
+
function bytesToCrockford(buffer) {
|
|
436
|
+
let value = 0;
|
|
437
|
+
let bitCount = 0;
|
|
438
|
+
const crockford = [];
|
|
439
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
440
|
+
value = (value << 8) | (buffer[i] & 0xff);
|
|
441
|
+
bitCount += 8;
|
|
442
|
+
while (bitCount >= 5) {
|
|
443
|
+
crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
|
|
444
|
+
bitCount -= 5;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
if (bitCount > 0) {
|
|
448
|
+
crockford.push(CROCKFORD_CHARACTERS.charAt((value << (5 - bitCount)) & 31));
|
|
449
|
+
}
|
|
450
|
+
return crockford.join('');
|
|
451
|
+
}
|
|
452
|
+
exports.trimUndefined = trimUndefined;
|
|
453
|
+
exports.bytesToCrockford = bytesToCrockford;
|
|
@@ -0,0 +1,94 @@
|
|
|
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 });
|
|
15
|
+
const bufferArray = [];
|
|
16
|
+
for await (const chunk of stream) {
|
|
17
|
+
bufferArray.push(chunk);
|
|
18
|
+
}
|
|
19
|
+
let buffer = Buffer.concat(bufferArray);
|
|
20
|
+
// decompress buffer
|
|
21
|
+
buffer = await inflatePromise(buffer);
|
|
22
|
+
const syncData = WAProto_1.proto.HistorySync.decode(buffer);
|
|
23
|
+
return syncData;
|
|
24
|
+
};
|
|
25
|
+
exports.downloadHistory = downloadHistory;
|
|
26
|
+
const processHistoryMessage = (item) => {
|
|
27
|
+
var _a, _b, _c;
|
|
28
|
+
const messages = [];
|
|
29
|
+
const contacts = [];
|
|
30
|
+
const chats = [];
|
|
31
|
+
switch (item.syncType) {
|
|
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:
|
|
36
|
+
for (const chat of item.conversations) {
|
|
37
|
+
contacts.push({ id: chat.id, name: chat.name || undefined, lid: chat.lidJid || undefined, jid: (0, WABinary_1.isJidUser)(chat.id) ? chat.id : chat.pnJid });
|
|
38
|
+
const msgs = chat.messages || [];
|
|
39
|
+
delete chat.messages;
|
|
40
|
+
delete chat.archived;
|
|
41
|
+
delete chat.muteEndTime;
|
|
42
|
+
delete chat.pinned;
|
|
43
|
+
for (const item of msgs) {
|
|
44
|
+
const message = item.message;
|
|
45
|
+
messages.push(message);
|
|
46
|
+
if (!((_a = chat.messages) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
47
|
+
// keep only the most recent message in the chat array
|
|
48
|
+
chat.messages = [{ message }];
|
|
49
|
+
}
|
|
50
|
+
if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
|
|
51
|
+
chat.lastMessageRecvTimestamp = (0, generics_1.toNumber)(message.messageTimestamp);
|
|
52
|
+
}
|
|
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])) {
|
|
56
|
+
contacts.push({
|
|
57
|
+
id: message.key.participant || message.key.remoteJid,
|
|
58
|
+
verifiedName: (_c = message.messageStubParameters) === null || _c === void 0 ? void 0 : _c[0],
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if ((0, WABinary_1.isJidUser)(chat.id) && chat.readOnly && chat.archived) {
|
|
63
|
+
delete chat.readOnly;
|
|
64
|
+
}
|
|
65
|
+
chats.push({ ...chat });
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.PUSH_NAME:
|
|
69
|
+
for (const c of item.pushnames) {
|
|
70
|
+
contacts.push({ id: c.id, notify: c.pushname });
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
chats,
|
|
76
|
+
contacts,
|
|
77
|
+
messages,
|
|
78
|
+
syncType: item.syncType,
|
|
79
|
+
progress: item.progress
|
|
80
|
+
};
|
|
81
|
+
};
|
|
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);
|
|
86
|
+
};
|
|
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;
|
|
92
|
+
return anyHistoryMsg;
|
|
93
|
+
};
|
|
94
|
+
exports.getHistoryMsg = getHistoryMsg;
|
|
@@ -0,0 +1,37 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./generics"), exports);
|
|
18
|
+
__exportStar(require("./decode-wa-message"), exports);
|
|
19
|
+
__exportStar(require("./messages"), exports);
|
|
20
|
+
__exportStar(require("./messages-media"), exports);
|
|
21
|
+
__exportStar(require("./validate-connection"), exports);
|
|
22
|
+
__exportStar(require("./crypto"), exports);
|
|
23
|
+
__exportStar(require("./signal"), exports);
|
|
24
|
+
__exportStar(require("./noise-handler"), exports);
|
|
25
|
+
__exportStar(require("./history"), exports);
|
|
26
|
+
__exportStar(require("./chat-utils"), exports);
|
|
27
|
+
__exportStar(require("./lt-hash"), exports);
|
|
28
|
+
__exportStar(require("./auth-utils"), exports);
|
|
29
|
+
__exportStar(require("./yebails-event-stream"), exports);
|
|
30
|
+
__exportStar(require("./use-multi-file-auth-state"), exports);
|
|
31
|
+
__exportStar(require("./use-custom-auth-state"), exports);
|
|
32
|
+
__exportStar(require("./use-sqlite-auth-state"), exports);
|
|
33
|
+
__exportStar(require("./link-preview"), exports);
|
|
34
|
+
__exportStar(require("./event-buffer"), exports);
|
|
35
|
+
__exportStar(require("./process-message"), exports);
|
|
36
|
+
__exportStar(require("./message-retry-manager"), exports);
|
|
37
|
+
__exportStar(require("./browser-utils"), exports);
|