Skip to content

Instantly share code, notes, and snippets.

@rtrv
Created December 2, 2021 15:09
Show Gist options
  • Save rtrv/0504f785e433ebb04df0b0e0fb37a2e1 to your computer and use it in GitHub Desktop.
Save rtrv/0504f785e433ebb04df0b0e0fb37a2e1 to your computer and use it in GitHub Desktop.

Quick start with your Telegram integration for Rails app. Check also:

Rails Telegram integration

  1. Add gem telegram-bot

  2. Add telegram_webhook TelegramWebhooksController to config/routes.rb

  3. Add telegram_webhooks_controller#start!

def start!(*)
  respond_with :message, text: t('.hi')
end
  1. Run and test it in development

  2. Add telegram_webhooks_controller#inline_keyboard!

def inline_keyboard!(*)
  respond_with :message, text: t('.prompt'), reply_markup: {
    inline_keyboard: [
      [
        {text: t('.alert'), callback_data: 'alert'},
        {text: t('.no_alert'), callback_data: 'no_alert'},
      ],
      [{text: t('.repo'), url: 'https://github.com/telegram-bot-rb/telegram-bot'}],
    ],
  }
end
  1. Add telegram_webhooks_controller#callback_query
def callback_query(data)
  if data == 'alert'
    answer_callback_query t('.alert'), show_alert: true
  else
    answer_callback_query t('.no_alert')
  end
end
  1. Add locales to en.yml:
en:
  telegram_webhooks:
    inline_keyboard:
      alert: Answer with alert
      no_alert: Without alert
      prompt: 'Check my inline keyboard:'
      repo: Open gem repo
    callback_query:
      alert: This is ALERT-T-T!!!
      no_alert: Simple answer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment