I’m building a Telegram bot that works like a quiz game where users answer multiple questions. I need to save both the questions I send and the answers users give back. Right now I’m thinking about using a database where I store everything using the user’s ID as the main identifier. But I’m not sure if this is the right approach or if there’s a better way to handle this kind of data storage. Should I use something like SQLite or maybe just keep everything in memory? Also, I’m having trouble finding good examples of similar bots with actual code that I can learn from. Most tutorials only show basic command handling but not how to manage ongoing conversations with data persistence.
totally agree, sqlite’s def the way to go. in-memory can get chaotic as you add stuff later. that structure with user_id, question_id, answer sounds solid for tracking. good luck with your bot!
Database approach is spot on. I built something similar last year and started with PostgreSQL, but SQLite would’ve been plenty unless you’re hitting thousands of concurrent users. The big lesson I learned: nail your schema design upfront. I had to restructure mine twice because I didn’t think about users retaking quizzes or tracking progress over time. For conversation state, store the current question index in your user table so you can handle interruptions. Users constantly restart conversations or send random messages mid-quiz. What worked for me was splitting things into separate tables - quiz_sessions, user_responses, and questions instead of cramming everything together. Makes querying way cleaner when you need reports or want to analyze user behavior.
In similar projects, I’ve often encountered the challenge of data storage during user interactions. My solution involved using a combination of Redis for caching conversation states while leveraging SQLite for permanent data storage. This approach allows for seamless chat flow management without data loss during bot restarts. A key insight I gained was to separate temporary conversation states from long-term quiz data. By maintaining the current question position and input validations in fast memory, you can ensure quick responses. However, it’s essential to save user answers and scores consistently to the database to maintain reliability. Establishing persistent storage early in development alleviates issues during debugging and enhances overall system stability.