Ruby and Telegram Bots

I’ve decided to implement Telegram notifications into one of my pet project -

After some googling I’ve found great gem, gem is actively maintained and have great documentation.

So, if you want to implement Telegram messages into some channel you need to follow this simple easy steps:

1) Create new bot using @BotFather bot, and get secret token.

2) Create Telegram channel from your Telegram client, and add new bot as Administrator.

3) Create config/initializers/telegram.rb


4) Just send message to your public channel:

bot =
bot.send_message(chat_id: "@#{YOUR_CHANNEL_NAME}", text: 'YOUR_TEXT')

If you want you can add more custom commands with overriding default controller with custom:

class TelegramWebhooksController < Telegram::Bot::UpdatesController
  include Telegram::Bot::UpdatesController::MessageContext

And add to your routes.rb:

telegram_webhooks TelegramWebhooksController

Some example bot action:

def send_message(message, parse_mode = :HTML)
  respond_with :message, text: message, parse_mode: parse_mode

def events
  send_message( { |event| "<b>[#{}] #{event.title}</b>" }.join("\n"))

More: telegram-bot gem

Example bot usage:

Example Custom Commands