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.
One-Tap Autofill Authentication Template Messages
Copy Code Authentication Template Messages
Zero-Tap Authentication Template Messages
Authentication Template Object
Programing Examples:
Curl Node.Js Python PHP Go Java Dart PowerShell Ruby C#
curl --location 'https://api.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"
}
]
}'
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 );
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://api.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://api.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://api.d7networks.com/whatsapp/v2/send' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
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
)
var client = new HttpClient ();
var request = new HttpRequestMessage ( HttpMethod . Post , "https://api.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 ());