leave_group
Leaves a specific WhatsApp group when provided with the session ID and group ID.
Instructions
Leave a WhatsApp group
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session ID | |
| groupId | Yes | Group ID to leave |
Implementation Reference
- src/tools/groups.ts:161-167 (handler)The handler function for the 'leave_group' tool. Calls openwaClient with POST method to `/sessions/{sessionId}/groups/{groupId}/leave`.
async ({ sessionId, groupId }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/groups/${groupId}/leave`, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } - src/tools/groups.ts:152-160 (schema)The tool registration and input schema for 'leave_group'. Requires sessionId (string) and groupId (string) parameters.
server.registerTool( "leave_group", { description: "Leave a WhatsApp group", inputSchema: { sessionId: z.string().describe("Session ID"), groupId: z.string().describe("Group ID to leave"), }, }, - src/index.ts:18-18 (registration)Registration of all group tools (including leave_group) via registerGroupTools(server) call in the main entry point.
registerGroupTools(server); - src/tools/groups.ts:152-168 (registration)The full server.registerTool call for 'leave_group', which both registers and defines the tool.
server.registerTool( "leave_group", { description: "Leave a WhatsApp group", inputSchema: { sessionId: z.string().describe("Session ID"), groupId: z.string().describe("Group ID to leave"), }, }, async ({ sessionId, groupId }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/groups/${groupId}/leave`, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/client.ts:10-31 (helper)The openwaClient helper function used by the handler to make HTTP requests to the OpenWA 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;