feat(notif): add Gotify agent (#2196)

* feat(notifications): adds gotify notifications

adds new settings screen for gotify notifications including url, token and types settings

fix #2183

* feat(notif): add Gotify agent
addresses PR comments, runs i18n:extract

fix #2183

* reword validationTokenRequired

change wording to indicate presence, not validity

Co-authored-by: TheCatLady <52870424+TheCatLady@users.noreply.github.com>

* feat(notifications): gotify notifications fix

applies changes from #2077 in which Yup validation was failing for types

fix #2183

* feat(notifications): adds gotify notifications

adds new settings screen for gotify notifications including url, token and types settings

fix #2183

* feat(notif): add Gotify agent
addresses PR comments, runs i18n:extract

fix #2183

* reword validationTokenRequired

change wording to indicate presence, not validity

Co-authored-by: TheCatLady <52870424+TheCatLady@users.noreply.github.com>

* feat(notifications): gotify notifications fix

applies changes from #2077 in which Yup validation was failing for types

fix #2183

* feat(notifications): incorporate issue feature into gotify notifications

* feat(notifications): adds gotify notifications

adds new settings screen for gotify notifications including url, token and types settings

fix #2183

* feat(notif): add Gotify agent
addresses PR comments, runs i18n:extract

fix #2183

* reword validationTokenRequired

change wording to indicate presence, not validity

Co-authored-by: TheCatLady <52870424+TheCatLady@users.noreply.github.com>

* feat: add missing ts field

include notifyAdmin in test notification endpoint

* feat: apply formatting/line break items

add addition line break before conditional, change ordering of notifyAdmin/notifyUser in test
endpoint

* feat: remove duplicated endpoints

during rebase, notification endpoints were duplicated upon rebasing. remove duplicate routes

* feat: correct linting quirks

* feat: formatting improvements

* feat(gotify): refactor axios post to leverage 'getNotificationPayload'

Co-authored-by: TheCatLady <52870424+TheCatLady@users.noreply.github.com>
This commit is contained in:
Sean Chambers
2022-01-13 19:04:25 -06:00
committed by GitHub
parent 879df20022
commit e0b6abe479
12 changed files with 589 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ import { Notification } from '../../lib/notifications';
import { NotificationAgent } from '../../lib/notifications/agents/agent';
import DiscordAgent from '../../lib/notifications/agents/discord';
import EmailAgent from '../../lib/notifications/agents/email';
import GotifyAgent from '../../lib/notifications/agents/gotify';
import LunaSeaAgent from '../../lib/notifications/agents/lunasea';
import PushbulletAgent from '../../lib/notifications/agents/pushbullet';
import PushoverAgent from '../../lib/notifications/agents/pushover';
@@ -377,4 +378,46 @@ notificationRoutes.post('/lunasea/test', async (req, res, next) => {
}
});
notificationRoutes.get('/gotify', (_req, res) => {
const settings = getSettings();
res.status(200).json(settings.notifications.agents.gotify);
});
notificationRoutes.post('/gotify', (req, rest) => {
const settings = getSettings();
settings.notifications.agents.gotify = req.body;
settings.save();
rest.status(200).json(settings.notifications.agents.gotify);
});
notificationRoutes.post('/gotify/test', async (req, rest, next) => {
if (!req.user) {
return next({
status: 500,
message: 'User information is missing from request',
});
}
const gotifyAgent = new GotifyAgent(req.body);
if (
await gotifyAgent.send(Notification.TEST_NOTIFICATION, {
notifyAdmin: false,
notifyUser: req.user,
subject: 'Test Notification',
message:
'This is a test notification! Check check, 1, 2, 3. Are we coming in clear?',
})
) {
return rest.status(204).send();
} else {
return next({
status: 500,
message: 'Failed to send Gotify notification.',
});
}
});
export default notificationRoutes;