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.
- Ruby 3.3.0
- Rails 7.x
- PostgreSQL
- OpenRouter API key
- Telegram Bot Token
- Foreman (for process management)
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
- Clone the repository
- Install dependencies:
bundle install
- Setup the database:
rails db:create db:migrate
- Sign up for an account at OpenRouter
- Get your API key from the dashboard
- Add the key to your Rails credentials:
Add to your credentials:
# Open credentials file (replace 'development' with your environment) rails credentials:edit --environment developmentopenrouter_api_key: your_api_key_here app_url: "https://your-app-url.com" # or http://localhost:3000 for development
- Start a chat with @BotFather on Telegram
- Send the
/newbotcommand and follow the instructions to create a new bot - Save the bot token provided by BotFather
- 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
The application uses Foreman to manage multiple processes (web server and Telegram bot). To start all services:
foreman startThis will start:
- Rails server on port 5000
- Telegram bot process
There are three standardized ways to start the bot, all using the same underlying initialization:
-
Using Foreman (recommended for development):
foreman start
-
Using Rake task (recommended for production):
bundle exec rake telegram:start -
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.
Create a .env file in the root directory with the following variables:
RAILS_ENV=development
DATABASE_URL=postgresql://localhost/ruby_llm_telegram_development
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 testThe 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/*For testing OpenRouter API interactions, you'll need to set up test credentials:
rails credentials:edit --environment testAdd the following to your test credentials:
openrouter_api_key: your_test_api_key_here- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
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.
This project is available as open source under the terms of the MIT License.