mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
9c31b0ca95
* fix: Fixed the bug where the bus was closed and consumers had unfinished messages. * fix: remove unnecessary blank line in Close method * fix: refactor message bus and channel handling for improved performance and reliability * fix: improve message handling and bus closure logic for better reliability * fix: reduce sleep duration in agent loop for improved responsiveness * fix the test case
49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
package telegram
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/mymmrac/telego"
|
|
|
|
"github.com/sipeed/picoclaw/pkg/bus"
|
|
"github.com/sipeed/picoclaw/pkg/channels"
|
|
)
|
|
|
|
func TestHandleMessage_DoesNotConsumeGenericCommandsLocally(t *testing.T) {
|
|
messageBus := bus.NewMessageBus()
|
|
ch := &TelegramChannel{
|
|
BaseChannel: channels.NewBaseChannel("telegram", nil, messageBus, nil),
|
|
chatIDs: make(map[string]int64),
|
|
ctx: context.Background(),
|
|
}
|
|
|
|
msg := &telego.Message{
|
|
Text: "/new",
|
|
MessageID: 9,
|
|
Chat: telego.Chat{
|
|
ID: 123,
|
|
Type: "private",
|
|
},
|
|
From: &telego.User{
|
|
ID: 42,
|
|
FirstName: "Alice",
|
|
},
|
|
}
|
|
|
|
if err := ch.handleMessage(context.Background(), msg); err != nil {
|
|
t.Fatalf("handleMessage error: %v", err)
|
|
}
|
|
|
|
inbound, ok := <-messageBus.InboundChan()
|
|
if !ok {
|
|
t.Fatal("expected inbound message to be forwarded")
|
|
}
|
|
if inbound.Channel != "telegram" {
|
|
t.Fatalf("channel=%q", inbound.Channel)
|
|
}
|
|
if inbound.Content != "/new" {
|
|
t.Fatalf("content=%q", inbound.Content)
|
|
}
|
|
}
|