How to create telegram bots in Ruby

Published: (January 15, 2026 at 08:47 AM EST)
1 min read
Source: Dev.to

Source: Dev.to

Cover image for How to create telegram bots in Ruby

You must have heard of or used Telegram bots.
Now the deep question is: how are they created? We’re going to see that—get your IDE ready because we’re going to create a bot in 5 minutes.

Requirements

  • A good IDE with Ruby installed
  • Basic or advanced knowledge of Ruby
  • Bot token from @BotFather

If you don’t know how to get your bot token, check out this post 👉 How to get your Telegram token.

Setup

1. Create a Gemfile

source 'https://rubygems.org'

gem 'telegem', '~> 3.0.4'
gem 'dotenv', '~> 2.8'

# add any other gems you wish (httparty, nethttp, json, etc.)

2. Install dependencies

If you’re using Bundler:

bundle install

Or install the gems manually:

gem install telegem dotenv

3. Add your bot token

Create a .env file in the project root:

BOT_TOKEN=11234:445849489449   # replace with your actual token

Creating the Bot

Create a file named bot.rb:

# bot.rb
require 'telegem'
require 'dotenv/load'

bot = Telegem.new(ENV['BOT_TOKEN'])

bot.command('start') do |ctx|
  ctx.reply('welcome to test2bot')
end

bot.command('help') do |ctx|
  ctx.reply('**u need help**', parse_mode: 'Markdown')
end

bot.start_polling
puts 'bot has started'

Running the Bot

bundle exec ruby bot.rb

Your bot will now respond to the /start and /help commands.

Further Resources

For a more in‑depth tutorial and additional examples, see the official repository: 👉 Telegem examples.

Back to Blog

Related posts

Read more »

Create a Telegram bot quote bot in Ruby

Requirements - Must have an IDE - Project structure: project_folder/ ├── bot.rb ├── quote.rb ├── help.rb ├── start.rb └── Gemfile Note: No .env file is committ...

Ruby 예외 처리와 정규 표현식

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