whalibmob 5.33.7 → 5.33.8
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/cli.js +7 -4
- package/lib/Registration.js +76 -7
- package/package.json +2 -2
package/cli.js
CHANGED
|
@@ -496,10 +496,13 @@ function normalizePhone(s) {
|
|
|
496
496
|
// describe a call that is never coming.
|
|
497
497
|
function printCodeNextSteps(store, phone, confirmCmd) {
|
|
498
498
|
if (store && store.codeMethod === 'flash') {
|
|
499
|
+
const cc = store.flashCliCc ? ' (from +' + store.flashCliCc + ')' : '';
|
|
500
|
+
const timeout = Number(store.flashTimeout) > 0 ? Number(store.flashTimeout) : null;
|
|
499
501
|
out(' a call will ring +' + phone + ' and hang up by itself — do not answer it');
|
|
500
|
-
out('
|
|
501
|
-
out('
|
|
502
|
-
out('
|
|
502
|
+
out(' it comes from a foreign number' + cc + ' — paste that WHOLE number here');
|
|
503
|
+
out(' whalibmob reads the code out of it for you (no need to pick out digits)');
|
|
504
|
+
if (timeout) out(' ⚠ be quick — the flash code expires about ' + timeout + 's after the call');
|
|
505
|
+
out(' run: ' + confirmCmd + ' <number-that-called>');
|
|
503
506
|
return;
|
|
504
507
|
}
|
|
505
508
|
out(' important: enter the code within 10 minutes');
|
|
@@ -2742,7 +2745,7 @@ options:
|
|
|
2742
2745
|
--pair connect by linking to an existing account (8-digit code)
|
|
2743
2746
|
--method sms | voice | wa_old | flash | email (default: sms)
|
|
2744
2747
|
flash: WhatsApp rings the number and hangs up; the code is
|
|
2745
|
-
|
|
2748
|
+
read from the calling number automatically (Android only)
|
|
2746
2749
|
--email <address> email address (required when --method email)
|
|
2747
2750
|
--business register/connect as WhatsApp Business (same as WA_BUSINESS=1)
|
|
2748
2751
|
--all refresh-version: every session in the session directory
|
package/lib/Registration.js
CHANGED
|
@@ -1838,13 +1838,50 @@ function flashCodeLength() {
|
|
|
1838
1838
|
return raw > 0 ? raw : FLASH_CODE_LENGTH;
|
|
1839
1839
|
}
|
|
1840
1840
|
|
|
1841
|
-
|
|
1841
|
+
// The server's own rule for pulling the code out of the number that rang.
|
|
1842
|
+
//
|
|
1843
|
+
// The /code reply for a flash call carries cli_filter — a regex such as
|
|
1844
|
+
// "(.*)373(.*)" — alongside cli_prefix and the code length. The code is the
|
|
1845
|
+
// part the filter isolates after the prefix: for a caller id "393739799312"
|
|
1846
|
+
// the filter's trailing group is "9799312", and the code is its last `length`
|
|
1847
|
+
// digits. Applying this is the whole fix for a flash "mismatch" on a correctly
|
|
1848
|
+
// read number — the national part of an Italian +39 373 XXXXXXX caller id has
|
|
1849
|
+
// more digits after the prefix than the six-digit code, so the old assumption
|
|
1850
|
+
// that the code was simply the last six digits took the wrong slice.
|
|
1851
|
+
//
|
|
1852
|
+
// Returns null when there is no filter, it does not compile, or it does not
|
|
1853
|
+
// match, so the caller can fall back to the plain last-`length` behaviour.
|
|
1854
|
+
function applyFlashFilter(digits, filter) {
|
|
1855
|
+
if (!filter) return null;
|
|
1856
|
+
let re;
|
|
1857
|
+
try { re = new RegExp(String(filter)); } catch (_) { return null; }
|
|
1858
|
+
const m = re.exec(digits);
|
|
1859
|
+
if (!m) return null;
|
|
1860
|
+
// The code follows the prefix, so it is the last capture group that has any
|
|
1861
|
+
// digits in it; earlier groups hold the country code and prefix.
|
|
1862
|
+
for (let i = m.length - 1; i >= 1; i--) {
|
|
1863
|
+
const g = m[i] && m[i].replace(/\D/g, '');
|
|
1864
|
+
if (g) return g;
|
|
1865
|
+
}
|
|
1866
|
+
return null;
|
|
1867
|
+
}
|
|
1868
|
+
|
|
1869
|
+
// `opts` may be a bare length (the historical signature) or
|
|
1870
|
+
// { length, filter }. The filter, when it matches, decides which digits are the
|
|
1871
|
+
// code; the length then trims them. Without a filter this is the old behaviour:
|
|
1872
|
+
// the last `length` digits of whatever was typed.
|
|
1873
|
+
function flashCodeFromCallerId(input, opts) {
|
|
1842
1874
|
const digits = normalizeCodeResult(input);
|
|
1843
|
-
const
|
|
1875
|
+
const o = (opts && typeof opts === 'object') ? opts : { length: opts };
|
|
1876
|
+
const want = Number(o.length) > 0 ? Number(o.length) : flashCodeLength();
|
|
1877
|
+
|
|
1878
|
+
const filtered = applyFlashFilter(digits, o.filter);
|
|
1879
|
+
const base = (filtered && filtered.length) ? filtered : digits;
|
|
1880
|
+
|
|
1844
1881
|
// Shorter than the code means the caller already typed just the tail (or the
|
|
1845
1882
|
// handset showed a short number); there is nothing to trim and guessing would
|
|
1846
1883
|
// only corrupt it.
|
|
1847
|
-
return
|
|
1884
|
+
return base.length > want ? base.slice(-want) : base;
|
|
1848
1885
|
}
|
|
1849
1886
|
|
|
1850
1887
|
// The digits /register is given, for whichever method the pending code came by.
|
|
@@ -1859,9 +1896,20 @@ function codeForSubmission(store, code, opts) {
|
|
|
1859
1896
|
const pending = String(
|
|
1860
1897
|
(opts && opts.method) || (store && store.codeMethod) || ''
|
|
1861
1898
|
).toLowerCase();
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1899
|
+
if (pending !== 'flash') return normalizeCodeResult(code);
|
|
1900
|
+
|
|
1901
|
+
// Length: an explicit WA_FLASH_CODE_LEN / opts.flashCodeLen wins, else the
|
|
1902
|
+
// length the server named in its /code reply (captured as store.flashCodeLength),
|
|
1903
|
+
// else the six-digit default inside flashCodeFromCallerId.
|
|
1904
|
+
const envLen = parseInt(process.env.WA_FLASH_CODE_LEN, 10);
|
|
1905
|
+
const length = envLen > 0 ? envLen
|
|
1906
|
+
: (opts && Number(opts.flashCodeLen) > 0 ? Number(opts.flashCodeLen)
|
|
1907
|
+
: (store && Number(store.flashCodeLength) > 0 ? Number(store.flashCodeLength) : 0));
|
|
1908
|
+
// Filter: the server's cli_filter from the /code reply, isolating the code
|
|
1909
|
+
// after the prefix. opts.flashFilter lets a caller state it outright.
|
|
1910
|
+
const filter = (opts && opts.flashFilter) || (store && store.flashCliFilter) || null;
|
|
1911
|
+
|
|
1912
|
+
return flashCodeFromCallerId(code, { length, filter });
|
|
1865
1913
|
}
|
|
1866
1914
|
|
|
1867
1915
|
// Take the digits the server filed the account under. Brazilian mobiles are the
|
|
@@ -2214,6 +2262,27 @@ async function requestSmsCode(store, method, opts) {
|
|
|
2214
2262
|
// The confirmation step is usually a separate command, so this is
|
|
2215
2263
|
// written to the session rather than kept in memory.
|
|
2216
2264
|
store.codeMethod = m;
|
|
2265
|
+
|
|
2266
|
+
// A flash /code reply states exactly how to read the code out of the
|
|
2267
|
+
// number that will ring: cli_filter is a regex isolating the code after
|
|
2268
|
+
// cli_prefix, and `length` is how many digits it is. Confirmation is
|
|
2269
|
+
// usually a separate command, so these are written to the session for
|
|
2270
|
+
// codeForSubmission to use rather than kept in memory. flash_timeout is
|
|
2271
|
+
// the window the call is valid for, carried so the CLI can warn.
|
|
2272
|
+
if (m === 'flash') {
|
|
2273
|
+
const srvLen = Number(result.length);
|
|
2274
|
+
store.flashCliFilter = result.cli_filter || null;
|
|
2275
|
+
store.flashCliPrefix = result.cli_prefix || null;
|
|
2276
|
+
store.flashCliCc = result.cli_cc || null;
|
|
2277
|
+
store.flashCodeLength = srvLen > 0 ? srvLen : null;
|
|
2278
|
+
store.flashTimeout = Number(result.flash_timeout) > 0 ? Number(result.flash_timeout) : null;
|
|
2279
|
+
_whaDbg('[DBG] REG ← /code flash cli: cc=' + (result.cli_cc || '?')
|
|
2280
|
+
+ ' prefix=' + (result.cli_prefix || '?')
|
|
2281
|
+
+ ' filter=' + (result.cli_filter || '?')
|
|
2282
|
+
+ ' length=' + (srvLen > 0 ? srvLen : '?')
|
|
2283
|
+
+ ' timeout=' + (result.flash_timeout || '?') + 's');
|
|
2284
|
+
}
|
|
2285
|
+
|
|
2217
2286
|
await sendFunnelLog(store, waVersion, verifyScreen, 'request_code', 'request_code_success');
|
|
2218
2287
|
return result;
|
|
2219
2288
|
}
|
|
@@ -2426,7 +2495,7 @@ module.exports._token = { computeToken, androidMaterialPath, registrationHeaders
|
|
|
2426
2495
|
module.exports._verify = {
|
|
2427
2496
|
hasChallenge, is2FARequired, decodeOrNull, isSuccessful,
|
|
2428
2497
|
normalizeCodeResult, currentVerifyScreen, adoptCanonicalNumber, funnelEnabled, waitHint,
|
|
2429
|
-
flashCodeFromCallerId, flashCodeLength, codeForSubmission,
|
|
2498
|
+
flashCodeFromCallerId, flashCodeLength, applyFlashFilter, codeForSubmission,
|
|
2430
2499
|
getRequestVerificationCodeParameters
|
|
2431
2500
|
};
|
|
2432
2501
|
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "whalibmob",
|
|
3
|
-
"version": "5.33.
|
|
3
|
+
"version": "5.33.8",
|
|
4
4
|
"description": "Node.js library for WhatsApp — register a number over SMS, or link as a companion by QR. Signal E2E encryption, media, groups, channels.",
|
|
5
5
|
"author": "Kunboruto20",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"types": "index.d.ts",
|
|
8
8
|
"bin": {
|
|
9
|
-
"wa": "cli.js"
|
|
9
|
+
"wa": "./cli.js"
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"index.js",
|