chore(): generate docs
This commit is contained in:
parent
611b7c63d7
commit
376c60668c
76 changed files with 849 additions and 323 deletions
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta name="generator" content="JSDoc 3.6.11">
|
||||
<meta charset="utf-8">
|
||||
<title>whatsapp-web.js 1.34.2 » Source: Client.js</title>
|
||||
<title>whatsapp-web.js 1.34.3 » Source: Client.js</title>
|
||||
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
|
||||
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
|
||||
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
|
||||
<div id="jsdoc-navbar-container">
|
||||
<div id="jsdoc-navbar-content">
|
||||
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>34.<wbr>2</a>
|
||||
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>34.<wbr>3</a>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
|
@ -37,7 +37,7 @@ const moduleRaid = require('@pedroslopez/moduleraid/moduleraid');
|
|||
|
||||
const Util = require('./util/Util');
|
||||
const InterfaceController = require('./util/InterfaceController');
|
||||
const { WhatsWebURL, DefaultOptions, Events, WAState } = require('./util/Constants');
|
||||
const { WhatsWebURL, DefaultOptions, Events, WAState, MessageTypes } = require('./util/Constants');
|
||||
const { ExposeAuthStore } = require('./util/Injected/AuthStore/AuthStore');
|
||||
const { ExposeStore } = require('./util/Injected/Store');
|
||||
const { ExposeLegacyAuthStore } = require('./util/Injected/AuthStore/LegacyAuthStore');
|
||||
|
|
@ -58,6 +58,7 @@ const {exposeFunctionIfAbsent} = require('./util/Puppeteer');
|
|||
* @param {string} options.webVersion - The version of WhatsApp Web to use. Use options.webVersionCache to configure how the version is retrieved.
|
||||
* @param {object} options.webVersionCache - Determines how to retrieve the WhatsApp Web version. Defaults to a local cache (LocalWebCache) that falls back to latest if the requested version is not found.
|
||||
* @param {number} options.authTimeoutMs - Timeout for authentication selector in puppeteer
|
||||
* @param {function} options.evalOnNewDoc - function to eval on new doc
|
||||
* @param {object} options.puppeteer - Puppeteer launch options. View docs here: https://github.com/puppeteer/puppeteer/
|
||||
* @param {number} options.qrMaxRetries - How many times should the qrcode be refreshed before giving up
|
||||
* @param {string} options.restartOnAuthFail - @deprecated This option should be set directly on the LegacySessionAuth.
|
||||
|
|
@ -126,7 +127,22 @@ class Client extends EventEmitter {
|
|||
* Private function
|
||||
*/
|
||||
async inject() {
|
||||
await this.pupPage.waitForFunction('window.Debug?.VERSION != undefined', {timeout: this.options.authTimeoutMs});
|
||||
|
||||
if(this.options.authTimeoutMs === undefined){
|
||||
this.options.authTimeoutMs = 30000;
|
||||
}
|
||||
let start = Date.now();
|
||||
let timeout = this.options.authTimeoutMs;
|
||||
let res = false;
|
||||
while(start > (Date.now() - timeout)){
|
||||
res = await this.pupPage.evaluate('window.Debug?.VERSION != undefined');
|
||||
if(res){break;}
|
||||
await new Promise(r => setTimeout(r, 200));
|
||||
}
|
||||
if(!res){
|
||||
throw 'auth timeout';
|
||||
}
|
||||
|
||||
await this.setDeviceName(this.options.deviceName, this.options.browserName);
|
||||
const pairWithPhoneNumber = this.options.pairWithPhoneNumber;
|
||||
const version = await this.getWWebVersion();
|
||||
|
|
@ -256,9 +272,17 @@ class Client extends EventEmitter {
|
|||
await new Promise(r => setTimeout(r, 2000));
|
||||
await this.pupPage.evaluate(ExposeLegacyStore);
|
||||
}
|
||||
|
||||
// Check window.Store Injection
|
||||
await this.pupPage.waitForFunction('window.Store != undefined');
|
||||
let start = Date.now();
|
||||
let res = false;
|
||||
while(start > (Date.now() - 30000)){
|
||||
// Check window.Store Injection
|
||||
res = await this.pupPage.evaluate('window.Store != undefined');
|
||||
if(res){break;}
|
||||
await new Promise(r => setTimeout(r, 200));
|
||||
}
|
||||
if(!res){
|
||||
throw 'ready timeout';
|
||||
}
|
||||
|
||||
/**
|
||||
* Current connection information
|
||||
|
|
@ -331,7 +355,7 @@ class Client extends EventEmitter {
|
|||
page = await browser.newPage();
|
||||
} else {
|
||||
const browserArgs = [...(puppeteerOpts.args || [])];
|
||||
if(!browserArgs.find(arg => arg.includes('--user-agent'))) {
|
||||
if(this.options.userAgent !== false &amp;&amp; !browserArgs.find(arg => arg.includes('--user-agent'))) {
|
||||
browserArgs.push(`--user-agent=${this.options.userAgent}`);
|
||||
}
|
||||
// navigator.webdriver fix
|
||||
|
|
@ -344,8 +368,9 @@ class Client extends EventEmitter {
|
|||
if (this.options.proxyAuthentication !== undefined) {
|
||||
await page.authenticate(this.options.proxyAuthentication);
|
||||
}
|
||||
|
||||
await page.setUserAgent(this.options.userAgent);
|
||||
if(this.options.userAgent !== false) {
|
||||
await page.setUserAgent(this.options.userAgent);
|
||||
}
|
||||
if (this.options.bypassCSP) await page.setBypassCSP(true);
|
||||
|
||||
this.pupBrowser = browser;
|
||||
|
|
@ -353,7 +378,11 @@ class Client extends EventEmitter {
|
|||
|
||||
await this.authStrategy.afterBrowserInitialized();
|
||||
await this.initWebVersionCache();
|
||||
|
||||
|
||||
if (this.options.evalOnNewDoc !== undefined) {
|
||||
await page.evaluateOnNewDocument(this.options.evalOnNewDoc);
|
||||
}
|
||||
|
||||
// ocVersion (isOfficialClient patch)
|
||||
// remove after 2.3000.x hard release
|
||||
await page.evaluateOnNewDocument(() => {
|
||||
|
|
@ -979,9 +1008,10 @@ class Client extends EventEmitter {
|
|||
*/
|
||||
async sendMessage(chatId, content, options = {}) {
|
||||
const isChannel = /@\w*newsletter\b/.test(chatId);
|
||||
const isStatus = /@\w*broadcast\b/.test(chatId);
|
||||
|
||||
if (isChannel &amp;&amp; [
|
||||
options.sendMediaAsDocument, options.quotedMessageId,
|
||||
options.sendMediaAsDocument, options.quotedMessageId,
|
||||
options.parseVCards, options.isViewOnce,
|
||||
content instanceof Location, content instanceof Contact,
|
||||
content instanceof Buttons, content instanceof List,
|
||||
|
|
@ -989,6 +1019,16 @@ class Client extends EventEmitter {
|
|||
].includes(true)) {
|
||||
console.warn('The message type is currently not supported for sending in channels,\nthe supported message types are: text, image, sticker, gif, video, voice and poll.');
|
||||
return null;
|
||||
|
||||
} else if (isStatus &amp;&amp; [
|
||||
options.sendMediaAsDocument, options.quotedMessageId,
|
||||
options.parseVCards, options.isViewOnce, options.sendMediaAsSticker,
|
||||
content instanceof Location, content instanceof Contact,
|
||||
content instanceof Poll, content instanceof Buttons, content instanceof List,
|
||||
Array.isArray(content) &amp;&amp; content.length > 0 &amp;&amp; content[0] instanceof Contact
|
||||
].includes(true)) {
|
||||
console.warn('The message type is currently not supported for sending in status broadcast,\nthe supported message types are: text, image, gif, audio and video.');
|
||||
return null;
|
||||
}
|
||||
|
||||
if (options.mentions) {
|
||||
|
|
@ -1224,7 +1264,12 @@ class Client extends EventEmitter {
|
|||
|
||||
return ContactFactory.create(this, contact);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get message by ID
|
||||
* @param {string} messageId
|
||||
* @returns {Promise&lt;Message>}
|
||||
*/
|
||||
async getMessageById(messageId) {
|
||||
const msg = await this.pupPage.evaluate(async messageId => {
|
||||
let msg = window.Store.Msg.get(messageId);
|
||||
|
|
@ -2001,7 +2046,7 @@ class Client extends EventEmitter {
|
|||
|
||||
return labels.map(data => new Label(this, data));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all current Broadcast
|
||||
* @returns {Promise&lt;Array&lt;Broadcast>>}
|
||||
|
|
@ -2013,6 +2058,49 @@ class Client extends EventEmitter {
|
|||
return broadcasts.map(data => new Broadcast(this, data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get broadcast instance by current user ID
|
||||
* @param {string} contactId
|
||||
* @returns {Promise&lt;Broadcast>}
|
||||
*/
|
||||
async getBroadcastById(contactId) {
|
||||
const broadcast = await this.pupPage.evaluate(async (userId) => {
|
||||
let status;
|
||||
try {
|
||||
status = window.Store.Status.get(userId);
|
||||
if (!status) {
|
||||
status = await window.Store.Status.find(userId);
|
||||
}
|
||||
} catch {
|
||||
status = null;
|
||||
}
|
||||
|
||||
if (status) return window.WWebJS.getStatusModel(status);
|
||||
}, contactId);
|
||||
return new Broadcast(this, broadcast);
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke current own status messages
|
||||
* @param {string} messageId
|
||||
* @returns {Promise&lt;void>}
|
||||
*/
|
||||
async revokeStatusMessage(messageId) {
|
||||
return await this.pupPage.evaluate(async (msgId) => {
|
||||
const status = window.Store.Status.getMyStatus();
|
||||
if (!status) return;
|
||||
|
||||
const msg =
|
||||
window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
||||
if (!msg) return;
|
||||
|
||||
if (!msg.id.fromMe || !msg.id.remote.isStatus())
|
||||
throw 'Invalid usage! Can only revoke the message its from own status broadcast';
|
||||
|
||||
return await window.Store.StatusUtils.sendStatusRevokeMsgAction(status, msg);
|
||||
}, messageId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Label instance by ID
|
||||
* @param {string} labelId
|
||||
|
|
@ -2456,7 +2544,7 @@ class Client extends EventEmitter {
|
|||
async getPollVotes(messageId) {
|
||||
const msg = await this.getMessageById(messageId);
|
||||
if (!msg) return [];
|
||||
if (msg.type != 'poll_creation') throw 'Invalid usage! Can only be used with a pollCreation message';
|
||||
if (msg.type != MessageTypes.POLL_CREATION) throw 'Invalid usage! Can only be used with a pollCreation message';
|
||||
|
||||
const pollVotes = await this.pupPage.evaluate( async (msg) => {
|
||||
const msgKey = window.Store.MsgKey.fromString(msg.id._serialized);
|
||||
|
|
@ -2486,7 +2574,7 @@ module.exports = Client;
|
|||
<footer id="jsdoc-footer" class="jsdoc-footer">
|
||||
<div id="jsdoc-footer-container">
|
||||
<p>
|
||||
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.11 on November 6, 2025.
|
||||
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.11 on December 13, 2025.
|
||||
</p>
|
||||
</div>
|
||||
</footer>
|
||||
|
|
|
|||
Loading…
Reference in a new issue