Fix proxy env bug in Telegram alert
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
from datetime import timedelta
|
||||
import asyncio
|
||||
import os
|
||||
import httpx
|
||||
from fastapi import APIRouter, Depends, HTTPException, status, Request
|
||||
from pydantic import BaseModel
|
||||
@@ -36,11 +35,11 @@ async def send_failed_login_alert(ip_address: str, username: str, reason: str):
|
||||
return
|
||||
msg = f"🚨 *Dashboard Security Alert* 🚨\nFailed login attempt detected.\n\n👤 User: `{username}`\n🌐 IP: `{ip_address}`\n❌ Reason: {reason}"
|
||||
try:
|
||||
client_options = {}
|
||||
if config.TELEGRAM_PROXY:
|
||||
os.environ["HTTP_PROXY"] = config.TELEGRAM_PROXY
|
||||
os.environ["HTTPS_PROXY"] = config.TELEGRAM_PROXY
|
||||
client_options["proxy"] = config.TELEGRAM_PROXY
|
||||
|
||||
async with httpx.AsyncClient() as client:
|
||||
async with httpx.AsyncClient(**client_options) as client:
|
||||
res = await client.post(
|
||||
f"https://api.telegram.org/bot{config.TELEGRAM_BOT_TOKEN}/sendMessage",
|
||||
data={"chat_id": config.TELEGRAM_CHAT_ID, "text": msg, "parse_mode": "Markdown"},
|
||||
|
||||
Reference in New Issue
Block a user