diff --git a/apps/x/packages/core/src/knowledge/sync_slack.ts b/apps/x/packages/core/src/knowledge/sync_slack.ts index 632b91a4..4e55e7fd 100644 --- a/apps/x/packages/core/src/knowledge/sync_slack.ts +++ b/apps/x/packages/core/src/knowledge/sync_slack.ts @@ -201,12 +201,19 @@ async function performSync(): Promise { await ensureRun(); totalMessages += messages.length; - // Batch-resolve unknown user IDs + // Batch-resolve unknown user IDs (from authors + @mentions in content) const unknownIds = new Set(); + const mentionPattern = /<@(U[A-Z0-9]+)>/g; for (const msg of messages) { if (msg.author?.user_id && !state.userCache[msg.author.user_id]) { unknownIds.add(msg.author.user_id); } + let match; + while ((match = mentionPattern.exec(msg.content)) !== null) { + if (!state.userCache[match[1]]) { + unknownIds.add(match[1]); + } + } } for (const userId of unknownIds) { @@ -219,6 +226,13 @@ async function performSync(): Promise { } } + // Replace @mentions in message content with resolved names + for (const msg of messages) { + msg.content = msg.content.replace(/<@(U[A-Z0-9]+)>/g, (_: string, id: string) => { + return `@${state.userCache[id] || id}`; + }); + } + // Build and write markdown const wsName = workspaceNameFromUrl(workspace.url); const md = buildMarkdown(workspace.url, workspace.name || wsName, messages, state.userCache);