send_template_message
Send pre-approved WhatsApp Business template messages to initiate conversations outside the 24-hour window using Meta-approved templates with customizable variables.
Instructions
Send a pre-approved template message. Required for initiating conversations outside the 24-hour window. Templates must be approved by Meta before use.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| to | Yes | Recipient phone number in international format | |
| template_name | Yes | Name of the approved template | |
| language | No | Template language code (e.g., pt_BR, en_US) | pt_BR |
| components | No | Template components with variable values (header, body, button params) |
Implementation Reference
- src/whatsapp-client.ts:130-146 (handler)Actual implementation of the WhatsApp template message sending logic.
async sendTemplateMessage( to: string, templateName: string, language: string, components?: unknown[] ) { return this.request(`/${this.config.phoneNumberId}/messages`, "POST", { messaging_product: "whatsapp", to, type: "template", template: { name: templateName, language: { code: language }, ...(components ? { components } : {}), }, }); } - src/index.ts:140-159 (registration)MCP tool registration for "send_template_message" which calls the handler in WhatsAppClient.
server.tool( "send_template_message", "Send a pre-approved template message. Required for initiating conversations outside the 24-hour window. Templates must be approved by Meta before use.", { to: z.string().describe("Recipient phone number in international format"), template_name: z.string().describe("Name of the approved template"), language: z.string().default("pt_BR").describe("Template language code (e.g., pt_BR, en_US)"), components: z .array(z.record(z.string(), z.unknown())) .optional() .describe("Template components with variable values (header, body, button params)"), }, async ({ to, template_name, language, components }) => executeWithHooks( "send_template_message", { to, template_name, language, components }, config, () => wa.sendTemplateMessage(to, template_name, language, components) ) );