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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user