Archived
1
0
Fork 0

Use markdown in Telegram

Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
Julien Riou 2021-03-24 12:51:58 +01:00
parent 93a37f2f89
commit 9ef7ac928e
No known key found for this signature in database
GPG key ID: FF42D23B580C89F7

View file

@ -56,7 +56,12 @@ func (n *TelegramNotifier) NotifyWhenAvailable(shopName string, productName stri
// send message to telegram // send message to telegram
formattedPrice := formatPrice(productPrice, productCurrency) formattedPrice := formatPrice(productPrice, productCurrency)
message := fmt.Sprintf("🟢 %s: %s for %s is available at %s", shopName, productName, formattedPrice, productURL) rawMessage := `*Name:* %s
*Retailer:* %s
*Price:* %s
*URL*: [go to website](%s)
*Date/Time:* %s`
message := fmt.Sprintf(rawMessage, productName, shopName, formattedPrice, productURL, time.Now().UTC().Format("2006-01-02 15:04:05 (-0700)"))
messageID, err := n.sendMessage(message, 0) messageID, err := n.sendMessage(message, 0)
if err != nil { if err != nil {
return err return err
@ -88,7 +93,7 @@ func (n *TelegramNotifier) NotifyWhenNotAvailable(productURL string, duration ti
} }
// format message // format message
text := fmt.Sprintf("🔴 And it's gone (%s)", duration) text := fmt.Sprintf("And it's gone (%s)", duration)
// send reply on telegram // send reply on telegram
_, err := n.sendMessage(text, m.MessageID) _, err := n.sendMessage(text, m.MessageID)
@ -115,6 +120,7 @@ func (n *TelegramNotifier) sendMessage(text string, reply int) (int, error) {
request = telegram.NewMessageToChannel(n.channelName, text) request = telegram.NewMessageToChannel(n.channelName, text)
} }
request.DisableWebPagePreview = true request.DisableWebPagePreview = true
request.ParseMode = telegram.ModeMarkdown
if reply != 0 { if reply != 0 {
request.ReplyToMessageID = reply request.ReplyToMessageID = reply