Use Sentiment Analysis

This guide will help you set up and use Sentiment Analysis by NeurochainAI for monitoring sentiment in Telegram group chats. With this setup, you'll be able to analyze group messages, track sentiment, and collect insights using Docker and Python.


Prerequisites

Before starting, ensure you have the following software installed:


Step 1: Clone the Repository

Begin by cloning the Sentiment Analysis repository and navigating to the project directory:

# Clone the repository
git clone https://github.com/NeuroChainAi/python-telegram-sentiment.git

# Navigate to the project directory
cd python-telegram-sentiment
    

  1. Install Dependencies

Install the Python dependencies from the requirements file

# Install dependencies
pip install -r requirements.txt
    

  1. Configure Environment Variables

Create a `.env` file with the following environment variables:

# .env file content
NEUROCHAIN_API_KEY=your_neurochain_api_key
TELEGRAM_API_KEY=your_telegram_api_key
DATABASE_URL=postgres://your_user:your_password@postgres/your_database
    

  1. Setup Docker Compose

Docker Compose sets up both PostgreSQL and the Telegram bot. Use the following command to start the services:

# Build and start Docker services
docker-compose up --build
    

This command will:

  • Start a PostgreSQL container

  • Build and run the Telegram bot container

  1. Docker Compose File Structure

The `docker-compose.yml` file defines both PostgreSQL and the bot containers. Below is the structure:

version: '3.8'

services:
  # PostgreSQL container
  postgres:
    image: postgres:14
    environment:
      POSTGRES_USER: your_user
      POSTGRES_PASSWORD: your_password
      POSTGRES_DB: your_database
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data

  # Telegram bot container
  telegram-bot:
    build: ./bot  # Path to the bot folder where the Dockerfile is located
    environment:
      DATABASE_URL: postgres://your_user:your_password@postgres/your_database  # Database connection string
                  NEUROCHAIN_API_KEY: your_neurochain_api_key
      TELEGRAM_API_KEY: your_telegram_api_key
    depends_on:
      - postgres  # Ensures PostgreSQL starts before the bot
    volumes:
      - ./bot:/app  # Mount the bot folder to the container
    restart: always

volumes:
  postgres_data:
    driver: local
    

  1. Running the Bot

Once the containers are running, the bot should start interacting with the Telegram API and PostgreSQL. You can monitor logs to check the status:

# Monitor logs
docker-compose logs -f
    

  1. Stopping the Containers

To stop and remove the containers, use the following command:

docker-compose down
    

Last updated