get_channel_message_replies
Retrieve replies to a specific message in a Microsoft Teams channel, including content, sender details, and timestamps, using Team ID, Channel ID, and Message ID.
Instructions
Get all replies to a specific message in a channel. Returns reply content, sender information, and timestamps.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| channelId | Yes | Channel ID | |
| limit | No | Number of replies to retrieve (default: 20) | |
| messageId | Yes | Message ID to get replies for | |
| teamId | Yes | Team ID |
Implementation Reference
- src/tools/teams.ts:423-507 (registration)Registers the get_channel_message_replies tool, including inline schema definition and handler function.server.tool( "get_channel_message_replies", "Get all replies to a specific message in a channel. Returns reply content, sender information, and timestamps.", { teamId: z.string().describe("Team ID"), channelId: z.string().describe("Channel ID"), messageId: z.string().describe("Message ID to get replies for"), limit: z .number() .min(1) .max(50) .optional() .default(20) .describe("Number of replies to retrieve (default: 20)"), }, async ({ teamId, channelId, messageId, limit }) => { try { const client = await graphService.getClient(); // Only $top is supported for message replies const queryParams: string[] = [`$top=${limit}`]; const queryString = queryParams.join("&"); const response = (await client .api( `/teams/${teamId}/channels/${channelId}/messages/${messageId}/replies?${queryString}` ) .get()) as GraphApiResponse<ChatMessage>; if (!response?.value?.length) { return { content: [ { type: "text", text: "No replies found for this message.", }, ], }; } const repliesList: MessageSummary[] = response.value.map((reply: ChatMessage) => ({ id: reply.id, content: reply.body?.content, from: reply.from?.user?.displayName, createdDateTime: reply.createdDateTime, importance: reply.importance, })); // Sort replies by creation date (oldest first for replies) repliesList.sort((a, b) => { const dateA = new Date(a.createdDateTime || 0).getTime(); const dateB = new Date(b.createdDateTime || 0).getTime(); return dateA - dateB; }); return { content: [ { type: "text", text: JSON.stringify( { parentMessageId: messageId, totalReplies: repliesList.length, hasMore: !!response["@odata.nextLink"], replies: repliesList, }, null, 2 ), }, ], }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : "Unknown error occurred"; return { content: [ { type: "text", text: `❌ Error: ${errorMessage}`, }, ], }; } } );
- src/tools/teams.ts:426-437 (schema)Zod schema defining input parameters: teamId, channelId, messageId, and optional limit.{ teamId: z.string().describe("Team ID"), channelId: z.string().describe("Channel ID"), messageId: z.string().describe("Message ID to get replies for"), limit: z .number() .min(1) .max(50) .optional() .default(20) .describe("Number of replies to retrieve (default: 20)"), },
- src/tools/teams.ts:438-506 (handler)Handler function that retrieves replies to a message using Microsoft Graph API, processes and sorts them, and returns formatted JSON response.async ({ teamId, channelId, messageId, limit }) => { try { const client = await graphService.getClient(); // Only $top is supported for message replies const queryParams: string[] = [`$top=${limit}`]; const queryString = queryParams.join("&"); const response = (await client .api( `/teams/${teamId}/channels/${channelId}/messages/${messageId}/replies?${queryString}` ) .get()) as GraphApiResponse<ChatMessage>; if (!response?.value?.length) { return { content: [ { type: "text", text: "No replies found for this message.", }, ], }; } const repliesList: MessageSummary[] = response.value.map((reply: ChatMessage) => ({ id: reply.id, content: reply.body?.content, from: reply.from?.user?.displayName, createdDateTime: reply.createdDateTime, importance: reply.importance, })); // Sort replies by creation date (oldest first for replies) repliesList.sort((a, b) => { const dateA = new Date(a.createdDateTime || 0).getTime(); const dateB = new Date(b.createdDateTime || 0).getTime(); return dateA - dateB; }); return { content: [ { type: "text", text: JSON.stringify( { parentMessageId: messageId, totalReplies: repliesList.length, hasMore: !!response["@odata.nextLink"], replies: repliesList, }, null, 2 ), }, ], }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : "Unknown error occurred"; return { content: [ { type: "text", text: `❌ Error: ${errorMessage}`, }, ], }; } }