feat: requestPairingCode method added
This commit is contained in:
parent
9e9d18af48
commit
71c8deeb4a
3 changed files with 150 additions and 0 deletions
|
|
@ -291,11 +291,60 @@ const terminateAllSessions = async (req, res) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request authentication via pairing code instead of QR code.
|
||||||
|
*
|
||||||
|
* @async
|
||||||
|
* @function
|
||||||
|
* @param {Object} req - The HTTP request object containing the chatId and sessionId.
|
||||||
|
* @param {string} req.body.phoneNumber - The phone number in international, symbol-free format (e.g. 12025550108 for US, 551155501234 for Brazil).
|
||||||
|
* @param {boolean} req.body.showNotification - Show notification to pair on phone number.
|
||||||
|
* @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 requestPairingCode = async (req, res) => {
|
||||||
|
/*
|
||||||
|
#swagger.summary = 'Request authentication via pairing code'
|
||||||
|
#swagger.requestBody = {
|
||||||
|
required: true,
|
||||||
|
schema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
phoneNumber: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Phone number in international, symbol-free format',
|
||||||
|
example: '12025550108'
|
||||||
|
},
|
||||||
|
showNotification: {
|
||||||
|
type: 'boolean',
|
||||||
|
description: 'Show notification to pair on phone number',
|
||||||
|
example: true
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
const { phoneNumber, showNotification = true } = req.body
|
||||||
|
const client = sessions.get(req.params.sessionId)
|
||||||
|
if (!client) {
|
||||||
|
return res.json({ success: false, message: 'session_not_found' })
|
||||||
|
}
|
||||||
|
const result = await client.requestPairingCode(phoneNumber, showNotification)
|
||||||
|
res.json({ success: true, result })
|
||||||
|
} catch (error) {
|
||||||
|
sendErrorResponse(res, 500, error.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
startSession,
|
startSession,
|
||||||
statusSession,
|
statusSession,
|
||||||
sessionQrCode,
|
sessionQrCode,
|
||||||
sessionQrCodeImage,
|
sessionQrCodeImage,
|
||||||
|
requestPairingCode,
|
||||||
restartSession,
|
restartSession,
|
||||||
terminateSession,
|
terminateSession,
|
||||||
terminateInactiveSessions,
|
terminateInactiveSessions,
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ sessionRouter.get('/start/:sessionId', middleware.sessionNameValidation, session
|
||||||
sessionRouter.get('/status/:sessionId', middleware.sessionNameValidation, sessionController.statusSession)
|
sessionRouter.get('/status/:sessionId', middleware.sessionNameValidation, sessionController.statusSession)
|
||||||
sessionRouter.get('/qr/:sessionId', middleware.sessionNameValidation, sessionController.sessionQrCode)
|
sessionRouter.get('/qr/:sessionId', middleware.sessionNameValidation, sessionController.sessionQrCode)
|
||||||
sessionRouter.get('/qr/:sessionId/image', middleware.sessionNameValidation, sessionController.sessionQrCodeImage)
|
sessionRouter.get('/qr/:sessionId/image', middleware.sessionNameValidation, sessionController.sessionQrCodeImage)
|
||||||
|
sessionRouter.post('/requestPairingCode/:sessionId', middleware.sessionNameValidation, sessionController.requestPairingCode)
|
||||||
sessionRouter.get('/restart/:sessionId', middleware.sessionNameValidation, sessionController.restartSession)
|
sessionRouter.get('/restart/:sessionId', middleware.sessionNameValidation, sessionController.restartSession)
|
||||||
sessionRouter.get('/terminate/:sessionId', middleware.sessionNameValidation, sessionController.terminateSession)
|
sessionRouter.get('/terminate/:sessionId', middleware.sessionNameValidation, sessionController.terminateSession)
|
||||||
sessionRouter.get('/terminateInactive', sessionController.terminateInactiveSessions)
|
sessionRouter.get('/terminateInactive', sessionController.terminateInactiveSessions)
|
||||||
|
|
|
||||||
100
swagger.json
100
swagger.json
|
|
@ -367,6 +367,106 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/session/requestPairingCode/{sessionId}": {
|
||||||
|
"post": {
|
||||||
|
"tags": [
|
||||||
|
"Session"
|
||||||
|
],
|
||||||
|
"summary": "Request authentication via pairing code",
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"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": {
|
||||||
|
"phoneNumber": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Phone number in international, symbol-free format",
|
||||||
|
"example": "12025550108"
|
||||||
|
},
|
||||||
|
"showNotification": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Show notification to pair on phone number",
|
||||||
|
"example": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"application/xml": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"phoneNumber": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Phone number in international, symbol-free format",
|
||||||
|
"example": "12025550108"
|
||||||
|
},
|
||||||
|
"showNotification": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Show notification to pair on phone number",
|
||||||
|
"example": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/session/restart/{sessionId}": {
|
"/session/restart/{sessionId}": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": [
|
"tags": [
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue