From 3dd918d4298ef80921a8b82b69b6de84aedb4b50 Mon Sep 17 00:00:00 2001 From: DBT Date: Tue, 24 Feb 2026 09:14:43 +0000 Subject: [PATCH] guard non-send message actions by channel capability --- pkg/channels/base.go | 5 +++++ pkg/channels/manager.go | 15 +++++++++++++++ pkg/channels/telegram.go | 9 +++++++++ 3 files changed, 29 insertions(+) diff --git a/pkg/channels/base.go b/pkg/channels/base.go index d501a38..16822ea 100644 --- a/pkg/channels/base.go +++ b/pkg/channels/base.go @@ -20,6 +20,11 @@ type Channel interface { HealthCheck(ctx context.Context) error } +// ActionCapable is an optional capability interface for channels that support non-send message actions. +type ActionCapable interface { + SupportsAction(action string) bool +} + type BaseChannel struct { config interface{} bus *bus.MessageBus diff --git a/pkg/channels/manager.go b/pkg/channels/manager.go index 9c1b54b..8c9310e 100644 --- a/pkg/channels/manager.go +++ b/pkg/channels/manager.go @@ -9,6 +9,7 @@ package channels import ( "context" "fmt" + "strings" "sync" "clawgo/pkg/bus" @@ -268,6 +269,20 @@ func (m *Manager) dispatchOutbound(ctx context.Context) { continue } + action := strings.ToLower(strings.TrimSpace(msg.Action)) + if action == "" { + action = "send" + } + if action != "send" { + if ac, ok := channel.(ActionCapable); !ok || !ac.SupportsAction(action) { + logger.WarnCF("channels", "Channel does not support outbound action", map[string]interface{}{ + logger.FieldChannel: msg.Channel, + "action": action, + }) + continue + } + } + // Bound fan-out concurrency to prevent goroutine explosion under burst traffic. m.dispatchSem <- struct{}{} go func(c Channel, outbound bus.OutboundMessage) { diff --git a/pkg/channels/telegram.go b/pkg/channels/telegram.go index a18f969..7faa8c0 100644 --- a/pkg/channels/telegram.go +++ b/pkg/channels/telegram.go @@ -41,6 +41,15 @@ type TelegramChannel struct { handleWG sync.WaitGroup } +func (c *TelegramChannel) SupportsAction(action string) bool { + switch strings.ToLower(strings.TrimSpace(action)) { + case "", "send", "edit", "delete", "react": + return true + default: + return false + } +} + func NewTelegramChannel(cfg config.TelegramConfig, bus *bus.MessageBus) (*TelegramChannel, error) { bot, err := telego.NewBot(cfg.Token, telego.WithDefaultLogger(false, false)) if err != nil {