From bf33e5b4572cce3173db9629430f4cd28a0c35ec Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Thu, 29 Nov 2018 19:30:38 +0500 Subject: [PATCH] Echo bot --- app/controllers/telegram_bot_updates_controller.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/controllers/telegram_bot_updates_controller.rb b/app/controllers/telegram_bot_updates_controller.rb index 2834e10..e8a0148 100644 --- a/app/controllers/telegram_bot_updates_controller.rb +++ b/app/controllers/telegram_bot_updates_controller.rb @@ -8,6 +8,8 @@ class TelegramBotUpdatesController < ApplicationController def create logger.info params.inspect + handle_message params[:message] if params[:message] + render status: :no_content, json: {} end @@ -20,4 +22,15 @@ private def verify_telegram_bot_secret raise NotAuthorizedError unless params[:secret] == @telegram_bot.secret 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