regular expression in config
This commit is contained in:
parent
7a572cdd4a
commit
2445f54899
|
@ -17,3 +17,4 @@ 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__CLOSE_ALERT_PATTERN=^Problem has been resolved
|
||||
|
|
|
@ -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):
|
||||
|
|
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
|
@ -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,8 +16,13 @@ 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)
|
||||
if msg_id:
|
||||
msg_id = int(msg_id.decode("utf-8"))
|
||||
await del_message_from_dashboard(message_id=msg_id)
|
||||
return
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import logging as log
|
||||
|
||||
import aiohttp
|
||||
import asyncio
|
||||
from config import conf
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue