Create a Telegram bot quote bot in Ruby

Published: (January 17, 2026 at 03:53 AM EST)
1 min read
Source: Dev.to

Source: Dev.to

Requirements

  • Must have an IDE
  • Project structure:
project_folder/
├── bot.rb
├── quote.rb
├── help.rb
├── start.rb
└── Gemfile

Note: No .env file is committed to git.

start.rb

# start.rb
class Start
  def initialize(bot)
    @bot = bot
    start_handler
  end

  def start_handler
    @bot.command("start") do |ctx|
      ctx.reply("welcome to quote_bot use /quote to get astonishing quotes")
    end
  end
end

telegem provides the .command method for handling / commands (e.g., /help, /start, /quote).
ctx.reply sends a reply to the current chat and accepts options such as reply_markup and parse_mode.

help.rb

# help.rb
class Help
  def initialize(bot)
    @bot = bot
    send_help_message
  end

  def send_help_message
    @bot.command("help") do |ctx|
      help_message =  3.0.4"

Gemfile

gem "httparty", "~> 0.21.0"
gem "dotenv", "~> 2.8"

.env file

Create a .env file (do not commit it) with your token:

BOT_TOKEN=

Installation & Running

# Install bundler if needed
gem install bundler

# Install dependencies
bundle install

# Run the bot
bundle exec ruby bot.rb

For more detailed examples, see the repository.

Back to Blog

Related posts

Read more »

How to create telegram bots in Ruby

!Cover image for How to create telegram bots in Rubyhttps://media2.dev.to/dynamic/image/width=1000,height=420,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fd...

Ruby 예외 처리와 정규 표현식

예외 처리 Ruby에서 예외를 발생시키고 처리하는 기본적인 방법을 살펴봅니다. ruby def raise_exception puts 'I am before the raise.' raise 'An error has occured' puts 'I am after the raise' 실행되...