Skip to content

Instantly share code, notes, and snippets.

@chloegrace94
Created October 2, 2018 15:53
Show Gist options
  • Save chloegrace94/feee1e31fbd8198e83ec3ba9f5dde022 to your computer and use it in GitHub Desktop.
Save chloegrace94/feee1e31fbd8198e83ec3ba9f5dde022 to your computer and use it in GitHub Desktop.
Post to Slack using response URL
# Post to Slack
def post_to_slack(channel_id, message_ts, original_message, message_response, response_url):
try:
slack_data = {
"channel":channel_id,
"ts":message_ts,
"text":original_message,
#"attachment_type": "default",
"attachments": [
{
"name": "action_decision",
"text": message_response,
"fallback": "Sorry, I'm unable to do that for you at the moment"
}
]
}
logger.info("\nResponse Message: " + str(slack_data))
response = requests.post(
response_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)
)
except Exception as err:
logger.error('Error: %s' % str(err))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment