ig_get_messages
Retrieve direct messages from a specific Instagram conversation using conversation ID, with options for pagination and message limits.
Instructions
Get messages in a specific DM conversation.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| conversation_id | Yes | Conversation ID | |
| limit | No | Number of messages | |
| after | No | Pagination cursor |
Implementation Reference
- src/tools/instagram/messaging.ts:33-54 (handler)Implementation of the ig_get_messages tool handler, including schema validation and the API call logic.
server.tool( "ig_get_messages", "Get messages in a specific DM conversation.", { conversation_id: z.string().describe("Conversation ID"), limit: z.number().optional().describe("Number of messages"), after: z.string().optional().describe("Pagination cursor"), }, async ({ conversation_id, limit, after }) => { try { const params: Record<string, unknown> = { fields: "id,message,from,created_time,attachments", }; if (limit) params.limit = limit; if (after) params.after = after; const { data, rateLimit } = await client.ig("GET", `/${conversation_id}/messages`, params); return { content: [{ type: "text", text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Get messages failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } );