Skip to contentSkip to navigationSkip to topbar
On this page

whatsapp/authentication


WhatsApp/authentication templates let companies deliver WA 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 are not allowed.

(information)

Info

  • When sending whatsapp/authentication templates a single variable must be defined at send time and set to the one time passcode.
  • whatsapp/authentication templates must be approved by WhatsApp to send to customers.

Supported Channels

supported-channels page anchor

WhatsApp


Copycode.

add_security_recommendation:

  • Type: Boolean
  • Required: no
  • Variable Support: no
  • Description: Optional 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_minutes:

  • Type: integer

  • Required: no

  • Variable Support: no

  • Description: The 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.

    • One whole numbers from 1-90 is allowed

actions:

  • Type: array[actions]

  • Required: yes

  • Variable Support: See Common Components: Actions definition

  • Description: Buttons that recipients can tap on to act on the message:

    • Type must be specified as COPY_CODE.
    • copy_code_text must be specified as a string less than 25 characters long.
Create a WhatsApp OTP Button TemplateLink to code sample: Create a WhatsApp OTP Button Template
1
// Install the C# / .NET helper library from twilio.com/docs/csharp/install
2
3
using System;
4
using Twilio;
5
using Twilio.Rest.Content.V1;
6
7
TwilioClient.Init(accountSid, authToken);
8
9
// define the whatsapp/authentication type
10
var whatsappAuthentication = new WhatsappAuthentication.Builder();
11
var auth1 = new WhatsappAuthAction.Builder()
12
.WithType(WhatsappAuthActionType.CopyCode)
13
.WithCopyCodeText("Check Flight Status")
14
.Build();
15
whatsappAuthentication.WithActions(new List<WhatsappAuthAction>() { auth1 });
16
17
// define all the content types to be part of the template
18
var types = new Types.Builder();
19
types.WithWhatsappAuthentication(whatsappAuthentication.Build());
20
21
// build the create request object
22
var contentCreateRequest = new ContentCreateRequest.Builder();
23
contentCreateRequest.WithTypes(types.Build());
24
contentCreateRequest.WithLanguage("en");
25
contentCreateRequest.WithFriendlyName("whatsapp_otp");
26
27
// create the twilio template
28
var contentTemplate = await CreateAsync(contentCreateRequest.Build());
29
30
Console.WriteLine($"Created Twilio Content Template SID: {contentTemplate.Sid}");

Output

1
{
2
"account_sid": "$TWILIO_ACCOUNT_SID",
3
"date_created": "2023-06-02T14:34:25Z",
4
"date_updated": "2023-06-02T14:34:25Z",
5
"friendly_name": "whatsapp_otp",
6
"language": "en",
7
"links": {
8
"approval_create": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/ApprovalRequests/whatsapp",
9
"approval_fetch": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/ApprovalRequests"
10
},
11
"sid": "HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
12
"types": {
13
"whatsapp/authentication": {
14
"actions": [
15
{
16
"copy_code_text": "Copy verification code",
17
"type": "COPY_CODE"
18
}
19
],
20
"add_security_recommendation": true,
21
"body": "{{1}}",
22
"code_expiration_minutes": 30
23
}
24
},
25
"url": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
26
"variables": {}
27
}

Send WA Authentication Templates Created with Content Templates

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

Authentication templates are slightly different from other content types in that the body field is preset and there is a pre-existing content variable.

To send these templates you will need to send them as usual but include a content variable containing the OTP code you would like to send.

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

1
--data-urlencode "ContentVariables={"1": "12345"}" \
2
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();

Output

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
"tags": {
23
"campaign_name": "Spring Sale 2022",
24
"message_type": "cart_abandoned"
25
},
26
"to": "whatsapp: +18551234567",
27
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
28
}

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.