Send Automated Messages To Your WhatsApp Channel

August 19, 2024

In this tutorial, you will learn how to send automated messages to your WhatsApp Channel from Wassenger for better audience engagement.

What are WhatsApp Channels?

A WhatsApp Channel allows companies to send messages to a large number of customers at once. This broadcast feature makes communication easier and saves resources, as you only need to send one message to reach a lot of people at once.

Companies can send, for example, important information, updates, product launches, special deals, and company news on the channels. This direct style of communication can improve customer loyalty and brand awareness.

By connecting your number to Wassenger, you can automate sending messages to your WhatsApp Channel(s), supporting the following types of messages:

  • Send text messages
  • Send images
  • Send videos
  • Send GIFs
  • Send polls

In this article, we can learn how to send automated messages to a WhatsApp Channel with ready-to-use code examples.

🤩 🤖 Wassenger is a complete communication platform and API solution for WhatsApp. Explore more than 100+ API use cases and automate anything on WhatsApp by signing up for a free trial and get started in minutes**!**

Requirements

  • Have a WhatsApp number already linked to the platform and online.
  • Channel WhatsApp ID (WID) that you can find in two ways:
  1. On your WhatsApp number’s management panel, go to “Groups”. From there you will see the channels your number has access to.
  2. By using the API, query the available channels in your device for this endpoint.

API endpoint

In this tutorial we will use the following API endpoint:

Prepare the request

Target API URL

https://api.wassenger.com/v1/messages

Required HTTPS headers

Content-Type: application/json
Token: $API-TOKEN

Request body in JSON format

{
  "channel": "12036319703700@newsletter",
  "message": "This is a sample message sent to a channel"
}

Explore how to use the code in your browser without installing any software.

Also, you can find different languages you can test on Replit.com:

