chore: mark version v1.22.0
This commit is contained in:
parent
8bd2624866
commit
a1bbd25fd3
66 changed files with 846 additions and 284 deletions
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta name="generator" content="JSDoc 3.6.11">
|
||||
<meta charset="utf-8">
|
||||
<title>whatsapp-web.js 1.21.0 » Source: Client.js</title>
|
||||
<title>whatsapp-web.js 1.22.0 » 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>21.<wbr>0</a>
|
||||
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>22.<wbr>0</a>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
|
@ -269,9 +269,9 @@ class Client extends EventEmitter {
|
|||
// Listens to qr token change
|
||||
if (mut.type === 'attributes' &amp;&amp; mut.attributeName === 'data-ref') {
|
||||
window.qrChanged(mut.target.dataset.ref);
|
||||
} else
|
||||
}
|
||||
// Listens to retry button, when found, click it
|
||||
if (mut.type === 'childList') {
|
||||
else if (mut.type === 'childList') {
|
||||
const retry_button = document.querySelector(selectors.QR_RETRY_BUTTON);
|
||||
if (retry_button) retry_button.click();
|
||||
}
|
||||
|
|
@ -306,6 +306,50 @@ class Client extends EventEmitter {
|
|||
|
||||
}
|
||||
|
||||
await page.evaluate(() => {
|
||||
/**
|
||||
* Helper function that compares between two WWeb versions. Its purpose is to help the developer to choose the correct code implementation depending on the comparison value and the WWeb version.
|
||||
* @param {string} lOperand The left operand for the WWeb version string to compare with
|
||||
* @param {string} operator The comparison operator
|
||||
* @param {string} rOperand The right operand for the WWeb version string to compare with
|
||||
* @returns {boolean} Boolean value that indicates the result of the comparison
|
||||
*/
|
||||
window.compareWwebVersions = (lOperand, operator, rOperand) => {
|
||||
if (!['>', '>=', '&lt;', '&lt;=', '='].includes(operator)) {
|
||||
throw class _ extends Error {
|
||||
constructor(m) { super(m); this.name = 'CompareWwebVersionsError'; }
|
||||
}('Invalid comparison operator is provided');
|
||||
|
||||
}
|
||||
if (typeof lOperand !== 'string' || typeof rOperand !== 'string') {
|
||||
throw class _ extends Error {
|
||||
constructor(m) { super(m); this.name = 'CompareWwebVersionsError'; }
|
||||
}('A non-string WWeb version type is provided');
|
||||
}
|
||||
|
||||
lOperand = lOperand.replace(/-beta$/, '');
|
||||
rOperand = rOperand.replace(/-beta$/, '');
|
||||
|
||||
while (lOperand.length !== rOperand.length) {
|
||||
lOperand.length > rOperand.length
|
||||
? rOperand = rOperand.concat('0')
|
||||
: lOperand = lOperand.concat('0');
|
||||
}
|
||||
|
||||
lOperand = Number(lOperand.replace(/\./g, ''));
|
||||
rOperand = Number(rOperand.replace(/\./g, ''));
|
||||
|
||||
return (
|
||||
operator === '>' ? lOperand > rOperand :
|
||||
operator === '>=' ? lOperand >= rOperand :
|
||||
operator === '&lt;' ? lOperand &lt; rOperand :
|
||||
operator === '&lt;=' ? lOperand &lt;= rOperand :
|
||||
operator === '=' ? lOperand === rOperand :
|
||||
false
|
||||
);
|
||||
};
|
||||
});
|
||||
|
||||
await page.evaluate(ExposeStore, moduleRaid.toString());
|
||||
const authEventPayload = await this.authStrategy.getAuthEventPayload();
|
||||
|
||||
|
|
@ -345,7 +389,7 @@ class Client extends EventEmitter {
|
|||
await page.exposeFunction('onAddMessageEvent', msg => {
|
||||
if (msg.type === 'gp2') {
|
||||
const notification = new GroupNotification(this, msg);
|
||||
if (msg.subtype === 'add' || msg.subtype === 'invite') {
|
||||
if (['add', 'invite', 'linked_group_join'].includes(msg.subtype)) {
|
||||
/**
|
||||
* Emitted when a user joins the chat via invite link or is added by an admin.
|
||||
* @event Client#group_join
|
||||
|
|
@ -427,18 +471,18 @@ class Client extends EventEmitter {
|
|||
|
||||
/**
|
||||
* The event notification that is received when one of
|
||||
* the group participants changes thier phone number.
|
||||
* the group participants changes their phone number.
|
||||
*/
|
||||
const isParticipant = msg.type === 'gp2' &amp;&amp; msg.subtype === 'modify';
|
||||
|
||||
/**
|
||||
* The event notification that is received when one of
|
||||
* the contacts changes thier phone number.
|
||||
* the contacts changes their phone number.
|
||||
*/
|
||||
const isContact = msg.type === 'notification_template' &amp;&amp; msg.subtype === 'change_number';
|
||||
|
||||
if (isParticipant || isContact) {
|
||||
/** {@link GroupNotification} object does not provide enough information about this event, so a {@link Message} object is used. */
|
||||
/** @type {GroupNotification} object does not provide enough information about this event, so a @type {Message} object is used. */
|
||||
const message = new Message(this, msg);
|
||||
|
||||
const newId = isParticipant ? msg.recipients[0] : msg.to;
|
||||
|
|
@ -615,12 +659,28 @@ class Client extends EventEmitter {
|
|||
this.emit(Events.CHAT_ARCHIVED, new Chat(this, chat), currState, prevState);
|
||||
});
|
||||
|
||||
await page.exposeFunction('onEditMessageEvent', (msg, newBody, prevBody) => {
|
||||
|
||||
if(msg.type === 'revoked'){
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Emitted when messages are edited
|
||||
* @event Client#message_edit
|
||||
* @param {Message} message
|
||||
* @param {string} newBody
|
||||
* @param {string} prevBody
|
||||
*/
|
||||
this.emit(Events.MESSAGE_EDIT, new Message(this, msg), newBody, prevBody);
|
||||
});
|
||||
|
||||
await page.evaluate(() => {
|
||||
window.Store.Msg.on('change', (msg) => { window.onChangeMessageEvent(window.WWebJS.getMessageModel(msg)); });
|
||||
window.Store.Msg.on('change:type', (msg) => { window.onChangeMessageTypeEvent(window.WWebJS.getMessageModel(msg)); });
|
||||
window.Store.Msg.on('change:ack', (msg, ack) => { window.onMessageAckEvent(window.WWebJS.getMessageModel(msg), ack); });
|
||||
window.Store.Msg.on('change:isUnsentMedia', (msg, unsent) => { if (msg.id.fromMe &amp;&amp; !unsent) window.onMessageMediaUploadedEvent(window.WWebJS.getMessageModel(msg)); });
|
||||
window.Store.Msg.on('remove', (msg) => { if (msg.isNewMsg) window.onRemoveMessageEvent(window.WWebJS.getMessageModel(msg)); });
|
||||
window.Store.Msg.on('change:body', (msg, newBody, prevBody) => { window.onEditMessageEvent(window.WWebJS.getMessageModel(msg), newBody, prevBody); });
|
||||
window.Store.AppState.on('change:state', (_AppState, state) => { window.onAppStateChangedEvent(state); });
|
||||
window.Store.Conn.on('change:battery', (state) => { window.onBatteryStateChangedEvent(state); });
|
||||
window.Store.Call.on('add', (call) => { window.onIncomingCall(call); });
|
||||
|
|
@ -717,7 +777,14 @@ class Client extends EventEmitter {
|
|||
await this.pupPage.evaluate(() => {
|
||||
return window.Store.AppState.logout();
|
||||
});
|
||||
|
||||
await this.pupBrowser.close();
|
||||
|
||||
let maxDelay = 0;
|
||||
while (this.pupBrowser.isConnected() &amp;&amp; (maxDelay &lt; 10)) { // waits a maximum of 1 second before calling the AuthStrategy
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
maxDelay++;
|
||||
}
|
||||
|
||||
await this.authStrategy.logout();
|
||||
}
|
||||
|
||||
|
|
@ -753,6 +820,7 @@ class Client extends EventEmitter {
|
|||
* @property {boolean} [sendVideoAsGif=false] - Send video as gif
|
||||
* @property {boolean} [sendMediaAsSticker=false] - Send media as a sticker
|
||||
* @property {boolean} [sendMediaAsDocument=false] - Send media as a document
|
||||
* @property {boolean} [isViewOnce=false] - Send photo/video as a view once message
|
||||
* @property {boolean} [parseVCards=true] - Automatically parse vCards and send them as contacts
|
||||
* @property {string} [caption] - Image or video caption
|
||||
* @property {string} [quotedMessageId] - Id of the message that is being quoted (or replied to)
|
||||
|
|
@ -763,7 +831,7 @@ class Client extends EventEmitter {
|
|||
* @property {string[]} [stickerCategories=undefined] - Sets the categories of the sticker, (if sendMediaAsSticker is true). Provide emoji char array, can be null.
|
||||
* @property {MessageMedia} [media] - Media to be sent
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Send a message to a specific chatId
|
||||
* @param {string} chatId
|
||||
|
|
@ -773,6 +841,10 @@ class Client extends EventEmitter {
|
|||
* @returns {Promise&lt;Message>} Message that was just sent
|
||||
*/
|
||||
async sendMessage(chatId, content, options = {}) {
|
||||
if (options.mentions &amp;&amp; options.mentions.some(possiblyContact => possiblyContact instanceof Contact)) {
|
||||
console.warn('Mentions with an array of Contact are now deprecated. See more at https://github.com/pedroslopez/whatsapp-web.js/pull/2166.');
|
||||
options.mentions = options.mentions.map(a => a.id._serialized);
|
||||
}
|
||||
let internalOptions = {
|
||||
linkPreview: options.linkPreview === false ? undefined : true,
|
||||
sendAudioAsVoice: options.sendAudioAsVoice,
|
||||
|
|
@ -782,7 +854,7 @@ class Client extends EventEmitter {
|
|||
caption: options.caption,
|
||||
quotedMessageId: options.quotedMessageId,
|
||||
parseVCards: options.parseVCards === false ? false : true,
|
||||
mentionedJidList: Array.isArray(options.mentions) ? options.mentions.map(contact => contact.id._serialized) : [],
|
||||
mentionedJidList: Array.isArray(options.mentions) ? options.mentions : [],
|
||||
extraOptions: options.extra
|
||||
};
|
||||
|
||||
|
|
@ -790,10 +862,12 @@ class Client extends EventEmitter {
|
|||
|
||||
if (content instanceof MessageMedia) {
|
||||
internalOptions.attachment = content;
|
||||
internalOptions.isViewOnce = options.isViewOnce,
|
||||
content = '';
|
||||
} else if (options.media instanceof MessageMedia) {
|
||||
internalOptions.attachment = options.media;
|
||||
internalOptions.caption = content;
|
||||
internalOptions.isViewOnce = options.isViewOnce,
|
||||
content = '';
|
||||
} else if (content instanceof Location) {
|
||||
internalOptions.location = content;
|
||||
|
|
@ -812,7 +886,7 @@ class Client extends EventEmitter {
|
|||
internalOptions.list = content;
|
||||
content = '';
|
||||
}
|
||||
|
||||
|
||||
if (internalOptions.sendMediaAsSticker &amp;&amp; internalOptions.attachment) {
|
||||
internalOptions.attachment = await Util.formatToWebpSticker(
|
||||
internalOptions.attachment, {
|
||||
|
|
@ -838,7 +912,7 @@ class Client extends EventEmitter {
|
|||
|
||||
return new Message(this, newMessage);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Searches for messages
|
||||
* @param {string} query
|
||||
|
|
@ -906,6 +980,24 @@ class Client extends EventEmitter {
|
|||
|
||||
return ContactFactory.create(this, contact);
|
||||
}
|
||||
|
||||
async getMessageById(messageId) {
|
||||
const msg = await this.pupPage.evaluate(async messageId => {
|
||||
let msg = window.Store.Msg.get(messageId);
|
||||
if(msg) return window.WWebJS.getMessageModel(msg);
|
||||
|
||||
const params = messageId.split('_');
|
||||
if(params.length !== 3) throw new Error('Invalid serialized message id specified');
|
||||
|
||||
let messagesObject = await window.Store.Msg.getMessagesById([messageId]);
|
||||
if (messagesObject &amp;&amp; messagesObject.messages.length) msg = messagesObject.messages[0];
|
||||
|
||||
if(msg) return window.WWebJS.getMessageModel(msg);
|
||||
}, messageId);
|
||||
|
||||
if(msg) return new Message(this, msg);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object with information about the invite code's group
|
||||
|
|
@ -941,7 +1033,8 @@ class Client extends EventEmitter {
|
|||
if (inviteInfo.inviteCodeExp == 0) throw 'Expired invite code';
|
||||
return this.pupPage.evaluate(async inviteInfo => {
|
||||
let { groupId, fromId, inviteCode, inviteCodeExp } = inviteInfo;
|
||||
return await window.Store.JoinInviteV4.sendJoinGroupViaInviteV4(inviteCode, String(inviteCodeExp), groupId, fromId);
|
||||
let userWid = window.Store.WidFactory.createWid(fromId);
|
||||
return await window.Store.JoinInviteV4.joinGroupViaInviteV4(inviteCode, String(inviteCodeExp), groupId, userWid);
|
||||
}, inviteInfo);
|
||||
}
|
||||
|
||||
|
|
@ -1343,6 +1436,35 @@ class Client extends EventEmitter {
|
|||
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change labels in chats
|
||||
* @param {Array&lt;number|string>} labelIds
|
||||
* @param {Array&lt;string>} chatIds
|
||||
* @returns {Promise&lt;void>}
|
||||
*/
|
||||
async addOrRemoveLabels(labelIds, chatIds) {
|
||||
|
||||
return this.pupPage.evaluate(async (labelIds, chatIds) => {
|
||||
if (['smba', 'smbi'].indexOf(window.Store.Conn.platform) === -1) {
|
||||
throw '[LT01] Only Whatsapp business';
|
||||
}
|
||||
const labels = window.WWebJS.getLabels().filter(e => labelIds.find(l => l == e.id) !== undefined);
|
||||
const chats = window.Store.Chat.filter(e => chatIds.includes(e.id._serialized));
|
||||
|
||||
let actions = labels.map(label => ({id: label.id, type: 'add'}));
|
||||
|
||||
chats.forEach(chat => {
|
||||
(chat.labels || []).forEach(n => {
|
||||
if (!actions.find(e => e.id == n)) {
|
||||
actions.push({id: n, type: 'remove'});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return await window.Store.Label.addOrRemoveLabels(actions, chats);
|
||||
}, labelIds, chatIds);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Client;
|
||||
|
|
@ -1356,7 +1478,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 May 29, 2023.
|
||||
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.11 on August 10, 2023.
|
||||
</p>
|
||||
</div>
|
||||
</footer>
|
||||
|
|
|
|||
Loading…
Reference in a new issue