Skip to main content

Mental Health Prediction Using Machine Learning: Building an Explainable AI Web Application

Machine learning is increasingly being explored for applications in healthcare and wellbeing. However, building an ML model for a sensitive domain such as mental health requires more than simply achieving a high accuracy score. I developed a Mental Health Prediction & Assessment System that combines machine learning, PHQ-9 screening, Explainable AI and a Flask-based web application. The project is available on GitHub: https://github.com/starJeet000/Mental-Health-Prediction-Using-Machine-Learning What Is the Project? The application is designed as an educational and preliminary screening system that evaluates mental-health-related information and produces a risk prediction. It combines an ML-based prediction system with a standardized PHQ-9 questionnaire. The purpose is not to replace mental-health professionals but to demonstrate how machine learning can be incorporated into a complete software application. Machine Learning Model Several classification algorithms were tr...

How I Built an AI-Powered Telegram Motivation Bot with Node.js and Gemini

What if your Telegram bot could do more than respond to commands?

I built a Telegram-based AI motivation system that generates personalized motivational messages, schedules them automatically, tracks user streaks, collects feedback, and continues operating even when the AI service becomes unavailable.

The project is called Telegram Daily Motivation Bot.


What Does the Bot Do?

The basic idea is simple:

Generate useful motivation → deliver it automatically → track engagement → learn from feedback.

Users can interact with the bot directly through Telegram.

Some of the available commands include:

  • /motivate — generate an instant motivational message

  • /today — retrieve the latest motivation

  • /subscribe — subscribe to automated messages

  • /unsubscribe — stop automated messages

  • /history — view recent generated messages

  • /stats — check engagement information

  • /leaderboard — view the global streak leaderboard

  • /schedule — configure delivery periods

  • /set_tone — customize the motivational style

  • /set_language — change the response language

  • /suggest_quote_topic — request motivation around a specific topic

The command system is implemented using the Telegram Bot API and Node.js.

The AI Layer

The interesting part is the generation engine.

Instead of keeping a static list of motivational quotes, the application sends a structured prompt to Google's Gemini API.

The generation system supports different personality styles such as:

  • Stoic

  • Warrior

  • Philosopher

  • Strategist

  • Mentor

  • Elder

  • Survivor

  • Observer

  • Wanderer

There are also different delivery modalities:

  • Raw reality

  • Deep observation

  • Quiet compassion

  • Pragmatic advice

This means two users don't necessarily have to receive the same type of motivational message.

Scheduled Automation

The bot isn't dependent on someone manually opening Telegram.

node-cron is used to schedule automated dispatches.

The current implementation supports:

  • Morning messages

  • Midday messages

  • Evening messages

  • Weekly messages

  • Automated database cleanup

The schedules are configured around the Asia/Kolkata timezone.

This turns the project from a simple chatbot into an automation system.

Personalization

Each user can have their own preferences.

The application stores information such as:

  • Subscription status

  • Streak

  • Language

  • Tone

  • Schedule preferences

  • Last activity

Users can therefore customize how and when they receive messages.

Streaks and Gamification

The bot also introduces a simple gamification layer.

As users continue interacting with the system, their streak increases.

The project includes milestone badges such as:

  • Rising Star

  • 7-Day Believer

  • Unbreakable

  • Iron Will

  • Century Member

There's also a leaderboard showing users with the highest active streaks.

The goal isn't to make the application complicated.

It's to demonstrate how a simple feature can create an engagement loop.

Feedback System

Each generated message contains 👍 and 👎 buttons.

When a user votes, the system records the feedback and the corresponding A/B variant.

This creates a basic feedback loop:

Generate → Deliver → Collect Feedback → Analyze

That pattern can eventually be extended into a much more sophisticated recommendation or personalization system.

Reliability Was Important

One of the biggest lessons from building this project was that an AI API should never be treated as an always-available dependency.

The generation service contains multiple layers of protection.

Retry Logic

If the Gemini request fails, the system retries the request.

Model Fallback

The project maintains a model priority chain so the application can move to another configured model when a model becomes unavailable.

Memory Cache

Recently generated content can be served from an in-memory cache when appropriate.

This can help reduce unnecessary API calls.

Local Fallback

If the AI generation system ultimately fails, the application can fall back to locally stored motivational content.

So the user can still receive a message instead of simply getting an error.

Telemetry

The project also records execution information such as:

  • Generation source

  • Response time

  • Success/failure state

  • Schedule period

  • A/B variant

  • Generated message

This is important because production applications need more than functionality.

You also need to know what the system is doing.

Express API

The project also exposes an Express server.

For example, the application provides an endpoint for retrieving recent generated quotes and a protected webhook endpoint for external broadcasts.

The broadcast endpoint uses an API key to authorize external requests before sending messages to active users.

Technology Stack

The main technologies are:

Backend

  • Node.js

  • Express.js

  • Telegram Bot API

  • node-telegram-bot-api

  • node-cron

