Skip to content

Comments

docs: fix listener middleware function and use global middleware examples#2610

Merged
zimeg merged 1 commit intomainfrom
zimeg-docs-middleware
Jul 25, 2025
Merged

docs: fix listener middleware function and use global middleware examples#2610
zimeg merged 1 commit intomainfrom
zimeg-docs-middleware

Conversation

@zimeg
Copy link
Member

@zimeg zimeg commented Jul 22, 2025

Summary

This PR fixes an example listener middleware function and includes a more complete global listener middleware example 🙏 📚

Requirements

@zimeg zimeg self-assigned this Jul 22, 2025
@zimeg zimeg added the docs M-T: Documentation work only label Jul 22, 2025
@codecov
Copy link

codecov bot commented Jul 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.37%. Comparing base (5baeaee) to head (93badf4).
Report is 1 commits behind head on main.

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.
📢 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.

Copy link
Member Author

@zimeg zimeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Leaving a few quick notes for the wonderful reviewers.

await next();
}

app.use(authWithAcme);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👁️‍🗨️ 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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📣 The bot_message subtype is only available to classic Slack apps - preferring the GBP approach here!

In classic Slack apps, the bot_message event 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 the bot_id and bot_profile fields in the event payload.

https://api.slack.com/events/message/bot_message

Comment on lines 23 to +33
// 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}`);
}
));
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👾 Changed this to a function, also with automatic formatting.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗣️ And the same or similar changes to files that follow-

Copy link
Contributor

@lukegalbraithrussell lukegalbraithrussell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amazing

@zimeg
Copy link
Member Author

zimeg commented Jul 25, 2025

@WilliamBergamin @lukegalbraithrussell Thank y'all both for the kind reviews 😌 ✨

I'll merge this now for the sake of example 🤖

@zimeg zimeg merged commit c3c1990 into main Jul 25, 2025
21 checks passed
@zimeg zimeg deleted the zimeg-docs-middleware branch July 25, 2025 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs M-T: Documentation work only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants