diff --git a/app/controllers/telegram_bots/updates_controller.rb b/app/controllers/callbacks/telegram_bots/updates_controller.rb similarity index 91% rename from app/controllers/telegram_bots/updates_controller.rb rename to app/controllers/callbacks/telegram_bots/updates_controller.rb index eaa7481..60be3b1 100644 --- a/app/controllers/telegram_bots/updates_controller.rb +++ b/app/controllers/callbacks/telegram_bots/updates_controller.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -class TelegramBots::UpdatesController < ApplicationController +class Callbacks::TelegramBots::UpdatesController < ApplicationController before_action :set_telegram_bot before_action :verify_telegram_bot_secret skip_after_action :verify_authorized - # POST /telegram_bots/:telegram_bot_id/updates + # POST /callbacks/telegram_bots/:telegram_bot_id/updates def create handle_message params[:message] diff --git a/app/interactors/initialize_telegram_bot.rb b/app/interactors/initialize_telegram_bot.rb index 944522e..6928be6 100644 --- a/app/interactors/initialize_telegram_bot.rb +++ b/app/interactors/initialize_telegram_bot.rb @@ -29,7 +29,7 @@ private end def webhook_url - telegram_bot_updates_url( + callbacks_telegram_bot_updates_url( context.telegram_bot, format: 'json', protocol: 'https', diff --git a/config/routes.rb b/config/routes.rb index f800d59..ad81414 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -38,10 +38,12 @@ Rails.application.routes.draw do # Callbacks for third-party services # ###################################### - resources :telegram_bots, only: [] do - resources :updates, - controller: 'telegram_bots/updates', - only: :create + namespace :callbacks do + resources :telegram_bots, only: [] do + resources :updates, + controller: 'telegram_bots/updates', + only: :create + end end ######################### diff --git a/spec/requests/telegram_bots/updates/create_spec.rb b/spec/requests/callbacks/telegram_bots/updates/create_spec.rb similarity index 71% rename from spec/requests/telegram_bots/updates/create_spec.rb rename to spec/requests/callbacks/telegram_bots/updates/create_spec.rb index 77ebe1b..278e57d 100644 --- a/spec/requests/telegram_bots/updates/create_spec.rb +++ b/spec/requests/callbacks/telegram_bots/updates/create_spec.rb @@ -2,12 +2,12 @@ require 'rails_helper' -RSpec.describe 'POST /telegram_bots/:telegram_bot_id/updates' do +RSpec.describe 'POST /callbacks/telegram_bots/:telegram_bot_id/updates' do let(:telegram_bot) { create :telegram_bot } context 'with valid params' do before do - post "/telegram_bots/#{telegram_bot.id}/updates", + post "/callbacks/telegram_bots/#{telegram_bot.id}/updates", params: { secret: telegram_bot.secret } end @@ -18,7 +18,7 @@ RSpec.describe 'POST /telegram_bots/:telegram_bot_id/updates' do context 'when no telegram bot exist' do before do - post "/telegram_bots/#{rand(10_000..1_000_000)}/updates", + post "/callbacks/telegram_bots/#{rand(10_000..1_000_000)}/updates", params: { secret: telegram_bot.secret } end @@ -29,7 +29,7 @@ RSpec.describe 'POST /telegram_bots/:telegram_bot_id/updates' do context 'when secret is not valid' do before do - post "/telegram_bots/#{telegram_bot.id}/updates", + post "/callbacks/telegram_bots/#{telegram_bot.id}/updates", params: { secret: SecureRandom.hex } end