Skip to content

Commit 1d4e434

Browse files
author
Kai Liu
committed
fix(slack): resolve workspace token for synthetic-thread questions
Mirror the token-resolution logic from sendMessage in the sendQuestion adapter. When the thread id is a synthetic placeholder (task: / cron-job: / cron:), postSlackQuestion drops thread_ts and degenerates to a top-level channel post; in that case the registry has no entry for the fake thread_ts, and getSlackBotToken(channelId, fakeTs) can fall back to the first registered workspace token in multi-workspace installs. Use getWorkspaceBotTokenForChannel(channelId) first so the posted Block Kit / plain-text question lands with the token bound to the actual channel. Addresses Codex review comment on PR #212.
1 parent 6da6431 commit 1d4e434

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

packages/ims/slack/client.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,19 @@ function createSlackAdapter(processorId?: string): IMAdapter {
649649
options: string[] | undefined,
650650
prefix?: string
651651
) => {
652-
const token = getSlackBotTokenForProcessor(processorId) ?? getSlackBotToken(channelId, threadId);
652+
// Mirror the token-resolution logic in `sendMessage`: when the thread
653+
// id is a synthetic placeholder (`task:` / `cron-job:` / `cron:`), the
654+
// posted question degenerates to a top-level channel post inside
655+
// `postSlackQuestion`, so the registry has no entry for that fake
656+
// `thread_ts`. Resolve via the channel's workspace first to avoid the
657+
// multi-workspace edge case where `getSlackBotToken(channelId, fakeTs)`
658+
// can fall back to the first registered token instead of the one bound
659+
// to `channelId`.
660+
const threadIsSynthetic = isSyntheticOwner(threadId);
661+
const token = getSlackBotTokenForProcessor(processorId)
662+
?? (threadIsSynthetic
663+
? (getWorkspaceBotTokenForChannel(channelId) ?? getSlackBotToken(channelId))
664+
: getSlackBotToken(channelId, threadId));
653665
if (!token) {
654666
// No token -> fall through to plain-text sendMessage so the question
655667
// still gets delivered through whatever channel/path the caller has.

0 commit comments

Comments
 (0)