mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-05-07 08:37:28 +08:00
Refine cron outbound fix with smaller implementation
This commit is contained in:
@@ -616,12 +616,16 @@ func (al *AgentLoop) prepareOutbound(msg bus.InboundMessage, response string) (b
|
|||||||
if al.shouldSuppressOutbound(msg, clean) {
|
if al.shouldSuppressOutbound(msg, clean) {
|
||||||
return bus.OutboundMessage{}, false
|
return bus.OutboundMessage{}, false
|
||||||
}
|
}
|
||||||
return bus.OutboundMessage{
|
outbound := bus.OutboundMessage{Channel: msg.Channel, ChatID: msg.ChatID, Content: clean, ReplyToID: strings.TrimSpace(replyToID)}
|
||||||
Channel: msg.Channel,
|
if msg.Channel == "system" {
|
||||||
ChatID: msg.ChatID,
|
if originChannel, originChatID, ok := strings.Cut(msg.ChatID, ":"); ok && strings.TrimSpace(originChannel) != "" {
|
||||||
Content: clean,
|
outbound.Channel = originChannel
|
||||||
ReplyToID: strings.TrimSpace(replyToID),
|
outbound.ChatID = originChatID
|
||||||
}, true
|
} else {
|
||||||
|
outbound.Channel = "cli"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return outbound, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (al *AgentLoop) ProcessDirect(ctx context.Context, content, sessionKey string) (string, error) {
|
func (al *AgentLoop) ProcessDirect(ctx context.Context, content, sessionKey string) (string, error) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"clawgo/pkg/bus"
|
"clawgo/pkg/bus"
|
||||||
"clawgo/pkg/config"
|
"clawgo/pkg/config"
|
||||||
@@ -107,6 +108,27 @@ func TestProcessSystemMessage_UsesOriginSessionKey(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestProcessInbound_SystemMessagePublishesToOriginChannel(t *testing.T) {
|
||||||
|
rp := &recordingProvider{}
|
||||||
|
loop := setupLoop(t, rp)
|
||||||
|
|
||||||
|
in := bus.InboundMessage{Channel: "system", SenderID: "cron", ChatID: "telegram:chat-1", Content: "system task"}
|
||||||
|
loop.processInbound(context.Background(), in)
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||||
|
defer cancel()
|
||||||
|
out, ok := loop.bus.SubscribeOutbound(ctx)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("expected outbound message")
|
||||||
|
}
|
||||||
|
if out.Channel != "telegram" {
|
||||||
|
t.Fatalf("expected outbound channel telegram, got %q", out.Channel)
|
||||||
|
}
|
||||||
|
if out.ChatID != "chat-1" {
|
||||||
|
t.Fatalf("expected outbound chat_id chat-1, got %q", out.ChatID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func summarizeUsers(msgs []providers.Message) []string {
|
func summarizeUsers(msgs []providers.Message) []string {
|
||||||
out := []string{}
|
out := []string{}
|
||||||
for _, m := range msgs {
|
for _, m := range msgs {
|
||||||
|
|||||||
Reference in New Issue
Block a user