telegrambot.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. `<b>%s</b> - <a href=%q>%s</a>`,
  11. feed.Title,
  12. entry.URL,
  13. entry.Title,
  14. )
  15. message := &MessageRequest{
  16. ChatID: chatID,
  17. Text: formattedText,
  18. ParseMode: HTMLFormatting,
  19. DisableWebPagePreview: disableWebPagePreview,
  20. DisableNotification: disableNotification,
  21. }
  22. if topicID != nil {
  23. message.MessageThreadID = *topicID
  24. }
  25. if !disableButtons {
  26. var markupRow []*InlineKeyboardButton
  27. websiteURLButton := InlineKeyboardButton{Text: "Go to website", URL: feed.SiteURL}
  28. markupRow = append(markupRow, &websiteURLButton)
  29. articleURLButton := InlineKeyboardButton{Text: "Go to article", URL: entry.URL}
  30. markupRow = append(markupRow, &articleURLButton)
  31. if entry.CommentsURL != "" {
  32. commentURLButton := InlineKeyboardButton{Text: "Comments", URL: entry.CommentsURL}
  33. markupRow = append(markupRow, &commentURLButton)
  34. }
  35. message.ReplyMarkup = &InlineKeyboard{}
  36. message.ReplyMarkup.InlineKeyboard = append(message.ReplyMarkup.InlineKeyboard, markupRow)
  37. }
  38. client := NewClient(botToken, chatID)
  39. _, err := client.SendMessage(message)
  40. return err
  41. }