π¬ Send WhatsApp Group Message API
Send a text message to any WhatsApp group that your connected WhatsApp session has already joined.
This endpoint is part of the Baileys REST Mongo API and supports Hybrid Authentication β it accepts both x-api-key (for external clients) and JWT Bearer tokens (for internal users).
Internally, the API uses the Baileys WhatsApp Web library to deliver group messages and automatically triggers webhook events for delivery updates, errors, or group notifications.
π Endpoint
GET https://api.walytic.com/api/whatsapp/:sessionId/groups β get all groups joined by that session
POST https://api.walytic.com/api/whatsapp/:sessionId/send-group
π Required Headers
Header |
Type |
Required |
Description |
|---|---|---|---|
x-api-key |
String |
β Yes |
Your Walytic API key (for external integrations). |
Authorization |
String |
Optional |
JWT Bearer token for dashboard-authenticated users. |
Content-Type |
String |
β Yes |
Must be |
π€ Required Fields (Request Body)
Field |
Type |
Required |
Description |
|---|---|---|---|
groupName |
String |
β Yes |
The exact WhatsApp group name (must be already joined by this session). |
message |
String |
β Yes |
The text message you want to send to the group. |
β οΈ Important Notes
The group name must match exactly (case-insensitive) with the group your WhatsApp session has joined.
Example:"Test Group"and"test group"are considered the same.The WhatsApp session must be active and connected.
Each group message counts as 1 message against your subscription quota.
π§© Example Request (Node.js)
const axios = require("axios");
async function sendGroupMessage() {
try {
const response = await axios.post(
"https://api.walytic.com/api/whatsapp/session-919876543210/send-group",
{
groupName: "My Team Group",
message: "Hello everyone! π This is an automated group message."
},
{
headers: {
"x-api-key": "YOUR_API_KEY",
"Content-Type": "application/json"
}
}
);
if (response.data.success) {
console.log("β
Group message sent successfully!");
console.log(response.data);
} else {
console.log("β Error:", response.data.error);
}
} catch (error) {
console.error("Request failed:", error.response?.data || error.message);
}
}
sendGroupMessage();
π§Ύ Example Request (cURL)
$curl -X POST https://api.walytic.com/api/whatsapp/session-919876543210/send-group \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"groupName": "My Team Group",
"message": "Hello everyone! π This is an automated group message."
}'
π¦ Example Response (β Success)
{
"success": true,
"message": "Message sent to group 'My Team Group'"
}
β Example Response (Error)
Group not found:
{
"success": false,
"error": "Group 'My Team Group' not found or not joined by this number."
}
Session disconnected:
{
"success": false,
"error": "Session not found or not connected"
}
π‘ Webhook Events
When the group message is sent or fails, your configured webhook URL will automatically receive an event.
β Group Message Sent Event
{
"event": "group_message_sent",
"sessionId": "session-919876543210",
"groupName": "My Team Group",
"groupId": "120363022345678901@g.us",
"message": "Hello everyone! π This is an automated group message.",
"status": "sent",
"timestamp": 1734902336
}
π΄ Group Message Failed Event
{
"event": "group_message_failed",
"sessionId": "session-919876543210",
"groupName": "My Team Group",
"error": "Group not found or session disconnected",
"timestamp": 1734902340
}
π§ Internal Workflow (For Developers)
The request is handled by
controllers/whatsappController.js β sendGroupMessage().The system verifies session ownership and quota.
-
The Baileys socket fetches all joined groups:
const groups = await sock.groupFetchAllParticipating(); -
It locates the target group by name:
const targetGroup = Object.values(groups).find( g => g.subject.toLowerCase() === groupName.toLowerCase() ); -
The message is sent using:
sock.sendMessage(targetGroup.id, { text: message }); Message details are stored in MongoDB (
Messagemodel).A webhook (
groupMessageSentorgroupMessageFailed) is triggered.
π Authentication Flow
Type |
Header |
Description |
|---|---|---|
API Key |
|
Used by external integrations or partners. |
JWT Token |
|
Used by internal logged-in dashboard users. |
The Hybrid Auth middleware automatically validates both and sets req.userId for session ownership and quota tracking.
βοΈ Notes
Requires a connected WhatsApp session.
Check status with/api/whatsapp/:sessionId/status.Group name matching is case-insensitive.
-
If you need to list all available groups, use:
GET /api/whatsapp/:sessionId/groups Each message to a group consumes 1 message from the userβs quota (enforced by
enforceFeatureQuota('message', 1)).Supports multiple sessions for multi-number accounts.