Send Template Message
Send WhatsApp template messages from your WhatsApp Business Account.
Params
A unique string. Please see the Keys and Resumability doc for more info.
The id of the phone number you want to send the message from. You can find this in the your WhatsApp Business dashboard. Note, this is not the phone number.
The phone number you want to send the message to.
The name of the template you want to send. Note that these have to be approved by Meta before they can be used. You can find this in the your WhatsApp Business dashboard.
The language code of the template you want to send, e.g. “en_US”. You can find this in the your WhatsApp Business dashboard.
You can customise the message by providing values for variables in the template. There are three sections header, body and buttons. Full WhatsApp documentation
Response
The contact information of who received the message
An array of message ids that were sent
Always whatsapp
Example Workflows
Notify Slack on New GitHub Star
import { Trigger } from "@trigger.dev/sdk";
import { events, sendText } from "@trigger.dev/whatsapp";
new Trigger({
id: "demo",
on: events.messageEvent({
accountId: "<account_id>",
}),
run: async (event, ctx) => {
//send a templated message, with variables
//in this example we have included are the possible variables (mostly commented out)
const templateResponse = await sendTemplate("template-msg", {
fromId: event.metadata.phone_number_id,
to: event.message.from,
//this template must be approved in your WhatsApp Business Account
template: "hello_world",
languageCode: "en_US",
//you only need to include these if your template has variables
parameters: {
//only include this if your header has variables, they can be text, image, video or document
header: [
{
type: "text",
text: "Matt",
},
// {
// type: "image",
// image: {
// link: "https://app.trigger.dev/emails/logo.png",
// caption: "This is a logo",
// },
// },
// {
// type: "video",
// video: {
// link: "https://media.giphy.com/media/5i7umUqAOYYEw/giphy.mp4",
// caption: "This is a fun video",
// },
// },
// {
// type: "document",
// video: {
// link: "https://upload.wikimedia.org/wikipedia/commons/2/20/Re_example.pdf",
// caption: "This is a document",
// },
// },
],
//only include this if the body of your message has variables. They can be text, currency, date_time
body: [
{
type: "text",
text: "Matt",
},
// {
// type: "currency",
// currency: {
// amount_1000: 1000,
// code: "USD",
// fallback_value: "1000 USD",
// },
// },
// {
// type: "date_time",
// date_time: {
// fallback_value: "2021-01-01",
// },
// }
],
//only include this if the buttons of your message have variables. They can be quick_reply or call_to_action
buttons: [
{
sub_type: "quick_reply",
parameters: [
{
type: "payload",
payload: "buy",
},
// {
// type: "text",
// text: "Buy now!",
// },
],
},
{
sub_type: "call_to_action",
parameters: [
{
type: "text",
text: "Buy now!",
},
],
},
],
},
});
},
}).listen();