Skip to main content

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

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,
}),
}
);

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:

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,
}),
}
);
  • 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:

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,
}),
}
);
  • 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:

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,
}),
}
);
  • 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.