integration.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package integration // import "miniflux.app/v2/internal/integration"
  4. import (
  5. "log/slog"
  6. "miniflux.app/v2/internal/config"
  7. "miniflux.app/v2/internal/integration/apprise"
  8. "miniflux.app/v2/internal/integration/betula"
  9. "miniflux.app/v2/internal/integration/cubox"
  10. "miniflux.app/v2/internal/integration/espial"
  11. "miniflux.app/v2/internal/integration/instapaper"
  12. "miniflux.app/v2/internal/integration/linkace"
  13. "miniflux.app/v2/internal/integration/linkding"
  14. "miniflux.app/v2/internal/integration/linkwarden"
  15. "miniflux.app/v2/internal/integration/matrixbot"
  16. "miniflux.app/v2/internal/integration/notion"
  17. "miniflux.app/v2/internal/integration/ntfy"
  18. "miniflux.app/v2/internal/integration/nunuxkeeper"
  19. "miniflux.app/v2/internal/integration/omnivore"
  20. "miniflux.app/v2/internal/integration/pinboard"
  21. "miniflux.app/v2/internal/integration/pocket"
  22. "miniflux.app/v2/internal/integration/raindrop"
  23. "miniflux.app/v2/internal/integration/readeck"
  24. "miniflux.app/v2/internal/integration/readwise"
  25. "miniflux.app/v2/internal/integration/shaarli"
  26. "miniflux.app/v2/internal/integration/shiori"
  27. "miniflux.app/v2/internal/integration/telegrambot"
  28. "miniflux.app/v2/internal/integration/wallabag"
  29. "miniflux.app/v2/internal/integration/webhook"
  30. "miniflux.app/v2/internal/model"
  31. )
  32. // SendEntry sends the entry to third-party providers when the user click on "Save".
  33. func SendEntry(entry *model.Entry, userIntegrations *model.Integration) {
  34. if userIntegrations.BetulaEnabled {
  35. slog.Debug("Sending entry to Betula",
  36. slog.Int64("user_id", userIntegrations.UserID),
  37. slog.Int64("entry_id", entry.ID),
  38. slog.String("entry_url", entry.URL),
  39. )
  40. client := betula.NewClient(userIntegrations.BetulaURL, userIntegrations.BetulaToken)
  41. err := client.CreateBookmark(
  42. entry.URL,
  43. entry.Title,
  44. entry.Tags,
  45. )
  46. if err != nil {
  47. slog.Error("Unable to send entry to Betula",
  48. slog.Int64("user_id", userIntegrations.UserID),
  49. slog.Int64("entry_id", entry.ID),
  50. slog.String("entry_url", entry.URL),
  51. slog.Any("error", err),
  52. )
  53. }
  54. }
  55. if userIntegrations.PinboardEnabled {
  56. slog.Debug("Sending entry to Pinboard",
  57. slog.Int64("user_id", userIntegrations.UserID),
  58. slog.Int64("entry_id", entry.ID),
  59. slog.String("entry_url", entry.URL),
  60. )
  61. client := pinboard.NewClient(userIntegrations.PinboardToken)
  62. err := client.CreateBookmark(
  63. entry.URL,
  64. entry.Title,
  65. userIntegrations.PinboardTags,
  66. userIntegrations.PinboardMarkAsUnread,
  67. )
  68. if err != nil {
  69. slog.Error("Unable to send entry to Pinboard",
  70. slog.Int64("user_id", userIntegrations.UserID),
  71. slog.Int64("entry_id", entry.ID),
  72. slog.String("entry_url", entry.URL),
  73. slog.Any("error", err),
  74. )
  75. }
  76. }
  77. if userIntegrations.InstapaperEnabled {
  78. slog.Debug("Sending entry to Instapaper",
  79. slog.Int64("user_id", userIntegrations.UserID),
  80. slog.Int64("entry_id", entry.ID),
  81. slog.String("entry_url", entry.URL),
  82. )
  83. client := instapaper.NewClient(userIntegrations.InstapaperUsername, userIntegrations.InstapaperPassword)
  84. if err := client.AddURL(entry.URL, entry.Title); err != nil {
  85. slog.Error("Unable to send entry to Instapaper",
  86. slog.Int64("user_id", userIntegrations.UserID),
  87. slog.Int64("entry_id", entry.ID),
  88. slog.String("entry_url", entry.URL),
  89. slog.Any("error", err),
  90. )
  91. }
  92. }
  93. if userIntegrations.WallabagEnabled {
  94. slog.Debug("Sending entry to Wallabag",
  95. slog.Int64("user_id", userIntegrations.UserID),
  96. slog.Int64("entry_id", entry.ID),
  97. slog.String("entry_url", entry.URL),
  98. )
  99. client := wallabag.NewClient(
  100. userIntegrations.WallabagURL,
  101. userIntegrations.WallabagClientID,
  102. userIntegrations.WallabagClientSecret,
  103. userIntegrations.WallabagUsername,
  104. userIntegrations.WallabagPassword,
  105. userIntegrations.WallabagOnlyURL,
  106. )
  107. if err := client.CreateEntry(entry.URL, entry.Title, entry.Content); err != nil {
  108. slog.Error("Unable to send entry to Wallabag",
  109. slog.Int64("user_id", userIntegrations.UserID),
  110. slog.Int64("entry_id", entry.ID),
  111. slog.String("entry_url", entry.URL),
  112. slog.Any("error", err),
  113. )
  114. }
  115. }
  116. if userIntegrations.NotionEnabled {
  117. slog.Debug("Sending entry to Notion",
  118. slog.Int64("user_id", userIntegrations.UserID),
  119. slog.Int64("entry_id", entry.ID),
  120. slog.String("entry_url", entry.URL),
  121. )
  122. client := notion.NewClient(
  123. userIntegrations.NotionToken,
  124. userIntegrations.NotionPageID,
  125. )
  126. if err := client.UpdateDocument(entry.URL, entry.Title); err != nil {
  127. slog.Error("Unable to send entry to Notion",
  128. slog.Int64("user_id", userIntegrations.UserID),
  129. slog.Int64("entry_id", entry.ID),
  130. slog.String("entry_url", entry.URL),
  131. slog.Any("error", err),
  132. )
  133. }
  134. }
  135. if userIntegrations.NunuxKeeperEnabled {
  136. slog.Debug("Sending entry to NunuxKeeper",
  137. slog.Int64("user_id", userIntegrations.UserID),
  138. slog.Int64("entry_id", entry.ID),
  139. slog.String("entry_url", entry.URL),
  140. )
  141. client := nunuxkeeper.NewClient(
  142. userIntegrations.NunuxKeeperURL,
  143. userIntegrations.NunuxKeeperAPIKey,
  144. )
  145. if err := client.AddEntry(entry.URL, entry.Title, entry.Content); err != nil {
  146. slog.Error("Unable to send entry to NunuxKeeper",
  147. slog.Int64("user_id", userIntegrations.UserID),
  148. slog.Int64("entry_id", entry.ID),
  149. slog.String("entry_url", entry.URL),
  150. slog.Any("error", err),
  151. )
  152. }
  153. }
  154. if userIntegrations.EspialEnabled {
  155. slog.Debug("Sending entry to Espial",
  156. slog.Int64("user_id", userIntegrations.UserID),
  157. slog.Int64("entry_id", entry.ID),
  158. slog.String("entry_url", entry.URL),
  159. )
  160. client := espial.NewClient(
  161. userIntegrations.EspialURL,
  162. userIntegrations.EspialAPIKey,
  163. )
  164. if err := client.CreateLink(entry.URL, entry.Title, userIntegrations.EspialTags); err != nil {
  165. slog.Error("Unable to send entry to Espial",
  166. slog.Int64("user_id", userIntegrations.UserID),
  167. slog.Int64("entry_id", entry.ID),
  168. slog.String("entry_url", entry.URL),
  169. slog.Any("error", err),
  170. )
  171. }
  172. }
  173. if userIntegrations.PocketEnabled {
  174. slog.Debug("Sending entry to Pocket",
  175. slog.Int64("user_id", userIntegrations.UserID),
  176. slog.Int64("entry_id", entry.ID),
  177. slog.String("entry_url", entry.URL),
  178. )
  179. client := pocket.NewClient(config.Opts.PocketConsumerKey(userIntegrations.PocketConsumerKey), userIntegrations.PocketAccessToken)
  180. if err := client.AddURL(entry.URL, entry.Title); err != nil {
  181. slog.Error("Unable to send entry to Pocket",
  182. slog.Int64("user_id", userIntegrations.UserID),
  183. slog.Int64("entry_id", entry.ID),
  184. slog.String("entry_url", entry.URL),
  185. slog.Any("error", err),
  186. )
  187. }
  188. }
  189. if userIntegrations.LinkAceEnabled {
  190. slog.Debug("Sending entry to LinkAce",
  191. slog.Int64("user_id", userIntegrations.UserID),
  192. slog.Int64("entry_id", entry.ID),
  193. slog.String("entry_url", entry.URL),
  194. )
  195. client := linkace.NewClient(
  196. userIntegrations.LinkAceURL,
  197. userIntegrations.LinkAceAPIKey,
  198. userIntegrations.LinkAceTags,
  199. userIntegrations.LinkAcePrivate,
  200. userIntegrations.LinkAceCheckDisabled,
  201. )
  202. if err := client.AddURL(entry.URL, entry.Title); err != nil {
  203. slog.Error("Unable to send entry to LinkAce",
  204. slog.Int64("user_id", userIntegrations.UserID),
  205. slog.Int64("entry_id", entry.ID),
  206. slog.String("entry_url", entry.URL),
  207. slog.Any("error", err),
  208. )
  209. }
  210. }
  211. if userIntegrations.LinkdingEnabled {
  212. slog.Debug("Sending entry to Linkding",
  213. slog.Int64("user_id", userIntegrations.UserID),
  214. slog.Int64("entry_id", entry.ID),
  215. slog.String("entry_url", entry.URL),
  216. )
  217. client := linkding.NewClient(
  218. userIntegrations.LinkdingURL,
  219. userIntegrations.LinkdingAPIKey,
  220. userIntegrations.LinkdingTags,
  221. userIntegrations.LinkdingMarkAsUnread,
  222. )
  223. if err := client.CreateBookmark(entry.URL, entry.Title); err != nil {
  224. slog.Error("Unable to send entry to Linkding",
  225. slog.Int64("user_id", userIntegrations.UserID),
  226. slog.Int64("entry_id", entry.ID),
  227. slog.String("entry_url", entry.URL),
  228. slog.Any("error", err),
  229. )
  230. }
  231. }
  232. if userIntegrations.LinkwardenEnabled {
  233. slog.Debug("Sending entry to linkwarden",
  234. slog.Int64("user_id", userIntegrations.UserID),
  235. slog.Int64("entry_id", entry.ID),
  236. slog.String("entry_url", entry.URL),
  237. )
  238. client := linkwarden.NewClient(
  239. userIntegrations.LinkwardenURL,
  240. userIntegrations.LinkwardenAPIKey,
  241. )
  242. if err := client.CreateBookmark(entry.URL, entry.Title); err != nil {
  243. slog.Error("Unable to send entry to Linkwarden",
  244. slog.Int64("user_id", userIntegrations.UserID),
  245. slog.Int64("entry_id", entry.ID),
  246. slog.String("entry_url", entry.URL),
  247. slog.Any("error", err),
  248. )
  249. }
  250. }
  251. if userIntegrations.ReadeckEnabled {
  252. slog.Debug("Sending entry to Readeck",
  253. slog.Int64("user_id", userIntegrations.UserID),
  254. slog.Int64("entry_id", entry.ID),
  255. slog.String("entry_url", entry.URL),
  256. )
  257. client := readeck.NewClient(
  258. userIntegrations.ReadeckURL,
  259. userIntegrations.ReadeckAPIKey,
  260. userIntegrations.ReadeckLabels,
  261. userIntegrations.ReadeckOnlyURL,
  262. )
  263. if err := client.CreateBookmark(entry.URL, entry.Title, entry.Content); err != nil {
  264. slog.Error("Unable to send entry to Readeck",
  265. slog.Int64("user_id", userIntegrations.UserID),
  266. slog.Int64("entry_id", entry.ID),
  267. slog.String("entry_url", entry.URL),
  268. slog.Any("error", err),
  269. )
  270. }
  271. }
  272. if userIntegrations.ReadwiseEnabled {
  273. slog.Debug("Sending entry to Readwise",
  274. slog.Int64("user_id", userIntegrations.UserID),
  275. slog.Int64("entry_id", entry.ID),
  276. slog.String("entry_url", entry.URL),
  277. )
  278. client := readwise.NewClient(
  279. userIntegrations.ReadwiseAPIKey,
  280. )
  281. if err := client.CreateDocument(entry.URL); err != nil {
  282. slog.Error("Unable to send entry to Readwise",
  283. slog.Int64("user_id", userIntegrations.UserID),
  284. slog.Int64("entry_id", entry.ID),
  285. slog.String("entry_url", entry.URL),
  286. slog.Any("error", err),
  287. )
  288. }
  289. }
  290. if userIntegrations.CuboxEnabled {
  291. slog.Debug("Sending entry to Cubox",
  292. slog.Int64("user_id", userIntegrations.UserID),
  293. slog.Int64("entry_id", entry.ID),
  294. slog.String("entry_url", entry.URL),
  295. )
  296. client := cubox.NewClient(userIntegrations.CuboxAPILink)
  297. if err := client.SaveLink(entry.URL); err != nil {
  298. slog.Error("Unable to send entry to Cubox",
  299. slog.Int64("user_id", userIntegrations.UserID),
  300. slog.Int64("entry_id", entry.ID),
  301. slog.String("entry_url", entry.URL),
  302. slog.Any("error", err),
  303. )
  304. }
  305. }
  306. if userIntegrations.ShioriEnabled {
  307. slog.Debug("Sending entry to Shiori",
  308. slog.Int64("user_id", userIntegrations.UserID),
  309. slog.Int64("entry_id", entry.ID),
  310. slog.String("entry_url", entry.URL),
  311. )
  312. client := shiori.NewClient(
  313. userIntegrations.ShioriURL,
  314. userIntegrations.ShioriUsername,
  315. userIntegrations.ShioriPassword,
  316. )
  317. if err := client.CreateBookmark(entry.URL, entry.Title); err != nil {
  318. slog.Error("Unable to send entry to Shiori",
  319. slog.Int64("user_id", userIntegrations.UserID),
  320. slog.Int64("entry_id", entry.ID),
  321. slog.String("entry_url", entry.URL),
  322. slog.Any("error", err),
  323. )
  324. }
  325. }
  326. if userIntegrations.ShaarliEnabled {
  327. slog.Debug("Sending entry to Shaarli",
  328. slog.Int64("user_id", userIntegrations.UserID),
  329. slog.Int64("entry_id", entry.ID),
  330. slog.String("entry_url", entry.URL),
  331. )
  332. client := shaarli.NewClient(
  333. userIntegrations.ShaarliURL,
  334. userIntegrations.ShaarliAPISecret,
  335. )
  336. if err := client.CreateLink(entry.URL, entry.Title); err != nil {
  337. slog.Error("Unable to send entry to Shaarli",
  338. slog.Int64("user_id", userIntegrations.UserID),
  339. slog.Int64("entry_id", entry.ID),
  340. slog.String("entry_url", entry.URL),
  341. slog.Any("error", err),
  342. )
  343. }
  344. }
  345. if userIntegrations.WebhookEnabled {
  346. slog.Debug("Sending entry to Webhook",
  347. slog.Int64("user_id", userIntegrations.UserID),
  348. slog.Int64("entry_id", entry.ID),
  349. slog.String("entry_url", entry.URL),
  350. slog.String("webhook_url", userIntegrations.WebhookURL),
  351. )
  352. webhookClient := webhook.NewClient(userIntegrations.WebhookURL, userIntegrations.WebhookSecret)
  353. if err := webhookClient.SendSaveEntryWebhookEvent(entry); err != nil {
  354. slog.Error("Unable to send entry to Webhook",
  355. slog.Int64("user_id", userIntegrations.UserID),
  356. slog.Int64("entry_id", entry.ID),
  357. slog.String("entry_url", entry.URL),
  358. slog.String("webhook_url", userIntegrations.WebhookURL),
  359. slog.Any("error", err),
  360. )
  361. }
  362. }
  363. if userIntegrations.OmnivoreEnabled {
  364. slog.Debug("Sending entry to Omnivore",
  365. slog.Int64("user_id", userIntegrations.UserID),
  366. slog.Int64("entry_id", entry.ID),
  367. slog.String("entry_url", entry.URL),
  368. )
  369. client := omnivore.NewClient(userIntegrations.OmnivoreAPIKey, userIntegrations.OmnivoreURL)
  370. if err := client.SaveUrl(entry.URL); err != nil {
  371. slog.Error("Unable to send entry to Omnivore",
  372. slog.Int64("user_id", userIntegrations.UserID),
  373. slog.Int64("entry_id", entry.ID),
  374. slog.String("entry_url", entry.URL),
  375. slog.Any("error", err),
  376. )
  377. }
  378. }
  379. if userIntegrations.RaindropEnabled {
  380. slog.Debug("Sending entry to Raindrop",
  381. slog.Int64("user_id", userIntegrations.UserID),
  382. slog.Int64("entry_id", entry.ID),
  383. slog.String("entry_url", entry.URL),
  384. )
  385. client := raindrop.NewClient(userIntegrations.RaindropToken, userIntegrations.RaindropCollectionID, userIntegrations.RaindropTags)
  386. if err := client.CreateRaindrop(entry.URL, entry.Title); err != nil {
  387. slog.Error("Unable to send entry to Raindrop",
  388. slog.Int64("user_id", userIntegrations.UserID),
  389. slog.Int64("entry_id", entry.ID),
  390. slog.String("entry_url", entry.URL),
  391. slog.Any("error", err),
  392. )
  393. }
  394. }
  395. }
  396. // PushEntries pushes a list of entries to activated third-party providers during feed refreshes.
  397. func PushEntries(feed *model.Feed, entries model.Entries, userIntegrations *model.Integration) {
  398. if userIntegrations.MatrixBotEnabled {
  399. slog.Debug("Sending new entries to Matrix",
  400. slog.Int64("user_id", userIntegrations.UserID),
  401. slog.Int("nb_entries", len(entries)),
  402. slog.Int64("feed_id", feed.ID),
  403. )
  404. err := matrixbot.PushEntries(
  405. feed,
  406. entries,
  407. userIntegrations.MatrixBotURL,
  408. userIntegrations.MatrixBotUser,
  409. userIntegrations.MatrixBotPassword,
  410. userIntegrations.MatrixBotChatID,
  411. )
  412. if err != nil {
  413. slog.Error("Unable to send new entries to Matrix",
  414. slog.Int64("user_id", userIntegrations.UserID),
  415. slog.Int("nb_entries", len(entries)),
  416. slog.Int64("feed_id", feed.ID),
  417. slog.Any("error", err),
  418. )
  419. }
  420. }
  421. if userIntegrations.WebhookEnabled {
  422. slog.Debug("Sending new entries to Webhook",
  423. slog.Int64("user_id", userIntegrations.UserID),
  424. slog.Int("nb_entries", len(entries)),
  425. slog.Int64("feed_id", feed.ID),
  426. slog.String("webhook_url", userIntegrations.WebhookURL),
  427. )
  428. webhookClient := webhook.NewClient(userIntegrations.WebhookURL, userIntegrations.WebhookSecret)
  429. if err := webhookClient.SendNewEntriesWebhookEvent(feed, entries); err != nil {
  430. slog.Debug("Unable to send new entries to Webhook",
  431. slog.Int64("user_id", userIntegrations.UserID),
  432. slog.Int("nb_entries", len(entries)),
  433. slog.Int64("feed_id", feed.ID),
  434. slog.String("webhook_url", userIntegrations.WebhookURL),
  435. slog.Any("error", err),
  436. )
  437. }
  438. }
  439. if userIntegrations.NtfyEnabled && feed.NtfyEnabled {
  440. slog.Debug("Sending new entries to Ntfy",
  441. slog.Int64("user_id", userIntegrations.UserID),
  442. slog.Int("nb_entries", len(entries)),
  443. slog.Int64("feed_id", feed.ID),
  444. )
  445. client := ntfy.NewClient(
  446. userIntegrations.NtfyURL,
  447. userIntegrations.NtfyTopic,
  448. userIntegrations.NtfyAPIToken,
  449. userIntegrations.NtfyUsername,
  450. userIntegrations.NtfyPassword,
  451. userIntegrations.NtfyIconURL,
  452. feed.NtfyPriority,
  453. )
  454. if err := client.SendMessages(feed, entries); err != nil {
  455. slog.Warn("Unable to send new entries to Ntfy", slog.Any("error", err))
  456. }
  457. }
  458. // Integrations that only support sending individual entries
  459. if userIntegrations.TelegramBotEnabled || userIntegrations.AppriseEnabled {
  460. for _, entry := range entries {
  461. if userIntegrations.TelegramBotEnabled {
  462. slog.Debug("Sending a new entry to Telegram",
  463. slog.Int64("user_id", userIntegrations.UserID),
  464. slog.Int64("entry_id", entry.ID),
  465. slog.String("entry_url", entry.URL),
  466. )
  467. if err := telegrambot.PushEntry(
  468. feed,
  469. entry,
  470. userIntegrations.TelegramBotToken,
  471. userIntegrations.TelegramBotChatID,
  472. userIntegrations.TelegramBotTopicID,
  473. userIntegrations.TelegramBotDisableWebPagePreview,
  474. userIntegrations.TelegramBotDisableNotification,
  475. userIntegrations.TelegramBotDisableButtons,
  476. ); err != nil {
  477. slog.Error("Unable to send entry to Telegram",
  478. slog.Int64("user_id", userIntegrations.UserID),
  479. slog.Int64("entry_id", entry.ID),
  480. slog.String("entry_url", entry.URL),
  481. slog.Any("error", err),
  482. )
  483. }
  484. }
  485. if userIntegrations.AppriseEnabled {
  486. slog.Debug("Sending a new entry to Apprise",
  487. slog.Int64("user_id", userIntegrations.UserID),
  488. slog.Int64("entry_id", entry.ID),
  489. slog.String("entry_url", entry.URL),
  490. slog.String("apprise_url", userIntegrations.AppriseURL),
  491. )
  492. appriseServiceURLs := userIntegrations.AppriseServicesURL
  493. if feed.AppriseServiceURLs != "" {
  494. appriseServiceURLs = feed.AppriseServiceURLs
  495. }
  496. client := apprise.NewClient(
  497. appriseServiceURLs,
  498. userIntegrations.AppriseURL,
  499. )
  500. if err := client.SendNotification(entry); err != nil {
  501. slog.Error("Unable to send entry to Apprise",
  502. slog.Int64("user_id", userIntegrations.UserID),
  503. slog.Int64("entry_id", entry.ID),
  504. slog.String("entry_url", entry.URL),
  505. slog.String("apprise_url", userIntegrations.AppriseURL),
  506. slog.Any("error", err),
  507. )
  508. }
  509. }
  510. }
  511. }
  512. }