demote_member
Demote a group admin to regular participant by providing session ID, group ID, and participant phone ID.
Instructions
Demote a group admin back to regular participant
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session ID | |
| groupId | Yes | Group ID | |
| participantId | Yes | Phone ID of the admin to demote |
Implementation Reference
- src/tools/groups.ts:113-130 (registration)Registration of the 'demote_member' tool with the MCP server, including description, input schema, and handler logic. The handler calls openwaClient to POST to /sessions/{sessionId}/groups/{groupId}/members/{participantId}/demote.
server.registerTool( "demote_member", { description: "Demote a group admin back to regular participant", inputSchema: { sessionId: z.string().describe("Session ID"), groupId: z.string().describe("Group ID"), participantId: z.string().describe("Phone ID of the admin to demote"), }, }, async ({ sessionId, groupId, participantId }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/groups/${groupId}/members/${participantId}/demote`, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/tools/groups.ts:123-129 (handler)Handler function for 'demote_member' that receives sessionId, groupId, and participantId, then makes a POST request to the OpenWA API endpoint to demote the participant from admin.
async ({ sessionId, groupId, participantId }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/groups/${groupId}/members/${participantId}/demote`, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } - src/tools/groups.ts:117-121 (schema)Input schema for 'demote_member' defining three required string parameters: sessionId, groupId, and participantId (the phone ID of the admin to demote).
inputSchema: { sessionId: z.string().describe("Session ID"), groupId: z.string().describe("Group ID"), participantId: z.string().describe("Phone ID of the admin to demote"), }, - src/client.ts:10-35 (helper)The openwaClient helper function that handles HTTP requests to the OpenWA API, used by the demote_member handler.
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; } }