Last active
June 20, 2016 08:30
-
-
Save MaksimAbramchuk/6240868884029545c30396b0dda0e336 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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