Skip to contentSkip to navigationSkip to topbar
Page toolsOn this page
Looking for more inspiration?Visit the

whatsapp/authentication


The whatsapp/authentication content type allows companies to deliver a WhatsApp-approved one-time password button. Unlike other templates, the body is preset by WhatsApp. Some modifications can be made by specifying certain parameters. However, custom authentication templates aren't allowed.

(information)

Info

  • When sending whatsapp/authentication content templates, a single variable must be defined at send time and set to the one-time passcode.
  • whatsapp/authentication content templates must be approved by WhatsApp before they can be sent to customers.

Supported channels

supported-channels page anchor

WhatsApp


WhatsApp message with verification code 1234, expires in 40 minutes.

ParameterTypeRequiredVariable supportDescription
add_security_recommendationBooleanNoNoOptional field to add the message "For your security, do not share this code" or the translated language's equivalent. This field defaults to TRUE.
code_expiration_minutesintegerNoNoThe amount of time you want to inform the customer that the one-time passcode is available for.
Adds a footer message stating "This code expires in x minutes," where x is the number specified.
Only whole numbers from 1–90 are allowed.
actionsarrayYesNoButtons that recipients can tap on to act on the message.

actions properties

actions-properties page anchor

To learn more about the actions parameter, see common components.

PropertyParameters
COPY_CODE
  • type: COPY_CODE.
  • copy_code_text: Must be specified. Meta will use approved localized wording.

Code examples and responses

code-examples-and-responses page anchor
Create a WhatsApp OTP button templateLink to code sample: Create a WhatsApp OTP button template
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createContent() {
11
const content = await client.content.v1.contents.create({
12
friendly_name: "whatsapp_otp",
13
language: "en",
14
types: {
15
"whatsapp/authentication": {
16
add_security_recommendation: true,
17
code_expiration_minutes: 30,
18
actions: [
19
{
20
type: "COPY_CODE",
21
copy_code_text: "Copy verification code",
22
},
23
],
24
},
25
},
26
});
27
28
console.log(content.dateCreated);
29
}
30
31
createContent();

Response

Note about this response
1
{
2
"sid": "HXaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"friendly_name": "whatsapp_otp",
5
"language": "en",
6
"variables": {
7
"name": "foo"
8
},
9
"types": {
10
"whatsapp/authentication": {
11
"add_security_recommendation": true,
12
"code_expiration_minutes": 30,
13
"actions": [
14
{
15
"type": "COPY_CODE",
16
"copy_code_text": "Copy verification code"
17
}
18
]
19
}
20
},
21
"url": "https://content.twilio.com/v1/Content/HXaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
22
"date_created": "2015-07-30T19:00:00Z",
23
"date_updated": "2015-07-30T19:00:00Z",
24
"links": {
25
"approval_create": "https://content.twilio.com/v1/Content/HXaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ApprovalRequests/whatsapp",
26
"approval_fetch": "https://content.twilio.com/v1/Content/HXaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ApprovalRequests"
27
}
28
}

How to send different types of WhatsApp Authentication Templates

how-to-send-different-types-of-whatsapp-authentication-templates page anchor
Copy codeOne-tap autofillZero-tap

Copy code is the default authentication template. Copy code templates include a button that copies an OTP code to the user's clipboard.

  1. Create the whatsapp/authentication template.
  2. Follow the steps to send the template.

Send WhatsApp authentication templates created with content templates

send-whatsapp-authentication-templates-created-with-content-templates page anchor

To send a whatsapp/authentication template, send it like any other content template, but include a content variable containing the one-time password (OTP) you want to send. The body field is preset and the template includes a pre-existing content variable for the OTP.

The OTP that you send must be fewer than 15 characters long.

--data-urlencode "ContentVariables={"1": "12345"}" \
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createMessage() {
11
const message = await client.messages.create({
12
contentSid: "HXXXXXXXXXX",
13
contentVariables: JSON.stringify({ 1: "123456" }),
14
from: "whatsapp:+18551234568",
15
messagingServiceSid: "MGXXXXXXXXXXX",
16
to: "whatsapp:+18551234567",
17
});
18
19
console.log(message.body);
20
}
21
22
createMessage();

Response

Note about this response
1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"api_version": "2010-04-01",
4
"body": "Hello! 👍",
5
"date_created": "Thu, 24 Aug 2023 05:01:45 +0000",
6
"date_sent": "Thu, 24 Aug 2023 05:01:45 +0000",
7
"date_updated": "Thu, 24 Aug 2023 05:01:45 +0000",
8
"direction": "outbound-api",
9
"error_code": null,
10
"error_message": null,
11
"from": "whatsapp:+18551234568",
12
"num_media": "0",
13
"num_segments": "1",
14
"price": null,
15
"price_unit": null,
16
"messaging_service_sid": "MGXXXXXXXXXXX",
17
"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
18
"status": "queued",
19
"subresource_uris": {
20
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"
21
},
22
"to": "whatsapp:+18551234567",
23
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
24
}