4
0

integration.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package integration // import "miniflux.app/integration"
  4. import (
  5. "miniflux.app/config"
  6. "miniflux.app/integration/espial"
  7. "miniflux.app/integration/instapaper"
  8. "miniflux.app/integration/linkding"
  9. "miniflux.app/integration/matrixbot"
  10. "miniflux.app/integration/notion"
  11. "miniflux.app/integration/nunuxkeeper"
  12. "miniflux.app/integration/pinboard"
  13. "miniflux.app/integration/pocket"
  14. "miniflux.app/integration/readwise"
  15. "miniflux.app/integration/telegrambot"
  16. "miniflux.app/integration/wallabag"
  17. "miniflux.app/logger"
  18. "miniflux.app/model"
  19. )
  20. // SendEntry sends the entry to third-party providers when the user click on "Save".
  21. func SendEntry(entry *model.Entry, integration *model.Integration) {
  22. if integration.PinboardEnabled {
  23. logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Pinboard", entry.ID, entry.URL, integration.UserID)
  24. client := pinboard.NewClient(integration.PinboardToken)
  25. err := client.AddBookmark(
  26. entry.URL,
  27. entry.Title,
  28. integration.PinboardTags,
  29. integration.PinboardMarkAsUnread,
  30. )
  31. if err != nil {
  32. logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
  33. }
  34. }
  35. if integration.InstapaperEnabled {
  36. logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Instapaper", entry.ID, entry.URL, integration.UserID)
  37. client := instapaper.NewClient(integration.InstapaperUsername, integration.InstapaperPassword)
  38. if err := client.AddURL(entry.URL, entry.Title); err != nil {
  39. logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
  40. }
  41. }
  42. if integration.WallabagEnabled {
  43. logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Wallabag", entry.ID, entry.URL, integration.UserID)
  44. client := wallabag.NewClient(
  45. integration.WallabagURL,
  46. integration.WallabagClientID,
  47. integration.WallabagClientSecret,
  48. integration.WallabagUsername,
  49. integration.WallabagPassword,
  50. integration.WallabagOnlyURL,
  51. )
  52. if err := client.AddEntry(entry.URL, entry.Title, entry.Content); err != nil {
  53. logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
  54. }
  55. }
  56. if integration.NotionEnabled {
  57. logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Notion", entry.ID, entry.URL, integration.UserID)
  58. client := notion.NewClient(
  59. integration.NotionToken,
  60. integration.NotionPageID,
  61. )
  62. if err := client.AddEntry(entry.URL, entry.Title); err != nil {
  63. logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
  64. }
  65. }
  66. if integration.NunuxKeeperEnabled {
  67. logger.Debug("[Integration] Sending Entry #%d %q for User #%d to NunuxKeeper", entry.ID, entry.URL, integration.UserID)
  68. client := nunuxkeeper.NewClient(
  69. integration.NunuxKeeperURL,
  70. integration.NunuxKeeperAPIKey,
  71. )
  72. if err := client.AddEntry(entry.URL, entry.Title, entry.Content); err != nil {
  73. logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
  74. }
  75. }
  76. if integration.EspialEnabled {
  77. logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Espial", entry.ID, entry.URL, integration.UserID)
  78. client := espial.NewClient(
  79. integration.EspialURL,
  80. integration.EspialAPIKey,
  81. )
  82. if err := client.AddEntry(entry.URL, entry.Title, entry.Content, integration.EspialTags); err != nil {
  83. logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
  84. }
  85. }
  86. if integration.PocketEnabled {
  87. logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Pocket", entry.ID, entry.URL, integration.UserID)
  88. client := pocket.NewClient(config.Opts.PocketConsumerKey(integration.PocketConsumerKey), integration.PocketAccessToken)
  89. if err := client.AddURL(entry.URL, entry.Title); err != nil {
  90. logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
  91. }
  92. }
  93. if integration.LinkdingEnabled {
  94. logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Linkding", entry.ID, entry.URL, integration.UserID)
  95. client := linkding.NewClient(
  96. integration.LinkdingURL,
  97. integration.LinkdingAPIKey,
  98. integration.LinkdingTags,
  99. integration.LinkdingMarkAsUnread,
  100. )
  101. if err := client.AddEntry(entry.Title, entry.URL); err != nil {
  102. logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
  103. }
  104. }
  105. if integration.ReadwiseEnabled {
  106. logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Readwise Reader", entry.ID, entry.URL, integration.UserID)
  107. client := readwise.NewClient(
  108. integration.ReadwiseAPIKey,
  109. )
  110. if err := client.AddEntry(entry.URL); err != nil {
  111. logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
  112. }
  113. }
  114. }
  115. // PushEntries pushes an entry array to third-party providers during feed refreshes.
  116. func PushEntries(entries model.Entries, integration *model.Integration) {
  117. if integration.MatrixBotEnabled {
  118. logger.Debug("[Integration] Sending %d entries for User #%d to Matrix", len(entries), integration.UserID)
  119. err := matrixbot.PushEntries(entries, integration.MatrixBotURL, integration.MatrixBotUser, integration.MatrixBotPassword, integration.MatrixBotChatID)
  120. if err != nil {
  121. logger.Error("[Integration] push entries to matrix bot failed: %v", err)
  122. }
  123. }
  124. }
  125. // PushEntry pushes an entry to third-party providers during feed refreshes.
  126. func PushEntry(entry *model.Entry, integration *model.Integration) {
  127. if integration.TelegramBotEnabled {
  128. logger.Debug("[Integration] Sending Entry %q for User #%d to Telegram", entry.URL, integration.UserID)
  129. err := telegrambot.PushEntry(entry, integration.TelegramBotToken, integration.TelegramBotChatID)
  130. if err != nil {
  131. logger.Error("[Integration] push entry to telegram bot failed: %v", err)
  132. }
  133. }
  134. }