Copy code authentication templates allow you to send a one-time password or code along with a copy code button to your users. When a WhatsApp user taps the copy code button, the WhatsApp client copies the password or code to the device's clipboard. The user can then switch to your app and paste the password or code into your app.
Copy code button authentication templates consist of:
URLs, media, and emojis are not supported.
Use the WhatsApp Business Account > Message Templates endpoint to create authentication templates.
POST /<WHATSAPP_BUSINESS_ACCOUNT_ID>/message_templates
{ "name": "<TEMPLATE_NAME>", "language": "<TEMPLATE_LANGUAGE>", "category": "authentication", "message_send_ttl_seconds": <TIME_T0_LIVE>, // Optional "components": [ { "type": "body", "add_security_recommendation": <SECURITY_RECOMMENDATION> // Optional }, { "type": "footer", "code_expiration_minutes": <CODE_EXPIRATION> // Optional }, { "type": "buttons", "buttons": [ { "type": "otp", "otp_type": "copy_code", "text": "<COPY_CODE_BUTTON_TEXT>" // Optional } ] } ] }
Note that in your template creation request the button type
is designated as OTP
, but upon creation the button type
will be set to URL
. You can confirm this by performing a GET request on a newly created authentication template and analyzing its components.
Placeholder | Description | Example Value |
---|---|---|
Integer | Optional. Indicates the number of minutes the password or code is valid. If included, the code expiration warning and this value will be displayed in the delivered message. The button will be disabled in the delivered message the indicated number of minutes from when the message was sent. If omitted, the code expiration warning will not be displayed in the delivered message. In addition, the button will be disabled 10 minutes from when the message was sent. Minimum 1, maximum 90. |
|
String | Optional. Copy code button label text. If omitted, the text will default to a pre-set value localized to the template's language. For example, Maximum 25 characters. |
|
Boolean | Optional. Set to |
|
String | Required. Template language and locale code. |
|
String | Required. Template name. Maximum 512 characters. |
|
Integer | Optional. Authentication message time-to-live value, in seconds. See Time-To-Live below. |
|
curl 'https://graph.facebook.com/v21.0
/102290129340398/message_templates' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer EAAJB...' \
-d '
{
"name": "authentication_code_copy_code_button",
"language": "en_US",
"category": "authentication",
"message_send_ttl_seconds": 60,
"components": [
{
"type": "body",
"add_security_recommendation": true
},
{
"type": "footer",
"code_expiration_minutes": 5
},
{
"type": "buttons",
"buttons": [
{
"type": "otp",
"otp_type": "copy_code",
"text": "Copy Code"
}
]
}
]
}'
{ "id": "594425479261596", "status": "PENDING", "category": "AUTHENTICATION" }
Use Cloud API or On-Premises API to send authentication template messages.
See our WhatsApp One-Time Password (OTP) Sample App for Android on Github. The sample app demonstrates how to send and receive OTP passwords and codes via the API, how to integrate the one-tap autofill and copy code buttons, how to create a template, and how to spin up a sample server.