Echo bot
This commit is contained in:
parent
ca06108ed4
commit
bf33e5b457
|
@ -8,6 +8,8 @@ class TelegramBotUpdatesController < ApplicationController
|
||||||
def create
|
def create
|
||||||
logger.info params.inspect
|
logger.info params.inspect
|
||||||
|
|
||||||
|
handle_message params[:message] if params[:message]
|
||||||
|
|
||||||
render status: :no_content, json: {}
|
render status: :no_content, json: {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -20,4 +22,15 @@ private
|
||||||
def verify_telegram_bot_secret
|
def verify_telegram_bot_secret
|
||||||
raise NotAuthorizedError unless params[:secret] == @telegram_bot.secret
|
raise NotAuthorizedError unless params[:secret] == @telegram_bot.secret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def handle_message(message)
|
||||||
|
chat_id = Integer message[:chat][:id]
|
||||||
|
text = String message[:text]
|
||||||
|
|
||||||
|
RestClient.post(
|
||||||
|
"https://api.telegram.org/bot#{@telegram_bot.api_token}/sendMessage",
|
||||||
|
chat_id: chat_id,
|
||||||
|
text: "Message received: #{text}",
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Reference in New Issue