The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Remove the "Answered in" duration footer from Slack assistant replies (#25237)
Abdul Rahmandab65c01bc13
diff --git a/packages/twenty-apps/public/slack/src/__tests__/slack-assistant-worker.integration-test.ts b/packages/twenty-apps/public/slack/src/__tests__/slack-assistant-worker.integration-test.tsindex cbd697cc4d4..e6c1fdf8446 100644--- a/packages/twenty-apps/public/slack/src/__tests__/slack-assistant-worker.integration-test.ts+++ b/packages/twenty-apps/public/slack/src/__tests__/slack-assistant-worker.integration-test.ts@@ -218,12 +218,6 @@ describe('Slack assistant worker', () => {expect(postedAnswer?.blocks).toEqual([{ type: 'markdown', text: 'Acme has 3 open deals.' },- {- type: 'context',- elements: [- { type: 'mrkdwn', text: expect.stringMatching(/^Answered in \d+s$/) },- ],- },// The feedback buttons carry the request record id, which is how a click// finds the answer it rates.expect.objectContaining({diff --git a/packages/twenty-apps/public/slack/src/logic-functions/slack-assistant-worker.ts b/packages/twenty-apps/public/slack/src/logic-functions/slack-assistant-worker.tsindex 6102947af0b..29bf129ff64 100644--- a/packages/twenty-apps/public/slack/src/logic-functions/slack-assistant-worker.ts+++ b/packages/twenty-apps/public/slack/src/logic-functions/slack-assistant-worker.ts@@ -17,7 +17,6 @@ import { updateSlackAssistantRequest } from 'src/logic-functions/data/update-slaimport { slackPostMessageHandler } from 'src/logic-functions/handlers/slack-post-message-handler';import { type SlackAssistantRequestRecord } from 'src/logic-functions/types/slack-assistant-request-record.type';import { buildSlackAssistantAnswerBlocks } from 'src/logic-functions/utils/build-slack-assistant-answer-blocks';-import { buildSlackAssistantAnswerText } from 'src/logic-functions/utils/build-slack-assistant-answer-text';import { buildSlackAssistantMessages } from 'src/logic-functions/utils/build-slack-assistant-messages';import { buildSlackAssistantRequestName } from 'src/logic-functions/utils/build-slack-assistant-request-name';import { extractAgentResponseText } from 'src/logic-functions/utils/extract-agent-response-text';@@ -39,7 +38,6 @@ type SlackAssistantRequestCreatedEvent = DatabaseEventPayload<export const slackAssistantWorkerHandler = async (event: SlackAssistantRequestCreatedEvent,): Promise<object> => {- const startedAt = Date.now();const record = event.properties.after;if (record.status !== SLACK_ASSISTANT_REQUEST_STATUS.PENDING) {@@ -152,14 +150,9 @@ export const slackAssistantWorkerHandler = async (});}- const durationMilliseconds = Date.now() - startedAt;-const deliveryResult = await slackPostMessageHandler({slackChannelId,- messageText: buildSlackAssistantAnswerText({- responseText,- durationMilliseconds,- }),+ messageText: responseText,parentMessageTimestamp,messageFormat: 'markdown',unfurlLinks: false,@@ -169,7 +162,6 @@ export const slackAssistantWorkerHandler = async (? undefined: buildSlackAssistantAnswerBlocks({responseText,- durationMilliseconds,requestId: record.id,}),});diff --git a/packages/twenty-apps/public/slack/src/logic-functions/utils/__tests__/build-slack-assistant-answer-blocks.test.ts b/packages/twenty-apps/public/slack/src/logic-functions/utils/__tests__/build-slack-assistant-answer-blocks.test.tsindex d5aee162b1c..43e814c3092 100644--- a/packages/twenty-apps/public/slack/src/logic-functions/utils/__tests__/build-slack-assistant-answer-blocks.test.ts+++ b/packages/twenty-apps/public/slack/src/logic-functions/utils/__tests__/build-slack-assistant-answer-blocks.test.ts@@ -5,19 +5,14 @@ import { buildSlackAssistantAnswerBlocks } from 'src/logic-functions/utils/buildconst REQUEST_ID = '3f77d0b1-30a1-4c3d-9d02-2f2a9f6f9d10';describe('buildSlackAssistantAnswerBlocks', () => {- it('should render the answer as a markdown block followed by a duration footer and feedback buttons', () => {+ it('should render the answer as a markdown block followed by feedback buttons', () => {expect(buildSlackAssistantAnswerBlocks({responseText: 'All done.',- durationMilliseconds: 3000,requestId: REQUEST_ID,}),).toEqual([{ type: 'markdown', text: 'All done.' },- {- type: 'context',- elements: [{ type: 'mrkdwn', text: 'Answered in 3s' }],- },{type: 'context_actions',block_id: REQUEST_ID,@@ -49,7 +44,6 @@ describe('buildSlackAssistantAnswerBlocks', () => {const [markdownBlock] = buildSlackAssistantAnswerBlocks({responseText,- durationMilliseconds: 1000,requestId: REQUEST_ID,});diff --git a/packages/twenty-apps/public/slack/src/logic-functions/utils/__tests__/build-slack-assistant-answer-text.test.ts b/packages/twenty-apps/public/slack/src/logic-functions/utils/__tests__/build-slack-assistant-answer-text.test.tsdeleted file mode 100644index f89bfaf39ee..00000000000--- a/packages/twenty-apps/public/slack/src/logic-functions/utils/__tests__/build-slack-assistant-answer-text.test.ts+++ /dev/null@@ -1,25 +0,0 @@-import { describe, expect, it } from 'vitest';--import { buildSlackAssistantAnswerText } from 'src/logic-functions/utils/build-slack-assistant-answer-text';--describe('buildSlackAssistantAnswerText', () => {- it('should append the formatted duration to the response', () => {- const text = buildSlackAssistantAnswerText({- responseText: 'ACME has 3 open opportunities.',- durationMilliseconds: 4200,- });-- expect(text).toBe('ACME has 3 open opportunities.\n\n_Answered in 4s_');- });-- it('should keep the response body untouched and put the footer after it', () => {- const responseText = '**bold**\n- item';-- expect(- buildSlackAssistantAnswerText({- responseText,- durationMilliseconds: 1000,- }),- ).toBe('**bold**\n- item\n\n_Answered in 1s_');- });-});diff --git a/packages/twenty-apps/public/slack/src/logic-functions/utils/build-slack-assistant-answer-blocks.ts b/packages/twenty-apps/public/slack/src/logic-functions/utils/build-slack-assistant-answer-blocks.tsindex 33dfcfc93c0..004954a0a93 100644--- a/packages/twenty-apps/public/slack/src/logic-functions/utils/build-slack-assistant-answer-blocks.ts+++ b/packages/twenty-apps/public/slack/src/logic-functions/utils/build-slack-assistant-answer-blocks.ts@@ -2,27 +2,15 @@ import { type KnownBlock } from '@slack/web-api';import { SLACK_ASSISTANT_FEEDBACK_ACTION_ID } from 'src/logic-functions/constants/slack-assistant-feedback-action-id';import { SLACK_ASSISTANT_FEEDBACK_BUTTON_VALUE } from 'src/logic-functions/constants/slack-assistant-feedback-button-value';-import { formatSlackAssistantDuration } from 'src/logic-functions/utils/format-slack-assistant-duration';export const buildSlackAssistantAnswerBlocks = ({responseText,- durationMilliseconds,requestId,}: {responseText: string;- durationMilliseconds: number;requestId: string;}): KnownBlock[] => [{ type: 'markdown', text: responseText },- {- type: 'context',- elements: [- {- type: 'mrkdwn',- text: `Answered in ${formatSlackAssistantDuration(durationMilliseconds)}`,- },- ],- },{type: 'context_actions',block_id: requestId,diff --git a/packages/twenty-apps/public/slack/src/logic-functions/utils/build-slack-assistant-answer-text.ts b/packages/twenty-apps/public/slack/src/logic-functions/utils/build-slack-assistant-answer-text.tsdeleted file mode 100644index f66fae77bb8..00000000000--- a/packages/twenty-apps/public/slack/src/logic-functions/utils/build-slack-assistant-answer-text.ts+++ /dev/null@@ -1,10 +0,0 @@-import { formatSlackAssistantDuration } from 'src/logic-functions/utils/format-slack-assistant-duration';--export const buildSlackAssistantAnswerText = ({- responseText,- durationMilliseconds,-}: {- responseText: string;- durationMilliseconds: number;-}): string =>- `${responseText}\n\n_Answered in ${formatSlackAssistantDuration(durationMilliseconds)}_`;diff --git a/packages/twenty-apps/public/slack/src/logic-functions/utils/format-slack-assistant-duration.ts b/packages/twenty-apps/public/slack/src/logic-functions/utils/format-slack-assistant-duration.tsdeleted file mode 100644index 175eee9466b..00000000000--- a/packages/twenty-apps/public/slack/src/logic-functions/utils/format-slack-assistant-duration.ts+++ /dev/null@@ -1,24 +0,0 @@-const MILLISECONDS_PER_SECOND = 1000;-const SECONDS_PER_MINUTE = 60;--export const formatSlackAssistantDuration = (- durationMilliseconds: number,-): string => {- const totalSeconds = Math.max(- 0,- Math.round(durationMilliseconds / MILLISECONDS_PER_SECOND),- );-- if (totalSeconds < SECONDS_PER_MINUTE) {- return `${totalSeconds}s`;- }-- const minutes = Math.floor(totalSeconds / SECONDS_PER_MINUTE);- const seconds = totalSeconds % SECONDS_PER_MINUTE;-- if (seconds === 0) {- return `${minutes}m`;- }-- return `${minutes}m ${seconds}s`;-};diff --git a/packages/twenty-apps/public/slack/src/logic-functions/utils/strip-slack-assistant-answer-footer.ts b/packages/twenty-apps/public/slack/src/logic-functions/utils/strip-slack-assistant-answer-footer.tsindex 774b936f95e..f3210212447 100644--- a/packages/twenty-apps/public/slack/src/logic-functions/utils/strip-slack-assistant-answer-footer.ts+++ b/packages/twenty-apps/public/slack/src/logic-functions/utils/strip-slack-assistant-answer-footer.ts@@ -1,4 +1,5 @@-// mirrors the footer appended by buildSlackAssistantAnswerText+// older versions of the bot appended this footer to every answer; still-live+// threads carry those messages, so replayed history keeps needing the stripconst ANSWER_FOOTER_PATTERN = /\n\n_Answered in [^\n_]+_$/;export const stripSlackAssistantAnswerFooter = (text: string): string =>