mirror of
https://github.com/miniflux/v2.git
synced 2025-08-26 18:21:01 +00:00
Minor improvements in integration package
This commit is contained in:
parent
34dd358eb0
commit
49119eff00
16 changed files with 57 additions and 108 deletions
|
@ -1,4 +1,8 @@
|
|||
package telegrambot
|
||||
// Copyright 2021 Frédéric Guillot. All rights reserved.
|
||||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package telegrambot // import "miniflux.app/integration/telegrambot"
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
@ -14,27 +18,25 @@ import (
|
|||
func PushEntry(entry *model.Entry, botToken, chatID string) error {
|
||||
bot, err := tgbotapi.NewBotAPI(botToken)
|
||||
if err != nil {
|
||||
return fmt.Errorf("telegrambot: create bot failed: %w", err)
|
||||
return fmt.Errorf("telegrambot: bot creation failed: %w", err)
|
||||
}
|
||||
|
||||
t, err := template.New("message").Parse("{{ .Title }}\n<a href=\"{{ .URL }}\">{{ .URL }}</a>")
|
||||
tpl, err := template.New("message").Parse("{{ .Title }}\n<a href=\"{{ .URL }}\">{{ .URL }}</a>")
|
||||
if err != nil {
|
||||
return fmt.Errorf("telegrambot: parse template failed: %w", err)
|
||||
return fmt.Errorf("telegrambot: template parsing failed: %w", err)
|
||||
}
|
||||
|
||||
var result bytes.Buffer
|
||||
|
||||
err = t.Execute(&result, entry)
|
||||
if err != nil {
|
||||
return fmt.Errorf("telegrambot: execute template failed: %w", err)
|
||||
if err := tpl.Execute(&result, entry); err != nil {
|
||||
return fmt.Errorf("telegrambot: template execution failed: %w", err)
|
||||
}
|
||||
|
||||
chatId, _ := strconv.ParseInt(chatID, 10, 64)
|
||||
msg := tgbotapi.NewMessage(chatId, result.String())
|
||||
chatIDInt, _ := strconv.ParseInt(chatID, 10, 64)
|
||||
msg := tgbotapi.NewMessage(chatIDInt, result.String())
|
||||
msg.ParseMode = tgbotapi.ModeHTML
|
||||
msg.DisableWebPagePreview = false
|
||||
if _, err := bot.Send(msg); err != nil {
|
||||
return fmt.Errorf("telegrambot: send message failed: %w", err)
|
||||
return fmt.Errorf("telegrambot: sending message failed: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue