whatsapp_send_audio
Send audio messages to WhatsApp contacts or groups using file URLs or base64 data. Supports various audio formats, mentions, replies, forwarding, and view-once functionality.
Instructions
Send an audio file message to a WhatsApp contact or group. Can send from URL or base64.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| audioBase64 | No | Base64 encoded audio data (alternative to audioURL) | |
| audioURL | No | URL of the audio file to send (alternative to audioBase64) | |
| isForwarded | No | Whether the message should be marked as forwarded | |
| mentions | No | List of phone numbers to mention | |
| mimeType | Yes | MIME type of the audio file | |
| replyTo | No | ID of the message being replied to | |
| to | Yes | Recipient phone number (with @s.whatsapp.net) or group ID (with @g.us) | |
| viewOnce | No | Whether the audio should be sent as view-once |
Input Schema (JSON Schema)
{
"properties": {
"audioBase64": {
"description": "Base64 encoded audio data (alternative to audioURL)",
"optional": true,
"type": "string"
},
"audioURL": {
"description": "URL of the audio file to send (alternative to audioBase64)",
"optional": true,
"type": "string"
},
"isForwarded": {
"description": "Whether the message should be marked as forwarded",
"optional": true,
"type": "boolean"
},
"mentions": {
"description": "List of phone numbers to mention",
"items": {
"type": "string"
},
"optional": true,
"type": "array"
},
"mimeType": {
"description": "MIME type of the audio file",
"enum": [
"audio/mpeg",
"audio/mp3",
"audio/ogg",
"audio/wav"
],
"type": "string"
},
"replyTo": {
"description": "ID of the message being replied to",
"optional": true,
"type": "string"
},
"to": {
"description": "Recipient phone number (with @s.whatsapp.net) or group ID (with @g.us)",
"type": "string"
},
"viewOnce": {
"description": "Whether the audio should be sent as view-once",
"optional": true,
"type": "boolean"
}
},
"required": [
"to",
"mimeType"
],
"type": "object"
}
Implementation Reference
- src/tools/messaging-advanced.ts:23-91 (handler)Complete ToolHandler implementation for 'whatsapp_send_audio', including inline inputSchema, description, and the core handler logic that validates input and sends the audio via WSAPI.export const sendAudioMessage: ToolHandler = { name: 'whatsapp_send_audio', description: 'Send an audio file message to a WhatsApp contact or group. Can send from URL or base64.', inputSchema: { type: 'object', properties: { to: { type: 'string', description: 'Recipient phone number (with @s.whatsapp.net) or group ID (with @g.us)', }, audioBase64: { type: 'string', description: 'Base64 encoded audio data (alternative to audioURL)', optional: true, }, audioURL: { type: 'string', description: 'URL of the audio file to send (alternative to audioBase64)', optional: true, }, mimeType: { type: 'string', enum: ['audio/mpeg', 'audio/mp3', 'audio/ogg', 'audio/wav'], description: 'MIME type of the audio file', }, mentions: { type: 'array', items: { type: 'string' }, description: 'List of phone numbers to mention', optional: true, }, replyTo: { type: 'string', description: 'ID of the message being replied to', optional: true, }, isForwarded: { type: 'boolean', description: 'Whether the message should be marked as forwarded', optional: true, }, viewOnce: { type: 'boolean', description: 'Whether the audio should be sent as view-once', optional: true, }, }, required: ['to', 'mimeType'], }, handler: async (args: any) => { const input = validateInput(sendAudioMessageSchema, args) as SendAudioMessageInput; logger.info('Sending audio message', { to: input.to, mimeType: input.mimeType, viewOnce: input.viewOnce, }); const result = await wsapiClient.post('/messages/audio', input); logger.info('Audio message sent successfully', { messageId: result.id }); return { success: true, messageId: result.id, message: 'Audio message sent successfully', }; }, };
- src/validation/schemas.ts:48-59 (schema)Zod validation schema (sendAudioMessageSchema) used in the handler for input validation, defining structure and constraints for SendAudioMessageInput.export const sendAudioMessageSchema = z.object({ to: chatIdSchema, audioBase64: base64Schema.optional(), audioURL: urlSchema.optional(), mimeType: z.enum(['audio/mpeg', 'audio/mp3', 'audio/ogg', 'audio/wav']), mentions: z.array(phoneNumberSchema).optional(), replyTo: messageIdSchema.optional(), isForwarded: z.boolean().optional(), viewOnce: z.boolean().optional(), }).refine(data => data.audioBase64 || data.audioURL, { message: "Either audioBase64 or audioURL must be provided", });
- src/tools/messaging.ts:541-555 (registration)Registration of advanced messaging tools (including whatsapp_send_audio via spread) into the messagingTools object.import { advancedMessagingTools } from './messaging-advanced.js'; // Export all messaging tools export const messagingTools = { sendTextMessage, sendImageMessage, sendVideoMessage, sendLinkMessage, sendReactionMessage, editMessage, deleteMessage, markMessageAsRead, starMessage, ...advancedMessagingTools, };
- src/server.ts:57-76 (registration)Final server registration: messagingTools (containing whatsapp_send_audio) is included in toolCategories and registered into the server's tools Map in setupToolHandlers().const toolCategories = [ messagingTools, contactTools, groupTools, chatTools, sessionTools, instanceTools, accountTools, ]; toolCategories.forEach(category => { Object.values(category).forEach(tool => { if (this.tools.has(tool.name)) { logger.warn(`Tool ${tool.name} already registered, skipping`); return; } this.tools.set(tool.name, tool); logger.debug(`Registered tool: ${tool.name}`); }); });
- src/validation/schemas.ts:318-318 (schema)TypeScript type definition for SendAudioMessageInput inferred from the Zod schema.export type SendAudioMessageInput = z.infer<typeof sendAudioMessageSchema>;