Last active
May 27, 2020 21:08
-
-
Save kavehbc/0e8fe40cf9d5f24ab99bb17e6730fca8 to your computer and use it in GitHub Desktop.
Python - Send a message to a Slack channel
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 | |
def sendSlackMessage(message): | |
webhook_url = 'here is your webhook_url' | |
slack_data = {"text": "{}".format(message), "username": "your app name"} | |
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