This bot monitors changes to specific files in a GitHub repository and sends real-time notifications to a Telegram chat.
-
Create a Telegram Bot:
- Use BotFather to create a new bot and get the API token.
- Note the chat ID where you want to receive notifications (can be a channel or user chat).
-
Get a GitHub Personal Access Token:
- Go to GitHub Settings > Developer Settings > Personal Access Tokens.
- Generate a new token with
reposcope.
-
Set Environment Variables:
- Create a
.envfile in the project root with the following variables:GITHUB_TOKEN=your_github_token TELEGRAM_TOKEN=your_telegram_bot_token TELEGRAM_CHAT_ID=your_telegram_chat_id
- Create a
-
Install Dependencies:
- Run
pip install -r requirements.txt
- Run
-
Run the Bot:
- Execute
python github_monitor_bot.py - Send
/startto your bot to begin monitoring.
- Execute
- Repository: Edit
REPO_OWNERandREPO_NAMEingithub_monitor_bot.pyto target your desired repository. - In-Scope Files: Modify
IN_SCOPE_FILESto list the file paths you want to monitor. - Polling Interval: Adjust
POLL_INTERVAL(in seconds) as needed.
- This demo uses polling. For real-time updates, consider using GitHub webhooks.
- Ensure your environment variables are correctly set before running the bot.
- Monitors specific files in a GitHub repository
- Sends real-time notifications to a Telegram chat when changes are detected
- Shows commit details including author, message, and file changes
- Displays file diffs in notifications
- Status command to check current monitoring state
- Python 3.7 or higher
- A Telegram bot token (get from @BotFather)
- A GitHub Personal Access Token
- A Telegram chat ID where notifications will be sent
- Clone this repository:
git clone <repository-url>
cd github-monitor-bot- Install the required dependencies:
pip install -r requirements.txt- Create a
.envfile based on.env.example:
cp .env.example .env- Edit the
.envfile with your credentials:
TELEGRAM_TOKEN: Your Telegram bot token from @BotFatherGITHUB_TOKEN: Your GitHub Personal Access TokenTELEGRAM_CHAT_ID: The chat ID where notifications will be sentREPO_OWNER: The owner of the GitHub repositoryREPO_NAME: The name of the GitHub repositorySCOPED_FILES: Comma-separated list of files to monitor
- Start the bot:
python bot.py- In Telegram, send the following commands to your bot:
/start- Get a welcome message and basic instructions/status- Check the current monitoring status
- Open Telegram and search for @BotFather
- Send
/newbotand follow the instructions - Copy the token provided by BotFather
- Go to GitHub Settings > Developer Settings > Personal Access Tokens
- Generate a new token with
reposcope - Copy the generated token
- Start a chat with your bot
- Send any message to the bot
- Visit
https://api.telegram.org/bot<YourBOTToken>/getUpdates - Look for the
"chat":{"id":XXXXX}in the response
- Never commit your
.envfile or share your tokens - Use environment variables or a secure secret management system in production
- Regularly rotate your GitHub token
- Consider using a dedicated GitHub account for monitoring
Feel free to submit issues and enhancement requests!