telegram-bot-ruby icon indicating copy to clipboard operation
telegram-bot-ruby copied to clipboard

[FAQ] sample rails app with telegram-bot-ruby

Open kirantpatil opened this issue 7 years ago • 3 comments

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.

kirantpatil avatar Nov 17 '17 10:11 kirantpatil

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

masfree avatar Nov 17 '17 10:11 masfree

Take a look at #19

chriso0710 avatar Nov 29 '17 22:11 chriso0710

@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

pskl avatar May 24 '20 22:05 pskl

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.

github-actions[bot] avatar Feb 19 '23 15:02 github-actions[bot]