2026-02-21 19:47:10 +00:00
|
|
|
import json
|
|
|
|
|
import logging
|
2025-07-26 13:15:21 +00:00
|
|
|
import os
|
2025-07-25 21:32:06 +00:00
|
|
|
|
2026-02-21 19:47:10 +00:00
|
|
|
import aiohttp
|
2025-07-25 21:32:06 +00:00
|
|
|
|
2026-02-21 19:47:10 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
2025-07-25 21:32:06 +00:00
|
|
|
|
2025-07-26 13:15:21 +00:00
|
|
|
|
|
|
|
|
async def send_notification(body: str, title: str = "") -> bool:
|
2026-02-21 19:47:10 +00:00
|
|
|
webhook_url = os.environ.get("SLACK_WEBHOOK_URL")
|
|
|
|
|
if not webhook_url:
|
|
|
|
|
logger.debug("No SLACK_WEBHOOK_URL configured, skipping notification")
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
text = f"*{title}*\n{body}" if title else body
|
|
|
|
|
try:
|
|
|
|
|
async with aiohttp.ClientSession() as session:
|
|
|
|
|
async with session.post(
|
|
|
|
|
webhook_url,
|
|
|
|
|
data=json.dumps({"text": text}),
|
|
|
|
|
headers={"Content-Type": "application/json"},
|
|
|
|
|
) as resp:
|
|
|
|
|
return resp.status == 200
|
|
|
|
|
except Exception:
|
|
|
|
|
logger.exception("Failed to send Slack notification")
|
|
|
|
|
return False
|