Ruby에서 텔레그램 봇을 만드는 방법

발행: (2026년 1월 15일 오후 10:47 GMT+9)
2 min read
원문: Dev.to

Source: Dev.to

Cover image for How to create telegram bots in Ruby

Telegram 봇에 대해 들어보셨거나 사용해 보셨을 겁니다.
이제 진짜 질문은: 어떻게 만들까요? IDE를 준비하세요. 5분 안에 봇을 만들 거예요.

Requirements

  • Ruby가 설치된 좋은 IDE
  • Ruby에 대한 기본 혹은 고급 지식
  • @BotFather 로부터 받은 봇 토큰

봇 토큰을 얻는 방법을 모른다면 이 글을 확인하세요 👉 How to get your Telegram token.

Setup

1. Gemfile 만들기

source 'https://rubygems.org'

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

# 필요에 따라 다른 gem을 추가하세요 (httparty, nethttp, json 등)

2. 의존성 설치

Bundler를 사용한다면:

bundle install

또는 gem을 수동으로 설치:

gem install telegem dotenv

3. 봇 토큰 추가

프로젝트 루트에 .env 파일을 만들고:

BOT_TOKEN=11234:445849489449   # 실제 토큰으로 교체하세요

Creating the Bot

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

이제 봇이 /start/help 명령에 응답합니다.

Further Resources

보다 심도 있는 튜토리얼과 추가 예제는 공식 저장소를 참고하세요 👉 Telegem examples.

Back to Blog

관련 글

더 보기 »

Ruby로 Telegram 인용 봇 만들기

요구 사항 - IDE가 필요합니다 - 프로젝트 구조: project_folder/ ├── bot.rb ├── quote.rb ├── help.rb ├── start.rb └── Gemfile 참고: .env 파일은 커밋되지 않습니다.

Ruby 예외 처리와 정규 표현식

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