Repository navigation
Conversation
bf5ae38 to
a40c9f0
Compare
jrasm91
left a comment
There was a problem hiding this comment.
It looks like there are system config for apprise and then also user preferences, similar to emails. Unlike emails, which have a user specific value ( user.email), apprise doesn't have any user specific values in how notifications are sent. Doesn't that mean that two users with apprise notifications enabled would result in two notifications being sent if they're both invited to the same album? Would it make sense to automatically add a tag for email or something when sending user specific events? Or, how can we better distinguish and group events per user when the configuration is global?
| enabled: process.env.IMMICH_APPRISE_ENABLED === 'true', | ||
| host: process.env.IMMICH_APPRISE_HOST || '', | ||
| port: Number(process.env.IMMICH_APPRISE_PORT) || null, | ||
| secure: process.env.IMMICH_APPRISE_SECURE === 'true', | ||
| basePath: process.env.IMMICH_APPRISE_BASE_PATH || '', | ||
| configId: process.env.IMMICH_APPRISE_CONFIG_ID || '', | ||
| tags: process.env.IMMICH_APPRISE_TAGS || '', | ||
| username: process.env.IMMICH_APPRISE_USERNAME || '', | ||
| password: process.env.IMMICH_APPRISE_PASSWORD || '', | ||
| timeout: Number(process.env.IMMICH_APPRISE_TIMEOUT) || 20, |
There was a problem hiding this comment.
There is a separate PR which will allow setting system config from environment variables (#32176). Just use defaults here and we'll get env support when that one lands instead.
|
@jrasm91 Your points are very valid. I will wait for your env PR you mentioned, but in the meantime, I did update the code to better align with supporting mutliple users. Basically the admin is where the server content is configed (following email patterns), but the users can then define the Apprise URLs uniquely/individually for the flexibility of "Alice getting a Telegram notice" and say "Bill getting a Pushover and signal notice". Going to try to update the screenshots.... will capture them tomorrow morning and upload them to show you the new look. |
6bca389 to
d62750a
Compare
| @Endpoint({ | ||
| summary: 'Test Apprise connection', | ||
| description: 'Check that the Apprise API server can be reached with the provided login, without sending anything.', | ||
| history: new HistoryBuilder().added('v3.3.0').beta('v3.3.0'), |
| .nullable() | ||
| .describe('Apprise API server port (defaults to 80, or 443 when secure)'), | ||
| secure: configBool.describe('Whether to use a secure connection (HTTPS)'), | ||
| basePath: z.string().describe('Path prefix the Apprise API is served under'), |
There was a problem hiding this comment.
Can we collapse this and host into one url (or similar) field?
| enabled: z.boolean().optional().describe('Whether Apprise notifications are enabled'), | ||
| albumInvite: z.boolean().optional().describe('Whether to receive Apprise notifications for album invites'), | ||
| albumUpdate: z.boolean().optional().describe('Whether to receive Apprise notifications for album updates'), | ||
| urls: z.string().optional().describe('Apprise URLs to notify, separated by commas or spaces'), |
|
|
||
| const MAX_MESSAGE_LENGTH = 500; | ||
|
|
||
| export class AppriseError extends Error { |
There was a problem hiding this comment.
We usually don't have custom errors. We just log with our logger that already has the context, and then throw a generic bad request exception (or similar)
There was a problem hiding this comment.
Done. Removed AppriseError. Changed it to use the pattern already in your code base; throws a BadRequestException with a readable message; the job handler just lets it bubble up (like the email job does).
| await this.request(options, 'notify', { urls, title, body, type: 'info', format: 'text' }); | ||
| } | ||
|
|
||
| private async request(options: AppriseOptions, route: 'status' | 'notify', payload?: object) { |
There was a problem hiding this comment.
It is a bit annoying to have to do this ourselves. I had a quick look and couldn't find a nodejs library (which I assume you know and is the reason for implementing this manually in the first place). As the author, do you expect (significant) changes to the API? I.e., do you think this will be annoying to keep up to date without just having renovate bump a library for us.
There was a problem hiding this comment.
Right, there's no Node client, which is why it's done by hand.
For some reassurance... as the Apprise author: the two endpoints used here (GET /status and POST /notify) have been around since the first releases (dating back 8-9 years now) and I keep them backwards compatible.
It's only two plain HTTP calls, so I don't expect this to need upkeep, and it avoids adding a dependency. Is that okay?
|
|
||
| let url: URL; | ||
| try { | ||
| url = new URL(`${secure ? 'https' : 'http'}://${host}:${port}/${path}`); |
There was a problem hiding this comment.
The constructor of URL also supports object-style initialization ({ host, port, ... }). I would prefer that here
There was a problem hiding this comment.
Agreed; this is now a single URL that is submitted as it is entered by the user.
|
|
||
| /** Sends to the given Apprise URLs (stateless), so each user's notifications go to their own services. */ | ||
| async notify(options: AppriseOptions, { title, body, urls }: AppriseNotification): Promise<void> { | ||
| await this.request(options, 'notify', { urls, title, body, type: 'info', format: 'text' }); |
There was a problem hiding this comment.
We should allow to customize type IMO (we may want to use this for error notifications later for instance)
| const { notifications } = await this.getConfig({ withCache: false }); | ||
| const { apprise } = notifications; |
There was a problem hiding this comment.
| const { notifications } = await this.getConfig({ withCache: false }); | |
| const { apprise } = notifications; | |
| const { notifications: { apprise } } = await this.getConfig({ withCache: false }); |
There was a problem hiding this comment.
Applied your suggestions for this and your next advised one 🙏 ; thank you for all of your help here.
| @@ -495,4 +532,37 @@ export class NotificationService extends BaseService { | |||
|
|
|||
| this.websocketRepository.clientSend('on_notification', userId, mapNotification(item)); | |||
| } | |||
|
|
|||
| /** Queues an Apprise notification to the recipient's own URLs, with the same wording as the in-app one. */ | |||
There was a problem hiding this comment.
| /** Queues an Apprise notification to the recipient's own URLs, with the same wording as the in-app one. */ |
There was a problem hiding this comment.
Removed the inline comment per comment.
| @@ -51,6 +62,37 @@ | |||
| <Field label={$t('album_updated')} description={$t('album_updated_setting_description')} {disabled}> | |||
| <Switch bind:checked={albumUpdateNotificationEnabled} /> | |||
| </Field> | |||
|
|
|||
| <!-- Only shown when the administrator has turned on Apprise --> | |||
| {#await getUserConfig() then config} | |||
There was a problem hiding this comment.
We use tanstack query for this. Just do const config = readPreloadedConfig(getUserConfigQuery()) in the script part
|
Exciting! |
|
Really appreciate the constructive feedback. My initial PR was intentionally breaking port, host, etc all into it's own strings because I was so focused on keeping the changes light 🙂 . But now that you've shown interest and do not mind the deviation to simplify these, i'm more than happy to oblige. While we're on this path, is there value in making the array of URLs have a small Test button next to each (per entry) that fires a single test message? Maybe another 150-300 lines of code added to the PR or so? Edit: Also for the CodeQL if it comes up again. Apprise (lke Immich) is self hosted... but there is safety built into it in the sense you can set a |
8f5f4a3 to
9f7bb36
Compare
|
📖 Documentation deployed to docs.pr-32605.preview.immich.app |
351f552 to
351142a
Compare
|
Hey, sorry for not getting back to this earlier, things are busy.
One possible solution to this would be to natively support a handful of notification providers, backed by Apprise, however I am not sure that's the best either, and the way Immich internals are built right now that would be rather annoying to do. Basically, I think this is a limitation of Apprise not being user-aware (and, in fact, stateless unless you configure some tags in the deployed container) which is kind of at odds with Immich's design. If you have any input on this and/or have seen how other projects that are similar to Immich's needs have done this, that'd be very much appreciated! |
|
@danieldietzler I hear your points... The trade-off is that you no longer have to manage the supported notification endpoints in Immich itself... As they keep growing and disappearing (such as Amazon Chime shut down in Feb this year) as they become available or are decommissioned over time. You also get access to all of the new systems (as they transpire). With email, you need to track the SMTP, the user, and the password, port, ssl, etc. With another provider, you need to track the web token, api keys, secrets, the ever-changing payload, and the webhook endpoint (form field after form field); you need to maintain them all now too. Apprise amalgamates its (now 189) supported services into a single char field... So you always support everything it does. The PR is nothing but a means of checking the box to support every upstream service anyone could ever want (or open a ticket for) with Immich in one blow (and maintain that support for upcoming ones). Also, Apprise isn't one of these AI Vibe coded applications; it's been around the block for almost 10 years of hardening to the point it's really easy to add/remove services to it. Apprise's biggest weakness is building the Apprise URL (for the first time); I get it - this is to your point exactly. But it's a set-it-and-forget-it thing... I don't advertise, and I do provide a URL Builder here: https://appriseit.com/url-builder/ which maybe would be worth just linking to? Either way, I respect your concern, though; to be fair, my mom wouldn't be able to fill out all of the email details for an SMTP server either, but your mom is more tech-savvy than mine 🙂 . My mindset was around the thought that the same administrator who sets up Immich would just set up an Apprise API server next to it. Thoughts? Edit: Apprise can also support tags (stateful setup) too where you set up all of your configuration on the Apprise API server instead (of Immich) and you just trigger a notification by an easy to reference name like |
Adds optional Apprise API delivery for album invite and album update notifications, alongside email.
351142a to
fadc163
Compare
Description
Adds optional notifications through an Apprise API server (alongside email).
This basically grants Immich the ability to send notifcations (through Apprise API) to 170+ endpoints (giving users much more flexibility). Apprise can forward messages along to Discord, Telegram, ntfy, Signal, Gotify, etc, etc and many other services. Apprise has been adapted by Apache Airflow, it's also in Home Asssistant too. The core library itself has over 17,000 stars & over 188 Million downloads. For clarity; the API (what this PR relates to), is just the Sidecar wrapper of this same popular application.
A full list of supported services (which are still growing) are available here: https://appriseit.com/services/
As per what I did to Immich:
I did not want to disrupt Immich or change how it works; so I really just borrowed from how the SMTP built in settings already existed and ran an Apprise setup followig this flow.
Email behaviour is unchanged, and Apprise is off by default. Welcome emails stay email-only, since they can contain a password.
How Has This Been Tested?
Unit tests cover the new repository, service, and controller code (URL building, the
X-Config-Apprise-IDheader, Basic Auth, each Apprise response code, and hiding URLs from admins).I also ran a build of this branch against my own Apprise API server, with a config that had one untagged service and one tagged.
Screenshots (if appropriate)
Here is what some of the output looks like (JSON format that would have otherwise been inside Immich just clenaed for presentation here in this PR:
API Changes
POST /admin/notifications/test-appriseendpointnotifications.appriseadded to the system configappriseNotificationsadded to user preferencesChecklist:
src/services/uses repositories implementations for database calls, filesystem operations, etc.src/repositories/is pretty basic/simple and does not have any immich specific logic (that belongs insrc/services/)Please describe to which degree, if any, an LLM was used in creating this pull request.