get_messages
Retrieve message history from a WhatsApp chat by providing session ID and chat ID.
Instructions
Retrieve message history from a specific WhatsApp chat
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session ID | |
| chatId | Yes | Chat ID to fetch messages from |
Implementation Reference
- src/tools/messages.ts:140-147 (handler)Handler function for get_messages tool. Sends a GET request to the OpenWA API to retrieve message history from a specific WhatsApp chat.
async ({ sessionId, chatId }) => { const data = await openwaClient({ method: "GET", path: `/sessions/${sessionId}/chats/${chatId}/messages`, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/tools/messages.ts:133-138 (schema)Schema definition for get_messages tool: expects sessionId (string) and chatId (string).
{ description: "Retrieve message history from a specific WhatsApp chat", inputSchema: { sessionId: z.string().describe("Session ID"), chatId: z.string().describe("Chat ID to fetch messages from"), }, - src/tools/messages.ts:131-147 (registration)Registration of the get_messages tool via server.registerTool() inside registerMessageTools().
server.registerTool( "get_messages", { description: "Retrieve message history from a specific WhatsApp chat", inputSchema: { sessionId: z.string().describe("Session ID"), chatId: z.string().describe("Chat ID to fetch messages from"), }, }, async ({ sessionId, chatId }) => { const data = await openwaClient({ method: "GET", path: `/sessions/${sessionId}/chats/${chatId}/messages`, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/client.ts:10-35 (helper)Helper function openwaClient used by get_messages handler to make HTTP requests to the OpenWA backend API.
export async function openwaClient<T = unknown>(opts: RequestOptions): Promise<T> { const url = `${BASE_URL}${opts.path}`; const headers: Record<string, string> = { "Content-Type": "application/json", "X-API-Key": API_KEY, }; const res = await fetch(url, { method: opts.method, headers, body: opts.body ? JSON.stringify(opts.body) : undefined, }); const text = await res.text(); if (!res.ok) { throw new Error(`OpenWA API ${res.status}: ${text}`); } try { return JSON.parse(text) as T; } catch { return text as T; } }