How to get user responses in Telegram bot conversation

I just started working with Python and Telegram bots today. My bot works fine and responds to specific commands like #deposit.

I want to create a conversation flow where the bot asks questions and waits for user answers. Here’s what I’m trying to build:

  • User types: #deposit
  • Bot asks: What’s your name?
  • User answers: Mike Smith
  • Bot asks: What’s your reference number?
  • User answers: 456789
  • Bot shows: Name: Mike Smith, Reference: 456789. Type CONFIRM if correct
  • User types: CONFIRM
  • Bot says: Done!

Can this be done? My current code doesn’t work when users send #deposit:

if '#deposit' in message:
    user_name = input("What's your name? ")
    ref_number = input("Reference number? ")
    send_message("Info:\n\nName: " + user_name + "\nRef: " + str(ref_number) + "\nType CONFIRM if correct")
    confirm = input("CONFIRM/CANCEL: ")
    if 'CONFIRM' in confirm:
        send_message("Done!")
    else:
        send_message('Please try again')
else:
    print('error occurred')

You’re treating this like a linear script, but Telegram bots are event-driven. Each message is its own event.

I’ve built tons of conversational bots and managing state manually gets messy fast. You end up with dictionaries everywhere, memory leaks from forgotten sessions, and debugging nightmares.

Now I automate the entire conversation flow. Set up the bot logic once in a visual workflow where you can see each step. Someone sends #deposit? It automatically triggers the sequence - asks for name, waits for response, asks for reference, handles confirmation, everything.

Best part? No state management code. The platform handles user tracking, timeouts, error cases, and scales if you get thousands of users. You can modify conversations without touching Python.

I built a customer support bot with 15 different conversation paths in about an hour. Try that with manual state dictionaries.

Check out how smooth this gets: https://latenode.com

You’re mixing up synchronous console input with async bot messaging. input() blocks execution waiting for console input, but Telegram bots get messages through webhooks or polling callbacks. Each user message gets handled independently - there’s no continuous session like console programs.

You need to store conversation state between messages. I usually make a simple class to hold user data and current step, then use the user ID as key in a global dictionary. When #deposit comes in, create a new conversation object and ask the first question. Next message from that user picks up where they left off. Just remember to clean up finished conversations so your memory doesn’t blow up.

yeah, telegram bots can’t really pause n wait for input like reg python scripts. each msg gets handled separately. i usually use a dict w/ user_id as key to store their current step and answers. it works great for basic flows like this.

You’re mixing synchronous input methods with async - that won’t work. Telegram bots handle each message independently through handlers.

I hit this same wall building my first multi-step bot. You need conversation states with a finite state machine pattern. Make an enum for your steps and track user context between messages.

For the deposit flow: kick it off when #deposit comes in, then route messages based on where the user is. Stash the name and reference number in your state object until they finish.

Pro tip I learned the hard way - set timeouts for incomplete conversations. Users bail on flows all the time, and you’ll get memory bloat if you don’t clean up dead sessions.

Your problem is input() - that only works for console apps, not Telegram bots. You need a state machine for multi-step conversations. Set up a dictionary to track user states and conversation data. When someone sends #deposit, change their state to ‘waiting_for_name’ and ask your question. In your message handler, check their current state. If they’re in ‘waiting_for_name’, save their response and switch to ‘waiting_for_reference’. Keep this going until you’re done. Most Python Telegram libraries like python-telegram-bot have conversation handlers built-in, which beats manually tracking states every time.