Quick start with your Telegram integration for Rails app. Check also:
telegram_bot
gem itself, which is the base of the integration- Rails template used for this guide
- Rails app example with advanced bot features like sessions
-
Add gem telegram-bot
-
Add
telegram_webhook TelegramWebhooksController
toconfig/routes.rb
-
Add
telegram_webhooks_controller#start!
def start!(*)
respond_with :message, text: t('.hi')
end
-
Run and test it in development
-
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
- 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
- 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