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": "REACTION",
                 "reaction": {
                     "message_id": "6847c2ea-b52f-11ee-8fa2-0242ac190007",
                     "emoji": "\uD83D\uDE00"
                 }
             },
             "recipients": [
                 {
                     "recipient": "{recipient}",
                     "recipient_type": "individual"
                 }
             ],
             "report_url": "https://webhook.site/4235f691-13ab-448e-b100-74a3a627927f"
         }
     ]
 }'
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": "43434"
    }
]

const response = await client.whatsapp.sendWhatsAppTemplatedMessage({
            originator : "{originator}",
            recipient : "{recipient}",
            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": "434343"
        }
    ]

client.whatsapp.send_whatsapp_templated_message(originator="{{originator}}", recipient="{{recipient}}",
                                                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" => "434343"
    ]
];  

$response = $direct7->whatsapp->sendWhatsAppTemplatedMessage(
    originator:'{originator}',
    recipient:'{recipient}',
    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}}"
    recipient := "{{recipient}}"
    templateId := "auth_template"
    language := "en"
    actions := []map[string]interface{}{
        {
            "action_type": "url",
            "action_index": "0",
            "action_payload": "dash",
        },
    }
    optParams := &OptionalParams{
        actions: actions,
    }
    response, err := client.whatsapp.SendWhatsAppTemplatedMessage(originator, recipient, 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\": \"REACTION\",\n                \"reaction\": {\n                    \"message_id\": \"6847c2ea-b52f-11ee-8fa2-0242ac190007\",\n                    \"emoji\": \"\\uD83D\\uDE00\"\n                }\n            },\n            \"recipients\": [\n                {\n                    \"recipient\": \"{recipient}\",\n                    \"recipient_type\": \"individual\"\n                }\n            ],\n            \"report_url\": \"https://webhook.site/4235f691-13ab-448e-b100-74a3a627927f\"\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": "REACTION",
         "reaction": {
           "message_id": "6847c2ea-b52f-11ee-8fa2-0242ac190007",
           "emoji": "😀"
         }
       },
       "recipients": [
         {
           "recipient": "{recipient}",
           "recipient_type": "individual"
         }
       ],
       "report_url": "https://webhook.site/4235f691-13ab-448e-b100-74a3a627927f"
     }
   ]
 });
 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`": `"REACTION`",
                 `"reaction`": {
                     `"message_id`": `"6847c2ea-b52f-11ee-8fa2-0242ac190007`",
                     `"emoji`": `"`\uD83D`\uDE00`"
                 }
             },
             `"recipients`": [
                 {
                     `"recipient`": `"{recipient}`",
                     `"recipient_type`": `"individual`"
                 }
             ],
             `"report_url`": `"https://webhook.site/4235f691-13ab-448e-b100-74a3a627927f`"
         }
     ]
 }
 "@

 $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" => "dash"
    }
]
client.whatsapp.send_whatsapp_templated_message(
    originator='{originator}', 
    recipient='{recipient}',
    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\": \"REACTION\",\n                \"reaction\": {\n                    \"message_id\": \"6847c2ea-b52f-11ee-8fa2-0242ac190007\",\n                    \"emoji\": \"\\uD83D\\uDE00\"\n                }\n            },\n            \"recipients\": [\n                {\n                    \"recipient\": \"{recipient}\",\n                    \"recipient_type\": \"individual\"\n                }\n            ],\n            \"report_url\": \"https://webhook.site/4235f691-13ab-448e-b100-74a3a627927f\"\n        }\n    ]\n}", null, "application/json");
  request.Content = content;
  var response = await client.SendAsync(request);
  response.EnsureSuccessStatusCode();
  Console.WriteLine(await response.Content.ReadAsStringAsync());