From cdb1824979919f1831a6ac94c331c1d4841eb92e Mon Sep 17 00:00:00 2001 From: Kathryn Beaty Date: Fri, 10 Nov 2023 11:17:13 -0500 Subject: [PATCH] truncate comment body sent to slack to stay under char limits --- .../core/server/events/listeners/slack/publishEvent.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/server/src/core/server/events/listeners/slack/publishEvent.ts b/server/src/core/server/events/listeners/slack/publishEvent.ts index 02f5b3c042..e2165934f3 100644 --- a/server/src/core/server/events/listeners/slack/publishEvent.ts +++ b/server/src/core/server/events/listeners/slack/publishEvent.ts @@ -103,9 +103,12 @@ export default class SlackPublishEvent { ); const commentLink = getURLWithCommentID(this.story.url, this.comment.id); - const body = getHTMLPlainText(getLatestRevision(this.comment).body); + // We truncate to less than 3000 characters to stay under Slack limits + const truncatedBody = getHTMLPlainText( + getLatestRevision(this.comment).body + ).slice(0, 2999); return { - text: body, + text: truncatedBody, blocks: [ { type: "section", @@ -121,7 +124,7 @@ export default class SlackPublishEvent { block_id: "body-block", text: { type: "plain_text", - text: body, + text: truncatedBody, }, }, {