Search code examples
pythonbotstelegram-botpy-telegram-bot-api

poll answer handler in telegrapm bot


I need to get poll answer from user.

I saw this post, but it doesn't work for me.

@bot.message_handler(commands=['test'])
def start(message):
    bot.send_poll(message.chat.id, 'chose', ['a', 'b'])


@bot.poll_answer_handler(func=lambda call: True) #without lambda doesn't work too
def hadle_poll(call):
    print(call)

I don't know how to catch it. Please help

EDIT

I'm using pytelegrambotapi


Solution

  • The solution is very simple. In anonimous poll's you can't catch answers. So you should add one flag:

    @bot.message_handler(commands=['test'])
    def start(message):
        bot.send_poll(message.chat.id, 'chose', ['a', 'b'], is_anonymous = False)
    

    Then your poll handler will work and catch answers.