add handler for empty message

This commit is contained in:
Christoforus Surjoputro 2026-03-23 17:57:09 +07:00
parent 4e3769e989
commit 3122aed8b4
2 changed files with 38 additions and 1 deletions

View file

@ -629,8 +629,12 @@ func (c *TelegramChannel) handleMessage(ctx context.Context, message *telego.Mes
}
}
if content == "" && len(mediaPaths) == 0 {
return nil
}
if content == "" {
content = "[empty message]"
content = "[media only]"
}
// In group chats, apply unified group trigger filtering

View file

@ -641,3 +641,36 @@ func TestHandleMessage_ReplyThread_NonForum_NoIsolation(t *testing.T) {
assert.Empty(t, inbound.Metadata["parent_peer_kind"])
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")
case <-time.After(100 * time.Millisecond):
// nothing was published
}
}