📚 Telegram Study Schedule Bot - Setup Guide

This is a fully automated Telegram bot that helps users plan their study schedule with daily reminders at 7 AM.

Features

  • Manual /start command - Begin scheduling anytime (for testing)
  • Daily 7 AM automatic trigger - Sends schedule prompts automatically
  • Interactive subject selection - Choose from 7 subjects across 4 time slots
  • Auto-generated timetable - Bot creates and displays your complete schedule

Time Slots

  • Slot 1: 8:30 AM - 11:00 AM
  • Slot 2: 12:10 PM - 2:00 PM
  • Slot 3: 2:40 PM - 5:40 PM
  • Slot 4: 7:30 PM - 10:00 PM

Available Subjects

  1. 1. Aerodynamics
  2. 2. Space Dynamics
  3. 3. Propulsion
  4. 4. Structures
  5. 5. Flight Mechanics
  6. 6. Mathematics
  7. 7. Aptitude

1️⃣ Create a Telegram Bot (2 minutes)

  1. Open Telegram app
  2. Search for "BotFather" (official Telegram bot for creating bots)
  3. Type /newbot
  4. Choose a name (e.g., "Study Schedule Bot")
  5. Choose a username (must be unique, e.g., "study_schedule_bot_123")
  6. Copy the API Token - looks like: 123456789:ABCDefGhijKlmnoPqrsTuvWxyz-1A2B3C4D

2️⃣ Deploy Your Bot

Option A: Deploy to Vercel (Recommended - Free)

  1. Push your code to GitHub
  2. Go to vercel.com
  3. Click "New Project" and import your GitHub repository
  4. Add environment variables in Vercel dashboard:
    • TELEGRAM_BOT_TOKEN: Paste your API token from BotFather
    • CRON_SECRET: Create any random string (e.g., "your-super-secret-key-123")
  5. Deploy!

Your webhook URL will be: https://your-project.vercel.app/api/telegram

Option B: Run Locally

  1. Create .env.local file:
TELEGRAM_BOT_TOKEN=123456789:ABCDefGhijKlmnoPqrsTuvWxyz-1A2B3C4D
CRON_SECRET=your-super-secret-key-123
  1. Run: npm run dev
  2. Your local URL: http://localhost:3000/api/telegram
  3. Use a service like ngrok to expose locally: ngrok http 3000

3️⃣ Set Webhook URL

The webhook URL tells Telegram where to send user messages.

Using BotFather (Easiest):

  1. Open Telegram, message BotFather
  2. Type /mybots → select your bot → "API Token"
  3. Go back to chat and type /setwebhook
  4. Send your webhook URL: https://your-project.vercel.app/api/telegram
  5. BotFather will confirm: "Webhook was set"

Using cURL:

curl -X POST https://api.telegram.org/bot{YOUR_TOKEN}/setWebhook \
  -H "Content-Type: application/json" \
  -d '{"url":"https://your-project.vercel.app/api/telegram"}'

4️⃣ Set Daily 7 AM Reminder (Cron Job)

Your bot will send daily prompts to all users at 7 AM. Use a free cron service:

Using cron-job.org (Free - Recommended):

  1. Go to cron-job.org
  2. Sign up (free)
  3. Click "Create Cronjob"
  4. Fill in:
    • Title: "Study Bot Daily Reminder"
    • URL: https://your-project.vercel.app/api/cron/schedule
    • Request Method: POST
    • HTTP Headers: Add custom header:
      • Key: x-cron-secret
      • Value: The secret from your CRON_SECRET env variable
    • Schedule: Set to run daily at 7:00 AM (choose your timezone)
  5. Save!

Using Upstash (Free - Alternative):

  1. Go to upstash.com
  2. Sign up and create a QStash project
  3. Create a scheduled message:
    • Endpoint: https://your-project.vercel.app/api/cron/schedule
    • Schedule: 0 7 * * * (7 AM daily)
    • Headers: x-cron-secret: your-secret-key
    • Method: POST

5️⃣ Test Your Bot

  1. Open Telegram
  2. Search for your bot (the username you created)
  3. Click "Start"
  4. Or send the message: start
  5. Select subjects for each time slot
  6. Bot will show your complete schedule!

Test Manual Start Anytime:

  • Type /start → Bot will reset and start the schedule process again
  • Perfect for testing!

How It Works

User Interaction Flow:

User sends /start
        ↓
Bot asks: "Select subject for Slot 1 (8:30 AM - 11:00 AM)"
        ↓
User clicks a subject button
        ↓
Bot asks: "Select subject for Slot 2 (12:10 PM - 2:00 PM)"
        ↓
User clicks a subject button