diff --git a/index.d.ts b/index.d.ts index 886b783..5525d1d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -822,6 +822,69 @@ declare namespace WAWebJS { export interface PrivateChat extends Chat { } + + export type GroupParticipant = { + id: ContactId, + isAdmin: boolean + isSuperAdmin: boolean + } + + /** Promotes or demotes participants by IDs to regular users or admins */ + export type ChangeParticipantsPermisions = + (participantIds: Array) => Promise<{ status: number }> + + /** Adds or removes a list of participants by ID to the group */ + export type ChangeGroupParticipants = + (participantIds: Array) => Promise<{ + status: number; + participants: Array<{ + [key: string]: { + code: number + } + }> + } & { + [key: string]: number; + }> + + export interface GroupChat extends Chat { + /** Group owner */ + owner: ContactId; + /** Date at which the group was created */ + createdAt: Date; + /** Group description */ + description: string; + /** Group participants */ + participants: Array; + /** Adds a list of participants by ID to the group */ + addParticipants: ChangeGroupParticipants; + /** Removes a list of participants by ID to the group */ + removeParticipants: ChangeGroupParticipants; + /** Promotes participants by IDs to admins */ + promoteParticipants: ChangeParticipantsPermisions; + /** Demotes participants by IDs to regular users */ + demoteParticipants: ChangeParticipantsPermisions; + /** Updates the group subject */ + setSubject: (subject: string) => Promise; + /** Updates the group description */ + setDescription: (description: string) => Promise; + /** Updates the group settings to only allow admins to send messages + * @param {boolean} [adminsOnly=true] Enable or disable this option + * @returns {Promise} Returns true if the setting was properly updated. This can return false if the user does not have the necessary permissions. + */ + setMessagesAdminsOnly: (adminsOnly?: boolean) => Promise; + /** + * 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} Returns true if the setting was properly updated. This can return false if the user does not have the necessary permissions. + */ + setInfoAdminsOnly: (adminsOnly?: boolean) => Promise; + /** Gets the invite code for a specific group */ + getInviteCode: () => Promise; + /** Invalidates the current group invite code and generates a new one */ + revokeInvite: () => Promise; + /** Makes the bot leave the group */ + leave: () => Promise; + } } export = WAWebJS diff --git a/src/structures/Contact.js b/src/structures/Contact.js index f8ec4e9..09d721c 100644 --- a/src/structures/Contact.js +++ b/src/structures/Contact.js @@ -2,6 +2,14 @@ const Base = require('./Base'); +/** + * ID that represents a contact + * @typedef {Object} ContactId + * @property {string} server + * @property {string} user + * @property {string} _serialized + */ + /** * Represents a Contact on WhatsApp * @extends {Base} @@ -16,7 +24,7 @@ class Contact extends Base { _patch(data) { /** * ID that represents the contact - * @type {object} + * @type {ContactId} */ this.id = data.id; diff --git a/src/structures/GroupChat.js b/src/structures/GroupChat.js index 988c5c9..76ff151 100644 --- a/src/structures/GroupChat.js +++ b/src/structures/GroupChat.js @@ -2,6 +2,14 @@ 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} @@ -15,6 +23,7 @@ class GroupChat extends Chat { /** * Gets the group owner + * @type {ContactId} */ get owner() { return this.groupMetadata.owner; @@ -38,7 +47,7 @@ class GroupChat extends Chat { /** * Gets the group participants - * @type {array} + * @type {Array} */ get participants() { return this.groupMetadata.participants; @@ -47,6 +56,7 @@ class GroupChat extends Chat { /** * Adds a list of participants by ID to the group * @param {Array} participantIds + * @returns {Promise} */ async addParticipants(participantIds) { return await this.client.pupPage.evaluate((chatId, participantIds) => { @@ -57,6 +67,7 @@ class GroupChat extends Chat { /** * Removes a list of participants by ID to the group * @param {Array} participantIds + * @returns {Promise} */ async removeParticipants(participantIds) { return await this.client.pupPage.evaluate((chatId, participantIds) => { @@ -67,6 +78,7 @@ class GroupChat extends Chat { /** * Promotes participants by IDs to admins * @param {Array} participantIds + * @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful */ async promoteParticipants(participantIds) { return await this.client.pupPage.evaluate((chatId, participantIds) => { @@ -77,6 +89,7 @@ class GroupChat extends Chat { /** * Demotes participants by IDs to regular users * @param {Array} participantIds + * @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful */ async demoteParticipants(participantIds) { return await this.client.pupPage.evaluate((chatId, participantIds) => { @@ -87,6 +100,7 @@ class GroupChat extends Chat { /** * Updates the group subject * @param {string} subject + * @returns {Promise} */ async setSubject(subject) { let res = await this.client.pupPage.evaluate((chatId, subject) => { @@ -101,6 +115,7 @@ class GroupChat extends Chat { /** * Updates the group description * @param {string} description + * @returns {Promise} */ async setDescription(description) { let res = await this.client.pupPage.evaluate((chatId, description) => { @@ -147,6 +162,7 @@ class GroupChat extends Chat { /** * Gets the invite code for a specific group + * @returns {Promise} Group's invite code */ async getInviteCode() { let res = await this.client.pupPage.evaluate(chatId => { @@ -162,6 +178,7 @@ class GroupChat extends Chat { /** * Invalidates the current group invite code and generates a new one + * @returns {Promise} */ async revokeInvite() { return await this.client.pupPage.evaluate(chatId => { @@ -171,6 +188,7 @@ class GroupChat extends Chat { /** * Makes the bot leave the group + * @returns {Promise} */ async leave() { return await this.client.pupPage.evaluate(chatId => {