add_group_member
Add a new member to a WhatsApp group by specifying the session, group, and participant phone IDs.
Instructions
Add a participant to a WhatsApp group
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session ID | |
| groupId | Yes | Group ID | |
| participantId | Yes | Phone ID of the participant to add |
Implementation Reference
- src/tools/groups.ts:65-72 (handler)The handler function for 'add_group_member' tool. Sends a POST request to /sessions/{sessionId}/groups/{groupId}/members with the participantId in the body.
async ({ sessionId, groupId, participantId }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/groups/${groupId}/members`, body: { participantId }, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } - src/tools/groups.ts:57-64 (schema)The schema definition for 'add_group_member' tool. Defines description and inputSchema with sessionId (string), groupId (string), and participantId (string).
{ description: "Add a participant to a WhatsApp group", inputSchema: { sessionId: z.string().describe("Session ID"), groupId: z.string().describe("Group ID"), participantId: z.string().describe("Phone ID of the participant to add"), }, }, - src/tools/groups.ts:55-73 (registration)Registration of 'add_group_member' tool via server.registerTool() inside the registerGroupTools function.
server.registerTool( "add_group_member", { description: "Add a participant to a WhatsApp group", inputSchema: { sessionId: z.string().describe("Session ID"), groupId: z.string().describe("Group ID"), participantId: z.string().describe("Phone ID of the participant to add"), }, }, async ({ sessionId, groupId, participantId }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/groups/${groupId}/members`, body: { participantId }, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/index.ts:18-18 (registration)The registerGroupTools(server) call that wires up all group tools including add_group_member.
registerGroupTools(server); - src/client.ts:10-35 (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; } catch { return text as T; } }