send_group_message
Send a text message to a WhatsApp group by providing session ID, group ID, and text content.
Instructions
Send a text message directly to a WhatsApp group
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session ID | |
| groupId | Yes | Group ID | |
| text | Yes | Message text content |
Implementation Reference
- src/tools/groups.ts:132-150 (handler)The send_group_message tool handler: sends a text message to a WhatsApp group via POST to /sessions/{sessionId}/groups/{groupId}/messages.
server.registerTool( "send_group_message", { description: "Send a text message directly to a WhatsApp group", inputSchema: { sessionId: z.string().describe("Session ID"), groupId: z.string().describe("Group ID"), text: z.string().describe("Message text content"), }, }, async ({ sessionId, groupId, text }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/groups/${groupId}/messages`, body: { text }, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/tools/groups.ts:136-140 (schema)Input schema for send_group_message: requires sessionId (string), groupId (string), and text (string).
inputSchema: { sessionId: z.string().describe("Session ID"), groupId: z.string().describe("Group ID"), text: z.string().describe("Message text content"), }, - src/tools/groups.ts:132-151 (registration)Registration of send_group_message tool on the MCP server, done inside registerGroupTools().
server.registerTool( "send_group_message", { description: "Send a text message directly to a WhatsApp group", inputSchema: { sessionId: z.string().describe("Session ID"), groupId: z.string().describe("Group ID"), text: z.string().describe("Message text content"), }, }, async ({ sessionId, groupId, text }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/groups/${groupId}/messages`, body: { text }, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/index.ts:18-18 (registration)Registration call: registerGroupTools is invoked from the main entry point, which adds send_group_message to the MCP server.
registerGroupTools(server); - src/client.ts:10-35 (helper)The openwaClient helper function used by send_group_message to make the POST request 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; } }