waha_send_audio
Send audio or voice messages to WhatsApp chats using URL links or base64 encoded data. Specify chat ID and MIME type to deliver audio files directly through the WAHA MCP Server.
Instructions
Send audio/voice messages to a WhatsApp chat. Supports URL or base64 data.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chatId | Yes | Chat ID (format: number@c.us) | |
| fileUrl | No | URL of the audio file to send (use either fileUrl or fileData, not both) | |
| fileData | No | Base64 encoded audio data (use either fileUrl or fileData, not both) | |
| mimetype | Yes | MIME type of the audio file (e.g., 'audio/ogg', 'audio/mpeg') | |
| filename | No | Optional filename for the audio | |
| replyTo | No | Optional message ID to reply to |
Implementation Reference
- src/index.ts:1666-1717 (handler)Main execution handler for waha_send_audio tool. Validates parameters, prepares file object from URL or base64 data, calls WAHA client sendAudio method, and returns formatted success response with message ID and timestamp.private async handleSendAudio(args: any) { const chatId = args.chatId; const fileUrl = args.fileUrl; const fileData = args.fileData; const mimetype = args.mimetype; const filename = args.filename; const replyTo = args.replyTo; if (!chatId) { throw new Error("chatId is required"); } if (!mimetype) { throw new Error("mimetype is required"); } if (!fileUrl && !fileData) { throw new Error("Either fileUrl or fileData is required"); } const file: any = { mimetype, filename, }; if (fileUrl) { file.url = fileUrl; } else { file.data = fileData; } const response = await this.wahaClient.sendAudio({ chatId, file, reply_to: replyTo, }); const formattedResponse = formatSendMessageSuccess( chatId, response.id, response.timestamp ); return { content: [ { type: "text", text: `${formattedResponse}\nMedia type: audio/voice`, }, ], }; }
- src/index.ts:389-422 (registration)Tool registration in ListTools handler, including name, description, and complete input schema definition for parameter validation.{ name: "waha_send_audio", description: "Send audio/voice messages to a WhatsApp chat. Supports URL or base64 data.", inputSchema: { type: "object", properties: { chatId: { type: "string", description: "Chat ID (format: number@c.us)", }, fileUrl: { type: "string", description: "URL of the audio file to send (use either fileUrl or fileData, not both)", }, fileData: { type: "string", description: "Base64 encoded audio data (use either fileUrl or fileData, not both)", }, mimetype: { type: "string", description: "MIME type of the audio file (e.g., 'audio/ogg', 'audio/mpeg')", }, filename: { type: "string", description: "Optional filename for the audio", }, replyTo: { type: "string", description: "Optional message ID to reply to", }, }, required: ["chatId", "mimetype"], }, },
- src/index.ts:392-421 (schema)Input schema for waha_send_audio tool defining structure, types, descriptions, and required fields for validation.inputSchema: { type: "object", properties: { chatId: { type: "string", description: "Chat ID (format: number@c.us)", }, fileUrl: { type: "string", description: "URL of the audio file to send (use either fileUrl or fileData, not both)", }, fileData: { type: "string", description: "Base64 encoded audio data (use either fileUrl or fileData, not both)", }, mimetype: { type: "string", description: "MIME type of the audio file (e.g., 'audio/ogg', 'audio/mpeg')", }, filename: { type: "string", description: "Optional filename for the audio", }, replyTo: { type: "string", description: "Optional message ID to reply to", }, }, required: ["chatId", "mimetype"], },
- src/client/waha-client.ts:580-611 (helper)Core WAHA client helper method that performs the actual HTTP POST to /api/sendVoice endpoint to send audio message.async sendAudio(params: { chatId: string; file: { mimetype: string; url?: string; data?: string; // base64 filename?: string; }; reply_to?: string; }): Promise<SendMessageResponse> { const { chatId, file, reply_to } = params; if (!chatId) { throw new WAHAError("chatId is required"); } if (!file || (!file.url && !file.data)) { throw new WAHAError("file with url or data is required"); } const body = { chatId, file, session: this.session, reply_to, }; return this.request<SendMessageResponse>("/api/sendVoice", { method: "POST", body: JSON.stringify(body), }); }
- src/tools/formatters.ts:107-109 (helper)Utility function used by the handler to format the success response text.export function formatSendMessageSuccess(chatId: string, messageId: string, timestamp: number): string { return `Message sent successfully!\nChat: ${chatId}\nMessage ID: ${messageId}\nTime: ${formatTimestamp(timestamp)}`; }