telegram-bot-ruby
telegram-bot-ruby copied to clipboard
[FAQ] sample rails app with telegram-bot-ruby
Hi,
I would like to know how to use this gem with Rails app ?
If there is a sample app, please provide its source code url.
Thanks.
Hi @kirantpatil , it look's like:
require 'telegram/bot'
class YourClass
Telegram::Bot::Api.new(your_token).send_message(chat_id: your_chat_id, text: your_text)
end
do not forgot gem 'telegram-bot-ruby'
in your bundle
Take a look at #19
@kirantpatil Something like
class TelegramController < ApplicationController
before_action :auth
skip_before_action :verify_authenticity_token
def webhook
update = Telegram::Bot::Types::Update.new(params.permit!.to_h)
message = update.message
# do something
end
private
def client
@client ||= Telegram::Bot::Api.new(Rails.application.credentials.telegram[:bot_token])
end
def auth
Raise "Unauthorized" unless params.require(:webhook_token) == Rails.application.credentials.telegram[:webhook_token]
end
end
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.