feat: update group controller

This commit is contained in:
Anton Voylenko 2024-12-09 15:14:02 +02:00
commit 7f509fc029
4 changed files with 931 additions and 110 deletions

View file

@ -2,6 +2,33 @@ const { MessageMedia } = require('whatsapp-web.js')
const { sessions } = require('../sessions') const { sessions } = require('../sessions')
const { sendErrorResponse } = require('../utils') const { sendErrorResponse } = require('../utils')
/**
* Retrieves information about a chat based on the provided chatId
*
* @async
* @function getClassInfo
* @param {object} req - The request object
* @param {object} res - The response object
* @param {string} req.body.chatId - The chatId of the chat to retrieve information about
* @param {string} req.params.sessionId - The sessionId of the client making the request
* @throws {Error} The chat is not a group.
* @returns {Promise<void>} - A JSON response with success true and chat object containing chat information
*/
const getClassInfo = async (req, res) => {
/*
#swagger.summary = 'Get the group'
*/
try {
const { chatId } = req.body
const client = sessions.get(req.params.sessionId)
const chat = await client.getChatById(chatId)
if (!chat.isGroup) { throw new Error('The chat is not a group') }
res.json({ success: true, chat })
} catch (error) {
sendErrorResponse(res, 500, error.message)
}
}
/** /**
* Adds participants to a group chat. * Adds participants to a group chat.
* @async * @async
@ -14,13 +41,40 @@ const { sendErrorResponse } = require('../utils')
* @throws {Error} Throws an error if the chat is not a group chat. * @throws {Error} Throws an error if the chat is not a group chat.
*/ */
const addParticipants = async (req, res) => { const addParticipants = async (req, res) => {
/*
#swagger.summary = 'Add the participant(s)'
#swagger.description = 'Add a list of participants by id to the group'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'Unique WhatsApp id for the given chat group',
example: 'XXXXXXXXXX@g.us'
},
contactIds: {
type: 'string',
description: 'Unique WhatsApp identifier for the contact',
example: '6281288888887@c.us'
},
options: {
type: 'object',
description: 'Options for adding participants',
example: { sleep: [250, 500], comment: '' }
}
}
}
}
*/
try { try {
const { chatId, contactIds } = req.body const { chatId, contactIds, options = {} } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const chat = await client.getChatById(chatId) const chat = await client.getChatById(chatId)
if (!chat.isGroup) { throw new Error('The chat is not a group') } if (!chat.isGroup) { throw new Error('The chat is not a group') }
await chat.addParticipants(contactIds) const result = Object.keys(options).length ? await chat.addParticipants(contactIds, options) : await chat.addParticipants(contactIds)
res.json({ success: true, participants: chat.participants }) res.json({ success: true, result })
} catch (error) { } catch (error) {
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
@ -37,13 +91,35 @@ const addParticipants = async (req, res) => {
* @throws {Error} If chat is not a group * @throws {Error} If chat is not a group
*/ */
const removeParticipants = async (req, res) => { const removeParticipants = async (req, res) => {
/*
#swagger.summary = 'Remove the participant(s)'
#swagger.description = 'Remove a list of participants by ID to the group'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'Unique WhatsApp id for the given chat group',
example: 'XXXXXXXXXX@g.us'
},
contactIds: {
type: 'string',
description: 'Unique WhatsApp identifier for the contact',
example: '6281288888887@c.us'
}
}
}
}
*/
try { try {
const { chatId, contactIds } = req.body const { chatId, contactIds } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const chat = await client.getChatById(chatId) const chat = await client.getChatById(chatId)
if (!chat.isGroup) { throw new Error('The chat is not a group') } if (!chat.isGroup) { throw new Error('The chat is not a group') }
await chat.removeParticipants(contactIds) const result = await chat.removeParticipants(contactIds)
res.json({ success: true, participants: chat.participants }) res.json({ success: true, result })
} catch (error) { } catch (error) {
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
@ -60,13 +136,35 @@ const removeParticipants = async (req, res) => {
* @throws {Error} If chat is not a group * @throws {Error} If chat is not a group
*/ */
const promoteParticipants = async (req, res) => { const promoteParticipants = async (req, res) => {
/*
#swagger.summary = 'Promote the participant(s)'
#swagger.description = 'Promote participants by IDs to admins'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'Unique WhatsApp id for the given chat group',
example: 'XXXXXXXXXX@g.us'
},
contactIds: {
type: 'string',
description: 'Unique WhatsApp identifier for the contact',
example: '6281288888887@c.us'
}
}
}
}
*/
try { try {
const { chatId, contactIds } = req.body const { chatId, contactIds } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const chat = await client.getChatById(chatId) const chat = await client.getChatById(chatId)
if (!chat.isGroup) { throw new Error('The chat is not a group') } if (!chat.isGroup) { throw new Error('The chat is not a group') }
await chat.promoteParticipants(contactIds) const result = await chat.promoteParticipants(contactIds)
res.json({ success: true, participants: chat.participants }) res.json({ success: true, result })
} catch (error) { } catch (error) {
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
@ -83,13 +181,35 @@ const promoteParticipants = async (req, res) => {
* @throws {Error} If chat is not a group * @throws {Error} If chat is not a group
*/ */
const demoteParticipants = async (req, res) => { const demoteParticipants = async (req, res) => {
/*
#swagger.summary = 'Demote the participant(s)'
#swagger.description = 'Demote participants by ids to regular users'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'Unique WhatsApp id for the given chat group',
example: 'XXXXXXXXXX@g.us'
},
contactIds: {
type: 'string',
description: 'Unique WhatsApp identifier for the contact',
example: '6281288888887@c.us'
}
}
}
}
*/
try { try {
const { chatId, contactIds } = req.body const { chatId, contactIds } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const chat = await client.getChatById(chatId) const chat = await client.getChatById(chatId)
if (!chat.isGroup) { throw new Error('The chat is not a group') } if (!chat.isGroup) { throw new Error('The chat is not a group') }
await chat.demoteParticipants(contactIds) const result = await chat.demoteParticipants(contactIds)
res.json({ success: true, participants: chat.participants }) res.json({ success: true, result })
} catch (error) { } catch (error) {
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
@ -106,6 +226,10 @@ const demoteParticipants = async (req, res) => {
* @throws {Error} If chat is not a group * @throws {Error} If chat is not a group
*/ */
const getInviteCode = async (req, res) => { const getInviteCode = async (req, res) => {
/*
#swagger.summary = 'Get the invite code'
#swagger.description = 'Get the invite code for a specific group'
*/
try { try {
const { chatId } = req.body const { chatId } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
@ -129,13 +253,34 @@ const getInviteCode = async (req, res) => {
* @throws {Error} If chat is not a group * @throws {Error} If chat is not a group
*/ */
const setSubject = async (req, res) => { const setSubject = async (req, res) => {
/*
#swagger.summary = 'Update the group subject'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'Unique WhatsApp id for the given chat group',
example: 'XXXXXXXXXX@g.us'
},
subject: {
type: 'string',
description: 'Group subject',
example: ''
}
}
}
}
*/
try { try {
const { chatId, subject } = req.body const { chatId, subject } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const chat = await client.getChatById(chatId) const chat = await client.getChatById(chatId)
if (!chat.isGroup) { throw new Error('The chat is not a group') } if (!chat.isGroup) { throw new Error('The chat is not a group') }
const success = await chat.setSubject(subject) const result = await chat.setSubject(subject)
res.json({ success, chat }) res.json({ success: true, result })
} catch (error) { } catch (error) {
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
@ -152,13 +297,34 @@ const setSubject = async (req, res) => {
* @throws {Error} If chat is not a group * @throws {Error} If chat is not a group
*/ */
const setDescription = async (req, res) => { const setDescription = async (req, res) => {
/*
#swagger.summary = 'Update the group description'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'Unique WhatsApp id for the given chat group',
example: 'XXXXXXXXXX@g.us'
},
description: {
type: 'string',
description: 'Group description',
example: ''
}
}
}
}
*/
try { try {
const { chatId, description } = req.body const { chatId, description } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const chat = await client.getChatById(chatId) const chat = await client.getChatById(chatId)
if (!chat.isGroup) { throw new Error('The chat is not a group') } if (!chat.isGroup) { throw new Error('The chat is not a group') }
const success = await chat.setDescription(description) const result = await chat.setDescription(description)
res.json({ success, chat }) res.json({ success: true, result })
} catch (error) { } catch (error) {
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
@ -175,37 +341,16 @@ const setDescription = async (req, res) => {
* @throws {Error} If chat is not a group * @throws {Error} If chat is not a group
*/ */
const leave = async (req, res) => { const leave = async (req, res) => {
/*
#swagger.summary = 'Leave the group'
*/
try { try {
const { chatId } = req.body const { chatId } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const chat = await client.getChatById(chatId) const chat = await client.getChatById(chatId)
if (!chat.isGroup) { throw new Error('The chat is not a group') } if (!chat.isGroup) { throw new Error('The chat is not a group') }
const outcome = await chat.leave() const result = await chat.leave()
res.json({ success: true, outcome }) res.json({ success: true, result })
} catch (error) {
sendErrorResponse(res, 500, error.message)
}
}
/**
* Retrieves information about a chat based on the provided chatId
*
* @async
* @function getClassInfo
* @param {object} req - The request object
* @param {object} res - The response object
* @param {string} req.body.chatId - The chatId of the chat to retrieve information about
* @param {string} req.params.sessionId - The sessionId of the client making the request
* @throws {Error} The chat is not a group.
* @returns {Promise<void>} - A JSON response with success true and chat object containing chat information
*/
const getClassInfo = async (req, res) => {
try {
const { chatId } = req.body
const client = sessions.get(req.params.sessionId)
const chat = await client.getChatById(chatId)
if (!chat.isGroup) { throw new Error('The chat is not a group') }
res.json({ success: true, chat })
} catch (error) { } catch (error) {
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
@ -224,13 +369,17 @@ const getClassInfo = async (req, res) => {
* @returns {Promise<void>} - A JSON response with success true and the new invite code for the group chat * @returns {Promise<void>} - A JSON response with success true and the new invite code for the group chat
*/ */
const revokeInvite = async (req, res) => { const revokeInvite = async (req, res) => {
/*
#swagger.summary = 'Invalidate the invite code'
#swagger.description = 'Invalidate the current group invite code and generates a new one'
*/
try { try {
const { chatId } = req.body const { chatId } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const chat = await client.getChatById(chatId) const chat = await client.getChatById(chatId)
if (!chat.isGroup) { throw new Error('The chat is not a group') } if (!chat.isGroup) { throw new Error('The chat is not a group') }
const newInviteCode = await chat.revokeInvite() const result = await chat.revokeInvite()
res.json({ success: true, newInviteCode }) res.json({ success: true, result })
} catch (error) { } catch (error) {
sendErrorResponse(res, 500, error.message) sendErrorResponse(res, 500, error.message)
} }
@ -251,8 +400,30 @@ const revokeInvite = async (req, res) => {
* @throws {Error} If the chat is not a group. * @throws {Error} If the chat is not a group.
*/ */
const setInfoAdminsOnly = async (req, res) => { const setInfoAdminsOnly = async (req, res) => {
/*
#swagger.summary = 'Update the info group settings'
#swagger.summary = 'Update the group settings to only allow admins to edit group info (title, description, photo).'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'Unique WhatsApp id for the given chat group',
example: 'XXXXXXXXXX@g.us'
},
adminsOnly: {
type: 'boolean',
description: 'Enable or disable this option',
example: true
}
}
}
}
*/
try { try {
const { chatId, adminsOnly } = req.body const { chatId, adminsOnly = true } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const chat = await client.getChatById(chatId) const chat = await client.getChatById(chatId)
if (!chat.isGroup) { throw new Error('The chat is not a group') } if (!chat.isGroup) { throw new Error('The chat is not a group') }
@ -278,8 +449,30 @@ const setInfoAdminsOnly = async (req, res) => {
* @throws {Error} If the chat is not a group. * @throws {Error} If the chat is not a group.
*/ */
const setMessagesAdminsOnly = async (req, res) => { const setMessagesAdminsOnly = async (req, res) => {
/*
#swagger.summary = 'Update the message group settings'
#swagger.summary = 'Update the group settings to only allow admins to send messages.'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'Unique WhatsApp id for the given chat group',
example: 'XXXXXXXXXX@g.us'
},
adminsOnly: {
type: 'boolean',
description: 'Enable or disable this option',
example: true
}
}
}
}
*/
try { try {
const { chatId, adminsOnly } = req.body const { chatId, adminsOnly = true } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const chat = await client.getChatById(chatId) const chat = await client.getChatById(chatId)
if (!chat.isGroup) { throw new Error('The chat is not a group') } if (!chat.isGroup) { throw new Error('The chat is not a group') }
@ -302,12 +495,36 @@ const setMessagesAdminsOnly = async (req, res) => {
* @throws {Error} If there is an issue setting the group picture, an error will be thrown. * @throws {Error} If there is an issue setting the group picture, an error will be thrown.
*/ */
const setPicture = async (req, res) => { const setPicture = async (req, res) => {
/*
#swagger.summary = 'Set the group picture'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'Unique WhatsApp id for the given chat group',
example: 'XXXXXXXXXX@g.us'
},
pictureMimeType: {
type: 'string',
description: 'MIME type of the attachment'
},
pictureData: {
type: 'string',
description: 'Base64-encoded data of the file'
}
}
}
}
*/
try { try {
const { pictureMimetype, pictureData, chatId } = req.body const { pictureMimeType, pictureData, chatId } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
const media = new MessageMedia(pictureMimetype, pictureData)
const chat = await client.getChatById(chatId) const chat = await client.getChatById(chatId)
if (!chat.isGroup) { throw new Error('The chat is not a group') } if (!chat.isGroup) { throw new Error('The chat is not a group') }
const media = new MessageMedia(pictureMimeType, pictureData)
const result = await chat.setPicture(media) const result = await chat.setPicture(media)
res.json({ success: true, result }) res.json({ success: true, result })
} catch (error) { } catch (error) {
@ -325,6 +542,9 @@ const setPicture = async (req, res) => {
* @throws {Error} If there is an issue setting the group picture, an error will be thrown. * @throws {Error} If there is an issue setting the group picture, an error will be thrown.
*/ */
const deletePicture = async (req, res) => { const deletePicture = async (req, res) => {
/*
#swagger.summary = 'Delete the group picture'
*/
try { try {
const { chatId } = req.body const { chatId } = req.body
const client = sessions.get(req.params.sessionId) const client = sessions.get(req.params.sessionId)
@ -337,6 +557,117 @@ const deletePicture = async (req, res) => {
} }
} }
/**
* Get an array of membership requests
* @param {Object} req - The request object.
* @param {Object} res - The response object.
* @param {Object} req.body.chatId - ID of the group chat.
* @param {string} req.params.sessionId - The ID of the session for the user.
* @returns {Object} Returns a JSON object with a success status and the result of the function.
* @throws {Error} If there is an issue setting the group picture, an error will be thrown.
*/
const getGroupMembershipRequests = async (req, res) => {
/*
#swagger.summary = 'Get the membership requests'
*/
try {
const { chatId } = req.body
const client = sessions.get(req.params.sessionId)
const chat = await client.getChatById(chatId)
if (!chat.isGroup) { throw new Error('The chat is not a group') }
const result = await chat.getGroupMembershipRequests()
res.json({ success: true, result })
} catch (error) {
sendErrorResponse(res, 500, error.message)
}
}
/**
* Approve membership requests if any
* @param {Object} req - The request object.
* @param {Object} res - The response object.
* @param {Object} req.body.chatId - ID of the group chat.
* @param {string} req.params.sessionId - The ID of the session for the user.
* @returns {Object} Returns a JSON object with a success status and the result of the function.
* @throws {Error} If there is an issue setting the group picture, an error will be thrown.
*/
const approveGroupMembershipRequests = async (req, res) => {
/*
#swagger.summary = 'Approve membership request'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'Unique WhatsApp id for the given chat group',
example: 'XXXXXXXXXX@g.us'
},
options: {
type: 'object',
description: 'Options for performing a membership request action',
example: { requesterIds: [], sleep: [250, 500] }
}
}
}
}
*/
try {
const { chatId, options = {} } = req.body
const client = sessions.get(req.params.sessionId)
const chat = await client.getChatById(chatId)
if (!chat.isGroup) { throw new Error('The chat is not a group') }
const result = await chat.approveGroupMembershipRequests(options)
res.json({ success: true, result })
} catch (error) {
sendErrorResponse(res, 500, error.message)
}
}
/**
* Reject membership requests if any
* @param {Object} req - The request object.
* @param {Object} res - The response object.
* @param {Object} req.body.chatId - ID of the group chat.
* @param {string} req.params.sessionId - The ID of the session for the user.
* @returns {Object} Returns a JSON object with a success status and the result of the function.
* @throws {Error} If there is an issue setting the group picture, an error will be thrown.
*/
const rejectGroupMembershipRequests = async (req, res) => {
/*
#swagger.summary = 'Reject membership request'
#swagger.requestBody = {
required: true,
schema: {
type: 'object',
properties: {
chatId: {
type: 'string',
description: 'Unique WhatsApp id for the given chat group',
example: 'XXXXXXXXXX@g.us'
},
options: {
type: 'object',
description: 'Options for performing a membership request action',
example: { requesterIds: [], sleep: [250, 500] }
}
}
}
}
*/
try {
const { chatId, options = {} } = req.body
const client = sessions.get(req.params.sessionId)
const chat = await client.getChatById(chatId)
if (!chat.isGroup) { throw new Error('The chat is not a group') }
const result = await chat.rejectGroupMembershipRequests(options)
res.json({ success: true, result })
} catch (error) {
sendErrorResponse(res, 500, error.message)
}
}
module.exports = { module.exports = {
getClassInfo, getClassInfo,
addParticipants, addParticipants,
@ -351,5 +682,8 @@ module.exports = {
setMessagesAdminsOnly, setMessagesAdminsOnly,
setSubject, setSubject,
setPicture, setPicture,
deletePicture deletePicture,
getGroupMembershipRequests,
approveGroupMembershipRequests,
rejectGroupMembershipRequests
} }

View file

@ -196,12 +196,20 @@ const groupChatSwagger = async (req, res, next) => {
properties: { properties: {
chatId: { chatId: {
type: 'string', type: 'string',
description: 'Unique WhatsApp ID for the given Chat (either group or personal)', description: 'Unique WhatsApp id for the given chat group',
example: '6281288888888@c.us' example: 'XXXXXXXXXX@g.us'
} }
} }
} }
} }
#swagger.responses[500] = {
description: "Server failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/ */
next() next()
} }

View file

@ -149,6 +149,9 @@ groupChatRouter.post('/setMessagesAdminsOnly/:sessionId', [middleware.sessionNam
groupChatRouter.post('/setSubject/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], groupChatController.setSubject) groupChatRouter.post('/setSubject/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], groupChatController.setSubject)
groupChatRouter.post('/setPicture/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], groupChatController.setPicture) groupChatRouter.post('/setPicture/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], groupChatController.setPicture)
groupChatRouter.post('/deletePicture/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], groupChatController.deletePicture) groupChatRouter.post('/deletePicture/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], groupChatController.deletePicture)
groupChatRouter.post('/getGroupMembershipRequests/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], groupChatController.getGroupMembershipRequests)
groupChatRouter.post('/approveGroupMembershipRequests/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], groupChatController.approveGroupMembershipRequests)
groupChatRouter.post('/rejectGroupMembershipRequests/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], groupChatController.rejectGroupMembershipRequests)
/** /**
* ================ * ================

View file

@ -6157,6 +6157,7 @@
"tags": [ "tags": [
"Group Chat" "Group Chat"
], ],
"summary": "Get the group",
"description": "", "description": "",
"parameters": [ "parameters": [
{ {
@ -6229,8 +6230,8 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
} }
} }
} }
@ -6241,8 +6242,8 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
} }
} }
} }
@ -6256,7 +6257,8 @@
"tags": [ "tags": [
"Group Chat" "Group Chat"
], ],
"description": "", "summary": "Add the participant(s)",
"description": "Add a list of participants by id to the group",
"parameters": [ "parameters": [
{ {
"name": "sessionId", "name": "sessionId",
@ -6328,8 +6330,24 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
},
"contactIds": {
"type": "string",
"description": "Unique WhatsApp identifier for the contact",
"example": "6281288888887@c.us"
},
"options": {
"type": "object",
"description": "Options for adding participants",
"example": {
"sleep": [
250,
500
],
"comment": ""
}
} }
} }
} }
@ -6340,8 +6358,24 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
},
"contactIds": {
"type": "string",
"description": "Unique WhatsApp identifier for the contact",
"example": "6281288888887@c.us"
},
"options": {
"type": "object",
"description": "Options for adding participants",
"example": {
"sleep": [
250,
500
],
"comment": ""
}
} }
} }
} }
@ -6355,7 +6389,8 @@
"tags": [ "tags": [
"Group Chat" "Group Chat"
], ],
"description": "", "summary": "Demote the participant(s)",
"description": "Demote participants by ids to regular users",
"parameters": [ "parameters": [
{ {
"name": "sessionId", "name": "sessionId",
@ -6427,8 +6462,13 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
},
"contactIds": {
"type": "string",
"description": "Unique WhatsApp identifier for the contact",
"example": "6281288888887@c.us"
} }
} }
} }
@ -6439,8 +6479,13 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
},
"contactIds": {
"type": "string",
"description": "Unique WhatsApp identifier for the contact",
"example": "6281288888887@c.us"
} }
} }
} }
@ -6454,7 +6499,8 @@
"tags": [ "tags": [
"Group Chat" "Group Chat"
], ],
"description": "", "summary": "Get the invite code",
"description": "Get the invite code for a specific group",
"parameters": [ "parameters": [
{ {
"name": "sessionId", "name": "sessionId",
@ -6526,8 +6572,8 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
} }
} }
} }
@ -6538,8 +6584,8 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
} }
} }
} }
@ -6553,6 +6599,7 @@
"tags": [ "tags": [
"Group Chat" "Group Chat"
], ],
"summary": "Leave the group",
"description": "", "description": "",
"parameters": [ "parameters": [
{ {
@ -6625,8 +6672,8 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
} }
} }
} }
@ -6637,8 +6684,8 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
} }
} }
} }
@ -6652,7 +6699,8 @@
"tags": [ "tags": [
"Group Chat" "Group Chat"
], ],
"description": "", "summary": "Promote the participant(s)",
"description": "Promote participants by IDs to admins",
"parameters": [ "parameters": [
{ {
"name": "sessionId", "name": "sessionId",
@ -6724,8 +6772,13 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
},
"contactIds": {
"type": "string",
"description": "Unique WhatsApp identifier for the contact",
"example": "6281288888887@c.us"
} }
} }
} }
@ -6736,8 +6789,13 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
},
"contactIds": {
"type": "string",
"description": "Unique WhatsApp identifier for the contact",
"example": "6281288888887@c.us"
} }
} }
} }
@ -6751,7 +6809,8 @@
"tags": [ "tags": [
"Group Chat" "Group Chat"
], ],
"description": "", "summary": "Remove the participant(s)",
"description": "Remove a list of participants by ID to the group",
"parameters": [ "parameters": [
{ {
"name": "sessionId", "name": "sessionId",
@ -6823,8 +6882,13 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
},
"contactIds": {
"type": "string",
"description": "Unique WhatsApp identifier for the contact",
"example": "6281288888887@c.us"
} }
} }
} }
@ -6835,8 +6899,13 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
},
"contactIds": {
"type": "string",
"description": "Unique WhatsApp identifier for the contact",
"example": "6281288888887@c.us"
} }
} }
} }
@ -6850,7 +6919,8 @@
"tags": [ "tags": [
"Group Chat" "Group Chat"
], ],
"description": "", "summary": "Invalidate the invite code",
"description": "Invalidate the current group invite code and generates a new one",
"parameters": [ "parameters": [
{ {
"name": "sessionId", "name": "sessionId",
@ -6922,8 +6992,8 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
} }
} }
} }
@ -6934,8 +7004,8 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
} }
} }
} }
@ -6949,6 +7019,7 @@
"tags": [ "tags": [
"Group Chat" "Group Chat"
], ],
"summary": "Update the group description",
"description": "", "description": "",
"parameters": [ "parameters": [
{ {
@ -7021,8 +7092,13 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
},
"description": {
"type": "string",
"description": "Group description",
"example": ""
} }
} }
} }
@ -7033,8 +7109,13 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
},
"description": {
"type": "string",
"description": "Group description",
"example": ""
} }
} }
} }
@ -7048,6 +7129,7 @@
"tags": [ "tags": [
"Group Chat" "Group Chat"
], ],
"summary": "Update the info group settings",
"description": "", "description": "",
"parameters": [ "parameters": [
{ {
@ -7120,8 +7202,13 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
},
"adminsOnly": {
"type": "boolean",
"description": "Enable or disable this option",
"example": true
} }
} }
} }
@ -7132,8 +7219,13 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
},
"adminsOnly": {
"type": "boolean",
"description": "Enable or disable this option",
"example": true
} }
} }
} }
@ -7147,6 +7239,7 @@
"tags": [ "tags": [
"Group Chat" "Group Chat"
], ],
"summary": "Update the message group settings",
"description": "", "description": "",
"parameters": [ "parameters": [
{ {
@ -7219,8 +7312,13 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
},
"adminsOnly": {
"type": "boolean",
"description": "Enable or disable this option",
"example": true
} }
} }
} }
@ -7231,8 +7329,13 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
},
"adminsOnly": {
"type": "boolean",
"description": "Enable or disable this option",
"example": true
} }
} }
} }
@ -7246,6 +7349,7 @@
"tags": [ "tags": [
"Group Chat" "Group Chat"
], ],
"summary": "Update the group subject",
"description": "", "description": "",
"parameters": [ "parameters": [
{ {
@ -7318,8 +7422,13 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
},
"subject": {
"type": "string",
"description": "Group subject",
"example": ""
} }
} }
} }
@ -7330,8 +7439,13 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
},
"subject": {
"type": "string",
"description": "Group subject",
"example": ""
} }
} }
} }
@ -7345,6 +7459,7 @@
"tags": [ "tags": [
"Group Chat" "Group Chat"
], ],
"summary": "Set the group picture",
"description": "", "description": "",
"parameters": [ "parameters": [
{ {
@ -7417,8 +7532,16 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
},
"pictureMimeType": {
"type": "string",
"description": "MIME type of the attachment"
},
"pictureData": {
"type": "string",
"description": "Base64-encoded data of the file"
} }
} }
} }
@ -7429,8 +7552,16 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
},
"pictureMimeType": {
"type": "string",
"description": "MIME type of the attachment"
},
"pictureData": {
"type": "string",
"description": "Base64-encoded data of the file"
} }
} }
} }
@ -7444,6 +7575,7 @@
"tags": [ "tags": [
"Group Chat" "Group Chat"
], ],
"summary": "Delete the group picture",
"description": "", "description": "",
"parameters": [ "parameters": [
{ {
@ -7516,8 +7648,8 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
} }
} }
} }
@ -7528,8 +7660,352 @@
"properties": { "properties": {
"chatId": { "chatId": {
"type": "string", "type": "string",
"description": "Unique WhatsApp ID for the given Chat (either group or personal)", "description": "Unique WhatsApp id for the given chat group",
"example": "6281288888888@c.us" "example": "XXXXXXXXXX@g.us"
}
}
}
}
}
}
}
},
"/groupChat/getGroupMembershipRequests/{sessionId}": {
"post": {
"tags": [
"Group Chat"
],
"summary": "Get the membership requests",
"description": "",
"parameters": [
{
"name": "sessionId",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
"description": "Unique identifier for the session (alphanumeric and - allowed)",
"example": "f8377d8d-a589-4242-9ba6-9486a04ef80c"
}
],
"responses": {
"200": {
"description": "OK"
},
"403": {
"description": "Forbidden.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ForbiddenResponse"
}
}
}
},
"404": {
"description": "Not Found.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/NotFoundResponse"
}
}
}
},
"422": {
"description": "Unprocessable Entity.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
},
"500": {
"description": "Server failure.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
}
},
"security": [
{
"apiKeyAuth": []
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"chatId": {
"type": "string",
"description": "Unique WhatsApp id for the given chat group",
"example": "XXXXXXXXXX@g.us"
}
}
}
},
"application/xml": {
"schema": {
"type": "object",
"properties": {
"chatId": {
"type": "string",
"description": "Unique WhatsApp id for the given chat group",
"example": "XXXXXXXXXX@g.us"
}
}
}
}
}
}
}
},
"/groupChat/approveGroupMembershipRequests/{sessionId}": {
"post": {
"tags": [
"Group Chat"
],
"summary": "Approve membership request",
"description": "",
"parameters": [
{
"name": "sessionId",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
"description": "Unique identifier for the session (alphanumeric and - allowed)",
"example": "f8377d8d-a589-4242-9ba6-9486a04ef80c"
}
],
"responses": {
"200": {
"description": "OK"
},
"403": {
"description": "Forbidden.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ForbiddenResponse"
}
}
}
},
"404": {
"description": "Not Found.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/NotFoundResponse"
}
}
}
},
"422": {
"description": "Unprocessable Entity.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
},
"500": {
"description": "Server failure.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
}
},
"security": [
{
"apiKeyAuth": []
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"chatId": {
"type": "string",
"description": "Unique WhatsApp id for the given chat group",
"example": "XXXXXXXXXX@g.us"
},
"options": {
"type": "object",
"description": "Options for performing a membership request action",
"example": {
"requesterIds": [],
"sleep": [
250,
500
]
}
}
}
}
},
"application/xml": {
"schema": {
"type": "object",
"properties": {
"chatId": {
"type": "string",
"description": "Unique WhatsApp id for the given chat group",
"example": "XXXXXXXXXX@g.us"
},
"options": {
"type": "object",
"description": "Options for performing a membership request action",
"example": {
"requesterIds": [],
"sleep": [
250,
500
]
}
}
}
}
}
}
}
}
},
"/groupChat/rejectGroupMembershipRequests/{sessionId}": {
"post": {
"tags": [
"Group Chat"
],
"summary": "Reject membership request",
"description": "",
"parameters": [
{
"name": "sessionId",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
"description": "Unique identifier for the session (alphanumeric and - allowed)",
"example": "f8377d8d-a589-4242-9ba6-9486a04ef80c"
}
],
"responses": {
"200": {
"description": "OK"
},
"403": {
"description": "Forbidden.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ForbiddenResponse"
}
}
}
},
"404": {
"description": "Not Found.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/NotFoundResponse"
}
}
}
},
"422": {
"description": "Unprocessable Entity.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
},
"500": {
"description": "Server failure.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
}
}
},
"security": [
{
"apiKeyAuth": []
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"chatId": {
"type": "string",
"description": "Unique WhatsApp id for the given chat group",
"example": "XXXXXXXXXX@g.us"
},
"options": {
"type": "object",
"description": "Options for performing a membership request action",
"example": {
"requesterIds": [],
"sleep": [
250,
500
]
}
}
}
}
},
"application/xml": {
"schema": {
"type": "object",
"properties": {
"chatId": {
"type": "string",
"description": "Unique WhatsApp id for the given chat group",
"example": "XXXXXXXXXX@g.us"
},
"options": {
"type": "object",
"description": "Options for performing a membership request action",
"example": {
"requesterIds": [],
"sleep": [
250,
500
]
}
} }
} }
} }