Class: TelegramBotEngine::Admin::BotsController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- BaseController
- TelegramBotEngine::Admin::BotsController
- Defined in:
- app/controllers/telegram_bot_engine/admin/bots_controller.rb
Overview
CRUD + token rotation + webhook status for bots-as-data (docs/0001 §3.8).
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #rotate_token ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/telegram_bot_engine/admin/bots_controller.rb', line 17 def create @bot = Bot.new(create_params) if @bot.save redirect_to admin_bots_path, notice: "Bot \"#{@bot.name}\" created." else flash.now[:alert] = @bot.errors..to_sentence render :new, status: :unprocessable_entity end end |
#destroy ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'app/controllers/telegram_bot_engine/admin/bots_controller.rb', line 40 def destroy if @bot.default? redirect_to admin_bots_path, alert: "Cannot delete the default bot. Promote another bot to default first." else @bot.destroy redirect_to admin_bots_path, notice: "Bot \"#{@bot.name}\" deleted." end end |
#edit ⇒ Object
27 |
# File 'app/controllers/telegram_bot_engine/admin/bots_controller.rb', line 27 def edit; end |
#index ⇒ Object
9 10 11 |
# File 'app/controllers/telegram_bot_engine/admin/bots_controller.rb', line 9 def index @bots = Bot.order(:name) end |
#new ⇒ Object
13 14 15 |
# File 'app/controllers/telegram_bot_engine/admin/bots_controller.rb', line 13 def new @bot = Bot.new(active: true) end |
#rotate_token ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'app/controllers/telegram_bot_engine/admin/bots_controller.rb', line 49 def rotate_token if params[:token].present? @bot.update!(token: params[:token]) redirect_to admin_bots_path, notice: "Token rotated for \"#{@bot.name}\"." else redirect_to edit_admin_bot_path(@bot), alert: "Enter a new token to rotate." end end |
#update ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/telegram_bot_engine/admin/bots_controller.rb', line 29 def update # Token is never touched here — it is rotated through #rotate_token so a normal # edit can't blank it. See update_params. if @bot.update(update_params) redirect_to admin_bots_path, notice: "Bot \"#{@bot.name}\" updated." else flash.now[:alert] = @bot.errors..to_sentence render :edit, status: :unprocessable_entity end end |