telegrambot.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package telegrambot // import "miniflux.app/v2/internal/integration/telegrambot"
  4. import (
  5. "fmt"
  6. "miniflux.app/v2/internal/model"
  7. )
  8. func PushEntry(feed *model.Feed, entry *model.Entry, botToken, chatID string, topicID *int64, disableWebPagePreview, disableNotification bool, disableButtons bool) error {
  9. formattedText := fmt.Sprintf(
  10. `<a href=%q>%s</a>`,
  11. entry.URL,
  12. entry.Title,
  13. )
  14. message := &MessageRequest{
  15. ChatID: chatID,
  16. Text: formattedText,
  17. ParseMode: HTMLFormatting,
  18. DisableWebPagePreview: disableWebPagePreview,
  19. DisableNotification: disableNotification,
  20. }
  21. if topicID != nil {
  22. message.MessageThreadID = *topicID
  23. }
  24. if !disableButtons {
  25. var markupRow []*InlineKeyboardButton
  26. websiteURLButton := InlineKeyboardButton{Text: "Go to website", URL: feed.SiteURL}
  27. markupRow = append(markupRow, &websiteURLButton)
  28. articleURLButton := InlineKeyboardButton{Text: "Go to article", URL: entry.URL}
  29. markupRow = append(markupRow, &articleURLButton)
  30. if entry.CommentsURL != "" {
  31. commentURLButton := InlineKeyboardButton{Text: "Comments", URL: entry.CommentsURL}
  32. markupRow = append(markupRow, &commentURLButton)
  33. }
  34. message.ReplyMarkup = &InlineKeyboard{}
  35. message.ReplyMarkup.InlineKeyboard = append(message.ReplyMarkup.InlineKeyboard, markupRow)
  36. }
  37. client := NewClient(botToken, chatID)
  38. _, err := client.SendMessage(message)
  39. return err
  40. }