Skip to content

nova032/buggit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Monitor Telegram Bot

This bot monitors changes to specific files in a GitHub repository and sends real-time notifications to a Telegram chat.

Setup

  1. 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).
  2. Get a GitHub Personal Access Token:

  3. Set Environment Variables:

    • Create a .env file 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
      
  4. Install Dependencies:

    • Run pip install -r requirements.txt
  5. Run the Bot:

    • Execute python github_monitor_bot.py
    • Send /start to your bot to begin monitoring.

Configuration

  • Repository: Edit REPO_OWNER and REPO_NAME in github_monitor_bot.py to target your desired repository.
  • In-Scope Files: Modify IN_SCOPE_FILES to list the file paths you want to monitor.
  • Polling Interval: Adjust POLL_INTERVAL (in seconds) as needed.

Notes

  • This demo uses polling. For real-time updates, consider using GitHub webhooks.
  • Ensure your environment variables are correctly set before running the bot.

Features

  • 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

Prerequisites

  • 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

Installation

  1. Clone this repository:
git clone <repository-url>
cd github-monitor-bot
  1. Install the required dependencies:
pip install -r requirements.txt
  1. Create a .env file based on .env.example:
cp .env.example .env
  1. Edit the .env file with your credentials:
  • TELEGRAM_TOKEN: Your Telegram bot token from @BotFather
  • GITHUB_TOKEN: Your GitHub Personal Access Token
  • TELEGRAM_CHAT_ID: The chat ID where notifications will be sent
  • REPO_OWNER: The owner of the GitHub repository
  • REPO_NAME: The name of the GitHub repository
  • SCOPED_FILES: Comma-separated list of files to monitor

Usage

  1. Start the bot:
python bot.py
  1. In Telegram, send the following commands to your bot:
  • /start - Get a welcome message and basic instructions
  • /status - Check the current monitoring status

How to Get Required Tokens

Telegram Bot Token

  1. Open Telegram and search for @BotFather
  2. Send /newbot and follow the instructions
  3. Copy the token provided by BotFather

GitHub Personal Access Token

  1. Go to GitHub Settings > Developer Settings > Personal Access Tokens
  2. Generate a new token with repo scope
  3. Copy the generated token

Telegram Chat ID

  1. Start a chat with your bot
  2. Send any message to the bot
  3. Visit https://api.telegram.org/bot<YourBOTToken>/getUpdates
  4. Look for the "chat":{"id":XXXXX} in the response

Security Notes

  • Never commit your .env file 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

Contributing

Feel free to submit issues and enhancement requests!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages