Skip to content

The open alternative to Salesforce, designed for AI.

feat(twenty-slack): stop Slack unfurling the record links in assistant replies (#24054)

Abdul Rahmand1c5d75e431a
diff --git a/packages/twenty-apps/public/slack/src/logic-functions/handlers/__tests__/slack-post-message-handler.test.ts b/packages/twenty-apps/public/slack/src/logic-functions/handlers/__tests__/slack-post-message-handler.test.ts
index 1e4d01feb8f..fb53031054b 100644
--- a/packages/twenty-apps/public/slack/src/logic-functions/handlers/__tests__/slack-post-message-handler.test.ts
+++ b/packages/twenty-apps/public/slack/src/logic-functions/handlers/__tests__/slack-post-message-handler.test.ts
@@ -63,6 +63,38 @@ describe('slackPostMessageHandler', () => {
});
});
+ it('should leave Slack link previews alone when the caller does not ask for them to be turned off', async () => {
+ postMessageMock.mockResolvedValue({ ts: '1700000000.000600' });
+
+ await slackPostMessageHandler({
+ slackChannelId: CHANNEL_ID,
+ messageText: 'hello',
+ });
+
+ expect(postMessageMock).toHaveBeenCalledTimes(1);
+ expect(postMessageMock.mock.calls[0][0]).toStrictEqual({
+ channel: CHANNEL_ID,
+ thread_ts: undefined,
+ text: 'hello',
+ });
+ });
+
+ it('should turn off link and media previews when asked', async () => {
+ postMessageMock.mockResolvedValue({ ts: '1700000000.000700' });
+
+ await slackPostMessageHandler({
+ slackChannelId: CHANNEL_ID,
+ messageText: 'hello',
+ unfurlLinks: false,
+ unfurlMedia: false,
+ });
+
+ expect(postMessageMock).toHaveBeenCalledTimes(1);
+ expect(postMessageMock).toHaveBeenCalledWith(
+ expect.objectContaining({ unfurl_links: false, unfurl_media: false }),
+ );
+ });
+
it('should reply inside a thread with a trimmed parent timestamp', async () => {
postMessageMock.mockResolvedValue({
ts: '1700000000.000200',
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.ts
index 62b48c6429d..06956056e82 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
@@ -129,6 +129,8 @@ export const slackAssistantWorkerHandler = async (
}),
parentMessageTimestamp,
messageFormat: 'markdown',
+ unfurlLinks: false,
+ unfurlMedia: false,
messageBlocks:
responseText.length > SLACK_MARKDOWN_BLOCK_MAX_LENGTH
? undefined
diff --git a/packages/twenty-apps/public/slack/src/logic-functions/types/slack-post-message-input.type.ts b/packages/twenty-apps/public/slack/src/logic-functions/types/slack-post-message-input.type.ts
index 6eaf5f5e3f0..24562a2a10a 100644
--- a/packages/twenty-apps/public/slack/src/logic-functions/types/slack-post-message-input.type.ts
+++ b/packages/twenty-apps/public/slack/src/logic-functions/types/slack-post-message-input.type.ts
@@ -1,7 +1,9 @@
import { type SlackMessageBody } from 'src/logic-functions/types/slack-message-body.type';
+import { type SlackUnfurlOptions } from 'src/logic-functions/types/slack-unfurl-options.type';
export type SlackPostMessageInput = {
slackChannelId: string;
messageText: string;
parentMessageTimestamp?: string;
-} & SlackMessageBody;
+} & SlackMessageBody &
+ SlackUnfurlOptions;
diff --git a/packages/twenty-apps/public/slack/src/logic-functions/types/slack-unfurl-options.type.ts b/packages/twenty-apps/public/slack/src/logic-functions/types/slack-unfurl-options.type.ts
new file mode 100644
index 00000000000..cb66c43724c
--- /dev/null
+++ b/packages/twenty-apps/public/slack/src/logic-functions/types/slack-unfurl-options.type.ts
@@ -0,0 +1,4 @@
+export type SlackUnfurlOptions = {
+ unfurlLinks?: boolean;
+ unfurlMedia?: boolean;
+};
diff --git a/packages/twenty-apps/public/slack/src/logic-functions/utils/post-slack-message.ts b/packages/twenty-apps/public/slack/src/logic-functions/utils/post-slack-message.ts
index c7ffee3c311..a2ad0ceb515 100644
--- a/packages/twenty-apps/public/slack/src/logic-functions/utils/post-slack-message.ts
+++ b/packages/twenty-apps/public/slack/src/logic-functions/utils/post-slack-message.ts
@@ -1,4 +1,5 @@
import { type WebClient } from '@slack/web-api';
+import { isDefined } from 'twenty-sdk/utils';
import { type SlackPostMessageInput } from 'src/logic-functions/types/slack-post-message-input.type';
import { type SlackToolResult } from 'src/logic-functions/types/slack-tool-result.type';
@@ -24,6 +25,12 @@ export const postSlackMessage = async (
const data = await client.chat.postMessage({
channel: parameters.slackChannelId,
thread_ts: parentTimestamp,
+ ...(isDefined(parameters.unfurlLinks)
+ ? { unfurl_links: parameters.unfurlLinks }
+ : {}),
+ ...(isDefined(parameters.unfurlMedia)
+ ? { unfurl_media: parameters.unfurlMedia }
+ : {}),
...bodyFields,
});