إرسال رسائل WhatsApp
تتيح لك Textly أيضًا إرسال رسائل نصية عبر واتساب إلى رقم هاتف واحد أو عدة أرقام، وذلك من خلال إرسال طلب
POST /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}");
}
}
كما نلاحظ من المثال، فإن جسم الطلب الذي يتم إرساله يتكوّن من
{
"target_numbers": ["09100000"],
"content": "4501",
"wait_for_send": true
}
- target_numbers: مصفوفة من أرقام الهواتف التي سيتم إرسال الرسالة إليها (يجب أن تحتوي على رقم واحد على الأقل)
- content: محتوى الرسالة النصية
- wait_for_send: تحديد ما إذا كان سيتم إرسال الرسالة فورًا أو جدولتها للإرسال خلال 3 إلى 5 ثوانٍ (اختياري)
إرسال المستندات
يوفر Textly أيضًا endpoint بسيطة لإرسال المستندات، وذلك عن طريق إرسال طلب POST إلى
api/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: محتوى الملف مشفر كسلسلة base64.
- mimeType: نوع MIME للملف.
- file_name: اسم الملف.
- caption: نص التسمية التوضيحية للملف.
- target_numbers: الأرقام المستهدفة التي ستستقبل الرسالة.
- wait_for_send: تحديد ما إذا كان يجب الانتظار لإرسال الرسالة مباشرة أو جدولتها للإرسال لاحقًا.
إرسال ملفات فيديو
يوفر Textly أيضًا endpoint بسيطة لإرسال مقاطع الفيديو، وذلك عن طريق إرسال طلب POST إلى
/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: محتوى الملف مشفر كسلسلة base64.
- mimeType: نوع MIME للملف.
- file_name: اسم الملف.
- caption: نص التسمية التوضيحية للملف.
- target_numbers: الأرقام المستهدفة التي ستستقبل الرسالة.
- wait_for_send: تحديد ما إذا كان يجب الانتظار لإرسال الرسالة مباشرة أو جدولتها للإرسال لاحقًا.
إرسال الصور
يوفر Textly أيضًا endpoint بسيطة لإرسال الصور، وذلك عن طريق إرسال طلب POST إلى
- 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: محتوى الملف مشفر كسلسلة base64.
- mimeType: نوع MIME للملف.
- file_name: اسم الملف.
- caption: نص التسمية التوضيحية للملف.
- target_numbers: الأرقام المستهدفة التي ستستقبل الرسالة.
- wait_for_send: تحديد ما إذا كان يجب الانتظار لإرسال الرسالة مباشرة أو جدولتها للإرسال لاحقًا.