slackapi/python-slack-events-api

Possible to handle HTTP headers from Slack within event adapter?

paul-griffith opened this issue · 1 comments

Description

Not sure if I just missed something, but if I wanted to handle an event with a particular header from Slack differently (ie, X-Slack-Retry-Num, from here) I don't see how to actually do that. I'm using the event adapter attached to an existing Flask instance; I can catch the header on my dedicated endpoints, just not sure how to within the event hook.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

As Flask's request objects are thread-local, you can access the value by importing flask.request and use request.headers in your listener functions.

#39 (comment)

import os
from flask import request
from slackeventsapi import SlackEventAdapter

slack_signing_secret = os.environ["SLACK_SIGNING_SECRET"]
slack_events_adapter = SlackEventAdapter(slack_signing_secret, "/slack/events")

# Example reaction emoji echo
@slack_events_adapter.on("reaction_added")
def reaction_added(event_data):
    print(request.headers)
    event = event_data["event"]