forked from unl1k3ly/AnchorHODL
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsend_notification.py
46 lines (40 loc) · 1.31 KB
/
send_notification.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
import config
import requests
import json
def slack_webhook(msg):
slack_data = {
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": msg
}
}
]
}
try:
response = requests.post(
config.SLACK_WEBHOOK_URL, data=json.dumps(slack_data),
headers={'Content-Type': 'application/json'}, timeout=5
)
if response.status_code != 200:
raise ValueError(
'Request to slack returned an error %s, the response is:\n%s'
% (response.status_code, response.text)
)
except Exception:
pass
def telegram_notification(msg):
tg_data = {"chat_id": str(config.TELEGRAM_CHAT_ID), "text": msg, "parse_mode": 'Markdown'}
try:
response = requests.post('https://api.telegram.org/bot' + config.TELEGRAM_TOKEN + '/sendMessage', data=json.dumps(tg_data),
headers={'Content-Type': 'application/json'}, timeout=5
)
if response.status_code != 200:
raise ValueError(
'Request to slack returned an error %s, the response is:\n%s'
% (response.status_code, response.text)
)
except Exception:
pass