-
Notifications
You must be signed in to change notification settings - Fork 431
announcements: integration with notifications #4378 #4816
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: main
Are you sure you want to change the base?
Changes from 5 commits
ae52af2
38e1aaf
7953564
6fd4a54
5c204e2
6f6f3e3
c48ede4
86078f2
1d22a8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@backstage-community/plugin-announcements-backend': minor | ||
--- | ||
|
||
announcements: integration with notifications #4378 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,44 @@ import { | |
} from '@backstage-community/plugin-announcements-common'; | ||
import { signalAnnouncement } from './service/signal'; | ||
import { AnnouncementsContext } from './service'; | ||
import { NotificationService } from '@backstage/plugin-notifications-node'; | ||
import { Config } from '@backstage/config'; | ||
|
||
const sendAnnouncementNotification = ( | ||
kurtaking marked this conversation as resolved.
Show resolved
Hide resolved
|
||
announcementId: string, | ||
announcementNotificationOpts: { | ||
notifications?: NotificationService; | ||
config: Config; | ||
}, | ||
) => { | ||
const notificationsConfig = | ||
announcementNotificationOpts.config.getOptionalConfig( | ||
'announcements.notification', | ||
); | ||
|
||
const notifications = announcementNotificationOpts.notifications; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking - you could consider destructuring right here const { config, notifications } = announcementNotificationOpts There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed now based on @gaelgoth next comment. But do revert if nay concern. |
||
|
||
if (!notificationsConfig || !notifications) { | ||
return; | ||
} | ||
const entityRefsTargets = | ||
notificationsConfig.getOptionalStringArray('targets'); | ||
const hostUrl = notificationsConfig.getOptionalString('hostUrl'); | ||
|
||
notifications.send({ | ||
recipients: { | ||
type: 'entity', | ||
entityRef: entityRefsTargets ?? [], | ||
gaelgoth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
payload: { | ||
title: 'New Announcement', | ||
description: 'New announcement has been added', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we allow the user to specify the title and description via params? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
link: hostUrl | ||
gaelgoth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
? `${hostUrl}/announcements/view/${announcementId}` | ||
: `/announcements/view/${announcementId}`, | ||
}, | ||
}); | ||
}; | ||
|
||
interface AnnouncementRequest { | ||
publisher: string; | ||
|
@@ -76,6 +114,7 @@ export async function createRouter( | |
persistenceContext, | ||
permissions, | ||
signals, | ||
notifications, | ||
} = context; | ||
|
||
const { | ||
|
@@ -209,6 +248,13 @@ export async function createRouter( | |
tags: validatedTags, | ||
}); | ||
|
||
// Send announcement notification | ||
const announcementNotificationOpts = { notifications, config }; | ||
sendAnnouncementNotification( | ||
announcement.id, | ||
announcementNotificationOpts, | ||
); | ||
|
||
if (events) { | ||
events.publish({ | ||
topic: EVENTS_TOPIC_ANNOUNCEMENTS, | ||
|
Uh oh!
There was an error while loading. Please reload this page.