Skip to content

Instantly share code, notes, and snippets.

@kavehbc
Last active May 27, 2020 21:08
Show Gist options
  • Save kavehbc/0e8fe40cf9d5f24ab99bb17e6730fca8 to your computer and use it in GitHub Desktop.
Save kavehbc/0e8fe40cf9d5f24ab99bb17e6730fca8 to your computer and use it in GitHub Desktop.
Python - Send a message to a Slack channel
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