Skip to content

Commit 73ccdf6

Browse files
committed
docs: add getParticipants() to Thread API reference and guides
1 parent d045968 commit 73ccdf6

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

apps/docs/content/docs/api/thread.mdx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,28 @@ await scheduled.cancel();
114114
Streaming and file uploads are not supported in scheduled messages.
115115
</Callout>
116116

117+
## getParticipants
118+
119+
Get the unique human participants in a thread. Returns deduplicated authors, excluding all bots. Useful for subscribing only to 1:1 conversations and unsubscribing when others join.
120+
121+
```typescript
122+
const participants = await thread.getParticipants();
123+
124+
// Subscribe only when one person is talking to the bot
125+
if (participants.length === 1) {
126+
await thread.subscribe();
127+
}
128+
129+
// Unsubscribe when the thread becomes a group conversation
130+
if (participants.length > 1) {
131+
await thread.unsubscribe();
132+
}
133+
```
134+
135+
<Callout type="warn">
136+
Each call fetches the full message history to find all participants. On threads with long history this makes multiple API calls to the platform. Consider checking `message.author` against a known set before calling `getParticipants()` on every incoming message.
137+
</Callout>
138+
117139
## subscribe / unsubscribe
118140

119141
Manage thread subscriptions. Subscribed threads route all messages to `onSubscribedMessage` handlers.

apps/docs/content/docs/threads-messages-channels.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,33 @@ await thread.unsubscribe();
4040
const subscribed = await thread.isSubscribed();
4141
```
4242

43+
### Participants
44+
45+
Get the unique human participants in a thread. Returns deduplicated authors, excluding all bots. Useful for deciding whether to subscribe based on how many humans are in the conversation.
46+
47+
```typescript title="lib/bot.ts" lineNumbers
48+
bot.onNewMention(async (thread) => {
49+
const participants = await thread.getParticipants();
50+
if (participants.length === 1) {
51+
await thread.subscribe();
52+
await thread.post("I'm here to help!");
53+
}
54+
});
55+
56+
bot.onSubscribedMessage(async (thread) => {
57+
const participants = await thread.getParticipants();
58+
if (participants.length > 1) {
59+
await thread.unsubscribe();
60+
return;
61+
}
62+
// respond...
63+
});
64+
```
65+
66+
<Callout type="warn">
67+
Each call fetches the full message history to find all participants. On threads with long history this makes multiple API calls to the platform. Consider checking `message.author` against a known set before calling `getParticipants()` on every incoming message.
68+
</Callout>
69+
4370
### Typing indicator
4471

4572
```typescript title="lib/bot.ts"

0 commit comments

Comments
 (0)