I am building a Telegram chatbot with python-telegram-bot package with inline keyboard that to link to the searching parts. I am not familiar with inline keyboard. At the moment in some way I figure out I need to separate to a function to trigger the keyboard, a function to get the inline keyboard reply and a function to run the searching.
For the function to trigger the keyboard, I figure out as follow:
def refSearch_handler(update, context):
reply_markup = InlineKeyboardMarkup([[
InlineKeyboardButton("Search by name", callback_data="search_name"),
InlineKeyboardButton("Search by function", callback_data="search_function")]])
bot.send_message(update.message.chat.id, "Please select:", reply_to_message_id = update.message.message_id,
reply_markup = reply_markup)
For the function to get the reply from inline keyboard and lead the user to input keyword, I figure out as follow:
def getClickButtonData(update, context):
if update.callback_query.data == "search_name":
update.callback_query.edit_message_text("Please input the name: ")
if update.callback_query.data == "search_function":
update.callback_query.edit_message_text("Please input the keyword of the function: ")
I know I need to add a conversation hander with the states which is something like below (this is from the demo of the python-telegram-bot package) and I think I should put it in the main() with other dispatchers:
conv_handler = ConversationHandler(
entry_points=[CommandHandler('start', start)],
states={
CHOOSING: [MessageHandler(Filters.regex('^(Age|Favourite colour|Number of siblings)$'),
regular_choice),
MessageHandler(Filters.regex('^Something else...$'),
custom_choice)
],
TYPING_CHOICE: [MessageHandler(Filters.text,
regular_choice)
],
TYPING_REPLY: [MessageHandler(Filters.text,
received_information),
],
},
fallbacks=[MessageHandler(Filters.regex('^Done$'), done)]
)
But I can't figure out how to set up the conv_handler so to point to the inline keyboard and link to the searching function? Just wonder if anyone has experience can guide me?
Many thanks!