Skip to content

The open alternative to Salesforce, designed for AI.

Write an AI summary on Call Recordings imported from Microsoft Teams (#28226)

nitinb462f543c4a9
diff --git a/packages/twenty-apps/public/teams/README.md b/packages/twenty-apps/public/teams/README.md
index fae9c98faff..cd9cdfc8932 100644
--- a/packages/twenty-apps/public/teams/README.md
+++ b/packages/twenty-apps/public/teams/README.md
@@ -8,6 +8,7 @@
- **List My Teams Transcripts**, an AI and workflow action for the meetings you organized
- **Sync Teams Transcript**, an AI and workflow action that imports one of those transcripts into a Call Recording
- **Import history**, a settings section that imports the transcripts of up to the last year
+- **AI summary** of each imported transcript, written on its Call Recording
## 📌 Heads up
diff --git a/packages/twenty-apps/public/teams/SETUP.md b/packages/twenty-apps/public/teams/SETUP.md
index b0a4da2adbf..8bc89ca9146 100644
--- a/packages/twenty-apps/public/teams/SETUP.md
+++ b/packages/twenty-apps/public/teams/SETUP.md
@@ -118,6 +118,10 @@ hours after the meeting or whose import keeps failing.
Transcripts link to the meeting's calendar event when that calendar is synced in
Twenty. An occurrence of a recurring meeting links to the series' event.
+Each Call Recording that Microsoft Teams imports gets an AI summary, including
+the 31-day import on connect and **Import history** runs. Each summary uses AI
+credits.
+
## Test the transcript actions
1. For a development build, set `IS_TRANSCRIPT_IMPORT_ENABLED` to `true`, rebuild
@@ -183,10 +187,16 @@ external resources, add its enable/disable reconciliation alongside that
feature's handlers. The shared settings component composes each feature's
section; the app's single uninstall hook will compose their cleanup.
-Feature flags do not exclude SDK definitions from the manifest or make broken
-code buildable. Disabled features must still pass typecheck and build. The
-Microsoft OAuth connection remains available independently of the transcript
-release flag; connecting an account only stores its credentials for future use.
+Feature flags gate behavior at runtime, not installation. The build puts every
+file that default-exports a `define…` call in the manifest, so a disabled
+feature's objects, fields, indexes, roles, agents and logic functions are still
+installed, and its handlers return before doing any work. The only definitions
+a flag changes are the transcript summary functions: they declare their Call
+Recording triggers only while `IS_TRANSCRIPT_IMPORT_ENABLED` is on, so they are
+not invoked before release. Disabled features must still pass typecheck and
+build. The Microsoft OAuth connection remains available independently of the
+transcript release flag; connecting an account only stores its credentials for
+future use.
## Development
diff --git a/packages/twenty-apps/public/teams/package.json b/packages/twenty-apps/public/teams/package.json
index cab072d04fa..c3628e791c5 100644
--- a/packages/twenty-apps/public/teams/package.json
+++ b/packages/twenty-apps/public/teams/package.json
@@ -4,7 +4,7 @@
"description": "Microsoft Teams assistant and workflow steps for Twenty",
"license": "MIT",
"engines": {
- "twenty": ">=2.45.0",
+ "twenty": ">=2.46.0",
"node": "^24.5.0",
"npm": "please-use-yarn",
"yarn": ">=4.0.2"
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/agents/teams-transcript-summarizer.agent.ts b/packages/twenty-apps/public/teams/src/features/transcripts/agents/teams-transcript-summarizer.agent.ts
new file mode 100644
index 00000000000..db603dee085
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/agents/teams-transcript-summarizer.agent.ts
@@ -0,0 +1,15 @@
+import { defineAgent } from 'twenty-sdk/define';
+
+import { DEFAULT_TEAMS_TRANSCRIPT_SUMMARY_PROMPT } from 'src/features/transcripts/constants/default-teams-transcript-summary-prompt';
+import { TEAMS_TRANSCRIPT_SUMMARIZER_AGENT_UNIVERSAL_IDENTIFIER } from 'src/features/transcripts/constants/universal-identifiers';
+
+export default defineAgent({
+ universalIdentifier: TEAMS_TRANSCRIPT_SUMMARIZER_AGENT_UNIVERSAL_IDENTIFIER,
+ name: 'teams-transcript-summarizer',
+ label: 'Teams Transcript Summarizer',
+ icon: 'IconFileText',
+ description:
+ 'Summarizes an imported Microsoft Teams transcript into structured Markdown notes stored on the Call Recording.',
+ prompt: DEFAULT_TEAMS_TRANSCRIPT_SUMMARY_PROMPT,
+ responseFormat: { type: 'text' },
+});
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/constants/default-teams-transcript-summary-prompt.ts b/packages/twenty-apps/public/teams/src/features/transcripts/constants/default-teams-transcript-summary-prompt.ts
new file mode 100644
index 00000000000..f6f3250ea2e
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/constants/default-teams-transcript-summary-prompt.ts
@@ -0,0 +1,54 @@
+import { TEAMS_TRANSCRIPT_SUMMARY_UNAVAILABLE_PREFIX } from 'src/features/transcripts/constants/teams-transcript-summary-unavailable-prefix';
+
+export const DEFAULT_TEAMS_TRANSCRIPT_SUMMARY_PROMPT = [
+ 'You are an AI meeting note-taker for a CRM. You receive the diarized,',
+ 'time-stamped transcript of a Microsoft Teams meeting and produce clean,',
+ 'factual meeting notes for the rep who attended.',
+ '',
+ 'Output GitHub-flavored Markdown only — no preamble, no closing remarks, no',
+ 'surrounding code fences. Emit exactly these sections, in this order, each',
+ 'with its heading exactly as written. Omit a section only when its rule says',
+ 'to.',
+ '',
+ '## Gist',
+ 'A single sentence (no bullet) capturing the essence of the meeting.',
+ '',
+ '## Overview',
+ 'One paragraph of 2-4 sentences covering what the meeting was about and how',
+ 'it ended. No bullets.',
+ '',
+ '## Action Items',
+ 'Concrete follow-ups, grouped by the person responsible. Write each owner as',
+ 'a bold line, then their tasks as a bulleted list beneath it. Use the',
+ 'speaker name from the transcript, or "Unassigned" when no owner is clear.',
+ 'Example:',
+ '**Alex**',
+ '- Send the pricing deck',
+ '- Follow up on Friday',
+ 'If the meeting produced no follow-ups, write the single line: None.',
+ '',
+ '## Notes',
+ 'The discussion split into short topical sections in chronological order.',
+ 'Begin each section with a bold title and the [mm:ss] timestamp it started',
+ 'at, then summarize it as concise bullets. Example:',
+ '**Introductions** — 0:00',
+ '- ...',
+ '**Pricing discussion** — 4:12',
+ '- ...',
+ '',
+ '## Keywords',
+ 'A single comma-separated line of the most important terms, names, and',
+ 'topics from the meeting.',
+ '',
+ 'Grounding rules: use only information present in the transcript. Never',
+ 'invent names, numbers, commitments, outcomes, or times — reuse the [mm:ss]',
+ 'timestamps exactly as they appear in the transcript.',
+ '',
+ 'If the transcript is too short, unintelligible, or contains no substantive',
+ 'discussion, ignore the output format above and return exactly one line in',
+ 'this format:',
+ `${TEAMS_TRANSCRIPT_SUMMARY_UNAVAILABLE_PREFIX} <one short sentence explaining why the transcript cannot be summarized reliably>`,
+ 'The reason must describe only what is observable in the transcript. Be',
+ 'specific and do not speculate. Example:',
+ `${TEAMS_TRANSCRIPT_SUMMARY_UNAVAILABLE_PREFIX} The transcript contains only greetings and audio checks, with no substantive discussion.`,
+].join('\n');
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/constants/teams-transcript-summary-unavailable-prefix.ts b/packages/twenty-apps/public/teams/src/features/transcripts/constants/teams-transcript-summary-unavailable-prefix.ts
new file mode 100644
index 00000000000..54882714548
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/constants/teams-transcript-summary-unavailable-prefix.ts
@@ -0,0 +1,2 @@
+export const TEAMS_TRANSCRIPT_SUMMARY_UNAVAILABLE_PREFIX =
+ 'SUMMARY_UNAVAILABLE:';
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/constants/universal-identifiers.ts b/packages/twenty-apps/public/teams/src/features/transcripts/constants/universal-identifiers.ts
index 6a757519179..65d06198b71 100644
--- a/packages/twenty-apps/public/teams/src/features/transcripts/constants/universal-identifiers.ts
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/constants/universal-identifiers.ts
@@ -36,3 +36,15 @@ export const TEAMS_TRANSCRIPT_HISTORY_IMPORT_UNIVERSAL_IDENTIFIER =
export const TEAMS_TRANSCRIPT_HISTORY_STATUS_UNIVERSAL_IDENTIFIER =
'4b39d2ea-7b16-4e68-a93c-bfb628ae5431';
+
+export const TEAMS_TRANSCRIPT_SUMMARIZER_AGENT_UNIVERSAL_IDENTIFIER =
+ '8be80a69-c787-4a37-989e-92131b0d79dd';
+
+export const TEAMS_SUMMARIZE_CREATED_CALL_RECORDINGS_UNIVERSAL_IDENTIFIER =
+ 'b8e2c414-d660-4703-9b5a-b714524b5a71';
+
+export const TEAMS_SUMMARIZE_UPDATED_CALL_RECORDINGS_UNIVERSAL_IDENTIFIER =
+ '652eb758-8fdd-46d8-b493-7bd373381f3b';
+
+export const TEAMS_SUMMARIZE_CALL_RECORDING_UNIVERSAL_IDENTIFIER =
+ '1b25742e-dc84-4a42-bca7-8ad41878f4c5';
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/teams-transcript-summary-job-retry-limit.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/teams-transcript-summary-job-retry-limit.ts
new file mode 100644
index 00000000000..03cf7063d94
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/teams-transcript-summary-job-retry-limit.ts
@@ -0,0 +1 @@
+export const TEAMS_TRANSCRIPT_SUMMARY_JOB_RETRY_LIMIT = 3;
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/teams-transcript-summary-timeout-seconds.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/teams-transcript-summary-timeout-seconds.ts
new file mode 100644
index 00000000000..1db3a6c4c36
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/teams-transcript-summary-timeout-seconds.ts
@@ -0,0 +1 @@
+export const TEAMS_TRANSCRIPT_SUMMARY_TIMEOUT_SECONDS = 240;
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/teams-summarize-call-recording.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/teams-summarize-call-recording.ts
new file mode 100644
index 00000000000..cea20c8ad6c
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/teams-summarize-call-recording.ts
@@ -0,0 +1,44 @@
+import { isNonEmptyString } from '@sniptt/guards';
+import { CoreApiClient } from 'twenty-client-sdk/core';
+import { defineLogicFunction } from 'twenty-sdk/define';
+
+import { TEAMS_SUMMARIZE_CALL_RECORDING_UNIVERSAL_IDENTIFIER } from 'src/features/transcripts/constants/universal-identifiers';
+import { TEAMS_TRANSCRIPT_SUMMARY_TIMEOUT_SECONDS } from 'src/features/transcripts/logic-functions/constants/teams-transcript-summary-timeout-seconds';
+import { type TeamsCallRecordingSummaryOutcome } from 'src/features/transcripts/logic-functions/types/teams-call-recording-summary-outcome.type';
+import { summarizeTeamsCallRecordingOrThrow } from 'src/features/transcripts/logic-functions/utils/summarize-teams-call-recording-or-throw';
+
+type TeamsSummarizeCallRecordingResult =
+ | {
+ success: true;
+ callRecordingId: string;
+ outcome: TeamsCallRecordingSummaryOutcome;
+ }
+ | { success: false; error: string };
+
+export const teamsSummarizeCallRecordingHandler = async (payload: {
+ callRecordingId?: unknown;
+}): Promise<TeamsSummarizeCallRecordingResult> => {
+ const { callRecordingId } = payload;
+
+ if (!isNonEmptyString(callRecordingId)) {
+ return { success: false, error: 'Invalid Teams transcript summary job' };
+ }
+
+ return {
+ success: true,
+ callRecordingId,
+ outcome: await summarizeTeamsCallRecordingOrThrow({
+ coreApiClient: new CoreApiClient({ runAs: 'application' }),
+ callRecordingId,
+ }),
+ };
+};
+
+export default defineLogicFunction({
+ universalIdentifier: TEAMS_SUMMARIZE_CALL_RECORDING_UNIVERSAL_IDENTIFIER,
+ name: 'teams-summarize-call-recording',
+ description:
+ 'Writes an AI summary on a Call Recording imported from Microsoft Teams.',
+ timeoutSeconds: TEAMS_TRANSCRIPT_SUMMARY_TIMEOUT_SECONDS,
+ handler: teamsSummarizeCallRecordingHandler,
+});
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/teams-summarize-created-call-recordings.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/teams-summarize-created-call-recordings.ts
new file mode 100644
index 00000000000..710175c1f48
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/teams-summarize-created-call-recordings.ts
@@ -0,0 +1,33 @@
+import { defineLogicFunction } from 'twenty-sdk/define';
+import {
+ type DatabaseEventBatchPayload,
+ type ObjectRecordCreateEvent,
+} from 'twenty-sdk/logic-function';
+
+import { FEATURE_FLAGS } from 'src/constants/feature-flags';
+import { TEAMS_SUMMARIZE_CREATED_CALL_RECORDINGS_UNIVERSAL_IDENTIFIER } from 'src/features/transcripts/constants/universal-identifiers';
+import { type TeamsCallRecordingEventRecord } from 'src/features/transcripts/logic-functions/types/teams-call-recording-event-record.type';
+import { enqueueTeamsTranscriptSummariesOrThrow } from 'src/features/transcripts/logic-functions/utils/enqueue-teams-transcript-summaries-or-throw';
+
+export const teamsSummarizeCreatedCallRecordingsHandler = (
+ batch: DatabaseEventBatchPayload<
+ ObjectRecordCreateEvent<TeamsCallRecordingEventRecord>
+ >,
+) => enqueueTeamsTranscriptSummariesOrThrow(batch.events);
+
+export default defineLogicFunction({
+ universalIdentifier:
+ TEAMS_SUMMARIZE_CREATED_CALL_RECORDINGS_UNIVERSAL_IDENTIFIER,
+ name: 'teams-summarize-created-call-recordings',
+ description:
+ 'Queues an AI summary for each Call Recording that Microsoft Teams created with a transcript.',
+ handler: teamsSummarizeCreatedCallRecordingsHandler,
+ ...(FEATURE_FLAGS.IS_TRANSCRIPT_IMPORT_ENABLED
+ ? {
+ databaseEventTriggerSettings: {
+ eventName: 'callRecording.created',
+ batchMode: true,
+ },
+ }
+ : {}),
+});
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/teams-summarize-updated-call-recordings.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/teams-summarize-updated-call-recordings.ts
new file mode 100644
index 00000000000..21a170b768b
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/teams-summarize-updated-call-recordings.ts
@@ -0,0 +1,34 @@
+import { defineLogicFunction } from 'twenty-sdk/define';
+import {
+ type DatabaseEventBatchPayload,
+ type ObjectRecordUpdateEvent,
+} from 'twenty-sdk/logic-function';
+
+import { FEATURE_FLAGS } from 'src/constants/feature-flags';
+import { TEAMS_SUMMARIZE_UPDATED_CALL_RECORDINGS_UNIVERSAL_IDENTIFIER } from 'src/features/transcripts/constants/universal-identifiers';
+import { type TeamsCallRecordingEventRecord } from 'src/features/transcripts/logic-functions/types/teams-call-recording-event-record.type';
+import { enqueueTeamsTranscriptSummariesOrThrow } from 'src/features/transcripts/logic-functions/utils/enqueue-teams-transcript-summaries-or-throw';
+
+export const teamsSummarizeUpdatedCallRecordingsHandler = (
+ batch: DatabaseEventBatchPayload<
+ ObjectRecordUpdateEvent<TeamsCallRecordingEventRecord>
+ >,
+) => enqueueTeamsTranscriptSummariesOrThrow(batch.events);
+
+export default defineLogicFunction({
+ universalIdentifier:
+ TEAMS_SUMMARIZE_UPDATED_CALL_RECORDINGS_UNIVERSAL_IDENTIFIER,
+ name: 'teams-summarize-updated-call-recordings',
+ description:
+ 'Queues an AI summary for each Microsoft Teams Call Recording whose transcript changed.',
+ handler: teamsSummarizeUpdatedCallRecordingsHandler,
+ ...(FEATURE_FLAGS.IS_TRANSCRIPT_IMPORT_ENABLED
+ ? {
+ databaseEventTriggerSettings: {
+ eventName: 'callRecording.updated',
+ updatedFields: ['transcript'],
+ batchMode: true,
+ },
+ }
+ : {}),
+});
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/teams-call-recording-event-record.type.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/teams-call-recording-event-record.type.ts
new file mode 100644
index 00000000000..3f15add9717
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/teams-call-recording-event-record.type.ts
@@ -0,0 +1,4 @@
+export type TeamsCallRecordingEventRecord = {
+ applicationId?: string | null;
+ transcript?: unknown;
+};
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/teams-call-recording-summary-event.type.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/teams-call-recording-summary-event.type.ts
new file mode 100644
index 00000000000..a252636d553
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/teams-call-recording-summary-event.type.ts
@@ -0,0 +1,8 @@
+import { type ObjectRecordBaseEvent } from 'twenty-sdk/logic-function';
+
+import { type TeamsCallRecordingEventRecord } from 'src/features/transcripts/logic-functions/types/teams-call-recording-event-record.type';
+
+export type TeamsCallRecordingSummaryEvent = Pick<
+ ObjectRecordBaseEvent<TeamsCallRecordingEventRecord>,
+ 'recordId' | 'properties'
+>;
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/teams-call-recording-summary-outcome.type.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/teams-call-recording-summary-outcome.type.ts
new file mode 100644
index 00000000000..7e4c4fec665
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/teams-call-recording-summary-outcome.type.ts
@@ -0,0 +1,9 @@
+export type TeamsCallRecordingSummaryOutcome =
+ | 'disabled'
+ | 'not-found'
+ | 'already-summarized'
+ | 'no-transcript'
+ | 'agent-failed'
+ | 'save-failed'
+ | 'not-summarizable'
+ | 'summarized';
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/teams-transcript-summary.type.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/teams-transcript-summary.type.ts
new file mode 100644
index 00000000000..9f85cfdc271
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/teams-transcript-summary.type.ts
@@ -0,0 +1,3 @@
+export type TeamsTranscriptSummary =
+ | { outcome: 'summarized'; markdown: string }
+ | { outcome: 'not-summarizable'; reason: string };
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/__tests__/build-teams-transcript-summary-prompt.test.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/__tests__/build-teams-transcript-summary-prompt.test.ts
new file mode 100644
index 00000000000..bc823775b37
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/__tests__/build-teams-transcript-summary-prompt.test.ts
@@ -0,0 +1,71 @@
+import { describe, expect, it } from 'vitest';
+
+import { buildTeamsTranscriptSummaryPrompt } from 'src/features/transcripts/logic-functions/utils/build-teams-transcript-summary-prompt';
+import { mapTeamsTranscriptToEntries } from 'src/features/transcripts/logic-functions/utils/map-teams-transcript-to-entries';
+
+describe('buildTeamsTranscriptSummaryPrompt', () => {
+ it('should turn an imported Teams transcript into timestamped speaker lines', () => {
+ const transcript = mapTeamsTranscriptToEntries(
+ [
+ 'WEBVTT',
+ '',
+ '00:00:01.000 --> 00:00:03.000',
+ '<v Alice Martin>Hello everyone.</v>',
+ '',
+ '00:00:04.000 --> 00:00:06.000',
+ '<v Alice Martin>Let us review pricing.</v>',
+ '',
+ '01:02:05.500 --> 01:02:07.000',
+ '<v Bob Lee>Sounds good.</v>',
+ '',
+ ].join('\n'),
+ );
+
+ expect(
+ buildTeamsTranscriptSummaryPrompt({
+ transcript,
+ title: ' Weekly sync ',
+ }),
+ ).toBe(
+ [
+ 'Meeting title: Weekly sync',
+ '',
+ 'Transcript:',
+ '[0:01] Alice Martin: Hello everyone. Let us review pricing.',
+ '[1:02:05] Bob Lee: Sounds good.',
+ ].join('\n'),
+ );
+ });
+
+ it('should label unnamed speakers and omit a blank title', () => {
+ expect(
+ buildTeamsTranscriptSummaryPrompt({
+ transcript: [
+ {
+ participant: { name: null },
+ words: [{ text: 'Can you hear me?' }],
+ },
+ ],
+ title: ' ',
+ }),
+ ).toBe('Transcript:\nUnknown speaker: Can you hear me?');
+ });
+
+ it('should return undefined when the transcript has no spoken text', () => {
+ expect(
+ buildTeamsTranscriptSummaryPrompt({
+ transcript: [
+ { participant: { name: 'Alice' }, words: [{ text: ' ' }] },
+ { participant: { name: 'Bob' } },
+ 'not an entry',
+ ],
+ }),
+ ).toBeUndefined();
+ expect(buildTeamsTranscriptSummaryPrompt({ transcript: [] })).toBe(
+ undefined,
+ );
+ expect(
+ buildTeamsTranscriptSummaryPrompt({ transcript: null }),
+ ).toBeUndefined();
+ });
+});
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/__tests__/parse-teams-transcript-summary-agent-response.test.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/__tests__/parse-teams-transcript-summary-agent-response.test.ts
new file mode 100644
index 00000000000..886e7fca110
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/__tests__/parse-teams-transcript-summary-agent-response.test.ts
@@ -0,0 +1,56 @@
+import { describe, expect, it } from 'vitest';
+
+import { parseTeamsTranscriptSummaryAgentResponse } from 'src/features/transcripts/logic-functions/utils/parse-teams-transcript-summary-agent-response';
+
+const buildAgentResult = (response: unknown) => ({
+ success: true,
+ error: null,
+ result: { response },
+});
+
+describe('parseTeamsTranscriptSummaryAgentResponse', () => {
+ it('should return the trimmed Markdown summary', () => {
+ expect(
+ parseTeamsTranscriptSummaryAgentResponse(
+ buildAgentResult('\n## Gist\nPricing was agreed.\n'),
+ ),
+ ).toEqual({
+ outcome: 'summarized',
+ markdown: '## Gist\nPricing was agreed.',
+ });
+ });
+
+ it('should return the reason when the transcript cannot be summarized', () => {
+ expect(
+ parseTeamsTranscriptSummaryAgentResponse(
+ buildAgentResult(
+ 'SUMMARY_UNAVAILABLE: The transcript only contains audio checks.',
+ ),
+ ),
+ ).toEqual({
+ outcome: 'not-summarizable',
+ reason: 'The transcript only contains audio checks.',
+ });
+ });
+
+ it('should return undefined for a failed run, a blank response or a bare unavailable marker', () => {
+ expect(
+ parseTeamsTranscriptSummaryAgentResponse({
+ success: false,
+ error: 'Agent run failed',
+ result: null,
+ }),
+ ).toBeUndefined();
+ expect(
+ parseTeamsTranscriptSummaryAgentResponse(buildAgentResult(' ')),
+ ).toBeUndefined();
+ expect(
+ parseTeamsTranscriptSummaryAgentResponse(buildAgentResult(42)),
+ ).toBeUndefined();
+ expect(
+ parseTeamsTranscriptSummaryAgentResponse(
+ buildAgentResult('SUMMARY_UNAVAILABLE: '),
+ ),
+ ).toBeUndefined();
+ });
+});
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/__tests__/select-teams-call-recording-ids-to-summarize.test.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/__tests__/select-teams-call-recording-ids-to-summarize.test.ts
new file mode 100644
index 00000000000..3833e5e959f
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/__tests__/select-teams-call-recording-ids-to-summarize.test.ts
@@ -0,0 +1,76 @@
+import { describe, expect, it } from 'vitest';
+
+import { selectTeamsCallRecordingIdsToSummarize } from 'src/features/transcripts/logic-functions/utils/select-teams-call-recording-ids-to-summarize';
+
+const TEAMS_APPLICATION_ID = 'teams-application';
+
+const TRANSCRIPT = [
+ {
+ participant: { name: 'Alice Martin' },
+ words: [{ text: 'Hello.', start_timestamp: { relative: 0 } }],
+ },
+];
+
+const buildEvent = (
+ recordId: string,
+ after: { applicationId?: string | null; transcript?: unknown },
+) => ({ recordId, properties: { after } });
+
+describe('selectTeamsCallRecordingIdsToSummarize', () => {
+ it('should keep each Teams recording that has a transcript once', () => {
+ expect(
+ selectTeamsCallRecordingIdsToSummarize({
+ applicationId: TEAMS_APPLICATION_ID,
+ events: [
+ buildEvent('recording-1', {
+ applicationId: TEAMS_APPLICATION_ID,
+ transcript: TRANSCRIPT,
+ }),
+ buildEvent('recording-2', {
+ applicationId: TEAMS_APPLICATION_ID,
+ transcript: TRANSCRIPT,
+ }),
+ buildEvent('recording-1', {
+ applicationId: TEAMS_APPLICATION_ID,
+ transcript: TRANSCRIPT,
+ }),
+ ],
+ }),
+ ).toEqual(['recording-1', 'recording-2']);
+ });
+
+ it('should skip recordings from other apps and recordings without a transcript', () => {
+ expect(
+ selectTeamsCallRecordingIdsToSummarize({
+ applicationId: TEAMS_APPLICATION_ID,
+ events: [
+ buildEvent('call-recorder-recording', {
+ applicationId: 'call-recorder-application',
+ transcript: TRANSCRIPT,
+ }),
+ buildEvent('unstamped-recording', {
+ applicationId: null,
+ transcript: TRANSCRIPT,
+ }),
+ buildEvent('processing-recording', {
+ applicationId: TEAMS_APPLICATION_ID,
+ }),
+ buildEvent('emptied-recording', {
+ applicationId: TEAMS_APPLICATION_ID,
+ transcript: [],
+ }),
+ { recordId: 'missing-snapshot', properties: {} },
+ ],
+ }),
+ ).toEqual([]);
+ });
+
+ it('should select nothing when the application id is unknown', () => {
+ expect(
+ selectTeamsCallRecordingIdsToSummarize({
+ applicationId: undefined,
+ events: [buildEvent('recording-1', { transcript: TRANSCRIPT })],
+ }),
+ ).toEqual([]);
+ });
+});
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/build-teams-transcript-summary-prompt.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/build-teams-transcript-summary-prompt.ts
new file mode 100644
index 00000000000..230145a4cfd
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/build-teams-transcript-summary-prompt.ts
@@ -0,0 +1,97 @@
+import { isArray, isNonEmptyString, isNumber, isObject } from '@sniptt/guards';
+import { isDefined } from 'twenty-sdk/utils';
+
+const UNKNOWN_SPEAKER = 'Unknown speaker';
+const SECONDS_PER_MINUTE = 60;
+const SECONDS_PER_HOUR = 3_600;
+
+const formatClockTimestamp = (totalSeconds: number): string => {
+ const wholeSeconds = Math.max(0, Math.floor(totalSeconds));
+ const hours = Math.floor(wholeSeconds / SECONDS_PER_HOUR);
+ const minutes = Math.floor(
+ (wholeSeconds % SECONDS_PER_HOUR) / SECONDS_PER_MINUTE,
+ );
+ const seconds = String(wholeSeconds % SECONDS_PER_MINUTE).padStart(2, '0');
+
+ return hours > 0
+ ? `${hours}:${String(minutes).padStart(2, '0')}:${seconds}`
+ : `${minutes}:${seconds}`;
+};
+
+const getWordText = (word: unknown): unknown =>
+ isObject(word) && 'text' in word ? word.text : undefined;
+
+const getWordStartSeconds = (word: unknown): unknown =>
+ isObject(word) &&
+ 'start_timestamp' in word &&
+ isObject(word.start_timestamp) &&
+ 'relative' in word.start_timestamp
+ ? word.start_timestamp.relative
+ : undefined;
+
+const getParticipantName = (entry: object): unknown =>
+ 'participant' in entry &&
+ isObject(entry.participant) &&
+ 'name' in entry.participant
+ ? entry.participant.name
+ : undefined;
+
+const findEntryStartSeconds = (words: unknown[]): number | undefined =>
+ words
+ .map(getWordStartSeconds)
+ .find(
+ (relative): relative is number =>
+ isNumber(relative) && Number.isFinite(relative),
+ );
+
+const buildTranscriptLine = (entry: unknown): string | undefined => {
+ if (!isObject(entry) || !('words' in entry) || !isArray(entry.words)) {
+ return undefined;
+ }
+
+ const text = entry.words
+ .map(getWordText)
+ .filter(isNonEmptyString)
+ .map((word) => word.trim())
+ .join(' ')
+ .trim();
+
+ if (!isNonEmptyString(text)) {
+ return undefined;
+ }
+
+ const participantName = getParticipantName(entry);
+ const speakerName = isNonEmptyString(participantName)
+ ? participantName.trim()
+ : UNKNOWN_SPEAKER;
+ const startSeconds = findEntryStartSeconds(entry.words);
+ const timestamp = isDefined(startSeconds)
+ ? `[${formatClockTimestamp(startSeconds)}] `
+ : '';
+
+ return `${timestamp}${speakerName}: ${text}`;
+};
+
+export const buildTeamsTranscriptSummaryPrompt = ({
+ transcript,
+ title,
+}: {
+ transcript: unknown;
+ title?: string;
+}): string | undefined => {
+ if (!isArray(transcript)) {
+ return undefined;
+ }
+
+ const lines = transcript.map(buildTranscriptLine).filter(isNonEmptyString);
+
+ if (lines.length === 0) {
+ return undefined;
+ }
+
+ const header = isNonEmptyString(title?.trim())
+ ? `Meeting title: ${title.trim()}\n\n`
+ : '';
+
+ return `${header}Transcript:\n${lines.join('\n')}`;
+};
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/enqueue-teams-transcript-summaries-or-throw.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/enqueue-teams-transcript-summaries-or-throw.ts
new file mode 100644
index 00000000000..6eb6ad184a1
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/enqueue-teams-transcript-summaries-or-throw.ts
@@ -0,0 +1,44 @@
+import {
+ enqueueJobs,
+ RetryableLogicFunctionError,
+} from 'twenty-sdk/logic-function';
+
+import { TEAMS_SUMMARIZE_CALL_RECORDING_UNIVERSAL_IDENTIFIER } from 'src/features/transcripts/constants/universal-identifiers';
+import { TEAMS_TRANSCRIPT_SUMMARY_JOB_RETRY_LIMIT } from 'src/features/transcripts/logic-functions/constants/teams-transcript-summary-job-retry-limit';
+import { type TeamsCallRecordingSummaryEvent } from 'src/features/transcripts/logic-functions/types/teams-call-recording-summary-event.type';
+import { isTeamsTranscriptSummaryEnabled } from 'src/features/transcripts/logic-functions/utils/is-teams-transcript-summary-enabled';
+import { selectTeamsCallRecordingIdsToSummarize } from 'src/features/transcripts/logic-functions/utils/select-teams-call-recording-ids-to-summarize';
+import { toErrorMessage } from 'src/utils/to-error-message';
+
+export const enqueueTeamsTranscriptSummariesOrThrow = async (
+ events: TeamsCallRecordingSummaryEvent[],
+): Promise<void> => {
+ if (!isTeamsTranscriptSummaryEnabled()) {
+ return;
+ }
+
+ const callRecordingIds = selectTeamsCallRecordingIdsToSummarize({
+ events,
+ applicationId: process.env.APPLICATION_ID,
+ });
+
+ if (callRecordingIds.length === 0) {
+ return;
+ }
+
+ try {
+ await enqueueJobs({
+ logicFunctionUniversalIdentifier:
+ TEAMS_SUMMARIZE_CALL_RECORDING_UNIVERSAL_IDENTIFIER,
+ jobs: callRecordingIds.map((callRecordingId) => ({
+ jobId: `teams-transcript-summary-${callRecordingId}`,
+ payload: { callRecordingId },
+ })),
+ retryLimit: TEAMS_TRANSCRIPT_SUMMARY_JOB_RETRY_LIMIT,
+ });
+ } catch (error) {
+ throw new RetryableLogicFunctionError(
+ `Could not schedule Teams transcript summaries: ${toErrorMessage(error)}`,
+ );
+ }
+};
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/find-call-recording-for-summary-or-throw.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/find-call-recording-for-summary-or-throw.ts
new file mode 100644
index 00000000000..8c674948662
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/find-call-recording-for-summary-or-throw.ts
@@ -0,0 +1,52 @@
+import { isNonEmptyString } from '@sniptt/guards';
+import { type CoreApiClient } from 'twenty-client-sdk/core';
+import { RetryableLogicFunctionError } from 'twenty-sdk/logic-function';
+import { isDefined } from 'twenty-sdk/utils';
+
+import { toErrorMessage } from 'src/utils/to-error-message';
+
+type CallRecordingForSummary = {
+ title: string | undefined;
+ transcript: unknown;
+ hasSummary: boolean;
+};
+
+export const findCallRecordingForSummaryOrThrow = async ({
+ coreApiClient,
+ callRecordingId,
+}: {
+ coreApiClient: Pick<CoreApiClient, 'query'>;
+ callRecordingId: string;
+}): Promise<CallRecordingForSummary | undefined> => {
+ const queryResult = await coreApiClient
+ .query({
+ callRecordings: {
+ __args: { filter: { id: { eq: callRecordingId } }, first: 1 },
+ edges: {
+ node: {
+ id: true,
+ title: true,
+ transcript: true,
+ summary: { markdown: true },
+ },
+ },
+ },
+ })
+ .catch((error: unknown) => {
+ throw new RetryableLogicFunctionError(
+ `Could not read call recording ${callRecordingId} to summarize it: ${toErrorMessage(error)}`,
+ );
+ });
+
+ const node = queryResult.callRecordings?.edges?.[0]?.node;
+
+ if (!isDefined(node)) {
+ return undefined;
+ }
+
+ return {
+ title: isNonEmptyString(node.title) ? node.title : undefined,
+ transcript: node.transcript,
+ hasSummary: isNonEmptyString(node.summary?.markdown?.trim()),
+ };
+};
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/is-teams-transcript-summary-enabled.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/is-teams-transcript-summary-enabled.ts
new file mode 100644
index 00000000000..0702e321c40
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/is-teams-transcript-summary-enabled.ts
@@ -0,0 +1,10 @@
+import { FEATURE_FLAGS } from 'src/constants/feature-flags';
+import { TRANSCRIPTS_ENABLED_APPLICATION_VARIABLE_KEY } from 'src/features/transcripts/constants/transcripts-enabled-application-variable-key';
+import { isFeatureEnabled } from 'src/utils/is-feature-enabled';
+
+// TODO(@ehconitin): gate on a workspace summary setting once Teams has settings; V1 summarizes every imported transcript
+export const isTeamsTranscriptSummaryEnabled = (): boolean =>
+ isFeatureEnabled({
+ isAvailable: FEATURE_FLAGS.IS_TRANSCRIPT_IMPORT_ENABLED,
+ settingValue: process.env[TRANSCRIPTS_ENABLED_APPLICATION_VARIABLE_KEY],
+ });
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/parse-teams-transcript-summary-agent-response.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/parse-teams-transcript-summary-agent-response.ts
new file mode 100644
index 00000000000..726d2a18e41
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/parse-teams-transcript-summary-agent-response.ts
@@ -0,0 +1,36 @@
+import { isNonEmptyString, isString } from '@sniptt/guards';
+import { type RunAgentResult } from 'twenty-sdk/logic-function';
+import { isDefined } from 'twenty-sdk/utils';
+
+import { TEAMS_TRANSCRIPT_SUMMARY_UNAVAILABLE_PREFIX } from 'src/features/transcripts/constants/teams-transcript-summary-unavailable-prefix';
+import { type TeamsTranscriptSummary } from 'src/features/transcripts/logic-functions/types/teams-transcript-summary.type';
+
+export const parseTeamsTranscriptSummaryAgentResponse = (
+ agentResult: Pick<RunAgentResult, 'success' | 'error' | 'result'>,
+): TeamsTranscriptSummary | undefined => {
+ if (!agentResult.success || !isDefined(agentResult.result)) {
+ return undefined;
+ }
+
+ const response =
+ 'response' in agentResult.result ? agentResult.result.response : undefined;
+ const trimmedResponse = isString(response) ? response.trim() : '';
+
+ if (!isNonEmptyString(trimmedResponse)) {
+ return undefined;
+ }
+
+ if (
+ !trimmedResponse.startsWith(TEAMS_TRANSCRIPT_SUMMARY_UNAVAILABLE_PREFIX)
+ ) {
+ return { outcome: 'summarized', markdown: trimmedResponse };
+ }
+
+ const reason = trimmedResponse
+ .slice(TEAMS_TRANSCRIPT_SUMMARY_UNAVAILABLE_PREFIX.length)
+ .trim();
+
+ return isNonEmptyString(reason)
+ ? { outcome: 'not-summarizable', reason }
+ : undefined;
+};
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/select-teams-call-recording-ids-to-summarize.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/select-teams-call-recording-ids-to-summarize.ts
new file mode 100644
index 00000000000..a959e8f4199
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/select-teams-call-recording-ids-to-summarize.ts
@@ -0,0 +1,25 @@
+import { isNonEmptyArray, isNonEmptyString } from '@sniptt/guards';
+
+import { type TeamsCallRecordingSummaryEvent } from 'src/features/transcripts/logic-functions/types/teams-call-recording-summary-event.type';
+
+export const selectTeamsCallRecordingIdsToSummarize = ({
+ events,
+ applicationId,
+}: {
+ events: TeamsCallRecordingSummaryEvent[];
+ applicationId: string | undefined;
+}): string[] => {
+ if (!isNonEmptyString(applicationId)) {
+ return [];
+ }
+
+ const callRecordingIds = events
+ .filter(
+ ({ properties }) =>
+ properties.after?.applicationId === applicationId &&
+ isNonEmptyArray(properties.after.transcript),
+ )
+ .map(({ recordId }) => recordId);
+
+ return [...new Set(callRecordingIds)];
+};
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/summarize-teams-call-recording-or-throw.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/summarize-teams-call-recording-or-throw.ts
new file mode 100644
index 00000000000..f516aa2ed40
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/summarize-teams-call-recording-or-throw.ts
@@ -0,0 +1,90 @@
+import { type CoreApiClient } from 'twenty-client-sdk/core';
+import { runAgent, type RunAgentResult } from 'twenty-sdk/logic-function';
+import { isDefined } from 'twenty-sdk/utils';
+
+import { TEAMS_TRANSCRIPT_SUMMARIZER_AGENT_UNIVERSAL_IDENTIFIER } from 'src/features/transcripts/constants/universal-identifiers';
+import { type TeamsCallRecordingSummaryOutcome } from 'src/features/transcripts/logic-functions/types/teams-call-recording-summary-outcome.type';
+import { buildTeamsTranscriptSummaryPrompt } from 'src/features/transcripts/logic-functions/utils/build-teams-transcript-summary-prompt';
+import { findCallRecordingForSummaryOrThrow } from 'src/features/transcripts/logic-functions/utils/find-call-recording-for-summary-or-throw';
+import { isTeamsTranscriptSummaryEnabled } from 'src/features/transcripts/logic-functions/utils/is-teams-transcript-summary-enabled';
+import { parseTeamsTranscriptSummaryAgentResponse } from 'src/features/transcripts/logic-functions/utils/parse-teams-transcript-summary-agent-response';
+import { toErrorMessage } from 'src/utils/to-error-message';
+
+export const summarizeTeamsCallRecordingOrThrow = async ({
+ coreApiClient,
+ callRecordingId,
+}: {
+ coreApiClient: Pick<CoreApiClient, 'query' | 'mutation'>;
+ callRecordingId: string;
+}): Promise<TeamsCallRecordingSummaryOutcome> => {
+ if (!isTeamsTranscriptSummaryEnabled()) {
+ return 'disabled';
+ }
+
+ const callRecording = await findCallRecordingForSummaryOrThrow({
+ coreApiClient,
+ callRecordingId,
+ });
+
+ if (!isDefined(callRecording)) {
+ return 'not-found';
+ }
+
+ if (callRecording.hasSummary) {
+ return 'already-summarized';
+ }
+
+ const prompt = buildTeamsTranscriptSummaryPrompt({
+ transcript: callRecording.transcript,
+ title: callRecording.title,
+ });
+
+ if (!isDefined(prompt)) {
+ return 'no-transcript';
+ }
+
+ const agentResult: Pick<RunAgentResult, 'success' | 'error' | 'result'> =
+ await runAgent({
+ agentUniversalIdentifier:
+ TEAMS_TRANSCRIPT_SUMMARIZER_AGENT_UNIVERSAL_IDENTIFIER,
+ prompt,
+ }).catch((error: unknown) => ({
+ success: false,
+ error: toErrorMessage(error),
+ result: null,
+ }));
+ const summary = parseTeamsTranscriptSummaryAgentResponse(agentResult);
+
+ if (!isDefined(summary)) {
+ console.error(
+ `[teams] summarizer agent returned no summary for call recording ${callRecordingId}: ${agentResult.error ?? 'empty response'}`,
+ );
+
+ return 'agent-failed';
+ }
+
+ const summaryMarkdown =
+ summary.outcome === 'summarized'
+ ? summary.markdown
+ : `## Summary unavailable\n\n${summary.reason}`;
+
+ try {
+ await coreApiClient.mutation({
+ updateCallRecording: {
+ __args: {
+ id: callRecordingId,
+ data: { summary: { blocknote: null, markdown: summaryMarkdown } },
+ },
+ id: true,
+ },
+ });
+ } catch (error) {
+ console.error(
+ `[teams] failed to save the summary of call recording ${callRecordingId}: ${toErrorMessage(error)}`,
+ );
+
+ return 'save-failed';
+ }
+
+ return summary.outcome;
+};
diff --git a/packages/twenty-apps/public/teams/src/roles/default-function.role.ts b/packages/twenty-apps/public/teams/src/roles/default-function.role.ts
index 6d638ce08ea..798c85dacf9 100644
--- a/packages/twenty-apps/public/teams/src/roles/default-function.role.ts
+++ b/packages/twenty-apps/public/teams/src/roles/default-function.role.ts
@@ -14,7 +14,7 @@ export default defineApplicationRole({
universalIdentifier: DEFAULT_ROLE_UNIVERSAL_IDENTIFIER,
label: 'Twenty Microsoft Teams tools role',
description:
- 'Reads calendar events and their calendar channel associations to match Teams meetings and writes imported transcripts to Call Recordings. Tracks assistant requests received from Teams, reads workspace members to match a Teams sender by email, keeps Teams user links so a matched sender is remembered and can be unlinked, and runs the Teams Assistant agent as that member, with the permissions of that member. Chat tools only forward requests to Microsoft Teams using the configured bot credentials.',
+ 'Reads calendar events and their calendar channel associations to match Teams meetings, writes imported transcripts to Call Recordings, and writes the summary from the Teams Transcript Summarizer agent on them. Tracks assistant requests received from Teams, reads workspace members to match a Teams sender by email, keeps Teams user links so a matched sender is remembered and can be unlinked, and runs the Teams Assistant agent as that member, with the permissions of that member. Chat tools only forward requests to Microsoft Teams using the configured bot credentials.',
canReadAllObjectRecords: false,
canUpdateAllObjectRecords: false,
canSoftDeleteAllObjectRecords: false,