Skip to content

Alanon202/openrouter-bot

 
 

Repository files navigation

OpenRouter
Bot (Refactored)

English (🇺🇸) | Русский (🇷🇺)

This project allows you to launch your Telegram bot in a few minutes to communicate with free and paid AI models via OpenRouter.

Important

This repository is a significant refactor and improvement of the original bot, migrated to the modern go-telegram/bot library. It is designed for high reliability, performance, and advanced Telegram features like Forum Topics.

Key Improvements & Advantages

  • Modern Telegram Engine: Migrated from telegram-bot-api to go-telegram/bot for better performance and support for the latest Telegram API features.
  • Forum/Thread Support: Full support for Telegram Forum Topics (MessageThreadID), allowing the bot to work seamlessly in organized group chats.
  • High Concurrency Safety: Completely refactored state management with fine-grained locking, preventing race conditions even with many simultaneous users.
  • Optimized for Docker:
    • Reduced resource footprint through singleton manager patterns.
    • Optional .env support.
    • Improved graceful shutdown and signal handling.
  • Enhanced Reliability:
    • Implementation of SafeEdit to prevent message truncation on Markdown errors.
    • Automatic API timeouts (5m) to prevent hanging goroutines.
    • Update deduplication to prevent "double-bubble" AI responses.
  • Smooth UX:
    • Throttled streaming updates (800ms) for a fluid visual experience without hitting rate limits.
    • Faster animation dots (400ms) for better interactivity.
    • Improved error handling and automatic plain-text fallback.

Preparation

Installation

Running in Docker

  • Create a working directory:
mkdir openrouter-bot
cd openrouter-bot
  • Create .env file (or provide environment variables directly):
# OpenRouter api key
API_KEY=
# Free modeles: https://openrouter.ai/models?max_price=0
MODEL=deepseek/deepseek-r1:free
# Telegram api key
TELEGRAM_BOT_TOKEN=
# Your Telegram id
ADMIN_IDS=
# List of users to access the bot, separated by commas
ALLOWED_USER_IDS=
# Disable guest access (enabled by default)
GUEST_BUDGET=0
# Language used for bot responses (supported: EN/RU)
LANG=EN
  • Run using Docker Compose:
docker-compose up -d --build

Build

go build -o openrouter-bot .

About

This project allows to launch your Telegram bot in a few minutes to communicate with free or paid AI models via OpenRouter.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Go 98.4%
  • Dockerfile 1.6%