Search code examples
pythontelegramtelegram-botpython-telegram-bot

How to use telebot module to create an inline button in bot window, which if clicked will work very similar to 'Create poll' button found in groups?


I am relatively new to python and I am trying to create a telegram bot using telebot, which will create a quiz-like game, and each user can create their own quiz-like game also. During the step by step process of creating this quiz by the user, at one point, I need them to send me a poll, just like how they create a new poll in a group. But there is no create poll button inside telegram bot as these buttons are generally found in groups and not in one-one chats. So I need to create an inline keyboard button, which upon clicking will let the users create a poll and send it to the bot. I have gone through the documentation in github and couldn't find anything useful for this.

This similar thing is implemented by telegram's own "Quizbot". I'll attach the screenshots from that bot for clarity. Please help me identify how to implement it in my bot. enter image description here

If 'Create question" button is clicked: enter image description here

I am a noob to python and coding, so please help me with this problem.

edit: I can send a poll to the bot if I am using telegram desktop and not from the phone. I want to know how to enable to use it in the phone.


Solution

  • By using telebot we can do this. This gives us the opportunity to create poll from phone apps also.

    import telebot
    from telebot.types import ReplyKeyboardMarkup,KeyboardButton, 
                              KeyboardButtonPollType,ReplyKeyboardRemove
    
    bot=telebot.Telebot(token='your bot token')
    poll_markup=ReplyKeyboardMarkup(one_time_keyboard=True) 
    poll_markup.add(KeyboardButton('send me a poll',
                    request_poll=KeyboardButtonPollType(type='quiz')))
    #from my experience, only quiz type and regular type polls can be send.
    
    remove_board=ReplyKeyboardRemove()
    bot.send_message(chat_id,text,reply_markup=poll_markup)
    #some other code here
    
    #this can be used to remove the replykeyboard when you no longer need it.
    bot.send_message(chat_id,text,reply_markup=remove_board)
    
                                              
    

    enter image description here