refactor(channels): standardize SyncSender to accept bus.OutboundMessage
This commit is contained in:
parent
cafdb51df2
commit
0b65f7d31c
2 changed files with 10 additions and 7 deletions
|
|
@ -3,6 +3,7 @@ package channels
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/sipeed/picoclaw/pkg/bus"
|
||||||
"github.com/sipeed/picoclaw/pkg/commands"
|
"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
|
// This is typically used by internal tools (like TaskTool) that must immediately
|
||||||
// receive the generated message ID in order to edit it later.
|
// receive the generated message ID in order to edit it later.
|
||||||
type SyncSender interface {
|
type SyncSender interface {
|
||||||
SendMessageWithID(ctx context.Context, chatID, content string) (string, error)
|
SendMessageWithID(ctx context.Context, msg bus.OutboundMessage) (string, error)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -843,8 +843,14 @@ func (m *Manager) SendMessageWithID(ctx context.Context, channelName, chatID, co
|
||||||
return "", fmt.Errorf("channel %s not found", channelName)
|
return "", fmt.Errorf("channel %s not found", channelName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
msg := bus.OutboundMessage{
|
||||||
|
Channel: channelName,
|
||||||
|
ChatID: chatID,
|
||||||
|
Content: content,
|
||||||
|
}
|
||||||
|
|
||||||
if syncSender, ok := ch.(SyncSender); ok {
|
if syncSender, ok := ch.(SyncSender); ok {
|
||||||
msgID, err := syncSender.SendMessageWithID(ctx, chatID, content)
|
msgID, err := syncSender.SendMessageWithID(ctx, msg)
|
||||||
if err == nil && msgID != "" {
|
if err == nil && msgID != "" {
|
||||||
return msgID, nil
|
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)
|
logger.WarnCF("manager", "falling back to bus publish", nil)
|
||||||
m.bus.PublishOutbound(ctx, bus.OutboundMessage{
|
m.bus.PublishOutbound(ctx, msg)
|
||||||
Channel: channelName,
|
|
||||||
ChatID: chatID,
|
|
||||||
Content: content,
|
|
||||||
})
|
|
||||||
|
|
||||||
return "", fmt.Errorf("channel does not support returning message ID")
|
return "", fmt.Errorf("channel does not support returning message ID")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue