The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Pull and apply workflow SEND_CHAT_MESSAGE steps (#29363)
Félix Malfaitcda8e601773b
diff --git a/packages/twenty-agent-skills/references/develop-app/workflows.md b/packages/twenty-agent-skills/references/develop-app/workflows.mdindex 57d94c3e741..6062062ae5e 100644--- a/packages/twenty-agent-skills/references/develop-app/workflows.md+++ b/packages/twenty-agent-skills/references/develop-app/workflows.md@@ -26,6 +26,11 @@ Workflows created at runtime through the workspace API are a `Workflow` plus at- Use `connectedAccountHandle` (the account's email address) in app code: ids only exist in one workspace. Apply resolves it to the oldest active account with that address that is shared with the workspace (`WORKSPACE` scope) and can run the step, and fails if none can. A member's private account can't be named by handle.- `twenty app pull` writes a shared account's id as its handle. Private account ids, variables and workspace member ids stay `connectedAccountId`.+## Send to Inbox Steps++- `SEND_CHAT_MESSAGE` posts `title` and `text` to the inbox of `workspaceMemberId`, optionally with a `toolCall` the member approves before the run goes on, and an optional `conversation`.+- Member ids only exist in one workspace: in app code, pass a variable such as `{{trigger.properties.after.assigneeId}}`.+## Manual Record Trigger- Trigger type: manual record selection.diff --git a/packages/twenty-docs/developers/extend/apps/logic/workflows.mdx b/packages/twenty-docs/developers/extend/apps/logic/workflows.mdxindex e6999e16819..c59acb00d3e 100644--- a/packages/twenty-docs/developers/extend/apps/logic/workflows.mdx+++ b/packages/twenty-docs/developers/extend/apps/logic/workflows.mdx@@ -99,7 +99,7 @@ A webhook workflow listens on `https://<your-twenty-domain>/webhooks/workflows/<## Steps-Application workflows support these step types: `LOGIC_FUNCTION`, `AI_AGENT`, `HTTP_REQUEST`, `CLASSIFY`, `CREATE_RECORD`, `UPDATE_RECORD`, `UPSERT_RECORD`, `DELETE_RECORD`, `FIND_RECORDS`, `PICK_RECORD`, `FILTER`, `IF_ELSE`, `ITERATOR`, `FORM`, `DELAY`, `WAIT_FOR_EVENT`, `SEND_EMAIL`, `DRAFT_EMAIL`, `CREATE_CALENDAR_EVENT` and `EMPTY`.+Application workflows support these step types: `LOGIC_FUNCTION`, `AI_AGENT`, `HTTP_REQUEST`, `CLASSIFY`, `CREATE_RECORD`, `UPDATE_RECORD`, `UPSERT_RECORD`, `DELETE_RECORD`, `FIND_RECORDS`, `PICK_RECORD`, `FILTER`, `IF_ELSE`, `ITERATOR`, `FORM`, `DELAY`, `WAIT_FOR_EVENT`, `SEND_EMAIL`, `DRAFT_EMAIL`, `CREATE_CALENDAR_EVENT`, `SEND_CHAT_MESSAGE` and `EMPTY`.Their inputs match the steps of the [workflow builder](/user-guide/workflows/capabilities/workflow-actions), with universal identifiers in place of names:- Record steps take `objectUniversalIdentifier` instead of an object name.@@ -113,6 +113,7 @@ Their inputs match the steps of the [workflow builder](/user-guide/workflows/cap- `connectedAccountId`: a variable, such as `{{trigger.properties.after.connectedAccountId}}`. Email steps also take a workspace member id, such as `{{trigger.properties.after.assigneeId}}`, which resolves to that member's first account able to send.Set exactly one of the two.+- `SEND_CHAT_MESSAGE` posts to a workspace member's inbox, set with `workspaceMemberId`. Member ids are local to each workspace too, so an app passes a variable, such as `{{trigger.properties.after.assigneeId}}`.## After installdiff --git a/packages/twenty-sdk/src/sdk/define/workflows/__tests__/define-workflow.spec.ts b/packages/twenty-sdk/src/sdk/define/workflows/__tests__/define-workflow.spec.tsindex 79d0ff27c7a..8baa9e60217 100644--- a/packages/twenty-sdk/src/sdk/define/workflows/__tests__/define-workflow.spec.ts+++ b/packages/twenty-sdk/src/sdk/define/workflows/__tests__/define-workflow.spec.ts@@ -111,7 +111,7 @@ describe('defineWorkflow', () => {problem: 'a step type applications cannot use',definition: withStep({ type: 'CODE' }),error:- 'version.steps.0.type: Unsupported step type. Application workflows support: LOGIC_FUNCTION, HTTP_REQUEST, CLASSIFY, ITERATOR, DELAY, WAIT_FOR_EVENT, EMPTY, CREATE_RECORD, UPDATE_RECORD, UPSERT_RECORD, DELETE_RECORD, FIND_RECORDS, PICK_RECORD, FILTER, IF_ELSE, FORM, SEND_EMAIL, DRAFT_EMAIL, CREATE_CALENDAR_EVENT, AI_AGENT',+ 'version.steps.0.type: Unsupported step type. Application workflows support: LOGIC_FUNCTION, HTTP_REQUEST, CLASSIFY, ITERATOR, DELAY, WAIT_FOR_EVENT, EMPTY, CREATE_RECORD, UPDATE_RECORD, UPSERT_RECORD, DELETE_RECORD, FIND_RECORDS, PICK_RECORD, FILTER, IF_ELSE, FORM, SEND_EMAIL, DRAFT_EMAIL, CREATE_CALENDAR_EVENT, SEND_CHAT_MESSAGE, AI_AGENT',},{problem: 'an unknown trigger type',diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-flat-workflow-to-workflow-manifest.util.spec.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-flat-workflow-to-workflow-manifest.util.spec.tsindex a8da2e0ad94..c65a14c349c 100644--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-flat-workflow-to-workflow-manifest.util.spec.ts+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-flat-workflow-to-workflow-manifest.util.spec.ts@@ -218,6 +218,16 @@ const STEP_INPUTS = {recipients: { to: '[email protected]', cc: '', bcc: '' },files: [],},+ SEND_CHAT_MESSAGE: {+ workspaceMemberId: WORKSPACE_MEMBER_ID,+ title: 'Approve the ticket',+ text: '{{trigger.properties.after.summary}}',+ toolCall: {+ toolName: 'update_one_ticket',+ arguments: { id: '{{trigger.recordId}}', status: 'APPROVED' },+ },+ conversation: { key: 'ticket:{{trigger.recordId}}', scope: 'KEY' },+ },CREATE_CALENDAR_EVENT: {connectedAccountHandle: SALES_HANDLE,title: 'Kick-off',@@ -589,19 +599,16 @@ describe('fromFlatWorkflowToWorkflowManifest', () => {});describe('unsupported workflows', () => {- it.each([WorkflowActionType.CODE, WorkflowActionType.SEND_CHAT_MESSAGE])(- 'reports a %s step',- (type) => {- const synced = syncWorkflow(buildWorkflow({}));- const [step] = synced.flatWorkflowVersion.steps ?? [];+ it('reports a CODE step', () => {+ const synced = syncWorkflow(buildWorkflow({}));+ const [step] = synced.flatWorkflowVersion.steps ?? [];- Object.assign(step, { type });+ Object.assign(step, { type: WorkflowActionType.CODE });- expect(exportWorkflow(synced)).toEqual({- reason: `${type} steps are not supported in application workflows`,- });- },- );+ expect(exportWorkflow(synced)).toEqual({+ reason: 'CODE steps are not supported in application workflows',+ });+ });it('reports a record filter on a field of a related record', () => {const synced = syncWorkflow(@@ -1029,6 +1036,41 @@ describe('fromFlatWorkflowToWorkflowManifest on versions built in the workflow bexpect(step.outputSchema).toEqual({});});+ it('exports a chat message step that waits for an approval', () => {+ const input = {+ text: '{{trigger.properties.after.summary}}',+ title: 'Approve the ticket',+ toolCall: {+ toolName: 'update_one_ticket',+ arguments: { id: '{{trigger.properties.after.id}}' },+ },+ conversation: {+ key: 'ticket:{{trigger.properties.after.id}}',+ scope: 'KEY',+ },+ workspaceMemberId: WORKSPACE_MEMBER_ID,+ };+ const [step] = exportBuilderVersion({+ triggers: [recordCreatedTrigger()],+ steps: [+ createRecordStep({+ name: 'Send to Inbox',+ type: 'SEND_CHAT_MESSAGE',+ settings: {+ outputSchema: {},+ errorHandlingOptions: {+ retryOnFailure: { value: 0 },+ continueOnFailure: { value: true },+ },+ input,+ },+ }),+ ],+ }).steps;++ expect(step).toMatchObject({ type: 'SEND_CHAT_MESSAGE', input });+ });+it('exports a step without a position as null', () => {const [step] = exportBuilderVersion({triggers: [recordCreatedTrigger()],diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-workflow-step-manifest-to-action-or-throw.util.spec.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-workflow-step-manifest-to-action-or-throw.util.spec.tsindex efdcf66ec56..c3d24e55d33 100644--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-workflow-step-manifest-to-action-or-throw.util.spec.ts+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-workflow-step-manifest-to-action-or-throw.util.spec.ts@@ -145,6 +145,11 @@ const inputs = {agentUniversalIdentifier: REFERENCE_ID,prompt: 'Summarize {{trigger.text}}',},+ SEND_CHAT_MESSAGE: {+ workspaceMemberId: '{{trigger.assigneeId}}',+ title: 'Approve',+ text: '{{trigger.text}}',+ },CLASSIFY: { state: '{{trigger.text}}', questions: [] },FILTER: filters,IF_ELSE: {diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-workflow-action-to-workflow-step-manifest.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-workflow-action-to-workflow-step-manifest.util.tsindex 31f9a293a32..0db4c5c03b0 100644--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-workflow-action-to-workflow-step-manifest.util.ts+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-workflow-action-to-workflow-step-manifest.util.ts@@ -229,6 +229,7 @@ const fromActionInput = ({};}case WorkflowActionType.HTTP_REQUEST:+ case WorkflowActionType.SEND_CHAT_MESSAGE:case WorkflowActionType.CLASSIFY:case WorkflowActionType.ITERATOR:case WorkflowActionType.DELAY:diff --git a/packages/twenty-shared/src/application/__tests__/workflowManifestType.spec.ts b/packages/twenty-shared/src/application/__tests__/workflowManifestType.spec.tsindex e3e1867f86b..c45171aff59 100644--- a/packages/twenty-shared/src/application/__tests__/workflowManifestType.spec.ts+++ b/packages/twenty-shared/src/application/__tests__/workflowManifestType.spec.ts@@ -153,6 +153,22 @@ describe('workflow manifest step types', () => {addConferencing: false,},},+ {+ type: 'SEND_CHAT_MESSAGE',+ input: {+ workspaceMemberId: ASSIGNEE,+ title: 'Approve the opportunity',+ text: 'Detected in an email thread',+ toolCall: {+ toolName: 'create_one_opportunity',+ arguments: { name: '{{trigger.properties.after.name}}' },+ },+ conversation: {+ key: 'mail:{{trigger.properties.after.threadId}}',+ scope: 'KEY',+ },+ },+ },])('accepts $type steps', ({ type, input }) => {const definition = structuredClone(workflow);Object.assign(getStep(definition, 2), { type, input });@@ -230,6 +246,24 @@ describe('workflow manifest step types', () => {});});+ it('requires the member a chat message is sent to', () => {+ const definition = structuredClone(workflow);+ Object.assign(getStep(definition, 2), {+ type: 'SEND_CHAT_MESSAGE',+ input: { title: 'Approve', text: 'Please review' },+ });+ const result = workflowManifestSchema.safeParse(definition);++ expect(result.success).toBe(false);+ expect(result.error?.issues[0]?.path).toEqual([+ 'version',+ 'steps',+ 2,+ 'input',+ 'workspaceMemberId',+ ]);+ });+it('rejects a step type applications cannot use', () => {const invalid = structuredClone(workflow);Object.assign(getStep(invalid, 2), { type: 'CODE' });diff --git a/packages/twenty-shared/src/application/workflowStepManifestType.ts b/packages/twenty-shared/src/application/workflowStepManifestType.tsindex bef3d5b8bf9..004dbc39636 100644--- a/packages/twenty-shared/src/application/workflowStepManifestType.ts+++ b/packages/twenty-shared/src/application/workflowStepManifestType.ts@@ -21,6 +21,7 @@ import { workflowFilterActionSettingsSchema } from '@/workflow/schemas/filter-acimport { workflowIfElseActionSettingsSchema } from '@/workflow/schemas/if-else-action-settings-schema';import { workflowSendEmailActionSettingsSchema } from '@/workflow/schemas/send-email-action-settings-schema';import { workflowCreateCalendarEventActionSettingsSchema } from '@/workflow/schemas/create-calendar-event-action-settings-schema';+import { workflowSendChatMessageActionSettingsSchema } from '@/workflow/schemas/send-chat-message-action-settings-schema';import { recordFilterGroupSchema } from '@/workflow/schemas/record-filter-group-schema';import { recordFilterSchema } from '@/workflow/schemas/record-filter-schema';import { stepFilterSchema } from '@/workflow/schemas/step-filter-schema';@@ -248,6 +249,10 @@ const workflowStepManifestOptions = [.extend(connectedAccountReferenceShape).superRefine(refineConnectedAccountReference),),+ stepSchema(+ 'SEND_CHAT_MESSAGE',+ workflowSendChatMessageActionSettingsSchema.shape.input,+ ),stepSchema('AI_AGENT',z.strictObject({