{"id":44823708,"url":"https://github.com/artcc/ollama-telegram-bot","last_synced_at":"2026-02-16T21:02:02.727Z","repository":{"id":338423542,"uuid":"1157826237","full_name":"ArtCC/ollama-telegram-bot","owner":"ArtCC","description":"Open-source Telegram bot to chat with Ollama models running on your server.","archived":false,"fork":false,"pushed_at":"2026-02-14T15:36:02.000Z","size":1856,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-14T20:08:14.845Z","etag":null,"topics":["artificial-intelligence","llm","ollama","ollama-api","python","telegram","telegrambot"],"latest_commit_sha":null,"homepage":"https://www.arturocarreterocalvo.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ArtCC.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-14T11:06:18.000Z","updated_at":"2026-02-14T15:36:05.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ArtCC/ollama-telegram-bot","commit_stats":null,"previous_names":["artcc/ollama-telegram-bot"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ArtCC/ollama-telegram-bot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtCC%2Follama-telegram-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtCC%2Follama-telegram-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtCC%2Follama-telegram-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtCC%2Follama-telegram-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ArtCC","download_url":"https://codeload.github.com/ArtCC/ollama-telegram-bot/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtCC%2Follama-telegram-bot/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29518593,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-16T18:37:19.720Z","status":"ssl_error","status_checked_at":"2026-02-16T18:36:46.920Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["artificial-intelligence","llm","ollama","ollama-api","python","telegram","telegrambot"],"created_at":"2026-02-16T21:01:08.985Z","updated_at":"2026-02-16T21:02:02.709Z","avatar_url":"https://github.com/ArtCC.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ollama Telegram Bot\n\n[![Docker Publish](https://github.com/ArtCC/ollama-telegram-bot/actions/workflows/docker-publish.yml/badge.svg)](https://github.com/ArtCC/ollama-telegram-bot/actions/workflows/docker-publish.yml)\n[![License: Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)\n[![Python 3.12+](https://img.shields.io/badge/Python-3.12%2B-3776AB?logo=python\u0026logoColor=white)](https://www.python.org/)\n[![Docker Compose](https://img.shields.io/badge/Docker%20Compose-Ready-2496ED?logo=docker\u0026logoColor=white)](docker-compose.yml)\n[![GHCR](https://img.shields.io/badge/GHCR-ghcr.io%2Fartcc%2Follama--telegram--bot-181717?logo=github)](https://ghcr.io/artcc/ollama-telegram-bot)\n\n\u003cp align=\"left\"\u003e\n  \u003cimg src=\"assets/ollama-telegram-bot.png\" alt=\"Ollama Telegram Bot Avatar\" width=\"150\"\u003e\n\u003c/p\u003e\n\nOpen-source Telegram bot to chat with Ollama models running on your server.\n\n## Overview\n\n- Telegram bot with async handlers and user-friendly error responses.\n- Ollama integration with timeout, retries, and categorized failures.\n- Docker-first deployment with environment-driven configuration.\n- CI workflow for publishing container images to GHCR.\n- Text + image interaction mode: voice/audio messages are intentionally disabled.\n\n## Project Structure\n\n```text\nollama-telegram-bot/\n├── .github/\n│   └── workflows/\n│       └── docker-publish.yml\n├── locales/\n│   ├── de.json\n│   ├── en.json\n│   ├── es.json\n│   ├── fr.json\n│   └── it.json\n├── src/\n│   ├── app.py\n│   ├── bot/\n│   │   ├── handlers.py\n│   │   └── error_handler.py\n│   ├── config/\n│   │   └── settings.py\n│   ├── core/\n│   │   ├── context_store.py\n│   │   ├── model_preferences_store.py\n│   │   └── rate_limiter.py\n│   ├── i18n/\n│   │   ├── __init__.py\n│   │   └── service.py\n│   ├── services/\n│   │   └── ollama_client.py\n│   └── utils/\n│       ├── logging.py\n│       └── telegram.py\n├── tests/\n│   ├── test_context_store.py\n│   ├── test_context_store_sqlite.py\n│   ├── test_i18n_service.py\n│   ├── test_model_preferences_store.py\n│   ├── test_rate_limiter.py\n│   ├── test_settings.py\n│   └── test_telegram_utils.py\n├── docker-compose.yml\n├── Dockerfile\n├── .env.example\n├── CHANGELOG.md\n├── CONTRIBUTING.md\n└── pyproject.toml\n```\n\n## Phase 1 (MVP)\n\n- [x] Core bot architecture and environment-based configuration.\n- [x] Docker-first deployment with Compose and GHCR publish workflow.\n- [x] Core conversation flow with contextual chat and error-safe Ollama calls.\n- [x] Base command set and UX (`/start`, `/help`, `/health`, `/clear`, `/models`, `/currentmodel`).\n- [x] Unified bot UI (slash commands + persistent quick buttons + inline actions).\n- [x] Unified status messaging (`ℹ️ info`, `✅ success`, `⚠️ warning`, `❌ error`).\n- [x] Per-user model management with SQLite persistence.\n- [x] Access control with user whitelist (`ALLOWED_USER_IDS`).\n- [x] Basic per-user rate limiting.\n- [x] Healthcheck command and operational status checks.\n- [x] Logging hardening for production observability.\n\n## Phase 2: New features\n\n- [x] Primary inference migration to Ollama Chat API (`/api/chat`).\n- [x] Automatic fallback to `/api/generate` for compatibility and resilience.\n- [x] Runtime feature flags for chat migration:\n  - `OLLAMA_USE_CHAT_API`\n  - `OLLAMA_KEEP_ALIVE`\n- [x] Configuration and deployment docs updated for new Chat API controls.\n- [x] Internal agent routing (planner/analyzer/chat) with natural-language responses only.\n- [x] Persistent SQLite conversation context across restarts.\n- [x] Natural-language-first UX: no extra technical commands required for advanced behavior.\n- [x] Image input support (photo/image document + optional caption instruction) using the selected model.\n- [x] Localization support with user Telegram language resolution and English fallback.\n- [x] Locale files available for `en`, `es`, `de`, `fr`, and `it`.\n\n## Configuration\n\nThe stack configuration file is `docker-compose.yml`.\n\n```yaml\nservices:\n  bot:\n    image: ${BOT_IMAGE}\n    container_name: ${BOT_CONTAINER_NAME:-ollama-telegram-bot}\n    restart: unless-stopped\n    volumes:\n      - ${BOT_DATA_DIR:-./data}:/data\n    environment:\n      TELEGRAM_BOT_TOKEN: ${TELEGRAM_BOT_TOKEN}\n      OLLAMA_BASE_URL: ${OLLAMA_BASE_URL}\n      OLLAMA_DEFAULT_MODEL: ${OLLAMA_DEFAULT_MODEL}\n      OLLAMA_USE_CHAT_API: ${OLLAMA_USE_CHAT_API:-true}\n      OLLAMA_KEEP_ALIVE: ${OLLAMA_KEEP_ALIVE:-5m}\n      MODEL_PREFS_DB_PATH: ${MODEL_PREFS_DB_PATH:-/data/bot.db}\n      ALLOWED_USER_IDS: ${ALLOWED_USER_IDS}\n      LOG_LEVEL: ${LOG_LEVEL:-INFO}\n      REQUEST_TIMEOUT_SECONDS: ${REQUEST_TIMEOUT_SECONDS:-60}\n      MAX_CONTEXT_MESSAGES: ${MAX_CONTEXT_MESSAGES:-12}\n      RATE_LIMIT_MAX_MESSAGES: ${RATE_LIMIT_MAX_MESSAGES:-8}\n      RATE_LIMIT_WINDOW_SECONDS: ${RATE_LIMIT_WINDOW_SECONDS:-30}\n      IMAGE_MAX_BYTES: ${IMAGE_MAX_BYTES:-5242880}\n      BOT_DEFAULT_LOCALE: ${BOT_DEFAULT_LOCALE:-en}\n      TZ: ${TZ:-Europe/Madrid}\n```\n\nSee `.env.example` for the complete list and example values.\n\n- `BOT_IMAGE`: Docker image reference used by Compose (`registry/repo:tag`).\n- `BOT_CONTAINER_NAME`: Name assigned to the running container.\n- `TELEGRAM_BOT_TOKEN`: Bot token generated by `@BotFather`.\n- `OLLAMA_BASE_URL`: Base URL of Ollama (for example `http://ollama:11434`, no `/v1`).\n- `OLLAMA_DEFAULT_MODEL`: Model used by default when user has no custom selection.\n- `OLLAMA_USE_CHAT_API`: Enables `/api/chat` as primary path with automatic generate fallback.\n- `OLLAMA_KEEP_ALIVE`: Chat keep-alive hint sent to Ollama (for example `5m`).\n- `MODEL_PREFS_DB_PATH`: SQLite database path inside container.\n- `BOT_DATA_DIR`: Host path mounted to `/data` for persistence.\n- `ALLOWED_USER_IDS`: Required comma-separated numeric Telegram user IDs.\n- `LOG_LEVEL`: Logging verbosity (`DEBUG|INFO|WARNING|ERROR|CRITICAL`).\n- `REQUEST_TIMEOUT_SECONDS`: Timeout for Ollama requests.\n- `MAX_CONTEXT_MESSAGES`: Number of recent turns kept in memory per user.\n- `RATE_LIMIT_MAX_MESSAGES`: Max user messages allowed inside the rate-limit window.\n- `RATE_LIMIT_WINDOW_SECONDS`: Sliding window size (seconds) for rate limiting.\n- `IMAGE_MAX_BYTES`: Maximum accepted image size in bytes for image analysis requests.\n- `BOT_DEFAULT_LOCALE`: Fallback locale when user Telegram language is not available in bot locales.\n- `TZ`: Timezone in IANA format (for example `Europe/Madrid`).\n\n`ALLOWED_USER_IDS` is required and must contain at least one numeric Telegram user ID.\nBot replies are localized using each user's Telegram language when available; unsupported locales automatically fallback to English (`en`).\nCurrent locale files: `locales/en.json`, `locales/es.json`, `locales/de.json`, `locales/fr.json`, and `locales/it.json`.\n\n## Docker Compose (Fully Variable-Driven)\n\nDeployment is designed to use:\n\n- `.env` locally.\n- Environment variables in Portainer (Stack \u003e Environment variables).\n\n### 1) Configure variables\n\n```bash\ncp .env.example .env\n```\n\nEdit `.env` with your values.\n\n### 2) Start the stack\n\n```bash\ndocker compose pull\ndocker compose up -d\n```\n\n## Local Development\n\n```bash\npython3 -m venv .venv\nsource .venv/bin/activate\npip install -e .[dev]\npython3 -m src.app\n```\n\n## Lint, Type Check, Tests\n\n```bash\nruff check .\nruff format .\nmypy src\npython3 -m pytest -q\n```\n\n## GHCR Publish\n\nThe workflow in `.github/workflows/docker-publish.yml` publishes:\n\n- `ghcr.io/artcc/ollama-telegram-bot:latest` (main branch)\n- `ghcr.io/artcc/ollama-telegram-bot:sha-\u003ccommit\u003e`\n- `ghcr.io/artcc/ollama-telegram-bot:vX.Y.Z` (tags)\n\nFor private image pulls on server/Portainer:\n\n```bash\necho \"$GITHUB_TOKEN\" | docker login ghcr.io -u YOUR_GITHUB_USER --password-stdin\n```\n\nThe token must include at least `read:packages` permission.\n\n## Documents\n\n- [CHANGELOG.md](CHANGELOG.md)\n- [CONTRIBUTING.md](CONTRIBUTING.md)\n\n## 🎨 Bot Avatar\n\nYou can use the official bot avatar for your own instance:\n\n\u003cp align=\"left\"\u003e\n  \u003cimg src=\"https://github.com/ArtCC/ollama-telegram-bot/blob/main/assets/ollama-telegram-bot.png\" alt=\"Ollama Telegram Bot Avatar\" width=\"200\"\u003e\n\u003c/p\u003e\n\nTo set this image as your bot's profile picture:\n1. Right-click the image above and save it\n2. Open [@BotFather](https://t.me/botfather) on Telegram\n3. Send `/setuserpic`\n4. Select your bot\n5. Upload the downloaded image\n\n## License\n\nThis project is licensed under the Apache License 2.0. See [LICENSE](LICENSE).\n\n## Author\n\nArturo Carretero Calvo ([ArtCC](https://github.com/ArtCC))","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartcc%2Follama-telegram-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fartcc%2Follama-telegram-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartcc%2Follama-telegram-bot/lists"}