integration.go 6.1 KB

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