integration.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package integration // import "miniflux.app/integration"
  5. import (
  6. "miniflux.app/config"
  7. "miniflux.app/integration/espial"
  8. "miniflux.app/integration/instapaper"
  9. "miniflux.app/integration/linkding"
  10. "miniflux.app/integration/matrixbot"
  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.NunuxKeeperEnabled {
  56. logger.Debug("[Integration] Sending Entry #%d %q for User #%d to NunuxKeeper", entry.ID, entry.URL, integration.UserID)
  57. client := nunuxkeeper.NewClient(
  58. integration.NunuxKeeperURL,
  59. integration.NunuxKeeperAPIKey,
  60. )
  61. if err := client.AddEntry(entry.URL, entry.Title, entry.Content); err != nil {
  62. logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
  63. }
  64. }
  65. if integration.EspialEnabled {
  66. logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Espial", entry.ID, entry.URL, integration.UserID)
  67. client := espial.NewClient(
  68. integration.EspialURL,
  69. integration.EspialAPIKey,
  70. )
  71. if err := client.AddEntry(entry.URL, entry.Title, entry.Content, integration.EspialTags); err != nil {
  72. logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
  73. }
  74. }
  75. if integration.PocketEnabled {
  76. logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Pocket", entry.ID, entry.URL, integration.UserID)
  77. client := pocket.NewClient(config.Opts.PocketConsumerKey(integration.PocketConsumerKey), integration.PocketAccessToken)
  78. if err := client.AddURL(entry.URL, entry.Title); err != nil {
  79. logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
  80. }
  81. }
  82. if integration.LinkdingEnabled {
  83. logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Linkding", entry.ID, entry.URL, integration.UserID)
  84. client := linkding.NewClient(
  85. integration.LinkdingURL,
  86. integration.LinkdingAPIKey,
  87. )
  88. if err := client.AddEntry(entry.Title, entry.URL); err != nil {
  89. logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
  90. }
  91. }
  92. }
  93. // PushEntries pushes an entry array to third-party providers during feed refreshes.
  94. func PushEntries(entries model.Entries, integration *model.Integration) {
  95. if integration.MatrixBotEnabled {
  96. logger.Debug("[Integration] Sending %d entries for User #%d to Matrix", len(entries), integration.UserID)
  97. err := matrixbot.PushEntries(entries, integration.MatrixBotURL, integration.MatrixBotUser, integration.MatrixBotPassword, integration.MatrixBotChatID)
  98. if err != nil {
  99. logger.Error("[Integration] push entries to matrix bot failed: %v", err)
  100. }
  101. }
  102. }
  103. // PushEntry pushes an entry to third-party providers during feed refreshes.
  104. func PushEntry(entry *model.Entry, integration *model.Integration) {
  105. if integration.TelegramBotEnabled {
  106. logger.Debug("[Integration] Sending Entry %q for User #%d to Telegram", entry.URL, integration.UserID)
  107. err := telegrambot.PushEntry(entry, integration.TelegramBotToken, integration.TelegramBotChatID)
  108. if err != nil {
  109. logger.Error("[Integration] push entry to telegram bot failed: %v", err)
  110. }
  111. }
  112. }