Skip to content

Commit

Permalink
Use HTML a tag for cleaner messages
Browse files Browse the repository at this point in the history
  • Loading branch information
minhdanh committed Dec 9, 2022
1 parent d397e95 commit 886c180
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pkg/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ func (t *TelegramClient) SendMessageForItem(item interface{}, url string, messag
}

func (t *TelegramClient) sendMessageForRSSItem(item *gofeed.Item, url string, messagePrefix string, telegramChannel string) (tgbotapi.Message, error) {
msgBody := strings.TrimSpace(item.Title) + "\n" + url
msgBody := strings.TrimSpace(item.Title)
if url != "" {
msgBody = "<a href=\"" + url + "\">" + msgBody + "</a>"
}
if messagePrefix != "" {
msgBody = "<strong>" + messagePrefix + "</strong>" + ": " + msgBody
}
Expand All @@ -62,12 +65,15 @@ func (t *TelegramClient) sendMessageForRSSItem(item *gofeed.Item, url string, me
}

func (t *TelegramClient) sendMessageForHNItem(item hackernews.HNItem, url string) (tgbotapi.Message, error) {
msgBody := "<strong>HackerNews</strong>: " + item.Title
if url != "" {
msgBody += "\n" + url
}
msgBody := "<strong>HackerNews</strong>: "
if t.YcombinatorLink {
msgBody += "\n" + "https://news.ycombinator.com/item?id=" + strconv.Itoa(item.ID)
msgBody = "<strong><a href=\"https://news.ycombinator.com/item?id=" + strconv.Itoa(item.ID) + "\">HackerNews</a></strong>: "
}

if url != "" {
msgBody += "<a href=\"" + url + "\">" + item.Title + "</a>"
} else {
msgBody += item.Title
}
msg := tgbotapi.NewMessageToChannel(t.TelegramChannel, msgBody)
msg.DisableWebPagePreview = t.TelegramPreviewLink
Expand Down

0 comments on commit 886c180

Please sign in to comment.