-
Notifications
You must be signed in to change notification settings - Fork 0
/
slack.py
31 lines (31 loc) · 1009 Bytes
/
slack.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
# pip install requests
import json
import sys
import random
import requests
if __name__ == '__main__':
url = "<YourSlack'sWebHookURLhere>"
message = ("This is my message")
title = (f"This is the Title:zap:")
slack_data = {
"username": "NotificationBot",
"icon_emoji": ":satellite:",
"channel" : "#job-updates",
"attachments": [
{
"color": "#9733EE",
"fields": [
{
"title": title,
"value": message,
"short": "false",
}
]
}
]
}
byte_length = str(sys.getsizeof(slack_data))
headers = {'Content-Type': "application/json", 'Content-Length': byte_length}
response = requests.post(url, data=json.dumps(slack_data), headers=headers)
if response.status_code != 200:
raise Exception(response.status_code, response.text)