Skip to content

Whatsapp Text Messages

Text messages are messages containing only a text body and an optional link preview.

Image Alt Text

TEXT Object

Parameter Type Description Value / Pattern
*body String Contains the text of the message, which can contain URLs and formatting. Maximum length: 4096 characters Hi, How can I help you?
preview url Boolean Set to true to have the WhatsApp Messenger and WhatsApp Business apps attempt to render a link preview of any URL in the body text string. URLs must begin with http:// or https://. If multiple URLs are in the body text string, only the first URL will be rendered. If preview_url is omitted, or if unable to retrieve a preview, a clickable link will be rendered instead.
"text":{
    "preview_url": true,
    "body": "Hi, How can I help you?"
}
Formatting Symbol Example
Bold Asterisk (*) Your total is $10.50
Italics Underscore (_) Welcome to WhatsApp!
Strike-through Tilde (~) This is ~better~ best!
Code Three backticks (```) ```print 'Hello World';```

Programing Examples:

 curl --location 'https://api.d7networks.com/whatsapp/v2/send' \
 --header 'Content-Type: application/json' \
 --header 'Authorization: Bearer {{api_access_token}}' \
 --data '{
      "messages": [
          {
              "originator": "{registered phone_number}",
              "content": {
                  "message_type": "TEXT",
                  "text":{
                      "preview_url": true,
                      "body": "Hi, How can I help you?"
                  }
              },
              "recipients": [{
                  "recipient": "{recipient}",
                  "recipient_type": "individual"
              }],
              "report_url": "https://webhook.site/4235f691-13ab-448e-b100-74a3a627927f"
          }
      ]
 }'
npm i direct7
1
2
3
4
5
6
7
const Client = require('direct7')

const client = new Client(apiToken="Your API token")

const response = await client.whatsapp.sendWhatsAppFreeformMessage({originator: "{registered_phonenumber}", recipients: [{"recipient": "{recipient}", "recipient_type": "individual"}], message_type: "TEXT", body: "Hi, How can I help you?"});

console.log(response);
pip install direct7
1
2
3
4
5
from direct7 import Client

client = Client(api_token="Your API token")

client.whatsapp.send_whatsapp_freeform_message(originator="{registered_phonenumber}", recipients: [{"recipient": "{recipient}", "recipient_type": "individual"}], message_type="TEXT", body="Hi, How can I help you?")    

composer require direct7/direct7-php
require_once 'vendor/autoload.php';
1
2
3
4
5
6
7
8
require_once __DIR__ . '/vendor/autoload.php';

use direct7\Direct7\Client;

$client = new Client(api_token="Your API token")

$response = $direct7->whatsapp->sendWhatsAppFreeformMessage(originator:"{registered_phonenumber}", recipients: [["recipient" => "{recipient}", "recipient_type" => "individual"]], message_type:"TEXT", body: "Hi");
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)
originator := "{registered_phonenumber}"
recipients := []map[string]string{
    "recipient": "{recipient}",
    "recipient_type": "individual",
}
messageType := "TEXT"
optParams := &OptionalParams{
    body: "Hi",
}
response, err := whatsapp.SendWhatsAppFreeformMessage(originator, recipients, messageType, 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\": \"TEXT\",\n                \"text\":{\n                    \"preview_url\": true,\n                    \"body\": \"Hi, How can I help you?\"\n                }\n            },\n            \"recipients\": [{\n                \"recipient\": \"{recipient}\",\n                \"recipient_type\": \"individual\"\n            }],\n            \"report_url\": \"https://webhook.site/4235f691-13ab-448e-b100-74a3a627927f\"\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 {{api_access_token}}")
 .build();
 Response response = client.newCall(request).execute();
 var headers = {
 'Content-Type': 'application/json',
 'Authorization': 'Bearer {{api_access_token}}'
 };
 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": "TEXT",
 "text": {
 "preview_url": true,
 "body": "Hi, How can I help you?"
 }
 },
 "recipients": [
 {
 "recipient": "{recipient}",
 "recipient_type": "individual"
 }
 ],
 "report_url": "https://webhook.site/4235f691-13ab-448e-b100-74a3a627927f"
 }
 ]
 });
 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 {{api_access_token}}")

  $body = @"
  {
  `"messages`": [
  {
  `"originator`": `"{registered phone_number}`",
  `"content`": {
  `"message_type`": `"TEXT`",
  `"text`":{
  `"preview_url`": true,
  `"body`": `"Hi, How can I help you?`"
  }
  },
  `"recipients`": [{
    `"recipient`": `"{recipient}`",
    `"recipient_type`": `"individual`"
  }],
  `"report_url`": `"https://webhook.site/4235f691-13ab-448e-b100-74a3a627927f`"
  }
  ]
  }
  "@

  $response = Invoke-RestMethod 'https://api.d7networks.com/whatsapp/v2/send' -Method 'POST' -Headers $headers -Body $body
  $response | ConvertTo-Json
gem install direct7
require 'direct7'

client = Direct7::Client.new('Your API token')

client.whatsapp.send_whatsapp_freeform_message(
    originator='{originator}',
    recipients=[{ "recipient" => "{recipient}", "recipient_type" => "individual" }],
    message_type='TEXT',
    body='Hi, How can I help you?',
)
1
2
3
4
5
6
7
8
  var client = new HttpClient();
  var request = new HttpRequestMessage(HttpMethod.Post, "https://api.d7networks.com/whatsapp/v2/send");
  request.Headers.Add("Authorization", "Bearer {{api_access_token}}");
  var content = new StringContent("{\n    \"messages\": [\n        {\n            \"originator\": \"{registered phone_number}\",\n            \"content\": {\n                \"message_type\": \"TEXT\",\n                \"text\":{\n                    \"preview_url\": true,\n                    \"body\": \"Hi, How can I help you?\"\n                }\n            },\n            \"recipients\": [{\n                \"recipient\": \"{recipient}\",\n                \"recipient_type\": \"individual\"\n            }],\n            \"report_url\": \"https://webhook.site/4235f691-13ab-448e-b100-74a3a627927f\"\n        }\n    ]\n}", null, "application/json");
  request.Content = content;
  var response = await client.SendAsync(request);
  response.EnsureSuccessStatusCode();
  Console.WriteLine(await response.Content.ReadAsStringAsync());