send_file
Send a file to a WhatsApp chat by providing a public URL, filename, and optional caption.
Instructions
Send a file/document 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 file | |
| filename | Yes | Filename to display in the chat | |
| caption | No | Optional caption for the file |
Implementation Reference
- src/tools/messages.ts:47-67 (handler)The handler function that executes the 'send_file' tool logic. It extracts sessionId, chatId, url, filename, and optional caption from the input, then makes a POST request to the OpenWA API endpoint /sessions/{sessionId}/messages/send-file with the body containing chatId, url, filename, and caption. It returns the JSON response as text content.
server.registerTool( "send_file", { description: "Send a file/document 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 file"), filename: z.string().describe("Filename to display in the chat"), caption: z.string().optional().describe("Optional caption for the file"), }, }, async ({ sessionId, chatId, url, filename, caption }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/messages/send-file`, body: { chatId, url, filename, caption }, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/tools/messages.ts:49-57 (schema)Input schema for the 'send_file' tool: sessionId (string), chatId (string), url (string, public URL of the file), filename (string, filename to display in the chat), and optional caption (string).
{ description: "Send a file/document 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 file"), filename: z.string().describe("Filename to display in the chat"), caption: z.string().optional().describe("Optional caption for the file"), }, - src/tools/messages.ts:47-67 (registration)The 'send_file' tool is registered via server.registerTool('send_file', ...) inside the registerMessageTools function in src/tools/messages.ts. This function is called from src/index.ts (line 16) during server initialization.
server.registerTool( "send_file", { description: "Send a file/document 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 file"), filename: z.string().describe("Filename to display in the chat"), caption: z.string().optional().describe("Optional caption for the file"), }, }, async ({ sessionId, chatId, url, filename, caption }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/messages/send-file`, body: { chatId, url, filename, caption }, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/client.ts:10-35 (helper)The openwaClient helper function is the underlying HTTP client used by the send_file handler. It takes method, path, and body parameters, constructs a URL using the OPENWA_BASE_URL env variable (default http://localhost:2785/api), includes the X-API-Key header, and performs the fetch request. The handler calls it with method: 'POST', path: `/sessions/${sessionId}/messages/send-file`, and body containing chatId, url, filename, caption.
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; } }