whatsapp_send_link
Send WhatsApp messages containing links with previews to contacts or groups using the WSAPI WhatsApp MCP Server. Include optional titles, descriptions, and thumbnails for enhanced link sharing.
Instructions
Send a link message with optional preview to a WhatsApp contact or group.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| to | Yes | Recipient phone number (with @s.whatsapp.net) or group ID (with @g.us) | |
| text | Yes | Message text content (max 4096 characters) | |
| url | Yes | URL to include in the message | |
| title | No | Title for the link preview (max 500 characters) | |
| description | No | Description for the link preview (max 1000 characters) | |
| jpegThumbnail | No | Base64 encoded JPEG thumbnail for the link preview | |
| mentions | No | List of phone numbers to mention in the message | |
| replyTo | No | ID of the message being replied to | |
| isForwarded | No | Whether the message should be marked as forwarded |
Implementation Reference
- src/tools/messaging.ts:230-302 (handler)The complete ToolHandler implementation for the 'whatsapp_send_link' tool. It defines the name, description, input schema (JSON schema), and the async handler function that performs validation using the imported sendLinkMessageSchema and sends the request to the WSAPI endpoint '/messages/link'.export const sendLinkMessage: ToolHandler = { name: 'whatsapp_send_link', description: 'Send a link message with optional preview to a WhatsApp contact or group.', inputSchema: { type: 'object', properties: { to: { type: 'string', description: 'Recipient phone number (with @s.whatsapp.net) or group ID (with @g.us)', }, text: { type: 'string', description: 'Message text content (max 4096 characters)', }, url: { type: 'string', description: 'URL to include in the message', }, title: { type: 'string', description: 'Title for the link preview (max 500 characters)', optional: true, }, description: { type: 'string', description: 'Description for the link preview (max 1000 characters)', optional: true, }, jpegThumbnail: { type: 'string', description: 'Base64 encoded JPEG thumbnail for the link preview', optional: true, }, mentions: { type: 'array', items: { type: 'string' }, description: 'List of phone numbers to mention in the message', 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', 'text', 'url'], }, handler: async (args: any) => { const input = validateInput(sendLinkMessageSchema, args) as SendLinkMessageInput; logger.info('Sending link message', { to: input.to, url: input.url, hasTitle: !!input.title, hasDescription: !!input.description, }); const result = await wsapiClient.post('/messages/link', input); logger.info('Link message sent successfully', { messageId: result.id }); return { success: true, messageId: result.id, message: 'Link message sent successfully', }; }, };
- src/validation/schemas.ts:126-136 (schema)Zod schema (sendLinkMessageSchema) used for strict input validation in the whatsapp_send_link handler. Defines types and constraints for all parameters including chatId, text, url, etc.export const sendLinkMessageSchema = z.object({ to: chatIdSchema, text: z.string().min(1).max(4096), url: urlSchema, title: z.string().max(500).optional(), description: z.string().max(1000).optional(), jpegThumbnail: base64Schema.optional(), mentions: z.array(phoneNumberSchema).optional(), replyTo: messageIdSchema.optional(), isForwarded: z.boolean().optional(), });
- src/server.ts:53-76 (registration)Tool registration logic in MCP server setup. Iterates over tool categories including 'messagingTools' (which exports 'whatsapp_send_link') and registers each tool by name in the server's tools Map for MCP protocol handling.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}`); }); });
- src/tools/messaging.ts:544-555 (registration)Export of messagingTools object aggregating sendLinkMessage (whatsapp_send_link) with other messaging tools, imported and registered in src/server.ts.export const messagingTools = { sendTextMessage, sendImageMessage, sendVideoMessage, sendLinkMessage, sendReactionMessage, editMessage, deleteMessage, markMessageAsRead, starMessage, ...advancedMessagingTools, };
- src/validation/schemas.ts:305-312 (helper)validateInput helper function called in the handler to parse and validate input arguments against sendLinkMessageSchema, throwing detailed errors if invalid.export function validateInput<T>(schema: z.ZodSchema<T>, data: unknown): T { const result = schema.safeParse(data); if (!result.success) { const errors = result.error.errors.map(err => `${err.path.join('.')}: ${err.message}`); throw new Error(`Validation failed: ${errors.join(', ')}`); } return result.data; }