Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13921

How to make a few queries in a telegram bot using python?

$
0
0

So, I have a telegram bot, that I want to have an InlineButtons control and I don't know how to make this. When I try to make just one message with InlineKeyboard it is ok, but when I try to implement the second one, with the buttons that should make different things Im just getting the same result as with the first set of buttons. So its basically has the same logic for different buttons and I cant't make it work properly

Here is my code:

CHARACTER, DATA = range(2)async def command(update : Update, context : ContextTypes.DEFAULT_TYPE):    keyboard = [[InlineKeyboardButton("Button2", callback_data="Button2")]]    reply_markup = InlineKeyboardMarkup(keyboard)    await update.message.reply_text("Some Text", reply_markup = reply_markup)    return CHARACTERasync def button(update: Update, context: ContextTypes.DEFAULT_TYPE):    query = update.callback_query    await query.answer()    await query.edit_message_text(text=f"Some Text")    return DATAasync def second_button(update: Update, context: ContextTypes.DEFAULT_TYPE):    query = update.callback_query    await query.answer()    await query.edit_message_text(text=f"Some Text")    return ConversationHandler.ENDif __name__ == "__main__":    app = Application.builder().token("").build()    conv_handler = ConversationHandler(entry_points = [CommandHandler("command", command)], states = {CHARACTER:[CallbackQueryHandler(command)], DATA:[CallbackQueryHandler(button)]}, fallbacks = [CallbackQueryHandler(second_button)],)    app.add_handler(conv_handler)    app.run_polling(poll_interval = 2)

I saw that people use a ConversationHandler for this, but I don't understand how to implement it in my code. I am really sorry if its a dumb question, I just couldn't figure out what exactly I have to do to make ConversationHandler work


Viewing all articles
Browse latest Browse all 13921

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>