Modern, blazing-fast async Telegram Bot API for Ruby - Inspired by Telegraf, built for performance.
Blazing-fast, modern Telegram Bot framework for Ruby. Inspired by Telegraf.js, built for performance with true async/await patterns.
β¨ Features
- β‘ True Async I/O - Built on async gem, not blocking threads
- π― Telegraf-style DSL - Familiar API for JavaScript developers
- π Middleware System - Compose behavior like Express.js
- π§ Scene System - Multi-step conversations (wizards/forms)
- πΎ Session Management - Redis, memory, or custom stores
- β¨οΈ Keyboard DSL - Clean markup builders with fluent API
- π Webhook Server - Production-ready async HTTP server
- ποΈ Type-Safe Objects - Ruby classes for all Telegram types
- π¦ Minimal Dependencies - Just async gems + mime-types
π Quick Start
Installation
gem install telegemOr add to your Gemfile:
gem 'telegem'Your First Bot (in 60 seconds)
require 'telegem'
# 1. Get token from @BotFather on Telegram
bot = Telegem.new('YOUR_BOT_TOKEN')
# 2. Add commands
bot.command('start') do |ctx|
ctx.reply "Hello #{ctx.from.first_name}! π"
end
bot.command('help') do |ctx|
ctx.reply "I'm your friendly Telegem bot!"
end
# 3. Start listening
puts "π€ Bot starting..."
bot.start_pollingInteractive Example
# Pizza ordering bot example
bot.command('order') do |ctx|
keyboard = Telegem.keyboard do
row "π Margherita", "π Pepperoni"
row "π₯€ Drinks", "π° Dessert"
row "π Support", "β Cancel"
end.resize.one_time
ctx.reply "What would you like?", reply_markup: keyboard
endπ― Why Telegem?
vs. Other Ruby Telegram Libraries
| Telegem | telegram-bot-ruby |
|---|---|
| fast async | multiple thread |
| non blocking request | slow thread based |
| clean telegraf dsl | no dsl |
| scene management. | verbose |
| middleware | raw json |
| clean markup dsl | . |
Perfect For:
- High-traffic bots needing async performance
- Complex conversations with multi-step flows
- Production deployments with webhooks & scaling
- Developers familiar with Telegraf.js/Express
- Modern Ruby (3.0+) applications
π§© Advanced Features
Scene System (Multi-step Conversations)
bot.scene :registration do
step :ask_name do |ctx|
ctx.reply "What's your name?"
end
step :save_name do |ctx|
ctx.session[:name] = ctx.message.text
ctx.reply "Hi #{ctx.session[:name]}! What's your email?"
end
step :complete do |ctx|
ctx.session[:email] = ctx.message.text
ctx.reply "Registration complete! β
"
ctx.leave_scene
end
endMiddleware Pipeline
# Add cross-cutting concerns
bot.use AuthenticationMiddleware.new
bot.use RateLimiter.new(limit: 10)
bot.use LoggingMiddleware.new
# Custom middleware
bot.use do |ctx, next_middleware|
puts "Processing message from #{ctx.from.username}"
next_middleware.call(ctx)
endMultiple Session Stores
# Memory (development)
Telegem::Session::MemoryStore.new
# Redis (production)
require 'redis'
redis = Redis.new(url: ENV['REDIS_URL'])
Telegem::Session::RedisStore.new(redis)
# Custom (database, etc.)
class DatabaseStore
def get(user_id); end
def set(user_id, data); end
endπ Production Deployment
Webhook Mode (Recommended)
# Production setup
server = bot.webhook_server(
port: ENV['PORT'] || 3000,
endpoint: Async::HTTP::Endpoint.parse("https://#{ENV['DOMAIN']}")
)
# Set webhook automatically
bot.set_webhook(
url: "https://#{ENV['DOMAIN']}/webhook/#{bot.token}",
max_connections: 40
)
server.run
endDocker Deployment
FROM ruby:3.2-alpine
WORKDIR /app
COPY Gemfile Gemfile.lock ./
RUN bundle install
COPY . .
CMD ["ruby", "bot.rb"]π¦ Project Structure
my_bot/
βββ bot.rb # Main bot file
βββ Gemfile
βββ config/
β βββ initializers/ # Middleware, database setup
β βββ environments/ # Development/production configs
βββ lib/
β βββ middleware/ # Custom middleware classes
β βββ scenes/ # Scene definitions
β βββ services/ # Business logic
βββ db/ # Database migrations
βββ spec/ # Tests
Development Setup:
git clone https://gitlab.com/ruby-telegem/telegem.git
cd telegem
bundle install
rake spec # Run testsNeed Help?
- Issues - Bug reports and feature requests
- Merge Requests - Code contributions
- Discussions - Questions and ideas
π§ Roadmap
Coming Soon
- Plugin System - Community plugins ecosystem
- More Session Stores - PostgreSQL, MySQL, MongoDB
- Built-in Analytics - Usage tracking & insights
- Admin Dashboard - Web interface for bot management
π License
MIT License - see LICENSE.txt for details.
π Acknowledgments
- Inspired by Telegraf.js - Amazing Node.js Telegram framework
- Built on async - Ruby's async I/O gem
- Thanks to the Telegram team for the excellent Bot API
- Community - All contributors and users
π Star History
π Support & Community
- GitLab Issues: Report bugs & request features
- Examples: Example bots repository
- Chat: Join our community (Telegram group)
π Ready to Build?
# Start building your bot now!
gem install telegem
ruby -r telegem -e "puts 'Welcome to Telegem! π'"Built with β€οΈ for the Ruby community. Happy bot building! π€β¨
