feat: update library and add new routes
This commit is contained in:
parent
b419618949
commit
a35442d609
6 changed files with 431 additions and 25 deletions
|
|
@ -1708,6 +1708,110 @@ const openChatWindow = async (req, res) => {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open or scroll the chat window to the position of the message.
|
||||
*
|
||||
* @async
|
||||
* @function
|
||||
* @param {Object} req - The HTTP request object containing the chatId and sessionId.
|
||||
* @param {string} req.body.chatId - The unique identifier of the chat to unmute.
|
||||
* @param {string} req.params.sessionId - The unique identifier of the session associated with the client to use.
|
||||
* @param {Object} res - The HTTP response object.
|
||||
* @returns {Promise<Object>} - A Promise that resolves with a JSON object containing a success flag and the result of the operation.
|
||||
* @throws {Error} - If an error occurs during the operation, it is thrown and handled by the catch block.
|
||||
*/
|
||||
const openChatWindowAt = async (req, res) => {
|
||||
/*
|
||||
#swagger.summary = 'Open the chat window to the position of the message'
|
||||
#swagger.requestBody = {
|
||||
required: true,
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
messageId: {
|
||||
type: 'string',
|
||||
description: 'ID of the message to scroll to (serialized)',
|
||||
example: 'false_31235678901@c.us_3A40CB10BC3680B1EE'
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
*/
|
||||
try {
|
||||
const { messageId } = req.body
|
||||
const client = sessions.get(req.params.sessionId)
|
||||
await client.interface.openChatWindowAt(messageId)
|
||||
res.json({ success: true })
|
||||
} catch (error) {
|
||||
sendErrorResponse(res, 500, error.message)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Force reset of connection state for the client.
|
||||
*
|
||||
* @async
|
||||
* @function
|
||||
* @param {Object} req - The HTTP request object containing the chatId and sessionId.
|
||||
* @param {string} req.body.chatId - The unique identifier of the chat to unmute.
|
||||
* @param {string} req.params.sessionId - The unique identifier of the session associated with the client to use.
|
||||
* @param {Object} res - The HTTP response object.
|
||||
* @returns {Promise<Object>} - A Promise that resolves with a JSON object containing a success flag and the result of the operation.
|
||||
* @throws {Error} - If an error occurs during the operation, it is thrown and handled by the catch block.
|
||||
*/
|
||||
const resetState = async (req, res) => {
|
||||
/*
|
||||
#swagger.summary = 'Force reset of connection state for the client'
|
||||
*/
|
||||
try {
|
||||
const client = sessions.get(req.params.sessionId)
|
||||
await client.resetState()
|
||||
res.json({ success: true })
|
||||
} catch (error) {
|
||||
sendErrorResponse(res, 500, error.message)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the background synchronization setting.
|
||||
*
|
||||
* @async
|
||||
* @function
|
||||
* @param {Object} req - The HTTP request object containing the chatId and sessionId.
|
||||
* @param {string} req.body.chatId - The unique identifier of the chat to unmute.
|
||||
* @param {string} req.params.sessionId - The unique identifier of the session associated with the client to use.
|
||||
* @param {Object} res - The HTTP response object.
|
||||
* @returns {Promise<Object>} - A Promise that resolves with a JSON object containing a success flag and the result of the operation.
|
||||
* @throws {Error} - If an error occurs during the operation, it is thrown and handled by the catch block.
|
||||
*/
|
||||
const setBackgroundSync = async (req, res) => {
|
||||
/*
|
||||
#swagger.summary = 'Change the background synchronization setting'
|
||||
#swagger.description = 'NOTE: This action will take effect after you restart the client'
|
||||
#swagger.requestBody = {
|
||||
required: true,
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
flag: {
|
||||
type: 'boolean',
|
||||
description: 'flag true/false',
|
||||
example: true
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
*/
|
||||
try {
|
||||
const { flag = true } = req.body
|
||||
const client = sessions.get(req.params.sessionId)
|
||||
await client.setBackgroundSync(flag)
|
||||
res.json({ success: true })
|
||||
} catch (error) {
|
||||
sendErrorResponse(res, 500, error.message)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getClassInfo,
|
||||
acceptInvite,
|
||||
|
|
@ -1753,5 +1857,8 @@ module.exports = {
|
|||
getContactDeviceCount,
|
||||
getCountryCode,
|
||||
getFormattedNumber,
|
||||
openChatWindow
|
||||
openChatWindow,
|
||||
openChatWindowAt,
|
||||
resetState,
|
||||
setBackgroundSync
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,17 +79,22 @@ const deleteMessage = async (req, res) => {
|
|||
type: 'boolean',
|
||||
description: 'If true and the message is sent by the current user or the user is an admin, will delete it for everyone in the chat.',
|
||||
example: true
|
||||
},
|
||||
clearMedia: {
|
||||
type: 'boolean',
|
||||
description: 'If true, any associated media will also be deleted from a device',
|
||||
example: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
try {
|
||||
const { messageId, chatId, everyone } = req.body
|
||||
const { messageId, chatId, everyone, clearMedia = true } = req.body
|
||||
const client = sessions.get(req.params.sessionId)
|
||||
const message = await _getMessageById(client, messageId, chatId)
|
||||
if (!message) { throw new Error('Message not found') }
|
||||
const result = await message.delete(everyone)
|
||||
const result = await message.delete(everyone, clearMedia)
|
||||
res.json({ success: true, result })
|
||||
} catch (error) {
|
||||
sendErrorResponse(res, 500, error.message)
|
||||
|
|
|
|||
|
|
@ -104,6 +104,9 @@ clientRouter.post('/getContactDeviceCount/:sessionId', [middleware.sessionNameVa
|
|||
clientRouter.post('/getCountryCode/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], clientController.getCountryCode)
|
||||
clientRouter.post('/getFormattedNumber/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], clientController.getFormattedNumber)
|
||||
clientRouter.post('/openChatWindow/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], clientController.openChatWindow)
|
||||
clientRouter.post('/openChatWindowAt/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], clientController.openChatWindowAt)
|
||||
clientRouter.post('/resetState/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], clientController.resetState)
|
||||
clientRouter.post('/setBackgroundSync/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], clientController.setBackgroundSync)
|
||||
|
||||
/**
|
||||
* ================
|
||||
|
|
|
|||
Loading…
Reference in a new issue