fix: agent triggered on empty message in telegram (#1927)
* add handler for empty message * fix undefined: time * fix linter * update test to remove 100ms wait time since the handleMessage publishes synchronously
This commit is contained in:
parent
6aff5b7ccd
commit
08fa9bb64b
2 changed files with 37 additions and 1 deletions
|
|
@ -642,8 +642,12 @@ func (c *TelegramChannel) handleMessage(ctx context.Context, message *telego.Mes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if content == "" && len(mediaPaths) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if content == "" {
|
if content == "" {
|
||||||
content = "[empty message]"
|
content = "[media only]"
|
||||||
}
|
}
|
||||||
|
|
||||||
// In group chats, apply unified group trigger filtering
|
// In group chats, apply unified group trigger filtering
|
||||||
|
|
|
||||||
|
|
@ -641,3 +641,35 @@ func TestHandleMessage_ReplyThread_NonForum_NoIsolation(t *testing.T) {
|
||||||
assert.Empty(t, inbound.Metadata["parent_peer_kind"])
|
assert.Empty(t, inbound.Metadata["parent_peer_kind"])
|
||||||
assert.Empty(t, inbound.Metadata["parent_peer_id"])
|
assert.Empty(t, inbound.Metadata["parent_peer_id"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHandleMessage_EmptyContent_Ignored(t *testing.T) {
|
||||||
|
messageBus := bus.NewMessageBus()
|
||||||
|
ch := &TelegramChannel{
|
||||||
|
BaseChannel: channels.NewBaseChannel("telegram", nil, messageBus, nil),
|
||||||
|
chatIDs: make(map[string]int64),
|
||||||
|
ctx: context.Background(),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Service message with no text/caption/media (like ForumTopicCreated)
|
||||||
|
msg := &telego.Message{
|
||||||
|
MessageID: 123,
|
||||||
|
Chat: telego.Chat{
|
||||||
|
ID: 456,
|
||||||
|
Type: "group",
|
||||||
|
},
|
||||||
|
From: &telego.User{
|
||||||
|
ID: 789,
|
||||||
|
FirstName: "User",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := ch.handleMessage(context.Background(), msg)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Should NOT publish to message bus
|
||||||
|
select {
|
||||||
|
case <-messageBus.InboundChan():
|
||||||
|
t.Fatal("Empty message should not be published to message bus")
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue