#8024: fix(slack): resolve channel names via directory for cross-account messaging
channel: slack
stale
Cluster:
Slack Integration Improvements
## 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
#13489: fix: preserve Slack channel/user ID case in target normalization
by sandieman2 · 2026-02-10
85.9%
#8684: fix(slack): add title param and channel resolution for file upload
by shuans · 2026-02-04
85.6%
#13881: fix: Address Greptile feedback - test isolation and channel resolution
by trevorgordon981 · 2026-02-11
84.4%
#22221: fix: preserve case of target ID in normalizeTargetId
by zerone0x · 2026-02-20
83.3%
#5312: fix(slack): skip users.list API call when all user entries are IDs
by gunpyo-park-musinsa · 2026-01-31
82.1%
#5036: docs: improve Slack setup and troubleshooting guide
by DanBatten · 2026-01-31
81.3%
#11491: feat(slack): allow agents to resolve channel IDs to names and list ...
by Lukavyi · 2026-02-07
81.0%
#19430: Slack: infer bare user targets before media upload
by gg2uah · 2026-02-17
80.8%
#12954: feat(slack): Add channel name resolution with TTL cache
by trevorgordon981 · 2026-02-10
80.7%
#10643: fix(slack): classify D-prefix DMs correctly when channel_type disag...
by mcaxtr · 2026-02-06
80.2%