2.3 KiB
Marvin Telegram Bot
Simple Telegram bot server that sends your Telegram messages and photos to OpenRouter and replies back. Recent conversation memory is stored persistently in SQLite.
Setup
- Copy the environment file:
cp .env.example .env
- Edit
.envand add:
TELEGRAM_BOT_TOKEN=...
OPENROUTER_API_KEY=...
SEARXNG_URL=http://192.168.0.225:8080
Get your key from:
https://openrouter.ai/keys
- Define the bot personality in
personality.md.
Example:
You are Marvin, a funny, slightly sarcastic assistant. Keep replies short and playful.
Optional settings in .env:
OPENROUTER_MODEL=openai/gpt-5.4-mini
PERSONALITY_FILE=personality.md
MEMORY_DB=marvin.sqlite
MAX_HISTORY_MESSAGES=20
Memory
Marvin stores chat messages and long-term memories in SQLite at marvin.sqlite by default.
The AI receives:
- the most recent
MAX_HISTORY_MESSAGESchat messages - all long-term memories for the current Telegram chat
Recent chat history commands:
/forget
Long-term memory commands:
/remember location = Zagreb
/memories
/forget_memory location
/forget_memories
Web browsing
Marvin will automatically search the web when a message looks like it needs current or live information, and it will return a short sourced summary directly. It uses your self-hosted SearXNG instance.
It will also automatically generate an image when a message looks like an image-generation request.
Use /web if you want to force a web search.
Use /image if you want to force image generation.
Example:
/web latest OpenRouter gpt-5.4-mini model ID
Images
Send the bot a photo with an optional caption/question and it will analyze it using the configured OpenRouter model.
Generate and send an image using Pollinations:
/image a sad robot drinking coffee in Zagreb, noir style
- Start the bot locally:
npm start
Then open Telegram and message your bot.
Production setup
Recommended production setup:
- Run Marvin as a systemd service
- Keep using polling
- Store config in
.env - Run it as a dedicated unprivileged user
- View logs with:
journalctl -u marvin -f
See deploy/README.md and deploy/marvin.service for an example service configuration.