โ† Back to Blog

๐Ÿ“ฌ Real-Time Telegram Notifications for Comments & High Scores

๐Ÿ“… April 10, 2026 โฑ๏ธ 10 min read

Want to know instantly when someone comments on your blog or beats your game high score? Here's how I built a zero-cost notification system that sends alerts straight to Telegramโ€”no third-party services, no monthly fees, just a simple Python script and Linux cron.

๐Ÿ“‹ Before You Start

  • Your blog already saves comments/high scores to JSON files (e.g., ~/blog-comments/data/)
  • You have SSH access to your VPS
  • You can create a Telegram bot (or reuse an existing one)
  • Basic comfort with copying/pasting commands

The Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ JSON DATA FILES โ”‚ โ”‚ ~/blog-comments/data/comments.json โ”‚ โ”‚ ~/blog-comments/data/highscores.json โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ File timestamps โ–ผ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ CRON (every 2 minutes) โ”‚ โ”‚ โ””โ”€> Python script checks mtime โ”‚ โ”‚ โ””โ”€> If newer: reads JSON, finds new entries โ”‚ โ”‚ โ””โ”€> Sends HTTP POST to Telegram API โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ HTTPS โ–ผ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ TELEGRAM BOT โ”‚ โ”‚ Instant message to your phone/desktop โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The script doesn't constantly watch the files. Every 2 minutes cron wakes it up, it compares the file's last-modified time against a hidden .last-check file, and only sends a message if something new appeared.

Why This Design?

The Setup

1. Create a Telegram Bot

  1. Open Telegram, search for @BotFather
  2. Send /newbot and follow prompts
  3. Copy your bot token (looks like: 123456789:ABCdef...)

2. Get Your Chat ID

This is the number the bot will message. The easiest way:

  1. In Telegram, search for @getmyid_bot (or @userinfobot)
  2. Tap Start
  3. The bot will instantly reply with your Chat ID (a number like 123456789)

๐Ÿ’ก Pro tip: If you already use OpenClaw with Telegram, your chat ID is already saved in ~/.openclaw/.env. Just open that file and copy the TELEGRAM_CHAT_ID value. It's the same ID for every bot you create.

3. Store Credentials Securely

# Create/edit the config file
nano ~/.openclaw/.env

# Add these lines:
TELEGRAM_BOT_TOKEN=your_token_here
TELEGRAM_CHAT_ID=your_chat_id_here

# Set permissions (only you can read it)
chmod 600 ~/.openclaw/.env

๐Ÿ”’ Security: Never commit this file to git. Add it to your .gitignore. The token gives full control of your bot to anyone who has it.

4. The Notification Script

Here's the core logic that runs every 2 minutes:

#!/usr/bin/env python3
"""Check for new comments/highscores and notify via Telegram."""

import os
import json
from datetime import datetime

COMMENTS_FILE = "~/blog-comments/data/comments.json"
LAST_CHECK_FILE = "~/blog-comments/data/.last-check"

def check_for_updates():
    if not os.path.exists(LAST_CHECK_FILE):
        return False  # First run initialization
    
    last_check = os.path.getmtime(LAST_CHECK_FILE)
    json_mtime = os.path.getmtime(COMMENTS_FILE)
    
    if json_mtime <= last_check:
        return False  # No changes
    
    # Read and find new comments
    with open(COMMENTS_FILE) as f:
        comments = json.load(f)
    
    new_items = [c for c in comments 
                 if parse_timestamp(c['timestamp']) > last_check]
    
    if new_items:
        send_telegram_notification(new_items)
    
    # Update timestamp
    os.utime(LAST_CHECK_FILE, None)
    return True

๐Ÿ“ Note: The code above is simplified core logic. The full working script (including the parse_timestamp() and send_telegram_notification() helper functions) is available in ~/blog-comments/scripts/check_new.py. The version shown here focuses on the key ideas.

5. Add the Cron Job

# Edit crontab
crontab -e

# Add this line (runs every 2 minutes)
# IMPORTANT: Use full path, not ~/
*/2 * * * * /usr/bin/python3 /home/yourusername/blog-comments/scripts/check_new.py >> /tmp/notifications.log 2>&1

Tip: Replace /home/yourusername with your actual home path (type echo $HOME to check). The log file in /tmp/ auto-clears on rebootโ€”perfect for testing.

Testing It Works

  1. Post a test comment on any blog post
  2. Wait 2 minutes (or run manually: python3 ~/blog-comments/scripts/check_new.py)
  3. Check Telegram for notification

Expected comment notification:

๐Ÿ’ฌ New Comment

๐Ÿ“ ๐Ÿ“ Blog: Telegram Notifications Setup
Username: Great article! Very helpful...

๐Ÿ“ ๐Ÿ“š Book: Zero to One
Reader: Loved this book review!

Expected high score notification:

๐Ÿ† New High Score

๐ŸŽฎ 2048
Player1: 25,000 pts

๐ŸŽฎ Crypto Breakout
Gamer42: 15,500 pts

Check logs: tail -f /tmp/notifications.log

Cost Breakdown

Managing Comments

Comments are stored in ~/blog-comments/data/comments.json. I created an admin script to manage them:

# List all comments
python3 ~/blog-comments/scripts/admin_comments.py list

# Filter by type
python3 ~/blog-comments/scripts/admin_comments.py list --type blog

# Search for text
python3 ~/blog-comments/scripts/admin_comments.py search "inappropriate"

# Delete by ID
python3 ~/blog-comments/scripts/admin_comments.py delete abc123

# Show statistics
python3 ~/blog-comments/scripts/admin_comments.py stats

To manually delete:

# Backup first
cp ~/blog-comments/data/comments.json ~/blog-comments/data/comments.json.bak

# Delete by ID
python3 -c "
import json
with open('$HOME/blog-comments/data/comments.json') as f:
    data = json.load(f)
data = [c for c in data if c['id'] != 'THE_ID']
with open('$HOME/blog-comments/data/comments.json', 'w') as f:
    json.dump(data, f, indent=2)
"

๐Ÿ’ก Note: Deleting comments doesn't affect the notification script. It simply reads the file each time it runs.

Extending It

Troubleshooting

Summary

This setup gives you instant notifications for zero cost. It's completely self-hosted, uses no external AI APIs, and runs entirely on your existing VPS infrastructure.

The patternโ€”file timestamp checking with cronโ€”is useful for any event-driven notification system. Same approach works for: log monitoring, file uploads, backup completion, certificate expiration, and more.

๐Ÿ’ฌ Comments

Email is required for anti-spam but can be fake if you prefer privacy.

Loading comments...
// Initialize engagement if (typeof EngagementSystem !== 'undefined') { EngagementSystem.initLikeButton('#like-container', 'blog', 'telegram-notifications-setup'); EngagementSystem.initSubscribeForm('#subscribe-container', { title: '๐Ÿ“ง Subscribe for Blog Updates', description: 'Get notified when new articles are published.' }); }