send_image
Deliver an image to a WhatsApp chat using a publicly accessible URL and optional caption.
Instructions
Send an image to a WhatsApp chat by providing a publicly accessible URL
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session ID to send from | |
| chatId | Yes | Target chat ID | |
| url | Yes | Public URL of the image | |
| caption | No | Optional caption for the image |
Implementation Reference
- src/tools/messages.ts:37-44 (handler)The handler function for the 'send_image' tool. It sends an image to a WhatsApp chat by making a POST request to the OpenWA API with sessionId, chatId, url, and optional caption.
async ({ sessionId, chatId, url, caption }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/messages/send-image`, body: { chatId, url, caption }, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } - src/tools/messages.ts:28-35 (schema)The input schema for 'send_image', defining required fields (sessionId, chatId, url) and optional caption.
{ description: "Send an image to a WhatsApp chat by providing a publicly accessible URL", inputSchema: { sessionId: z.string().describe("Session ID to send from"), chatId: z.string().describe("Target chat ID"), url: z.string().describe("Public URL of the image"), caption: z.string().optional().describe("Optional caption for the image"), }, - src/tools/messages.ts:26-45 (registration)Tool registration for 'send_image' via server.registerTool within registerMessageTools function.
server.registerTool( "send_image", { description: "Send an image to a WhatsApp chat by providing a publicly accessible URL", inputSchema: { sessionId: z.string().describe("Session ID to send from"), chatId: z.string().describe("Target chat ID"), url: z.string().describe("Public URL of the image"), caption: z.string().optional().describe("Optional caption for the image"), }, }, async ({ sessionId, chatId, url, caption }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/messages/send-image`, body: { chatId, url, caption }, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - 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; } }