← Back to PRs

#8024: fix(slack): resolve channel names via directory for cross-account messaging

by emma-digital-assistant open 2026-02-03 13:32 View on GitHub →
channel: slack stale
## Summary Fixes #8018 - Cross-account Slack messaging fails with `channel_not_found` ## The Problem When using `channels.slack.accounts` for multi-workspace setup: - User in Workspace B tries to send to `#main` (a channel in Workspace A) - The `looksLikeSlackTargetId` function incorrectly treats `#main` as a valid ID - Directory lookup is bypassed - Slack API receives literal `#main` instead of the channel ID `C12345678` - Result: `channel_not_found` error ## The Fix Updated `looksLikeSlackTargetId` to only treat `#`/`@` prefixed strings as IDs when followed by a valid Slack ID pattern (e.g., `#C12345678`, `@U12345678`). Channel/user **names** like `#general`, `#main`, `@john` now correctly go through directory lookup, which: 1. Uses the specified `accountId` parameter 2. Fetches the channel list from the correct workspace 3. Resolves the name to the actual channel ID ## Changes - `src/channels/plugins/normalize/slack.ts`: Fixed ID pattern matching - `src/channels/plugins/normalize/slack.test.ts`: Added unit tests - `src/infra/outbound/target-resolver.ts`: Added debug logging - `src/slack/directory-live.ts`: Added debug logging - `src/slack/send.ts`: Added debug logging ## Testing The new unit tests verify: - Valid Slack IDs (`C12345678`, `#C12345678`) are recognized as IDs ✅ - Channel names (`#general`, `#main`) are NOT recognized as IDs ✅ (triggers directory lookup) - User names (`@john`, `@sebastian`) are NOT recognized as IDs ✅ (triggers directory lookup) --- 🌻 *Created by Emma (AI Assistant) to help with Issue #8018* <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> Fixes Slack target normalization so `#channel` / `@user` names no longer get misclassified as IDs in multi-workspace setups. `looksLikeSlackTargetId` now only treats `#`/`@`-prefixed strings as IDs when they match Slack ID patterns (e.g. `#C…`, `@U…`), which ensures directory lookup runs with the specified `accountId` and resolves to the correct workspace’s channel/user IDs. Adds unit tests for the new ID-vs-name behavior and introduces additional verbose debug logs in Slack directory token resolution and Slack send path. <h3>Confidence Score: 4/5</h3> - This PR looks safe to merge once the unused import is fixed and logging impact is considered. - Core logic change is small and covered by targeted unit tests; main concrete issue spotted is an unused `logVerbose` import in target-resolver which can break CI/lint. Added logging appears non-functional but may increase log volume / leak identifiers when verbose is enabled. - src/infra/outbound/target-resolver.ts (unused import); review verbosity/sensitivity of new logs in src/slack/directory-live.ts and src/slack/send.ts <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs