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: add flag to ignore downloading status media (#836)

Dani Hidayatef830a13f48a
diff --git a/readme.md b/readme.md
index 607b72d0..36765a2f 100644
--- a/readme.md
+++ b/readme.md
@@ -122,6 +122,8 @@ Download:
- `--auto-mark-read=true`
- Automatically download media from incoming messages:
- `--auto-download-media=false` disables automatic media downloads (default: `true`).
+- Ignore downloading status media:
+ - `--ignore-status-media=true` disables downloading status media (default: `false`).
- Automatically reject incoming calls:
- `--auto-reject-call=true` or `WHATSAPP_AUTO_REJECT_CALL=true` (see
[Webhook Payload](./docs/webhook-payload.md#call-events) for call events).
@@ -256,6 +258,7 @@ To use environment variables:
| `WHATSAPP_AUTO_REPLY` | Auto-reply message | - | `WHATSAPP_AUTO_REPLY="Auto reply message"` |
| `WHATSAPP_AUTO_MARK_READ` | Auto-mark incoming messages as read | `false` | `WHATSAPP_AUTO_MARK_READ=true` |
| `WHATSAPP_AUTO_DOWNLOAD_MEDIA` | Auto-download media from incoming messages | `true` | `WHATSAPP_AUTO_DOWNLOAD_MEDIA=false` |
+| `WHATSAPP_IGNORE_STATUS_MEDIA` | Ignore downloading status media (status@broadcast) | `false` | `WHATSAPP_IGNORE_STATUS_MEDIA=true` |
| `WHATSAPP_AUTO_REJECT_CALL` | Auto-reject incoming WhatsApp calls | `false` | `WHATSAPP_AUTO_REJECT_CALL=true` |
| `WHATSAPP_WEBHOOK` | Webhook URL(s) for events (comma-separated) | - | `WHATSAPP_WEBHOOK=https://webhook.site/xxx` |
| `WHATSAPP_WEBHOOK_SECRET` | Webhook secret for validation | `secret` | `WHATSAPP_WEBHOOK_SECRET=super-secret-key` |
diff --git a/src/.env.example b/src/.env.example
index 73d37eb8..4d8dc1c6 100644
--- a/src/.env.example
+++ b/src/.env.example
@@ -50,6 +50,7 @@ WHATSAPP_AUTO_REPLY="Auto reply message"
WHATSAPP_AUTO_MARK_READ=false
WHATSAPP_AUTO_REJECT_CALL=false
WHATSAPP_AUTO_DOWNLOAD_MEDIA=true
+WHATSAPP_IGNORE_STATUS_MEDIA=false
WHATSAPP_WEBHOOK=https://webhook.site/07b69616-5943-4c7f-a8be-db4819df699e,https://webhook.site/09a38aff-d11a-4a38-a176-3f3efa0b5e8b
WHATSAPP_WEBHOOK_SECRET=super-secret-key
WHATSAPP_WEBHOOK_INSECURE_SKIP_VERIFY=false
diff --git a/src/cmd/root.go b/src/cmd/root.go
index 4624c99a..6306080e 100644
--- a/src/cmd/root.go
+++ b/src/cmd/root.go
@@ -160,6 +160,9 @@ func initEnvConfig() {
if viper.IsSet("whatsapp_auto_download_media") {
config.WhatsappAutoDownloadMedia = viper.GetBool("whatsapp_auto_download_media")
}
+ if viper.IsSet("whatsapp_ignore_status_media") {
+ config.WhatsappIgnoreStatusMedia = viper.GetBool("whatsapp_ignore_status_media")
+ }
if envWebhook := viper.GetString("whatsapp_webhook"); envWebhook != "" {
webhook := strings.Split(envWebhook, ",")
config.WhatsappWebhook = webhook
@@ -429,6 +432,12 @@ func initFlags() {
config.WhatsappAutoDownloadMedia,
`auto download media from incoming messages --auto-download-media <true/false> | example: --auto-download-media=false`,
)
+ rootCmd.PersistentFlags().BoolVarP(
+ &config.WhatsappIgnoreStatusMedia,
+ "ignore-status-media", "",
+ config.WhatsappIgnoreStatusMedia,
+ `ignore downloading status media --ignore-status-media <true/false> | example: --ignore-status-media=true`,
+ )
rootCmd.PersistentFlags().StringSliceVarP(
&config.WhatsappWebhook,
"webhook", "w",
diff --git a/src/config/settings.go b/src/config/settings.go
index 41277821..6c9b3198 100644
--- a/src/config/settings.go
+++ b/src/config/settings.go
@@ -45,6 +45,7 @@ var (
WhatsappAutoReplyMessage string
WhatsappAutoMarkRead = false // Auto-mark incoming messages as read
WhatsappAutoDownloadMedia = true // Auto-download media from incoming messages
+ WhatsappIgnoreStatusMedia = false // Ignore downloading status media
WhatsappWebhook []string
WhatsappWebhookSecret = "secret"
WhatsappWebhookInsecureSkipVerify = false // Skip TLS certificate verification for webhooks (insecure)
diff --git a/src/infrastructure/whatsapp/event_message_handler.go b/src/infrastructure/whatsapp/event_message_handler.go
index 295369ea..a1aada38 100644
--- a/src/infrastructure/whatsapp/event_message_handler.go
+++ b/src/infrastructure/whatsapp/event_message_handler.go
@@ -78,8 +78,18 @@ func buildMessageMetaParts(evt *events.Message) []string {
return metaParts
}
+func shouldIgnoreImageDownload(autoDownloadMedia, ignoreStatusMedia bool, chatJID types.JID) bool {
+ if !autoDownloadMedia {
+ return true
+ }
+ if ignoreStatusMedia && chatJID == types.StatusBroadcastJID {
+ return true
+ }
+ return false
+}
+
func handleImageMessage(ctx context.Context, evt *events.Message, client *whatsmeow.Client) {
- if !config.WhatsappAutoDownloadMedia {
+ if shouldIgnoreImageDownload(config.WhatsappAutoDownloadMedia, config.WhatsappIgnoreStatusMedia, evt.Info.Chat) {
return
}
if client == nil {
diff --git a/src/infrastructure/whatsapp/event_message_handler_test.go b/src/infrastructure/whatsapp/event_message_handler_test.go
index 5268c944..cabe47f4 100644
--- a/src/infrastructure/whatsapp/event_message_handler_test.go
+++ b/src/infrastructure/whatsapp/event_message_handler_test.go
@@ -289,3 +289,58 @@ func reactionEventForTest(eventID, targetID, emoji string) *events.Message {
},
}
}
+
+func TestShouldIgnoreImageDownload(t *testing.T) {
+ tests := []struct {
+ name string
+ autoDownloadMedia bool
+ ignoreStatusMedia bool
+ chatJID types.JID
+ expected bool
+ }{
+ {
+ name: "auto download disabled",
+ autoDownloadMedia: false,
+ ignoreStatusMedia: false,
+ chatJID: types.StatusBroadcastJID,
+ expected: true,
+ },
+ {
+ name: "status media ignored",
+ autoDownloadMedia: true,
+ ignoreStatusMedia: true,
+ chatJID: types.StatusBroadcastJID,
+ expected: true,
+ },
+ {
+ name: "normal broadcast list not ignored when status ignored",
+ autoDownloadMedia: true,
+ ignoreStatusMedia: true,
+ chatJID: types.NewJID("123456789", types.BroadcastServer),
+ expected: false,
+ },
+ {
+ name: "status media downloaded when ignore disabled",
+ autoDownloadMedia: true,
+ ignoreStatusMedia: false,
+ chatJID: types.StatusBroadcastJID,
+ expected: false,
+ },
+ {
+ name: "normal user chat not ignored",
+ autoDownloadMedia: true,
+ ignoreStatusMedia: true,
+ chatJID: types.NewJID("123456789", types.DefaultUserServer),
+ expected: false,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ result := shouldIgnoreImageDownload(tt.autoDownloadMedia, tt.ignoreStatusMedia, tt.chatJID)
+ if result != tt.expected {
+ t.Errorf("expected %v, got %v", tt.expected, result)
+ }
+ })
+ }
+}