I’m working on a Telegram bot and want to set up automatic messages that get sent to users for 5 consecutive days after they first interact with my bot. Each user should get their own personalized schedule based on when they initially started the conversation. Can I track when someone first sends a message to my bot and use that timestamp to create individual notification schedules? I’m wondering if there’s a way to store the initial contact time for each chat ID and then trigger daily messages for each user separately. What would be the best approach to handle this kind of user-specific timing system?
I’ve had good luck with a cron job setup for this. Create a database table with user_id, start_date, and current_day columns. When someone first messages your bot, add them with day 0. Then run a daily scheduled task that grabs all active users, figures out what reminder day they’re on, and fires off the right message. Make sure you handle errors properly - if a message won’t send, mark that user inactive so you don’t keep hitting the same failures. Way more reliable than trying to manage individual timers per user, especially when your server restarts or you need to scale.
yep, u can def do that! just save the chat_id and first interaction time in a db like sqlite. then use something like APScheduler for daily reminders. it’s pretty easy once u get it all set up!
I dealt with this recently. Best approach I found: database + scheduled tasks. Store each user’s chat_id and when they first interacted. For scheduling, use Python’s asyncio with sleep intervals or a background worker that checks the database every few hours. The trick is calculating time between now and their start date - that tells you which day they’re on. Don’t forget edge cases like users blocking your bot mid-sequence. Catch those delivery failures and kill their reminder cycle so you’re not wasting resources.