diff --git a/config/.env-template b/config/.env-template index ce3d86b..18baf6b 100644 --- a/config/.env-template +++ b/config/.env-template @@ -16,4 +16,5 @@ OAA_CFG__REDIS__PWD=P@ssw0rd! OAA_CFG__TG__TOKEN=string OAA_CFG__TG__DASHBOARD_CHAT_ID=0 -OAA_CFG__TG__DASHBOARD_TRED_ID=0 \ No newline at end of file +OAA_CFG__TG__DASHBOARD_TRED_ID=0 +OAA_CFG__TG__CLOSE_ALERT_PATTERN=^Problem has been resolved diff --git a/config/config.py b/config/config.py index 423e334..4498f60 100644 --- a/config/config.py +++ b/config/config.py @@ -50,6 +50,7 @@ class TelegramConfig(BaseModel): token: str dashboard_chat_id: int dashboard_tred_id: int | None = None + close_alert_pattern: str class SwaggerConfig(BaseModel): diff --git a/requirements.txt b/requirements.txt index fea2d3f..6d774f3 100644 Binary files a/requirements.txt and b/requirements.txt differ diff --git a/routers/tg_send.py b/routers/tg_send.py index 2635b48..a65d78a 100644 --- a/routers/tg_send.py +++ b/routers/tg_send.py @@ -5,6 +5,8 @@ from schemas import TelegramMessageToDashboard from auth import verify_token_admin from telegram import send_message_to_dashboard, del_message_from_dashboard from redis_db import set_value, pop_value +from config import conf +import re router = APIRouter() @@ -14,10 +16,15 @@ async def send_message( message: TelegramMessageToDashboard, token: str = Depends(verify_token_admin), ): - if message.text.startswith("Problem has been resolved"): + + match = re.search(conf.tg.close_alert_pattern, message.text) + + log.info(f"match: {match}") + if match: msg_id = await pop_value(message.problem_id) - msg_id = int(msg_id.decode("utf-8")) - await del_message_from_dashboard(message_id=msg_id) + if msg_id: + msg_id = int(msg_id.decode("utf-8")) + await del_message_from_dashboard(message_id=msg_id) return result = await send_message_to_dashboard(text=message.text) diff --git a/telegram/msg.py b/telegram/msg.py index e4bb9d5..a0c194f 100644 --- a/telegram/msg.py +++ b/telegram/msg.py @@ -1,7 +1,6 @@ import logging as log import aiohttp -import asyncio from config import conf