Skip to content

Whatsapp Authentication Templated Messages

If your mobile app offers users the option to receive one-time passwords or verification codes via WhatsApp, you must use an authentication template.

Before sending a Authentication template message, you need to create a Authentication template. See Create Message Templates.

Note:

Authentication template messages will be available in India on July 1, 2024.

Image Alt Text
One-Tap Autofill
Authentication Template Messages
Image Alt Text
Copy Code
Authentication Template Messages
Image Alt Text
Zero-Tap
Authentication Template Messages

Authentication Template Object

Parameter Type Description
*template_id String Template ID configured for WhatsApp template (HSM). This should be registered and approved by D7. You can create a new Whatsapp Template here
*language String Specifies the code of language the template may be rendered in. Supported languages
buttons Object Details of the button object.

Button Object

For Authentication templated messages button object must be actions.

Parameter Type Description
*action_type String Type of action that whats to do while clicking the button. For Authentication templated messages it is url.
*action_index String Position index of the button.
*action_payload String The one-time password or verification code to be delivered to the customer. Maximum 15 characters.
    "template": {
            "template_id": "3_auth_copy",
            "language": "en",
            "buttons":{
                "actions": [
                    {
                        "action_index": "0",
                        "action_type": "url",
                        "action_payload": "123443"
                    }
                ]
            }
        }

Programing Examples:

 curl --location 'https://apialpha.d7networks.com/whatsapp/v2/send' \
 --header 'Content-Type: application/json' \
 --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoLWJhY2tlbmQ6YXBwIiwic3ViIjoiZjM0N2JhMDktMTllMi00MmIxLWE3ZjYtZDIyOGNlOTczN2U2In0.-ECRlIIiXGoF01JJEf7lmZjHCzny0vAKSlTFGbHQuwc' \
 --data '{
     "messages": [
         {
             "originator": "{registered phone_number}",
             "content": {
                 "message_type": "TEMPLATE",
                 "template": {
                                "template_id": "{{template_id}}",
                                "language": "en",
                                "buttons":{
                                    "actions": [
                                        {
                                            "action_index": "0",
                                            "action_type": "url",
                                            "action_payload": "{{otp_code}}"
                                        }
                                    ]
                                }
                }
             },
             "recipients": [
                 {
                     "recipient": "{recipient}",
                     "recipient_type": "individual"
                 }
             ],
             "report_url": "https://the_url_to_recieve_delivery_report.com"
         }
     ]
 }'
npm i direct7
const Client = require('direct7')

const client = new Client(apiToken="Your API token")
const actions = [
    {
        "action_type": "url",
        "action_index": "0",
        "action_payload": "{{otp_code}}"
    }
]

const response = await client.whatsapp.sendWhatsAppTemplatedMessage({
            originator : "{originator}",
            recipients : [{"recipient": "{recipient}", "recipient_type": "individual"}],
            template_id : "{{template_id}}",
            language: "en",
            actions: actions});

console.log(response);
pip install direct7
from direct7 import Client

client = Client(api_token="Your API token")
actions = [
        {
            "action_type": "url",
            "action_index": "0",
            "action_payload": "{{otp_code}}"
        }
    ]

client.whatsapp.send_whatsapp_templated_message(originator="{{originator}}", 
                                                recipients=[{"recipient": "{recipient}", "recipient_type": "individual"}],
                                                language="en", 
                                                template_id="{{template_id}}", 
                                                actions=actions)
composer require direct7/direct7-php
require_once 'vendor/autoload.php';
require_once __DIR__ . '/vendor/autoload.php';

use direct7\Direct7\Client;

$direct7 = new Client(api_token="Your API token");
$actions = [
    [
        "action_type" => "url",
        "action_index" => "0",
        "action_payload" => "{{otp_code}}"
    ]
];  

$response = $direct7->whatsapp->sendWhatsAppTemplatedMessage(
    originator:'{originator}',
    recipients: [["recipient" => "{recipient}", "recipient_type" => "individual"]],
    template_id:'{template_id}',
    language: 'en',
    actions:$actions
);

