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 WA OTP Button Template

create-wa-otp-button-template page anchor
curl

_17
curl -X POST https://content.twilio.com/v1/Content \
_17
-H 'content-type: application/json' \
_17
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN \
_17
-d '{
_17
"friendly_name": "whatsapp_otp",
_17
"language": "en",
_17
"types": {
_17
"whatsapp/authentication":{
_17
"add_security_recommendation": true,
_17
"code_expiration_minutes": "30",
_17
"actions": [{
_17
"type": "COPY_CODE",
_17
"copy_code_text": "Button Text Here"
_17
}]
_17
}
_17
}
_17
}'

Output

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

_18
// Download the helper library from https://www.twilio.com/docs/node/install
_18
// Find your Account SID and Auth Token at twilio.com/console
_18
// and set the environment variables. See http://twil.io/secure
_18
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_18
const authToken = process.env.TWILIO_AUTH_TOKEN;
_18
const client = require('twilio')(accountSid, authToken);
_18
_18
client.messages
_18
.create({
_18
contentSid: 'HX....XXXXX',
_18
contentVariables: JSON.stringify({
_18
1: '123456'
_18
}),
_18
messagingServiceSid: 'MGXXXXXXXXXXX',
_18
from: 'whatsapp:+18551234568',
_18
to: 'whatsapp: +18551234567'
_18
})
_18
.then(message => console.log(message.sid));

Output

_24
{
_24
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_24
"api_version": "2010-04-01",
_24
"body": "Hello! 👍",
_24
"date_created": "Thu, 24 Aug 2023 05:01:45 +0000",
_24
"date_sent": "Thu, 24 Aug 2023 05:01:45 +0000",
_24
"date_updated": "Thu, 24 Aug 2023 05:01:45 +0000",
_24
"direction": "outbound-api",
_24
"error_code": null,
_24
"error_message": null,
_24
"from": "whatsapp:+18551234568",
_24
"num_media": "0",
_24
"num_segments": "1",
_24
"price": null,
_24
"price_unit": null,
_24
"messaging_service_sid": "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_24
"sid": "SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_24
"status": "queued",
_24
"subresource_uris": {
_24
"media": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media.json"
_24
},
_24
"to": "whatsapp: +18551234567",
_24
"uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.json"
_24
}


Rate this page: