WIP: Send Slack request with event data (if handler asks for it)#39
WIP: Send Slack request with event data (if handler asks for it)#39datashaman wants to merge 3 commits intoslackapi:mainfrom
Conversation
9550f2d to
c7ae074
Compare
|
This could be changed to send just the headers, but I thought that the whole request might make it more useful. |
|
Please notify me if/when the base PR is merged, and I'll rebase this on new master. |
c7ae074 to
8484576
Compare
8484576 to
90dd959
Compare
|
😘 |
|
I'm sorry the team took a very long time to respond to this. I'm still not sure if this approach is the best for addressing #32 yet. Allow me to hold off making any decisions about this for now. |
|
@seratch while you decide on what the best approach is, is there any way at all to access the request header while handling an event? |
As 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"]After leaving the above comment, I came to think that directly accessing
Considering this disadvantage, I think we don't have a strong reason to merge this PR's changes. |
|
As I mentioned in the last comment, you can access Flask's thread-local request object. Let me close this pull request. Thanks for taking the time to send it. |
Inspects arity of handler function to ascertain whether it should pass
request with event_data. Does not break current implementations.
Uses inspect module to check arity of the first listener for a specific event type.
If you want an event handler to get the Slack request, define it like this:
NB: A side-effect of this is that all event handlers of the same type must have the same number of arguments!
Resolves #32
Requires (and is based on) #37