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.
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.add_security_recommendation:
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.
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:
1// Install the C# / .NET helper library from twilio.com/docs/csharp/install23using System;4using Twilio;5using Twilio.Rest.Content.V1;67TwilioClient.Init(accountSid, authToken);89// define the whatsapp/authentication type10var whatsappAuthentication = new WhatsappAuthentication.Builder();11var auth1 = new WhatsappAuthAction.Builder()12.WithType(WhatsappAuthActionType.CopyCode)13.WithCopyCodeText("Check Flight Status")14.Build();15whatsappAuthentication.WithActions(new List<WhatsappAuthAction>() { auth1 });1617// define all the content types to be part of the template18var types = new Types.Builder();19types.WithWhatsappAuthentication(whatsappAuthentication.Build());2021// build the create request object22var contentCreateRequest = new ContentCreateRequest.Builder();23contentCreateRequest.WithTypes(types.Build());24contentCreateRequest.WithLanguage("en");25contentCreateRequest.WithFriendlyName("whatsapp_otp");2627// create the twilio template28var contentTemplate = await CreateAsync(contentCreateRequest.Build());2930Console.WriteLine($"Created Twilio Content Template SID: {contentTemplate.Sid}");
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": 3023}24},25"url": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",26"variables": {}27}
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/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function createMessage() {11const message = await client.messages.create({12contentSid: "HXXXXXXXXXX",13contentVariables: JSON.stringify({ 1: "123456" }),14from: "whatsapp:+18551234568",15messagingServiceSid: "MGXXXXXXXXXXX",16to: "whatsapp: +18551234567",17});1819console.log(message.body);20}2122createMessage();
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}