Skip to content

fix(slack): decode the bot self mention in incoming message text - #891

Merged
dancer merged 4 commits into
mainfrom
fix/slack-resolve-self-mention
Sep 3, 2026
Merged

fix(slack): decode the bot self mention in incoming message text#891
dancer merged 4 commits into
mainfrom
fix/slack-resolve-self-mention

Conversation

@privatenumber

@privatenumber privatenumber commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Problem

When a Slack message mentions the bot, the adapter resolves every mention in the text to a display name — except the bot's own. <@U_BOT> stays in message.text as raw user-ID markup while other mentions become @<DisplayName>.

Downstream consumers therefore see inconsistent text. For LLM-based consumers this is actively harmful: small models classify differently depending on whether the mention arrived as self-describing @<DisplayName> text or as cryptic <@U_BOT> markup, and there is no way for a consumer to tell a real mention from a lookalike string without re-implementing Slack's mrkdwn rules.

The reason the bot's own mention was left raw is detection coupling: Chat.detectMention matched @botUserId / <@botUserId> in the text, so resolving the markup would have hidden the mention from detection.

Changes

  • resolveInlineMentions now decodes the bot's own mention like any other: <@U_BOT> resolves to @<DisplayName> (via the same users.info lookup and cache as all other mentions).
  • Because resolution renders the ID markup away, detection moves to where the ID is still known: parseSlackMessage tests the raw event text for the bot's mention (labeled, unlabeled, and bare @ID forms) and sets isMention on the parsed message. Chat.detectMention remains as the fallback for username-style mentions on the rendered text.
  • The skipSelfMention option is removed; the history/thread fetch paths that passed skipSelfMention: false now behave identically to live events, which also fixes an inconsistency where edited messages (parseSlackMessageSync) never resolved mentions at all.

Behavior change

message.text for a message that mentions the bot changes from <@U_BOT> hello to @Vercel Bot hello (the bot's resolved display name). Mention detection is preserved: isMention is set from the raw event text, and the labeled form is matched by the new detection patterns. Apps matching the raw <@U_BOT> markup in message.text should match the resolved display name or read message.raw instead.

Relation to #355

#355 intentionally introduced the self-mention skip: in multi-workspace installs, the request-scoped bot ID was being resolved before mention detection ran, which broke onNewMention for those workspaces. This PR preserves that guarantee without the markup coupling — the multi-workspace replay test from that scenario is updated and still asserts that a plain message event containing the bot's mention sets isMention: true and routes to onNewMention. Detection additionally covers the labeled form (<@U_BOT|Name>) that resolution now produces.

@privatenumber
privatenumber requested a review from a team as a code owner September 3, 2026 10:38
@vercel

vercel Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
chat Ready Ready Preview, v0 Sep 3, 2026 5:34pm UTC
chat-sdk-nextjs-chat Ready Ready Preview, v0 Sep 3, 2026 5:34pm UTC

Signed-off-by: dancer <josh@afterima.ge>
@dancer
dancer merged commit 51322dd into main Sep 3, 2026
19 checks passed
@dancer
dancer deleted the fix/slack-resolve-self-mention branch September 3, 2026 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants