2023-06-19 23:42:47 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2017-12-03 06:12:03 +01:00
|
|
|
|
2023-08-11 04:46:45 +02:00
|
|
|
package integration // import "miniflux.app/v2/internal/integration"
|
2017-12-03 06:12:03 +01:00
|
|
|
|
|
|
|
import (
|
2023-08-11 04:46:45 +02:00
|
|
|
"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"
|
2023-08-11 04:46:45 +02:00
|
|
|
"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"
|
2023-08-11 04:46:45 +02:00
|
|
|
"miniflux.app/v2/internal/logger"
|
|
|
|
"miniflux.app/v2/internal/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 {
|
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)
|
2021-09-08 05:28:41 +02:00
|
|
|
|
2017-12-03 06:12:03 +01:00
|
|
|
client := pinboard.NewClient(integration.PinboardToken)
|
2023-08-14 06:58:45 +02:00
|
|
|
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 {
|
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 {
|
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)
|
2021-09-08 05:28:41 +02:00
|
|
|
|
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 {
|
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)
|
2021-09-08 05:28:41 +02:00
|
|
|
|
2017-12-19 05:52:46 +01:00
|
|
|
client := wallabag.NewClient(
|
|
|
|
integration.WallabagURL,
|
|
|
|
integration.WallabagClientID,
|
|
|
|
integration.WallabagClientSecret,
|
|
|
|
integration.WallabagUsername,
|
|
|
|
integration.WallabagPassword,
|
2022-09-19 01:52:28 +02:00
|
|
|
integration.WallabagOnlyURL,
|
2017-12-19 05:52:46 +01:00
|
|
|
)
|
|
|
|
|
2023-08-14 06:58:45 +02:00
|
|
|
if err := client.CreateEntry(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
|
|
|
|
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,
|
|
|
|
)
|
2023-08-14 06:58:45 +02:00
|
|
|
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)
|
2021-09-08 05:28:41 +02:00
|
|
|
|
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
|
|
|
|
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,
|
|
|
|
)
|
|
|
|
|
2023-08-14 06:58:45 +02:00
|
|
|
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)
|
2021-09-08 05:28:41 +02:00
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
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,
|
2023-05-21 16:29:51 +02:00
|
|
|
integration.LinkdingTags,
|
2023-06-24 17:08:58 +02:00
|
|
|
integration.LinkdingMarkAsUnread,
|
2022-05-23 17:53:06 +02:00
|
|
|
)
|
2023-08-14 06:58:45 +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,
|
|
|
|
)
|
|
|
|
|
2023-08-14 06:58:45 +02:00
|
|
|
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,
|
|
|
|
)
|
|
|
|
|
2023-08-14 06:58:45 +02:00
|
|
|
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,
|
|
|
|
)
|
|
|
|
|
2023-08-14 06:58:45 +02:00
|
|
|
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 {
|
2023-09-10 20:22:32 +02:00
|
|
|
logger.Debug("[Integration] Sending %d entries for user #%d to Matrix", len(entries), userIntegrations.UserID)
|
2022-10-14 17:18:44 +02:00
|
|
|
|
2023-09-10 01:16:45 +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 {
|
2023-09-10 21:50:58 +02:00
|
|
|
logger.Debug("[Integration] Sending %d entries for user #%d to Webhook URL: %s", len(entries), userIntegrations.UserID, userIntegrations.WebhookURL)
|
2021-09-08 05:28:41 +02:00
|
|
|
|
2023-09-09 07:45:17 +02:00
|
|
|
webhookClient := webhook.NewClient(userIntegrations.WebhookURL, userIntegrations.WebhookSecret)
|
2023-09-10 21:50:58 +02:00
|
|
|
if err := webhookClient.SendWebhook(feed, entries); err != nil {
|
2023-09-09 07:45:17 +02:00
|
|
|
logger.Error("[Integration] sending entries to webhook failed: %v", err)
|
2021-09-08 05:04:22 +02:00
|
|
|
}
|
|
|
|
}
|
2023-08-14 06:58:45 +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 {
|
2023-09-10 20:22:32 +02:00
|
|
|
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 {
|
2023-09-10 20:22:32 +02:00
|
|
|
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 {
|
2023-09-10 20:22:32 +02:00
|
|
|
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
|
|
|
}
|