jagproject 26.3.23 → 26.3.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/WAProto/GenerateStatics.sh +3 -4
- package/WAProto/WAProto.proto +1215 -511
- package/WAProto/fix-imports.js +73 -0
- package/WAProto/index.d.ts +14017 -0
- package/WAProto/index.js +64857 -145167
- package/engine-requirements.js +4 -7
- package/lib/Defaults/index.d.ts +74 -0
- package/lib/Defaults/index.js +49 -35
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/wileys-version.json +2 -2
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group-session-builder.js +5 -3
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +35 -46
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.js +21 -21
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.js +2 -2
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +5 -10
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +7 -7
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +8 -8
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-record.js +7 -16
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.js +25 -37
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +2 -2
- package/lib/Signal/libsignal.d.ts +5 -0
- package/lib/Signal/libsignal.js +358 -54
- package/lib/Signal/lid-mapping.d.ts +19 -0
- package/lib/Signal/lid-mapping.js +274 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +2 -2
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.js +1 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +18 -30
- package/lib/Socket/business.d.ts +202 -0
- package/lib/Socket/business.js +160 -38
- package/lib/Socket/chats.d.ts +111 -0
- package/lib/Socket/chats.js +497 -314
- package/lib/Socket/communities.d.ts +258 -0
- package/lib/Socket/communities.js +438 -0
- package/lib/Socket/community.js +333 -0
- package/lib/Socket/groups.d.ts +150 -0
- package/lib/Socket/groups.js +229 -91
- package/lib/Socket/index.d.ts +245 -0
- package/lib/Socket/index.js +9 -6
- package/lib/Socket/messages-recv.d.ts +187 -0
- package/lib/Socket/messages-recv.js +1105 -501
- package/lib/Socket/messages-send.d.ts +183 -0
- package/lib/Socket/messages-send.js +1181 -501
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.d.ts +160 -0
- package/lib/Socket/newsletter.js +227 -200
- package/lib/Socket/socket.d.ts +55 -0
- package/lib/Socket/socket.js +507 -206
- package/lib/Socket/usync.js +6 -6
- package/lib/Store/index.js +17 -5
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.js +48 -89
- package/lib/Store/make-ordered-dictionary.js +1 -1
- package/lib/Types/Auth.d.ts +116 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Chat.d.ts +123 -0
- package/lib/Types/Chat.js +7 -1
- package/lib/Types/Contact.d.ts +24 -0
- package/lib/Types/Events.d.ts +237 -0
- package/lib/Types/Events.js +1 -0
- package/lib/Types/GroupMetadata.d.ts +67 -0
- package/lib/Types/Label.d.ts +47 -0
- package/lib/Types/Label.js +1 -3
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/LabelAssociation.js +1 -3
- package/lib/Types/Message.d.ts +305 -0
- package/lib/Types/Message.js +9 -5
- package/lib/Types/MexUpdates.js +11 -0
- package/lib/Types/Newsletter.d.ts +135 -0
- package/lib/Types/Newsletter.js +36 -11
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Signal.d.ts +76 -0
- package/lib/Types/Signal.js +1 -0
- package/lib/Types/Socket.d.ts +133 -0
- package/lib/Types/Socket.js +1 -0
- package/lib/Types/State.d.ts +39 -0
- package/lib/Types/State.js +12 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.d.ts +65 -0
- package/lib/Types/index.js +14 -14
- package/lib/Utils/audioToBuffer.js +31 -0
- package/lib/Utils/auth-utils.d.ts +19 -0
- package/lib/Utils/auth-utils.js +222 -123
- package/lib/Utils/baileys-event-stream.js +60 -0
- package/lib/Utils/bridge-runtime.d.ts +1 -0
- package/lib/Utils/bridge-runtime.js +14 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.js +38 -29
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/business.js +54 -48
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/lib/Utils/chat-utils.js +284 -189
- package/lib/Utils/crypto.d.ts +37 -0
- package/lib/Utils/crypto.js +16 -41
- package/lib/Utils/decode-wa-message.d.ts +48 -0
- package/lib/Utils/decode-wa-message.js +128 -48
- package/lib/Utils/event-buffer.d.ts +34 -0
- package/lib/Utils/event-buffer.js +124 -62
- package/lib/Utils/generics.d.ts +91 -0
- package/lib/Utils/generics.js +154 -138
- package/lib/Utils/history.d.ts +22 -0
- package/lib/Utils/history.js +77 -34
- package/lib/Utils/identity-change-handler.d.ts +37 -0
- package/lib/Utils/identity-change-handler.js +54 -0
- package/lib/Utils/index.d.ts +22 -0
- package/lib/Utils/index.js +32 -19
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +12 -17
- package/lib/Utils/logger.d.ts +13 -0
- package/lib/Utils/lt-hash.d.ts +8 -0
- package/lib/Utils/lt-hash.js +2 -43
- package/lib/Utils/make-mutex.d.ts +9 -0
- package/lib/Utils/make-mutex.js +21 -27
- package/lib/Utils/message-retry-manager.d.ts +110 -0
- package/lib/Utils/message-retry-manager.js +143 -45
- package/lib/Utils/messages-media.d.ts +130 -0
- package/lib/Utils/messages-media.js +429 -502
- package/lib/Utils/messages-newsletter.d.ts +84 -0
- package/lib/Utils/messages-newsletter.js +295 -0
- package/lib/Utils/messages.d.ts +92 -0
- package/lib/Utils/messages.js +1025 -674
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +145 -91
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.js +112 -0
- package/lib/Utils/process-message.d.ts +60 -0
- package/lib/Utils/process-message.js +316 -184
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.js +262 -0
- package/lib/Utils/resolve-jid.d.ts +43 -0
- package/lib/Utils/resolve-jid.js +95 -0
- package/lib/Utils/rust-bridge-shim.d.ts +22 -0
- package/lib/Utils/rust-bridge-shim.js +70 -0
- package/lib/Utils/serial-task-queue.js +29 -0
- package/lib/Utils/signal.d.ts +34 -0
- package/lib/Utils/signal.js +56 -39
- package/lib/Utils/streamToBuffer.js +17 -0
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.js +52 -0
- package/lib/Utils/tc-token-utils.d.ts +12 -0
- package/lib/Utils/tc-token-utils.js +20 -0
- package/lib/Utils/use-mongo-file-auth-state.js +71 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +11 -12
- package/lib/Utils/use-single-file-auth-state.js +73 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +59 -82
- package/lib/Utils/wileys-event-stream.js +1 -61
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.js +39 -4
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +17 -11
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/generic-utils.js +46 -18
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.js +9 -5
- package/lib/WABinary/jid-utils.d.ts +48 -0
- package/lib/WABinary/jid-utils.js +67 -37
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.js +34 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/constants.d.ts +40 -0
- package/lib/WAM/constants.js +19183 -11678
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.js +15 -17
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.js +3 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +6 -6
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +9 -9
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +6 -6
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -8
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +18 -17
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +11 -3
- package/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/lib/WAUSync/Protocols/index.js +6 -4
- package/lib/WAUSync/USyncQuery.d.ts +29 -0
- package/lib/WAUSync/USyncQuery.js +38 -30
- package/lib/WAUSync/USyncUser.d.ts +13 -0
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.js +3 -3
- package/lib/index.d.ts +12 -0
- package/lib/index.js +3 -5
- package/package.json +7 -4
- package/LICENSE +0 -21
package/lib/Utils/generics.js
CHANGED
|
@@ -36,72 +36,56 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.
|
|
39
|
+
exports.fetchLatestWileysVersion = exports.asciiDecode = exports.asciiEncode = exports.fromUnicodeEscape = exports.toUnicodeEscape = exports.printQRIfNecessaryListener = exports.COMPANION_PLATFORM_MAP = 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.generateParticipantHashV2 = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.isStringNullOrEmpty = exports.getKeyAuthor = exports.BufferJSON = void 0;
|
|
40
40
|
exports.promiseTimeout = promiseTimeout;
|
|
41
41
|
exports.bindWaitForEvent = bindWaitForEvent;
|
|
42
42
|
exports.trimUndefined = trimUndefined;
|
|
43
43
|
exports.bytesToCrockford = bytesToCrockford;
|
|
44
|
+
exports.encodeNewsletterMessage = encodeNewsletterMessage;
|
|
44
45
|
const boom_1 = require("@hapi/boom");
|
|
45
|
-
const axios_1 = __importDefault(require("axios"));
|
|
46
46
|
const crypto_1 = require("crypto");
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
|
|
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
|
-
baileys: (browser) => ['Baileys', browser, '6.5.0'],
|
|
72
|
-
windows: (browser) => ['Windows', browser, '10.0.22631'],
|
|
73
|
-
/** The appropriate browser based on your OS & release */
|
|
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;
|
|
47
|
+
const axios_1 = __importDefault(require("axios"));
|
|
48
|
+
const index_js_1 = require("../../WAProto/index.js");
|
|
49
|
+
const waVer = require('../Defaults/wileys-version.json');
|
|
50
|
+
const baileysVersion = waVer?.version || [2, 3000, 1036687490];
|
|
51
|
+
const index_js_2 = require("../Types/index.js");
|
|
52
|
+
const index_js_3 = require("../WABinary/index.js");
|
|
53
|
+
const crypto_js_1 = require("./crypto.js");
|
|
81
54
|
exports.BufferJSON = {
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
82
56
|
replacer: (k, value) => {
|
|
83
|
-
if (Buffer.isBuffer(value) || value instanceof Uint8Array ||
|
|
84
|
-
return { type: 'Buffer', data: Buffer.from(
|
|
57
|
+
if (Buffer.isBuffer(value) || value instanceof Uint8Array || value?.type === 'Buffer') {
|
|
58
|
+
return { type: 'Buffer', data: Buffer.from(value?.data || value).toString('base64') };
|
|
85
59
|
}
|
|
86
60
|
return value;
|
|
87
61
|
},
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
88
63
|
reviver: (_, value) => {
|
|
89
|
-
if (typeof value === 'object' &&
|
|
90
|
-
|
|
91
|
-
|
|
64
|
+
if (typeof value === 'object' && value !== null && value.type === 'Buffer' && typeof value.data === 'string') {
|
|
65
|
+
return Buffer.from(value.data, 'base64');
|
|
66
|
+
}
|
|
67
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
68
|
+
const keys = Object.keys(value);
|
|
69
|
+
if (keys.length > 0 && keys.every(k => !isNaN(parseInt(k, 10)))) {
|
|
70
|
+
const values = Object.values(value);
|
|
71
|
+
if (values.every(v => typeof v === 'number')) {
|
|
72
|
+
return Buffer.from(values);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
92
75
|
}
|
|
93
76
|
return value;
|
|
94
77
|
}
|
|
95
78
|
};
|
|
96
|
-
const getKeyAuthor = (key, meId = 'me') => (
|
|
79
|
+
const getKeyAuthor = (key, meId = 'me') => (key?.fromMe ? meId : key?.participantAlt || key?.remoteJidAlt || key?.participant || key?.remoteJid) || '';
|
|
97
80
|
exports.getKeyAuthor = getKeyAuthor;
|
|
81
|
+
const isStringNullOrEmpty = (value) =>
|
|
82
|
+
// eslint-disable-next-line eqeqeq
|
|
83
|
+
value == null || value === '';
|
|
84
|
+
exports.isStringNullOrEmpty = isStringNullOrEmpty;
|
|
98
85
|
const writeRandomPadMax16 = (msg) => {
|
|
99
86
|
const pad = (0, crypto_1.randomBytes)(1);
|
|
100
|
-
pad[0]
|
|
101
|
-
|
|
102
|
-
pad[0] = 0xf;
|
|
103
|
-
}
|
|
104
|
-
return Buffer.concat([msg, Buffer.alloc(pad[0], pad[0])]);
|
|
87
|
+
const padLength = (pad[0] & 0x0f) + 1;
|
|
88
|
+
return Buffer.concat([msg, Buffer.alloc(padLength, padLength)]);
|
|
105
89
|
};
|
|
106
90
|
exports.writeRandomPadMax16 = writeRandomPadMax16;
|
|
107
91
|
const unpadRandomMax16 = (e) => {
|
|
@@ -116,10 +100,15 @@ const unpadRandomMax16 = (e) => {
|
|
|
116
100
|
return new Uint8Array(t.buffer, t.byteOffset, t.length - r);
|
|
117
101
|
};
|
|
118
102
|
exports.unpadRandomMax16 = unpadRandomMax16;
|
|
119
|
-
|
|
103
|
+
// code is inspired by whatsmeow
|
|
104
|
+
const generateParticipantHashV2 = (participants) => {
|
|
105
|
+
participants.sort();
|
|
106
|
+
const sha256Hash = (0, crypto_js_1.sha256)(Buffer.from(participants.join(''))).toString('base64');
|
|
107
|
+
return '2:' + sha256Hash.slice(0, 6);
|
|
108
|
+
};
|
|
109
|
+
exports.generateParticipantHashV2 = generateParticipantHashV2;
|
|
110
|
+
const encodeWAMessage = (message) => (0, exports.writeRandomPadMax16)(index_js_1.proto.Message.encode(message).finish());
|
|
120
111
|
exports.encodeWAMessage = encodeWAMessage;
|
|
121
|
-
const encodeNewsletterMessage = (message) => (WAProto_1.proto.Message.encode(message).finish());
|
|
122
|
-
exports.encodeNewsletterMessage = encodeNewsletterMessage;
|
|
123
112
|
const generateRegistrationId = () => {
|
|
124
113
|
return Uint16Array.from((0, crypto_1.randomBytes)(2))[0] & 16383;
|
|
125
114
|
};
|
|
@@ -134,7 +123,7 @@ const encodeBigEndian = (e, t = 4) => {
|
|
|
134
123
|
return a;
|
|
135
124
|
};
|
|
136
125
|
exports.encodeBigEndian = encodeBigEndian;
|
|
137
|
-
const toNumber = (t) =>
|
|
126
|
+
const toNumber = (t) => typeof t === 'object' && t ? ('toNumber' in t ? t.toNumber() : t.low) : t || 0;
|
|
138
127
|
exports.toNumber = toNumber;
|
|
139
128
|
/** unix timestamp of a date in seconds */
|
|
140
129
|
const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
|
|
@@ -146,14 +135,14 @@ const debouncedTimeout = (intervalMs = 1000, task) => {
|
|
|
146
135
|
task = newTask || task;
|
|
147
136
|
intervalMs = newIntervalMs || intervalMs;
|
|
148
137
|
timeout && clearTimeout(timeout);
|
|
149
|
-
timeout = setTimeout(() => task
|
|
138
|
+
timeout = setTimeout(() => task?.(), intervalMs);
|
|
150
139
|
},
|
|
151
140
|
cancel: () => {
|
|
152
141
|
timeout && clearTimeout(timeout);
|
|
153
142
|
timeout = undefined;
|
|
154
143
|
},
|
|
155
|
-
setTask: (newTask) => task = newTask,
|
|
156
|
-
setInterval: (newInterval) => intervalMs = newInterval
|
|
144
|
+
setTask: (newTask) => (task = newTask),
|
|
145
|
+
setInterval: (newInterval) => (intervalMs = newInterval)
|
|
157
146
|
};
|
|
158
147
|
};
|
|
159
148
|
exports.debouncedTimeout = debouncedTimeout;
|
|
@@ -189,23 +178,24 @@ async function promiseTimeout(ms, promise) {
|
|
|
189
178
|
const p = new Promise((resolve, reject) => {
|
|
190
179
|
delay
|
|
191
180
|
.then(() => reject(new boom_1.Boom('Timed Out', {
|
|
192
|
-
statusCode:
|
|
181
|
+
statusCode: index_js_2.DisconnectReason.timedOut,
|
|
193
182
|
data: {
|
|
194
183
|
stack
|
|
195
184
|
}
|
|
196
185
|
})))
|
|
197
186
|
.catch(err => reject(err));
|
|
198
187
|
promise(resolve, reject);
|
|
199
|
-
})
|
|
200
|
-
.finally(cancel);
|
|
188
|
+
}).finally(cancel);
|
|
201
189
|
return p;
|
|
202
190
|
}
|
|
191
|
+
// inspired from whatsmeow code
|
|
192
|
+
// https://github.com/tulir/whatsmeow/blob/64bc969fbe78d31ae0dd443b8d4c80a5d026d07a/send.go#L42
|
|
203
193
|
const generateMessageIDV2 = (userId) => {
|
|
204
194
|
const data = Buffer.alloc(8 + 20 + 16);
|
|
205
195
|
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
|
|
206
196
|
if (userId) {
|
|
207
|
-
const id = (0,
|
|
208
|
-
if (id
|
|
197
|
+
const id = (0, index_js_3.jidDecode)(userId);
|
|
198
|
+
if (id?.user) {
|
|
209
199
|
data.write(id.user, 8);
|
|
210
200
|
data.write('@c.us', 8 + id.user.length);
|
|
211
201
|
}
|
|
@@ -223,11 +213,10 @@ function bindWaitForEvent(ev, event) {
|
|
|
223
213
|
return async (check, timeoutMs) => {
|
|
224
214
|
let listener;
|
|
225
215
|
let closeListener;
|
|
226
|
-
await
|
|
216
|
+
await promiseTimeout(timeoutMs, (resolve, reject) => {
|
|
227
217
|
closeListener = ({ connection, lastDisconnect }) => {
|
|
228
218
|
if (connection === 'close') {
|
|
229
|
-
reject(
|
|
230
|
-
|| new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
|
219
|
+
reject(lastDisconnect?.error || new boom_1.Boom('Connection Closed', { statusCode: index_js_2.DisconnectReason.connectionClosed }));
|
|
231
220
|
}
|
|
232
221
|
};
|
|
233
222
|
ev.on('connection.update', closeListener);
|
|
@@ -237,87 +226,80 @@ function bindWaitForEvent(ev, event) {
|
|
|
237
226
|
}
|
|
238
227
|
};
|
|
239
228
|
ev.on(event, listener);
|
|
240
|
-
})
|
|
241
|
-
.finally(() => {
|
|
229
|
+
}).finally(() => {
|
|
242
230
|
ev.off(event, listener);
|
|
243
231
|
ev.off('connection.update', closeListener);
|
|
244
|
-
})
|
|
232
|
+
});
|
|
245
233
|
};
|
|
246
234
|
}
|
|
247
235
|
const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
|
|
248
236
|
exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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 fetchLatestWileysVersion = async (options = {}) => {
|
|
263
|
-
try {
|
|
264
|
-
const { data } = await axios_1.default.get('https://registry.npmjs.org/wileys', {
|
|
265
|
-
...options,
|
|
266
|
-
responseType: 'json'
|
|
267
|
-
});
|
|
268
|
-
const versionStr = data.version;
|
|
269
|
-
const [major, minor, patch] = versionStr.split('.').map(Number);
|
|
270
|
-
return {
|
|
271
|
-
version: [major, minor, patch],
|
|
272
|
-
isLatest: true
|
|
273
|
-
};
|
|
274
|
-
} catch (error) {
|
|
275
|
-
return {
|
|
276
|
-
version: wileys_version_json_1.version,
|
|
277
|
-
isLatest: false,
|
|
278
|
-
error
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
exports.fetchLatestWileysVersion = fetchLatestWileysVersion;
|
|
283
|
-
|
|
237
|
+
/**
|
|
238
|
+
* utility that fetches latest baileys version from the master branch.
|
|
239
|
+
* Use to ensure your WA connection is always on the latest version
|
|
240
|
+
*/
|
|
284
241
|
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
242
|
+
const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/index.ts';
|
|
285
243
|
try {
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
|
|
244
|
+
const response = await fetch(URL, {
|
|
245
|
+
dispatcher: options.dispatcher,
|
|
246
|
+
method: 'GET',
|
|
247
|
+
headers: options.headers
|
|
289
248
|
});
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
249
|
+
if (!response.ok) {
|
|
250
|
+
throw new boom_1.Boom(`Failed to fetch latest Baileys version: ${response.statusText}`, { statusCode: response.status });
|
|
251
|
+
}
|
|
252
|
+
const text = await response.text();
|
|
253
|
+
// Extract version from line 7 (const version = [...])
|
|
254
|
+
const lines = text.split('\n');
|
|
255
|
+
const versionLine = lines[6]; // Line 7 (0-indexed)
|
|
256
|
+
const versionMatch = versionLine.match(/const version = \[(\d+),\s*(\d+),\s*(\d+)\]/);
|
|
257
|
+
if (versionMatch) {
|
|
258
|
+
const version = [parseInt(versionMatch[1]), parseInt(versionMatch[2]), parseInt(versionMatch[3])];
|
|
259
|
+
return {
|
|
260
|
+
version,
|
|
261
|
+
isLatest: true
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
throw new Error('Could not parse version from Defaults/index.ts');
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
297
269
|
return {
|
|
298
|
-
version:
|
|
270
|
+
version: baileysVersion,
|
|
299
271
|
isLatest: false,
|
|
300
272
|
error
|
|
301
273
|
};
|
|
302
274
|
}
|
|
303
275
|
};
|
|
304
276
|
exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
|
305
|
-
|
|
306
277
|
/**
|
|
307
278
|
* A utility that fetches the latest web version of whatsapp.
|
|
308
279
|
* Use to ensure your WA connection is always on the latest version
|
|
309
280
|
*/
|
|
310
|
-
const fetchLatestWaWebVersion = async (options) => {
|
|
281
|
+
const fetchLatestWaWebVersion = async (options = {}) => {
|
|
311
282
|
try {
|
|
312
|
-
|
|
283
|
+
// Absolute minimal headers required to bypass anti-bot detection
|
|
284
|
+
const defaultHeaders = {
|
|
285
|
+
'sec-fetch-site': 'none',
|
|
286
|
+
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
|
|
287
|
+
};
|
|
288
|
+
const headers = { ...defaultHeaders, ...options.headers };
|
|
289
|
+
const response = await fetch('https://web.whatsapp.com/sw.js', {
|
|
313
290
|
...options,
|
|
314
|
-
|
|
291
|
+
method: 'GET',
|
|
292
|
+
headers
|
|
315
293
|
});
|
|
294
|
+
if (!response.ok) {
|
|
295
|
+
throw new boom_1.Boom(`Failed to fetch sw.js: ${response.statusText}`, { statusCode: response.status });
|
|
296
|
+
}
|
|
297
|
+
const data = await response.text();
|
|
316
298
|
const regex = /\\?"client_revision\\?":\s*(\d+)/;
|
|
317
299
|
const match = data.match(regex);
|
|
318
|
-
if (!
|
|
300
|
+
if (!match?.[1]) {
|
|
319
301
|
return {
|
|
320
|
-
version:
|
|
302
|
+
version: baileysVersion,
|
|
321
303
|
isLatest: false,
|
|
322
304
|
error: {
|
|
323
305
|
message: 'Could not find client revision in the fetched content'
|
|
@@ -332,7 +314,7 @@ const fetchLatestWaWebVersion = async (options) => {
|
|
|
332
314
|
}
|
|
333
315
|
catch (error) {
|
|
334
316
|
return {
|
|
335
|
-
version:
|
|
317
|
+
version: baileysVersion,
|
|
336
318
|
isLatest: false,
|
|
337
319
|
error
|
|
338
320
|
};
|
|
@@ -346,10 +328,10 @@ const generateMdTagPrefix = () => {
|
|
|
346
328
|
};
|
|
347
329
|
exports.generateMdTagPrefix = generateMdTagPrefix;
|
|
348
330
|
const STATUS_MAP = {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
'read-self':
|
|
331
|
+
sender: index_js_1.proto.WebMessageInfo.Status.SERVER_ACK,
|
|
332
|
+
played: index_js_1.proto.WebMessageInfo.Status.PLAYED,
|
|
333
|
+
read: index_js_1.proto.WebMessageInfo.Status.READ,
|
|
334
|
+
'read-self': index_js_1.proto.WebMessageInfo.Status.READ
|
|
353
335
|
};
|
|
354
336
|
/**
|
|
355
337
|
* Given a type of receipt, returns what the new status of the message should be
|
|
@@ -358,23 +340,23 @@ const STATUS_MAP = {
|
|
|
358
340
|
const getStatusFromReceiptType = (type) => {
|
|
359
341
|
const status = STATUS_MAP[type];
|
|
360
342
|
if (typeof type === 'undefined') {
|
|
361
|
-
return
|
|
343
|
+
return index_js_1.proto.WebMessageInfo.Status.DELIVERY_ACK;
|
|
362
344
|
}
|
|
363
345
|
return status;
|
|
364
346
|
};
|
|
365
347
|
exports.getStatusFromReceiptType = getStatusFromReceiptType;
|
|
366
348
|
const CODE_MAP = {
|
|
367
|
-
conflict:
|
|
349
|
+
conflict: index_js_2.DisconnectReason.connectionReplaced
|
|
368
350
|
};
|
|
369
351
|
/**
|
|
370
352
|
* Stream errors generally provide a reason, map that to a baileys DisconnectReason
|
|
371
353
|
* @param reason the string reason given, eg. "conflict"
|
|
372
354
|
*/
|
|
373
355
|
const getErrorCodeFromStreamError = (node) => {
|
|
374
|
-
const [reasonNode] = (0,
|
|
375
|
-
let reason =
|
|
376
|
-
const statusCode = +(node.attrs.code || CODE_MAP[reason] ||
|
|
377
|
-
if (statusCode ===
|
|
356
|
+
const [reasonNode] = (0, index_js_3.getAllBinaryNodeChildren)(node);
|
|
357
|
+
let reason = reasonNode?.tag || 'unknown';
|
|
358
|
+
const statusCode = +(node.attrs.code || CODE_MAP[reason] || index_js_2.DisconnectReason.badSession);
|
|
359
|
+
if (statusCode === index_js_2.DisconnectReason.restartRequired) {
|
|
378
360
|
reason = 'restart required';
|
|
379
361
|
}
|
|
380
362
|
return {
|
|
@@ -395,7 +377,7 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
|
395
377
|
status = 'timeout';
|
|
396
378
|
}
|
|
397
379
|
else {
|
|
398
|
-
//
|
|
380
|
+
//fired when accepted/rejected/timeout/caller hangs up
|
|
399
381
|
status = 'terminate';
|
|
400
382
|
}
|
|
401
383
|
break;
|
|
@@ -414,16 +396,18 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
|
414
396
|
exports.getCallStatusFromNode = getCallStatusFromNode;
|
|
415
397
|
const UNEXPECTED_SERVER_CODE_TEXT = 'Unexpected server response: ';
|
|
416
398
|
const getCodeFromWSError = (error) => {
|
|
417
|
-
var _a, _b, _c;
|
|
418
399
|
let statusCode = 500;
|
|
419
|
-
if (
|
|
420
|
-
const code = +
|
|
400
|
+
if (error?.message?.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
|
|
401
|
+
const code = +error?.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length);
|
|
421
402
|
if (!Number.isNaN(code) && code >= 400) {
|
|
422
403
|
statusCode = code;
|
|
423
404
|
}
|
|
424
405
|
}
|
|
425
|
-
else if (
|
|
426
|
-
|
|
406
|
+
else if (
|
|
407
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
408
|
+
error?.code?.startsWith('E') ||
|
|
409
|
+
error?.message?.includes('timed out')) {
|
|
410
|
+
// handle ETIMEOUT, ENOTFOUND etc
|
|
427
411
|
statusCode = 408;
|
|
428
412
|
}
|
|
429
413
|
return statusCode;
|
|
@@ -437,6 +421,7 @@ const isWABusinessPlatform = (platform) => {
|
|
|
437
421
|
return platform === 'smbi' || platform === 'smba';
|
|
438
422
|
};
|
|
439
423
|
exports.isWABusinessPlatform = isWABusinessPlatform;
|
|
424
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
440
425
|
function trimUndefined(obj) {
|
|
441
426
|
for (const key in obj) {
|
|
442
427
|
if (typeof obj[key] === 'undefined') {
|
|
@@ -450,8 +435,8 @@ function bytesToCrockford(buffer) {
|
|
|
450
435
|
let value = 0;
|
|
451
436
|
let bitCount = 0;
|
|
452
437
|
const crockford = [];
|
|
453
|
-
for (
|
|
454
|
-
value = (value << 8) | (
|
|
438
|
+
for (const element of buffer) {
|
|
439
|
+
value = (value << 8) | (element & 0xff);
|
|
455
440
|
bitCount += 8;
|
|
456
441
|
while (bitCount >= 5) {
|
|
457
442
|
crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
|
|
@@ -463,5 +448,36 @@ function bytesToCrockford(buffer) {
|
|
|
463
448
|
}
|
|
464
449
|
return crockford.join('');
|
|
465
450
|
}
|
|
466
|
-
|
|
467
|
-
|
|
451
|
+
function encodeNewsletterMessage(message) {
|
|
452
|
+
return index_js_1.proto.Message.encode(message).finish();
|
|
453
|
+
}
|
|
454
|
+
exports.COMPANION_PLATFORM_MAP = {
|
|
455
|
+
'Chrome': '49', 'Edge': '50', 'Firefox': '51', 'Opera': '53', 'Safari': '54',
|
|
456
|
+
'Brave': '1.79.112', 'Vivaldi': '6.2.3105.58', 'Tor': '12.5.3',
|
|
457
|
+
'Yandex': '23.7.1', 'Falkon': '22.08.3', 'Epiphany': '44.2'
|
|
458
|
+
};
|
|
459
|
+
// Browsers, PLATFORM_MAP, PLATFORM_VERSIONS, getPlatformId moved to browser-utils.js
|
|
460
|
+
const printQRIfNecessaryListener = (ev, logger) => {
|
|
461
|
+
ev.on('connection.update', async ({ qr }) => {
|
|
462
|
+
if (qr) {
|
|
463
|
+
const QR = await Promise.resolve().then(() => __importStar(require('qrcode-terminal'))).then(m => m.default || m).catch(() => {
|
|
464
|
+
logger.error('QR code terminal not added as dependency');
|
|
465
|
+
});
|
|
466
|
+
QR?.generate(qr, { small: true });
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
};
|
|
470
|
+
exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
|
|
471
|
+
const toUnicodeEscape = (text) => text.split('').map(c => '\\u' + c.charCodeAt(0).toString(16).padStart(4, '0')).join('');
|
|
472
|
+
exports.toUnicodeEscape = toUnicodeEscape;
|
|
473
|
+
const fromUnicodeEscape = (escapedText) => escapedText.replace(/\\u[\dA-Fa-f]{4}/g, m => String.fromCharCode(parseInt(m.slice(2), 16)));
|
|
474
|
+
exports.fromUnicodeEscape = fromUnicodeEscape;
|
|
475
|
+
const asciiEncode = (text) => text.split('').map(c => c.charCodeAt(0));
|
|
476
|
+
exports.asciiEncode = asciiEncode;
|
|
477
|
+
const asciiDecode = (...codes) => {
|
|
478
|
+
const arr = Array.isArray(codes[0]) ? codes[0] : codes;
|
|
479
|
+
return arr.map(c => String.fromCharCode(c)).join('');
|
|
480
|
+
};
|
|
481
|
+
exports.asciiDecode = asciiDecode;
|
|
482
|
+
|
|
483
|
+
exports.fetchLatestWileysVersion = exports.fetchLatestBaileysVersion;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
import type { Chat, Contact, LIDMapping, WAMessage } from '../Types/index.js';
|
|
3
|
+
import type { ILogger } from './logger.js';
|
|
4
|
+
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: RequestInit) => Promise<proto.HistorySync>;
|
|
5
|
+
export declare const processHistoryMessage: (item: proto.IHistorySync, logger?: ILogger) => {
|
|
6
|
+
chats: Chat[];
|
|
7
|
+
contacts: Contact[];
|
|
8
|
+
messages: WAMessage[];
|
|
9
|
+
lidPnMappings: LIDMapping[];
|
|
10
|
+
syncType: proto.HistorySync.HistorySyncType | null | undefined;
|
|
11
|
+
progress: number | null | undefined;
|
|
12
|
+
};
|
|
13
|
+
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: RequestInit, logger?: ILogger) => Promise<{
|
|
14
|
+
chats: Chat[];
|
|
15
|
+
contacts: Contact[];
|
|
16
|
+
messages: WAMessage[];
|
|
17
|
+
lidPnMappings: LIDMapping[];
|
|
18
|
+
syncType: proto.HistorySync.HistorySyncType | null | undefined;
|
|
19
|
+
progress: number | null | undefined;
|
|
20
|
+
}>;
|
|
21
|
+
export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification;
|
|
22
|
+
//# sourceMappingURL=history.d.ts.map
|