var_dump($response);
go get -u github.com/d7networks/direct7-go-sdk
    import (
    "github.com/d7networks/direct7-go-sdk/direct7"
    )
    apiToken := "Your Api Token"
    client := direct7.NewClient(apiToken)
    whatsapp := direct7.NewWhatsApp(client)
    originator := "{{originator}}"
    recipients := []map[string]string{
        "recipient": "{recipient}",
        "recipient_type": "individual",
    }
    templateId := "auth_template"
    language := "en"
    actions := []map[string]interface{}{
        {
            "action_type": "url",
            "action_index": "0",
            "action_payload": "{{otp_code}}",
        },
    }
    optParams := &OptionalParams{
        actions: actions,
    }
    response, err := client.whatsapp.SendWhatsAppTemplatedMessage(originator, recipients, templateId, language, optParams)
 OkHttpClient client = new OkHttpClient().newBuilder().build();
 MediaType mediaType = MediaType.parse("application/json");
 RequestBody body = RequestBody.create(mediaType, "{\n    \"messages\": [\n        {\n            \"originator\": \"{registered phone_number}\",\n            \"content\": {\n                \"message_type\": \"TEMPLATE\",\n                \"template\": {\n                    \"template_id\": \"{{template_id}}\",\n                    \"buttons\": {\n         \"actions\": [\n        {\n     \"action_index\":    \"0\",\n       \"action_type\":    \"url\",\n       \"action_payload\":    \"{{otp_code}}\"          ]\n     }\n                }\n            },\n            \"recipients\": [\n                {\n                    \"recipient\": \"{recipient}\",\n                    \"recipient_type\": \"individual\"\n                }\n            ],\n            \"report_url\": \"https://the_url_to_recieve_delivery_report.com\"\n        }\n    ]\n}");
 Request request = new Request.Builder()
   .url("https://apialpha.d7networks.com/whatsapp/v2/send")
   .method("POST", body)
   .addHeader("Content-Type", "application/json")
   .addHeader("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoLWJhY2tlbmQ6YXBwIiwic3ViIjoiZjM0N2JhMDktMTllMi00MmIxLWE3ZjYtZDIyOGNlOTczN2U2In0.-ECRlIIiXGoF01JJEf7lmZjHCzny0vAKSlTFGbHQuwc")
   .build();
 Response response = client.newCall(request).execute();
 var headers = {
   'Content-Type': 'application/json',
   'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoLWJhY2tlbmQ6YXBwIiwic3ViIjoiZjM0N2JhMDktMTllMi00MmIxLWE3ZjYtZDIyOGNlOTczN2U2In0.-ECRlIIiXGoF01JJEf7lmZjHCzny0vAKSlTFGbHQuwc'
 };
 var request = http.Request('POST', Uri.parse('https://apialpha.d7networks.com/whatsapp/v2/send'));
 request.body = json.encode({
   "messages": [
     {
       "originator": "{registered phone_number}",
       "content": {
                 "message_type": "TEMPLATE",
                 "template": {
                                "template_id": "{{template_id}}",
                                "language": "en",
                                "buttons":{
                                    "actions": [
                                        {
                                            "action_index": "0",
                                            "action_type": "url",
                                            "action_payload": "{{otp_code}}"
                                        }
                                    ]
                                }
                }
        },
       "recipients": [
         {
           "recipient": "{recipient}",
           "recipient_type": "individual"
         }
       ],
       "report_url": "https://the_url_to_recieve_delivery_report.com"
     }
   ]
 });
 request.headers.addAll(headers);

 http.StreamedResponse response = await request.send();

 if (response.statusCode == 200) {
   print(await response.stream.bytesToString());
 }
 else {
   print(response.reasonPhrase);
 }
 $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
 $headers.Add("Content-Type", "application/json")
 $headers.Add("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoLWJhY2tlbmQ6YXBwIiwic3ViIjoiZjM0N2JhMDktMTllMi00MmIxLWE3ZjYtZDIyOGNlOTczN2U2In0.-ECRlIIiXGoF01JJEf7lmZjHCzny0vAKSlTFGbHQuwc")

 $body = @"
 {
     `"messages`": [
         {
             `"originator`": `"{registered phone_number}`",
             `"content`": {
                 `"message_type`": `"TEMPLATE`",
                 `"template`": {
                     `"template_id`": `"{{template_id}}`",
                     `"language`": `"en`",
                                `"buttons`":{
                                    `"actions`": [
                                        {
                                            `"action_index`": `"0`",
                                            `"action_type`": `"url`",
                                            `"action_payload`": `"{{otp_code}}`"
                                        }
                                    ]
                                }
                 }
             },
             `"recipients`": [
                 {
                     `"recipient`": `"{recipient}`",
                     `"recipient_type`": `"individual`"
                 }
             ],
             `"report_url`": `"https://the_url_to_recieve_delivery_report.com`"
         }
     ]
 }
 "@

 $response = Invoke-RestMethod 'https://apialpha.d7networks.com/whatsapp/v2/send' -Method 'POST' -Headers $headers -Body $body
 $response | ConvertTo-Json
gem install direct7
require 'direct7'

client = Direct7::Client.new('Your API token')
actions = [
    {
        "action_type" => "url",
        "action_index" => "0",
        "action_payload" => "{otp_code}"
    }
]
client.whatsapp.send_whatsapp_templated_message(
    originator='{originator}', 
    recipients=[{ "recipient" => "{recipient}", "recipient_type" => "individual" }],
    template_id="{template_id}", 
    language="en",
    body_parameter_values=nil, media_type=nil, text_header_title=nil, media_url=nil, latitude=nil, 
    longitude=nil, name=nil, address=nil,lto_expiration_time_ms=nil, coupon_code=nil, quick_replies=nil,
    actions=actions
)
1
2
3
4
5
6
7
8
  var client = new HttpClient();
  var request = new HttpRequestMessage(HttpMethod.Post, "https://apialpha.d7networks.com/whatsapp/v2/send");
  request.Headers.Add("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoLWJhY2tlbmQ6YXBwIiwic3ViIjoiZjM0N2JhMDktMTllMi00MmIxLWE3ZjYtZDIyOGNlOTczN2U2In0.-ECRlIIiXGoF01JJEf7lmZjHCzny0vAKSlTFGbHQuwc");
  var content = new StringContent("{\n    \"messages\": [\n        {\n            \"originator\": \"{registered phone_number}\",\n            \"content\": {\n                 \"message_type\": \"TEMPLATE\",\n                \"template\": {\n                    \"template_id\": \"{{template_id}}\",\n                    \"buttons\": {\n         \"actions\": [\n        {\n     \"action_index\":    \"0\",\n       \"action_type\":    \"url\",\n       \"action_payload\":    \"{{otp_code}}\"          ]\n     }\n                }\n            },\n            \"recipients\": [\n                {\n                    \"recipient\": \"{recipient}\",\n                    \"recipient_type\": \"individual\"\n                }\n            ],\n            \"report_url\": \"https://the_url_to_recieve_delivery_report.com\"\n        }\n    ]\n}");
  request.Content = content;
  var response = await client.SendAsync(request);
  response.EnsureSuccessStatusCode();
  Console.WriteLine(await response.Content.ReadAsStringAsync());