Implementing a Habit Tracking Bot in a Mobile Application
A user marked a habit as complete three times in a row, then forgot for a week. The streak broke — motivation dropped. The primary goal of a habit tracker is to prevent this from happening. A reminder at the right moment matters more than beautiful design.
Reminder Logic — More Complex Than Just Cron
Naive implementation: cron runs daily at 20:00 — "Don't forget your habits". Works poorly: all notifications arrive simultaneously, users learn to ignore them.
Correct approach: each habit has its own schedule. "Exercise" — 7:00, "Reading" — 21:30, "Meditation" — 8:00 and 22:00. Plus smart reminders: if by 19:00 a habit isn't completed, send a reminder (only if the user enabled this option).
A server-side scheduler (Bull Queue) creates tasks for the next day for each habit of each user. At a scale of 10,000 users with 5 habits each — 50,000 tasks per day. Redis handles this; Bull processes the queue reliably.
User timezone is stored in the profile and factored into scheduling — all calculations in UTC, display in local time.
Mobile Application + Telegram Bot
Two interaction channels: mobile app (primary interface) and Telegram bot (quick marking without opening the app).
In Telegram, one button suffices: "✅ Done" — inline keyboard right in the notification. Tap it — streak is recorded, app updates on next open.
In the mobile app, push notifications with actionable notifications: on iOS via UNNotificationAction with identifier mark_done, on Android via RemoteInput or action button in NotificationCompat. User marks completion directly from the notification shade without opening the app.
Action handling on iOS:
UNUserNotificationCenter.current().delegate = self
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse) async {
if response.actionIdentifier == "mark_done" {
let habitId = response.notification.request.content
.userInfo["habit_id"] as? String
await HabitService.markCompleted(habitId: habitId)
}
}
Streaks and Gamification
Streak is the key motivational mechanic. Logic: completed today — streak +1, missed a day — streak resets (or give one "grace day" like Duolingo does).
Upon reaching milestones (7 days, 30 days, 100 days), the app sends a "congratulations" push with on-screen animation. In Flutter, lottie animation triggered when processing special FCM payload.
Developing a habit tracker bot + mobile app typically takes 3–5 weeks depending on gamification feature complexity.







