send_template
Send pre-approved WhatsApp Business template messages with dynamic variables for order confirmations, appointment reminders, and promotional communications.
Instructions
Send a message using a template
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| instanceName | Yes | Instance name | |
| number | Yes | Recipient phone number | |
| templateId | Yes | Template ID | |
| variables | Yes | Variables to replace in template |
Implementation Reference
- src/index.ts:766-808 (handler)The handler function that implements the core logic for the 'send_template' tool. Retrieves the template, validates and processes variables, then sends the message via appropriate API calls.private async handleSendTemplate(args: any) { const template = templateService.getTemplate(args.templateId); if (!template) { throw new Error(`Template ${args.templateId} not found`); } // Validate variables const missingVars = templateService.validateVariables(template, args.variables); if (missingVars.length > 0) { throw new Error(`Missing variables: ${missingVars.join(', ')}`); } // Process template const processedContent = templateService.processTemplate(template, args.variables); // Send message based on content type let result; if (processedContent.text) { result = await evolutionAPI.sendText(args.instanceName, { number: args.number, text: processedContent.text }); } else if (processedContent.listMessage) { result = await evolutionAPI.sendList(args.instanceName, { number: args.number, ...processedContent.listMessage }); } else if (processedContent.buttons) { result = await evolutionAPI.sendButtons(args.instanceName, { number: args.number, buttons: processedContent.buttons }); } return { content: [ { type: 'text', text: JSON.stringify(result, null, 2) } ] }; }
- src/index.ts:247-263 (schema)The tool definition including name, description, and input schema for 'send_template', used for tool listing and validation.{ name: 'send_template', description: 'Send a message using a template', inputSchema: { type: 'object', properties: { instanceName: { type: 'string', description: 'Instance name' }, number: { type: 'string', description: 'Recipient phone number' }, templateId: { type: 'string', description: 'Template ID' }, variables: { type: 'object', description: 'Variables to replace in template' } }, required: ['instanceName', 'number', 'templateId', 'variables'] } },
- src/index.ts:514-515 (registration)The dispatch case in the CallToolRequest handler that routes 'send_template' calls to the specific handler method.case 'send_template': return await this.handleSendTemplate(args);