AI

  • Google Gemini

  • @google/generative-ai

Configuration

  • dotenv

  • Environment variables

Testing

  • Jest

Storage

  • Local JSON-based application data and telemetry files

Architecture

At a high level, the system looks like this:

User
  │
  ▼
Telegram
  │
  ▼
Node.js Bot
  │
  ├── Command System
  ├── User Preferences
  ├── Scheduling
  ├── Streak System
  ├── Feedback
  │
  ▼
AI Generation Service
  │
  ├── Gemini
  ├── Retry Logic
  ├── Model Fallback
  ├── Memory Cache
  └── Local Fallback
  │
  ▼
Telemetry + Application Data

What I Learned

This project taught me that building an AI application isn't just about calling an LLM API.

The more interesting engineering problems are around the API:

  • What happens when it fails?

  • How do you prevent unnecessary requests?

  • How do users personalize the experience?

  • How do you measure response performance?

  • How do you collect feedback?

  • How do you automate repeated tasks?

  • How do you maintain a useful experience when the AI is unavailable?

These are the problems that turn an AI demo into an actual software project.

Final Thoughts

The Telegram Daily Motivation Bot started with a relatively simple idea: send motivational messages through Telegram.

But it evolved into a practical exploration of:

AI + APIs + automation + personalization + feedback + reliability.

That's also why I think small projects like this are useful for developers.

You don't necessarily need to build the next huge platform to learn production-style engineering.

Sometimes, a small bot is enough to explore the architecture behind much larger systems.

Source Code

The complete project is available on GitHub.

Check the repository to explore the implementation, experiment with the bot, and build your own version.

Comments

Popular posts from this blog

Cybersecurity & Ethical Hacking Terminology: 100+ Essential Terms Explained

Cybersecurity has its own vocabulary. When you begin studying cybersecurity, you will quickly encounter terms such as malware, phishing, vulnerability, exploit, authentication, authorization, firewall, zero-day, ransomware, social engineering, penetration testing, and threat actor . At first, these terms can seem confusing. Some are closely related, while others describe completely different concepts. This glossary provides a beginner-friendly explanation of the most important cybersecurity and ethical-hacking terminology. The goal is not to memorize every word. Instead, use this guide as a reference whenever you encounter an unfamiliar security term. A — Cybersecurity Terms Access Control Access control determines who or what is allowed to access a resource and what they are permitted to do with it . It is commonly implemented using permissions, roles, policies, and authentication mechanisms. Active Directory Active Directory is Microsoft's directory and identity-management techno...

Mandatory Skills Every Tech Professional Should Have on Their Resume

A technology resume is more than a collection of programming languages and frameworks. Recruiters want to understand what you can actually build, how you solve problems, and whether you can work with the tools used in modern software development. If you're preparing a resume for a software developer, web developer, DevOps engineer, data professional, or other technology role, these are the major skill categories you should consider including. 1. Programming Languages Start with the programming languages you actually know. Depending on your career path, these might include: JavaScript TypeScript Python Java C++ C# Go PHP Don't add every language you've ever watched a tutorial about. If an interviewer asks you to solve a problem using a language listed on your resume, you should be comfortable using it. 2. Frameworks and Libraries Framework knowledge is important because modern software development rarely involves building everything from scratch. Examples include: React Next...

The Complete AI + Cybersecurity + MERN Developer Roadmap for 2026

Artificial intelligence, cybersecurity, and web development are three of the most interesting areas of modern technology. Each field provides valuable career opportunities on its own. But combining them can create an especially powerful technical skill set. This roadmap is designed for developers and students who want to learn MERN + cybersecurity + AI and eventually build real-world applications that combine all three. Why Learn AI + Cybersecurity + MERN? Consider a modern security application. A user opens a React dashboard. The application sends information to a Node.js backend. The backend stores data in MongoDB. Security rules analyze the data. An AI service helps classify or summarize the results. That single system requires knowledge of: Frontend development Backend development Databases APIs Security AI Deployment This is the intersection we are targeting. Phase 1: Learn Web Fundamentals Start with: HTML CSS JavaScript HTTP REST APIs Git GitHub Do not rush into advanced AI bef...

Mental Health Prediction Using Machine Learning: Building an Explainable AI Web Application

Machine learning is increasingly being explored for applications in healthcare and wellbeing. However, building an ML model for a sensitive domain such as mental health requires more than simply achieving a high accuracy score. I developed a Mental Health Prediction & Assessment System that combines machine learning, PHQ-9 screening, Explainable AI and a Flask-based web application. The project is available on GitHub: https://github.com/starJeet000/Mental-Health-Prediction-Using-Machine-Learning What Is the Project? The application is designed as an educational and preliminary screening system that evaluates mental-health-related information and produces a risk prediction. It combines an ML-based prediction system with a standardized PHQ-9 questionnaire. The purpose is not to replace mental-health professionals but to demonstrate how machine learning can be incorporated into a complete software application. Machine Learning Model Several classification algorithms were tr...