Skip to contentSkip to navigationSkip to topbar
Rate this page:
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 Template

create-a-whatsapp-otp-button-template page anchor
C#
Java
curl

_30
// Install the C# / .NET helper library from twilio.com/docs/csharp/install
_30
_30
using System;
_30
using Twilio;
_30
using Twilio.Rest.Content.V1;
_30
_30
TwilioClient.Init(accountSid, authToken);
_30
_30
// define the whatsapp/authentication type
_30
var whatsappAuthentication = new WhatsappAuthentication.Builder();
_30
var auth1 = new WhatsappAuthAction.Builder()
_30
.WithType(WhatsappAuthActionType.CopyCode)
_30
.WithCopyCodeText("Check Flight Status")
_30
.Build();
_30
whatsappAuthentication.WithActions(new List<WhatsappAuthAction>() { auth1 });
_30
_30
// define all the content types to be part of the template
_30
var types = new Types.Builder();
_30
types.WithWhatsappAuthentication(whatsappAuthentication.Build());
_30
_30
// build the create request object
_30
var contentCreateRequest = new ContentCreateRequest.Builder();
_30
contentCreateRequest.WithTypes(types.Build());
_30
contentCreateRequest.WithLanguage("en");
_30
contentCreateRequest.WithFriendlyName("whatsapp_otp");
_30
_30
// create the twilio template
_30
var contentTemplate = await CreateAsync(contentCreateRequest.Build());
_30
_30
Console.WriteLine($"Created Twilio Content Template SID: {contentTemplate.Sid}");

Output

_27
{
_27
"account_sid": "$TWILIO_ACCOUNT_SID",
_27
"date_created": "2023-06-02T14:34:25Z",
_27
"date_updated": "2023-06-02T14:34:25Z",
_27
"friendly_name": "whatsapp_otp",
_27
"language": "en",
_27
"links": {
_27
"approval_create": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/ApprovalRequests/whatsapp",
_27
"approval_fetch": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/ApprovalRequests"
_27
},
_27
"sid": "HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_27
"types": {
_27
"whatsapp/authentication": {
_27
"actions": [
_27
{
_27
"copy_code_text": "Copy verification code",
_27
"type": "COPY_CODE"
_27
}
_27
],
_27
"add_security_recommendation": true,
_27
"body": "{{1}}",
_27
"code_expiration_minutes": 30
_27
}
_27
},
_27
"url": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_27
"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.


_10
--data-urlencode "ContentVariables={"1": "12345"}" \

Sending WA Authentication Templates

sending-wa-authentication-templates page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_22
// Download the helper library from https://www.twilio.com/docs/node/install
_22
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_22
_22
// Find your Account SID and Auth Token at twilio.com/console
_22
// and set the environment variables. See http://twil.io/secure
_22
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_22
const authToken = process.env.TWILIO_AUTH_TOKEN;
_22
const client = twilio(accountSid, authToken);
_22
_22
async function createMessage() {
_22
const message = await client.messages.create({
_22
contentSid: "HXXXXXXXXXX",
_22
contentVariables: JSON.stringify({ 1: "123456" }),
_22
from: "whatsapp:+18551234568",
_22
messagingServiceSid: "MGXXXXXXXXXXX",
_22
to: "whatsapp: +18551234567",
_22
});
_22
_22
console.log(message.body);
_22
}
_22
_22
createMessage();

Output

_28
{
_28
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_28
"api_version": "2010-04-01",
_28
"body": "Hello! 👍",
_28
"date_created": "Thu, 24 Aug 2023 05:01:45 +0000",
_28
"date_sent": "Thu, 24 Aug 2023 05:01:45 +0000",
_28
"date_updated": "Thu, 24 Aug 2023 05:01:45 +0000",
_28
"direction": "outbound-api",
_28
"error_code": null,
_28
"error_message": null,
_28
"from": "whatsapp:+18551234568",
_28
"num_media": "0",
_28
"num_segments": "1",
_28
"price": null,
_28
"price_unit": null,
_28
"messaging_service_sid": "MGXXXXXXXXXXX",
_28
"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_28
"status": "queued",
_28
"subresource_uris": {
_28
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"
_28
},
_28
"tags": {
_28
"campaign_name": "Spring Sale 2022",
_28
"message_type": "cart_abandoned"
_28
},
_28
"to": "whatsapp: +18551234567",
_28
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
_28
}


Rate this page: