Marcus Vechiato

Telegram Alerts for UK Commute Disruptions

The Telegram notifier is independent of SwiftBar and xbar. It runs on a schedule and sends alerts when trains are cancelled or delayed beyond a threshold.

Repo: https://github.com/vechiato/uk-next-train/tree/main/telegram

What it does

  • Polls Huxley2 for configured routes inside defined time windows
  • Filters by weekdays and criteria per trip
  • Sends a single alert per problematic next train to avoid spam
  • Logs to cron.log for audit

Directory layout

  • notify_train.py — main script
  • config.json.example — starter config
  • setup_cron.sh — adds a cron job to run every 5 minutes
  • README.md — usage notes

Configure config.json

{
  "telegram_token": "YOUR_BOT_TOKEN",
  "telegram_chat_id": "YOUR_CHAT_ID",
  "trips": [
    {
      "name": "Morning Commute",
      "from": "WIM",
      "to": "WAT",
      "days": [, "tuesday", "thursday"],
      "time_start": "06:45",
      "time_end": "08:00",
      "criteria": {
        "notify_cancelled": true,
        "notify_delayed": true,
        "delay_threshold_minutes": 5
      }
    },
    {
      "name": "Evening Commute",
      "from": "WAT",
      "to": "WIM",
      "days": [, "tuesday", "thursday"],
      "time_start": "16:00",
      "time_end": "17:30",
      "criteria": {
        "notify_cancelled": true,
        "notify_delayed": true,
        "delay_threshold_minutes": 10
      }
    }
  ]
}

Setup

# Create bot and get token via @BotFather
# Get chat ID via @userinfobot

cd telegram
cp config.json.example config.json
# Edit config.json with token, chat ID, and trips

# Add a cron job every 5 minutes
chmod +x setup_cron.sh
./setup_cron.sh

# Or add manually:
# */5 * * * * /usr/bin/python3 /path/to/telegram/notify_train.py >> /path/to/telegram/cron.log 2>&1

Message format

  • Cancelled: ❌ Cancelled WIM → WAT 08:54
  • Delayed beyond threshold: ⏰ Delayed +7m WIM → WAT 09:02
  • Includes platform and destination when available