- Notifications
You must be signed in to change notification settings - Fork 46.7k
/
Copy pathslack_message.py
22 lines (17 loc) · 740 Bytes
/
slack_message.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Created by sarathkaul on 12/11/19
importrequests
defsend_slack_message(message_body: str, slack_url: str) ->None:
headers= {"Content-Type": "application/json"}
response=requests.post(
slack_url, json={"text": message_body}, headers=headers, timeout=10
)
ifresponse.status_code!=200:
msg= (
"Request to slack returned an error "
f"{response.status_code}, the response is:\n{response.text}"
)
raiseValueError(msg)
if__name__=="__main__":
# Set the slack url to the one provided by Slack when you create the webhook at
# https://my.slack.com/services/new/incoming-webhook/
send_slack_message("<YOUR MESSAGE BODY>", "<SLACK CHANNEL URL>")