get_profile_picture
Retrieve the profile picture URL of a WhatsApp contact by providing a session ID and contact ID.
Instructions
Get the profile picture URL for a WhatsApp contact
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session ID | |
| contactId | Yes | Contact ID |
Implementation Reference
- src/tools/contacts.ts:50-63 (registration)Registration of the 'get_profile_picture' tool on the MCP server, with input schema (sessionId, contactId) and handler that calls the OpenWA API.
server.registerTool( "get_profile_picture", { description: "Get the profile picture URL for a WhatsApp contact", inputSchema: { sessionId: z.string().describe("Session ID"), contactId: z.string().describe("Contact ID"), }, }, async ({ sessionId, contactId }) => { const data = await openwaClient({ method: "GET", path: `/sessions/${sessionId}/contacts/${contactId}/picture` }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/tools/contacts.ts:59-62 (handler)Handler function that makes a GET request to /sessions/{sessionId}/contacts/{contactId}/picture to retrieve the profile picture URL.
async ({ sessionId, contactId }) => { const data = await openwaClient({ method: "GET", path: `/sessions/${sessionId}/contacts/${contactId}/picture` }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } - src/tools/contacts.ts:52-58 (schema)Input schema definition for get_profile_picture tool: sessionId (string) and contactId (string).
{ description: "Get the profile picture URL for a WhatsApp contact", inputSchema: { sessionId: z.string().describe("Session ID"), contactId: z.string().describe("Contact ID"), }, }, - 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; } } - src/index.ts:8-8 (registration)Import of registerContactTools which registers the get_profile_picture tool.
import { registerContactTools } from "./tools/contacts.js";