Cloud AI chatbots are convenient, but every message you send goes to someone else's servers. A public Telegram bot is also open to anyone who finds its username, which is a problem if it can read your server logs. You want a small assistant that lives on your own machine and answers only you.
Prerequisites
You need a VPS running Ubuntu 24.04 with 2 vCPU and 4 GB RAM. An SSH connection to the server is required to execute the deployment commands.
The Architecture: Local Inference, Remote Interface
This guide builds a Telegram bot running in Docker on your VPS that talks to a tiny local Ollama model. It summarizes a server log on request and ignores everyone except your Telegram ID. Self-hosting keeps your prompts and logs on your own server, costs nothing per request, and needs no GPU.
Security Through Obscurity and Access Control
Unlike public bots, this implementation enforces strict access control via a hardcoded owner ID. The Python script, contained within the tgbot Docker container, checks every incoming message against a numeric Telegram ID stored in a restricted .env file. If the sender ID does not match the owner, the bot silently ignores the message and logs the attempt. This prevents unauthorized users from consuming your serverβs CPU cycles or probing your private data.
Deployment Steps
The setup begins by updating the system package list and installing Docker and Ollama using their official installation scripts. A small Python script is then created to handle Telegram polling and Ollama API calls, with a /logs command specifically designed to summarize the last lines of the system's dpkg log.
Operational Simplicity
The bot is launched as a Docker container using host networking to communicate with the local Ollama instance at 127.0.0.1:11434. This ensures the AI endpoint remains invisible to external scanners, as Ollama lacks native authentication. The deployment relies on standard tools like curl and emphasizes security hygiene, such as setting chmod 600 on the environment file to protect the Telegram bot token.
Key Takeaways
- Privacy First: All prompts and server log summaries remain on your VPS, eliminating cloud data leakage.
- Cost Effective: The solution requires no per-request fees and runs on standard, low-cost VPS hardware (2 vCPU / 4 GB RAM).
- Owner-Only Access: A strict ID check ensures the bot responds exclusively to the configured user, ignoring all other traffic.
- Lightweight Model: Qwen 2.5 (0.5B) is used to balance speed and resource usage, suitable for basic queries rather than complex reasoning.
The Bottom Line
For developers who value data sovereignty over raw intelligence, this stack is a pragmatic win. It sacrifices deep reasoning for total privacy and zero marginal cost, making it ideal for sensitive log analysis and quick queries on modest hardware.