whatsapp_send_link
Send WhatsApp messages containing links with previews to contacts or groups. Include text content, URL, and optional preview elements like title, description, and thumbnail for enhanced link sharing.
Instructions
Send a link message with optional preview to a WhatsApp contact or group.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| description | No | Description for the link preview (max 1000 characters) | |
| isForwarded | No | Whether the message should be marked as forwarded | |
| 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 | |
| text | Yes | Message text content (max 4096 characters) | |
| title | No | Title for the link preview (max 500 characters) | |
| to | Yes | Recipient phone number (with @s.whatsapp.net) or group ID (with @g.us) | |
| url | Yes | URL to include in the message |
Input Schema (JSON Schema)
{
"properties": {
"description": {
"description": "Description for the link preview (max 1000 characters)",
"optional": true,
"type": "string"
},
"isForwarded": {
"description": "Whether the message should be marked as forwarded",
"optional": true,
"type": "boolean"
},
"jpegThumbnail": {
"description": "Base64 encoded JPEG thumbnail for the link preview",
"optional": true,
"type": "string"
},
"mentions": {
"description": "List of phone numbers to mention in the message",
"items": {
"type": "string"
},
"optional": true,
"type": "array"
},
"replyTo": {
"description": "ID of the message being replied to",
"optional": true,
"type": "string"
},
"text": {
"description": "Message text content (max 4096 characters)",
"type": "string"
},
"title": {
"description": "Title for the link preview (max 500 characters)",
"optional": true,
"type": "string"
},
"to": {
"description": "Recipient phone number (with @s.whatsapp.net) or group ID (with @g.us)",
"type": "string"
},
"url": {
"description": "URL to include in the message",
"type": "string"
}
},
"required": [
"to",
"text",
"url"
],
"type": "object"
}
Implementation Reference
- src/tools/messaging.ts:230-302 (handler)The complete ToolHandler implementation for the 'whatsapp_send_link' tool. Defines the name, description, input schema for MCP, and the async handler function that validates input using Zod schema and sends the link message via the WSAPI client.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 validation schema (sendLinkMessageSchema) used in the handler for input validation, along with the inferred SendLinkMessageInput type.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-79 (registration)Tool registration logic in the MCP server. Imports messagingTools (which includes whatsapp_send_link) and registers all tools from various categories into the server's tools Map.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`); }
- src/tools/messaging.ts:544-555 (registration)Export of messagingTools object that bundles sendLinkMessage with other messaging tools for registration in the MCP server.export const messagingTools = { sendTextMessage, sendImageMessage, sendVideoMessage, sendLinkMessage, sendReactionMessage, editMessage, deleteMessage, markMessageAsRead, starMessage, ...advancedMessagingTools, };
- src/validation/schemas.ts:305-312 (helper)validateInput helper function used in the handler to validate arguments against sendLinkMessageSchema.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; }