Add getPollVotes for a message (#115)

* Add getPollVotes for a message

* Add swagger.json

* CR fixes

---------

Co-authored-by: nir <nir@severin>
This commit is contained in:
Nir 2026-03-08 18:33:19 +02:00 • committed by GitHub
commit 6894b8ecd6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 143 additions and 3 deletions

View file

@ -187,7 +187,6 @@ const downloadMediaAsData = async (req, res) => {
* @param {string} req.body.messageId - The ID of the message to forward.
* @param {string} req.body.chatId - The ID of the chat that contains the message to forward.
* @param {string} req.body.destinationChatId - The ID of the chat to forward the message to.
* @param {string} req.params.sessionId - The ID of the session to use the Telegram API with.
* @param {Object} res - The response object to be sent back to the client.
* @returns {Object} - The response object with a JSON body containing the result of the forward operation.
* @throws Will throw an error if the message is not found or if there is an error during the forward operation.
@ -239,7 +238,6 @@ const forward = async (req, res) => {
* @param {Object} req.body - The body of the request object.
* @param {string} req.body.messageId - The ID of the message to get information about.
* @param {string} req.body.chatId - The ID of the chat that contains the message to get information about.
* @param {string} req.params.sessionId - The ID of the session to use the Telegram API with.
* @param {Object} res - The response object to be sent back to the client.
* @returns {Object} - The response object with a JSON body containing the information about the message.
* @throws Will throw an error if the message is not found or if there is an error during the get info operation.
@ -716,7 +714,7 @@ const edit = async (req, res) => {
* @param {string} req.params.sessionId - The session ID.
* @param {string} req.body.messageId - The message ID.
* @param {string} req.body.chatId - The chat ID.
* @returns {Promise} A Promise that resolves with the result of the message.getReactions() call.
* @returns {Promise} A Promise that resolves with the result of the message.getContact() call.
* @throws {Error} If message is not found, it throws an error with the message "Message not found".
*/
const getContact = async (req, res) => {
@ -735,6 +733,36 @@ const getContact = async (req, res) => {
}
}
/**
* Gets vote results for a message with a poll.
* @async
* @function getPollVotes
* @param {Object} req - The request object received by the server.
* @param {Object} req.body - The body of the request object.
* @param {string} req.body.messageId - The ID of the message to get information about.
* @param {string} req.body.chatId - The ID of the chat that contains the message to get information about.
* @param {Object} res - The response object to be sent back to the client.
* @returns {Object} - The response object with a JSON body containing the poll results.
* @throws Will throw an error if the message is not found or if there is an error during the get poll votes operation.
*/
const getPollVotes = async (req, res) => {
/*
#swagger.summary = 'Get poll vote results for a message with a poll'
#swagger.description = 'May return null if the message does not exist or is not a poll.'
*/
try {
const { messageId, chatId } = 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 votes = await message.getPollVotes()
res.json({ success: true, votes })
} catch (error) {
sendErrorResponse(res, 500, error.message)
}
}
/**
* Executes a method on the message associated with the given sessionId.
*
@ -816,5 +844,6 @@ module.exports = {
getGroupMentions,
edit,
getContact,
getPollVotes,
runMethod
}

View file

@ -201,6 +201,7 @@ messageRouter.post('/getReactions/:sessionId', [middleware.sessionNameValidation
messageRouter.post('/getGroupMentions/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], messageController.getGroupMentions)
messageRouter.post('/edit/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], messageController.edit)
messageRouter.post('/getContact/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], messageController.getContact)
messageRouter.post('/getPollVotes/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], messageController.getPollVotes)
messageRouter.post('/runMethod/:sessionId', [middleware.sessionNameValidation, middleware.sessionValidation], messageController.runMethod)
/**