docs: fix listener middleware function and use global middleware examples#2610
docs: fix listener middleware function and use global middleware examples#2610
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2610 +/- ##
=======================================
Coverage 93.37% 93.37%
=======================================
Files 37 37
Lines 7581 7581
Branches 667 667
=======================================
Hits 7079 7079
Misses 497 497
Partials 5 5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
zimeg
left a comment
There was a problem hiding this comment.
📝 Leaving a few quick notes for the wonderful reviewers.
| await next(); | ||
| } | ||
|
|
||
| app.use(authWithAcme); |
There was a problem hiding this comment.
👁️🗨️ This was added to demonstrate how global middleware is used!
| As an example, let’s say your listener should only deal with messages from humans. You can write a listener middleware that excludes any bot messages. | ||
|
|
||
| ```javascript | ||
| // Listener middleware that filters out messages with 'bot_message' subtype |
There was a problem hiding this comment.
📣 The bot_message subtype is only available to classic Slack apps - preferring the GBP approach here!
In classic Slack apps, the
bot_messageevent is sent when a message is sent to a channel by an integration "bot". It is like a normal user message, except it has no associated user. With current Slack apps, also known as granular bot permissions (GBP) apps, you can detect if a message was sent by a bot by the presence of thebot_idandbot_profilefields in the event payload.
| // The listener only receives messages from humans | ||
| app.message(noBotMessages, async ({ message, logger }) => logger.info( | ||
| app.message(noBotMessages, async ({ message, logger }) => { | ||
| // Handle only newly posted messages | ||
| if (message.subtype === undefined | ||
| // || message.subtype === 'bot_message' | ||
| || message.subtype === 'file_share' | ||
| || message.subtype === 'thread_broadcast') { | ||
| logger.info(`(MSG) User: ${message.user} Message: ${message.text}`) | ||
| if ( | ||
| message.subtype === undefined || | ||
| message.subtype === 'file_share' || | ||
| message.subtype === 'thread_broadcast' | ||
| ) { | ||
| logger.info(`(MSG) User: ${message.user} Message: ${message.text}`); | ||
| } | ||
| )); | ||
| }); |
There was a problem hiding this comment.
👾 Changed this to a function, also with automatic formatting.
There was a problem hiding this comment.
🗣️ And the same or similar changes to files that follow-
|
@WilliamBergamin @lukegalbraithrussell Thank y'all both for the kind reviews 😌 ✨ I'll merge this now for the sake of example 🤖 |
Summary
This PR fixes an example listener middleware function and includes a more complete global listener middleware example 🙏 📚
Requirements