-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Event Matching Specific Reaction #284
Comments
Hi @Beartime234, thanks for taking the time to write in! The For this use case, the recommended way is to utilize listener matchers as below. A listener matcher is a simplified wrapper of listener middleware. You can pass an array of # listener matcher: async function that returns bool
async def is_eyes(event: dict) -> bool:
return event["reaction"] == "eyes"
@app.event("reaction_added", matchers=[is_eyes])
async def handle_eyes_reactions_only(body, logger):
logger.info(body)
# common utility example
def is_target_reaction(reaction: str):
async def is_target(event) -> bool:
return event["reaction"] == reaction
return is_target
@app.event(
event="reaction_added",
matchers=[is_target_reaction("white_check_mark")],
)
async def handle_white_check_mark_reactions_only(body, logger):
logger.info(body) If Python supports async lambda syntax in the future, it can be much simpler like Also, if you would like to learn more about listener middleware, check the module document and the section in the website. |
HI @seratch, Thanks for your reply that makes sense. After delving into the code I realized that subtype was the only thing supported which is why I raised it as a feature request, but I see now that matchers is better suited for what I am wanting. I honestly didn't really click that matchers and middleware were the same thing! |
The latest revision already has a relevant sentence in docstring. bolt-python/slack_bolt/app/async_app.py Line 662 in 66aad21
@Beartime234 I'm glad to hear that listener matchers sound reasonable for you! Let me close this issue. |
Hi, Is there a way to tell bolt to execute another function or stop looking for a listener function when the reaction value in the event doesn't match what we want? We're getting the following error when it does not match. We register the event here.
|
This seemed to do the trick: Netflix/dispatch#3124, but I wish there was a better way to handle it. |
@mvilanova My recommendation is to have two listeners as below: # listener matcher to check if the reaction should be handled
def target_reactions_only(event) -> bool:
return event.get("reaction") in ["eyes", "white_check_mark"]
@app.event(event="reaction_added", matchers=[target_reactions_only])
def handle_target_reactions(body, logger):
# do something meaningful here
logger.info(body)
# Note that this listener must be defined after the above one
@app.event(event="reaction_added")
def just_ack_the_rest_of_reaciton_events():
pass |
This is useful! |
Hi Bolt Python,
I am currently trying to create listeners for specific reactions and not just the event as a whole.
If someone reacts with the reaction white_check_mark, it will run a specific listener. If someone reacts with eyes it will run an alternative listener.
I have noticed that this doesn't occur and it will just match the event type and run the first listener found. I can inspect the body and then disperse from their but it would be nice if I was able to just match the type of reaction.
Something like this
Category (place an
x
in each of the[ ]
)Requirements
Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.
The text was updated successfully, but these errors were encountered: