|
| 1 | +{-# LANGUAGE DataKinds #-} |
1 | 2 | {-# LANGUAGE MultiWayIf #-}
|
2 | 3 | {-# LANGUAGE StandaloneDeriving #-}
|
3 | 4 |
|
@@ -241,55 +242,59 @@ buildWebhookRequest webhookId uri event defaultPayload = do
|
241 | 242 | HTTPClient.requestBody = HTTPClient.RequestBodyLBS $ Aeson.encode defaultPayload
|
242 | 243 | }
|
243 | 244 |
|
244 |
| - mkSlackAttachment :: Maybe URI -> Text -> Text -> Text -> UTCTime -> Aeson.Value |
245 |
| - mkSlackAttachment mainURI author title msg timestamp = |
| 245 | + mkSlackAttachment :: Text -> URI -> Text -> URI -> Maybe URI -> Text -> Text -> UTCTime -> Aeson.Value |
| 246 | + mkSlackAttachment preText mainURI authorName authorLink authorAvatarUrl title msg timestamp = |
246 | 247 | let epochSeconds :: Int64
|
247 | 248 | epochSeconds = round (POSIX.utcTimeToPOSIXSeconds timestamp)
|
248 | 249 | t :: Text -> Text
|
249 | 250 | t x = x
|
250 | 251 | in Aeson.object $
|
251 | 252 | [ "mrkdwn_in" Aeson..= [t "text"],
|
252 | 253 | "color" .= t "#36a64f",
|
253 |
| - -- "pretext" .= "Optional pre-text that appears above the attachment block", |
254 |
| - "author_name" .= author, |
255 |
| - -- "author_link" .= "http://flickr.com/bobby/", |
256 |
| - -- "author_icon" .= "https://placeimg.com/16/16/people", |
| 254 | + "pretext" .= preText, |
| 255 | + "author_name" .= authorName, |
| 256 | + "author_link" .= uriToText authorLink, |
257 | 257 | "title" .= title,
|
| 258 | + "title_link" .= uriToText mainURI, |
258 | 259 | "text" .= msg,
|
259 |
| - -- "thumb_url" .= "http://placekitten.com/g/200/200", |
| 260 | + "thumb_url" .= uriToText Links.unisonLogoImage, |
260 | 261 | -- "footer" .= "footer",
|
261 | 262 | -- "footer_icon" .= "https://platform.slack-edge.com/img/default_application_icon.png",
|
262 | 263 | "ts" .= epochSeconds
|
263 | 264 | ]
|
264 |
| - <> (mainURI & foldMap \uri -> ["title_link" .= uriToText uri]) |
| 265 | + <> (authorAvatarUrl & foldMap \uri -> ["author_icon" .= uriToText uri]) |
265 | 266 | buildSlackWebhookRequest :: URI -> AppM reqCtx (Either WebhookSendFailure HTTPClient.Request)
|
266 | 267 | buildSlackWebhookRequest uri = do
|
267 | 268 | let actorName = event.eventActor ^. DisplayInfo.name_
|
268 |
| - actorHandle = "(" <> IDs.toText (event.eventActor ^. DisplayInfo.handle_) <> ")" |
| 269 | + actorHandle = "(" <> IDs.toText (PrefixedID @"@" $ event.eventActor ^. DisplayInfo.handle_) <> ")" |
269 | 270 | actorAuthor = maybe "" (<> " ") actorName <> actorHandle
|
| 271 | + actorAvatarUrl = event.eventActor ^. DisplayInfo.avatarUrl_ |
| 272 | + actorLink <- Links.userProfilePage (event.eventActor ^. DisplayInfo.handle_) |
270 | 273 | slackPayload <- case event.eventData of
|
271 | 274 | HydratedProjectBranchUpdatedPayload payload -> do
|
272 | 275 | let pbShorthand = (projectBranchShortHandFromParts payload.projectInfo.projectShortHand payload.branchInfo.branchShortHand)
|
273 | 276 | title = "Branch " <> IDs.toText pbShorthand <> " was just updated."
|
274 |
| - msg = "Branch " <> IDs.toText pbShorthand <> " was just updated." |
| 277 | + msg = "" |
| 278 | + preText = title |
275 | 279 | link <- Links.notificationLink event.eventData
|
276 | 280 | pure $
|
277 | 281 | Aeson.object
|
278 |
| - [ "text" Aeson..= msg, |
| 282 | + [ "text" Aeson..= title, |
279 | 283 | "attachments"
|
280 |
| - Aeson..= [ mkSlackAttachment (Just link) actorAuthor title msg event.eventOccurredAt |
| 284 | + Aeson..= [ mkSlackAttachment preText link actorAuthor actorLink actorAvatarUrl title msg event.eventOccurredAt |
281 | 285 | ]
|
282 | 286 | ]
|
283 | 287 | HydratedProjectContributionCreatedPayload payload -> do
|
284 | 288 | let pbShorthand = (projectBranchShortHandFromParts payload.projectInfo.projectShortHand payload.contributionInfo.contributionSourceBranch.branchShortHand)
|
285 |
| - title = "New Contribution in " <> IDs.toText pbShorthand |
286 |
| - msg = payload.contributionInfo.contributionTitle <> maybe "" (<> " — ") payload.contributionInfo.contributionDescription |
| 289 | + title = payload.contributionInfo.contributionTitle |
| 290 | + msg = fromMaybe "" payload.contributionInfo.contributionDescription |
| 291 | + preText = "New Contribution in " <> IDs.toText pbShorthand |
287 | 292 | link <- Links.notificationLink event.eventData
|
288 | 293 | pure $
|
289 | 294 | Aeson.object
|
290 |
| - [ "text" Aeson..= msg, |
| 295 | + [ "text" Aeson..= preText, |
291 | 296 | "attachments"
|
292 |
| - Aeson..= [ mkSlackAttachment (Just link) actorAuthor title msg event.eventOccurredAt |
| 297 | + Aeson..= [ mkSlackAttachment preText link actorAuthor actorLink actorAvatarUrl title msg event.eventOccurredAt |
293 | 298 | ]
|
294 | 299 | ]
|
295 | 300 | pure $
|
|
0 commit comments