Skip to content

feat: event listener filter middleware for agents#2840

Open
srtaalej wants to merge 1 commit intomainfrom
ale-event-listener-filters
Open

feat: event listener filter middleware for agents#2840
srtaalej wants to merge 1 commit intomainfrom
ale-event-listener-filters

Conversation

@srtaalej
Copy link
Copy Markdown

Summary

This PR adds agentEventFilter(), a listener middleware that filters out events agents don't need — bot messages, slackbot, and all message subtypes (message_changed, message_deleted, channel_join, etc.)

  • Works across listener types: app.message(), app.event('app_mention'), and any other event listener
  • Configurable via allow and block options for fine-grained control over which subtypes pass through

Motivation

Agent developers building on Bolt currently have to write the same boilerplate in every event handler:

 app.message(async ({ message }) => {                                                                                                                                               
   if (message.subtype) return;                                                                                                                                                     
   if (message.bot_id) return;                                                                                                                                                      
   if (message.user === 'USLACKBOT') return;                                                                                                                                        
   // ...actual logic                                                                                                                                                               
 });                                                                                                                                                                                

This is error-prone and easy to get wrong. agentEventFilter() replaces all of that with a single middleware call.

Testing

 import { App, agentEventFilter } from '@slack/bolt';                                                                                                                               
                                                                                                                                                                                    
 // Default: only plain user messages pass through                                                                                                                                  
 app.message(agentEventFilter(), async ({ message, say }) => {                                                                                                                      
   await say(`You said: ${message.text}`);                                                                                                                                          
 });                                                                                                                                                                                
                                                                                                                                                                                    
 // Also allow file_share messages through                                                                                                                                          
 app.message(agentEventFilter({ allow: ['file_share'] }), async ({ message, say }) => {
   if (message.subtype === 'file_share') {                                                                                                                                          
     await say('Thanks for the file!');                                                                                                                                             
   }                                                                                                                                                                                
 });                                                                                                                                                                                
                                                                                                                                                                                    
 // Works with app_mention too                                                                                                                                                      
 app.event('app_mention', agentEventFilter(), async ({ event, say }) => {                                                                                                           
   await say('You mentioned me!');                                                                                                                                                  
 });   

Requirements (place an x in each [ ])

@srtaalej srtaalej requested a review from a team as a code owner March 26, 2026 20:29
@srtaalej srtaalej self-assigned this Mar 26, 2026
@srtaalej srtaalej added enhancement M-T: A feature request for new functionality semver:minor labels Mar 26, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 26, 2026

Codecov Report

❌ Patch coverage is 98.63014% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.55%. Comparing base (8d10b03) to head (fc36140).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/middleware/builtin.ts 98.63% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2840      +/-   ##
==========================================
+ Coverage   93.50%   93.55%   +0.04%     
==========================================
  Files          42       42              
  Lines        7747     7820      +73     
  Branches      678      688      +10     
==========================================
+ Hits         7244     7316      +72     
- Misses        498      499       +1     
  Partials        5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement M-T: A feature request for new functionality semver:minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant