diff --git a/src/controllers/clientController.js b/src/controllers/clientController.js index 302938e..da1db32 100644 --- a/src/controllers/clientController.js +++ b/src/controllers/clientController.js @@ -102,6 +102,8 @@ const sendMessage = async (req, res) => { case 'Poll': { const poll = new Poll(content.pollName, content.pollOptions, content.options) messageOut = await client.sendMessage(chatId, poll, options) + // fix for poll events not being triggered (open the chat that you sent the poll) + await client.interface.openChatWindow(chatId) break } default: @@ -1000,7 +1002,7 @@ const pinChat = async (req, res) => { chatId: { type: 'string', description: 'ID of the chat', - example: '' + example: '6281288888888@c.us' }, } }, @@ -1133,7 +1135,7 @@ const sendSeen = async (req, res) => { chatId: { type: 'string', description: 'ID of the chat', - example: '' + example: '6281288888888@c.us' }, } }, @@ -1210,7 +1212,7 @@ const unarchiveChat = async (req, res) => { chatId: { type: 'string', description: 'ID of the chat', - example: '' + example: '6281288888888@c.us' }, } }, @@ -1249,7 +1251,7 @@ const unmuteChat = async (req, res) => { chatId: { type: 'string', description: 'ID of the chat', - example: '' + example: '6281288888888@c.us' }, } }, @@ -1288,7 +1290,7 @@ const unpinChat = async (req, res) => { chatId: { type: 'string', description: 'ID of the chat', - example: '' + example: '6281288888888@c.us' }, } }, @@ -1532,7 +1534,7 @@ const syncHistory = async (req, res) => { chatId: { type: 'string', description: 'ID of the chat', - example: '' + example: '6281288888888@c.us' }, } }, @@ -1666,6 +1668,45 @@ const getFormattedNumber = async (req, res) => { } } +/** + * Open the chat window. + * + * @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} - 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 openChatWindow = async (req, res) => { + /* + #swagger.summary = 'Open the chat window' + #swagger.requestBody = { + required: true, + schema: { + type: 'object', + properties: { + chatId: { + type: 'string', + description: 'ID of the chat', + example: '6281288888888@c.us' + }, + } + }, + } + */ + try { + const { chatId } = req.body + const client = sessions.get(req.params.sessionId) + await client.interface.openChatWindow(chatId) + res.json({ success: true }) + } catch (error) { + sendErrorResponse(res, 500, error.message) + } +} + module.exports = { getClassInfo, acceptInvite, @@ -1710,5 +1751,6 @@ module.exports = { syncHistory, getContactDeviceCount, getCountryCode, - getFormattedNumber + getFormattedNumber, + openChatWindow } diff --git a/src/controllers/messageController.js b/src/controllers/messageController.js index 346e376..43eaec4 100644 --- a/src/controllers/messageController.js +++ b/src/controllers/messageController.js @@ -472,10 +472,12 @@ const reply = async (req, res) => { } case 'Poll': { contentMessage = new Poll(content.pollName, content.pollOptions, content.options) + // fix for poll events not being triggered (open the chat that you sent the poll) + await client.interface.openChatWindow(chatId) break } default: - return sendErrorResponse(res, 400, 'contentType invalid, must be string, MessageMedia, MessageMediaFromURL, Location, Buttons, List, Contact or Poll') + return sendErrorResponse(res, 400, 'contentType invalid, must be string, MessageMedia, MessageMediaFromURL, Location, Contact or Poll') } const repliedMessage = await message.reply(contentMessage, chatId, options) res.json({ success: true, repliedMessage }) diff --git a/src/routes.js b/src/routes.js index 8565e12..fc63b84 100644 --- a/src/routes.js +++ b/src/routes.js @@ -102,6 +102,7 @@ clientRouter.post('/syncHistory/:sessionId', [middleware.sessionNameValidation, clientRouter.post('/getContactDeviceCount/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], clientController.getContactDeviceCount) 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) /** * ================ diff --git a/swagger.json b/swagger.json index 66dc22f..5c258ed 100644 --- a/swagger.json +++ b/swagger.json @@ -2876,7 +2876,7 @@ "chatId": { "type": "string", "description": "ID of the chat", - "example": "" + "example": "6281288888888@c.us" } } } @@ -2888,7 +2888,7 @@ "chatId": { "type": "string", "description": "ID of the chat", - "example": "" + "example": "6281288888888@c.us" } } } @@ -3396,7 +3396,7 @@ "chatId": { "type": "string", "description": "ID of the chat", - "example": "" + "example": "6281288888888@c.us" } } } @@ -3408,7 +3408,7 @@ "chatId": { "type": "string", "description": "ID of the chat", - "example": "" + "example": "6281288888888@c.us" } } } @@ -3600,10 +3600,10 @@ "schema": { "type": "object", "properties": { - "number": { + "chatId": { "type": "string", - "description": "Number or ID", - "example": "" + "description": "ID of the chat", + "example": "6281288888888@c.us" } } } @@ -3612,10 +3612,10 @@ "schema": { "type": "object", "properties": { - "number": { + "chatId": { "type": "string", - "description": "Number or ID", - "example": "" + "description": "ID of the chat", + "example": "6281288888888@c.us" } } } @@ -3803,7 +3803,7 @@ "chatId": { "type": "string", "description": "ID of the chat", - "example": "" + "example": "6281288888888@c.us" } } } @@ -3815,7 +3815,7 @@ "chatId": { "type": "string", "description": "ID of the chat", - "example": "" + "example": "6281288888888@c.us" } } } @@ -3903,7 +3903,7 @@ "chatId": { "type": "string", "description": "ID of the chat", - "example": "" + "example": "6281288888888@c.us" } } } @@ -3915,7 +3915,7 @@ "chatId": { "type": "string", "description": "ID of the chat", - "example": "" + "example": "6281288888888@c.us" } } } @@ -4003,7 +4003,7 @@ "chatId": { "type": "string", "description": "ID of the chat", - "example": "" + "example": "6281288888888@c.us" } } } @@ -4015,7 +4015,7 @@ "chatId": { "type": "string", "description": "ID of the chat", - "example": "" + "example": "6281288888888@c.us" } } } @@ -4645,7 +4645,7 @@ "chatId": { "type": "string", "description": "ID of the chat", - "example": "" + "example": "6281288888888@c.us" } } } @@ -4657,7 +4657,7 @@ "chatId": { "type": "string", "description": "ID of the chat", - "example": "" + "example": "6281288888888@c.us" } } } @@ -4966,6 +4966,106 @@ } } }, + "/client/openChatWindow/{sessionId}": { + "post": { + "tags": [ + "Client" + ], + "summary": "Open the chat window", + "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": "ID of the chat", + "example": "6281288888888@c.us" + } + } + } + }, + "application/xml": { + "schema": { + "type": "object", + "properties": { + "chatId": { + "type": "string", + "description": "ID of the chat", + "example": "6281288888888@c.us" + } + } + } + } + } + } + } + }, "/chat/getClassInfo/{sessionId}": { "post": { "tags": [