The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Add List My Teams Transcripts action backed by a Microsoft Graph client (#26315)
nitin390b55b71e61
diff --git a/packages/twenty-apps/public/teams/README.md b/packages/twenty-apps/public/teams/README.mdindex 74bce073719..f60707e3198 100644--- a/packages/twenty-apps/public/teams/README.md+++ b/packages/twenty-apps/public/teams/README.md@@ -1,86 +1,19 @@-# Microsoft Teams for Twenty+# Microsoft Teams-Microsoft Teams chat and transcript features in one application.+**Microsoft Teams chat and meeting transcripts, right inside your CRM.**-## Status+## β¨ What you get-The application provides a settings page, the Bot Connector helpers, and a-Microsoft OAuth connection for transcripts. Chat handlers and transcript imports-are still under development. Both features are unavailable in this version and-their workspace settings default to off. Connecting a Microsoft account does not-start transcript imports or register subscriptions. The default application role-has no CRM data access.+- **A Microsoft connection** for your work or school account+- **List My Teams Transcripts**, an AI and workflow action for the meetings you organized-See [SETUP.md](SETUP.md) for Microsoft OAuth setup.+## π Heads up-## Features, settings, and feature flags+- **Still in development.** Chat and transcript import are off by default and+ not available in this version. Connecting an account only stores its+ credentials; nothing is imported.+- **Work or school accounts only.** Personal Microsoft accounts are not+ supported.-- **Features** are the product areas: chat and transcripts. Their code, settings- components, identifiers, and tests live in `src/features/chat` and- `src/features/transcripts` respectively.-- **Settings** are workspace choices. `TEAMS_CHAT_ENABLED` and- `TEAMS_TRANSCRIPTS_ENABLED` are Boolean application variables managed through- **Settings β Applications β Microsoft Teams β Settings**. Updates use the- metadata API, which requires permission to manage applications.-- **Feature flags** are developer-controlled release decisions, defined in- `src/constants/feature-flags.ts`. They follow the server's- `IS_β¦_ENABLED` naming and are bundled with the app. Changing them requires a- new build and deployment; a workspace setting cannot override them.--`IS_CHAT_ASSISTANT_ENABLED` controls availability of chat in this scaffold, and-`IS_TRANSCRIPT_IMPORT_ENABLED` controls transcript imports. Both start as-`false`. A disabled feature is shown as unavailable in settings, retaining any-saved workspace preference.--The frontend and future handlers share-`isFeatureEnabled({ isAvailable, settingValue })`. Pass the feature's development-flag as `isAvailable`; the serialized workspace setting must also be `'true'`.-In a logic function, use `process.env[CHAT_ENABLED_APPLICATION_VARIABLE_KEY]` or-`process.env[TRANSCRIPTS_ENABLED_APPLICATION_VARIABLE_KEY]` as `settingValue`.-The settings page initializes from `getApplicationVariable` and updates its-local value after a successful save. Changes made by another client require a-page refresh. Live updates need shared host/SDK support for application-variable-change events.--New routes, connection hooks that start work, workflow actions, schedulers, and-queued workers must check feature availability before starting work and then-validate that feature's credentials. Keep disconnect, uninstall, and cleanup-paths available even when a feature is disabled. When a setting starts managing-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.--## Bot server variables--The bot's identity is an Entra app registration behind an Azure Bot resource.-An admin configures these on the Teams application registration under-**Settings β Applications**. They are optional at registration so marketplace-listing does not depend on an Azure Bot being provisioned. Chat requires all-three credentials before bot operations can run.--| Variable | Secret | Where it comes from |-| ------------------------ | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |-| `TEAMS_BOT_APP_ID` | no | Application (client) ID of the Entra app registration. Public in the Bot Framework protocol, and the expected audience when verifying inbound activities. |-| `TEAMS_BOT_APP_PASSWORD` | yes | Client secret of that app registration. Used to mint Bot Connector tokens. |-| `TEAMS_BOT_TENANT_ID` | no | Directory (tenant) ID that owns the Azure Bot. Microsoft stopped issuing multi-tenant bots after 2025-07-31, so token minting is tenant-scoped rather than going through the shared `botframework.com` authority. |--## Development--This package is a standalone project rather than a root workspace, so run yarn-from this directory.--```bash-yarn install-yarn lint-yarn typecheck-yarn test:unit-yarn twenty dev:build-```--Installation tests run with `yarn test` against a disposable Twenty workspace.-They install and uninstall the Teams application; see [SETUP.md](SETUP.md).+**Self-hosting?** Your admin registers the Microsoft app first: see the+[setup guide](https://github.com/twentyhq/twenty/blob/main/packages/twenty-apps/public/teams/SETUP.md).diff --git a/packages/twenty-apps/public/teams/SETUP.md b/packages/twenty-apps/public/teams/SETUP.mdindex 41f93ff3694..c0c53ab317e 100644--- a/packages/twenty-apps/public/teams/SETUP.md+++ b/packages/twenty-apps/public/teams/SETUP.md@@ -12,13 +12,16 @@Twenty. Use the secret **Value**, not its ID.4. Add the Microsoft Graph delegated permissions below and obtain administratorconsent where required by your organization.+5. In Teams admin center > Meetings > Meeting settings > Transcript API access,+ enable **Microsoft Graph access**. Without it, Graph answers transcript+ requests with `GraphAccessToTranscriptsDisabled`.-| Permission | Purpose |-| ---------------------------------- | ------------------------------------------------------- |-| `User.Read` | Identify the connected Microsoft account |-| `Calendars.ReadBasic` | Discover scheduled meetings in the upcoming import flow |-| `OnlineMeetings.Read` | Read meeting metadata in the upcoming import flow |-| `OnlineMeetingTranscript.Read.All` | Read transcripts in the upcoming import flow |+| Permission | Purpose |+| ---------------------------------- | ------------------------------------------------- |+| `User.Read` | Identify the connected Microsoft account |+| `Calendars.ReadBasic` | Find the scheduled meetings the account organizes |+| `OnlineMeetings.Read` | Resolve a calendar event to its online meeting |+| `OnlineMeetingTranscript.Read.All` | List the transcripts of those meetings |The connection also requests `openid`, `profile`, `email`, and `offline_access`for account identity and refresh tokens. It uses the authorization code flow@@ -27,24 +30,98 @@ with PKCE through Twenty's connection provider.These OAuth credentials are separate from the `TEAMS_BOT_*` credentials used bythe chat Bot Connector. They are optional at registration so Teams can beinstalled without transcript setup. Both must be configured before users can add-a Microsoft connection. See [README.md](README.md#bot-server-variables) for the+a Microsoft connection. See [Bot server variables](#bot-server-variables) for thebot configuration.+## Bot server variables++The bot's identity is an Entra app registration behind an Azure Bot resource.+An admin configures these on the Teams application registration under+**Settings β Applications**. They are optional at registration so marketplace+listing does not depend on an Azure Bot being provisioned. Chat requires all+three credentials before bot operations can run.++| Variable | Secret | Where it comes from |+| ------------------------ | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |+| `TEAMS_BOT_APP_ID` | no | Application (client) ID of the Entra app registration. Public in the Bot Framework protocol, and the expected audience when verifying inbound activities. |+| `TEAMS_BOT_APP_PASSWORD` | yes | Client secret of that app registration. Used to mint Bot Connector tokens. |+| `TEAMS_BOT_TENANT_ID` | no | Directory (tenant) ID that owns the Azure Bot. Microsoft stopped issuing multi-tenant bots after 2025-07-31, so token minting is tenant-scoped rather than going through the shared `botframework.com` authority. |+## ConnectOpen **Settings > Applications > Microsoft Teams > Settings**, select**Add connection**, and sign in with your Microsoft work or school account.-This version stores the connection; it does not import transcripts or register-webhooks. The transcript release flag and workspace setting remain off. Connecting-an account does not enable them.+Connecting an account does not import transcripts or register webhooks. The+transcript release flag and workspace setting remain off. Connecting an account+does not enable them.++## Test the list action++1. For a development build, set `IS_TRANSCRIPT_IMPORT_ENABLED` to `true`, rebuild+ and deploy the app, then enable transcripts in the Microsoft Teams settings.+2. Schedule a Teams meeting with the connected account, join it at its+ scheduled time, start transcription, speak, and end the meeting. Microsoft+ publishes the transcript a few minutes later.+3. Ask the Twenty AI assistant to list your Teams transcripts, or add the+ **List My Teams Transcripts** action to a workflow. The result carries one+ entry per transcript with the meeting subject, the Graph meeting ID, and the+ transcript ID.++The action uses your own connection first and falls back to a workspace-shared+one. Optional `startDateTime` and `endDateTime` select the meeting window,+which defaults to the last 31 days; `nextPageUrl` continues a paginated result.References: [Microsoft authorization code flow](https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow)-and [transcript permissions](https://learn.microsoft.com/en-us/graph/api/onlinemeeting-list-transcripts?view=graph-rest-1.0).+and [transcript permissions](https://learn.microsoft.com/en-us/graph/api/onlinemeeting-list-transcripts?view=graph-rest-1.0),+plus [Teams transcript API access settings](https://learn.microsoft.com/en-us/microsoftteams/meeting-transcript-api-access).++## Features, settings, and feature flags++- **Features** are the product areas: chat and transcripts. Their code, settings+ components, identifiers, and tests live in `src/features/chat` and+ `src/features/transcripts` respectively.+- **Settings** are workspace choices. `TEAMS_CHAT_ENABLED` and+ `TEAMS_TRANSCRIPTS_ENABLED` are Boolean application variables managed through+ **Settings β Applications β Microsoft Teams β Settings**. Updates use the+ metadata API, which requires permission to manage applications.+- **Feature flags** are developer-controlled release decisions, defined in+ `src/constants/feature-flags.ts`. They follow the server's+ `IS_β¦_ENABLED` naming and are bundled with the app. Changing them requires a+ new build and deployment; a workspace setting cannot override them.++`IS_CHAT_ASSISTANT_ENABLED` controls availability of chat in this scaffold, and+`IS_TRANSCRIPT_IMPORT_ENABLED` controls transcript imports. Both start as+`false`. A disabled feature is shown as unavailable in settings, retaining any+saved workspace preference.++The frontend and handlers share+`isFeatureEnabled({ isAvailable, settingValue })`. Pass the feature's development+flag as `isAvailable`; the serialized workspace setting must also be `'true'`.+In a logic function, use `process.env[CHAT_ENABLED_APPLICATION_VARIABLE_KEY]` or+`process.env[TRANSCRIPTS_ENABLED_APPLICATION_VARIABLE_KEY]` as `settingValue`.+The settings page initializes from `getApplicationVariable` and updates its+local value after a successful save. Changes made by another client require a+page refresh. Live updates need shared host/SDK support for application-variable+change events.++New routes, connection hooks that start work, workflow actions, schedulers, and+queued workers must check feature availability before starting work and then+validate that feature's credentials. Keep disconnect, uninstall, and cleanup+paths available even when a feature is disabled. When a setting starts managing+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.## Development-Use the Node version in `.nvmrc` and Yarn 4. From this directory:+This package is a standalone project rather than a root workspace, so run yarn+from this directory with the Node version in `.nvmrc` and Yarn 4:```bashyarn install --immutable@@ -58,3 +135,21 @@ Installation tests use a disposable Twenty workspace. Configure`TWENTY_API_URL` and `TWENTY_API_KEY` for that workspace, then run `yarn test`.The test setup installs and uninstalls the application; do not use the shared QAworkspace. Public apps use the monorepo CI workflows.++## Troubleshooting++- No Add connection button: check that the provider was deployed and its two+ server variables are filled.+- Redirect mismatch: register the exact `/auth/apps/callback` URI on the **Web**+ platform, including the correct scheme and hostname.+- Admin approval required: the Microsoft tenant administrator must consent to+ the delegated permissions before the connection can finish.+- `Teams transcripts are not enabled`: enable the transcript release flag in+ the build and the workspace transcript setting.+- `Microsoft Teams is not connected`: the requesting user has no personal+ connection and the workspace has no shared one.+- `GraphAccessToTranscriptsDisabled`: enable Microsoft Graph transcript access+ in Teams meeting settings.+- Empty result: verify that transcription was started during the scheduled+ meeting time, give or take 15 minutes, Microsoft has finished processing it,+ and the connected account organized the meeting.diff --git a/packages/twenty-apps/public/teams/src/__tests__/schema.integration-test.ts b/packages/twenty-apps/public/teams/src/__tests__/schema.integration-test.tsindex ccf7c12bc9b..758aefbc041 100644--- a/packages/twenty-apps/public/teams/src/__tests__/schema.integration-test.ts+++ b/packages/twenty-apps/public/teams/src/__tests__/schema.integration-test.ts@@ -5,6 +5,16 @@ import { APPLICATION_UNIVERSAL_IDENTIFIER } from 'src/constants/universal-identiimport { describe, expect, it } from 'vitest';describe('App installation', () => {+ it('deploys the List My Teams Transcripts function', async () => {+ const result = await new MetadataApiClient().query({+ findManyLogicFunctions: { name: true },+ });++ expect(+ result.findManyLogicFunctions.map((logicFunction) => logicFunction.name),+ ).toContain('teams-list-organizer-transcripts');+ });+it('registers Microsoft OAuth under Teams without configured credentials', async () => {const client = new MetadataApiClient();diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/connection-providers/microsoft-teams-connection.ts b/packages/twenty-apps/public/teams/src/features/transcripts/connection-providers/microsoft-teams-connection.tsindex 0d0b726a581..0d9f81b0909 100644--- a/packages/twenty-apps/public/teams/src/features/transcripts/connection-providers/microsoft-teams-connection.ts+++ b/packages/twenty-apps/public/teams/src/features/transcripts/connection-providers/microsoft-teams-connection.ts@@ -1,10 +1,11 @@import { defineConnectionProvider } from 'twenty-sdk/define';+import { TEAMS_PROVIDER_NAME } from 'src/features/transcripts/constants/teams-provider-name';import { TEAMS_CONNECTION_PROVIDER_UNIVERSAL_IDENTIFIER } from 'src/features/transcripts/constants/universal-identifiers';export default defineConnectionProvider({universalIdentifier: TEAMS_CONNECTION_PROVIDER_UNIVERSAL_IDENTIFIER,- name: 'microsoft-teams',+ name: TEAMS_PROVIDER_NAME,displayName: 'Microsoft Teams',type: 'oauth',oauth: {diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/constants/teams-provider-name.ts b/packages/twenty-apps/public/teams/src/features/transcripts/constants/teams-provider-name.tsnew file mode 100644index 00000000000..9000a9d01ba--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/constants/teams-provider-name.ts@@ -0,0 +1 @@+export const TEAMS_PROVIDER_NAME = 'microsoft-teams';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.tsindex cfb9cc136d8..446b1384fd6 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@@ -3,3 +3,6 @@ export const TRANSCRIPTS_ENABLED_APPLICATION_VARIABLE_UNIVERSAL_IDENTIFIER =export const TEAMS_CONNECTION_PROVIDER_UNIVERSAL_IDENTIFIER ='b81c3c60-2cb1-44b8-9ec6-6f731997f5f0';++export const TEAMS_LIST_ORGANIZER_TRANSCRIPTS_UNIVERSAL_IDENTIFIER =+ 'e76f9ccb-cda3-4bd1-99aa-0e5806b1f4a2';diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/graph-request-max-attempts.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/graph-request-max-attempts.tsnew file mode 100644index 00000000000..305b4a69dae--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/graph-request-max-attempts.ts@@ -0,0 +1 @@+export const GRAPH_REQUEST_MAX_ATTEMPTS = 4;diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/graph-request-retry-base-delay-milliseconds.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/graph-request-retry-base-delay-milliseconds.tsnew file mode 100644index 00000000000..ff6ad55606f--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/graph-request-retry-base-delay-milliseconds.ts@@ -0,0 +1 @@+export const GRAPH_REQUEST_RETRY_BASE_DELAY_MILLISECONDS = 1_000;diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/graph-retryable-statuses.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/graph-retryable-statuses.tsnew file mode 100644index 00000000000..b534f1a3d99--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/graph-retryable-statuses.ts@@ -0,0 +1 @@+export const GRAPH_RETRYABLE_STATUSES = new Set([429, 502, 503, 504]);diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/max-graph-transcript-list-pages.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/max-graph-transcript-list-pages.tsnew file mode 100644index 00000000000..56969d63a14--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/max-graph-transcript-list-pages.ts@@ -0,0 +1 @@+export const MAX_GRAPH_TRANSCRIPT_LIST_PAGES = 200;diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/microsoft-graph-base-url.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/microsoft-graph-base-url.tsnew file mode 100644index 00000000000..e5a9f0e5020--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/microsoft-graph-base-url.ts@@ -0,0 +1 @@+export const MICROSOFT_GRAPH_BASE_URL = 'https://graph.microsoft.com/v1.0';diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/teams-calendar-page-size.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/teams-calendar-page-size.tsnew file mode 100644index 00000000000..d181cf2b52a--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/teams-calendar-page-size.ts@@ -0,0 +1 @@+export const TEAMS_CALENDAR_PAGE_SIZE = 50;diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/teams-default-lookback-milliseconds.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/teams-default-lookback-milliseconds.tsnew file mode 100644index 00000000000..152ebe64ac0--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/teams-default-lookback-milliseconds.ts@@ -0,0 +1 @@+export const TEAMS_DEFAULT_LOOKBACK_MILLISECONDS = 31 * 24 * 60 * 60 * 1_000;diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/teams-occurrence-margin-milliseconds.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/teams-occurrence-margin-milliseconds.tsnew file mode 100644index 00000000000..c476e31de60--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/constants/teams-occurrence-margin-milliseconds.ts@@ -0,0 +1 @@+export const TEAMS_OCCURRENCE_MARGIN_MILLISECONDS = 15 * 60 * 1_000;diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/teams-list-organizer-transcripts.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/teams-list-organizer-transcripts.tsnew file mode 100644index 00000000000..8a8beae41cb--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/teams-list-organizer-transcripts.ts@@ -0,0 +1,183 @@+import { isNonEmptyString } from '@sniptt/guards';+import { defineLogicFunction } from 'twenty-sdk/define';+import { isDefined } from 'twenty-sdk/utils';+import {+ type InputJsonSchema,+ type LogicFunctionExecutionContext,+ jsonSchemaToInputSchema,+} from 'twenty-sdk/logic-function';++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 { TEAMS_LIST_ORGANIZER_TRANSCRIPTS_UNIVERSAL_IDENTIFIER } from 'src/features/transcripts/constants/universal-identifiers';+import { buildTeamsCalendarViewUrl } from 'src/features/transcripts/logic-functions/utils/build-teams-calendar-view-url';+import { getMeetingByJoinUrl } from 'src/features/transcripts/logic-functions/utils/get-meeting-by-join-url';+import { getTeamsConnectionForRequestOrThrow } from 'src/features/transcripts/logic-functions/utils/get-teams-connection-for-request-or-throw';+import { isTranscriptDuringOccurrence } from 'src/features/transcripts/logic-functions/utils/is-transcript-during-occurrence';+import { listMeetingTranscripts } from 'src/features/transcripts/logic-functions/utils/list-meeting-transcripts';+import { listTeamsCalendarPage } from 'src/features/transcripts/logic-functions/utils/list-teams-calendar-page';+import { resolveTeamsCalendarNextPageUrlOrThrow } from 'src/features/transcripts/logic-functions/utils/resolve-teams-calendar-next-page-url-or-throw';+import { resolveTeamsMeetingWindowOrThrow } from 'src/features/transcripts/logic-functions/utils/resolve-teams-meeting-window-or-throw';+import { toErrorMessage } from 'src/features/transcripts/logic-functions/utils/to-error-message';+import { isFeatureEnabled } from 'src/utils/is-feature-enabled';++const teamsListOrganizerTranscriptsInputSchema: InputJsonSchema = {+ type: 'object',+ properties: {+ startDateTime: {+ type: 'string',+ label: 'Start (ISO 8601, UTC)',+ description: 'Find meetings after this instant. Defaults to 31 days ago.',+ },+ endDateTime: {+ type: 'string',+ label: 'End (ISO 8601, UTC)',+ description: 'Find meetings before this instant. Defaults to now.',+ },+ nextPageUrl: {+ type: 'string',+ label: 'Next page URL',+ description:+ 'Continue from nextPageUrl returned by a previous list call.',+ },+ },+ required: [],+ additionalProperties: false,+};++type ListedTranscript = {+ transcriptId: string;+ meetingId: string;+ subject?: string;+ createdDateTime?: string;+};++type TeamsListOrganizerTranscriptsResult =+ | {+ success: true;+ connectedAccount: string;+ transcripts: ListedTranscript[];+ nextPageUrl?: string;+ }+ | { success: false; error: string };++export const teamsListOrganizerTranscriptsHandler = async (+ parameters: {+ startDateTime?: unknown;+ endDateTime?: unknown;+ nextPageUrl?: unknown;+ },+ context: Pick<LogicFunctionExecutionContext, 'userWorkspaceId'>,+): Promise<TeamsListOrganizerTranscriptsResult> => {+ if (+ !isFeatureEnabled({+ isAvailable: FEATURE_FLAGS.IS_TRANSCRIPT_IMPORT_ENABLED,+ settingValue: process.env[TRANSCRIPTS_ENABLED_APPLICATION_VARIABLE_KEY],+ })+ ) {+ return { success: false, error: 'Teams transcripts are not enabled.' };+ }++ try {+ const calendarPageUrl = isNonEmptyString(parameters.nextPageUrl)+ ? resolveTeamsCalendarNextPageUrlOrThrow(parameters.nextPageUrl)+ : buildTeamsCalendarViewUrl(resolveTeamsMeetingWindowOrThrow(parameters));+ const connection = await getTeamsConnectionForRequestOrThrow(context);+ const page = await listTeamsCalendarPage({+ accessToken: connection.accessToken,+ url: calendarPageUrl,+ });+ const joinWebUrls = [+ ...new Set(page.occurrences.map((occurrence) => occurrence.joinWebUrl)),+ ];+ const transcripts: ListedTranscript[] = [];++ for (const joinWebUrl of joinWebUrls) {+ const meeting = await getMeetingByJoinUrl({+ accessToken: connection.accessToken,+ joinWebUrl,+ });++ if (!isDefined(meeting)) {+ continue;+ }++ const occurrences = page.occurrences.filter(+ (occurrence) => occurrence.joinWebUrl === joinWebUrl,+ );+ const meetingTranscripts = await listMeetingTranscripts({+ accessToken: connection.accessToken,+ meetingId: meeting.id,+ });++ transcripts.push(+ ...meetingTranscripts+ .filter((transcript) =>+ occurrences.some((occurrence) =>+ isTranscriptDuringOccurrence({ transcript, occurrence }),+ ),+ )+ .map((transcript) => ({+ transcriptId: transcript.id,+ meetingId: meeting.id,+ subject: isNonEmptyString(meeting.subject)+ ? meeting.subject+ : undefined,+ createdDateTime: isNonEmptyString(transcript.createdDateTime)+ ? transcript.createdDateTime+ : undefined,+ })),+ );+ }++ return {+ success: true,+ connectedAccount: connection.handle,+ transcripts,+ nextPageUrl: page.nextPageUrl,+ };+ } catch (error) {+ return { success: false, error: toErrorMessage(error) };+ }+};++export default defineLogicFunction({+ universalIdentifier: TEAMS_LIST_ORGANIZER_TRANSCRIPTS_UNIVERSAL_IDENTIFIER,+ name: 'teams-list-organizer-transcripts',+ description:+ 'List transcripts for scheduled Teams meetings organized by your connected Microsoft account. Returns one calendar page at a time, with nextPageUrl for continuation.',+ timeoutSeconds: 300,+ handler: teamsListOrganizerTranscriptsHandler,+ toolTriggerSettings: {+ inputSchema: teamsListOrganizerTranscriptsInputSchema,+ },+ workflowActionTriggerSettings: {+ label: 'List My Teams Transcripts',+ inputSchema: jsonSchemaToInputSchema(+ teamsListOrganizerTranscriptsInputSchema,+ ),+ outputSchema: [+ {+ type: 'object',+ properties: {+ success: { type: 'boolean' },+ error: { type: 'string' },+ connectedAccount: { type: 'string' },+ nextPageUrl: { type: 'string' },+ transcripts: {+ type: 'array',+ items: {+ type: 'object',+ properties: {+ transcriptId: { type: 'string' },+ meetingId: { type: 'string' },+ subject: { type: 'string' },+ createdDateTime: { type: 'string' },+ },+ },+ },+ },+ },+ ],+ },+});diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/graph-call-transcript.type.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/graph-call-transcript.type.tsnew file mode 100644index 00000000000..ca581d54420--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/graph-call-transcript.type.ts@@ -0,0 +1,4 @@+export type GraphCallTranscript = {+ id: string;+ createdDateTime?: string | null;+};diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/graph-collection-page.type.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/graph-collection-page.type.tsnew file mode 100644index 00000000000..33a36699f3b--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/graph-collection-page.type.ts@@ -0,0 +1,4 @@+export type GraphCollectionPage<TItem> = {+ value?: TItem[];+ '@odata.nextLink'?: string;+};diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/graph-date-time-time-zone.type.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/graph-date-time-time-zone.type.tsnew file mode 100644index 00000000000..853660193aa--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/graph-date-time-time-zone.type.ts@@ -0,0 +1,4 @@+export type GraphDateTimeTimeZone = {+ dateTime: string;+ timeZone: string;+};diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/graph-online-meeting.type.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/graph-online-meeting.type.tsnew file mode 100644index 00000000000..69a85283568--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/graph-online-meeting.type.ts@@ -0,0 +1,4 @@+export type GraphOnlineMeeting = {+ id: string;+ subject: string | null;+};diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/graph-request-error.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/graph-request-error.tsnew file mode 100644index 00000000000..10bc8b984e3--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/graph-request-error.ts@@ -0,0 +1,9 @@+export class GraphRequestError extends Error {+ readonly status: number;++ constructor({ message, status }: { message: string; status: number }) {+ super(message);+ this.name = 'GraphRequestError';+ this.status = status;+ }+}diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/teams-calendar-event.type.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/teams-calendar-event.type.tsnew file mode 100644index 00000000000..c3d4ceba068--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/teams-calendar-event.type.ts@@ -0,0 +1,10 @@+import { type GraphDateTimeTimeZone } from 'src/features/transcripts/logic-functions/types/graph-date-time-time-zone.type';++export type TeamsCalendarEvent = {+ isOrganizer?: boolean;+ isCancelled?: boolean;+ onlineMeetingProvider?: string;+ onlineMeeting?: { joinUrl?: string | null } | null;+ start?: GraphDateTimeTimeZone | null;+ end?: GraphDateTimeTimeZone | null;+};diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/teams-meeting-occurrence.type.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/teams-meeting-occurrence.type.tsnew file mode 100644index 00000000000..1710571bfe6--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/teams-meeting-occurrence.type.ts@@ -0,0 +1,5 @@+import { type TeamsMeetingWindow } from 'src/features/transcripts/logic-functions/types/teams-meeting-window.type';++export type TeamsMeetingOccurrence = TeamsMeetingWindow & {+ joinWebUrl: string;+};diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/teams-meeting-window.type.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/teams-meeting-window.type.tsnew file mode 100644index 00000000000..4944b19c12a--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/types/teams-meeting-window.type.ts@@ -0,0 +1,4 @@+export type TeamsMeetingWindow = {+ startDateTime: string;+ endDateTime: string;+};diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/build-teams-calendar-view-url.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/build-teams-calendar-view-url.tsnew file mode 100644index 00000000000..275db18c14e--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/build-teams-calendar-view-url.ts@@ -0,0 +1,16 @@+import { TEAMS_CALENDAR_PAGE_SIZE } from 'src/features/transcripts/logic-functions/constants/teams-calendar-page-size';+import { type TeamsMeetingWindow } from 'src/features/transcripts/logic-functions/types/teams-meeting-window.type';++export const buildTeamsCalendarViewUrl = (+ window: TeamsMeetingWindow,+): string => {+ const query = new URLSearchParams({+ startDateTime: window.startDateTime,+ endDateTime: window.endDateTime,+ $select:+ 'isOrganizer,isCancelled,onlineMeetingProvider,onlineMeeting,start,end',+ $top: String(TEAMS_CALENDAR_PAGE_SIZE),+ });++ return `me/calendarView?${query}`;+};diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/fetch-graph-json.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/fetch-graph-json.tsnew file mode 100644index 00000000000..9f1152edfee--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/fetch-graph-json.ts@@ -0,0 +1,81 @@+import { isNonEmptyString } from '@sniptt/guards';++import { GRAPH_REQUEST_MAX_ATTEMPTS } from 'src/features/transcripts/logic-functions/constants/graph-request-max-attempts';+import { GRAPH_REQUEST_RETRY_BASE_DELAY_MILLISECONDS } from 'src/features/transcripts/logic-functions/constants/graph-request-retry-base-delay-milliseconds';+import { GRAPH_RETRYABLE_STATUSES } from 'src/features/transcripts/logic-functions/constants/graph-retryable-statuses';+import { GraphRequestError } from 'src/features/transcripts/logic-functions/types/graph-request-error';+import { resolveGraphUrlOrThrow } from 'src/features/transcripts/logic-functions/utils/resolve-graph-url-or-throw';+import { sleepForMilliseconds } from 'src/features/transcripts/logic-functions/utils/sleep-for-milliseconds';++type GraphErrorBody = {+ error?: {+ message?: unknown;+ innerError?: { code?: unknown } | null;+ };+};++const fetchGraphResponse = async ({+ accessToken,+ url,+ attempt,+}: {+ accessToken: string;+ url: string;+ attempt: number;+}): Promise<Response> => {+ const response = await fetch(url, {+ redirect: 'error',+ headers: {+ Authorization: `Bearer ${accessToken}`,+ Accept: 'application/json',+ },+ });++ if (response.ok) {+ return response;+ }++ if (+ GRAPH_RETRYABLE_STATUSES.has(response.status) &&+ attempt + 1 < GRAPH_REQUEST_MAX_ATTEMPTS+ ) {+ const retryAfterSeconds = Number(response.headers.get('Retry-After'));++ await sleepForMilliseconds(+ retryAfterSeconds > 0+ ? retryAfterSeconds * 1_000+ : GRAPH_REQUEST_RETRY_BASE_DELAY_MILLISECONDS * 2 ** attempt,+ );++ return fetchGraphResponse({ accessToken, url, attempt: attempt + 1 });+ }++ const body: GraphErrorBody = await response.json().catch(() => ({}));+ const innerErrorCode = body.error?.innerError?.code;+ const message = isNonEmptyString(body.error?.message)+ ? body.error.message+ : response.statusText;++ throw new GraphRequestError({+ message: `Microsoft Graph request failed (${response.status}${isNonEmptyString(innerErrorCode) ? ` ${innerErrorCode}` : ''}): ${message}`,+ status: response.status,+ });+};++export const fetchGraphJson = async <TResponse>({+ accessToken,+ url,+}: {+ accessToken: string;+ url: string;+}): Promise<TResponse> => {+ const response = await fetchGraphResponse({+ accessToken,+ url: resolveGraphUrlOrThrow(url),+ attempt: 0,+ });++ const body: TResponse = await response.json();++ return body;+};diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/get-meeting-by-join-url.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/get-meeting-by-join-url.tsnew file mode 100644index 00000000000..bcf3eb0156b--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/get-meeting-by-join-url.ts@@ -0,0 +1,31 @@+import { type GraphCollectionPage } from 'src/features/transcripts/logic-functions/types/graph-collection-page.type';+import { type GraphOnlineMeeting } from 'src/features/transcripts/logic-functions/types/graph-online-meeting.type';+import { GraphRequestError } from 'src/features/transcripts/logic-functions/types/graph-request-error';+import { fetchGraphJson } from 'src/features/transcripts/logic-functions/utils/fetch-graph-json';++export const getMeetingByJoinUrl = async ({+ accessToken,+ joinWebUrl,+}: {+ accessToken: string;+ joinWebUrl: string;+}): Promise<GraphOnlineMeeting | undefined> => {+ const query = new URLSearchParams({+ $filter: `JoinWebUrl eq '${joinWebUrl.replace(/'/g, "''")}'`,+ });++ try {+ const page = await fetchGraphJson<GraphCollectionPage<GraphOnlineMeeting>>({+ accessToken,+ url: `me/onlineMeetings?${query}`,+ });++ return page.value?.[0];+ } catch (error) {+ if (error instanceof GraphRequestError && error.status === 404) {+ return undefined;+ }++ throw error;+ }+};diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/get-teams-connection-for-request-or-throw.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/get-teams-connection-for-request-or-throw.tsnew file mode 100644index 00000000000..58b8b8f8f29--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/get-teams-connection-for-request-or-throw.ts@@ -0,0 +1,29 @@+import {+ findConnectionForRequest,+ listConnections,+ type LogicFunctionExecutionContext,+} from 'twenty-sdk/logic-function';+import { isDefined } from 'twenty-sdk/utils';++import { TEAMS_PROVIDER_NAME } from 'src/features/transcripts/constants/teams-provider-name';++export const getTeamsConnectionForRequestOrThrow = async (+ context: Pick<LogicFunctionExecutionContext, 'userWorkspaceId'>,+) => {+ const connection = findConnectionForRequest(+ await listConnections({ providerName: TEAMS_PROVIDER_NAME }),+ context,+ );++ if (!isDefined(connection)) {+ throw new Error(+ 'Microsoft Teams is not connected. Open Microsoft Teams app settings and add a connection first.',+ );+ }++ if (isDefined(connection.authFailedAt)) {+ throw new Error('Reconnect Microsoft Teams in the app settings.');+ }++ return connection;+};diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/is-transcript-during-occurrence.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/is-transcript-during-occurrence.tsnew file mode 100644index 00000000000..efcd4c80fbd--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/is-transcript-during-occurrence.ts@@ -0,0 +1,27 @@+import { isNonEmptyString } from '@sniptt/guards';++import { TEAMS_OCCURRENCE_MARGIN_MILLISECONDS } from 'src/features/transcripts/logic-functions/constants/teams-occurrence-margin-milliseconds';+import { type GraphCallTranscript } from 'src/features/transcripts/logic-functions/types/graph-call-transcript.type';+import { type TeamsMeetingWindow } from 'src/features/transcripts/logic-functions/types/teams-meeting-window.type';++export const isTranscriptDuringOccurrence = ({+ transcript,+ occurrence,+}: {+ transcript: Pick<GraphCallTranscript, 'createdDateTime'>;+ occurrence: TeamsMeetingWindow;+}): boolean => {+ if (!isNonEmptyString(transcript.createdDateTime)) {+ return false;+ }++ const createdMilliseconds = Date.parse(transcript.createdDateTime);++ return (+ createdMilliseconds >=+ Date.parse(occurrence.startDateTime) -+ TEAMS_OCCURRENCE_MARGIN_MILLISECONDS &&+ createdMilliseconds <=+ Date.parse(occurrence.endDateTime) + TEAMS_OCCURRENCE_MARGIN_MILLISECONDS+ );+};diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/list-meeting-transcripts.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/list-meeting-transcripts.tsnew file mode 100644index 00000000000..e9bad7fe16a--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/list-meeting-transcripts.ts@@ -0,0 +1,53 @@+import { isNonEmptyString } from '@sniptt/guards';++import { MAX_GRAPH_TRANSCRIPT_LIST_PAGES } from 'src/features/transcripts/logic-functions/constants/max-graph-transcript-list-pages';+import { type GraphCallTranscript } from 'src/features/transcripts/logic-functions/types/graph-call-transcript.type';+import { type GraphCollectionPage } from 'src/features/transcripts/logic-functions/types/graph-collection-page.type';+import { fetchGraphJson } from 'src/features/transcripts/logic-functions/utils/fetch-graph-json';++const listMeetingTranscriptPages = async ({+ accessToken,+ url,+ pageIndex,+}: {+ accessToken: string;+ url: string;+ pageIndex: number;+}): Promise<GraphCallTranscript[]> => {+ if (pageIndex >= MAX_GRAPH_TRANSCRIPT_LIST_PAGES) {+ throw new Error('Microsoft transcript pagination exceeded its limit');+ }++ const page = await fetchGraphJson<GraphCollectionPage<GraphCallTranscript>>({+ accessToken,+ url,+ });+ const transcripts = page.value ?? [];+ const nextPageUrl = page['@odata.nextLink'];++ if (!isNonEmptyString(nextPageUrl)) {+ return transcripts;+ }++ return [+ ...transcripts,+ ...(await listMeetingTranscriptPages({+ accessToken,+ url: nextPageUrl,+ pageIndex: pageIndex + 1,+ })),+ ];+};++export const listMeetingTranscripts = ({+ accessToken,+ meetingId,+}: {+ accessToken: string;+ meetingId: string;+}): Promise<GraphCallTranscript[]> =>+ listMeetingTranscriptPages({+ accessToken,+ url: `me/onlineMeetings/${encodeURIComponent(meetingId)}/transcripts`,+ pageIndex: 0,+ });diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/list-teams-calendar-page.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/list-teams-calendar-page.tsnew file mode 100644index 00000000000..b230c184bb2--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/list-teams-calendar-page.ts@@ -0,0 +1,36 @@+import { isNonEmptyString } from '@sniptt/guards';+import { isDefined } from 'twenty-sdk/utils';++import { type GraphCollectionPage } from 'src/features/transcripts/logic-functions/types/graph-collection-page.type';+import { type TeamsCalendarEvent } from 'src/features/transcripts/logic-functions/types/teams-calendar-event.type';+import { type TeamsMeetingOccurrence } from 'src/features/transcripts/logic-functions/types/teams-meeting-occurrence.type';+import { fetchGraphJson } from 'src/features/transcripts/logic-functions/utils/fetch-graph-json';+import { toTeamsMeetingOccurrence } from 'src/features/transcripts/logic-functions/utils/to-teams-meeting-occurrence';++export const listTeamsCalendarPage = async ({+ accessToken,+ url,+}: {+ accessToken: string;+ url: string;+}): Promise<{+ occurrences: TeamsMeetingOccurrence[];+ nextPageUrl?: string;+}> => {+ const page = await fetchGraphJson<GraphCollectionPage<TeamsCalendarEvent>>({+ accessToken,+ url,+ });+ const occurrences = (page.value ?? []).flatMap((event) => {+ const occurrence = toTeamsMeetingOccurrence(event);++ return isDefined(occurrence) ? [occurrence] : [];+ });++ return {+ occurrences,+ nextPageUrl: isNonEmptyString(page['@odata.nextLink'])+ ? page['@odata.nextLink']+ : undefined,+ };+};diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/parse-graph-utc-date-time.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/parse-graph-utc-date-time.tsnew file mode 100644index 00000000000..10cdc594737--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/parse-graph-utc-date-time.ts@@ -0,0 +1,17 @@+import { isDefined } from 'twenty-sdk/utils';++import { type GraphDateTimeTimeZone } from 'src/features/transcripts/logic-functions/types/graph-date-time-time-zone.type';++export const parseGraphUtcDateTime = (+ dateTimeTimeZone: GraphDateTimeTimeZone | null | undefined,+): string | undefined => {+ if (!isDefined(dateTimeTimeZone)) {+ return undefined;+ }++ const milliseconds = Date.parse(`${dateTimeTimeZone.dateTime}Z`);++ return Number.isFinite(milliseconds)+ ? new Date(milliseconds).toISOString()+ : undefined;+};diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/resolve-graph-url-or-throw.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/resolve-graph-url-or-throw.tsnew file mode 100644index 00000000000..5d20f0f6d98--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/resolve-graph-url-or-throw.ts@@ -0,0 +1,11 @@+import { MICROSOFT_GRAPH_BASE_URL } from 'src/features/transcripts/logic-functions/constants/microsoft-graph-base-url';++export const resolveGraphUrlOrThrow = (url: string): string => {+ const resolvedUrl = new URL(url, `${MICROSOFT_GRAPH_BASE_URL}/`);++ if (resolvedUrl.origin !== new URL(MICROSOFT_GRAPH_BASE_URL).origin) {+ throw new Error('Microsoft Graph URLs must use graph.microsoft.com');+ }++ return resolvedUrl.toString();+};diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/resolve-teams-calendar-next-page-url-or-throw.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/resolve-teams-calendar-next-page-url-or-throw.tsnew file mode 100644index 00000000000..138f2289f03--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/resolve-teams-calendar-next-page-url-or-throw.ts@@ -0,0 +1,19 @@+import { resolveGraphUrlOrThrow } from 'src/features/transcripts/logic-functions/utils/resolve-graph-url-or-throw';++export const resolveTeamsCalendarNextPageUrlOrThrow = (+ nextPageUrl: string,+): string => {+ const url = resolveGraphUrlOrThrow(nextPageUrl);+ const { pathname } = new URL(url);++ if (+ pathname !== '/v1.0/me/calendarView' &&+ pathname !== '/v1.0/me/calendarView/'+ ) {+ throw new Error(+ 'Teams calendar pagination URLs must use /v1.0/me/calendarView',+ );+ }++ return url;+};diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/resolve-teams-meeting-window-or-throw.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/resolve-teams-meeting-window-or-throw.tsnew file mode 100644index 00000000000..14c4c66db2f--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/resolve-teams-meeting-window-or-throw.ts@@ -0,0 +1,34 @@+import { isNonEmptyString } from '@sniptt/guards';++import { TEAMS_DEFAULT_LOOKBACK_MILLISECONDS } from 'src/features/transcripts/logic-functions/constants/teams-default-lookback-milliseconds';+import { type TeamsMeetingWindow } from 'src/features/transcripts/logic-functions/types/teams-meeting-window.type';++export const resolveTeamsMeetingWindowOrThrow = ({+ startDateTime,+ endDateTime,+}: {+ startDateTime?: unknown;+ endDateTime?: unknown;+}): TeamsMeetingWindow => {+ const now = Date.now();+ const window = {+ startDateTime: isNonEmptyString(startDateTime)+ ? startDateTime+ : new Date(now - TEAMS_DEFAULT_LOOKBACK_MILLISECONDS).toISOString(),+ endDateTime: isNonEmptyString(endDateTime)+ ? endDateTime+ : new Date(now).toISOString(),+ };+ const startMilliseconds = Date.parse(window.startDateTime);+ const endMilliseconds = Date.parse(window.endDateTime);++ if (+ !Number.isFinite(startMilliseconds) ||+ !Number.isFinite(endMilliseconds) ||+ startMilliseconds >= endMilliseconds+ ) {+ throw new Error('Provide a valid startDateTime before endDateTime');+ }++ return window;+};diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/sleep-for-milliseconds.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/sleep-for-milliseconds.tsnew file mode 100644index 00000000000..ddfad0990e3--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/sleep-for-milliseconds.ts@@ -0,0 +1,2 @@+export const sleepForMilliseconds = (milliseconds: number): Promise<void> =>+ new Promise((resolve) => setTimeout(resolve, milliseconds));diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/to-error-message.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/to-error-message.tsnew file mode 100644index 00000000000..d9fa1691ab6--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/to-error-message.ts@@ -0,0 +1,2 @@+export const toErrorMessage = (error: unknown): string =>+ error instanceof Error ? error.message : String(error);diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/to-teams-meeting-occurrence.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/to-teams-meeting-occurrence.tsnew file mode 100644index 00000000000..d71d7f9fe4a--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/to-teams-meeting-occurrence.ts@@ -0,0 +1,27 @@+import { isNonEmptyString } from '@sniptt/guards';+import { isDefined } from 'twenty-sdk/utils';++import { type TeamsCalendarEvent } from 'src/features/transcripts/logic-functions/types/teams-calendar-event.type';+import { type TeamsMeetingOccurrence } from 'src/features/transcripts/logic-functions/types/teams-meeting-occurrence.type';+import { parseGraphUtcDateTime } from 'src/features/transcripts/logic-functions/utils/parse-graph-utc-date-time';++export const toTeamsMeetingOccurrence = (+ event: TeamsCalendarEvent,+): TeamsMeetingOccurrence | undefined => {+ const joinWebUrl = event.onlineMeeting?.joinUrl;+ const startDateTime = parseGraphUtcDateTime(event.start);+ const endDateTime = parseGraphUtcDateTime(event.end);++ if (+ !event.isOrganizer ||+ event.isCancelled ||+ event.onlineMeetingProvider !== 'teamsForBusiness' ||+ !isNonEmptyString(joinWebUrl) ||+ !isDefined(startDateTime) ||+ !isDefined(endDateTime)+ ) {+ return undefined;+ }++ return { joinWebUrl, startDateTime, endDateTime };+};