How to send a message to WhatsApp Channel via API

WAHA, Free Self-Hosted WhatsApp API, supports WhatsApp Channels, a brand-new feature introduced by WhatsApp.

Image description

It is a one-way broadcast tool that allows administrators to send various content types such as text, photos, videos, and polls.
Users receive push notifications from the channel, similar to a private message.

In this article, we give you a Step-By-Step guide how to send messages to WhatsApp Channels using WAHA – free, self-hosted WhatsApp API!

We’ll install it on your own laptop or server, so no suspicious services have access to your WhatsApp account.

Image description

Step 0. Requirements

WAHA works on top of Docker, that’s the only think you’ll need!

Image description

👉 Please follow the

Docker official guides to install it on Linux, Windows, and macOS

Why Docker?
Docker makes it easy to ship all-in-one solution with the runtime and dependencies. You don’t have to worry about language-specific libraries or chrome installation.

Also, Docker makes installation and update processes so simple, just one command!

Step 1. Run WAHA

After you installed Docker – you’re ready to run WAHA!

docker run -it --rm -p 3000:3000/tcp --name waha devlikeapro/waha # It prints logs and the last line must be
# WhatsApp API is running on: http://[::1]:3000
Enter fullscreen mode Exit fullscreen mode

It may take time to download the image, depending on your internet speed.

If you’re using ARM processor (like Apple M1/M2) run the following commands instead:

# Download the image
docker pull devlikeapro/waha:arm
# Rename it, so you can use devlikeapro/waha image in other place
docker tag devlikeapro/waha:arm devlikeapro/waha
# Run the same command!
docker run -it --rm -p 3000:3000/tcp --name waha devlikeapro/waha # It prints logs and the last line must be
# WhatsApp API is running on: http://[::1]:3000
Enter fullscreen mode Exit fullscreen mode

👉 Now, open Dashboard at

http://localhost:3000/dashboard

You’ll see WAHA Dashboard:

Image description

Step 2. Run session

Now you start default session (current status should be STOPPED).

You can leave all configuration parameters by default:

Image description

Step 3. Scan QR

Wait until the session status is SCAN_QR and click on “camera” icon:

Image description

👉 If instead of QR you see Click to reload QRstop the session and start it again.

You’ll see QR code from WhatsApp Web app, now get your phone with installed WhatsApp application and scan the QR:

Image description

The session status will move to WORKING status:

Image description

Step 4. Get Channel ID

One step before you can send a message to you Channel – you need to get Channel ID in format 123123123@newsletter
to know where to send a message.

You can just execute the following curl command:

curl -X 'GET' \ 'http://localhost:3000/api/default/channels?role=OWNER' \ -H 'accept: application/json'
Enter fullscreen mode Exit fullscreen mode

In the response you’ll see all channels, choose one and copy id:

[ { "id": "111111111111111111@newsletter", // <========= copy that "name": "Channel Name", "role": "OWNER", ... }
]
Enter fullscreen mode Exit fullscreen mode

As alternative to curl, you can use WAHA Swagger for that, open it at

http://localhost:3000/#/channels
, scroll down to Channels section.

  • Find GET /api/{session}/channels endpoint and expand it
  • Click Try it out
  • Choose role=OWNER if you have your own channels or role=ADMIN if you’re admin in the channel (you can not send messages if you’re SUBSCRIBER in the channel)
  • Click Execute

Image description

Step 5. Send a message to WhatsApp Channel

Now we’re ready to send first messages to WhatsApp Channel via API!

Replace 123123@newsletter with your newsletter id, like 29847512@newsletter in the bellow command:

curl -X 'POST' \ 'http://localhost:3000/api/sendText' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ "chatId": "123123123123@newsletter", "text": "Hi there!", "session": "default"
}'
Enter fullscreen mode Exit fullscreen mode

As alternative to curl, you can use WAHA Swagger for that, open it at

http://localhost:3000/#/chatting
, scroll down to chatting section.

  • Find POST /api/sendText endpoint and expand it
  • Click Try it out
  • Replace 123123@newsletter with your newsletter id, like 29847512@newsletter in the bellow command
  • Click Execute

Image description

What is next?

🎉 You’ve sent the first message to WhatsApp Channel using WhatsApp API! 🎉

https://waha.devlike.pro/whatsapp-channels/


Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top