-
-
Notifications
You must be signed in to change notification settings - Fork 60
feat: add ntfy integration #2900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
Here's the code health analysis summary for commits Analysis Summary
|
Don't forget to mark the PR as ready for review when you're done ;) |
My config for the screenshot (left to right, top to bottom): Integrations: Widgets:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for this contribution. Let me know if you have any questions
packages/integrations/src/interfaces/notifications/notification.ts
Outdated
Show resolved
Hide resolved
packages/integrations/src/interfaces/notifications/notifications-integration.ts
Outdated
Show resolved
Hide resolved
packages/integrations/src/interfaces/notifications/notifications-integration.ts
Outdated
Show resolved
Hide resolved
Hi @itzTheMeow , do you need further input from us or what is the status of this? |
Hey, currently on vacation so I haven't had time to work on this. It's still in my plans. |
No worries, thanks for the update. Enjoy the vacation |
Hi @itzTheMeow , any updates? :) |
Sorry, been really busy. I'll do this after the weekend. |
No problem, we only wanted to now if you are still interested in working on this. Otherwise we would either have dismissed it or implemented it ourself. |
const integrationInstance = await createIntegrationAsync(integration); | ||
return await integrationInstance.getNotificationsAsync(); | ||
}, | ||
cacheDuration: dayjs.duration(30, "seconds"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's this a bit too aggressive? In my opinion, 5 minutes should be plenty!
Remember, Homarr will fetch even if there is no user "active", meaning that we need to be careful with setting too low intervals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, @homarr-labs/maintainers please add a second review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution ❤️
Looks good beside a few small things
await fetchWithTrustedCertificatesAsync(url, { headers: this.getHeaders() }) | ||
.then((response) => { | ||
if (!response.ok) { | ||
throw new Error(response.statusText); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use the ResponseError
instead
}) | ||
.catch((error) => { | ||
if (error instanceof Error) { | ||
throw new Error(error.message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to just throw the existing error, so just throw error
instead of throw new Error(error.message)
export const ntfyNotificationSchema = z.object({ | ||
id: z.string(), | ||
time: z.number(), | ||
event: z.literal("message"), // we only care about messages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I understand correctly, that we let the parsing fail if the event is different than message? IMO it would make more sense to just have event a string then and check in the integration that the event is message. Then we could also always throw a ParseError
if there is an issue with parsing (just using parseAsync
would be enough because of the existing event handler in the base integration for zod)
<Text size="sm" c="dimmed"> | ||
{date} | ||
</Text> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you could use the useTimeAgo
hook that automatically updates the timestamp. Maybe you can add a second argument that specifies the update frequency and make it a longer time between updates here
Homarr
Thank you for your contribution. Please ensure that your pull request meets the following pull request:
pnpm build
, autofix withpnpm format:fix
)dev
branchx
,y
,i
or any abbrevation)WORK IN PROGRESS
Adds widget to show ntfy notifications.
notifications
.Preview:

I attempted to make the
notifications
widget accessible to other notification services such as gotify, however not all services use topics to define the notification locations so it may need reworking if another service is to be supported.The ntfy integration supports authentication or no authentication. To test the URL can be set to
https://ntfy.sh
and access token left unset. Some example topics to subscribe to:mytopic
,test
To publish messages to these topics, use https://ntfy.sh/mytopic
Additional notes:
I set the cron timer for these to 30 seconds to avoid spamming the API with requests every 5 seconds (was getting ratelimited).
The integrations selector allows for multiple ntfy integrations to be selected for the same widget. The selected topics are shared between both instances so most likely one or the other will not have a specified topic.