-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebhook.py
31 lines (29 loc) · 1.05 KB
/
webhook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import requests
import json
import os
def post_webhook(message, timestamp, status, title, color=0):
"""Post webhook to Discord
Set an environment variable for 'WEBHOOK' to point to the URI for your channel
Attributes
message (str): The message to put in the embed
timestamp (str): ISO 8601 timestamp of the event
title (str): Stats of the build process for the embed title. Defaults to 'Status'
color (int): Color to use for embed highlight. Defaults to black
Returns
result (requests.result): Result of Requests post
"""
url = os.environ.get('WEBHOOK')
data = {}
data['embeds'] = []
embed = {}
embed['title'] = f'{title} Notice'
embed['description'] = message
embed['footer'] = {}
embed['footer']['text'] = f'Alert state: {status}'
embed['timestamp'] = timestamp
embed['color'] = color
data['embeds'].append(embed)
print(data)
result = requests.post(url, data=json.dumps(data), headers={"Content-Type": "application/json"})
print(result)
return result