Created
November 27, 2020 01:34
-
-
Save trimkadriu/4cffd108101230321ccf2af83713249d to your computer and use it in GitHub Desktop.
Send Slack message with web-hooks on Python
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
import json | |
import requests | |
webhook_url = "" #Add the webhook here | |
slack_data = {"text": "This is a test message", "channel": "<channel-name> or <@person>"} | |
response = requests.post( | |
webhook_url, data = json.dumps(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) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment