Skip to content
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

chore(Mattermost): Catch notification errors #10729

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ REDIS_URL='redis://localhost:6379'
# Disable the built in Mattermost webhook integration
# MATTERMOST_DISABLED='false'
# For private instances with SSO and the Mattermost plugin, set the secret and URL
# MATTERMOST_SECRET=''
# MATTERMOST_URL=''
# MATTERMOST_SECRET='key_MATTERMOST_SECRET'
# MATTERMOST_URL='https://mattermost.example.com'
# MSTEAMS_DISABLED='false'

# MAIL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import {
makeHackedFieldButtonValue
} from './makeMattermostAttachments'

const MATTERMOST_URL = process.env.MATTERMOST_URL && new URL(process.env.MATTERMOST_URL)
const MATTERMOST_SECRET = process.env.MATTERMOST_SECRET

const notifyMattermost = async (
event: SlackNotification['event'],
channel: {webhookUrl: string | null; serverBaseUrl: string | null; sharedSecret: string | null},
Expand Down Expand Up @@ -358,13 +361,13 @@ async function getMattermost(
userId: string,
event: NotificationSettings['event']
) {
if (process.env.MATTERMOST_SECRET && process.env.MATTERMOST_URL) {
if (MATTERMOST_SECRET && MATTERMOST_URL) {
return [
MattermostNotificationHelper({
userId,
teamId,
serverBaseUrl: process.env.MATTERMOST_URL,
sharedSecret: process.env.MATTERMOST_SECRET,
serverBaseUrl: MATTERMOST_URL.toString(),
sharedSecret: MATTERMOST_SECRET,
webhookUrl: null
})
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {getTeamPromptResponsesByMeetingId} from '../../../../postgres/queries/getTeamPromptResponsesByMeetingIds'
import {SlackNotification} from '../../../../postgres/types'
import sendToSentry from '../../../../utils/sendToSentry'
import {DataLoaderWorker} from '../../../graphql'
import {NotificationIntegration, NotifyResponse} from './NotificationIntegrationHelper'

Expand Down Expand Up @@ -57,19 +58,30 @@ async function loadMeetingTeam(dataLoader: DataLoaderWorker, meetingId: string,
}
}

const fireAndForget = (
notifiers: NotificationIntegration[],
call: (notifier: NotificationIntegration) => Promise<NotifyResponse> | undefined
) => {
notifiers.forEach((notifier) => {
call(notifier)?.catch((e) => {
sendToSentry(e)
})
})
}

export const createNotifier = (loader: NotificationIntegrationLoader): Notifier => ({
async startMeeting(dataLoader: DataLoaderWorker, meetingId: string, teamId: string) {
const {meeting, team, user} = await loadMeetingTeam(dataLoader, meetingId, teamId)
if (!meeting || !team || !user) return
const notifiers = await loader(dataLoader, team.id, meeting.facilitatorUserId!, 'meetingStart')
notifiers.forEach((notifier) => notifier.startMeeting(meeting, team, user))
fireAndForget(notifiers, (notifier) => notifier.startMeeting(meeting, team, user))
},

async updateMeeting(dataLoader: DataLoaderWorker, meetingId: string, teamId: string) {
const {meeting, team, user} = await loadMeetingTeam(dataLoader, meetingId, teamId)
if (!meeting || !team || !user) return
const notifiers = await loader(dataLoader, team.id, meeting.facilitatorUserId!, 'meetingStart')
notifiers.forEach((notifier) => notifier.updateMeeting?.(meeting, team, user))
fireAndForget(notifiers, (notifier) => notifier.updateMeeting?.(meeting, team, user))
},

async endMeeting(dataLoader: DataLoaderWorker, meetingId: string, teamId: string) {
Expand All @@ -86,7 +98,9 @@ export const createNotifier = (loader: NotificationIntegrationLoader): Notifier
})
)
const notifiers = await loader(dataLoader, team.id, meeting.facilitatorUserId!, 'meetingEnd')
notifiers.forEach((notifier) => notifier.endMeeting(meeting, team, user, standupResponses))
fireAndForget(notifiers, (notifier) =>
notifier.endMeeting(meeting, team, user, standupResponses)
)
},

async startTimeLimit(
Expand All @@ -103,7 +117,9 @@ export const createNotifier = (loader: NotificationIntegrationLoader): Notifier
meeting.facilitatorUserId!,
'MEETING_STAGE_TIME_LIMIT_START'
)
notifiers.forEach((notifier) => notifier.startTimeLimit(scheduledEndTime, meeting, team, user))
fireAndForget(notifiers, (notifier) =>
notifier.startTimeLimit(scheduledEndTime, meeting, team, user)
)
},

async endTimeLimit(dataLoader: DataLoaderWorker, meetingId: string, teamId: string) {
Expand All @@ -115,14 +131,14 @@ export const createNotifier = (loader: NotificationIntegrationLoader): Notifier
meeting.facilitatorUserId!,
'MEETING_STAGE_TIME_LIMIT_END'
)
notifiers.forEach((notifier) => notifier.endTimeLimit(meeting, team, user))
fireAndForget(notifiers, (notifier) => notifier.endTimeLimit(meeting, team, user))
},

async integrationUpdated(dataLoader: DataLoaderWorker, teamId: string, userId: string) {
const notifiers = await loader(dataLoader, teamId, userId, 'meetingEnd')
const user = await dataLoader.get('users').load(userId)
if (!user) return
notifiers.forEach((notifier) => notifier.integrationUpdated(user))
fireAndForget(notifiers, (notifier) => notifier.integrationUpdated(user))
},

async standupResponseSubmitted(
Expand All @@ -144,7 +160,7 @@ export const createNotifier = (loader: NotificationIntegrationLoader): Notifier
meeting.facilitatorUserId!,
'STANDUP_RESPONSE_SUBMITTED'
)
notifiers.forEach((notifier) =>
fireAndForget(notifiers, (notifier) =>
notifier.standupResponseSubmitted(meeting, team, user, response)
)
}
Expand Down
Loading