-
-
Save yazinsai/2452879d909ab1a612e9fcd69ad62373 to your computer and use it in GitHub Desktop.
POST a JSON payload to a Slack Incoming Webhook using Python requests
This file contains 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
''' | |
This is an example of how to send data to Slack webhooks in Python with the | |
requests module. | |
Detailed documentation of Slack Incoming Webhooks: | |
https://api.slack.com/incoming-webhooks | |
''' | |
import requests | |
# Set the webhook_url to the one provided by Slack when you create the webhook at | |
# https://my.slack.com/services/new/incoming-webhook/ | |
webhook_url = 'https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX' | |
slack_data = {'text': 'Message from Python! :spaghetti:'} | |
response = requests.post(webhook_url, json=slack_data) | |
if response.status_code != 200: | |
raise ValueError( | |
'Request to slack returned an error %s, the response is:\n%s' | |
% (response.status_code, response.text) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment