mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-05-19 16:18:58 +08:00
guard non-send message actions by channel capability
This commit is contained in:
@@ -20,6 +20,11 @@ type Channel interface {
|
|||||||
HealthCheck(ctx context.Context) error
|
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 {
|
type BaseChannel struct {
|
||||||
config interface{}
|
config interface{}
|
||||||
bus *bus.MessageBus
|
bus *bus.MessageBus
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ package channels
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"clawgo/pkg/bus"
|
"clawgo/pkg/bus"
|
||||||
@@ -268,6 +269,20 @@ func (m *Manager) dispatchOutbound(ctx context.Context) {
|
|||||||
continue
|
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.
|
// Bound fan-out concurrency to prevent goroutine explosion under burst traffic.
|
||||||
m.dispatchSem <- struct{}{}
|
m.dispatchSem <- struct{}{}
|
||||||
go func(c Channel, outbound bus.OutboundMessage) {
|
go func(c Channel, outbound bus.OutboundMessage) {
|
||||||
|
|||||||
@@ -41,6 +41,15 @@ type TelegramChannel struct {
|
|||||||
handleWG sync.WaitGroup
|
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) {
|
func NewTelegramChannel(cfg config.TelegramConfig, bus *bus.MessageBus) (*TelegramChannel, error) {
|
||||||
bot, err := telego.NewBot(cfg.Token, telego.WithDefaultLogger(false, false))
|
bot, err := telego.NewBot(cfg.Token, telego.WithDefaultLogger(false, false))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user