regular expression in config

This commit is contained in:
sergey 2024-10-09 17:21:19 +03:00
parent 7a572cdd4a
commit 2445f54899
5 changed files with 13 additions and 5 deletions

View File

@ -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
OAA_CFG__TG__DASHBOARD_TRED_ID=0
OAA_CFG__TG__CLOSE_ALERT_PATTERN=^Problem has been resolved

View File

@ -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):

Binary file not shown.

View File

@ -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)

View File

@ -1,7 +1,6 @@
import logging as log
import aiohttp
import asyncio
from config import conf