Reputation: 87
Not being able to call /order twice. I call /order, without doing anything, i call /order again. It's not calling the async def order. It should work without allow_reentry=True. WHY?
ORDER_CATEGORY, ORDER_PRODUCT, ORDER_CART, ORDER_CONFIRM = range(4)
async def order(update: Update, context: ContextTypes.DEFAULT_TYPE):
keyboard = [
[InlineKeyboardButton("Insulin (အင်ဆူလင်)", callback_data='insulin')],
[InlineKeyboardButton("Pill (ဆေးလုံး)", callback_data='pill')],
[InlineKeyboardButton("Ozempic, Wegovy, Mounjaro", callback_data='injection')],
[InlineKeyboardButton("Machine (ကရိယာ)", callback_data='machine')]
]
# Create the markup for the inline keyboard
reply_markup = InlineKeyboardMarkup(keyboard)
# Send the message with the inline keyboard
await update.message.reply_text('Choose an option:', reply_markup=reply_markup)
return ORDER_CATEGORY
# Define the ConversationHandler
def order_handler():
return ConversationHandler(
entry_points=[CommandHandler('order', order)],
states={
ORDER_CATEGORY: [CallbackQueryHandler(category)],
ORDER_PRODUCT: [CallbackQueryHandler(product, pattern=r'^\d+$')],
ORDER_CART: [CallbackQueryHandler(cart, pattern=r'^\d+_qty_\d+$')],
ORDER_CONFIRM: [CallbackQueryHandler(confirm, pattern=r'^confirm$')],
},
fallbacks=[CommandHandler('cancel', cancel)],
allow_reentry=True # Should work without this. WHY?
)
# Set up the Application and add the handler
async def cancel(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text(text="Cancelled")
context.user_data.clear()
return ConversationHandler.END
def main():
application = Application.builder().token(TELEGRAM_BOT_TOKEN).build()
# Start
application.add_handler(CommandHandler("start", start))
# Order
application.add_handler(order_handler())
# Start the bot
application.run_polling()
I tried with allow_reentry=True, obviously it works but it should be working without it.
I also tried removing the state, it works but won’t proceed to the next step.
Upvotes: 1
Views: 21