forked from pedroslopez/whatsapp-web.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstructures_GroupChat.js.html
287 lines (255 loc) · 10.9 KB
/
structures_GroupChat.js.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<!doctype html>
<html>
<head>
<meta name="generator" content="JSDoc 3.6.7">
<meta charset="utf-8">
<title>whatsapp-web.js 1.16.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>16.<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((chatId, participantIds) => {
const chatWid = window.Store.WidFactory.createWid(chatId);
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
return window.Store.GroupParticipants.sendAddParticipants(chatWid, participantWids);
}, 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((chatId, participantIds) => {
const chatWid = window.Store.WidFactory.createWid(chatId);
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
return window.Store.GroupParticipants.sendRemoveParticipants(chatWid, participantWids);
}, 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((chatId, participantIds) => {
const chatWid = window.Store.WidFactory.createWid(chatId);
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
return window.Store.GroupParticipants.sendPromoteParticipants(chatWid, participantWids);
}, 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((chatId, participantIds) => {
const chatWid = window.Store.WidFactory.createWid(chatId);
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
return window.Store.GroupParticipants.sendDemoteParticipants(chatWid, participantWids);
}, 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 {
return await window.Store.GroupUtils.sendSetGroupSubject(chatWid, subject);
} 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 {
return await window.Store.GroupUtils.sendSetGroupDescription(chatWid, description, window.Store.MsgKey.newId(), descId);
} 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 {
return await window.Store.GroupUtils.sendSetGroupProperty(chatWid, 'announcement', adminsOnly ? 1 : 0);
} 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 {
return await window.Store.GroupUtils.sendSetGroupProperty(chatWid, 'restrict', adminsOnly ? 1 : 0);
} 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 code = await this.client.pupPage.evaluate(async chatId => {
const chatWid = window.Store.WidFactory.createWid(chatId);
return window.Store.Invite.sendQueryGroupInviteCode(chatWid);
}, this.id._serialized);
return code;
}
/**
* Invalidates the current group invite code and generates a new one
* @returns {Promise&lt;string>} New invite code
*/
async revokeInvite() {
const code = await this.client.pupPage.evaluate(chatId => {
const chatWid = window.Store.WidFactory.createWid(chatId);
return window.Store.Invite.sendRevokeGroupInviteCode(chatWid);
}, this.id._serialized);
return code;
}
/**
* Makes the bot leave the group
* @returns {Promise}
*/
async leave() {
await this.client.pupPage.evaluate(chatId => {
const chatWid = window.Store.WidFactory.createWid(chatId);
return window.Store.GroupUtils.sendExitGroup(chatWid);
}, 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.7 on March 9, 2022.
</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>