mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
Merge pull request #3052 from wzg-gie/fix/telegram-location-message
fix: handle Telegram location messages
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user