From 3bba6338ca68448b986bd4d9523f7a39928fa719 Mon Sep 17 00:00:00 2001 From: 2023478 <2694762037@qq.com> Date: Mon, 8 Jun 2026 15:53:42 +0800 Subject: [PATCH] fix: handle Telegram location messages --- pkg/channels/telegram/telegram.go | 7 +++++ pkg/channels/telegram/telegram_test.go | 36 ++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/pkg/channels/telegram/telegram.go b/pkg/channels/telegram/telegram.go index 8fe325b25..bb04261a6 100644 --- a/pkg/channels/telegram/telegram.go +++ b/pkg/channels/telegram/telegram.go @@ -1227,6 +1227,13 @@ func (c *TelegramChannel) collectTelegramMessageParts( if caption := strings.TrimSpace(msg.Caption); caption != "" { parts.content = append(parts.content, caption) } + if msg.Location != nil { + parts.content = append(parts.content, fmt.Sprintf( + "[User location: lat=%.6f, lng=%.6f]", + msg.Location.Latitude, + msg.Location.Longitude, + )) + } if len(msg.Photo) > 0 { photo := msg.Photo[len(msg.Photo)-1] photoPath := c.downloadPhoto(ctx, photo.FileID) diff --git a/pkg/channels/telegram/telegram_test.go b/pkg/channels/telegram/telegram_test.go index b52f2c9b2..6d243e180 100644 --- a/pkg/channels/telegram/telegram_test.go +++ b/pkg/channels/telegram/telegram_test.go @@ -1497,6 +1497,42 @@ func TestHandleMessage_EmptyContent_Ignored(t *testing.T) { } } +func TestHandleMessage_LocationForwardedAsText(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{ + MessageID: 3049, + Location: &telego.Location{ + Latitude: 35.197713, + Longitude: 136.885705, + }, + Chat: telego.Chat{ + ID: 456, + Type: "private", + }, + From: &telego.User{ + ID: 789, + FirstName: "User", + }, + } + + err := ch.handleMessage(context.Background(), msg) + require.NoError(t, err) + + select { + case inbound := <-messageBus.InboundChan(): + assert.Equal(t, "[User location: lat=35.197713, lng=136.885705]", inbound.Content) + assert.Equal(t, "3049", inbound.Context.MessageID) + case <-time.After(time.Second): + t.Fatal("timed out waiting for location message") + } +} + func TestHandleMessage_MediaGroupCombinesCaptionMessages(t *testing.T) { messageBus, ch := newMediaGroupTestChannel(10 * time.Millisecond) base := testMediaGroupMessage("album-1")