Send message to Group Whatsapp using arduino

Hi All,

I would like to build an alert system which will send a alert msg thru Whatsapp. But, instead of send to my personal number, it will send it to Group Whatsapp. Is this achievable?

I tried to find out how to do it, but didn't have any success.
The comments in this tutorial say it's not supported.
I also found some info on reddit saying it's not supported.
Maybe someone else on here, with more knowledge than me, will be able to help

I think you can do with some service provider as ifttt ( search of others too, don't know if free or paid )

Hi Hisyam,

Yes, sending messages to a WhatsApp group using Arduino is achievable with the right approach. While WhatsApp doesn’t offer a direct API for sending messages to a group, you can use services like Twilio’s WhatsApp API to send messages to the group’s phone number (the admin or member’s phone number).

Here's a simple outline of the solution:

  1. Set up Twilio API: Sign up for Twilio, and set up the WhatsApp API. You’ll need to get the Twilio number configured for WhatsApp messaging.
  2. Get the group admin’s phone number: Since WhatsApp groups don’t have a direct API for sending messages, you can use the admin's number or another member’s number associated with the group.
  3. Use an Arduino with Wi-Fi (like ESP8266/ESP32): This will allow your Arduino to send HTTP requests to the Twilio API. You can use the Arduino IDE to write code that sends an HTTP POST request to Twilio when an alert condition is met.
  4. Send the message: When the alert system triggers on Arduino, the HTTP request can send a message via WhatsApp to the specified number (which should be part of the group).

You can integrate this process with any monitoring or alert system where your Arduino sends the data and, based on certain conditions, triggers the message to WhatsApp.

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>

const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";

const char* host = "api.twilio.com";
const char* twilioSID = "your_TWILIO_SID";
const char* authToken = "your_TWILIO_AUTH_TOKEN";

void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
}

void loop() {
WiFiClientSecure client;
if (client.connect(host, 443)) {
String url = "/2010-04-01/Accounts/" + String(twilioSID) + "/Messages.json";
String data = "To=whatsapp:+group_admin_number&From=whatsapp:+twilio_number&Body=Alert%20Message";

client.print(String("POST ") + url + " HTTP/1.1\r\n" +
             "Host: " + host + "\r\n" +
             "Authorization: Basic " + base64::encode(twilioSID + ":" + authToken) + "\r\n" +
             "Content-Type: application/x-www-form-urlencoded\r\n" +
             "Content-Length: " + data.length() + "\r\n\r\n" + data);

delay(5000);  // wait for response

}
}

This will send an alert message to the WhatsApp group. Keep in mind that your Twilio number must be authorized for WhatsApp, and the group number should be added as a recipient.

Hope this helps! Let me know if you need further assistance with the setup.

Hello hyluoonz

Many thanks fpr your hint. One question arose:

Can WhatsApp send and receive information to and from the ESP32 application?

Yes, it’s achievable, but WhatsApp doesn’t officially support direct group messaging via APIs. You can use:

  1. Twilio API: Requires setting up your group in Twilio’s sandbox.
  2. Python Automation: Use pywhatkit or selenium for WhatsApp Web automation.
  3. Custom Arduino Setup: Use ESP32 to trigger APIs like Twilio for alerts.

Ensure compliance with WhatsApp’s policies to avoid issues. Let me know if you need details!

One small point I did this with Twitter a few years back and found that it detected and rejected posts that were identical to previous ones , so each msg needs to be different .
This was connected to the cat flap.