2017-12-03 06:12:03 +01:00
|
|
|
// Copyright 2017 Frédéric Guillot. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2018-08-25 06:51:50 +02:00
|
|
|
package integration // import "miniflux.app/integration"
|
2017-12-03 06:12:03 +01:00
|
|
|
|
|
|
|
import (
|
2018-08-25 06:51:50 +02:00
|
|
|
"miniflux.app/config"
|
|
|
|
"miniflux.app/integration/instapaper"
|
|
|
|
"miniflux.app/integration/nunuxkeeper"
|
|
|
|
"miniflux.app/integration/pinboard"
|
|
|
|
"miniflux.app/integration/pocket"
|
2021-09-08 05:04:22 +02:00
|
|
|
"miniflux.app/integration/telegrambot"
|
2018-08-25 06:51:50 +02:00
|
|
|
"miniflux.app/integration/wallabag"
|
|
|
|
"miniflux.app/logger"
|
|
|
|
"miniflux.app/model"
|
2017-12-03 06:12:03 +01:00
|
|
|
)
|
|
|
|
|
2021-09-08 05:28:41 +02:00
|
|
|
// SendEntry sends the entry to third-party providers when the user click on "Save".
|
2019-06-02 03:18:09 +02:00
|
|
|
func SendEntry(entry *model.Entry, integration *model.Integration) {
|
2017-12-03 06:12:03 +01:00
|
|
|
if integration.PinboardEnabled {
|
2021-09-08 05:28:41 +02:00
|
|
|
logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Pinboard", entry.ID, entry.URL, integration.UserID)
|
|
|
|
|
2017-12-03 06:12:03 +01:00
|
|
|
client := pinboard.NewClient(integration.PinboardToken)
|
2017-12-19 05:52:46 +01:00
|
|
|
err := client.AddBookmark(
|
|
|
|
entry.URL,
|
|
|
|
entry.Title,
|
|
|
|
integration.PinboardTags,
|
|
|
|
integration.PinboardMarkAsUnread,
|
|
|
|
)
|
|
|
|
|
2017-12-03 06:12:03 +01:00
|
|
|
if err != nil {
|
2018-04-30 02:58:09 +02:00
|
|
|
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
|
2017-12-03 06:12:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if integration.InstapaperEnabled {
|
2021-09-08 05:28:41 +02:00
|
|
|
logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Instapaper", entry.ID, entry.URL, integration.UserID)
|
|
|
|
|
2017-12-03 06:12:03 +01:00
|
|
|
client := instapaper.NewClient(integration.InstapaperUsername, integration.InstapaperPassword)
|
2017-12-19 05:52:46 +01:00
|
|
|
if err := client.AddURL(entry.URL, entry.Title); err != nil {
|
2018-04-30 02:58:09 +02:00
|
|
|
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
|
2017-12-19 05:52:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if integration.WallabagEnabled {
|
2021-09-08 05:28:41 +02:00
|
|
|
logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Wallabag", entry.ID, entry.URL, integration.UserID)
|
|
|
|
|
2017-12-19 05:52:46 +01:00
|
|
|
client := wallabag.NewClient(
|
|
|
|
integration.WallabagURL,
|
|
|
|
integration.WallabagClientID,
|
|
|
|
integration.WallabagClientSecret,
|
|
|
|
integration.WallabagUsername,
|
|
|
|
integration.WallabagPassword,
|
|
|
|
)
|
|
|
|
|
2021-02-21 08:34:07 +01:00
|
|
|
if err := client.AddEntry(entry.URL, entry.Title, entry.Content); err != nil {
|
2018-04-30 02:58:09 +02:00
|
|
|
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
|
2017-12-03 06:12:03 +01:00
|
|
|
}
|
|
|
|
}
|
2018-02-25 20:49:08 +01:00
|
|
|
|
|
|
|
if integration.NunuxKeeperEnabled {
|
2021-09-08 05:28:41 +02:00
|
|
|
logger.Debug("[Integration] Sending Entry #%d %q for User #%d to NunuxKeeper", entry.ID, entry.URL, integration.UserID)
|
|
|
|
|
2018-02-25 20:49:08 +01:00
|
|
|
client := nunuxkeeper.NewClient(
|
|
|
|
integration.NunuxKeeperURL,
|
|
|
|
integration.NunuxKeeperAPIKey,
|
|
|
|
)
|
|
|
|
|
|
|
|
if err := client.AddEntry(entry.URL, entry.Title, entry.Content); err != nil {
|
2018-04-30 02:58:09 +02:00
|
|
|
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
|
2018-02-25 20:49:08 +01:00
|
|
|
}
|
|
|
|
}
|
2018-05-20 22:31:56 +02:00
|
|
|
|
|
|
|
if integration.PocketEnabled {
|
2021-09-08 05:28:41 +02:00
|
|
|
logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Pocket", entry.ID, entry.URL, integration.UserID)
|
|
|
|
|
2019-06-02 03:18:09 +02:00
|
|
|
client := pocket.NewClient(config.Opts.PocketConsumerKey(integration.PocketConsumerKey), integration.PocketAccessToken)
|
2018-05-20 22:31:56 +02:00
|
|
|
if err := client.AddURL(entry.URL, entry.Title); err != nil {
|
|
|
|
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
|
|
|
|
}
|
|
|
|
}
|
2017-12-03 06:12:03 +01:00
|
|
|
}
|
2021-09-08 05:04:22 +02:00
|
|
|
|
2021-09-08 05:28:41 +02:00
|
|
|
// PushEntry pushes an entry to third-party providers during feed refreshes.
|
2021-09-08 05:04:22 +02:00
|
|
|
func PushEntry(entry *model.Entry, integration *model.Integration) {
|
|
|
|
if integration.TelegramBotEnabled {
|
2021-09-08 05:28:41 +02:00
|
|
|
logger.Debug("[Integration] Sending Entry %q for User #%d to Telegram", entry.URL, integration.UserID)
|
|
|
|
|
2021-09-08 05:04:22 +02:00
|
|
|
err := telegrambot.PushEntry(entry, integration.TelegramBotToken, integration.TelegramBotChatID)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("[Integration] push entry to telegram bot failed: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|