-
Notifications
You must be signed in to change notification settings - Fork 0
/
notifications.py
31 lines (28 loc) · 960 Bytes
/
notifications.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
slack_channel = '#jetson-camera'
slack_icon_url = 'https://i.pinimg.com/originals/fa/2e/58/fa2e583668a7d0ec15f4fa1bcb20975d.jpg'
slack_user_name = 'Jetson Cam'
def post_message_to_slack(text, args, blocks = None):
return requests.post('https://slack.com/api/chat.postMessage', {
'token': args.slack_token,
'channel': slack_channel,
'text': text,
'icon_url': slack_icon_url,
'username': slack_user_name,
'blocks': json.dumps(blocks) if blocks else None
}).json()
def post_file_to_slack(
text, args, file_name, file_bytes, file_type=None, title=None
):
return requests.post(
'https://slack.com/api/files.upload',
{
'token': args.slack_token,
'filename': file_name,
'channels': slack_channel,
'filetype': file_type,
'initial_comment': text,
'title': title
},
files = { 'file': file_bytes }).json()