send_audio
Sends an audio file to a WhatsApp chat using a public URL.
Instructions
Send an audio file 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 audio file |
Implementation Reference
- src/tools/messages.ts:69-87 (handler)Handler function for the 'send_audio' tool. It sends an audio file to a WhatsApp chat by making a POST request to the OpenWA API endpoint /sessions/{sessionId}/messages/send-audio with chatId and url (publicly accessible URL of the audio file) in the request body.
server.registerTool( "send_audio", { description: "Send an audio file 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 audio file"), }, }, async ({ sessionId, chatId, url }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/messages/send-audio`, body: { chatId, url }, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/tools/messages.ts:71-77 (schema)Input schema for the 'send_audio' tool: sessionId (string), chatId (string), url (string). All are required (no optional fields).
{ description: "Send an audio file 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 audio file"), }, - src/tools/messages.ts:69-87 (registration)Registration of the 'send_audio' tool via server.registerTool() inside the registerMessageTools() function.
server.registerTool( "send_audio", { description: "Send an audio file 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 audio file"), }, }, async ({ sessionId, chatId, url }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/messages/send-audio`, body: { chatId, url }, }); 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. It constructs the URL from BASE_URL + path, adds API key header, and sends the request.
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; } }