wrongmove/notifications.py

28 lines
799 B
Python
Raw Normal View History

import json
import logging
import os
import aiohttp
logger = logging.getLogger(__name__)
async def send_notification(body: str, title: str = "") -> bool:
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