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.
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.