refactor(channels): standardize SyncSender to accept bus.OutboundMessage

This commit is contained in:
Dmitrii Balabanov 2026-03-07 23:22:39 +02:00
parent cafdb51df2
commit 0b65f7d31c
2 changed files with 10 additions and 7 deletions

View file

@ -3,6 +3,7 @@ package channels
import (
"context"
"github.com/sipeed/picoclaw/pkg/bus"
"github.com/sipeed/picoclaw/pkg/commands"
)
@ -55,5 +56,5 @@ type CommandRegistrarCapable interface {
// This is typically used by internal tools (like TaskTool) that must immediately
// receive the generated message ID in order to edit it later.
type SyncSender interface {
SendMessageWithID(ctx context.Context, chatID, content string) (string, error)
SendMessageWithID(ctx context.Context, msg bus.OutboundMessage) (string, error)
}

View file

@ -843,8 +843,14 @@ func (m *Manager) SendMessageWithID(ctx context.Context, channelName, chatID, co
return "", fmt.Errorf("channel %s not found", channelName)
}
msg := bus.OutboundMessage{
Channel: channelName,
ChatID: chatID,
Content: content,
}
if syncSender, ok := ch.(SyncSender); ok {
msgID, err := syncSender.SendMessageWithID(ctx, chatID, content)
msgID, err := syncSender.SendMessageWithID(ctx, msg)
if err == nil && msgID != "" {
return msgID, nil
}
@ -854,11 +860,7 @@ func (m *Manager) SendMessageWithID(ctx context.Context, channelName, chatID, co
}
logger.WarnCF("manager", "falling back to bus publish", nil)
m.bus.PublishOutbound(ctx, bus.OutboundMessage{
Channel: channelName,
ChatID: chatID,
Content: content,
})
m.bus.PublishOutbound(ctx, msg)
return "", fmt.Errorf("channel does not support returning message ID")
}