integration.go 3.3 KB

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