feat: per-chat command toggle, listener name + toggle in bot tab

- Add commands_enabled field to TelegramChat (default off) with
  migration, gating command dispatch in both poller and webhook
- Show toggle switch per chat in bot tab for enabling/disabling commands
- Fix listener response to include bot name instead of just type
- Replace listener "Enabled" label + "Edit" link with toggle switch
  and crosslink to command-trackers page
This commit is contained in:
2026-03-23 19:23:37 +03:00
parent 37388c430c
commit b3b6c31c4d
10 changed files with 90 additions and 24 deletions
@@ -13,7 +13,7 @@ from sqlmodel.ext.asyncio.session import AsyncSession
from notify_bridge_core.notifications.telegram.client import TelegramClient
from ..database.engine import get_session
from ..database.models import TelegramBot
from ..database.models import TelegramBot, TelegramChat
from ..services.telegram import save_chat_from_webhook
from .handler import handle_command, send_media_group, send_reply
@@ -76,8 +76,16 @@ async def telegram_webhook(
except Exception:
_LOGGER.warning("Failed to auto-save chat %s", chat_id, exc_info=True)
# Handle commands
# Handle commands (only if chat has commands enabled)
if text.startswith("/"):
chat_row = (await session.exec(
select(TelegramChat).where(
TelegramChat.bot_id == bot.id,
TelegramChat.chat_id == chat_id,
)
)).first()
if not chat_row or not chat_row.commands_enabled:
return {"ok": True, "skipped": "commands_disabled"}
message_id = message.get("message_id")
cmd_response = await handle_command(bot, chat_id, text, language_code=msg_language)
if cmd_response is not None: