webhook.py 508 Bytes
Newer Older
Timothy J. Baek's avatar
Timothy J. Baek committed
1
2
3
import requests


Timothy J. Baek's avatar
Timothy J. Baek committed
4
def post_webhook(url: str, message: str, event_data: dict) -> bool:
Timothy J. Baek's avatar
Timothy J. Baek committed
5
    try:
Timothy J. Baek's avatar
Timothy J. Baek committed
6
7
8
9
10
11
12
13
14
15
        payload = {}

        if "https://hooks.slack.com" in url:
            payload["text"] = message
        elif "https://discord.com/api/webhooks" in url:
            payload["content"] = message
        else:
            payload = {**event_data}

        r = requests.post(url, json=payload)
Timothy J. Baek's avatar
Timothy J. Baek committed
16
17
18
19
20
        r.raise_for_status()
        return True
    except Exception as e:
        print(e)
        return False