whatsapp_send_document
Send document files to WhatsApp contacts or groups using URLs or base64 encoding. Specify recipients, file names, and optional captions or mentions.
Instructions
Send a document file to a WhatsApp contact or group. Can send from URL or base64.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| to | Yes | Recipient phone number (with @s.whatsapp.net) or group ID (with @g.us) | |
| documentBase64 | No | Base64 encoded document data (alternative to documentURL) | |
| documentURL | No | URL of the document to send (alternative to documentBase64) | |
| fileName | Yes | Name of the document file (max 255 characters) | |
| caption | No | Caption for the document (max 1024 characters) | |
| mentions | No | List of phone numbers to mention in the caption | |
| replyTo | No | ID of the message being replied to | |
| isForwarded | No | Whether the message should be marked as forwarded |
Implementation Reference
- src/tools/messaging-advanced.ts:207-226 (handler)The handler function that validates the input using sendDocumentMessageSchema and sends the document message via the WSAPI client.handler: async (args: any) => { const input = validateInput(sendDocumentMessageSchema, args) as SendDocumentMessageInput; logger.info('Sending document message', { to: input.to, fileName: input.fileName, hasCaption: !!input.caption, }); const result = await wsapiClient.post('/messages/document', input); logger.info('Document message sent successfully', { messageId: result.id }); return { success: true, messageId: result.id, message: 'Document message sent successfully', }; }, };
- src/validation/schemas.ts:73-84 (schema)Zod schema for validating the input parameters of the whatsapp_send_document tool.export const sendDocumentMessageSchema = z.object({ to: chatIdSchema, documentBase64: base64Schema.optional(), documentURL: urlSchema.optional(), fileName: z.string().min(1).max(255), caption: z.string().max(1024).optional(), mentions: z.array(phoneNumberSchema).optional(), replyTo: messageIdSchema.optional(), isForwarded: z.boolean().optional(), }).refine(data => data.documentBase64 || data.documentURL, { message: "Either documentBase64 or documentURL must be provided", });
- src/server.ts:67-77 (registration)Registration logic in the MCP server that adds all tools, including whatsapp_send_document, to the server's tool map by name.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/tools/messaging.ts:554-554 (registration)Spreads the advancedMessagingTools object (containing whatsapp_send_document) into the main messagingTools export used by the server....advancedMessagingTools,
- Descriptive inputSchema provided to the MCP protocol for the tool's expected inputs.inputSchema: { type: 'object', properties: { to: { type: 'string', description: 'Recipient phone number (with @s.whatsapp.net) or group ID (with @g.us)', }, documentBase64: { type: 'string', description: 'Base64 encoded document data (alternative to documentURL)', optional: true, }, documentURL: { type: 'string', description: 'URL of the document to send (alternative to documentBase64)', optional: true, }, fileName: { type: 'string', description: 'Name of the document file (max 255 characters)', }, caption: { type: 'string', description: 'Caption for the document (max 1024 characters)', optional: true, }, mentions: { type: 'array', items: { type: 'string' }, description: 'List of phone numbers to mention in the caption', 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, }, }, required: ['to', 'fileName'], },