Skip to content

Commit

Permalink
feat: add slack notification for mention and kudos in reflections (#9377
Browse files Browse the repository at this point in the history
)

* feat: add notifications for mention in reflections and show kudos preview

* Fix types

* feat: add slack notification for mention and kudos in reflections

* use const
  • Loading branch information
igorlesnenko committed Jan 25, 2024
1 parent a7f9b5d commit bd0347b
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 16 deletions.
1 change: 1 addition & 0 deletions packages/client/components/Mentioned.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const Mentioned = (props: Props) => {
retroReflection,
retroDiscussStageIdx
} = notification

const isAnonymous = !senderName
const authorName = isAnonymous ? 'Someone' : senderName

Expand Down
1 change: 1 addition & 0 deletions packages/client/mutations/toasts/mapMentionedToToast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const mapMentionedToToast = (
retroDiscussStageIdx,
meetingId
} = notification

const isAnonymous = !senderName
const authorName = isAnonymous ? 'Someone' : senderName

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,19 @@ const getSlackMessageForNotification = async (
}
const author = await dataLoader.get('users').loadNonNull(notification.authorId)
const comment = await dataLoader.get('comments').load(notification.commentId)

const options = {
searchParams: {
utm_source: 'slack standup notification',
utm_medium: 'product',
utm_campaign: 'notifications',
responseId
}
}

const buttonUrl = makeAppURL(appOrigin, `meet/${notification.meetingId}/responses`, options)
return {
responseId,
buttonUrl,
title: `*${author.preferredName}* replied to your response in *${meeting.name}*`,
body: `> ${comment.plaintextContent}`,
buttonText: 'See the discussion'
Expand All @@ -274,11 +285,59 @@ const getSlackMessageForNotification = async (
const title = notification.kudosEmojiUnicode
? `${notification.kudosEmojiUnicode} *${author.preferredName}* mentioned you and gave kudos in their response in *${meeting.name}*`
: `*${author.preferredName}* mentioned you in their response in *${meeting.name}*`

const options = {
searchParams: {
utm_source: 'slack standup notification',
utm_medium: 'product',
utm_campaign: 'notifications',
responseId
}
}

const buttonUrl = makeAppURL(appOrigin, `meet/${notification.meetingId}/responses`, options)

return {
responseId,
buttonUrl,
title,
buttonText: 'See their response'
}
} else if (notification.type === 'MENTIONED') {
const authorName = notification.senderName ?? 'Someone'
const {meetingId} = notification

let location = 'message'
let buttonText = 'See their message'
const searchParams = {
utm_source: 'slack mention notification',
utm_medium: 'product',
utm_campaign: 'notifications'
}
let buttonUrl = makeAppURL(appOrigin, `meet/${meetingId}`, {
searchParams
})

if (notification.retroDiscussStageIdx) {
buttonText = 'See their reflection'
location = 'reflection'
buttonUrl = makeAppURL(
appOrigin,
`meet/${meetingId}/discuss/${notification.retroDiscussStageIdx}`,
{
searchParams
}
)
}

const title = notification.kudosEmojiUnicode
? `${notification.kudosEmojiUnicode} *${authorName}* mentioned you and gave kudos in their ${location} in *${meeting.name}*`
: `*${authorName}* mentioned you in their ${location} in *${meeting.name}*`

return {
buttonUrl,
title,
buttonText
}
}

return null
Expand Down Expand Up @@ -634,7 +693,11 @@ export const SlackNotifier = {
userId: string
) {
const notification = await dataLoader.get('notifications').load(notificationId)
if (notification.type !== 'RESPONSE_MENTIONED' && notification.type !== 'RESPONSE_REPLIED') {
if (
notification.type !== 'RESPONSE_MENTIONED' &&
notification.type !== 'RESPONSE_REPLIED' &&
notification.type !== 'MENTIONED'
) {
return
}

Expand All @@ -655,26 +718,16 @@ export const SlackNotifier = {
return
}

const {responseId, title, buttonText, body} = slackMessageFields
const {buttonUrl, title, buttonText, body} = slackMessageFields

if (!responseId) {
if (!buttonUrl) {
return
}

const options = {
searchParams: {
utm_source: 'slack standup notification',
utm_medium: 'product',
utm_campaign: 'notifications',
responseId
}
}

const responseUrl = makeAppURL(appOrigin, `meet/${notification.meetingId}/responses`, options)
const blocks: Array<{type: string}> = [
makeSection(title),
...(body ? [makeSection(body)] : []),
makeButtons([{text: buttonText, url: responseUrl, type: 'primary'}])
makeButtons([{text: buttonText, url: buttonUrl, type: 'primary'}])
]

const {botAccessToken} = userSlackAuth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ const sendKudos = async (
if (notificationsToInsert.length) {
await r.table('Notification').insert(notificationsToInsert).run()
notificationsToInsert.forEach((notification) => {
IntegrationNotifier.sendNotificationToUser?.(dataLoader, notification.id, notification.userId)
publishNotification(notification, subOptions)
})
}
Expand Down

0 comments on commit bd0347b

Please sign in to comment.