Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/channels/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class SlackChannel implements Channel {
private ownerUserId: string | null;
private phantomName: string;
private rejectedUsers = new Set<string>();
private participatedThreads = new Set<string>();

constructor(config: SlackChannelConfig) {
this.app = new App({
Expand Down Expand Up @@ -150,6 +151,11 @@ export class SlackChannel implements Channel {
lastTs = result.ts ?? "";
}

// Track thread participation so we can respond to replies without @ mention
if (replyThreadTs) {
this.participatedThreads.add(`${channel}:${replyThreadTs}`);
}

return {
id: lastTs || randomUUID(),
channelId: this.id,
Expand Down Expand Up @@ -282,6 +288,10 @@ export class SlackChannel implements Channel {
}
}

trackThreadParticipation(channelId: string, threadTs: string): void {
this.participatedThreads.add(`${channelId}:${threadTs}`);
}

private registerEventHandlers(): void {
this.app.event("app_mention", async ({ event, client: _client }) => {
if (!this.messageHandler) return;
Expand Down Expand Up @@ -334,7 +344,13 @@ export class SlackChannel implements Channel {
if (this.botUserId && userId === this.botUserId) return;

const channelType = msg.channel_type as string | undefined;
if (channelType !== "im") return;
if (channelType !== "im") {
// In channels, only respond to thread replies in threads we've participated in
const incomingThreadTs = msg.thread_ts as string | undefined;
if (!incomingThreadTs) return;
const threadKey = `${msg.channel as string}:${incomingThreadTs}`;
if (!this.participatedThreads.has(threadKey)) return;
}

if (userId && !this.isOwner(userId)) {
console.log(`[slack] Ignoring DM from non-owner: ${userId}`);
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,12 +450,16 @@ async function main(): Promise<void> {
if (progressStream) {
// Slack: update the progress message with the final response + feedback buttons
await progressStream.finish(response.text);
if (slackChannel && slackChannelId && slackThreadTs) {
slackChannel.trackThreadParticipation(slackChannelId, slackThreadTs);
}
} else if (isSlack && slackChannel && slackChannelId && slackThreadTs) {
// Slack fallback: send direct reply with feedback
const thinkingTs = await slackChannel.postThinking(slackChannelId, slackThreadTs);
if (thinkingTs) {
await slackChannel.updateWithFeedback(slackChannelId, thinkingTs, response.text);
}
slackChannel.trackThreadParticipation(slackChannelId, slackThreadTs);
} else {
// All other channels: send via router
await router.send(msg.channelId, msg.conversationId, {
Expand Down