Skip to content

Instantly share code, notes, and snippets.

@dwdraju
Created May 1, 2019 06:42
Show Gist options
  • Save dwdraju/0a7c29f7bcdf030075070b6cf7f38359 to your computer and use it in GitHub Desktop.
Save dwdraju/0a7c29f7bcdf030075070b6cf7f38359 to your computer and use it in GitHub Desktop.
Slack incoming webhook in python
import json
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/T*******Y/BCU****4/8YaPzL******MUk***Tz'
slack_data = {'text': "Sup! We're hacking shit together :spaghetti:"}
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