-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_slack_msg.py
48 lines (45 loc) · 1.43 KB
/
send_slack_msg.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import json, requests, sys
def format_slack_data(score, title, message):
if score == "5":
stars = ":star::star::star::star::star:"
elif score == "4":
stars = ":star::star::star::star:"
elif score == "3":
stars = ":star::star::star:"
elif score == "2":
stars = ":star::star:"
elif score == "1":
stars = ":star:"
else:
stars = ""
slack_data = {
"username": "AppReview",
"icon_emoji": ":android:",
#"channel" : "#somerandomcahnnel",
"text": title,
"attachments": [
{
"color": "#9733EE",
"fields": [
{
"title": stars,
"value": message,
"short": "false",
}
]
}
]
}
byte_length = str(sys.getsizeof(slack_data))
slack_data_formated = json.dumps(slack_data)
return slack_data_formated, byte_length
def send_msg(webhook_url, message, byte_length):
headers = {
'Content-Type': "application/json",
'Content-Length': byte_length
}
response = requests.request("POST", webhook_url, headers=headers, data=message)
if response.status_code != 200:
raise ValueError(
'Request to slack returned an error %s, the response is:\n%s'
% (response.status_code, response.text))