Sending Whatsapp Messages
Textly also allows you to send text messages via whatsapp to one or more targets which you can do by dispatching a post request to /api/v1/client/whatsapp/send_plain
- TypeScript
- PHP (Laravel)
- Curl
- VB.NET
- C#
const myApiToken = await getApiToken(); // See authentication guide to learn how to get a token
const response = await fetch(
"https://api.textly.ly/api/v1/client/whatsapp/send_plain",
{
method: "POST",
headers: new Headers({
"Content-Type": "application/json",
Authorization: `Bearer ${myApiToken}`,
}),
body: JSON.stringify({
target_numbers: ["09100000"],
content: "Hello world",
wait_for_send: true,
}),
}
);
use Illuminate\Support\Facades\Http;
$token = getApiToken();
$response = Http::withHeaders([
"Authorization" => "Bearer $token"
])->post('https://api.textly.ly/api/v1/client/whatsapp/send_plain', [
"target_numbers" => ["09100000"],
"content" => "Hello world"
"wait_for_send" => true,
]);
$ curl -X POST https://api.textly.ly/api/v1/client/whatsapp/send_plain \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <YOUR API TOKEN>" \
-d '{
"target_numbers": ["09100000"],
"content": "Hello world",
"wait_for_send": true
}'
' Required Imports
Imports System
Imports System.Net.Http
Imports System.Net.Http.Headers
Imports System.Text
Private Sub SendSms()
Using client As New HttpClient()
client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue("Bearer", "<api-key>")
Dim requestBody As String = $"{{""target_numbers"":[""<phone-number>""],""content"":""test"",""wait_for_send"":true}}"
Dim content As New StringContent(requestBody, Encoding.UTF8, "application/json")
Dim response As HttpResponseMessage = client.PostAsync("https://api.textly.ly/api/v1/client/whatsapp/send_plain", content).Result
Console.WriteLine(response.Content.ReadAsStringAsync().Result)
End Using
End Sub
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
string token = "<your-api-key-here>";
using (HttpClient cl = new HttpClient())
{
cl.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
cl.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var requestBody = new
{
target_numbers = new[] { "<number1>", "<number2>" },
content = "Hello world",
};
var json = JsonSerializer.Serialize(requestBody);
var content = new StringContent(json, Encoding.UTF8, "application/json");
HttpResponseMessage response = await cl.PostAsync("https://api.textly.ly/api/v1/client/whatsapp/send_plain", content);
if (response.IsSuccessStatusCode)
{
Console.WriteLine("Message sent successfully.");
}
else
{
Console.WriteLine($"Error: {response.StatusCode}");
}
}
As we can see from the code snippet the /api/v1/client/whatsapp/send_plain expects a json body that contains
{
"target_numbers": ["09100000"],
"content": "4501",
"wait_for_send": true
}
- target_numbers: an array of phone numbers which the message will be sent to (must contain at least one number)
- content: is the content of the text message
- wait_for_send: whether or not to immediately send the message or have it be scheduled to send 3 to 5 seconds (optional)
Sending documents
Textly also exposes a simple API for sending documents, by dispatching a POST request to /v1/client/whatsapp/send_document:
- TypeScript
- PHP (Laravel)
- Curl
- VB.NET
- C#
const myApiToken = await getApiToken(); // See authentication guide to learn how to get a token
const file = await getFileAsBase64();
const response = await fetch(
"https://api.textly.ly/api/v1/client/whatsapp/send_document",
{
method: "POST",
headers: new Headers({
"Content-Type": "application/json",
Authorization: `Bearer ${myApiToken}`,
}),
body: JSON.stringify({
target_numbers: ["09100000"],
caption: "test document",
wait_for_send: true,
file_name: "test.pdf",
mimeType: 'application/pdf',
base65_content: file,
}),
}
);
use Illuminate\Support\Facades\Http;
$myApiToken = 'YOUR_API_TOKEN';
$fileContent = base64_encode(file_get_contents('path/to/test.pdf'));
$response = Http::withHeaders([
'Authorization' => "Bearer {$myApiToken}",
'Content-Type' => 'application/json',
])->post('https://api.textly.ly/api/v1/client/whatsapp/send_document', [
'target_numbers' => ['09100000'],
'caption' => 'test document',
'wait_for_send' => true,
'file_name' => 'test.pdf',
'mimeType' => 'application/pdf',
'base65_content' => $fileContent,
]);
curl -X POST "https://api.textly.ly/api/v1/client/whatsapp/send_document" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-d '{
"target_numbers": ["09100000"],
"caption": "test document",
"wait_for_send": true,
"file_name": "test.pdf",
"mimeType": "application/pdf",
"base65_content": "BASE64_ENCODED_FILE_CONTENT_HERE"
}'
Imports System.Net.Http
Imports System.Text
Module Program
Sub Main()
SendRequest().Wait()
End Sub
Private Async Function SendRequest() As Task
Dim apiToken As String = "YOUR_API_TOKEN"
Dim fileBase64 As String = Convert.ToBase64String(System.IO.File.ReadAllBytes("path/to/test.pdf"))
Dim json As String = "{
""target_numbers"": [""09100000""],
""caption"": ""test document"",
""wait_for_send"": true,
""file_name"": ""test.pdf"",
""mimeType"": ""application/pdf"",
""base65_content"": """ & fileBase64 & """
}"
Using client As New HttpClient()
client.DefaultRequestHeaders.Authorization =
New System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", apiToken)
Dim content = New StringContent(json, Encoding.UTF8, "application/json")
Dim response = Await client.PostAsync("https://api.textly.ly/api/v1/client/whatsapp/send_document", content)
Dim result As String = Await response.Content.ReadAsStringAsync()
Console.WriteLine(result)
End Using
End Function
End Module
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
string apiToken = "YOUR_API_TOKEN";
string fileBase64 = Convert.ToBase64String(System.IO.File.ReadAllBytes("path/to/test.pdf"));
var json = $@"{{
""target_numbers"": [""09100000""],
""caption"": ""test document"",
""wait_for_send"": true,
""file_name"": ""test.pdf"",
""mimeType"": ""application/pdf"",
""base65_content"": ""{fileBase64}""
}}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", apiToken);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://api.textly.ly/api/v1/client/whatsapp/send_document", content);
string result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}
}
}
- base64_content: The file content encoded as a base64 string.
- mimeType: The MIME type of the file.
- file_name: The name of the file.
- caption: The file's caption text.
- target_numbers: The target numbers that will receive the message.
- wait_for_send: whether or not to wait for message to be sent or have it be scheduled.
Sending videos
Textly also exposes a simple API for sending videos, by dispatching a POST request to /v1/client/whatsapp/send_video:
- TypeScript
- PHP (Laravel)
- Curl
- VB.NET
- C#
const myApiToken = await getApiToken(); // See authentication guide to learn how to get a token
const file = await getFileAsBase64();
const response = await fetch(
"https://api.textly.ly/api/v1/client/whatsapp/send_video",
{
method: "POST",
headers: new Headers({
"Content-Type": "application/json",
Authorization: `Bearer ${myApiToken}`,
}),
body: JSON.stringify({
target_numbers: ["09100000"],
caption: "test document",
wait_for_send: true,
file_name: "test.pdf",
mimeType: 'application/pdf',
base65_content: file,
}),
}
);
use Illuminate\Support\Facades\Http;
$myApiToken = 'YOUR_API_TOKEN';
$fileContent = base64_encode(file_get_contents('path/to/test.pdf'));
$response = Http::withHeaders([
'Authorization' => "Bearer {$myApiToken}",
'Content-Type' => 'application/json',
])->post('https://api.textly.ly/api/v1/client/whatsapp/send_video', [
'target_numbers' => ['09100000'],
'caption' => 'test document',
'wait_for_send' => true,
'file_name' => 'test.pdf',
'mimeType' => 'application/pdf',
'base65_content' => $fileContent,
]);
curl -X POST "https://api.textly.ly/api/v1/client/whatsapp/send_video" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-d '{
"target_numbers": ["09100000"],
"caption": "test document",
"wait_for_send": true,
"file_name": "test.pdf",
"mimeType": "application/pdf",
"base65_content": "BASE64_ENCODED_FILE_CONTENT_HERE"
}'
Imports System.Net.Http
Imports System.Text
Module Program
Sub Main()
SendRequest().Wait()
End Sub
Private Async Function SendRequest() As Task
Dim apiToken As String = "YOUR_API_TOKEN"
Dim fileBase64 As String = Convert.ToBase64String(System.IO.File.ReadAllBytes("path/to/test.pdf"))
Dim json As String = "{
""target_numbers"": [""09100000""],
""caption"": ""test document"",
""wait_for_send"": true,
""file_name"": ""test.pdf"",
""mimeType"": ""application/pdf"",
""base65_content"": """ & fileBase64 & """
}"
Using client As New HttpClient()
client.DefaultRequestHeaders.Authorization =
New System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", apiToken)
Dim content = New StringContent(json, Encoding.UTF8, "application/json")
Dim response = Await client.PostAsync("https://api.textly.ly/api/v1/client/whatsapp/send_video", content)
Dim result As String = Await response.Content.ReadAsStringAsync()
Console.WriteLine(result)
End Using
End Function
End Module
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
string apiToken = "YOUR_API_TOKEN";
string fileBase64 = Convert.ToBase64String(System.IO.File.ReadAllBytes("path/to/test.pdf"));
var json = $@"{{
""target_numbers"": [""09100000""],
""caption"": ""test document"",
""wait_for_send"": true,
""file_name"": ""test.pdf"",
""mimeType"": ""application/pdf"",
""base65_content"": ""{fileBase64}""
}}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", apiToken);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://api.textly.ly/api/v1/client/whatsapp/send_video", content);
string result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}
}
}
- base64_content: The file content encoded as a base64 string.
- mimeType: The MIME type of the file.
- file_name: The name of the file.
- caption: The file's caption text.
- target_numbers: The target numbers that will receive the message.
- wait_for_send: whether or not to wait for message to be sent or have it be scheduled.
Sending images
Textly also exposes a simple API for sending images, by dispatching a POST request to /v1/client/whatsapp/send_image:
- TypeScript
- PHP (Laravel)
- Curl
- VB.NET
- C#
const myApiToken = await getApiToken(); // See authentication guide to learn how to get a token
const file = await getFileAsBase64();
const response = await fetch(
"https://api.textly.ly/api/v1/client/whatsapp/send_image",
{
method: "POST",
headers: new Headers({
"Content-Type": "application/json",
Authorization: `Bearer ${myApiToken}`,
}),
body: JSON.stringify({
target_numbers: ["09100000"],
caption: "test document",
wait_for_send: true,
file_name: "test.pdf",
mimeType: 'application/pdf',
base65_content: file,
}),
}
);
use Illuminate\Support\Facades\Http;
$myApiToken = 'YOUR_API_TOKEN';
$fileContent = base64_encode(file_get_contents('path/to/test.pdf'));
$response = Http::withHeaders([
'Authorization' => "Bearer {$myApiToken}",
'Content-Type' => 'application/json',
])->post('https://api.textly.ly/api/v1/client/whatsapp/send_image', [
'target_numbers' => ['09100000'],
'caption' => 'test document',
'wait_for_send' => true,
'file_name' => 'test.pdf',
'mimeType' => 'application/pdf',
'base65_content' => $fileContent,
]);
curl -X POST "https://api.textly.ly/api/v1/client/whatsapp/send_image" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-d '{
"target_numbers": ["09100000"],
"caption": "test document",
"wait_for_send": true,
"file_name": "test.pdf",
"mimeType": "application/pdf",
"base65_content": "BASE64_ENCODED_FILE_CONTENT_HERE"
}'
Imports System.Net.Http
Imports System.Text
Module Program
Sub Main()
SendRequest().Wait()
End Sub
Private Async Function SendRequest() As Task
Dim apiToken As String = "YOUR_API_TOKEN"
Dim fileBase64 As String = Convert.ToBase64String(System.IO.File.ReadAllBytes("path/to/test.pdf"))
Dim json As String = "{
""target_numbers"": [""09100000""],
""caption"": ""test document"",
""wait_for_send"": true,
""file_name"": ""test.pdf"",
""mimeType"": ""application/pdf"",
""base65_content"": """ & fileBase64 & """
}"
Using client As New HttpClient()
client.DefaultRequestHeaders.Authorization =
New System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", apiToken)
Dim content = New StringContent(json, Encoding.UTF8, "application/json")
Dim response = Await client.PostAsync("https://api.textly.ly/api/v1/client/whatsapp/send_image", content)
Dim result As String = Await response.Content.ReadAsStringAsync()
Console.WriteLine(result)
End Using
End Function
End Module
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
string apiToken = "YOUR_API_TOKEN";
string fileBase64 = Convert.ToBase64String(System.IO.File.ReadAllBytes("path/to/test.pdf"));
var json = $@"{{
""target_numbers"": [""09100000""],
""caption"": ""test document"",
""wait_for_send"": true,
""file_name"": ""test.pdf"",
""mimeType"": ""application/pdf"",
""base65_content"": ""{fileBase64}""
}}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", apiToken);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://api.textly.ly/api/v1/client/whatsapp/send_image", content);
string result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}
}
}
- base64_content: The file content encoded as a base64 string.
- mimeType: The MIME type of the file.
- file_name: The name of the file.
- caption: The file's caption text.
- target_numbers: The target numbers that will receive the message.
- wait_for_send: whether or not to wait for message to be sent or have it be scheduled.