1
0
Fork 0
miniflux/integration/integration.go

164 lines
5.6 KiB
Go
Raw Normal View History

// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
2017-12-03 00:12:03 -05:00
2018-08-25 00:51:50 -04:00
package integration // import "miniflux.app/integration"
2017-12-03 00:12:03 -05:00
import (
2018-08-25 00:51:50 -04:00
"miniflux.app/config"
2022-04-20 22:44:47 -04:00
"miniflux.app/integration/espial"
2018-08-25 00:51:50 -04:00
"miniflux.app/integration/instapaper"
2022-05-23 11:53:06 -04:00
"miniflux.app/integration/linkding"
2022-10-14 11:18:44 -04:00
"miniflux.app/integration/matrixbot"
2023-07-07 18:20:14 -04:00
"miniflux.app/integration/notion"
2018-08-25 00:51:50 -04:00
"miniflux.app/integration/nunuxkeeper"
"miniflux.app/integration/pinboard"
"miniflux.app/integration/pocket"
2023-07-27 23:51:44 -04:00
"miniflux.app/integration/readwise"
2021-09-07 23:04:22 -04:00
"miniflux.app/integration/telegrambot"
2018-08-25 00:51:50 -04:00
"miniflux.app/integration/wallabag"
"miniflux.app/logger"
"miniflux.app/model"
2017-12-03 00:12:03 -05:00
)
// SendEntry sends the entry to third-party providers when the user click on "Save".
func SendEntry(entry *model.Entry, integration *model.Integration) {
2017-12-03 00:12:03 -05:00
if integration.PinboardEnabled {
logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Pinboard", entry.ID, entry.URL, integration.UserID)
2017-12-03 00:12:03 -05:00
client := pinboard.NewClient(integration.PinboardToken)
2017-12-18 23:52:46 -05:00
err := client.AddBookmark(
entry.URL,
entry.Title,
integration.PinboardTags,
integration.PinboardMarkAsUnread,
)
2017-12-03 00:12:03 -05:00
if err != nil {
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
2017-12-03 00:12:03 -05:00
}
}
if integration.InstapaperEnabled {
logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Instapaper", entry.ID, entry.URL, integration.UserID)
2017-12-03 00:12:03 -05:00
client := instapaper.NewClient(integration.InstapaperUsername, integration.InstapaperPassword)
2017-12-18 23:52:46 -05:00
if err := client.AddURL(entry.URL, entry.Title); err != nil {
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
2017-12-18 23:52:46 -05:00
}
}
if integration.WallabagEnabled {
logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Wallabag", entry.ID, entry.URL, integration.UserID)
2017-12-18 23:52:46 -05:00
client := wallabag.NewClient(
integration.WallabagURL,
integration.WallabagClientID,
integration.WallabagClientSecret,
integration.WallabagUsername,
integration.WallabagPassword,
integration.WallabagOnlyURL,
2017-12-18 23:52:46 -05:00
)
2021-02-21 02:34:07 -05:00
if err := client.AddEntry(entry.URL, entry.Title, entry.Content); err != nil {
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
2017-12-03 00:12:03 -05:00
}
}
2018-02-25 14:49:08 -05:00
2023-07-07 18:20:14 -04:00
if integration.NotionEnabled {
logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Notion", entry.ID, entry.URL, integration.UserID)
client := notion.NewClient(
integration.NotionToken,
integration.NotionPageID,
)
if err := client.AddEntry(entry.URL, entry.Title); err != nil {
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
}
}
2018-02-25 14:49:08 -05:00
if integration.NunuxKeeperEnabled {
logger.Debug("[Integration] Sending Entry #%d %q for User #%d to NunuxKeeper", entry.ID, entry.URL, integration.UserID)
2018-02-25 14:49:08 -05:00
client := nunuxkeeper.NewClient(
integration.NunuxKeeperURL,
integration.NunuxKeeperAPIKey,
)
if err := client.AddEntry(entry.URL, entry.Title, entry.Content); err != nil {
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
2018-02-25 14:49:08 -05:00
}
}
2018-05-20 16:31:56 -04:00
2022-04-20 22:44:47 -04:00
if integration.EspialEnabled {
logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Espial", entry.ID, entry.URL, integration.UserID)
client := espial.NewClient(
integration.EspialURL,
integration.EspialAPIKey,
)
if err := client.AddEntry(entry.URL, entry.Title, entry.Content, integration.EspialTags); err != nil {
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
}
}
2018-05-20 16:31:56 -04:00
if integration.PocketEnabled {
logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Pocket", entry.ID, entry.URL, integration.UserID)
client := pocket.NewClient(config.Opts.PocketConsumerKey(integration.PocketConsumerKey), integration.PocketAccessToken)
2018-05-20 16:31:56 -04:00
if err := client.AddURL(entry.URL, entry.Title); err != nil {
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
}
}
2022-05-23 11:53:06 -04:00
if integration.LinkdingEnabled {
logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Linkding", entry.ID, entry.URL, integration.UserID)
client := linkding.NewClient(
integration.LinkdingURL,
integration.LinkdingAPIKey,
integration.LinkdingTags,
integration.LinkdingMarkAsUnread,
2022-05-23 11:53:06 -04:00
)
if err := client.AddEntry(entry.Title, entry.URL); err != nil {
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
}
}
2023-07-27 23:51:44 -04:00
if integration.ReadwiseEnabled {
logger.Debug("[Integration] Sending Entry #%d %q for User #%d to Readwise Reader", entry.ID, entry.URL, integration.UserID)
client := readwise.NewClient(
integration.ReadwiseAPIKey,
)
if err := client.AddEntry(entry.URL); err != nil {
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
}
}
2017-12-03 00:12:03 -05:00
}
2021-09-07 23:04:22 -04:00
2022-10-14 11:18:44 -04:00
// PushEntries pushes an entry array to third-party providers during feed refreshes.
func PushEntries(entries model.Entries, integration *model.Integration) {
if integration.MatrixBotEnabled {
logger.Debug("[Integration] Sending %d entries for User #%d to Matrix", len(entries), integration.UserID)
err := matrixbot.PushEntries(entries, integration.MatrixBotURL, integration.MatrixBotUser, integration.MatrixBotPassword, integration.MatrixBotChatID)
if err != nil {
logger.Error("[Integration] push entries to matrix bot failed: %v", err)
}
}
}
// PushEntry pushes an entry to third-party providers during feed refreshes.
2021-09-07 23:04:22 -04:00
func PushEntry(entry *model.Entry, integration *model.Integration) {
if integration.TelegramBotEnabled {
logger.Debug("[Integration] Sending Entry %q for User #%d to Telegram", entry.URL, integration.UserID)
2021-09-07 23:04:22 -04:00
err := telegrambot.PushEntry(entry, integration.TelegramBotToken, integration.TelegramBotChatID)
if err != nil {
logger.Error("[Integration] push entry to telegram bot failed: %v", err)
}
}
}