diff --git a/src/controllers/clientController.js b/src/controllers/clientController.js index b0d2c50..c689d10 100644 --- a/src/controllers/clientController.js +++ b/src/controllers/clientController.js @@ -1812,6 +1812,49 @@ const setBackgroundSync = async (req, res) => { } } +/** + * Retrieve the contact lid and phone number for a specific chat. + * + * @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 getContactLidAndPhone = async (req, res) => { + /* + #swagger.summary = 'Get contact lid and phone' + #swagger.description = 'Retrieve the contact lid and phone number for a specific chat' + #swagger.requestBody = { + required: true, + schema: { + type: 'object', + properties: { + userIds: { + type: 'array', + items: { + type: 'string', + description: 'The unique identifier of the user', + }, + example: ['6281288888888@c.us'] + }, + } + }, + } + */ + try { + const { userIds = [] } = req.body + const client = sessions.get(req.params.sessionId) + const result = await client.getContactLidAndPhone(userIds) + res.json({ success: true, data: result }) + } catch (error) { + sendErrorResponse(res, 500, error.message) + } +} + module.exports = { getClassInfo, acceptInvite, @@ -1860,5 +1903,6 @@ module.exports = { openChatWindow, openChatWindowAt, resetState, - setBackgroundSync + setBackgroundSync, + getContactLidAndPhone } diff --git a/src/routes.js b/src/routes.js index b1ed00b..d52f869 100644 --- a/src/routes.js +++ b/src/routes.js @@ -108,6 +108,7 @@ clientRouter.post('/openChatWindow/:sessionId', [middleware.sessionNameValidatio 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) +clientRouter.post('/getContactLidAndPhone/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], clientController.getContactLidAndPhone) /** * ================ diff --git a/swagger.json b/swagger.json index 8149f76..9c0553e 100644 --- a/swagger.json +++ b/swagger.json @@ -3732,10 +3732,15 @@ "schema": { "type": "object", "properties": { - "flag": { - "type": "boolean", - "description": "flag true/false", - "example": true + "userIds": { + "type": "array", + "items": { + "type": "string", + "description": "The unique identifier of the user" + }, + "example": [ + "6281288888888@c.us" + ] } } } @@ -3744,10 +3749,15 @@ "schema": { "type": "object", "properties": { - "flag": { - "type": "boolean", - "description": "flag true/false", - "example": true + "userIds": { + "type": "array", + "items": { + "type": "string", + "description": "The unique identifier of the user" + }, + "example": [ + "6281288888888@c.us" + ] } } } @@ -5469,6 +5479,116 @@ } } }, + "/client/getContactLidAndPhone/{sessionId}": { + "post": { + "tags": [ + "Client" + ], + "summary": "Get contact lid and phone", + "description": "Retrieve the contact lid and phone number for a specific chat", + "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": { + "userIds": { + "type": "array", + "items": { + "type": "string", + "description": "The unique identifier of the user" + }, + "example": [ + "6281288888888@c.us" + ] + } + } + } + }, + "application/xml": { + "schema": { + "type": "object", + "properties": { + "userIds": { + "type": "array", + "items": { + "type": "string", + "description": "The unique identifier of the user" + }, + "example": [ + "6281288888888@c.us" + ] + } + } + } + } + } + } + } + }, "/chat/getClassInfo/{sessionId}": { "post": { "tags": [