Skip to content

Daniilmipt/Telegram-news-analyzer

Repository files navigation

Telegram News Analyzer

πŸ€– Intelligent bot for analyzing negative posts in Telegram channels

πŸ“‹ Description

Telegram News Analyzer is a powerful tool for monitoring and analyzing sentiment in Telegram channels. The bot uses modern machine learning technologies to detect negative posts based on the analysis of user comments.

✨ Key Features

  • πŸ” Sentiment analysis β€” automatic detection of negative posts using AI
  • πŸ“Š Multi-channel monitoring β€” simultaneous analysis of multiple channels
  • πŸ“… Flexible time ranges β€” analysis for today, yesterday, last week, last month, or a custom period
  • 🎯 Configurable thresholds β€” ability to adjust the sensitivity of the analysis

πŸ›  Technologies

  • Python 3.8+ β€” main programming language
  • Telethon β€” interaction with the Telegram API
  • Transformers β€” machine learning models for sentiment analysis
  • PyTorch β€” deep learning framework
  • spaCy & NLTK β€” natural language processing
  • pandas & scikit-learn β€” data analysis
  • python-telegram-bot β€” Telegram bot framework

πŸš€ Installation and Setup

1. Clone the repository

git clone https://github.com/your-username/Telegram-news-analyzer.git
cd Telegram-news-analyzer

2. Create a virtual environment

python -m venv venv
source venv/bin/activate  # Linux/Mac
# or
venv\Scripts\activate  # Windows

3. Install dependencies

pip install -r requirements.txt

4. Configure environment

Copy the env_template file to .env and fill in the required parameters:

cp env_template .env

Edit the .env file:

# Telegram API Configuration
TELEGRAM_API_ID=your_api_id_here
TELEGRAM_API_HASH=your_api_hash_here
TELEGRAM_PHONE=+1234567890

# Telegram Bot Token
BOT_TOKEN=your_bot_token_here

# Channels to analyze
CHANNELS_LIST=@yourchannel,@anotherchannel,@thirdchannel

# Analysis settings
NEGATIVE_COMMENT_THRESHOLD=0.3
OUTPUT_DIR=output
MAX_MESSAGES=200

5. Obtain API keys

Telegram API
  1. Go to my.telegram.org
  2. Log in to your account
  3. Create a new application
  4. Copy the API ID and API Hash
Telegram Bot Token
  1. Find @BotFather in Telegram
  2. Send the /newbot command
  3. Follow the instructions to create a bot
  4. Copy the generated token

🎯 Usage

Run the bot

python main.py

Bot commands

  • /start β€” start and main menu
  • /help β€” usage help
  • /analyze β€” start post analysis

Interface options

  1. πŸ“Š Analyze β€” select a period and start analysis
  2. πŸ“‹ Select channels β€” configure the list of channels to monitor
  3. ℹ️ Help β€” detailed information about the features

Analysis modes

  • πŸ“… Today β€” analyze posts for the current day
  • πŸ“† Yesterday β€” analyze posts for the previous day
  • πŸ“Š Last 7 days β€” weekly analysis
  • πŸ“ˆ Last 30 days β€” monthly analysis
  • πŸ”§ Custom period β€” arbitrary time range

πŸ“Š Report Formats

HTML report

  • Interactive web page with detailed statistics
  • Data visualizations and charts
  • Convenient navigation through results

JSON data

  • Structured data for further processing
  • Complete information about posts and comments
  • Metrics and statistics

βš™οΈ Parameters Configuration

Negativity threshold (NEGATIVE_COMMENT_THRESHOLD)

  • 0.3 (30%) β€” moderate sensitivity
  • 0.5 (50%) β€” high sensitivity
  • 0.2 (20%) β€” very high sensitivity

Maximum number of messages (MAX_MESSAGES)

  • Recommended: 100–500 messages
  • For large channels: 1000+ messages

πŸ“ Project Structure

Telegram-news-analyzer/
β”œβ”€β”€ main.py                 # Entry point
β”œβ”€β”€ telegram_bot.py         # Telegram bot logic
β”œβ”€β”€ telegram_client.py      # Client for working with Telegram API
β”œβ”€β”€ sentiment_analyzer.py   # Sentiment analysis
β”œβ”€β”€ report_generator.py     # Report generation
β”œβ”€β”€ config.py               # Configuration
β”œβ”€β”€ logging_config.py       # Logging configuration
β”œβ”€β”€ requirements.txt        # Dependencies
β”œβ”€β”€ env_template            # Configuration template
└── output/                 # Reports folder

πŸ”§ Development

Adding new channels

Edit the CHANNELS_LIST variable in the .env file:

CHANNELS_LIST=@channel1,@channel2,@channel3

Configuring the analysis model

You can change the machine learning model in sentiment_analyzer.py:

model_name = "cardiffnlp/twitter-xlm-roberta-base-sentiment"

Customizing reports

Edit report_generator.py to change the format and style of the reports.

πŸ› Troubleshooting

Common issues

  1. Telegram authorization error

    • Check that API_ID and API_HASH are correct
    • Make sure the phone number is in international format
  2. The bot does not respond

    • Check that BOT_TOKEN is correct
    • Make sure the bot is running and not blocked
  3. Sentiment analysis errors

    • Check your internet connection
    • Make sure all dependencies are installed

Logs

Logs are saved to logs/news_analyzer.log for debugging.

🀝 Contributing

We welcome contributions to the project! Please:

  1. Fork the repository
  2. Create a branch for your feature
  3. Make your changes
  4. Open a Pull Request

πŸ“ž Support

If you have any questions or issues:

Created with ❀️ for analyzing Telegram content

About

Telegram bot for news analyze

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages