Search code examples
pythontelegramtelegram-botpython-telegram-bot

Get poll's results and user selections from Telegram's bot API


I would like to know if there is a way to find user's replies to a non anonymous poll, using bot API. I'm able to get the number of votes, but I would like to know the actual choice from a specific user.


Solution

  • Yes, for non-anonymous polls you get an update when a user makes a vote. Those are the updates with update.poll_answer, see https://core.telegram.org/bots/api#update and https://core.telegram.org/bots/api#pollanswer.

    Because you used the corresponding tag, I'm assuming that you're using the python-telegram-bot library. In that case you can use the PollAnswerHandler to catch those updates. Please also have a look at the pollbot.py example, which summarizes some common use cases for polls.

    Disclaimer: I'm the maintainer of python-telegram-bot.