Skip to content

noderik/FoolOfREST

Repository files navigation

FoolOfREST

A Telegram message logging system. A Python bot captures messages from Telegram chats and stores them in PostgreSQL. A REST API and MVC web frontend provide access to the logged data.

Architecture

Component Tech Description
FoolOfRESTAPI ASP.NET Core 9, EF Core, Npgsql REST API for querying logged data
FoolOfRESTWeb ASP.NET Core 9 MVC, Tailwind CSS Web interface for browsing chats and users
TelegramLogger Python 3.11, python-telegram-bot, psycopg3 Telegram bot that logs all messages to the database. Runs as a subprocess inside the API container
PostgreSQL 16 Stores users, chats, and messages

The API generates a random key on startup and shares it with the web frontend for internal authentication. All API endpoints require this key via the APIKEY header.

Prerequisites

  • Docker and Docker Compose
  • A Telegram bot token — create one via @BotFather and add it to a group or use it in private chats

Running with Docker

Test (no configuration needed except a bot token)

Uses a pre-configured PostgreSQL instance with hardcoded credentials. All connection strings are injected automatically.

TOKEN=your_telegram_bot_token docker compose -f docker-compose.test.yml up

Or set TOKEN in a .env file and run:

docker compose -f docker-compose.test.yml up

Production

  1. Copy the example environment file and fill in your values:

    cp .env.backend.example .env
    Variable Description
    DB_USER PostgreSQL username
    DB_PASSWORD PostgreSQL password
    POSTGRES_CONNECTION_STRING Npgsql connection string for the API (e.g. Host=db;Database=logger;Username=USER;Password=PASS)
    CONNECTION_STRING libpq connection string for the bot (e.g. host=db port=5432 dbname=logger user=USER password=PASS)
    TOKEN Telegram bot token
    APIKEY Shared secret between the API and Web containers (any random string)
  2. Start all services:

    docker compose up

Services

Service URL Notes
Web frontend http://localhost:5002 Browse chats and users
REST API http://localhost:5001 Requires APIKEY header
PostgreSQL (test) localhost:5431 Credentials: postgres / testdb
PostgreSQL (prod) localhost:5433 Credentials from .env

Running without Docker

Requires a running PostgreSQL instance. Configure the connection string in FoolOfRESTAPI/appsettings.Development.json:

{
  "ConnectionStrings": {
    "Docker": "Host=localhost;Port=5431;Database=logger;Username=postgres;Password=testdb"
  }
}

Start both .NET projects (the API automatically launches the Python bot as a subprocess):

./run_project.sh

For Python bot setup (token, virtual environment), see TelegramLogger/Config.md.

API Endpoints

All endpoints require an APIKEY header matching the key generated by the API on startup.

Method Path Description
GET /users/ All users
GET /users/{id} User by ID
GET /chats All chats
GET /chats/{id} Chat by ID
GET /messages/ All messages
GET /messages/{id} Message by ID
GET /usermessages/{userid} Messages from a user
GET /chatmessages/{chatid} Messages in a chat
GET /chatusers/{chatid} Users in a chat

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors