whatsapp_send_voice
Send voice messages to WhatsApp contacts or groups using either a URL or base64-encoded audio data. Supports mentions, replies, forwarding, and view-once delivery options.
Instructions
Send a voice message (PTT) to a WhatsApp contact or group. Can send from URL or base64.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| isForwarded | No | Whether the message should be marked as forwarded | |
| mentions | No | List of phone numbers to mention | |
| 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 voice message should be sent as view-once | |
| voiceBase64 | No | Base64 encoded voice data (alternative to voiceURL) | |
| voiceURL | No | URL of the voice file to send (alternative to voiceBase64) |
Input Schema (JSON Schema)
{
"properties": {
"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"
},
"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 voice message should be sent as view-once",
"optional": true,
"type": "boolean"
},
"voiceBase64": {
"description": "Base64 encoded voice data (alternative to voiceURL)",
"optional": true,
"type": "string"
},
"voiceURL": {
"description": "URL of the voice file to send (alternative to voiceBase64)",
"optional": true,
"type": "string"
}
},
"required": [
"to"
],
"type": "object"
}
Implementation Reference
- src/tools/messaging-advanced.ts:94-156 (handler)Complete ToolHandler implementation for whatsapp_send_voice tool. Validates input using sendVoiceMessageSchema and calls WSAPI /messages/voice endpoint.export const sendVoiceMessage: ToolHandler = { name: 'whatsapp_send_voice', description: 'Send a voice message (PTT) 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)', }, voiceBase64: { type: 'string', description: 'Base64 encoded voice data (alternative to voiceURL)', optional: true, }, voiceURL: { type: 'string', description: 'URL of the voice file to send (alternative to voiceBase64)', optional: true, }, 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 voice message should be sent as view-once', optional: true, }, }, required: ['to'], }, handler: async (args: any) => { const input = validateInput(sendVoiceMessageSchema, args) as SendVoiceMessageInput; logger.info('Sending voice message', { to: input.to, viewOnce: input.viewOnce, }); const result = await wsapiClient.post('/messages/voice', input); logger.info('Voice message sent successfully', { messageId: result.id }); return { success: true, messageId: result.id, message: 'Voice message sent successfully', }; }, };
- src/validation/schemas.ts:61-71 (schema)Zod validation schema for SendVoiceMessageInput used in the tool handler.export const sendVoiceMessageSchema = z.object({ to: chatIdSchema, voiceBase64: base64Schema.optional(), voiceURL: urlSchema.optional(), mentions: z.array(phoneNumberSchema).optional(), replyTo: messageIdSchema.optional(), isForwarded: z.boolean().optional(), viewOnce: z.boolean().optional(), }).refine(data => data.voiceBase64 || data.voiceURL, { message: "Either voiceBase64 or voiceURL must be provided", });
- src/server.ts:56-79 (registration)Tool registration logic in MCP server that includes messagingTools (which contains whatsapp_send_voice via advancedMessagingTools).// Register all tool categories 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}`); }); }); logger.info(`Registered ${this.tools.size} tools`); }
- src/tools/messaging.ts:541-555 (registration)Collection of messaging tools including advancedMessagingTools which exports sendVoiceMessage (whatsapp_send_voice).import { advancedMessagingTools } from './messaging-advanced.js'; // Export all messaging tools export const messagingTools = { sendTextMessage, sendImageMessage, sendVideoMessage, sendLinkMessage, sendReactionMessage, editMessage, deleteMessage, markMessageAsRead, starMessage, ...advancedMessagingTools, };
- src/validation/schemas.ts:319-319 (schema)TypeScript type definition for SendVoiceMessageInput derived from the Zod schema.export type SendVoiceMessageInput = z.infer<typeof sendVoiceMessageSchema>;