Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MaksimAbramchuk/6240868884029545c30396b0dda0e336 to your computer and use it in GitHub Desktop.
Save MaksimAbramchuk/6240868884029545c30396b0dda0e336 to your computer and use it in GitHub Desktop.
class WebhooksController < ApplicationController
skip_before_action :verify_authenticity_token
def callback
dispatcher.new(webhook, user).process
render nothing: true, head: :ok
end
def webhook
params['webhook']
end
def dispatcher
BotMessageDispatcher
end
def from
webhook[:message][:from]
end
def user
@user ||= User.find_by(telegram_id: from[:id]) || register_user
end
def register_user
@user = User.find_or_initialize_by(telegram_id: from[:id])
@user.update_attributes!(first_name: from[:first_name], last_name: from[:last_name])
@user
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment