27 lines
722 B
Ruby
27 lines
722 B
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
module Telegram
|
||
|
# Recibe los mensajes desde Telegram y asocia piratas con cuentas de
|
||
|
# Telegram.
|
||
|
class WebhookController < Telegram::Bot::UpdatesController
|
||
|
include Telegram::Bot::UpdatesController::TypedUpdate
|
||
|
|
||
|
# Recibe un token, lo busca y asocia las cuentas
|
||
|
def start!(token = nil)
|
||
|
unless token
|
||
|
respond_with :message, text: t('.need_token')
|
||
|
return
|
||
|
end
|
||
|
|
||
|
unless (pirata = Pirata.find_by(telegram_token: token))
|
||
|
respond_with :message, text: t('.couldnt_find')
|
||
|
return
|
||
|
end
|
||
|
|
||
|
pirata.update_attribute :telegram_user, payload.from.id
|
||
|
|
||
|
respond_with :message, text: t('.hi', pirata: pirata.nick)
|
||
|
end
|
||
|
end
|
||
|
end
|