mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
236 lines
7.7 KiB
HTML
236 lines
7.7 KiB
HTML
<!doctype html>
|
|
<html>
|
|
|
|
<head>
|
|
<meta name="generator" content="JSDoc 3.6.6">
|
|
<meta charset="utf-8">
|
|
<title>whatsapp-web.js 1.11.1 » 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>11.<wbr>1</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');
|
|
|
|
/**
|
|
* 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
|
|
*/
|
|
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}
|
|
*/
|
|
get participants() {
|
|
return this.groupMetadata.participants;
|
|
}
|
|
|
|
/**
|
|
* Adds a list of participants by ID to the group
|
|
* @param {Array&lt;string>} participantIds
|
|
*/
|
|
async addParticipants(participantIds) {
|
|
return await this.client.pupPage.evaluate((chatId, participantIds) => {
|
|
return window.Store.Wap.addParticipants(chatId, participantIds);
|
|
}, this.id._serialized, participantIds);
|
|
}
|
|
|
|
/**
|
|
* Removes a list of participants by ID to the group
|
|
* @param {Array&lt;string>} participantIds
|
|
*/
|
|
async removeParticipants(participantIds) {
|
|
return await this.client.pupPage.evaluate((chatId, participantIds) => {
|
|
return window.Store.Wap.removeParticipants(chatId, participantIds);
|
|
}, this.id._serialized, participantIds);
|
|
}
|
|
|
|
/**
|
|
* Promotes participants by IDs to admins
|
|
* @param {Array&lt;string>} participantIds
|
|
*/
|
|
async promoteParticipants(participantIds) {
|
|
return await this.client.pupPage.evaluate((chatId, participantIds) => {
|
|
return window.Store.Wap.promoteParticipants(chatId, participantIds);
|
|
}, this.id._serialized, participantIds);
|
|
}
|
|
|
|
/**
|
|
* Demotes participants by IDs to regular users
|
|
* @param {Array&lt;string>} participantIds
|
|
*/
|
|
async demoteParticipants(participantIds) {
|
|
return await this.client.pupPage.evaluate((chatId, participantIds) => {
|
|
return window.Store.Wap.demoteParticipants(chatId, participantIds);
|
|
}, this.id._serialized, participantIds);
|
|
}
|
|
|
|
/**
|
|
* Updates the group subject
|
|
* @param {string} subject
|
|
*/
|
|
async setSubject(subject) {
|
|
let res = await this.client.pupPage.evaluate((chatId, subject) => {
|
|
return window.Store.Wap.changeSubject(chatId, subject);
|
|
}, this.id._serialized, subject);
|
|
|
|
if(res.status == 200) {
|
|
this.name = subject;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Updates the group description
|
|
* @param {string} description
|
|
*/
|
|
async setDescription(description) {
|
|
let res = await this.client.pupPage.evaluate((chatId, description) => {
|
|
let descId = window.Store.GroupMetadata.get(chatId).descId;
|
|
return window.Store.Wap.setGroupDescription(chatId, description, window.Store.genId(), descId);
|
|
}, this.id._serialized, description);
|
|
|
|
if (res.status == 200) {
|
|
this.groupMetadata.desc = description;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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) {
|
|
let res = await this.client.pupPage.evaluate((chatId, value) => {
|
|
return window.Store.Wap.setGroupProperty(chatId, 'announcement', value);
|
|
}, this.id._serialized, adminsOnly);
|
|
|
|
if (res.status !== 200) 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) {
|
|
let res = await this.client.pupPage.evaluate((chatId, value) => {
|
|
return window.Store.Wap.setGroupProperty(chatId, 'restrict', value);
|
|
}, this.id._serialized, adminsOnly);
|
|
|
|
if (res.status !== 200) return false;
|
|
|
|
this.groupMetadata.restrict = adminsOnly;
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Gets the invite code for a specific group
|
|
*/
|
|
async getInviteCode() {
|
|
let res = await this.client.pupPage.evaluate(chatId => {
|
|
return window.Store.Wap.groupInviteCode(chatId);
|
|
}, this.id._serialized);
|
|
|
|
if (res.status == 200) {
|
|
return res.code;
|
|
}
|
|
|
|
throw new Error('Not authorized');
|
|
}
|
|
|
|
/**
|
|
* Invalidates the current group invite code and generates a new one
|
|
*/
|
|
async revokeInvite() {
|
|
return await this.client.pupPage.evaluate(chatId => {
|
|
return window.Store.Wap.revokeGroupInvite(chatId);
|
|
}, this.id._serialized);
|
|
}
|
|
|
|
/**
|
|
* Makes the bot leave the group
|
|
*/
|
|
async leave() {
|
|
return await this.client.pupPage.evaluate(chatId => {
|
|
return window.Store.Wap.leaveGroup(chatId);
|
|
}, 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.6 on November 19, 2020.
|
|
</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> |