C
C
Cyril2020-04-22 17:13:01
Python
Cyril, 2020-04-22 17:13:01

How to implement adding options to a poll using python-telegram-bot?

I'm trying to write a telegram bot using python-telegram-bot.
I can't figure out how to implement adding answer options to the poll as inline buttons.
As I see it, there are 3 options:
1 - You can create each option in one message on different lines. Then you need to somehow describe the function that creates the number of options = the number of lines. Use a loop? what to cling to?
2 - You can create a button each separately, but in this case, if you refer to the same function, where to store the previous buttons? they will be interchangeable.
I wanted to try to do it using the ConversationHandler, but, as I understand it, in this way you can only add a fixed value of options (for example, only 3)

Perhaps all of these options are initially wrong. Please give me an idea.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Krostelev, 2020-04-22
@twistfire92

#Список с ответами
answers = ['вариант 1', 'вариант 2', 'вариант 3', 'вариант 4']

markup = types.InlineKeyboardMarkup()
for answer in answers:
    button = types.InlineKeyboardButton(text=answer, callback_data=answer)
    markup.row(button)

question = 'какой вариант выберете?'

bot.send_message(message.chat.id, question, reply_markup=marckup)

If everything is written correctly, then in the end there will be a message with the text of the question ( 'which option will you choose?' ) and 4 inline buttons, each in its own line (thanks to the row() function )

B
bittenmuskrat, 2020-04-22
@bittenmuskrat

May be able to help: https://groosha.gitbook.io/telegram-bot-lessons/ch...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question