get_groups
Lists all WhatsApp groups visible to a given session. Use a session ID to retrieve the group list.
Instructions
List all WhatsApp groups visible to the given session
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session ID |
Implementation Reference
- src/tools/groups.ts:6-18 (registration)Registration of the 'get_groups' tool via server.registerTool(), with input schema and handler logic.
server.registerTool( "get_groups", { description: "List all WhatsApp groups visible to the given session", inputSchema: { sessionId: z.string().describe("Session ID"), }, }, async ({ sessionId }) => { const data = await openwaClient({ method: "GET", path: `/sessions/${sessionId}/groups` }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/tools/groups.ts:14-17 (handler)Handler function for 'get_groups' that makes a GET request to the OpenWA API and returns the JSON result.
async ({ sessionId }) => { const data = await openwaClient({ method: "GET", path: `/sessions/${sessionId}/groups` }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } - src/tools/groups.ts:10-12 (schema)Input schema for 'get_groups': requires a sessionId string.
inputSchema: { sessionId: z.string().describe("Session ID"), }, - src/client.ts:10-35 (helper)The openwaClient helper function used by the 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; } } - src/index.ts:7-7 (registration)Import of the registerGroupTools function which registers 'get_groups' along with other group tools.
import { registerGroupTools } from "./tools/groups.js";