feat(slack): resolve @displayname mentions to <@USER_ID> in outgoing messages#230
feat(slack): resolve @displayname mentions to <@USER_ID> in outgoing messages#230
Conversation
…messages Build a reverse index from display name → user IDs during lookupUser(), track thread participants on incoming messages, and resolve @name mentions to Slack's <@USER_ID> format before sending. Disambiguates using thread participants when multiple users share a display name. Also increases user/channel cache TTLs to 8 days. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
matchai
left a comment
There was a problem hiding this comment.
Non-blocking but might be worth holding off until we address cache busting.
packages/adapter-slack/src/index.ts
Outdated
| return text.replace(mentionPattern, (match, name: string) => { | ||
| const idx = text.indexOf(match); | ||
| if (idx > 0 && text[idx - 1] === "<") { | ||
| return match; | ||
| } |
There was a problem hiding this comment.
In the event of two mentions in the same message, this indexOf will resolve to the first instance for every match. Patched up by using the offset:
| return text.replace(mentionPattern, (match, name: string) => { | |
| const idx = text.indexOf(match); | |
| if (idx > 0 && text[idx - 1] === "<") { | |
| return match; | |
| } | |
| return text.replace(mentionPattern, (match, name: string, offset: number) => { | |
| if (offset > 0 && text[offset - 1] === "<") { | |
| return match; | |
| } |
| private readonly formatConverter = new SlackFormatConverter(); | ||
| private static USER_CACHE_TTL_MS = 60 * 60 * 1000; // 1 hour | ||
| private static CHANNEL_CACHE_TTL_MS = 60 * 60 * 1000; // 1 hour | ||
| private static USER_CACHE_TTL_MS = 8 * 24 * 60 * 60 * 1000; // 8 days |
There was a problem hiding this comment.
The userId → displayName mapping will be stale here for 8 days. This'll cause cosmetic issues with the agent using an old user name after a name change for to up to 8 days.
We have users:read in the manifest so we should subscribe to user_change events for cache invalidation.
…he on user_change
…date cache on user_change" This reverts commit 8cb0d90.
|
@cramforce I've gone ahead and stacked #236 on your PR to implement cache invalidation 👍 |
…he on user_change (#236) * fix(slack): use replace offset for duplicate mentions, invalidate cache on user_change * style: align handleUserChange to async/await, expand changeset
Build a reverse index from display name → user IDs during lookupUser(), track thread participants on incoming messages, and resolve @name mentions to Slack's <@USER_ID> format before sending. Disambiguates using thread participants when multiple users share a display name. Also increases user/channel cache TTLs to 8 days.