Created
January 10, 2019 23:18
-
-
Save Smerity/77d0d5edfdeb2304393f9d253c705bf5 to your computer and use it in GitHub Desktop.
Send a message using the Slack postMessage API
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 requests | |
AUTH_TOKEN = 'xoxb-...' | |
channel = '#locked-out' | |
USER_ID = 'UDAS0J04S' # A user ID obtained by `list_members.py` | |
text = f'<@{USER_ID}>, Smerity locked himself out' | |
params = { | |
'token': AUTH_TOKEN, | |
'channel': channel, | |
'text': text | |
} | |
r = requests.post('https://slack.com/api/chat.postMessage', params=params) | |
# You can print the response to see if it succeeded - expecting a 200 | |
print(r) | |
# The Slack response itself may actually be an error however | |
# 'ok' will be true or false depending on whether an error was triggered | |
print(r.json()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment