Skip to content

The open alternative to Salesforce, designed for AI.

feat(slack): report a broken connection through the app health check (#26414)

Abdul Rahmand01e7f6e8b55
diff --git a/packages/twenty-apps/public/slack/package.json b/packages/twenty-apps/public/slack/package.json
index 887c4d95211..2c01c57d4b4 100644
--- a/packages/twenty-apps/public/slack/package.json
+++ b/packages/twenty-apps/public/slack/package.json
@@ -1,10 +1,10 @@
{
"name": "@twentyhq/slack",
- "version": "1.4.2",
+ "version": "1.5.0",
"description": "Slack assistant and workflow steps for Twenty",
"license": "MIT",
"engines": {
- "twenty": ">=2.41.0",
+ "twenty": ">=2.42.0",
"node": "^24.5.0",
"npm": "please-use-yarn",
"yarn": ">=4.0.2"
@@ -41,8 +41,8 @@
"oxlint": "^0.16.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
- "twenty-client-sdk": "^2.41.0",
- "twenty-sdk": "^2.41.0",
+ "twenty-client-sdk": "^2.42.0",
+ "twenty-sdk": "^2.42.0",
"twenty-ui": "^1.0.0-alpha.1",
"typescript": "^5.9.3",
"vite-tsconfig-paths": "^4.2.1",
diff --git a/packages/twenty-apps/public/slack/src/constants/universal-identifiers.ts b/packages/twenty-apps/public/slack/src/constants/universal-identifiers.ts
index 753ee0834cd..9f104b0804a 100644
--- a/packages/twenty-apps/public/slack/src/constants/universal-identifiers.ts
+++ b/packages/twenty-apps/public/slack/src/constants/universal-identifiers.ts
@@ -225,3 +225,6 @@ export const SLACK_REMOVE_CHANNEL_RULE_UNIVERSAL_IDENTIFIER =
export const SLACK_SEARCH_CHANNELS_UNIVERSAL_IDENTIFIER =
'41047b7d-e551-4c35-919a-5cb2bb60efbf';
+
+export const SLACK_HEALTH_CHECK_UNIVERSAL_IDENTIFIER =
+ '7c303a5c-80ff-4e27-9997-c6c14239c0ba';
diff --git a/packages/twenty-apps/public/slack/src/front-components/components/SlackUserLinksSettings.tsx b/packages/twenty-apps/public/slack/src/front-components/components/SlackUserLinksSettings.tsx
index 696a324c32f..3d1c273cd69 100644
--- a/packages/twenty-apps/public/slack/src/front-components/components/SlackUserLinksSettings.tsx
+++ b/packages/twenty-apps/public/slack/src/front-components/components/SlackUserLinksSettings.tsx
@@ -18,7 +18,6 @@ import { SlackChannelRulesSection } from 'src/front-components/components/SlackC
import { SlackUserLinkForm } from 'src/front-components/components/SlackUserLinkForm';
import { SlackUserLinksList } from 'src/front-components/components/SlackUserLinksList';
import { UnlinkedSlackUsersList } from 'src/front-components/components/UnlinkedSlackUsersList';
-import { SLACK_CONNECTION_HEALTH_CALLOUTS } from 'src/front-components/constants/slack-connection-health-callouts.constant';
import { useCanManageSlackUserLinks } from 'src/front-components/hooks/use-can-manage-slack-user-links';
import { useMatchSlackUserLinks } from 'src/front-components/hooks/use-match-slack-user-links';
import { useSlackConnectionStatus } from 'src/front-components/hooks/use-slack-connection-status';
@@ -28,6 +27,7 @@ import { useSlackUserLinks } from 'src/front-components/hooks/use-slack-user-lin
import { useUnlinkedSlackUsers } from 'src/front-components/hooks/use-unlinked-slack-users';
import { type SlackUserLinkRecord } from 'src/front-components/types/slack-user-link-record.type';
import { enqueueSlackToolResultSnackbar } from 'src/front-components/utils/enqueue-slack-tool-result-snackbar.util';
+import { SLACK_CONNECTION_HEALTH } from 'src/logic-functions/constants/slack-connection-health';
const StyledContainer = styled.div`
box-sizing: border-box;
@@ -167,24 +167,14 @@ const SlackUserLinksSettingsContent = () => {
}
};
- if (isConnectionStatusLoading || !isSlackConnected) {
- return null;
- }
-
- const connectionHealthCallout = isDefined(connectionHealth)
- ? SLACK_CONNECTION_HEALTH_CALLOUTS[connectionHealth]
- : undefined;
+ const isConnectionBroken =
+ isDefined(connectionHealth) &&
+ connectionHealth !== SLACK_CONNECTION_HEALTH.OK;
- if (isDefined(connectionHealthCallout)) {
- return (
- <StyledContainer>
- <Callout
- variant="error"
- title={connectionHealthCallout.title}
- description={connectionHealthCallout.description}
- />
- </StyledContainer>
- );
+ // A broken connection is reported by the app health banner, which stays
+ // visible next to the connection itself; the tools below need a working one.
+ if (isConnectionStatusLoading || !isSlackConnected || isConnectionBroken) {
+ return null;
}
if (isPermissionLoading) {
diff --git a/packages/twenty-apps/public/slack/src/logic-functions/constants/slack-connection-banner-action.ts b/packages/twenty-apps/public/slack/src/logic-functions/constants/slack-connection-banner-action.ts
new file mode 100644
index 00000000000..c1efaa1b9d1
--- /dev/null
+++ b/packages/twenty-apps/public/slack/src/logic-functions/constants/slack-connection-banner-action.ts
@@ -0,0 +1,6 @@
+// The connection lives in the app's General tab, so the banner button sends the
+// admin there instead of whichever tab the banner is read from.
+export const SLACK_CONNECTION_BANNER_ACTION = {
+ label: 'Manage connection',
+ location: '#general',
+};
diff --git a/packages/twenty-apps/public/slack/src/front-components/constants/slack-connection-health-callouts.constant.ts b/packages/twenty-apps/public/slack/src/logic-functions/constants/slack-connection-health-banners.ts
similarity index 84%
rename from packages/twenty-apps/public/slack/src/front-components/constants/slack-connection-health-callouts.constant.ts
rename to packages/twenty-apps/public/slack/src/logic-functions/constants/slack-connection-health-banners.ts
index 944199c05dd..fcc9af5b116 100644
--- a/packages/twenty-apps/public/slack/src/front-components/constants/slack-connection-health-callouts.constant.ts
+++ b/packages/twenty-apps/public/slack/src/logic-functions/constants/slack-connection-health-banners.ts
@@ -1,12 +1,15 @@
-import { type CalloutProps } from 'twenty-ui/feedback';
-
import {
SLACK_CONNECTION_HEALTH,
type SlackConnectionHealth,
} from 'src/logic-functions/constants/slack-connection-health';
-export const SLACK_CONNECTION_HEALTH_CALLOUTS: Partial<
- Record<SlackConnectionHealth, Pick<CalloutProps, 'title' | 'description'>>
+type SlackConnectionHealthBanner = {
+ title: string;
+ description: string;
+};
+
+export const SLACK_CONNECTION_HEALTH_BANNERS: Partial<
+ Record<SlackConnectionHealth, SlackConnectionHealthBanner>
> = {
[SLACK_CONNECTION_HEALTH.TOKEN_REJECTED]: {
title: 'Slack connection is no longer valid',
diff --git a/packages/twenty-apps/public/slack/src/logic-functions/handlers/__tests__/slack-health-check-handler.test.ts b/packages/twenty-apps/public/slack/src/logic-functions/handlers/__tests__/slack-health-check-handler.test.ts
new file mode 100644
index 00000000000..db7a4db58cf
--- /dev/null
+++ b/packages/twenty-apps/public/slack/src/logic-functions/handlers/__tests__/slack-health-check-handler.test.ts
@@ -0,0 +1,106 @@
+import { type WebClient } from '@slack/web-api';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { SLACK_CONNECTION_STATUS_TIMEOUT_MS } from 'src/logic-functions/constants/slack-connection-status-timeout-ms';
+import { slackHealthCheckHandler } from 'src/logic-functions/handlers/slack-health-check-handler';
+import { getSlackClient } from 'src/logic-functions/utils/get-slack-client';
+import { resolveSlackConnectionHealth } from 'src/logic-functions/utils/resolve-slack-connection-health';
+
+vi.mock('src/logic-functions/utils/get-slack-client', () => ({
+ getSlackClient: vi.fn(),
+}));
+
+vi.mock('src/logic-functions/utils/resolve-slack-connection-health', () => ({
+ resolveSlackConnectionHealth: vi.fn(),
+}));
+
+describe('slackHealthCheckHandler', () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ vi.mocked(getSlackClient).mockResolvedValue({
+ success: true,
+ client: {} as WebClient,
+ connectionId: 'connected-account-1',
+ });
+ vi.mocked(resolveSlackConnectionHealth).mockResolvedValue({
+ connectionHealth: 'ok',
+ installedSlackTeamId: 'T0INSTALLED',
+ });
+ });
+
+ it('should bound the Slack call so a hanging Slack cannot exhaust the check budget', async () => {
+ await slackHealthCheckHandler();
+
+ expect(getSlackClient).toHaveBeenCalledTimes(1);
+ expect(getSlackClient).toHaveBeenCalledWith({
+ timeout: SLACK_CONNECTION_STATUS_TIMEOUT_MS,
+ retryConfig: { retries: 0 },
+ });
+ });
+
+ it('should report nothing for a healthy connection', async () => {
+ await expect(slackHealthCheckHandler()).resolves.toEqual({ status: 'OK' });
+ });
+
+ it('should report nothing when Slack is not connected', async () => {
+ vi.mocked(getSlackClient).mockResolvedValue({
+ success: false,
+ error: 'Slack is not connected.',
+ });
+
+ await expect(slackHealthCheckHandler()).resolves.toEqual({ status: 'OK' });
+
+ expect(resolveSlackConnectionHealth).not.toHaveBeenCalled();
+ });
+
+ it('should report nothing when the health could not be verified', async () => {
+ vi.mocked(resolveSlackConnectionHealth).mockResolvedValue({
+ connectionHealth: undefined,
+ installedSlackTeamId: 'T0INSTALLED',
+ });
+
+ await expect(slackHealthCheckHandler()).resolves.toEqual({ status: 'OK' });
+ });
+
+ it('should report a rejected token with a button to the connection', async () => {
+ vi.mocked(resolveSlackConnectionHealth).mockResolvedValue({
+ connectionHealth: 'token_rejected',
+ installedSlackTeamId: undefined,
+ });
+
+ await expect(slackHealthCheckHandler()).resolves.toEqual({
+ status: 'ERROR',
+ title: 'Slack connection is no longer valid',
+ description: expect.stringContaining('Slack rejected the stored'),
+ action: { label: 'Manage connection', location: '#general' },
+ });
+ });
+
+ it('should report a Slack workspace claimed by another Twenty workspace', async () => {
+ vi.mocked(resolveSlackConnectionHealth).mockResolvedValue({
+ connectionHealth: 'team_claimed_by_another_workspace',
+ installedSlackTeamId: 'T0INSTALLED',
+ });
+
+ await expect(slackHealthCheckHandler()).resolves.toEqual(
+ expect.objectContaining({
+ status: 'ERROR',
+ title: 'Slack workspace already connected elsewhere',
+ }),
+ );
+ });
+
+ it('should report an unclaimed Slack workspace', async () => {
+ vi.mocked(resolveSlackConnectionHealth).mockResolvedValue({
+ connectionHealth: 'team_unclaimed',
+ installedSlackTeamId: 'T0INSTALLED',
+ });
+
+ await expect(slackHealthCheckHandler()).resolves.toEqual(
+ expect.objectContaining({
+ status: 'ERROR',
+ title: 'Slack connection needs to be registered again',
+ }),
+ );
+ });
+});
diff --git a/packages/twenty-apps/public/slack/src/logic-functions/handlers/slack-health-check-handler.ts b/packages/twenty-apps/public/slack/src/logic-functions/handlers/slack-health-check-handler.ts
new file mode 100644
index 00000000000..489166eced3
--- /dev/null
+++ b/packages/twenty-apps/public/slack/src/logic-functions/handlers/slack-health-check-handler.ts
@@ -0,0 +1,44 @@
+import { type ApplicationHealthCheckResult } from 'twenty-sdk/define';
+import { isDefined } from 'twenty-sdk/utils';
+
+import { SLACK_CONNECTION_BANNER_ACTION } from 'src/logic-functions/constants/slack-connection-banner-action';
+import { SLACK_CONNECTION_HEALTH_BANNERS } from 'src/logic-functions/constants/slack-connection-health-banners';
+import { SLACK_CONNECTION_STATUS_TIMEOUT_MS } from 'src/logic-functions/constants/slack-connection-status-timeout-ms';
+import { getSlackClient } from 'src/logic-functions/utils/get-slack-client';
+import { resolveSlackConnectionHealth } from 'src/logic-functions/utils/resolve-slack-connection-health';
+
+export const slackHealthCheckHandler =
+ async (): Promise<ApplicationHealthCheckResult> => {
+ const slackClientResult = await getSlackClient({
+ timeout: SLACK_CONNECTION_STATUS_TIMEOUT_MS,
+ retryConfig: { retries: 0 },
+ });
+
+ // Nothing to repair while Slack is not connected: the connection itself
+ // already shows that, and the banner would only repeat it.
+ if (!slackClientResult.success) {
+ return { status: 'OK' };
+ }
+
+ const { connectionHealth } = await resolveSlackConnectionHealth({
+ slackClient: slackClientResult.client,
+ connectionId: slackClientResult.connectionId,
+ });
+
+ const healthBanner = isDefined(connectionHealth)
+ ? SLACK_CONNECTION_HEALTH_BANNERS[connectionHealth]
+ : undefined;
+
+ // An unverified health reads as undefined here, so a transient Slack
+ // failure never tells an admin to reconnect a working integration.
+ if (!isDefined(healthBanner)) {
+ return { status: 'OK' };
+ }
+
+ return {
+ status: 'ERROR',
+ title: healthBanner.title,
+ description: healthBanner.description,
+ action: SLACK_CONNECTION_BANNER_ACTION,
+ };
+ };
diff --git a/packages/twenty-apps/public/slack/src/logic-functions/health-check.ts b/packages/twenty-apps/public/slack/src/logic-functions/health-check.ts
new file mode 100644
index 00000000000..16c44225c93
--- /dev/null
+++ b/packages/twenty-apps/public/slack/src/logic-functions/health-check.ts
@@ -0,0 +1,13 @@
+import { defineHealthCheck } from 'twenty-sdk/define';
+
+import { SLACK_HEALTH_CHECK_UNIVERSAL_IDENTIFIER } from 'src/constants/universal-identifiers';
+import { slackHealthCheckHandler } from 'src/logic-functions/handlers/slack-health-check-handler';
+
+export default defineHealthCheck({
+ universalIdentifier: SLACK_HEALTH_CHECK_UNIVERSAL_IDENTIFIER,
+ name: 'slack-health-check',
+ description:
+ 'Reports a broken Slack connection as a banner on the app settings page, whichever tab is open: the stored token no longer passes auth.test, or the installed Slack team is claimed by another Twenty workspace, so its messages are delivered elsewhere.',
+ timeoutSeconds: 30,
+ handler: slackHealthCheckHandler,
+});
diff --git a/packages/twenty-apps/public/slack/src/logic-functions/slack-connection-status.ts b/packages/twenty-apps/public/slack/src/logic-functions/slack-connection-status.ts
index 5263c91d6d3..1c7938c62c9 100644
--- a/packages/twenty-apps/public/slack/src/logic-functions/slack-connection-status.ts
+++ b/packages/twenty-apps/public/slack/src/logic-functions/slack-connection-status.ts
@@ -8,7 +8,7 @@ export default defineLogicFunction({
universalIdentifier: SLACK_CONNECTION_STATUS_UNIVERSAL_IDENTIFIER,
name: 'slack-connection-status',
description:
- 'Tells the settings tab whether a Slack workspace connection exists and whether it is healthy: the stored token still passes auth.test, and the installed Slack team is claimed by this Twenty workspace so events route here. The tab hides the link management tools until Slack is connected and shows a repair callout when the connection is broken.',
+ 'Tells the settings tab whether a Slack workspace connection exists and whether it is healthy: the stored token still passes auth.test, and the installed Slack team is claimed by this Twenty workspace so events route here. The tab hides the link management tools until Slack is connected and while the connection is broken, which the app health check reports as a banner on the settings page.',
timeoutSeconds: 30,
httpRouteTriggerSettings: {
path: SLACK_USER_LINKS_CONNECTION_STATUS_ROUTE_PATH,
diff --git a/packages/twenty-apps/public/slack/yarn.lock b/packages/twenty-apps/public/slack/yarn.lock
index 01abeaed849..949695ea40e 100644
--- a/packages/twenty-apps/public/slack/yarn.lock
+++ b/packages/twenty-apps/public/slack/yarn.lock
@@ -1475,8 +1475,8 @@ __metadata:
oxlint: "npm:^0.16.0"
react: "npm:^18.2.0"
react-dom: "npm:^18.2.0"
- twenty-client-sdk: "npm:^2.41.0"
- twenty-sdk: "npm:^2.41.0"
+ twenty-client-sdk: "npm:^2.42.0"
+ twenty-sdk: "npm:^2.42.0"
twenty-ui: "npm:^1.0.0-alpha.1"
typescript: "npm:^5.9.3"
vite-tsconfig-paths: "npm:^4.2.1"
@@ -4073,22 +4073,22 @@ __metadata:
languageName: node
linkType: hard
-"twenty-client-sdk@npm:2.41.0, twenty-client-sdk@npm:^2.41.0":
- version: 2.41.0
- resolution: "twenty-client-sdk@npm:2.41.0"
+"twenty-client-sdk@npm:2.42.0, twenty-client-sdk@npm:^2.42.0":
+ version: 2.42.0
+ resolution: "twenty-client-sdk@npm:2.42.0"
dependencies:
"@genql/runtime": "npm:^2.10.0"
esbuild: "npm:^0.28.1"
graphql: "npm:^16.8.1"
lodash: "npm:^4.17.21"
prettier: "npm:^3.8.3"
- checksum: 10c0/7b7e555dbd24ce359c4d21f7465f43307945622a3be429bce0f6b97d1cfc21280db0c7dba24036128380f28b60b82f13dc7434eac422d2bc1c0111c4f96338dd
+ checksum: 10c0/38f77595ffc2bb365cef23a30d7ab7096fcf129d407921bb97497327da27526e9721ba6a1a16d299bd9b3a2e3f0eeac3fb41ec360c0547e7a2c0f0c044cc570b
languageName: node
linkType: hard
-"twenty-sdk@npm:^2.41.0":
- version: 2.41.0
- resolution: "twenty-sdk@npm:2.41.0"
+"twenty-sdk@npm:^2.42.0":
+ version: 2.42.0
+ resolution: "twenty-sdk@npm:2.42.0"
dependencies:
"@sniptt/guards": "npm:^0.2.0"
axios: "npm:^1.16.0"
@@ -4107,12 +4107,12 @@ __metadata:
semver: "npm:7.6.3"
sharp: "npm:^0.35.3"
tinyglobby: "npm:^0.2.15"
- twenty-client-sdk: "npm:2.41.0"
+ twenty-client-sdk: "npm:2.42.0"
typescript: "npm:^5.9.3"
uuid: "npm:^13.0.2"
bin:
twenty: dist/cli.cjs
- checksum: 10c0/1229f01f8fa77f10a89643a88ca93eb41eedd46ee0376ec47b9ef10d771fb8c6850a090dea3805bc22cdfdc117613e6ca2c009b6382fa11bc5c6da3e06152611
+ checksum: 10c0/1e43d0c2af55ab8705506f55fe693688575325e506b6cfb16ba4d486d0bfdc0c0f257fc8963ee86f218c10d09b87bacdc769803b6b59283f9e24c7a88346fb84
languageName: node
linkType: hard