Skip to content

Gabrcodes/depi-schedule-bot

Repository files navigation

🇪🇬 DEPI Schedule Bot (Cohort 4)

A sophisticated Telegram bot designed to monitor the Digital Egypt Pioneers Initiative (DEPI) schedule API. It runs entirely on GitHub Actions, making it free and serverless, while providing real-time updates to students about their training schedules.

✨ Features

🤖 Core Functionality

  • Automated Monitoring: Runs every 5 minutes to check for schedule changes.
  • Smart Diffs: Doesn't just say "Updated"; it tells you exactly what changed (New sessions added, sessions removed, or details updated).
  • Bilingual Support: Fully localized in English and Arabic.
  • Multi-User Support: Allows multiple students to subscribe to updates.

🛡️ Admin & Security

  • Admin Priority: Admin receives notifications immediately. Subscribers receive them after a 10-minute delay (to allow admin verification).
  • Remote Control: Admin can Stop and Start the bot directly from Telegram buttons.
  • Token Management: Update the expired API token by simply pasting it into the chat. No need to open GitHub Settings!
  • Self-Destruct: "Nuke Subscribers" button to clear the database if needed.

🚀 Setup Guide

1. Prerequisites

  • A GitHub Account.
  • A Telegram Account.
  • Python 3.12+ (for local token generation).

📊 Live Dashboard

You can view the real-time status of the bot, including the last run time, subscriber count, and latest schedule changes here: 🔗 View Status Dashboard (Note: Enable GitHub Pages in Settings > Pages > Source: "Deploy from a branch" > Branch: "main" / "root")

🚀 Setup Guide

1. Prerequisites

  • A GitHub Account.
  • A Telegram Account.
  • Python 3.12+ (for local token generation).

2. GitHub Repository Setup

  1. Fork or Push this repository to your own GitHub account.
  2. Navigate to Settings > Secrets and variables > Actions.
  3. Add the following Repository Secrets:
Secret Name Value / Description
TELEGRAM_TOKEN Get this from @BotFather on Telegram.
TELEGRAM_ADMIN_ID Your numeric Telegram ID (use @userinfobot to find it).
DEPI_TOKEN The initial Bearer token (see "Getting the Token" below).
SCHEDULE_API https://api.depi.gov.eg/api/Schedule/GetUserSchedules
ENCRYPTION_KEY Required for Public Repos. Run python generate_key.py to get this.

3. Getting the Token & Key (Local Step)

  1. Install dependencies:

    pip install playwright requests cryptography
    playwright install
  2. Generate Encryption Key:

    python generate_key.py

    Copy the output key and add it as ENCRYPTION_KEY in GitHub Secrets. This ensures your data is encrypted before being saved to the public repo.

  3. Get DEPI Token:

    python get_token.py

    Copy the token and add it as DEPI_TOKEN in GitHub Secrets.

4. Enable GitHub Pages (For Dashboard)

  1. Go to Settings > Pages.
  2. Under Build and deployment, select Source: Deploy from a branch.
  3. Select Branch: main and folder /(root).
  4. Click Save.

🎮 Usage

User Commands

  • /start or Hello: Subscribe to updates and show the main menu.
  • 📅 Check Schedule / جدول المواعيد: Checks if the bot is running and when the next update is due.
  • ℹ️ About Bot / عن البوت: Shows information about the bot.

Admin Commands (Hidden)

  • 🛑 Stop Bot: Pauses the bot. It will still run on GitHub but will exit immediately without checking the API.
  • ▶️ Start Bot: Resumes normal operation.
  • 💣 Nuke Subscribers: Deletes all subscribers from subscribers.json (except the admin).
  • Paste Token: Simply paste a long token string (containing dots) into the chat to update the DEPI_TOKEN for the next run.

🛠️ Architecture & Maintenance

How it Works

The bot is stateless but persistent.

  1. GitHub Action triggers depi.py every 5 minutes.
  2. It loads state from state.json (encrypted) and subscribers.json (encrypted).
  3. It fetches the API.
  4. If changes are found, it notifies the admin and queues messages for subscribers.
  5. It updates status.json (unencrypted, safe data) for the dashboard.
  6. It commits and pushes the updated files back to the repository.

Handling Token Expiry

When the token expires (usually after a few hours or days):

  1. The bot will message the Admin: "⚠️ Token expired! Please paste the new token here..."
  2. Run python get_token.py on your local machine.
  3. Copy the new token.
  4. Paste it directly into the Telegram chat.
  5. The bot will save it to state.json and use it for the next run.

📂 File Structure

  • depi.py: The brain of the bot. Handles logic, Telegram API, encryption, and diffing.
  • index.html: The status dashboard.
  • get_token.py: Local tool to bypass CloudWAF and get a valid session token.
  • generate_key.py: Tool to generate the encryption key.
  • state.json: Encrypted state file.
  • subscribers.json: Encrypted subscribers list.
  • status.json: Public status data for the dashboard.
  • .github/workflows/schedule.yml: Configuration for the 5-minute CRON timer.

⚠️ Troubleshooting

  • Bot not replying? GitHub Actions might be delayed. Check the "Actions" tab in your repo.
  • 403/401 Errors? Your token is expired. Generate a new one and paste it in the chat.
  • GitHub Action failing to push? Ensure "Workflow permissions" in Settings > Actions > General are set to "Read and write permissions".

About

A serverless Telegram bot that monitors DEPI Cohort 4 schedules. Features bilingual notifications (En/Ar), smart diffs, and runs entirely on GitHub Actions.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors