Skip to content
This repository was archived by the owner on Feb 3, 2026. It is now read-only.

spacebarlabs/ruby_llm_telegram

Repository files navigation

Ruby LLM Telegram Bot

From your friends at spacebarlabs.com

This Rails application implements a Telegram bot powered by OpenRouter for AI interactions. It provides a simple interface for users to interact with various AI models through Telegram.

Requirements

  • Ruby 3.3.0
  • Rails 7.x
  • PostgreSQL
  • OpenRouter API key
  • Telegram Bot Token
  • Foreman (for process management)

Project Status

Currently in development. Core features being implemented:

  • Basic Rails application setup
  • Dependencies configuration
  • OpenRouter integration
  • Telegram Bot implementation
  • Standardized bot entry points
  • Comprehensive test coverage
  • Conversation handling
  • User management

Configuration

Initial Setup

  1. Clone the repository
  2. Install dependencies:
    bundle install
  3. Setup the database:
    rails db:create db:migrate

Setting up OpenRouter

  1. Sign up for an account at OpenRouter
  2. Get your API key from the dashboard
  3. Add the key to your Rails credentials:
    # Open credentials file (replace 'development' with your environment)
    rails credentials:edit --environment development
    Add to your credentials:
    openrouter_api_key: your_api_key_here
    app_url: "https://your-app-url.com"  # or http://localhost:3000 for development

Setting up Telegram Bot

  1. Start a chat with @BotFather on Telegram
  2. Send the /newbot command and follow the instructions to create a new bot
  3. Save the bot token provided by BotFather
  4. Add the token to your Rails credentials:
    telegram_bot_token: your_bot_token_here
    telegram_main_channel_id: your_channel_id_here  # Optional: for startup messages

Development

The application uses Foreman to manage multiple processes (web server and Telegram bot). To start all services:

foreman start

This will start:

  • Rails server on port 5000
  • Telegram bot process

Starting the Bot

There are three standardized ways to start the bot, all using the same underlying initialization:

  1. Using Foreman (recommended for development):

    foreman start
  2. Using Rake task (recommended for production):

    bundle exec rake telegram:start
  3. Using the binary directly:

    bundle exec bin/telegram_bot

All methods provide identical functionality and logging configuration. Choose the one that best fits your deployment environment.

Environment Variables

Create a .env file in the root directory with the following variables:

RAILS_ENV=development
DATABASE_URL=postgresql://localhost/ruby_llm_telegram_development

Testing

The project uses Minitest for testing and VCR for recording HTTP interactions. This ensures tests are reliable and don't make actual API calls during test runs.

Run the test suite:

rails test

VCR Cassettes

The project uses VCR to record and replay HTTP interactions in tests. Cassettes are stored in test/vcr_cassettes/. When debugging API-related tests, you might want to delete the relevant cassette to record new interactions:

# Remove specific cassette
rm test/vcr_cassettes/openrouter/specific_cassette.yml

# Remove all OpenRouter cassettes
rm test/vcr_cassettes/openrouter/*

Test Environment Credentials

For testing OpenRouter API interactions, you'll need to set up test credentials:

rails credentials:edit --environment test

Add the following to your test credentials:

openrouter_api_key: your_test_api_key_here

Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

Warranty

THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

License

This project is available as open source under the terms of the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors 2

  •  
  •