integration.go 5.2 KB

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