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:
@@ -20,7 +20,7 @@ from sqlmodel.ext.asyncio.session import AsyncSession
|
||||
from notify_bridge_core.notifications.telegram.client import TelegramClient
|
||||
|
||||
from ..database.engine import get_engine
|
||||
from ..database.models import CommandTracker, CommandTrackerListener, TelegramBot
|
||||
from ..database.models import CommandTracker, CommandTrackerListener, TelegramBot, TelegramChat
|
||||
from ..services.telegram import save_chat_from_webhook
|
||||
from .scheduler import get_scheduler
|
||||
|
||||
@@ -195,9 +195,18 @@ async def _poll_bot(bot_id: int) -> None:
|
||||
except Exception:
|
||||
_LOGGER.debug("Failed to auto-save chat %s", chat_id, exc_info=True)
|
||||
|
||||
# Dispatch commands
|
||||
# Dispatch commands (only if chat has commands enabled)
|
||||
if text and text.startswith("/"):
|
||||
try:
|
||||
async with AsyncSession(engine) as cmd_session:
|
||||
chat_row = (await cmd_session.exec(
|
||||
select(TelegramChat).where(
|
||||
TelegramChat.bot_id == bot_obj.id,
|
||||
TelegramChat.chat_id == chat_id,
|
||||
)
|
||||
)).first()
|
||||
if not chat_row or not chat_row.commands_enabled:
|
||||
continue
|
||||
message_id = message.get("message_id")
|
||||
cmd_response = await handle_command(bot_obj, chat_id, text, language_code=msg_language)
|
||||
if cmd_response is not None:
|
||||
|
||||
Reference in New Issue
Block a user