integration.go 7.2 KB

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