mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
309 lines
12 KiB
HTML
309 lines
12 KiB
HTML
<!doctype html>
|
|
<html>
|
|
|
|
<head>
|
|
<meta name="generator" content="JSDoc 3.6.11">
|
|
<meta charset="utf-8">
|
|
<title>whatsapp-web.js 1.19.4 » Source: structures/GroupChat.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">
|
|
<link href="css/baseline.css" rel="stylesheet">
|
|
</head>
|
|
|
|
<body onload="prettyPrint()">
|
|
<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>19.<wbr>4</a>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
<div id="jsdoc-body-container">
|
|
<div id="jsdoc-content">
|
|
<div id="jsdoc-content-container">
|
|
<div id="jsdoc-banner" role="banner">
|
|
</div>
|
|
<div id="jsdoc-main" role="main">
|
|
<header class="page-header">
|
|
<h1>Source: structures/GroupChat.js</h1>
|
|
</header>
|
|
<article>
|
|
<pre class="prettyprint linenums"><code>'use strict';
|
|
|
|
const Chat = require('./Chat');
|
|
|
|
/**
|
|
* Group participant information
|
|
* @typedef {Object} GroupParticipant
|
|
* @property {ContactId} id
|
|
* @property {boolean} isAdmin
|
|
* @property {boolean} isSuperAdmin
|
|
*/
|
|
|
|
/**
|
|
* Represents a Group Chat on WhatsApp
|
|
* @extends {Chat}
|
|
*/
|
|
class GroupChat extends Chat {
|
|
_patch(data) {
|
|
this.groupMetadata = data.groupMetadata;
|
|
|
|
return super._patch(data);
|
|
}
|
|
|
|
/**
|
|
* Gets the group owner
|
|
* @type {ContactId}
|
|
*/
|
|
get owner() {
|
|
return this.groupMetadata.owner;
|
|
}
|
|
|
|
/**
|
|
* Gets the date at which the group was created
|
|
* @type {date}
|
|
*/
|
|
get createdAt() {
|
|
return new Date(this.groupMetadata.creation * 1000);
|
|
}
|
|
|
|
/**
|
|
* Gets the group description
|
|
* @type {string}
|
|
*/
|
|
get description() {
|
|
return this.groupMetadata.desc;
|
|
}
|
|
|
|
/**
|
|
* Gets the group participants
|
|
* @type {Array&lt;GroupParticipant>}
|
|
*/
|
|
get participants() {
|
|
return this.groupMetadata.participants;
|
|
}
|
|
|
|
/**
|
|
* Adds a list of participants by ID to the group
|
|
* @param {Array&lt;string>} participantIds
|
|
* @returns {Promise&lt;Object>}
|
|
*/
|
|
async addParticipants(participantIds) {
|
|
return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
|
|
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
const chat = await window.Store.Chat.find(chatWid);
|
|
const participants = await Promise.all(participantIds.map(async p => {
|
|
const wid = window.Store.WidFactory.createWid(p);
|
|
return await window.Store.Contact.get(wid);
|
|
}));
|
|
await window.Store.GroupParticipants.addParticipants(chat, participants);
|
|
return { status: 200 };
|
|
}, this.id._serialized, participantIds);
|
|
}
|
|
|
|
/**
|
|
* Removes a list of participants by ID to the group
|
|
* @param {Array&lt;string>} participantIds
|
|
* @returns {Promise&lt;Object>}
|
|
*/
|
|
async removeParticipants(participantIds) {
|
|
return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
|
|
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
const chat = await window.Store.Chat.find(chatWid);
|
|
const participants = participantIds.map(p => {
|
|
return chat.groupMetadata.participants.get(p);
|
|
}).filter(p => Boolean(p));
|
|
await window.Store.GroupParticipants.removeParticipants(chat, participants);
|
|
return { status: 200 };
|
|
}, this.id._serialized, participantIds);
|
|
}
|
|
|
|
/**
|
|
* Promotes participants by IDs to admins
|
|
* @param {Array&lt;string>} participantIds
|
|
* @returns {Promise&lt;{ status: number }>} Object with status code indicating if the operation was successful
|
|
*/
|
|
async promoteParticipants(participantIds) {
|
|
return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
|
|
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
const chat = await window.Store.Chat.find(chatWid);
|
|
const participants = participantIds.map(p => {
|
|
return chat.groupMetadata.participants.get(p);
|
|
}).filter(p => Boolean(p));
|
|
await window.Store.GroupParticipants.promoteParticipants(chat, participants);
|
|
return { status: 200 };
|
|
}, this.id._serialized, participantIds);
|
|
}
|
|
|
|
/**
|
|
* Demotes participants by IDs to regular users
|
|
* @param {Array&lt;string>} participantIds
|
|
* @returns {Promise&lt;{ status: number }>} Object with status code indicating if the operation was successful
|
|
*/
|
|
async demoteParticipants(participantIds) {
|
|
return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
|
|
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
const chat = await window.Store.Chat.find(chatWid);
|
|
const participants = participantIds.map(p => {
|
|
return chat.groupMetadata.participants.get(p);
|
|
}).filter(p => Boolean(p));
|
|
await window.Store.GroupParticipants.demoteParticipants(chat, participants);
|
|
return { status: 200 };
|
|
}, this.id._serialized, participantIds);
|
|
}
|
|
|
|
/**
|
|
* Updates the group subject
|
|
* @param {string} subject
|
|
* @returns {Promise&lt;boolean>} Returns true if the subject was properly updated. This can return false if the user does not have the necessary permissions.
|
|
*/
|
|
async setSubject(subject) {
|
|
const success = await this.client.pupPage.evaluate(async (chatId, subject) => {
|
|
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
try {
|
|
await window.Store.GroupUtils.setGroupSubject(chatWid, subject);
|
|
return true;
|
|
} catch (err) {
|
|
if(err.name === 'ServerStatusCodeError') return false;
|
|
throw err;
|
|
}
|
|
}, this.id._serialized, subject);
|
|
|
|
if(!success) return false;
|
|
this.name = subject;
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Updates the group description
|
|
* @param {string} description
|
|
* @returns {Promise&lt;boolean>} Returns true if the description was properly updated. This can return false if the user does not have the necessary permissions.
|
|
*/
|
|
async setDescription(description) {
|
|
const success = await this.client.pupPage.evaluate(async (chatId, description) => {
|
|
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
let descId = window.Store.GroupMetadata.get(chatWid).descId;
|
|
try {
|
|
await window.Store.GroupUtils.setGroupDescription(chatWid, description, window.Store.MsgKey.newId(), descId);
|
|
return true;
|
|
} catch (err) {
|
|
if(err.name === 'ServerStatusCodeError') return false;
|
|
throw err;
|
|
}
|
|
}, this.id._serialized, description);
|
|
|
|
if(!success) return false;
|
|
this.groupMetadata.desc = description;
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Updates the group settings to only allow admins to send messages.
|
|
* @param {boolean} [adminsOnly=true] Enable or disable this option
|
|
* @returns {Promise&lt;boolean>} Returns true if the setting was properly updated. This can return false if the user does not have the necessary permissions.
|
|
*/
|
|
async setMessagesAdminsOnly(adminsOnly=true) {
|
|
const success = await this.client.pupPage.evaluate(async (chatId, adminsOnly) => {
|
|
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
try {
|
|
await window.Store.GroupUtils.setGroupProperty(chatWid, 'announcement', adminsOnly ? 1 : 0);
|
|
return true;
|
|
} catch (err) {
|
|
if(err.name === 'ServerStatusCodeError') return false;
|
|
throw err;
|
|
}
|
|
}, this.id._serialized, adminsOnly);
|
|
|
|
if(!success) return false;
|
|
|
|
this.groupMetadata.announce = adminsOnly;
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Updates the group settings to only allow admins to edit group info (title, description, photo).
|
|
* @param {boolean} [adminsOnly=true] Enable or disable this option
|
|
* @returns {Promise&lt;boolean>} Returns true if the setting was properly updated. This can return false if the user does not have the necessary permissions.
|
|
*/
|
|
async setInfoAdminsOnly(adminsOnly=true) {
|
|
const success = await this.client.pupPage.evaluate(async (chatId, adminsOnly) => {
|
|
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
try {
|
|
await window.Store.GroupUtils.setGroupProperty(chatWid, 'restrict', adminsOnly ? 1 : 0);
|
|
return true;
|
|
} catch (err) {
|
|
if(err.name === 'ServerStatusCodeError') return false;
|
|
throw err;
|
|
}
|
|
}, this.id._serialized, adminsOnly);
|
|
|
|
if(!success) return false;
|
|
|
|
this.groupMetadata.restrict = adminsOnly;
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Gets the invite code for a specific group
|
|
* @returns {Promise&lt;string>} Group's invite code
|
|
*/
|
|
async getInviteCode() {
|
|
const codeRes = await this.client.pupPage.evaluate(async chatId => {
|
|
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
return window.Store.Invite.queryGroupInviteCode(chatWid);
|
|
}, this.id._serialized);
|
|
|
|
return codeRes.code;
|
|
}
|
|
|
|
/**
|
|
* Invalidates the current group invite code and generates a new one
|
|
* @returns {Promise&lt;string>} New invite code
|
|
*/
|
|
async revokeInvite() {
|
|
const codeRes = await this.client.pupPage.evaluate(chatId => {
|
|
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
return window.Store.Invite.resetGroupInviteCode(chatWid);
|
|
}, this.id._serialized);
|
|
|
|
return codeRes.code;
|
|
}
|
|
|
|
/**
|
|
* Makes the bot leave the group
|
|
* @returns {Promise}
|
|
*/
|
|
async leave() {
|
|
await this.client.pupPage.evaluate(async chatId => {
|
|
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
const chat = await window.Store.Chat.find(chatWid);
|
|
return window.Store.GroupUtils.sendExitGroup(chat);
|
|
}, this.id._serialized);
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = GroupChat;</code></pre>
|
|
</article>
|
|
</div>
|
|
</div>
|
|
<nav id="jsdoc-toc-nav" role="navigation"></nav>
|
|
</div>
|
|
</div>
|
|
<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 February 11, 2023.
|
|
</p>
|
|
</div>
|
|
</footer>
|
|
<script src="scripts/jquery.min.js"></script>
|
|
<script src="scripts/tree.jquery.js"></script>
|
|
<script src="scripts/prettify.js"></script>
|
|
<script src="scripts/jsdoc-toc.js"></script>
|
|
<script src="scripts/linenumber.js"></script>
|
|
<script src="scripts/scrollanchor.js"></script>
|
|
</body>
|
|
|
|
</html> |