The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
feat(slack): adopt the native agent surface, starting with suggested prompts (#23838)
Abdul Rahmanad9df657c5eb
diff --git a/packages/twenty-apps/public/slack/SETUP.md b/packages/twenty-apps/public/slack/SETUP.mdindex fc710154cf9..bb1acc65a63 100644--- a/packages/twenty-apps/public/slack/SETUP.md+++ b/packages/twenty-apps/public/slack/SETUP.md@@ -4,7 +4,9 @@ Two parts: a **Slack app** you create, and the **Twenty side** where you paste i## 1. Slack app-1. Create a Slack app at [api.slack.com/apps](https://api.slack.com/apps). Use a dedicated app — do not reuse one across Twenty apps.+1. Create a Slack app at [api.slack.com/apps](https://api.slack.com/apps) → **Create New App → From a manifest**, pasting [`slack-app-manifest.json`](./slack-app-manifest.json) with both `<YOUR_TWENTY_SERVER_URL>` placeholders replaced. The manifest is the source of truth for scopes, event subscriptions and the agent surface — the steps below describe what it configures, so an app created from it only needs credentials copied (step 4). Use a dedicated app — do not reuse one across Twenty apps.++ The manifest enables `agent_view` (Slack's Agent messaging experience): the app is listed as an agent in Slack's UI and shows clickable suggested prompts at the top of its Messages tab. The native thinking status for replies is not wired up yet and arrives with a later release. On an app configured by hand instead, enable **Agents & AI Apps** in the app settings, which also adds the `assistant:write` scope.2. **OAuth & Permissions → Bot Token Scopes.** Twenty uses Slack's bot OAuth (`oauth/v2/authorize` with `scope=…`), so scopes must be added here and not only under **User Token Scopes**, otherwise Slack refuses the install with *"doesn't have a bot user to install"*.@@ -21,6 +23,9 @@ Two parts: a **Slack app** you create, and the **Twenty side** where you paste i| `channels:history` | assistant: thread follow-ups in public channels || `groups:history` | assistant: thread follow-ups in private channels || `im:history` | assistant: direct messages |+ | `users:read` | assistant: look up the requester's display name |+ | `users:read.email` | assistant: match Slack users to Twenty workspace members (requested up front, not used yet) |+ | `assistant:write` | agent surface: `assistant.threads.*` (statuses, titles, suggested prompts) |Adding or removing scopes later means existing installs must re-authorize: disconnect and **Add connection** again.@@ -56,6 +61,7 @@ The assistant reuses the same Slack connection — no second bot identity.Under **Subscribe to bot events**, add:+ - `app_home_opened` — a user opened the bot's Messages tab; sets the suggested prompts- `app_mention` — mentions of the bot in a channel- `message.im` — direct messages to the bot- `message.channels` — replies in public-channel threads, for un-mentioned follow-ups@@ -70,6 +76,7 @@ The assistant reuses the same Slack connection — no second bot identity.## Behaviour notes+- **Suggested prompts.** With `app_home_opened` subscribed and the Agents feature enabled, opening the bot's Messages tab shows clickable example prompts, refreshed on every open.- **Thread memory.** After a successful reply the bot stays active in that thread, so follow-ups need no mention. Channel threads stay active for 24 hours after the last reply (each reply renews it); DM threads never expire.- **No silent dead-ends.** A mention or DM with no request text gets a short hint reply. The first follow-up in a thread whose 24-hour window has lapsed gets an ephemeral nudge (only that member sees it) to mention the bot again.- **Channel welcome.** With `member_joined_channel` subscribed, the bot posts a short introduction the first time it is added to a channel, with the details (what to ask it, what it reads, and the shared-role caveat from step 4 above) in a thread reply so the channel itself stays quiet. It fires once per channel for 30 days, and only for the bot's own join — humans joining afterwards trigger nothing. Skip the subscription if you would rather it arrived silently.diff --git a/packages/twenty-apps/public/slack/package.json b/packages/twenty-apps/public/slack/package.jsonindex d18d8ebde9e..ad3ccff31f0 100644--- a/packages/twenty-apps/public/slack/package.json+++ b/packages/twenty-apps/public/slack/package.json@@ -22,7 +22,7 @@"test:unit": "vitest run --config vitest.unit.config.ts"},"dependencies": {- "@slack/web-api": "^7.8.0"+ "@slack/web-api": "^7.18.0"},"devDependencies": {"@types/node": "^24.7.2",diff --git a/packages/twenty-apps/public/slack/slack-app-manifest.json b/packages/twenty-apps/public/slack/slack-app-manifest.jsonnew file mode 100644index 00000000000..d7bb296ca15--- /dev/null+++ b/packages/twenty-apps/public/slack/slack-app-manifest.json@@ -0,0 +1,55 @@+{+ "display_information": {+ "name": "Twenty",+ "description": "Conversational CRM assistant for Twenty",+ "long_description": "Ask Twenty about your CRM from Slack: look up people, companies and opportunities, create and update records, and capture notes and tasks. Mention the bot in a channel or message it directly."+ },+ "features": {+ "bot_user": {+ "display_name": "Twenty",+ "always_online": true+ },+ "app_home": {+ "messages_tab_enabled": true,+ "messages_tab_read_only_enabled": false+ },+ "agent_view": {+ "agent_description": "Ask about your CRM: look up people, companies and opportunities, create and update records, and capture notes and tasks."+ }+ },+ "oauth_config": {+ "redirect_urls": ["<YOUR_TWENTY_SERVER_URL>/auth/apps/callback"],+ "scopes": {+ "bot": [+ "channels:read",+ "chat:write",+ "chat:write.public",+ "groups:read",+ "reactions:write",+ "app_mentions:read",+ "channels:history",+ "groups:history",+ "im:history",+ "users:read",+ "users:read.email",+ "assistant:write"+ ]+ }+ },+ "settings": {+ "event_subscriptions": {+ "request_url": "<YOUR_TWENTY_SERVER_URL>/webhooks/server/9ad6fa20-dff5-4d3f-ad5f-084f3c8b0b09",+ "bot_events": [+ "app_home_opened",+ "app_mention",+ "member_joined_channel",+ "message.channels",+ "message.groups",+ "message.im"+ ]+ },+ "org_deploy_enabled": false,+ "socket_mode_enabled": false,+ "token_rotation_enabled": false+ }+}diff --git a/packages/twenty-apps/public/slack/src/connection-providers/slack-connection.ts b/packages/twenty-apps/public/slack/src/connection-providers/slack-connection.tsindex 092bb91dd7f..11872752901 100644--- a/packages/twenty-apps/public/slack/src/connection-providers/slack-connection.ts+++ b/packages/twenty-apps/public/slack/src/connection-providers/slack-connection.ts@@ -27,11 +27,14 @@ export default defineConnectionProvider({'chat:write.public','groups:read','reactions:write',- // Inbound scopes, only used by the conversational assistant+ // Only used by the conversational assistant'app_mentions:read','channels:history','groups:history','im:history',+ 'users:read',+ 'users:read.email',+ 'assistant:write',],clientIdVariable: 'SLACK_CLIENT_ID',clientSecretVariable: 'SLACK_CLIENT_SECRET',diff --git a/packages/twenty-apps/public/slack/src/constants/universal-identifiers.ts b/packages/twenty-apps/public/slack/src/constants/universal-identifiers.tsindex 45548b9c21e..ba981f7f913 100644--- a/packages/twenty-apps/public/slack/src/constants/universal-identifiers.ts+++ b/packages/twenty-apps/public/slack/src/constants/universal-identifiers.ts@@ -52,6 +52,9 @@ export const SLACK_EVENTS_ENQUEUE_UNIVERSAL_IDENTIFIER =export const SLACK_CHANNEL_WELCOME_UNIVERSAL_IDENTIFIER ='c5e8b13a-7f42-4d90-8a6b-1e3c9d052f47';+export const SLACK_HOME_OPENED_UNIVERSAL_IDENTIFIER =+ '0ab0156f-11eb-49d6-bda2-cf078638886c';+export const SLACK_ASSISTANT_WORKER_UNIVERSAL_IDENTIFIER ='4b92a49f-d674-46ea-a3d9-e8d658ae3a17';diff --git a/packages/twenty-apps/public/slack/src/logic-functions/constants/slack-suggested-prompts.ts b/packages/twenty-apps/public/slack/src/logic-functions/constants/slack-suggested-prompts.tsnew file mode 100644index 00000000000..9ab602a6038--- /dev/null+++ b/packages/twenty-apps/public/slack/src/logic-functions/constants/slack-suggested-prompts.ts@@ -0,0 +1,20 @@+export const SLACK_SUGGESTED_PROMPTS_TITLE = 'Ask me about your CRM';++export const SLACK_SUGGESTED_PROMPTS: { title: string; message: string }[] = [+ {+ title: 'Review the pipeline',+ message: 'How many open opportunities are in the pipeline, by stage?',+ },+ {+ title: 'Spot the biggest deals',+ message: 'What are our five biggest open opportunities and who owns them?',+ },+ {+ title: 'See the newest companies',+ message: 'Which companies were added recently, and who added them?',+ },+ {+ title: 'Create a task',+ message: 'Create a task for me to follow up with our newest company next week.',+ },+];diff --git a/packages/twenty-apps/public/slack/src/logic-functions/slack-events-resolver.ts b/packages/twenty-apps/public/slack/src/logic-functions/slack-events-resolver.tsindex 841c0efee31..a32b78a842e 100644--- a/packages/twenty-apps/public/slack/src/logic-functions/slack-events-resolver.ts+++ b/packages/twenty-apps/public/slack/src/logic-functions/slack-events-resolver.ts@@ -6,6 +6,7 @@ import {SLACK_CHANNEL_WELCOME_UNIVERSAL_IDENTIFIER,SLACK_EVENTS_ENQUEUE_UNIVERSAL_IDENTIFIER,SLACK_EVENTS_ROUTE_UNIVERSAL_IDENTIFIER,+ SLACK_HOME_OPENED_UNIVERSAL_IDENTIFIER,} from 'src/constants/universal-identifiers';import { type SlackEventsRequestBody } from 'src/logic-functions/types/slack-events-request-body.type';import { getSlackWebhookSecret } from 'src/logic-functions/utils/get-slack-webhook-secret';@@ -59,18 +60,29 @@ export const slackEventsResolverHandler = async (return {workspaceId: await resolveTargetWorkspaceId(body),targetLogicFunctionUniversalIdentifier:- body.event?.type === 'member_joined_channel'- ? SLACK_CHANNEL_WELCOME_UNIVERSAL_IDENTIFIER- : SLACK_EVENTS_ENQUEUE_UNIVERSAL_IDENTIFIER,+ resolveTargetLogicFunctionUniversalIdentifier(body),payload: body,};};+const resolveTargetLogicFunctionUniversalIdentifier = (+ body: SlackEventsRequestBody,+): string => {+ switch (body.event?.type) {+ case 'member_joined_channel':+ return SLACK_CHANNEL_WELCOME_UNIVERSAL_IDENTIFIER;+ case 'app_home_opened':+ return SLACK_HOME_OPENED_UNIVERSAL_IDENTIFIER;+ default:+ return SLACK_EVENTS_ENQUEUE_UNIVERSAL_IDENTIFIER;+ }+};+export default defineLogicFunction({universalIdentifier: SLACK_EVENTS_ROUTE_UNIVERSAL_IDENTIFIER,name: 'slack-events-resolver',description:- 'Receives Slack Events API callbacks, verifies the request signature in the owner workspace, answers the url_verification handshake, and resolves the target workspace plus the function that handles the event (assistant enqueue, or the channel welcome on member_joined_channel).',+ 'Receives Slack Events API callbacks, verifies the request signature in the owner workspace, answers the url_verification handshake, and resolves the target workspace plus the function that handles the event (assistant enqueue, the channel welcome on member_joined_channel, or the suggested prompts on app_home_opened).',timeoutSeconds: 15,handler: slackEventsResolverHandler,serverRouteTriggerSettings: {diff --git a/packages/twenty-apps/public/slack/src/logic-functions/slack-home-opened.ts b/packages/twenty-apps/public/slack/src/logic-functions/slack-home-opened.tsnew file mode 100644index 00000000000..a2adc17495a--- /dev/null+++ b/packages/twenty-apps/public/slack/src/logic-functions/slack-home-opened.ts@@ -0,0 +1,13 @@+import { defineLogicFunction } from 'twenty-sdk/define';++import { SLACK_HOME_OPENED_UNIVERSAL_IDENTIFIER } from 'src/constants/universal-identifiers';+import { setSlackSuggestedPrompts } from 'src/logic-functions/utils/set-slack-suggested-prompts';++export default defineLogicFunction({+ universalIdentifier: SLACK_HOME_OPENED_UNIVERSAL_IDENTIFIER,+ name: 'slack-home-opened',+ description:+ "Runs in the resolved workspace: sets the agent's suggested prompts when a user opens the bot's Messages tab.",+ timeoutSeconds: 15,+ handler: setSlackSuggestedPrompts,+});diff --git a/packages/twenty-apps/public/slack/src/logic-functions/types/slack-events-request-body.type.ts b/packages/twenty-apps/public/slack/src/logic-functions/types/slack-events-request-body.type.tsindex ee6d40e0ca2..647b6c7b0ca 100644--- a/packages/twenty-apps/public/slack/src/logic-functions/types/slack-events-request-body.type.ts+++ b/packages/twenty-apps/public/slack/src/logic-functions/types/slack-events-request-body.type.ts@@ -13,6 +13,7 @@ type SlackInboundEvent = {ts?: string;thread_ts?: string;channel?: string;+ tab?: string;};export type SlackEventsRequestBody = {diff --git a/packages/twenty-apps/public/slack/src/logic-functions/utils/__tests__/parse-slack-home-opened-event.test.ts b/packages/twenty-apps/public/slack/src/logic-functions/utils/__tests__/parse-slack-home-opened-event.test.tsnew file mode 100644index 00000000000..136bb3b025d--- /dev/null+++ b/packages/twenty-apps/public/slack/src/logic-functions/utils/__tests__/parse-slack-home-opened-event.test.ts@@ -0,0 +1,88 @@+import { describe, expect, it } from 'vitest';++import { parseSlackHomeOpenedEvent } from 'src/logic-functions/utils/parse-slack-home-opened-event';++const buildHomeOpenedBody = (overrides: Record<string, unknown> = {}) => ({+ type: 'event_callback',+ event_id: 'Ev123',+ team_id: 'T123',+ event: {+ type: 'app_home_opened',+ user: 'U123',+ channel: 'D123',+ tab: 'messages',+ ...overrides,+ },+});++describe('parseSlackHomeOpenedEvent', () => {+ it('should parse a messages-tab open', () => {+ const result = parseSlackHomeOpenedEvent(buildHomeOpenedBody());++ expect(result).toEqual({+ homeOpened: { slackChannelId: 'D123', slackUserId: 'U123' },+ });+ });++ it('should skip other tabs', () => {+ const result = parseSlackHomeOpenedEvent(+ buildHomeOpenedBody({ tab: 'home' }),+ );++ expect(result).toEqual({+ homeOpened: null,+ skipReason: 'Unhandled app home tab: home',+ });+ });++ it('should skip other event types', () => {+ const result = parseSlackHomeOpenedEvent(+ buildHomeOpenedBody({ type: 'app_mention' }),+ );++ expect(result).toEqual({+ homeOpened: null,+ skipReason: 'Unhandled event type: app_mention',+ });+ });++ it('should skip non event_callback bodies', () => {+ const result = parseSlackHomeOpenedEvent({ type: 'url_verification' });++ expect(result).toEqual({+ homeOpened: null,+ skipReason: 'Unhandled body type: url_verification',+ });+ });++ it('should skip a body without an event payload', () => {+ const result = parseSlackHomeOpenedEvent({ type: 'event_callback' });++ expect(result).toEqual({+ homeOpened: null,+ skipReason: 'Missing event payload',+ });+ });++ it('should skip an event without a channel', () => {+ const result = parseSlackHomeOpenedEvent(+ buildHomeOpenedBody({ channel: undefined }),+ );++ expect(result).toEqual({+ homeOpened: null,+ skipReason: 'Event is missing required fields',+ });+ });++ it('should skip an event without a user', () => {+ const result = parseSlackHomeOpenedEvent(+ buildHomeOpenedBody({ user: '' }),+ );++ expect(result).toEqual({+ homeOpened: null,+ skipReason: 'Event is missing required fields',+ });+ });+});diff --git a/packages/twenty-apps/public/slack/src/logic-functions/utils/parse-slack-home-opened-event.ts b/packages/twenty-apps/public/slack/src/logic-functions/utils/parse-slack-home-opened-event.tsnew file mode 100644index 00000000000..782c2dd27e8--- /dev/null+++ b/packages/twenty-apps/public/slack/src/logic-functions/utils/parse-slack-home-opened-event.ts@@ -0,0 +1,49 @@+import { isNonEmptyString } from '@sniptt/guards';++import { type SlackEventsRequestBody } from 'src/logic-functions/types/slack-events-request-body.type';++type ParsedSlackHomeOpenedEvent =+ | { homeOpened: { slackChannelId: string; slackUserId: string } }+ | { homeOpened: null; skipReason: string };++export const parseSlackHomeOpenedEvent = (+ body: SlackEventsRequestBody,+): ParsedSlackHomeOpenedEvent => {+ if (body.type !== 'event_callback') {+ return {+ homeOpened: null,+ skipReason: `Unhandled body type: ${body.type}`,+ };+ }++ const event = body.event;++ if (!event) {+ return { homeOpened: null, skipReason: 'Missing event payload' };+ }++ if (event.type !== 'app_home_opened') {+ return {+ homeOpened: null,+ skipReason: `Unhandled event type: ${event.type}`,+ };+ }++ if (event.tab !== 'messages') {+ return {+ homeOpened: null,+ skipReason: `Unhandled app home tab: ${event.tab}`,+ };+ }++ if (!isNonEmptyString(event.channel) || !isNonEmptyString(event.user)) {+ return {+ homeOpened: null,+ skipReason: 'Event is missing required fields',+ };+ }++ return {+ homeOpened: { slackChannelId: event.channel, slackUserId: event.user },+ };+};diff --git a/packages/twenty-apps/public/slack/src/logic-functions/utils/set-slack-suggested-prompts.ts b/packages/twenty-apps/public/slack/src/logic-functions/utils/set-slack-suggested-prompts.tsnew file mode 100644index 00000000000..c0b8612a244--- /dev/null+++ b/packages/twenty-apps/public/slack/src/logic-functions/utils/set-slack-suggested-prompts.ts@@ -0,0 +1,43 @@+import {+ SLACK_SUGGESTED_PROMPTS,+ SLACK_SUGGESTED_PROMPTS_TITLE,+} from 'src/logic-functions/constants/slack-suggested-prompts';+import { type SlackEventsRequestBody } from 'src/logic-functions/types/slack-events-request-body.type';+import { getSlackClient } from 'src/logic-functions/utils/get-slack-client';+import { parseSlackHomeOpenedEvent } from 'src/logic-functions/utils/parse-slack-home-opened-event';++type SetSlackSuggestedPromptsResult = { ok: boolean; skipped?: string };++export const setSlackSuggestedPrompts = async (+ body: SlackEventsRequestBody,+): Promise<SetSlackSuggestedPromptsResult> => {+ const parsed = parseSlackHomeOpenedEvent(body);++ if (parsed.homeOpened === null) {+ return { ok: true, skipped: parsed.skipReason };+ }++ const { slackChannelId } = parsed.homeOpened;++ const slackClientResult = await getSlackClient();++ if (!slackClientResult.success) {+ throw new Error(slackClientResult.error);+ }++ try {+ await slackClientResult.client.assistant.threads.setSuggestedPrompts({+ channel_id: slackChannelId,+ title: SLACK_SUGGESTED_PROMPTS_TITLE,+ prompts: SLACK_SUGGESTED_PROMPTS,+ });+ } catch (error) {+ throw new Error(+ `Failed to set the Slack suggested prompts in channel ${slackChannelId}: ${+ error instanceof Error ? error.message : String(error)+ }`,+ );+ }++ return { ok: true };+};diff --git a/packages/twenty-apps/public/slack/yarn.lock b/packages/twenty-apps/public/slack/yarn.lockindex 286892912f0..4d61d0727bb 100644--- a/packages/twenty-apps/public/slack/yarn.lock+++ b/packages/twenty-apps/public/slack/yarn.lock@@ -938,22 +938,22 @@ __metadata:languageName: nodelinkType: hard-"@slack/types@npm:^2.20.1":- version: 2.20.1- resolution: "@slack/types@npm:2.20.1"- checksum: 10c0/62f1ff4d387cf511316f45c18ce9beaa1d0989a063ede5b40458fa776d460417f49faafb6cf7312fe2a9a5c8dfeb5c39ab685b911332f117a8222708da6468d7+"@slack/types@npm:^2.21.0":+ version: 2.22.0+ resolution: "@slack/types@npm:2.22.0"+ checksum: 10c0/0630feebb790957b227821ce4c474c174d9a4473481b9f04bfa589b2dc4f52a615b9f80664222c8a44090590fd1e1aaf5427986eb2c3a98dc75a5fabce3e2d53languageName: nodelinkType: hard-"@slack/web-api@npm:^7.8.0":- version: 7.15.1- resolution: "@slack/web-api@npm:7.15.1"+"@slack/web-api@npm:^7.18.0":+ version: 7.19.0+ resolution: "@slack/web-api@npm:7.19.0"dependencies:"@slack/logger": "npm:^4.0.1"- "@slack/types": "npm:^2.20.1"+ "@slack/types": "npm:^2.21.0""@types/node": "npm:>=18""@types/retry": "npm:0.12.0"- axios: "npm:^1.15.0"+ axios: "npm:^1.16.0"eventemitter3: "npm:^5.0.1"form-data: "npm:^4.0.4"is-electron: "npm:2.2.2"@@ -961,7 +961,7 @@ __metadata:p-queue: "npm:^6"p-retry: "npm:^4"retry: "npm:^0.13.1"- checksum: 10c0/69abd28f60805a90fa57851b20f856a4f2bc929b2863f1e434d9cec8a844a4dc0574720c8d5543aa860cd627013d5ccac969391580dbc4f05c95a21d77c2116f+ checksum: 10c0/78d52590feede0e5b55bfb3effa2723e090f3b684878f069d830fee2bad712abc285f4abdd1c0a7d308e19378c330aa86e9795667a229c888ca1862d39dd40d8languageName: nodelinkType: hard@@ -983,7 +983,7 @@ __metadata:version: 0.0.0-use.localresolution: "@twentyhq/slack@workspace:."dependencies:- "@slack/web-api": "npm:^7.8.0"+ "@slack/web-api": "npm:^7.18.0""@types/node": "npm:^24.7.2""@types/react": "npm:^18.2.0""@typescript/native-preview": "npm:^7.0.0-dev.20260116.1"@@ -1333,7 +1333,7 @@ __metadata:languageName: nodelinkType: hard-"axios@npm:^1.15.0, axios@npm:^1.16.0":+"axios@npm:^1.16.0":version: 1.18.1resolution: "axios@npm:1.18.1"dependencies: