integration.go 3.8 KB

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