# Examples requires to have installed requests Python package.
# Install it by running: pip install requests
import requests
url = "https://api.wassenger.com/v1/messages"
payload = {
"channel": "12036319703700@newsletter", 
"message": "This is a sample message sent to a channel"
}
headers = {
"Content-Type": "application/json", 
"Token": "API_TOKEN_GOES_HERE"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
<?php
$curl = curl_init();
curl_setopt_array($curl, [
  CURLOPT_URL => 'https://api.wassenger.com/v1/messages',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => json_encode([
    'channel' => '12036319703700@newsletter',
    'message' => 'This is a sample message sent to a channel',
  ]),
  CURLOPT_HTTPHEADER => [
    'Content-Type: application/json',
    'Token: API_TOKEN_GOES_HERE',
  ],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
  echo 'cURL Error #:' . $err;
} else {
  echo $response;
}
// Examples requires to have installed pecl_http package, a simple and elegant HTTP client for PHP.
// Install it by running: pecl install pecl_http
// More information: https://pecl.php.net/package/pecl_http/3.2.0
<?php
$client = new http\Client();
$request = new http\Client\Request();
$body = new http\Message\Body();
$body->append(
  json_encode([
    'channel' => '120363197037006@newsletter',
    'message' => 'This is a sample message sent to a channel',
  ])
);
$request->setRequestUrl('https://api.wassenger.com/v1/messages');
$request->setRequestMethod('POST');
$request->setBody($body);
$request->setHeaders([
  'Content-Type' => 'application/json',
  'Token' => 'API_TOKEN_GOES_HERE',
]);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
package main
import(
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url:= "https://api.wassenger.com/v1/messages"
payload:= strings.NewReader("{\"channel\":\"12036319703700@newsletter\", \"message\":\"This is a sample message sent to a channel\"}")
req, _:= http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Token", "API_TOKEN_GOES_HERE")
res, _:= http.DefaultClient.Do(req)
defer res.Body.Close()
body, _:= io.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp
var client = new RestClient("https://api.wassenger.com/v1/messages");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Token", "API_TOKEN_GOES_HERE");
request.AddParameter("application/json", "{\"channel\":\"1203631970370@newsletter\", \"message\":\"This is a sample message sent to a channel\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

require 'uri' require 'net/http'

url = URI("https://api.wassenger.com/v1/messages")

http = Net::HTTP.new(url.host, url.port) http.use_ssl = true

request = Net::HTTP::Post.new(url) request["Content-Type"] = 'application/json' request["Token"] = 'API_TOKEN_GOES_HERE' request.body = "{\"channel\":\"12036319703700@newsletter\",\"message\":\"This is a sample message sent to a channel\"}"

response = http.request(request) puts response.read_body

// This code requires you to have installed Unirest package.
// Documentation: https://kong.github.io/unirest-java/#requests
// Installation: http://kong.github.io/unirest-java/
HttpResponse<String> response = Unirest.post("https://api.wassenger.com/v1/messages")
.header("Content-Type", "application/json")
.header("Token", "API_TOKEN_GOES_HERE")
.body("{\"channel\":\"12036319703700@newsletter\", \"message\":\"This is a sample message sent to a channel\"}")
.asString();

🤩 🤖 Wassenger is a complete communication platform and API solution for WhatsApp. Explore more than 100+ API use cases and automate anything on WhatsApp by signing up for a free trial and get started in minutes**!**

Want to send more? Discover all the options in the following examples

In the following code samples, we will show you how to send media messages to your WhatsApp channels

Send images to a WhatsApp Channel

# Examples requires to have installed requests Python package.
# Install it by running: pip install requests
import requests
url = "https://api.wassenger.com/v1/messages"
payload = {
"channel": "12036319703700@newsletter", 
"message": "This is a caption for an image message", 
"media": {
"url": "https://picsum.photos/seed/picsum/600/400", 
"viewOnce": False
}
}
headers = {
"Content-Type": "application/json", 
"Token": "API_TOKEN_GOES_HERE"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
<?php
$curl = curl_init();
curl_setopt_array($curl, [
  CURLOPT_URL => 'https://api.wassenger.com/v1/messages',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => json_encode([
    'channel' => '12036319703700@newsletter',
    'message' => 'This is a caption for an image message',
    'media' => [
      'url' => 'https://picsum.photos/seed/picsum/600/400',
      'viewOnce' => null,
    ],
  ]),
  CURLOPT_HTTPHEADER => [
    'Content-Type: application/json',
    'Token: API_TOKEN_GOES_HERE',
  ],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
  echo 'cURL Error #:' . $err;
} else {
  echo $response;
}
// Examples requires to have installed pecl_http package, a simple and elegant HTTP client for PHP.
// Install it by running: pecl install pecl_http
// More information: https://pecl.php.net/package/pecl_http/3.2.0
<?php
$client = new http\Client();
$request = new http\Client\Request();
$body = new http\Message\Body();
$body->append(
  json_encode([
    'channel' => '12036319703700@newsletter',
    'message' => 'This is a caption for an image message',
    'media' => [
      'url' => 'https://picsum.photos/seed/picsum/600/400',
      'viewOnce' => null,
    ],
  ])
);
$request->setRequestUrl('https://api.wassenger.com/v1/messages');
$request->setRequestMethod('POST');
$request->setBody($body);
$request->setHeaders([
  'Content-Type' => 'application/json',
  'Token' => 'API_TOKEN_GOES_HERE',
]);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
package main
import(
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url:= "https://api.wassenger.com/v1/messages"
payload:= strings.NewReader("{\"channel\":\"12036319703700@newsletter\", \"message\":\"This is a caption for an image message\", \"media\":{\"url\":\"https://picsum.photos/seed/picsum/600/400\", \"viewOnce\":false}}")
req, _:= http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Token", "API_TOKEN_GOES_HERE")
res, _:= http.DefaultClient.Do(req)
defer res.Body.Close()
body, _:= io.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp
var client = new RestClient("https://api.wassenger.com/v1/messages");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Token", "API_TOKEN_GOES_HERE");
request.AddParameter("application/json", "{\"channel\":\"12036319703700@newsletter\", \"message\":\"This is a caption for an image message\", \"media\":{\"url\":\"https://picsum.photos/seed/picsum/600/400\", \"viewOnce\":false}}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

require 'uri' require 'net/http'

url = URI("https://api.wassenger.com/v1/messages")

http = Net::HTTP.new(url.host, url.port) http.use_ssl = true

request = Net::HTTP::Post.new(url) request["Content-Type"] = 'application/json' request["Token"] = 'API_TOKEN_GOES_HERE' request.body = "{\"channel\":\"12036319703700@newsletter\",\"message\":\"This is a caption for an image message\",\"media\":{\"url\":\"https://picsum.photos/seed/picsum/600/400\\",\\"viewOnce\\":false}}"

response = http.request(request) puts response.read_body

// This code requires you to have installed Unirest package.
// Documentation: https://kong.github.io/unirest-java/#requests
// Installation: http://kong.github.io/unirest-java/
HttpResponse<String> response = Unirest.post("https://api.wassenger.com/v1/messages")
.header("Content-Type", "application/json")
.header("Token", "API_TOKEN_GOES_HERE")
.body("{\"channel\":\"12036319703700@newsletter\", \"message\":\"This is a caption for an image message\", \"media\":{\"url\":\"https://picsum.photos/seed/picsum/600/400\", \"viewOnce\":false}}")
.asString();

Send videos to a WhatsApp Channel

# Examples requires to have installed requests Python package.
# Install it by running: pip install requests
import requests
url = "https://api.wassenger.com/v1/messages"
payload = {
"channel": "12036319703700@newsletter", 
"message": "This is a caption for an image message", 
"media": {
"url": "https://download.samplelib.com/mp4/sample-5s.mp4", 
"viewOnce": False
}
}
headers = {
"Content-Type": "application/json", 
"Token": "API_TOKEN_GOES_HERE"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
<?php
$curl = curl_init();
curl_setopt_array($curl, [
  CURLOPT_URL => 'https://api.wassenger.com/v1/messages',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => json_encode([
    'channel' => '12036319703700@newsletter',
    'message' => 'This is a caption for an image message',
    'media' => [
      'url' => 'https://download.samplelib.com/mp4/sample-5s.mp4',
      'viewOnce' => null,
    ],
  ]),
  CURLOPT_HTTPHEADER => [
    'Content-Type: application/json',
    'Token: API_TOKEN_GOES_HERE',
  ],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
  echo 'cURL Error #:' . $err;
} else {
  echo $response;
}
// Examples requires to have installed pecl_http package, a simple and elegant HTTP client for PHP.
// Install it by running: pecl install pecl_http
// More information: https://pecl.php.net/package/pecl_http/3.2.0
<?php
$client = new http\Client();
$request = new http\Client\Request();
$body = new http\Message\Body();
$body->append(
  json_encode([
    'channel' => '12036319703700@newsletter',
    'message' => 'This is a caption for a video message',
    'media' => [
      'url' => 'https://download.samplelib.com/mp4/sample-5s.mp4',
      'viewOnce' => null,
    ],
  ])
);
$request->setRequestUrl('https://api.wassenger.com/v1/messages');
$request->setRequestMethod('POST');
$request->setBody($body);
$request->setHeaders([
  'Content-Type' => 'application/json',
  'Token' => 'API_TOKEN_GOES_HERE',
]);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
package main
import(
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url:= "https://api.wassenger.com/v1/messages"
payload:= strings.NewReader("{\"channel\":\"12036319703700@newsletter\", \"message\":\"This is a caption for a video message\", \"media\":{\"url\":\"https://download.samplelib.com/mp4/sample-5s.mp4\", \"viewOnce\":false}}")
req, _:= http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Token", "API_TOKEN_GOES_HERE")
res, _:= http.DefaultClient.Do(req)
defer res.Body.Close()
body, _:= io.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
// This code requires you to have installed RestSharp package.
// Documentation: https://restsharp.dev
// Installation: https://www.nuget.org/packages/RestSharp
var client = new RestClient("https://api.wassenger.com/v1/messages");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Token", "API_TOKEN_GOES_HERE");
request.AddParameter("application/json", "{\"channel\":\"12036319703700@newsletter\", \"message\":\"This is a caption for a video message\", \"media\":{\"url\":\"https://download.samplelib.com/mp4/sample-5s.mp4\", \"viewOnce\":false}}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

require 'uri' require 'net/http'

url = URI("https://api.wassenger.com/v1/messages")

http = Net::HTTP.new(url.host, url.port) http.use_ssl = true

request = Net::HTTP::Post.new(url) request["Content-Type"] = 'application/json' request["Token"] = 'API_TOKEN_GOES_HERE' request.body = "{\"channel\":\"12036319703700@newsletter\",\"message\":\"This is a caption for a video message\",\"media\":{\"url\":\"https://download.samplelib.com/mp4/sample-5s.mp4\\",\\"viewOnce\\":false}}"

response = http.request(request) puts response.read_body

// This code requires you to have installed Unirest package.
// Documentation: https://kong.github.io/unirest-java/#requests
// Installation: http://kong.github.io/unirest-java/
HttpResponse<String> response = Unirest.post("https://api.wassenger.com/v1/messages")
.header("Content-Type", "application/json")
.header("Token", "API_TOKEN_GOES_HERE")
.body("{\"channel\":\"12036319703700@newsletter\", \"message\":\"This is a caption for a video message\", \"media\":{\"url\":\"https://download.samplelib.com/mp4/sample-5s.mp4\", \"viewOnce\":false}}")
.asString();

Live API testing

You can live-test and play with the API directly from your browser.

Once you are done testing, get the auto-generated code example in your preferred programming language and you will be ready to go.

Try our API-Live tester now

🤩 🤖 Wassenger is a complete communication platform and API solution for WhatsApp. Explore more than 100+ API use cases and automate anything on WhatsApp by signing up for a free trial and get started in minutes**!**

FAQ

Can I use Wassenger to send marketing messages?

As you may know, WhatsApp has strict policies about sending unsolicited marketing messages, illicit content or spam.

Sending marketing or any unsolicited messages to users is not allowed and you would put your WhatsApp number at a high risk of getting banned.

WhatsApp communication is unsuitable for all business cases, so we recommend designing a legitimate and user-approved communication strategy to avoid problems.

Please read our guidelines with communication best practices and how to prevent getting banned.

How to send messages to multiple phone numbers 📲

You have to send numerous API requests, one per target phone number.

For instance, to send a message to 10 phone numbers, you should send 10 independent HTTPS requests to the API.

There is no option to send multiple messages in a single API request.

How to validate if a phone number can receive WhatsApp messages 📳

You can validate if a given phone number is linked to a WhatsApp account and can receive messages.

The API provides an endpoint that can validate whether a given phone number exists in WhatsApp or not.

The only requirement is to have at least one WhatsApp number connected to the platform in your current account.

For more details, please check out the API endpoint documentation here.

Before you check if a phone number exists on WhatsApp, you can also validate and normalize the format of a list of phone numbers by using the numbers validator API endpoint. This endpoint only validates the correct E164 format, but it does not check whether the phone number effectively exists on WhatsApp.

Note: The number of WhatsApp check validations is limited per month based on your subscription plan. Please check out the pricing table for more details about the limits.

Looking for more answers? Check out the extended FAQs.

Further useful resources

API Documentation 🖥️

For more details about the endpoint API, please check the documentation where you will find all the details about the accepted request params, possible success or error responses and ready-to-use code examples in multiple programming languages:

https://app.wassenger.com/docs/#tag/Messages/operation/createMessage

Ready to transform your WhatsApp communication?

Start automating your customer interactions today with Wassenger

Get Started Free