4 files changed,
20 insertions(+),
7 deletions(-)
Author:
Oleksandr Smirnov
olexsmir@gmail.com
Committed at:
2026-04-22 20:13:38 +0300
Authored at:
2026-04-22 19:56:22 +0300
Change ID:
tkmkqzytuynvyslrulrknlswksyrznqz
Parent:
20e54e6
M
sources/telegram/sdk.go
··· 56 56 From *User `json:"from"` 57 57 Chat *Chat `json:"chat"` 58 58 Text string `json:"text"` 59 + Caption string `json:"caption,omitempty"` 59 60 Date int64 `json:"date"` 60 61 Photo []PhotoSize `json:"photo,omitempty"` 61 62 PhotoBase64 string `json:"photo_base64,omitempty"`
M
sources/telegram/sdk_test.go
··· 32 32 "message": { 33 33 "message_id": 7, 34 34 "date": 1713790000, 35 - "text": "photo msg", 35 + "caption": "photo msg", 36 36 "photo": [ 37 37 {"file_id": "small", "width": 90, "height": 90, "file_size": 100}, 38 38 {"file_id": "large", "width": 1280, "height": 720, "file_size": 2048} ··· 58 58 59 59 msg := updates[0].Message 60 60 is.Equal(t, "large", seenGetFileForID) 61 + is.Equal(t, "photo msg", msg.Caption) 61 62 is.Equal(t, base64.StdEncoding.EncodeToString(pngData), msg.PhotoBase64) 62 63 is.Equal(t, "image/png", msg.PhotoMIMEType) 63 64 }
M
sources/telegram/telegram.go
··· 86 86 87 87 for _, u := range updates { 88 88 if u.Message != nil && u.Message.From != nil { 89 - slog.InfoContext(ctx, "message from", "user_id", u.Message.From.ID, "username", u.Message.From.Username, "msg", u.Message.Text) 89 + slog.InfoContext(ctx, "message from", "user_id", u.Message.From.ID, "username", u.Message.From.Username, "msg", messageText(u.Message)) 90 90 } 91 91 92 92 if u.Message == nil || u.Message.From == nil || u.Message.From.ID != t.allowedID { ··· 153 153 154 154 func feedEntryFromMessage(m *Message) app.FeedEntry { 155 155 updated := time.Unix(m.Date, 0) 156 + text := messageText(m) 156 157 if m.PhotoBase64 == "" { 157 - title := m.Text 158 + title := text 158 159 if len(title) > 64 { 159 160 title = title[:64] + "..." 160 161 } 161 162 return app.FeedEntry{ 162 163 Title: title, 163 164 ID: fmt.Sprintf("telegram-%d", m.MessageID), 164 - Content: m.Text, 165 + Content: text, 165 166 Updated: updated, 166 167 } 167 168 } 168 169 169 170 parts := make([]string, 0, 2) 170 - if text := strings.TrimSpace(m.Text); text != "" { 171 - parts = append(parts, "<p>"+html.EscapeString(text)+"</p>") 171 + if t := strings.TrimSpace(text); t != "" { 172 + parts = append(parts, "<p>"+html.EscapeString(t)+"</p>") 172 173 } 173 174 mimeType := m.PhotoMIMEType 174 175 if mimeType == "" { ··· 184 185 Updated: updated, 185 186 } 186 187 } 188 + 189 +func messageText(m *Message) string { 190 + if m == nil { 191 + return "" 192 + } 193 + if caption := strings.TrimSpace(m.Caption); caption != "" { 194 + return m.Caption 195 + } 196 + return m.Text 197 +}
M
sources/telegram/telegram_test.go
··· 11 11 func TestFeedEntryFromMessageWithImage(t *testing.T) { 12 12 msg := &Message{ 13 13 MessageID: 42, 14 - Text: "hello <world>", 14 + Caption: "hello <world>", 15 15 Date: time.Date(2026, 4, 22, 19, 38, 0, 0, time.UTC).Unix(), 16 16 PhotoBase64: "YWJj", 17 17 PhotoMIMEType: "image/png",