-
Notifications
You must be signed in to change notification settings - Fork 0
/
embeds.py
56 lines (52 loc) · 1.76 KB
/
embeds.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
49
50
51
52
53
54
55
56
from slack_webhook import Slack
from redmine import get_user_data
import os
WEBHOOK_URL = os.getenv('WEBHOOK_URL')
def send_webhook(url, username, position, issues, hours, thumbnail_url, color):
if color == 'green':
color = 'good'
else:
color = 'danger'
slack = Slack(url=url)
response = slack.post(
attachments = [{
"fallback": "Attendance Marked",
"author_name": "Redmine marked an attendance",
"title": "User",
"text": username,
"color": color,
"actions": [
{
"name": "action",
"type": "button",
"text": "Check attendance",
"style": "",
"value": "complete",
"url": "https://attendance.koders.in"
},
],
"fields": [
{
"title": "Position",
"value": position,
"short": False
},
{
"title": "Issues",
"value": issues,
"short": True
},
{
"title": "Spent time",
"value": str(hours),
"short": True
}
],
"thumb_url": thumbnail_url,
}]
)
print(response)
def create_webhook(user_id, color):
username, position, opened_issues, total_issues, hours, thumbnail_url = get_user_data(user_id)
issues = str(opened_issues) + "/" + str(total_issues)
send_webhook(WEBHOOK_URL, username, position, issues, hours, thumbnail_url, color)