skip to Main Content

I’m trying to get input text from the user..
He arrive to the function after he interact with

 keyboard = [[InlineKeyboardButton("exapmple", callback_data='example')]]
 reply_markup = InlineKeyboardMarkup(keyboard)

so in update I’m getting callback_query
after he choose the button example I ask him for input text.
this work for me I get input with the button but not with his own input

def getInput(update, context):
    query = update.callback_query
    query.answer()
    input = query.data

I want to get the input like

input = update.message.text

but since I get callback_query I don’t have the message..
so how I switch to message or get input with callback_query

edit:
I arrive to getInput with

    dp.add_handler(CallbackQueryHandler(getInput, pattern='example'))

3

Answers


  1. The response from a callback query is

    text = update.callback_query.data
    

    If the user decides to type instead something then the message is processed as a default text message

    def main_handler(update, context):
       print(update.message.text)
    
    updater.dispatcher.add_handler(MessageHandler(Filters.text, main_handler))
    
    Login or Signup to reply.
  2. def get_text_from_user(updater, context):
    text = updater.message.text # <- this is text from user
    print(text)

    updater.dispatcher.add_handler(telegram.exe.MessageHandler(telegram.exe.Filters.text,get_text_from_user))

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search