-
-
Save joriatyBen/76fce4fddd03514322a1e8607b6b7686 to your computer and use it in GitHub Desktop.
POST a JSON payload to Slack via Webhook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import requests | |
data = open('message.json', 'r').read() | |
def post_to_slack(message): | |
webhook_url = 'https://hooks.slack.com/webhook' | |
slack_data = json.dumps({'blocks': message}) | |
response = requests.post( | |
webhook_url, data=slack_data, | |
headers={'Content-Type': 'application/json'} | |
) | |
if response.status_code != 200: | |
raise ValueError( | |
'Request to slack returned an error %s, the response is:\n%s' | |
% (response.status_code, response.text) | |
) | |
post_to_slack(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment