From aee1d54ee71350d1a4744428ec0343f7a60c15e9 Mon Sep 17 00:00:00 2001 From: Law Zava Date: Mon, 20 Apr 2020 17:10:33 +0200 Subject: [PATCH] :sparkles: Better formatting for telegram message --- broadcast/telegram.go | 34 ++++++++++++++++++++-------------- snapcraft.yaml | 2 +- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/broadcast/telegram.go b/broadcast/telegram.go index f50417b..16988b2 100644 --- a/broadcast/telegram.go +++ b/broadcast/telegram.go @@ -28,20 +28,35 @@ func (t Telegram) New() (Broadcast, error) { } func (t Telegram) Send(message Message) error { + type inlineKeyboard struct { + Text string `json:"text"` + URL string `json:"url"` + SwitchInlineQuery string `json:"switch_inline_query"` + } + + type replyMarkup struct { + InlineKeyboard [][]inlineKeyboard `json:"inline_keyboard"` + } + telegramMessage := struct { - ChatID string `json:"chat_id"` - ParseMode string `json:"parse_mode"` - Text string `json:"text"` + ChatID string `json:"chat_id"` + ParseMode string `json:"parse_mode"` + Text string `json:"text"` + ReplyMarkup replyMarkup `json:"reply_markup"` }{ ChatID: t.ChatID, ParseMode: "MarkdownV2", Text: fmt.Sprintf(`*%s* - *Link:* [%s](%s)`, +%s`, // empty line is intended escapeTelegramText(message.Title), escapeTelegramText(message.Link), - escapeTelegramLink(message.Link), ), + ReplyMarkup: replyMarkup{ + InlineKeyboard: [][]inlineKeyboard{ + {{Text: "Read", URL: message.Link}}, + }, + }, } requestBody, err := json.Marshal(telegramMessage) @@ -108,12 +123,3 @@ func escapeTelegramText(text string) string { return replacer.Replace(text) } - -func escapeTelegramLink(link string) string { - replacer := strings.NewReplacer( - ")", "\\)", - "\\", "\\\\", - ) - - return replacer.Replace(link) -} diff --git a/snapcraft.yaml b/snapcraft.yaml index 3ddc73e..c2e42e7 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -1,5 +1,5 @@ name: mynews -version: '1.1.7' +version: '1.1.8' summary: Personalized news feed parser & broadcast description: | Easily specify your RSS/Atom sources and broadcast preferences to get personalized news feed.