integration.go 4.2 KB

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