- Node
- Ruby
- Python
- PHP
- .NET
- Java
- Go
Overview
This guide shows how to send authentication templates to any destination WhatsApp numbers. Authentication templates are critical to fulfil your 2FA or OTP authentication use case. You can start sending authentication templates using our APIs. Follow the instructions below.Prerequisites
To get started, you need a Plivo account — sign up with your work email address if you don’t have one already. If this is your first time using Plivo APIs, follow our instructions to set up a Node.js development environment.Once you have a Plivo account, follow our WhatsApp guide to onboard your WhatsApp account, register a number against your WABA and have a template in an approved state.If your phone number is in connected state and your authentication template is in approved state, you can send your first message.Create Send WhatsApp application
Create a file called send_authentication_whatsapp.js and paste into it this code.Copy
Ask AI
"var plivo = require('plivo');
var client = new plivo.Client("<auth_id>", "<auth_token>");
const template = {
"name": "plivo_authentication_template",
"language": "en_US",
"components": [
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "33422388"
}
]
}
]
}
client.messages.create(
{
src:"+14151112221",
dst:"+14151112222",
type:"whatsapp",
template:template,
url: "https://foo.com/sms_status/"
}
).then(function (response) {
console.log(response);
});"
Test
Save the file and run it.Copy
Ask AI
send_authentication_whatsapp.js node
Note: If you’re using a Plivo Trial account, you can send messages only to phone numbers that have been verified with Plivo. You can verify (sandbox) a number by going to the console’s Phone Numbers > Sandbox Numbers page.
Overview
This guide shows how to send authentication templates to any destination WhatsApp numbers. Authentication templates are critical to fulfill your 2FA or OTP authentication use case. You can start sending authentication templates using our APIs. Follow the instructions below.Prerequisites
To get started, you need a Plivo account — sign up with your work email address if you don’t have one already. If this is your first time using Plivo APIs, follow our instructions to set up a Ruby development environment.Once you have a Plivo account, follow our WhatsApp guide to onboard your WhatsApp account, register a number against your WABA and have a template in an approved state.If your phone number is in connected state and your authentication template is in approved state, you can send your first message.Create Send WhatsApp application
Create a file called WhatsappAuthenticationMessagheCreate.rb and paste into it this code.Copy
Ask AI
require "plivo"
include Plivo
api = RestClient.new("<auth_id>","<auth_token>")
template={
"name": "plivo_authentication_template",
"language": "en_US",
"components": [
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "33422388"
}
]
}
]
}
response = api.messages.create(
src: "+14151112221",
dst:"+14151112222",
type:"whatsapp",
template:template,
url: "https://<yourdomain>.com/sms status/",
)
puts response
#Prints only the message_uuid
puts response.message_uuid
Test
Save the file and run it.Copy
Ask AI
$ WhatsappAuthenticationMessageCreate.rb
Note: If you’re using a Plivo Trial account, you can send messages only to phone numbers that have been verified with Plivo. You can verify (sandbox) a number by going to the console’s Phone Numbers > Sandbox Numbers page.
Overview
This guide shows how to send authentication templates to any destination WhatsApp numbers. Authentication templates are critical to fulfil your 2FA or OTP authentication use case. You can start sending authentication templates using our APIs. Follow the instructions below.Prerequisites
To get started, you need a Plivo account — sign up with your work email address if you don’t have one already. If this is your first time using Plivo APIs, follow our instructions to set up a Python development environment.Once you have a Plivo account, follow our WhatsApp guide to onboard your WhatsApp account, register a number against your WABA and have a template in an approved state.If your phone number is in connected state and your authentication template is in approved state, you can send your first message.Create Send WhatsApp application
Create a file called send_authentication_whatsapp.py and paste into it this code.Copy
Ask AI
import plivo
from plivo.utils.template import Template
client = plivo.RestClient('<auth_id>','<auth_token>')
template=Template(**{
"name"": "plivo_authentication_template",
"language": "en_US",
"components": [
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "33422388"
}
]
}
]
} )
response = client.messages.create(
src="+14151112221",
dst="+14151112222",
type="whatsapp",
template=template,
url="https://foo.com/sms_status/"
)
print(response)
#prints only the message_uuid
print(response.message_uuid)
Test
Save the file and run it.Copy
Ask AI
$ python send_whatsappauthentication.py
Note: If you’re using a Plivo Trial account, you can send messages only to phone numbers that have been verified with Plivo. You can verify (sandbox) a number by going to the console’s Phone Numbers > Sandbox Numbers page.
Overview
This guide shows how to send authentication templates to any destination WhatsApp numbers. Authentication templates are critical to fulfill your 2FA or OTP authentication use case. You can start sending authentication templates using our APIs. Follow the instructions below.Prerequisites
To get started, you need a Plivo account — sign up with your work email address if you don’t have one already. If this is your first time using Plivo APIs, follow our instructions to set up a PHP development environment.Once you have a Plivo account, follow our WhatsApp guide to onboard your WhatsApp account, register a number against your WABA and have a template in approved state.If you phone number is in connected state and your authentication template is in approved state, you can send your first message.Create the send WhatsApp application
Create a file called send_authentication_whatsapp.php and paste into it this code.Copy
Ask AI
"<?php
require 'vendor/autoload.php';
use Plivo\RestClient;
$client = new RestClient("<auth_id>","<auth_token>");
$template = '{
"name": "plivo_authentication_template",
"language": "en_US",
"components": [
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "33422388"
}
]
}
]
}';
$response = $client->messages->create(
[
"src" => "+14151112221",
"dst" => "+14151112222",
"type"=>"whatsapp",
"template" =>$template,
"url"=>"https://foo.com/sms_status/"
]
);
print_r($response);
// Prints only the message_uuid
print_r($response->getmessageUuid(0));
?>"
Test
Save the file and run it.Copy
Ask AI
$ php send_whatsappauthentication.php
Note: If you’re using a Plivo Trial account, you can send messages only to phone numbers that have been verified with Plivo. You can verify (sandbox) a number by going to the console’s Phone Numbers > Sandbox Numbers page.
Overview
This guide shows how to send authentication templates to any destination WhatsApp numbers. Authentication templates are critical to fulfil your 2FA or OTP authentication use case. You can start sending authentication templates using our APIs. Follow the instructions below.Prerequisites
To get started, you need a Plivo account — sign up with your work email address if you don’t have one already. If this is your first time using Plivo APIs, follow our instructions to set up a .Net development environment.Once you have a Plivo account, follow our WhatsApp guide to onboard your WhatsApp account, register a number against your WABA and have a template in an approved state.If your phone number is in connected state and your authentication template is in approved state, you can send your first message.Create Send WhatsApp application
Create a file called WhatsappAuthenticationMessageCreate.NET and paste into it this code.Copy
Ask AI
using System;
using System.Collections.Generic;
using Plivo;
namespace PlivoExamples
{
internal class Program
{
public static void Main(string[] args)
{
var api = new PlivoApi("<auth_id>","<auth_token>");
String templateJson = "{
"\name\": "\plivo_authentication_template\",
"\language\": "\en_US\",
"\components\": [
{
"\type\": "\body\",
"\parameters\": [
{
"\type\": "\text\",
"\text\": "\33422388\"
}
]
}
]
}";
var response = api.Message.Create(
src: "+14151112221",
dst: "+14151112222",
type: "whatsapp",
template_json_string: templateJson,
url: "https://<yourdomain>.com/sms_status/"
);
Console.WriteLine(response);
// Prints the message_uuid
Console.WriteLine(response.MessageUuid[0]);
}
}
}"
Test
Save the file and run it.Copy
Ask AI
$ WhatsappAuthenticationMessageCreate.NET
Note: If you’re using a Plivo Trial account, you can send messages only to phone numbers that have been verified with Plivo. You can verify (sandbox) a number by going to the console’s Phone Numbers > Sandbox Numbers page.
Overview
This guide shows how to send authentication templates to any destination WhatsApp numbers. Authentication templates are critical to fulfill your 2FA or OTP authentication use case. You can start sending authentication templates using our APIs. Follow the instructions below.Prerequisites
To get started, you need a Plivo account — sign up with your work email address if you don’t have one already. If this is your first time using Plivo APIs, follow our instructions to set up a Java development environment.Once you have a Plivo account, follow our WhatsApp guide to onboard your WhatsApp account, register a number against your WABA and have a template in approved state.If you phone number is in connected state and your authentication template is in approved state, you can send your first message.Create the send WhatsApp application
Create a file called send_authentication_whatsapp.js and paste into it this code.Copy
Ask AI
import java.io.IOException;
import java.net.URL;
import java.util.Collections;
import com.plivo.api.Plivo;
import com.plivo.api.exceptions.PlivoRestException;
import com.plivo.api.models.message.Message;
import com.plivo.api.models.message.MessageCreateResponse;
import com.plivo.api.models.message.MessageType;
import com.fasterxml.jackson.databind.ObjectMapper;
class MessageCreate
{
public static void main(String [] args)
{
Plivo.init('<auth_id>','<auth_token>');
try
{
String templateJson = "{
"\name\": "\plivo_authentication_template\",
"\language\": "\en_US\",
"\components\": [
{
"\type\": "\body\",
"\parameters\": [
{
"\type\": "\text\",
"\text\": "\33422388\"
}
]
}
]
}";
MessageCreateResponse response = Message.creator("+14151112221","14151112222")
.template_json_string(templateJson)
.type(MessageType.WHATSAPP)
.url(new URL("https://<yourdomain>.com/sms_status/") )
.create();
ObjectMapper ow = new ObjectMapper();
String output = ow.writeValueAsString(response);
System.out.println(output);
}
catch (PlivoRestException | IOException e)
{
e.printStackTrace();
}
}
}
Test
Save the file and run it.Copy
Ask AI
send_authentication_whatsapp.js node
Note: If you’re using a Plivo Trial account, you can send messages only to phone numbers that have been verified with Plivo. You can verify (sandbox) a number by going to the console’s Phone Numbers > Sandbox Numbers page.
Overview
This guide shows how to send authentication templates to any destination WhatsApp numbers. Authentication templates are critical to fulfill your 2FA or OTP authentication use case. You can start sending authentication templates using our APIs. Follow the instructions below.Prerequisites
To get started, you need a Plivo account — sign up with your work email address if you don’t have one already. If this is your first time using Plivo APIs, follow our instructions to set up a Go development environment.Once you have a Plivo account, follow our WhatsApp guide to onboard your WhatsApp account, register a number against your WABA and have a template in approved state.If you phone number is in connected state and your authentication template is in approved state, you can send your first message.Create the send WhatsApp application
Create a file called WhatsappAuthenticationMessageCreate.go and paste into it this code.Copy
Ask AI
package main
import (
"fmt"
"github.com/plivo/plivo-go/v7"
)
func main() {
client, err := plivo.NewClient("<auth_id>", "<auth_token>", &plivo.ClientOptions{})
if err != nil {
fmt.Print(""Error"", err.Error())
return
}
template, err := plivo.CreateWhatsappTemplate(`{
"name": "plivo_authentication_template",
"language": "en_US",
"components": [
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "33422388"
}
]
}
]
}`)
if err != nil {
fmt.Print("Error", err.Error())
return
}
response, err := client.Messages.Create(
plivo.MessageCreateParams{
Src:"+14151112221",
Dst:"+14151112222",
Type:"whatsapp",
Template:&template,
URL: "https://foo.com/sms_status/"
},
)
if err != nil {
fmt.Print("Error", err.Error())
return
}
fmt.Printf("Response: %#v\n", response)
// Prints only the message_uuid
fmt.Printf("Response: %#v\n", response.MessageUUID)
}
Test
Save the file and run it.Copy
Ask AI
go run WhatsappAuthenticationMessageCreate.go
Note: If you’re using a Plivo Trial account, you can send messages only to phone numbers that have been verified with Plivo. You can verify (sandbox) a number by going to the console’s Phone Numbers > Sandbox Numbers page.