Skip to main content
Glama
wsapi-chat
by wsapi-chat

whatsapp_send_audio

Send audio files to WhatsApp contacts or groups using URLs or base64 encoding. Supports multiple audio formats and includes features for mentions, replies, forwarding, and view-once messages.

Instructions

Send an audio file message to a WhatsApp contact or group. Can send from URL or base64.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
toYesRecipient phone number (with @s.whatsapp.net) or group ID (with @g.us)
audioBase64NoBase64 encoded audio data (alternative to audioURL)
audioURLNoURL of the audio file to send (alternative to audioBase64)
mimeTypeYesMIME type of the audio file
mentionsNoList of phone numbers to mention
replyToNoID of the message being replied to
isForwardedNoWhether the message should be marked as forwarded
viewOnceNoWhether the audio should be sent as view-once

Implementation Reference

  • The ToolHandler object defining the 'whatsapp_send_audio' tool, including its name, description, input schema, and the async handler function that validates input using Zod schema, logs the action, sends the audio via wsapiClient.post('/messages/audio'), and returns a success response with message ID.
    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', }; }, };
  • Zod schema for validating input to the whatsapp_send_audio tool, including fields like to, audioBase64/audioURL (one required), mimeType, mentions, etc., used in the handler via validateInput.
    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/server.ts:53-79 (registration)
    The setupToolHandlers method in the MCP server that registers all tools by iterating over tool categories including messagingTools (which includes whatsapp_send_audio via advancedMessagingTools), adding them to the internal tools Map for execution.
    private setupToolHandlers(): void { logger.info('Setting up tool handlers'); // 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`); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/wsapi-chat/wsapi-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server