A Python bot that monitors a JSON endpoint and sends Telegram notifications when:
- Data changes are detected
- Specified keywords appear in the data
- Periodic checking of a JSON API endpoint
- Change detection using hash comparison
- Keyword monitoring in JSON data
- Telegram notifications with Markdown formatting
- Manual data fetching and checking
- Start/stop monitoring controls
- Python 3.7+
- A Telegram bot token (from @BotFather)
- A Telegram chat ID
- Clone this repository
- Install dependencies:
pip install -r requirements.txt - Create a
.envfile with your configuration (see below)
Create a .env file in the project root with the following variables:
TELEGRAM_TOKEN=your_telegram_bot_token
TELEGRAM_CHAT_ID=your_chat_id
TARGET_URL=https://api.example.com/data.json
KEYWORDS=keyword1,keyword2,important_term
CHECK_INTERVAL=300
| Variable | Description |
|---|---|
TELEGRAM_TOKEN |
Your Telegram bot API token |
TELEGRAM_CHAT_ID |
The chat ID where notifications will be sent |
TARGET_URL |
The URL of the JSON endpoint to monitor |
KEYWORDS |
Comma-separated list of keywords to look for |
CHECK_INTERVAL |
Time between checks in seconds (default: 300) |
-
Creating a bot and getting a token:
- Start a chat with @BotFather on Telegram
- Send the command
/newbotand follow the instructions - Once created, BotFather will provide you with a token (like
123456789:ABCDefGhIJKlmNoPQRsTUVwxyZ)
-
Getting your Chat ID:
- Method 1: Send a message to @userinfobot
- Method 2: Send a message to your new bot, then access this URL:
https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates - Look for the "chat" object which contains "id"
Run the bot with:
python main.py
The bot will start and send a notification that it's online. It won't automatically start monitoring until you use the start command.
The bot responds to the following commands:
/start- Start monitoring the target URL at the configured interval/stop- Stop the monitoring process/fetch- Manually fetch data once and check for keywords/help- Display available commands and monitoring status
The bot is designed to be easily customizable for different JSON APIs:
- The
format_data()function inmain.pycan be modified to format the JSON data according to your needs - The data change detection uses hashing to identify when the endpoint returns different data
- Keyword checking is performed on the entire JSON string for simplicity
- 🤖 Bot is online! - When the bot starts up
- ✅ Monitoring started! - When monitoring is activated
- 🛑 Monitoring stopped - When monitoring is deactivated
- 🔄 Data has been updated! - When the JSON data changes
- 🔎 Found keywords: keyword1, keyword2 - When specified keywords are found
- 🔎 No keywords found - When no keywords are found during a check
Note: If your API endpoint is geo-restricted, consider using a VPN before making requests to the endpoint.