block_contact
Blocks a WhatsApp contact using session ID and contact ID to prevent further messages.
Instructions
Block a WhatsApp contact
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session ID | |
| contactId | Yes | Contact ID to block |
Implementation Reference
- src/tools/contacts.ts:65-78 (handler)The handler function for the 'block_contact' tool. It accepts sessionId and contactId inputs, makes a POST request to the OpenWA API endpoint /sessions/{sessionId}/contacts/{contactId}/block, and returns the result as text content.
server.registerTool( "block_contact", { description: "Block a WhatsApp contact", inputSchema: { sessionId: z.string().describe("Session ID"), contactId: z.string().describe("Contact ID to block"), }, }, async ({ sessionId, contactId }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/contacts/${contactId}/block` }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/tools/contacts.ts:67-72 (schema)Input schema for the 'block_contact' tool using Zod validation. Requires sessionId (string) and contactId (string, the contact to block).
{ description: "Block a WhatsApp contact", inputSchema: { sessionId: z.string().describe("Session ID"), contactId: z.string().describe("Contact ID to block"), }, - src/tools/contacts.ts:65-78 (registration)The 'block_contact' tool is registered via server.registerTool() inside the registerContactTools function (line 5). The registration is triggered from src/index.ts line 19 where registerContactTools(server) is called.
server.registerTool( "block_contact", { description: "Block a WhatsApp contact", inputSchema: { sessionId: z.string().describe("Session ID"), contactId: z.string().describe("Contact ID to block"), }, }, async ({ sessionId, contactId }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/contacts/${contactId}/block` }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/client.ts:10-35 (helper)The openwaClient helper function that executes the actual HTTP request. It takes a method, path, and optional body, sends a fetch request to the OpenWA API base URL with the X-API-Key header, and returns the parsed JSON response.
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; } }