refactor(manager): update SendMessageWithID to accept bus.OutboundMessage
This commit is contained in:
parent
eeabdd098f
commit
e938241c0d
2 changed files with 9 additions and 12 deletions
|
|
@ -411,7 +411,11 @@ func (al *AgentLoop) bindAdvancedMessageManagers(cm *channels.Manager) {
|
||||||
advancedManager.SetCallbacks(
|
advancedManager.SetCallbacks(
|
||||||
// sendPlaceholder
|
// sendPlaceholder
|
||||||
func(channelName, chatID, content string) (string, error) {
|
func(channelName, chatID, content string) (string, error) {
|
||||||
return cm.SendMessageWithID(context.Background(), channelName, chatID, content)
|
return cm.SendMessageWithID(context.Background(), bus.OutboundMessage{
|
||||||
|
Channel: channelName,
|
||||||
|
ChatID: chatID,
|
||||||
|
Content: content,
|
||||||
|
})
|
||||||
},
|
},
|
||||||
// editMessage
|
// editMessage
|
||||||
func(channelName, chatID, messageID, content string) error {
|
func(channelName, chatID, messageID, content string) error {
|
||||||
|
|
|
||||||
|
|
@ -837,16 +837,10 @@ func (m *Manager) SendToChannel(ctx context.Context, channelName, chatID, conten
|
||||||
// SendMessageWithID sends a message synchronously via the channel's native API if supported,
|
// SendMessageWithID sends a message synchronously via the channel's native API if supported,
|
||||||
// returning the platform-specific message ID. If the channel does not support SyncSender,
|
// returning the platform-specific message ID. If the channel does not support SyncSender,
|
||||||
// it falls back to the async bus and returns an error.
|
// it falls back to the async bus and returns an error.
|
||||||
func (m *Manager) SendMessageWithID(ctx context.Context, channelName, chatID, content string) (string, error) {
|
func (m *Manager) SendMessageWithID(ctx context.Context, msg bus.OutboundMessage) (string, error) {
|
||||||
ch, ok := m.GetChannel(channelName)
|
ch, ok := m.GetChannel(msg.Channel)
|
||||||
if !ok {
|
if !ok {
|
||||||
return "", fmt.Errorf("channel %s not found", channelName)
|
return "", fmt.Errorf("channel %s not found", msg.Channel)
|
||||||
}
|
|
||||||
|
|
||||||
msg := bus.OutboundMessage{
|
|
||||||
Channel: channelName,
|
|
||||||
ChatID: chatID,
|
|
||||||
Content: content,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if syncSender, ok := ch.(SyncSender); ok {
|
if syncSender, ok := ch.(SyncSender); ok {
|
||||||
|
|
@ -855,8 +849,7 @@ func (m *Manager) SendMessageWithID(ctx context.Context, channelName, chatID, co
|
||||||
return msgID, nil
|
return msgID, nil
|
||||||
}
|
}
|
||||||
logger.ErrorCF("manager", "SendMessageWithID failed", map[string]any{"error": err, "msgID": msgID})
|
logger.ErrorCF("manager", "SendMessageWithID failed", map[string]any{"error": err, "msgID": msgID})
|
||||||
} else {
|
logger.WarnCF("manager", "channel does not implement SyncSender", map[string]any{"channel": msg.Channel})
|
||||||
logger.WarnCF("manager", "channel does not implement SyncSender", map[string]any{"channel": channelName})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.WarnCF("manager", "falling back to bus publish", nil)
|
logger.WarnCF("manager", "falling back to bus publish", nil)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue