Skip to content

GOWA - WhatsApp REST API with support for UI, Multi Account, Webhooks, and MCP, and Chatwoot. Built with Golang for efficient memory use.

feat(webhook): forward group name changes as group.info (#882)

Mihir Desai0a1026be34b9
diff --git a/docs/webhook-payload.md b/docs/webhook-payload.md
index c0ba9fa4..b7230a62 100644
--- a/docs/webhook-payload.md
+++ b/docs/webhook-payload.md
@@ -22,6 +22,7 @@ The following events can be received via webhook:
| `message.deleted` | Messages deleted for the user |
| `chat_presence` | Typing and recording indicators from contacts |
| `group.participants` | Group member join/leave/promote/demote events |
+| `group.info` | Group name (subject) changed |
| `group.joined` | You were added to a group |
| `label.edit` | WhatsApp label metadata changed |
| `label.association` | Label applied to or removed from a chat |
@@ -48,7 +49,7 @@ WHATSAPP_WEBHOOK_EVENTS=message,message.ack
WHATSAPP_WEBHOOK_EVENTS=message,message.reaction,message.revoked,message.edited,message.ack,message.deleted
# Receive only group events
-WHATSAPP_WEBHOOK_EVENTS=group.participants
+WHATSAPP_WEBHOOK_EVENTS=group.participants,group.info,group.joined
# Receive label events
WHATSAPP_WEBHOOK_EVENTS=label.edit,label.association
@@ -60,7 +61,7 @@ WHATSAPP_WEBHOOK_EVENTS=newsletter.joined,newsletter.left,newsletter.message,new
WHATSAPP_WEBHOOK_EVENTS=call.offer
# Receive all group and newsletter events
-WHATSAPP_WEBHOOK_EVENTS=group.participants,group.joined,newsletter.joined,newsletter.left,newsletter.message
+WHATSAPP_WEBHOOK_EVENTS=group.participants,group.info,group.joined,newsletter.joined,newsletter.left,newsletter.message
```
**CLI Flag:**
1:1 chats.
- Note: a few events carry the group JID elsewhere or omit `chat_id` — `call.offer` puts the group in
`group_jid` (not `chat_id`), `message.deleted` only includes `chat_id` when the original message is
- found locally, and `group.participants`/`group.joined` have no `from`. The `@g.us` wildcard still
+ found locally, and `group.participants`/`group.info`/`group.joined` have no `from`. The `@g.us` wildcard still
covers ordinary group messages and receipts (which is the common case for muting groups).
## Security
@@ -189,7 +190,7 @@ All webhook payloads follow a consistent top-level structure:
| **Field** | **Type** | **Description** |
|--------------|----------|---------------------------------------------------------------------------------------------------------------------|
-| `event` | string | Event type: `message`, `message.reaction`, `message.revoked`, `message.edited`, `message.ack`, `message.deleted`, `chat_presence`, `group.participants`, `group.joined`, `label.edit`, `label.association`, `newsletter.joined`, `newsletter.left`, `newsletter.message`, `newsletter.mute`, `call.offer` |
+| `event` | string | Event type: `message`, `message.reaction`, `message.revoked`, `message.edited`, `message.ack`, `message.deleted`, `chat_presence`, `group.participants`, `group.info`, `group.joined`, `label.edit`, `label.association`, `newsletter.joined`, `newsletter.left`, `newsletter.message`, `newsletter.mute`, `call.offer` |
| `device_id` | string | JID of the device that received this event (e.g., `[email protected]`) |
| `session_id` | string | Session ID registered via `POST /devices` (e.g., `org_2`), for correlating the event back to a tenant. Omitted when the JID can't be mapped to a session. |
| `payload` | object | Event-specific payload data |
@@ -640,9 +641,8 @@ Triggered when a chat-level label is applied to or removed from a chat.
## Group Events
-Group events are triggered when group metadata changes, including member join/leave events, admin promotions/demotions,
-and group settings updates. These events use the `group.participants` event type and provide comprehensive information
-about group changes.
+Group events are triggered when group metadata changes. Member join/leave events and admin promotions/demotions use the
+`group.participants` event type. Group name (subject) changes use the `group.info` event type.
### Group Member Join
@@ -721,17 +721,44 @@ Triggered when users are demoted from admin.
}
```
-### Group Event Fields
+### Group Participant Event Fields
| **Field** | **Type** | **Description** |
|-------------------|----------|--------------------------------------------------------------|
-| `event` | string | Always `"group.participants"` for group events |
+| `event` | string | Always `"group.participants"` for participant events |
| `device_id` | string | JID of the device that received this event |
| `timestamp` | string | RFC3339 formatted timestamp when the group event occurred |
| `payload.chat_id` | string | Group identifier (e.g., `"[email protected]"`) |
| `payload.type` | string | Action type: `"join"`, `"leave"`, `"promote"`, or `"demote"` |
| `payload.jids` | array | Array of user JIDs affected by this action |
+### Group Name Change
+
+Triggered when a group's name (subject) is changed, by any participant or by this device. This event uses the
+`group.info` event type.
+
+```json
+{
+ "event": "group.info",
+ "device_id": "[email protected]",
+ "timestamp": "2025-07-28T10:35:00Z",
+ "payload": {
+ "chat_id": "[email protected]",
+ "name": "Project Team",
+ "name_set_by": "[email protected]"
+ }
+}
+```
+
+| **Field** | **Type** | **Description** |
+|-----------------------|----------|-------------------------------------------------------------------------------------------|
+| `event` | string | Always `"group.info"` |
+| `device_id` | string | JID of the device that received this event |
+| `timestamp` | string | RFC3339 formatted timestamp when the name was changed |
+| `payload.chat_id` | string | Group identifier (e.g., `"[email protected]"`) |
+| `payload.name` | string | The new group name |
+| `payload.name_set_by` | string | JID of the user who changed the name, resolved from LID to phone number when possible. Omitted when WhatsApp does not say who changed it |
+
## Newsletter Events
Newsletter events are triggered when you interact with WhatsApp Channels (newsletters). These include subscribing,
diff --git a/readme.md b/readme.md
index a1569fd5..8a523e90 100644
--- a/readme.md
+++ b/readme.md
@@ -182,6 +182,7 @@ Download:
| `message.deleted` | Messages deleted for the user |
| `chat_presence` | Typing and recording indicators from contacts |
| `group.participants` | Group member join/leave/promote/demote events |
+ | `group.info` | Group name (subject) changed |
| `group.joined` | You were added to a group |
| `label.edit` | WhatsApp label metadata changed |
| `label.association` | Label applied to or removed from a chat |
diff --git a/src/infrastructure/whatsapp/event_group.go b/src/infrastructure/whatsapp/event_group.go
index a03fa1d6..f35c894d 100644
--- a/src/infrastructure/whatsapp/event_group.go
+++ b/src/infrastructure/whatsapp/event_group.go
@@ -76,9 +76,51 @@ func forwardGroupInfoToWebhook(ctx context.Context, evt *events.GroupInfo, devic
}
}
+ if evt.Name != nil {
+ payload := createGroupNamePayload(ctx, evt, deviceID, client)
+
+ if err := forwardPayloadToConfiguredWebhooks(ctx, payload, "group.info"); err != nil {
+ logrus.Warnf("Failed to forward group name change to webhook: %v", err)
+ }
+ }
+
return nil
}
+// createGroupNamePayload creates a group.info webhook payload for a group name (subject) change
+func createGroupNamePayload(ctx context.Context, evt *events.GroupInfo, deviceID string, client *whatsmeow.Client) map[string]any {
+ payload := map[string]any{
+ "chat_id": evt.JID.ToNonAD().String(),
+ "name": evt.Name.Name,
+ }
+ if setBy := groupNameSetBy(ctx, evt.Name, client); setBy != "" {
+ payload["name_set_by"] = setBy
+ }
+
+ body := map[string]any{
+ "event": "group.info",
+ "payload": payload,
+ "timestamp": evt.Timestamp.Format(time.RFC3339),
+ }
+ if deviceID != "" {
+ body["device_id"] = deviceID
+ }
+
+ return body
+}
+
+// groupNameSetBy returns the JID of the user who set the group name, preferring the phone
+// number JID that WhatsApp sends next to a LID. Returns "" when WhatsApp did not say who.
+func groupNameSetBy(ctx context.Context, name *types.GroupName, client *whatsmeow.Client) string {
+ if !name.NameSetByPN.IsEmpty() {
+ return name.NameSetByPN.ToNonAD().String()
+ }
+ if name.NameSetBy.IsEmpty() {
+ return ""
+ }
+ return NormalizeJIDFromLID(ctx, name.NameSetBy, client).ToNonAD().String()
+}
+
// handleJoinedGroup handles the event when the connected device is added to a new group
func handleJoinedGroup(ctx context.Context, evt *events.JoinedGroup, deviceID string, client *whatsmeow.Client) {
log.Infof("Joined group %s (reason: %s, type: %s)", evt.JID, evt.Reason, evt.Type)
diff --git a/src/infrastructure/whatsapp/event_group_test.go b/src/infrastructure/whatsapp/event_group_test.go
new file mode 100644
index 00000000..c0fd7463
--- /dev/null
+++ b/src/infrastructure/whatsapp/event_group_test.go
@@ -0,0 +1,208 @@
+package whatsapp
+
+import (
+ "context"
+ "testing"
+ "time"
+
+ "github.com/aldinokemal/go-whatsapp-web-multidevice/config"
+ "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/chatstorage"
+ "go.mau.fi/whatsmeow/types"
+ "go.mau.fi/whatsmeow/types/events"
+ waLog "go.mau.fi/whatsmeow/util/log"
+)
+
+type capturedWebhook struct {
+ event string
+ payload map[string]any
+}
+
+// captureGroupWebhooks routes every webhook submission into the returned slice and
+// restores the replaced config and package globals when the test ends.
+func captureGroupWebhooks(t *testing.T) *[]capturedWebhook {
+ t.Helper()
+
+ originalWebhooks := config.WhatsappWebhook
+ originalEvents := config.WhatsappWebhookEvents
+ originalIgnore := config.WhatsappWebhookIgnoreJids
+ originalChatwoot := config.ChatwootEnabled
+ originalSubmit := submitWebhookFn
+ originalStorage := webhookStorageForTest
+ originalSessionID := sessionIDForJIDFn
+ t.Cleanup(func() {
+ config.WhatsappWebhook = originalWebhooks
+ config.WhatsappWebhookEvents = originalEvents
+ config.WhatsappWebhookIgnoreJids = originalIgnore
+ config.ChatwootEnabled = originalChatwoot
+ submitWebhookFn = originalSubmit
+ webhookStorageForTest = originalStorage
+ sessionIDForJIDFn = originalSessionID
+ })
+
+ config.WhatsappWebhook = []string{"https://example.test/webhook"}
+ config.WhatsappWebhookEvents = nil
+ config.WhatsappWebhookIgnoreJids = nil
+ config.ChatwootEnabled = false
+ webhookStorageForTest = func(string) (*chatstorage.DeviceRecord, error) { return nil, nil }
+ sessionIDForJIDFn = func(string) string { return "" }
+
+ var captured []capturedWebhook
+ submitWebhookFn = func(_ context.Context, payload map[string]any, _ string, _ *chatstorage.DeviceWebhookConfig) error {
+ event, _ := payload["event"].(string)
+ inner, _ := payload["payload"].(map[string]any)
+ captured = append(captured, capturedWebhook{event: event, payload: inner})
+ return nil
+ }
+ return &captured
+}
+
+// groupNameEvent builds a GroupInfo event that carries only a group name change.
+func groupNameEvent(name types.GroupName) *events.GroupInfo {
+ return &events.GroupInfo{
+ JID: types.NewJID("120363402106000000", types.GroupServer),
+ Timestamp: time.Date(2026, 10, 14, 9, 30, 0, 0, time.UTC),
+ Name: &name,
+ }
+}
+
+func TestForwardGroupInfoToWebhook_NameChange(t *testing.T) {
+ captured := captureGroupWebhooks(t)
+
+ evt := groupNameEvent(types.GroupName{
+ Name: "Kitchen @ Home",
+ NameSetBy: types.NewJID("123456789012345", types.HiddenUserServer),
+ NameSetByPN: types.NewJID("6289685000000", types.DefaultUserServer),
+ })
+
+ if err := forwardGroupInfoToWebhook(context.Background(), evt, "[email protected]", nil); err != nil {
+ t.Fatalf("expected no error, got %v", err)
+ }
+
+ if len(*captured) != 1 {
+ t.Fatalf("expected 1 webhook, got %d", len(*captured))
+ }
+ got := (*captured)[0]
+ if got.event != "group.info" {
+ t.Errorf("expected event group.info, got %q", got.event)
+ }
+ if got.payload["chat_id"] != "[email protected]" {
+ t.Errorf("unexpected chat_id %v", got.payload["chat_id"])
+ }
+ if got.payload["name"] != "Kitchen @ Home" {
+ t.Errorf("unexpected name %v", got.payload["name"])
+ }
+ if got.payload["name_set_by"] != "[email protected]" {
+ t.Errorf("expected the phone number JID in name_set_by, got %v", got.payload["name_set_by"])
+ }
+}
+
+func TestCreateGroupNamePayload(t *testing.T) {
+ evt := groupNameEvent(types.GroupName{Name: "Renamed"})
+
+ body := createGroupNamePayload(context.Background(), evt, "[email protected]", nil)
+
+ if body["event"] != "group.info" {
+ t.Errorf("expected event group.info, got %v", body["event"])
+ }
+ if body["device_id"] != "[email protected]" {
+ t.Errorf("unexpected device_id %v", body["device_id"])
+ }
+ if body["timestamp"] != "2026-10-14T09:30:00Z" {
+ t.Errorf("unexpected timestamp %v", body["timestamp"])
+ }
+ payload := body["payload"].(map[string]any)
+ if _, ok := payload["name_set_by"]; ok {
+ t.Errorf("expected no name_set_by when WhatsApp does not say who set the name, got %v", payload["name_set_by"])
+ }
+}
+
+func TestGroupNameSetBy(t *testing.T) {
+ phone := types.NewJID("6289685000000", types.DefaultUserServer)
+ lid := types.NewJID("123456789012345", types.HiddenUserServer)
+
+ originalLog := log
+ log = waLog.Noop
+ t.Cleanup(func() { log = originalLog })
+
+ tests := []struct {
+ name string
+ in types.GroupName
+ want string
+ }{
+ {"phone number JID next to a LID", types.GroupName{NameSetBy: lid, NameSetByPN: phone}, "[email protected]"},
+ {"phone number JID only", types.GroupName{NameSetBy: phone}, "[email protected]"},
+ {"unresolvable LID only", types.GroupName{NameSetBy: lid}, "123456789012345@lid"},
+ {"no setter", types.GroupName{}, ""},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := groupNameSetBy(context.Background(), &tt.in, nil); got != tt.want {
+ t.Errorf("expected %q, got %q", tt.want, got)
+ }
+ })
+ }
+}
+
+func TestForwardGroupInfoToWebhook_ParticipantsOnlySendsNoGroupInfo(t *testing.T) {
+ captured := captureGroupWebhooks(t)
+
+ evt := &events.GroupInfo{
+ JID: types.NewJID("120363402106000000", types.GroupServer),
+ Timestamp: time.Date(2026, 10, 14, 9, 30, 0, 0, time.UTC),
+ Join: []types.JID{types.NewJID("6289685000000", types.DefaultUserServer)},
+ }
+
+ if err := forwardGroupInfoToWebhook(context.Background(), evt, "", nil); err != nil {
+ t.Fatalf("expected no error, got %v", err)
+ }
+
+ if len(*captured) != 1 || (*captured)[0].event != "group.participants" {
+ t.Fatalf("expected only a group.participants webhook, got %+v", *captured)
+ }
+}
+
+func TestForwardGroupInfoToWebhook_NameAndParticipantsSendsBoth(t *testing.T) {
+ captured := captureGroupWebhooks(t)
+
+ evt := groupNameEvent(types.GroupName{Name: "Renamed"})
+ evt.Join = []types.JID{types.NewJID("6289685000000", types.DefaultUserServer)}
+
+ if err := forwardGroupInfoToWebhook(context.Background(), evt, "", nil); err != nil {
+ t.Fatalf("expected no error, got %v", err)
+ }
+
+ counts := map[string]int{}
+ for _, webhook := range *captured {
+ counts[webhook.event]++
+ }
+ if len(*captured) != 2 || counts["group.participants"] != 1 || counts["group.info"] != 1 {
+ t.Fatalf("expected one group.participants and one group.info webhook, got %+v", *captured)
+ }
+}
+
+func TestForwardGroupInfoToWebhook_NameChangeFollowsEventWhitelist(t *testing.T) {
+ tests := []struct {
+ name string
+ whitelist []string
+ want int
+ }{
+ {"group.info whitelisted", []string{"group.info"}, 1},
+ {"only group.participants whitelisted", []string{"group.participants"}, 0},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ captured := captureGroupWebhooks(t)
+ config.WhatsappWebhookEvents = tt.whitelist
+
+ evt := groupNameEvent(types.GroupName{Name: "Renamed"})
+
+ if err := forwardGroupInfoToWebhook(context.Background(), evt, "", nil); err != nil {
+ t.Fatalf("expected no error, got %v", err)
+ }
+
+ if len(*captured) != tt.want {
+ t.Fatalf("expected %d webhook(s), got %+v", tt.want, *captured)
+ }
+ })
+ }
+}
diff --git a/src/infrastructure/whatsapp/event_handler.go b/src/infrastructure/whatsapp/event_handler.go
index ff9cef03..b9d28b10 100644
--- a/src/infrastructure/whatsapp/event_handler.go
+++ b/src/infrastructure/whatsapp/event_handler.go
@@ -421,6 +421,9 @@ func handleGroupInfo(ctx context.Context, evt *events.GroupInfo, deviceID string
if len(evt.Demote) > 0 {
log.Infof("Group %s: %d users demoted at %s", evt.JID, len(evt.Demote), evt.Timestamp)
}
+ if evt.Name != nil {
+ log.Infof("Group %s: name changed at %s", evt.JID, evt.Timestamp)
+ }
// Forward group info event to webhook
go func(e *events.GroupInfo, c *whatsmeow.Client) {