get_contact
Retrieve detailed information for a specific WhatsApp contact using session and contact IDs.
Instructions
Get detailed info for a specific WhatsApp contact
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session ID | |
| contactId | Yes | Contact ID to look up |
Implementation Reference
- src/tools/contacts.ts:20-33 (handler)Handler for 'get_contact' tool - makes GET request to /sessions/{sessionId}/contacts/{contactId} and returns the contact details as text content.
server.registerTool( "get_contact", { description: "Get detailed info for a specific WhatsApp contact", inputSchema: { sessionId: z.string().describe("Session ID"), contactId: z.string().describe("Contact ID to look up"), }, }, async ({ sessionId, contactId }) => { const data = await openwaClient({ method: "GET", path: `/sessions/${sessionId}/contacts/${contactId}` }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/tools/contacts.ts:22-28 (schema)Input schema for 'get_contact' tool - requires sessionId (string) and contactId (string).
{ description: "Get detailed info for a specific WhatsApp contact", inputSchema: { sessionId: z.string().describe("Session ID"), contactId: z.string().describe("Contact ID to look up"), }, }, - src/tools/contacts.ts:20-33 (registration)Registration of 'get_contact' tool via server.registerTool() inside registerContactTools().
server.registerTool( "get_contact", { description: "Get detailed info for a specific WhatsApp contact", inputSchema: { sessionId: z.string().describe("Session ID"), contactId: z.string().describe("Contact ID to look up"), }, }, async ({ sessionId, contactId }) => { const data = await openwaClient({ method: "GET", path: `/sessions/${sessionId}/contacts/${contactId}` }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/index.ts:19-19 (registration)Top-level registration call that triggers the tool registration.
registerContactTools(server); - src/client.ts:10-35 (helper)Helper function 'openwaClient' 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; } }