Req: Support matching multiple message events
See original GitHub issueIf a message contains multiple matches, it seems that Bolt will only call the first message handler that matches, and then stop processing the message
event.
I would like to see Bolt have a way to continue handling other message events.
Category
- slack_bolt.App and/or its core components
- slack_bolt.async_app.AsyncApp and/or its core components
Example
@app.message("ping")
async def message_ping(self, message: Dict, say: AsyncSay):
await say("Pong!")
@app.message("pong")
async def message_pong(self, message: Dict, say: AsyncSay):
await say("Ping!")
If I send the message Testing ping pong responders, I expect Bolt to respond twice, say
ing both Pong! and Ping!, but it only returns Pong!
This is a silly example meant to demonstrate the issue, but there are real-world use cases where a message can contain multiple “triggers” that should all be processed by the app.
I’m thinking that this could be implemented like middleware, where message handlers could (optionally) call next()
to have Bolt continue processing other message handlers.
(Unfortunately this is a blocking issue for me, so if you have any ideas on how to work around it, I’m open to suggestions!)
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (8 by maintainers)
The second line in the comment was a bit unclear. I just updated the line. The reason why there are two patterns is Slack app’s permission model migration: https://api.slack.com/authentication/token-types#bot
Messages posted by most apps with the current permission model don’t have the subtype. On the other hand, messages by “classic” apps always have the subtype. Other apps in a workspace may send a message with the subtype.
The
Most apps utilize bot events to receive notifications from Slack. In this case,
is_bot
flag underauthorizations
is not suitable for the purpose. The flag tells whether an event is a bot event. Here is a screenshot of Slack app configuration page:is_bot
is always true. If an event is the one on behalf of users, the field is false.If you want to have a global middleware that does the same with the listener matcher I shared above, the code can be like this:
I do not know about your app but probably the approach may work well.
One thing I can suggest is that your app may want to filter subtypes this way:
The
handle_only_new_messages
handler matches only newly posted messages. If you want to handle others as well, you can add more subtypes to the tuple in the constraints. See https://api.slack.com/events/message#message-event-type__message-subtypes for the list of available subtypes.