miniflux/internal/integration/integration.go

231 lines
8.1 KiB
Go
Raw Normal View History

// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
2017-12-03 06:12:03 +01:00
package integration // import "miniflux.app/v2/internal/integration"
2017-12-03 06:12:03 +01:00
import (
"miniflux.app/v2/internal/config"
"miniflux.app/v2/internal/integration/apprise"
"miniflux.app/v2/internal/integration/espial"
"miniflux.app/v2/internal/integration/instapaper"
"miniflux.app/v2/internal/integration/linkding"
"miniflux.app/v2/internal/integration/matrixbot"
"miniflux.app/v2/internal/integration/notion"
"miniflux.app/v2/internal/integration/nunuxkeeper"
"miniflux.app/v2/internal/integration/pinboard"
"miniflux.app/v2/internal/integration/pocket"
"miniflux.app/v2/internal/integration/readwise"
2023-08-13 23:30:57 +02:00
"miniflux.app/v2/internal/integration/shaarli"
2023-08-13 21:48:29 +02:00
"miniflux.app/v2/internal/integration/shiori"
"miniflux.app/v2/internal/integration/telegrambot"
"miniflux.app/v2/internal/integration/wallabag"
2023-09-09 07:45:17 +02:00
"miniflux.app/v2/internal/integration/webhook"
"miniflux.app/v2/internal/logger"
"miniflux.app/v2/internal/model"
2017-12-03 06:12:03 +01: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 06:12:03 +01:00
if integration.PinboardEnabled {
2023-08-13 23:30:57 +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)
err := client.CreateBookmark(
2017-12-19 05:52:46 +01:00
entry.URL,
entry.Title,
integration.PinboardTags,
integration.PinboardMarkAsUnread,
)
2017-12-03 06:12:03 +01:00
if err != nil {
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
2017-12-03 06:12:03 +01:00
}
}
if integration.InstapaperEnabled {
2023-08-13 23:30:57 +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 {
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
2017-12-19 05:52:46 +01:00
}
}
if integration.WallabagEnabled {
2023-08-13 23:30:57 +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,
integration.WallabagOnlyURL,
2017-12-19 05:52:46 +01:00
)
if err := client.CreateEntry(entry.URL, entry.Title, entry.Content); err != nil {
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
2023-07-08 00:20:14 +02:00
if integration.NotionEnabled {
2023-08-13 23:30:57 +02:00
logger.Debug("[Integration] Sending entry #%d %q for user #%d to Notion", entry.ID, entry.URL, integration.UserID)
2023-07-08 00:20:14 +02:00
client := notion.NewClient(
integration.NotionToken,
integration.NotionPageID,
)
if err := client.UpdateDocument(entry.URL, entry.Title); err != nil {
2023-07-08 00:20:14 +02:00
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
}
}
2018-02-25 20:49:08 +01:00
if integration.NunuxKeeperEnabled {
2023-08-13 23:30:57 +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 {
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
2022-04-21 04:44:47 +02:00
if integration.EspialEnabled {
2023-08-13 23:30:57 +02:00
logger.Debug("[Integration] Sending entry #%d %q for user #%d to Espial", entry.ID, entry.URL, integration.UserID)
2022-04-21 04:44:47 +02:00
client := espial.NewClient(
integration.EspialURL,
integration.EspialAPIKey,
)
if err := client.CreateLink(entry.URL, entry.Title, integration.EspialTags); err != nil {
logger.Error("[Integration] Unable to send entry #%d to Espial for user #%d: %v", entry.ID, integration.UserID, err)
2022-04-21 04:44:47 +02:00
}
}
2018-05-20 22:31:56 +02:00
if integration.PocketEnabled {
2023-08-13 23:30:57 +02:00
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 22:31:56 +02:00
if err := client.AddURL(entry.URL, entry.Title); err != nil {
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
}
}
2022-05-23 17:53:06 +02:00
if integration.LinkdingEnabled {
2023-08-13 23:30:57 +02:00
logger.Debug("[Integration] Sending entry #%d %q for user #%d to Linkding", entry.ID, entry.URL, integration.UserID)
2022-05-23 17:53:06 +02:00
client := linkding.NewClient(
integration.LinkdingURL,
integration.LinkdingAPIKey,
integration.LinkdingTags,
integration.LinkdingMarkAsUnread,
2022-05-23 17:53:06 +02:00
)
if err := client.CreateBookmark(entry.URL, entry.Title); err != nil {
2022-05-23 17:53:06 +02:00
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
}
}
2023-07-28 05:51:44 +02:00
if integration.ReadwiseEnabled {
2023-08-13 23:30:57 +02:00
logger.Debug("[Integration] Sending entry #%d %q for user #%d to Readwise Reader", entry.ID, entry.URL, integration.UserID)
2023-07-28 05:51:44 +02:00
client := readwise.NewClient(
integration.ReadwiseAPIKey,
)
if err := client.CreateDocument(entry.URL); err != nil {
2023-07-28 05:51:44 +02:00
logger.Error("[Integration] UserID #%d: %v", integration.UserID, err)
}
}
2023-08-13 21:48:29 +02:00
if integration.ShioriEnabled {
2023-08-13 23:30:57 +02:00
logger.Debug("[Integration] Sending entry #%d %q for user #%d to Shiori", entry.ID, entry.URL, integration.UserID)
2023-08-13 21:48:29 +02:00
client := shiori.NewClient(
integration.ShioriURL,
integration.ShioriUsername,
integration.ShioriPassword,
)
if err := client.CreateBookmark(entry.URL, entry.Title); err != nil {
2023-08-13 21:48:29 +02:00
logger.Error("[Integration] Unable to send entry #%d to Shiori for user #%d: %v", entry.ID, integration.UserID, err)
}
}
2023-08-13 23:30:57 +02:00
if integration.ShaarliEnabled {
logger.Debug("[Integration] Sending entry #%d %q for user #%d to Shaarli", entry.ID, entry.URL, integration.UserID)
client := shaarli.NewClient(
integration.ShaarliURL,
integration.ShaarliAPISecret,
)
if err := client.CreateLink(entry.URL, entry.Title); err != nil {
2023-08-13 23:30:57 +02:00
logger.Error("[Integration] Unable to send entry #%d to Shaarli for user #%d: %v", entry.ID, integration.UserID, err)
}
}
2017-12-03 06:12:03 +01:00
}
2021-09-08 05:04:22 +02:00
2023-09-09 07:45:17 +02:00
// PushEntries pushes a list of entries to activated third-party providers during feed refreshes.
func PushEntries(feed *model.Feed, entries model.Entries, userIntegrations *model.Integration) {
if userIntegrations.MatrixBotEnabled {
logger.Debug("[Integration] Sending %d entries for user #%d to Matrix", len(entries), userIntegrations.UserID)
2022-10-14 17:18:44 +02:00
err := matrixbot.PushEntries(feed, entries, userIntegrations.MatrixBotURL, userIntegrations.MatrixBotUser, userIntegrations.MatrixBotPassword, userIntegrations.MatrixBotChatID)
2022-10-14 17:18:44 +02:00
if err != nil {
logger.Error("[Integration] push entries to matrix bot failed: %v", err)
}
}
2023-09-09 07:45:17 +02:00
if userIntegrations.WebhookEnabled {
logger.Debug("[Integration] Sending %d entries for User #%d to Webhook URL: %s", len(entries), userIntegrations.UserID, userIntegrations.WebhookURL)
2023-09-09 07:45:17 +02:00
webhookClient := webhook.NewClient(userIntegrations.WebhookURL, userIntegrations.WebhookSecret)
if err := webhookClient.SendWebhook(entries); err != nil {
logger.Error("[Integration] sending entries to webhook failed: %v", err)
2021-09-08 05:04:22 +02:00
}
}
2023-09-09 07:45:17 +02:00
// Integrations that only support sending individual entries
if userIntegrations.TelegramBotEnabled || userIntegrations.AppriseEnabled {
for _, entry := range entries {
if userIntegrations.TelegramBotEnabled {
logger.Debug("[Integration] Sending entry %q for user #%d to Telegram", entry.URL, userIntegrations.UserID)
if err := telegrambot.PushEntry(
feed,
entry,
userIntegrations.TelegramBotToken,
userIntegrations.TelegramBotChatID,
userIntegrations.TelegramBotTopicID,
userIntegrations.TelegramBotDisableWebPagePreview,
userIntegrations.TelegramBotDisableNotification,
); err != nil {
logger.Error("[Integration] %v", err)
2023-09-09 07:45:17 +02:00
}
}
if userIntegrations.AppriseEnabled {
logger.Debug("[Integration] Sending entry %q for user #%d to Apprise", entry.URL, userIntegrations.UserID)
2023-09-09 07:45:17 +02:00
appriseServiceURLs := userIntegrations.AppriseURL
if feed.AppriseServiceURLs != "" {
appriseServiceURLs = feed.AppriseServiceURLs
}
client := apprise.NewClient(
userIntegrations.AppriseServicesURL,
appriseServiceURLs,
)
if err := client.SendNotification(entry); err != nil {
logger.Error("[Integration] %v", err)
2023-09-09 07:45:17 +02:00
}
}
2023-08-01 05:55:17 +02:00
}
}
2021-09-08 05:04:22 +02:00
}