Slack Bolt app.message: Strings, Regex and context.matches Tested
We sent 9 test messages to the same listeners in Bolt Python and Bolt JS. Strings match anywhere and are case sensitive, regex groups land in context.matches, and edits and /me messages behave differently in each.
On this page
app.message("hello") in Bolt fires when "hello" appears anywhere in the message text, and the match is case sensitive. To match whole words, ignore case or pull values out of the text, pass a regex instead: re.compile(r"deploy (\w+) to (\w+)", re.IGNORECASE) in Python or /deploy (\w+) to (\w+)/i in JavaScript, and read the captured values from context.matches.
We ran the same four listeners in Bolt Python 1.30.0 and Bolt JS 4.7.3 against one throwaway app on 29 November 2026, and a second workspace member sent the same 9 messages to each. Every result below is what fired.
The test messages and what fired
| Message | Bolt Python | Bolt JS |
|---|---|---|
| hello world | "hello" | 'hello' |
| Hello team | nothing (HTTP 404, resent) | nothing |
| Othello is on tonight | "hello" | 'hello' |
| deploy api to prod | regex, matches ['api', 'prod'] | regex, matches ['deploy api to prod', 'api', 'prod'] |
| Deploy web to staging please | regex, matches ['web', 'staging'] | regex, matches ['Deploy web to staging', 'web', 'staging'] |
| a thread reply | thread-reply matcher | thread-reply middleware |
| an edit that adds "hello" | message_changed only | subtype('message_changed') only |
| /me says hello | nothing (HTTP 404) | 'hello' and subtype('me_message') |
| hello from our own bot | ignored | ignored |
Four results catch people out:
- Strings are substring and case sensitive. "Othello" matched
hello, "Hello team" did not. Use a regex with a word boundary,\bhello\b, plus the ignore-case flag if you mean the word. context.matchesdiffers between the SDKs. Python gave only the capture groups; JS gave the full match first, then the groups (the output ofRegExp.exec). Index 1 in JS is index 0 in Python.- Edits do not fire
app.message. Editing a message to add "hello" fired neitherhellolistener. The edit arrives as amessage_changedevent with the new text underevent.message.text, so listen for that subtype if edits matter. /memessages split the two SDKs. Bolt JS ran thehellolistener for ame_message; Bolt Python did not, and answered 404.
The Python listeners we ran
import os, re, json, time
from slack_bolt import App
app = App(token=os.environ["SLACK_BOT_TOKEN"], signing_secret=os.environ["SLACK_SIGNING_SECRET"])
LOG = open(os.environ["FIRE_LOG"], "a")
def fired(name, message, context):
LOG.write(json.dumps({"listener": name, "text": message.get("text"),
"subtype": message.get("subtype"), "thread_ts": message.get("thread_ts"),
"matches": context.get("matches")}) + "\n"); LOG.flush()
# 1. plain string
@app.message("hello")
def on_hello(message, context):
fired("string 'hello'", message, context)
# 2. regex with capture groups
@app.message(re.compile(r"deploy (\w+) to (\w+)", re.IGNORECASE))
def on_deploy(message, context):
fired("regex deploy (\\w+) to (\\w+)", message, context)
# 3. subtype filter through app.event
@app.event({"type": "message", "subtype": "message_changed"})
def on_edit(event, context):
fired("event subtype message_changed", event.get("message", {}), context)
# 4. thread replies only
def is_thread_reply(message):
return message.get("thread_ts") not in (None, message.get("ts"))
@app.message(re.compile(r".*"), matchers=[lambda message: is_thread_reply(message)])
def on_reply(message, context):
fired("thread reply matcher", message, context)
The JS version is the same four listeners, with subtype('message_changed') from @slack/bolt for the edit and a small middleware for thread replies:
const { App, subtype } = require('@slack/bolt');
app.message('hello', async ({ message, context }) => { /* ... */ });
app.message(/deploy (\w+) to (\w+)/i, async ({ context }) => {
const [full, service, env] = context.matches; // full match first in JS
});
app.message(subtype('message_changed'), async ({ message }) => {
console.log(message.message.text); // the new text
});
const threadReply = async ({ message, next }) => {
if (message.thread_ts && message.thread_ts !== message.ts) await next();
};
app.message(threadReply, async ({ message }) => { /* ... */ });
Never appear "away" on Slack again
Cloud-based. No downloads. Works 24/7 even when your laptop is off.
Unmatched messages in Bolt Python get a 404, and Slack sends them again
Our app used HTTP mode (Events API through a tunnel). For every message event that no listener matched, Bolt Python logged this and answered 404:
Unhandled request ({'type': 'event_callback', 'event': {'type': 'message'}})
---
[Suggestion] You can handle this type of event with the following listener function:
@app.event("message")
def handle_message_events(body, logger):
logger.info(body)
127.0.0.1 - - [29/Nov/2026 18:52:52] "POST /slack/events HTTP/1.1" 404 -
127.0.0.1 - - [29/Nov/2026 18:53:53] "POST /slack/events HTTP/1.1" 404 - (same event, 61 s later)
Slack treats a 404 as a failed delivery and retries it, so each unmatched message reached the app again about a minute later. In a busy channel that doubles your traffic and fills the log. The fix is a catch-all registered after all the others:
@app.event("message")
def ignore_other_messages(event, logger):
pass # acked with 200, no retry
With it in place, "Hello team" reached the catch-all and got a 200, and no retry followed. Bolt JS acknowledged every event with 200 whether a listener matched or not, so it needs no catch-all. For other ways to handle failures, see Bolt error handling.
Scopes and events the listeners need
app.message only sees messages Slack sends you. For public channels subscribe to message.channels with the channels:history scope; add message.groups and groups:history for private channels, and message.im with im:history for DMs. The bot must be a member of the channel. A message that @mentions the bot also arrives as app_mention if you subscribe to it, so do not handle the same text in both. To start from scratch, our Bolt Python example and Bolt TypeScript guide set up the app; Bolt middleware covers custom matchers in more depth.
FAQ
Why does my app.message listener reply to its own messages?
It should not: both SDKs ignored our bot's own "hello" by default. If yours loops, the reply probably comes from a different app or token, such as a user token posting as you.
Can one message fire two app.message listeners?
Yes. In Bolt JS the /me says hello message fired both the 'hello' listener and the me_message subtype listener. Every listener whose pattern matches runs, so make patterns specific.
Stop Jiggling Your Mouse.
Join hundreds of remote workers who never worry about their Slack status. Set it up once, stay green forever.
Related Articles
Slack OAuth Errors: invalid_scope, Invalid Permissions Requested and bad_redirect_uri
We broke a Slack OAuth install on purpose six ways and recorded each error page, the error code your redirect URL receives, and the oauth.v2.access answers, including the one that burns your code.
Slack Attachments vs Blocks: What Still Works in Each
We posted the same alert as legacy attachments, as blocks, and as blocks inside an attachment. Here is what renders, what Slack ignores now, and when the color bar still needs an attachment.
Slack Workspace vs Channel: What Each One Is
A workspace is the whole Slack account your team signs in to; a channel is one conversation inside it. Screenshots and API IDs from a real workspace show where each one lives.