Skip to content

Instantly share code, notes, and snippets.

@Ebaneck
Created May 13, 2022 06:34
Show Gist options
  • Select an option

  • Save Ebaneck/e49c6f79ab657ce4ace719e9887f2914 to your computer and use it in GitHub Desktop.

Select an option

Save Ebaneck/e49c6f79ab657ce4ace719e9887f2914 to your computer and use it in GitHub Desktop.
slack event api
@app.route('/slack/slack-reactions', methods=['POST'])
def slack_reactions():
logger.info(request)
slack_payload = request.get_json()
# slack event subscription verification
slack_request_timestamp = request.headers["X-Slack-Request-Timestamp"]
request_body = request.get_data().decode()
slack_signature = request.headers["X-Slack-Signature"]
if (int(time.time()) - int(slack_request_timestamp)) > 60:
print("Verification failed. Request is out of date.")
return Response(), 400
sig_basestring = 'v0:' + slack_request_timestamp + ':' + request_body
sig_basestring = sig_basestring.encode('utf-8')
signing_secret = bytes(SLACK_SIGNING_SECRET, 'utf-8')
my_signature = 'v0=' + hmac.new(signing_secret, sig_basestring, hashlib.sha256).hexdigest()
if hmac.compare_digest(my_signature, slack_signature):
return Response(slack_payload['challenge']), 200
else:
return Response(), 500
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment