discourse_list_user_chat_channels
Retrieve all chat channels for the authenticated user, including public channels and direct messages, with unread status tracking.
Instructions
List all chat channels for the currently authenticated user, including both public channels they're a member of and direct message channels. Includes unread tracking information.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The handler function that implements the tool logic: fetches the user's chat channels from `/chat/api/me/channels`, processes public and DM channels with unread tracking, formats into Markdown list with details like ID, slug, status, unread/mention counts, last message, and URLs.async (_args, _extra: any) => { try { const { base, client } = ctx.siteState.ensureSelectedSite(); const url = `/chat/api/me/channels`; const data = (await client.get(url)) as any; const publicChannels: any[] = data?.public_channels || []; const dmChannels: any[] = data?.direct_message_channels || []; const tracking = data?.tracking || {}; const lines: string[] = []; lines.push("# My Chat Channels"); lines.push(""); // Public channels if (publicChannels.length > 0) { lines.push(`## Public Channels (${publicChannels.length})`); lines.push(""); for (const channel of publicChannels) { const title = channel.title || `Channel ${channel.id}`; const slug = channel.slug || String(channel.id); const unreadCount = tracking?.channel_tracking?.[channel.id]?.unread_count || 0; const mentionCount = tracking?.channel_tracking?.[channel.id]?.mention_count || 0; lines.push(`### ${title}`); lines.push(`- **ID**: ${channel.id}`); lines.push(`- **Slug**: ${slug}`); lines.push(`- **Status**: ${channel.status || "open"}`); if (unreadCount > 0) { lines.push(`- **Unread**: ${unreadCount} messages`); } if (mentionCount > 0) { lines.push(`- **Mentions**: ${mentionCount}`); } if (channel.last_message) { const lastMsg = channel.last_message; lines.push(`- **Last Message**: by @${lastMsg.user?.username || "unknown"} at ${lastMsg.created_at || "unknown time"}`); } lines.push(`- **URL**: ${base}/chat/c/${slug}/${channel.id}`); lines.push(""); } } else { lines.push("## Public Channels"); lines.push("No public channels."); lines.push(""); } // Direct message channels if (dmChannels.length > 0) { lines.push(`## Direct Messages (${dmChannels.length})`); lines.push(""); for (const channel of dmChannels) { const title = channel.title || `DM ${channel.id}`; const unreadCount = tracking?.channel_tracking?.[channel.id]?.unread_count || 0; const mentionCount = tracking?.channel_tracking?.[channel.id]?.mention_count || 0; lines.push(`### ${title}`); lines.push(`- **ID**: ${channel.id}`); if (unreadCount > 0) { lines.push(`- **Unread**: ${unreadCount} messages`); } if (mentionCount > 0) { lines.push(`- **Mentions**: ${mentionCount}`); } if (channel.last_message) { const lastMsg = channel.last_message; lines.push(`- **Last Message**: by @${lastMsg.user?.username || "unknown"} at ${lastMsg.created_at || "unknown time"}`); } lines.push(`- **URL**: ${base}/chat/c/-/${channel.id}`); lines.push(""); } } else { lines.push("## Direct Messages"); lines.push("No direct message channels."); lines.push(""); } return { content: [{ type: "text", text: lines.join("\n") }] }; } catch (e: any) { return { content: [{ type: "text", text: `Failed to list user chat channels: ${e?.message || String(e)}` }], isError: true }; } }
- Zod input schema for the tool (empty object, no parameters required).const schema = z.object({}).strict();
- src/tools/builtin/list_user_chat_channels.ts:8-100 (registration)Registers the tool using server.registerTool with name, metadata (title, description, inputSchema), and handler function."discourse_list_user_chat_channels", { title: "List User's Chat Channels", description: "List all chat channels for the currently authenticated user, including both public channels they're a member of and direct message channels. Includes unread tracking information.", inputSchema: schema.shape, }, async (_args, _extra: any) => { try { const { base, client } = ctx.siteState.ensureSelectedSite(); const url = `/chat/api/me/channels`; const data = (await client.get(url)) as any; const publicChannels: any[] = data?.public_channels || []; const dmChannels: any[] = data?.direct_message_channels || []; const tracking = data?.tracking || {}; const lines: string[] = []; lines.push("# My Chat Channels"); lines.push(""); // Public channels if (publicChannels.length > 0) { lines.push(`## Public Channels (${publicChannels.length})`); lines.push(""); for (const channel of publicChannels) { const title = channel.title || `Channel ${channel.id}`; const slug = channel.slug || String(channel.id); const unreadCount = tracking?.channel_tracking?.[channel.id]?.unread_count || 0; const mentionCount = tracking?.channel_tracking?.[channel.id]?.mention_count || 0; lines.push(`### ${title}`); lines.push(`- **ID**: ${channel.id}`); lines.push(`- **Slug**: ${slug}`); lines.push(`- **Status**: ${channel.status || "open"}`); if (unreadCount > 0) { lines.push(`- **Unread**: ${unreadCount} messages`); } if (mentionCount > 0) { lines.push(`- **Mentions**: ${mentionCount}`); } if (channel.last_message) { const lastMsg = channel.last_message; lines.push(`- **Last Message**: by @${lastMsg.user?.username || "unknown"} at ${lastMsg.created_at || "unknown time"}`); } lines.push(`- **URL**: ${base}/chat/c/${slug}/${channel.id}`); lines.push(""); } } else { lines.push("## Public Channels"); lines.push("No public channels."); lines.push(""); } // Direct message channels if (dmChannels.length > 0) { lines.push(`## Direct Messages (${dmChannels.length})`); lines.push(""); for (const channel of dmChannels) { const title = channel.title || `DM ${channel.id}`; const unreadCount = tracking?.channel_tracking?.[channel.id]?.unread_count || 0; const mentionCount = tracking?.channel_tracking?.[channel.id]?.mention_count || 0; lines.push(`### ${title}`); lines.push(`- **ID**: ${channel.id}`); if (unreadCount > 0) { lines.push(`- **Unread**: ${unreadCount} messages`); } if (mentionCount > 0) { lines.push(`- **Mentions**: ${mentionCount}`); } if (channel.last_message) { const lastMsg = channel.last_message; lines.push(`- **Last Message**: by @${lastMsg.user?.username || "unknown"} at ${lastMsg.created_at || "unknown time"}`); } lines.push(`- **URL**: ${base}/chat/c/-/${channel.id}`); lines.push(""); } } else { lines.push("## Direct Messages"); lines.push("No direct message channels."); lines.push(""); } return { content: [{ type: "text", text: lines.join("\n") }] }; } catch (e: any) { return { content: [{ type: "text", text: `Failed to list user chat channels: ${e?.message || String(e)}` }], isError: true }; } } );
- src/tools/registry.ts:59-59 (registration)Invokes the registration function for this tool within the overall tools registry.registerListUserChatChannels(server, ctx, { allowWrites: false });
- src/tools/registry.ts:18-18 (registration)Imports the registration function for the discourse_list_user_chat_channels tool.import { registerListUserChatChannels } from "./builtin/list_user_chat_channels.js";