Skip to content

feat(chat): add thread.getParticipants()#386

Merged
bensabic merged 3 commits intomainfrom
feat/thread-get-participants
Apr 15, 2026
Merged

feat(chat): add thread.getParticipants()#386
bensabic merged 3 commits intomainfrom
feat/thread-get-participants

Conversation

@bensabic
Copy link
Copy Markdown
Contributor

  • Add thread.getParticipants() method that returns unique human participants in a thread
  • Scans message history, deduplicates by user ID, excludes the bot itself
  • Includes the current message author even if message history hasn't been fetched yet
  • 4 unit tests covering deduplication, bot exclusion, empty threads, and currentMessage inclusion

Use case: subscribe only to 1:1 conversations, unsubscribe when others join so humans can chat without the bot replying to every message.

bot.onNewMention(async (thread) => {
  const participants = await thread.getParticipants();
  if (participants.length === 1) {
    await thread.subscribe();
    await thread.post("I'm here to help!");
  }
});

bot.onSubscribedMessage(async (thread) => {
  const participants = await thread.getParticipants();
  if (participants.length > 1) {
    await thread.unsubscribe();
    return;
  }
  // respond...
});

Returns unique human participants in a thread by scanning message
history. Excludes the bot itself. Useful for subscribing only to
1:1 conversations and unsubscribing when others join.
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chat Ready Ready Preview, Comment, Open in v0 Apr 15, 2026 0:42am
chat-sdk-nextjs-chat Ready Ready Preview, Comment, Open in v0 Apr 15, 2026 0:42am

@bensabic bensabic requested a review from dancer April 15, 2026 00:13
Comment thread packages/chat/src/thread.ts Outdated
Third-party bots (e.g. Jira, GitHub) were included as participants
because only isMe was checked. Now filters on isBot as well.
@bensabic bensabic merged commit 37dbb4a into main Apr 15, 2026
12 checks passed
@bensabic bensabic deleted the feat/thread-get-participants branch April 15, 2026 00:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants