get_channel_messages
Retrieve recent messages from a specific Mattermost channel with author details and pagination support for efficient message management.
Instructions
특정 채널의 최근 메시지들을 가져옵니다. 결과에는 자동으로 작성자의 이름(user_name)과 username이 포함됩니다.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| channel_id | Yes | 채널 ID | |
| page | No | 페이지 번호 (기본값: 0) | |
| per_page | No | 페이지당 메시지 수 (기본값: 60) |
Implementation Reference
- src/index.ts:555-592 (handler)Main tool handler that extracts parameters, fetches channel messages using the client, enriches them with user information using getUsersInfo, formats timestamps, and returns a JSON response with the processed posts.case "get_channel_messages": { const channelId = args.channel_id as string; const page = (args.page as number) || 0; const perPage = (args.per_page as number) || 60; const messages = await client.getChannelMessages(channelId, page, perPage); // 고유한 user_id 추출 및 사용자 정보 조회 const uniqueUserIds = [...new Set(messages.order?.map((postId: string) => messages.posts[postId].user_id) || [])]; const userMap = await client.getUsersInfo(uniqueUserIds); const posts = messages.order?.map((postId: string) => { const post = messages.posts[postId]; const createTime = formatTimestamp(post.create_at); const userInfo = userMap.get(post.user_id); return { id: post.id, message: post.message, user_id: post.user_id, username: userInfo?.username || "unknown", user_name: userInfo?.name || "Unknown User", create_at: createTime, }; }) || []; return { content: [ { type: "text", text: JSON.stringify({ channel_id: channelId, posts: posts, }, null, 2), }, ], }; }
- src/index.ts:282-301 (schema)Input schema defining parameters for the get_channel_messages tool: channel_id (required), page (optional, default 0), per_page (optional, default 60).inputSchema: { type: "object", properties: { channel_id: { type: "string", description: "채널 ID", }, page: { type: "number", description: "페이지 번호 (기본값: 0)", default: 0, }, per_page: { type: "number", description: "페이지당 메시지 수 (기본값: 60)", default: 60, }, }, required: ["channel_id"], },
- src/index.ts:279-302 (registration)Registration of the get_channel_messages tool in the list of available tools, including name, description, and input schema.{ name: "get_channel_messages", description: "특정 채널의 최근 메시지들을 가져옵니다. 결과에는 자동으로 작성자의 이름(user_name)과 username이 포함됩니다.", inputSchema: { type: "object", properties: { channel_id: { type: "string", description: "채널 ID", }, page: { type: "number", description: "페이지 번호 (기본값: 0)", default: 0, }, per_page: { type: "number", description: "페이지당 메시지 수 (기본값: 60)", default: 60, }, }, required: ["channel_id"], }, },
- src/index.ts:159-161 (helper)Helper method in MattermostClient class that performs the actual API request to fetch messages from a specific channel in Mattermost.async getChannelMessages(channelId: string, page: number = 0, perPage: number = 60): Promise<MattermostPostsResult> { return await this.request(`/channels/${channelId}/posts?page=${page}&per_page=${perPage}`) as MattermostPostsResult; }