Ruby에서 텔레그램 봇을 만드는 방법
Source: Dev.to

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.