@@ -236,7 +236,7 @@ instance ToJSON (MessageContent 'Slack) where
236
236
[ " text" .= preText,
237
237
" attachments"
238
238
.= [ Aeson. object
239
- [ " title" .= title,
239
+ [ " title" .= cutOffText 250 title,
240
240
" title_link" .= uriToText mainLink,
241
241
" text" .= content,
242
242
" author_name" .= authorName,
@@ -254,13 +254,13 @@ instance ToJSON (MessageContent 'Discord) where
254
254
Aeson. object
255
255
[ " username" .= (" Share Notifications" :: Text ),
256
256
" avatar_url" .= Links. unisonLogoImage,
257
- " content" .= preText,
257
+ " content" .= cutOffText 1950 preText,
258
258
" embeds"
259
259
.= [ Aeson. object
260
- [ " title" .= title,
260
+ [ " title" .= cutOffText 250 title,
261
261
" url" .= uriToText mainLink,
262
- " description" .= content,
263
- " author" .= Aeson. object [" name" .= authorName, " url" .= uriToText authorLink, " icon_url" .= fmap uriToText authorAvatarUrl],
262
+ " description" .= cutOffText 4000 content,
263
+ " author" .= Aeson. object [" name" .= cutOffText 250 authorName, " url" .= uriToText authorLink, " icon_url" .= fmap uriToText authorAvatarUrl],
264
264
" timestamp" .= (Just $ Text. pack $ Time. formatTime Time. defaultTimeLocale " %FT%T%QZ" timestamp),
265
265
" thumbnail" .= fmap (\ url -> Aeson. object [" url" .= uriToText url]) thumbnailUrl
266
266
]
@@ -270,9 +270,9 @@ instance ToJSON (MessageContent 'Discord) where
270
270
buildWebhookRequest :: NotificationWebhookId -> URI -> NotificationEvent NotificationEventId UnifiedDisplayInfo UTCTime HydratedEventPayload -> WebhookEventPayload JWTParam -> Background (Either WebhookSendFailure HTTPClient. Request )
271
271
buildWebhookRequest webhookId uri event defaultPayload = do
272
272
if
273
- | isSlackWebhook uri -> buildChatAppPayload (Proxy @ Slack ) uri
274
- | isDiscordWebhook uri -> buildChatAppPayload (Proxy @ Discord ) uri
275
- | otherwise -> pure $ buildDefaultPayload
273
+ | isSlackWebhook uri -> buildChatAppPayload (Proxy @ Slack ) uri
274
+ | isDiscordWebhook uri -> buildChatAppPayload (Proxy @ Discord ) uri
275
+ | otherwise -> pure $ buildDefaultPayload
276
276
where
277
277
isSlackWebhook :: URI -> Bool
278
278
isSlackWebhook uri =
@@ -355,6 +355,13 @@ buildWebhookRequest webhookId uri event defaultPayload = do
355
355
}
356
356
)
357
357
358
+ -- | Nicely cut off text so that it doesn't exceed the max length
359
+ cutOffText :: Int -> Text -> Text
360
+ cutOffText maxLength text =
361
+ if Text. length text > maxLength
362
+ then Text. take (maxLength - 3 ) text <> " ..."
363
+ else text
364
+
358
365
attemptWebhookSend ::
359
366
AuthZ. AuthZReceipt ->
360
367
(NotificationEvent NotificationEventId UnifiedDisplayInfo UTCTime HydratedEventPayload -> NotificationWebhookId -> IO (Maybe WebhookSendFailure )) ->
0 commit comments