2023-06-19 17:42:47 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2021-09-07 23:28:41 -04:00
|
|
|
|
2023-08-10 22:46:45 -04:00
|
|
|
package telegrambot // import "miniflux.app/v2/internal/integration/telegrambot"
|
2021-09-07 23:04:22 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2023-08-10 22:46:45 -04:00
|
|
|
"miniflux.app/v2/internal/model"
|
2021-09-07 23:04:22 -04:00
|
|
|
)
|
|
|
|
|
2023-09-27 23:02:22 -04:00
|
|
|
func PushEntry(feed *model.Feed, entry *model.Entry, botToken, chatID string, topicID *int64, disableWebPagePreview, disableNotification bool, disableButtons bool) error {
|
2023-09-10 14:22:32 -04:00
|
|
|
formattedText := fmt.Sprintf(
|
2023-09-27 23:20:09 -04:00
|
|
|
`<a href=%q>%s</a>`,
|
2023-09-10 14:22:32 -04:00
|
|
|
entry.URL,
|
|
|
|
entry.Title,
|
|
|
|
)
|
|
|
|
|
|
|
|
message := &MessageRequest{
|
|
|
|
ChatID: chatID,
|
|
|
|
Text: formattedText,
|
|
|
|
ParseMode: HTMLFormatting,
|
|
|
|
DisableWebPagePreview: disableWebPagePreview,
|
|
|
|
DisableNotification: disableNotification,
|
2021-09-07 23:04:22 -04:00
|
|
|
}
|
|
|
|
|
2023-09-10 14:22:32 -04:00
|
|
|
if topicID != nil {
|
|
|
|
message.MessageThreadID = *topicID
|
2021-09-07 23:04:22 -04:00
|
|
|
}
|
|
|
|
|
2023-09-27 23:02:22 -04:00
|
|
|
if !disableButtons {
|
|
|
|
var markupRow []*InlineKeyboardButton
|
2021-09-07 23:04:22 -04:00
|
|
|
|
2023-09-27 23:20:09 -04:00
|
|
|
websiteURLButton := InlineKeyboardButton{Text: "Go to website", URL: feed.SiteURL}
|
|
|
|
markupRow = append(markupRow, &websiteURLButton)
|
|
|
|
|
|
|
|
articleURLButton := InlineKeyboardButton{Text: "Go to article", URL: entry.URL}
|
|
|
|
markupRow = append(markupRow, &articleURLButton)
|
2022-05-21 08:58:45 -04:00
|
|
|
|
2023-09-27 23:02:22 -04:00
|
|
|
if entry.CommentsURL != "" {
|
2023-09-27 23:20:09 -04:00
|
|
|
commentURLButton := InlineKeyboardButton{Text: "Comments", URL: entry.CommentsURL}
|
|
|
|
markupRow = append(markupRow, &commentURLButton)
|
2023-09-27 23:02:22 -04:00
|
|
|
}
|
2022-05-21 08:58:45 -04:00
|
|
|
|
2023-09-27 23:02:22 -04:00
|
|
|
message.ReplyMarkup = &InlineKeyboard{}
|
|
|
|
message.ReplyMarkup.InlineKeyboard = append(message.ReplyMarkup.InlineKeyboard, markupRow)
|
|
|
|
}
|
2021-09-07 23:04:22 -04:00
|
|
|
|
2023-09-10 14:22:32 -04:00
|
|
|
client := NewClient(botToken, chatID)
|
|
|
|
_, err := client.SendMessage(message)
|
|
|
|
return err
|
2021-09-07 23:04:22 -04:00
|
|
|
}
|