Skip to content

The open alternative to Salesforce, designed for AI.

Add an Import history section to the Teams transcripts settings (#27679)

nitin9daa45abd5be
diff --git a/packages/twenty-apps/public/teams/README.md b/packages/twenty-apps/public/teams/README.md
index 78f61b857f1..fae9c98faff 100644
--- a/packages/twenty-apps/public/teams/README.md
+++ b/packages/twenty-apps/public/teams/README.md
@@ -7,6 +7,7 @@
- **A Microsoft connection** for your work or school account
- **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
## 📌 Heads up
diff --git a/packages/twenty-apps/public/teams/SETUP.md b/packages/twenty-apps/public/teams/SETUP.md
index 54cb469a551..586cbf94b5c 100644
--- a/packages/twenty-apps/public/teams/SETUP.md
+++ b/packages/twenty-apps/public/teams/SETUP.md
@@ -65,9 +65,16 @@ account or uninstalling the app deletes the subscription.
Connecting also imports the transcripts of the last 31 days, once per
connection. Reconnecting starts it again only when that import failed or
-stalled. Use the **Sync Teams Transcript** action for older transcripts, and
-for any that Microsoft had not published about two and a half hours after the
-meeting or whose import keeps failing.
+stalled. For older ones, use **Import history** in **Settings > Applications >
+Microsoft Teams > Settings**: count the transcripts of up to the last 365 days
+first, then import them. Only members who can open the app settings see this
+section, and it imports the meetings of a connection they added themselves:
+their personal one, or a workspace-shared one they created. Every member's
+connection still imports its last 31 days when it connects. The import runs in
+the background, newest first, waiting a minute after each calendar page that
+imported transcripts. Use the **Sync Teams Transcript** action for a single
+transcript, such as one that Microsoft had not published about two and a half
+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.
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/front-components/TranscriptImportHistoryCountSummary.tsx b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/TranscriptImportHistoryCountSummary.tsx
new file mode 100644
index 00000000000..974c3e95985
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/TranscriptImportHistoryCountSummary.tsx
@@ -0,0 +1,71 @@
+import { useTranslate } from 'twenty-sdk/front-component';
+
+import { type TeamsTranscriptHistoryView } from 'src/features/transcripts/front-components/types/teams-transcript-history-view.type';
+import { StyledSettingsButton } from 'src/front-components/components/StyledSettingsButton';
+import { StyledSettingsFigureList } from 'src/front-components/components/StyledSettingsFigureList';
+import { StyledSettingsHint } from 'src/front-components/components/StyledSettingsHint';
+import { StyledSettingsText } from 'src/front-components/components/StyledSettingsText';
+
+type TranscriptImportHistoryCountSummaryProps = {
+ view: Extract<TeamsTranscriptHistoryView, { kind: 'counted' }>;
+ isSubmitting: boolean;
+ onImport: () => void;
+};
+
+export const TranscriptImportHistoryCountSummary = ({
+ view,
+ isSubmitting,
+ onImport,
+}: TranscriptImportHistoryCountSummaryProps) => {
+ const { t } = useTranslate();
+
+ return (
+ <>
+ <StyledSettingsText>
+ {t('Last {days} days', { days: view.days })}
+ </StyledSettingsText>
+ <StyledSettingsFigureList>
+ <li>
+ {t('Transcripts found: {transcriptCount}', {
+ transcriptCount: view.transcriptCount,
+ })}
+ </li>
+ <li>
+ {t('Already in Twenty: {alreadyImportedCount}', {
+ alreadyImportedCount: view.alreadyImportedCount,
+ })}
+ </li>
+ <li>
+ {t('Deleted in Twenty: {deletedCount}', {
+ deletedCount: view.deletedCount,
+ })}
+ </li>
+ <li>
+ {t('To import: {toImportCount}', {
+ toImportCount: view.toImportCount,
+ })}
+ </li>
+ </StyledSettingsFigureList>
+ {view.toImportCount > 0 ? (
+ <>
+ <StyledSettingsButton
+ type="button"
+ disabled={isSubmitting}
+ onClick={onImport}
+ >
+ {t('Import transcripts')}
+ </StyledSettingsButton>
+ <StyledSettingsHint>
+ {view.importEstimate.unit === 'minute'
+ ? t('About {minutes} min', {
+ minutes: view.importEstimate.count,
+ })
+ : t('About {hours} h', { hours: view.importEstimate.count })}
+ </StyledSettingsHint>
+ </>
+ ) : (
+ <StyledSettingsText>{t('Nothing new to import.')}</StyledSettingsText>
+ )}
+ </>
+ );
+};
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/front-components/TranscriptImportHistoryProgress.tsx b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/TranscriptImportHistoryProgress.tsx
new file mode 100644
index 00000000000..55365849707
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/TranscriptImportHistoryProgress.tsx
@@ -0,0 +1,61 @@
+import { useTranslate } from 'twenty-sdk/front-component';
+import { isDefined } from 'twenty-sdk/utils';
+
+import { type TeamsTranscriptHistoryView } from 'src/features/transcripts/front-components/types/teams-transcript-history-view.type';
+import { formatTeamsTranscriptHistoryDate } from 'src/features/transcripts/front-components/utils/format-teams-transcript-history-date';
+import { StyledSettingsFigureList } from 'src/front-components/components/StyledSettingsFigureList';
+import { StyledSettingsText } from 'src/front-components/components/StyledSettingsText';
+
+type TranscriptImportHistoryProgressProps = {
+ view: Extract<TeamsTranscriptHistoryView, { kind: 'importing' | 'imported' }>;
+};
+
+export const TranscriptImportHistoryProgress = ({
+ view,
+}: TranscriptImportHistoryProgressProps) => {
+ const { t, locale } = useTranslate();
+
+ const getImportedText = () => {
+ if (isDefined(view.toImportCount)) {
+ return t('Imported {importedCount} of {toImportCount}', {
+ importedCount: view.importedCount,
+ toImportCount: view.toImportCount,
+ });
+ }
+
+ if (isDefined(view.checkedThrough)) {
+ return t('Imported {importedCount}, checked back to {date}', {
+ importedCount: view.importedCount,
+ date: formatTeamsTranscriptHistoryDate({
+ date: view.checkedThrough,
+ locale,
+ }),
+ });
+ }
+
+ return t('Imported {importedCount}', { importedCount: view.importedCount });
+ };
+
+ return (
+ <>
+ <StyledSettingsText>
+ {view.kind === 'importing'
+ ? t('Importing transcripts...')
+ : t('Import finished.')}
+ </StyledSettingsText>
+ <StyledSettingsFigureList>
+ <li>{getImportedText()}</li>
+ <li>
+ {t('Already in Twenty or deleted: {skippedCount}', {
+ skippedCount: view.skippedCount,
+ })}
+ </li>
+ <li>
+ {t('Not available from Microsoft: {unavailableCount}', {
+ unavailableCount: view.unavailableCount,
+ })}
+ </li>
+ </StyledSettingsFigureList>
+ </>
+ );
+};
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/front-components/TranscriptImportHistorySection.tsx b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/TranscriptImportHistorySection.tsx
new file mode 100644
index 00000000000..f4f123d6fca
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/TranscriptImportHistorySection.tsx
@@ -0,0 +1,301 @@
+import styled from '@emotion/styled';
+import { type FormEvent, useId, useRef, useState } from 'react';
+import { enqueueSnackbar, useTranslate } from 'twenty-sdk/front-component';
+import { isDefined } from 'twenty-sdk/utils';
+import { themeCssVariables } from 'twenty-ui/theme';
+
+import { TEAMS_TRANSCRIPT_HISTORY_COUNT_ROUTE_PATH } from 'src/features/transcripts/constants/teams-transcript-history-count-route-path';
+import { TEAMS_TRANSCRIPT_HISTORY_IMPORT_ROUTE_PATH } from 'src/features/transcripts/constants/teams-transcript-history-import-route-path';
+import { TEAMS_TRANSCRIPT_HISTORY_INITIAL_IMPORT_DAYS } from 'src/features/transcripts/constants/teams-transcript-history-initial-import-days';
+import { TEAMS_TRANSCRIPT_HISTORY_MAX_DAYS } from 'src/features/transcripts/constants/teams-transcript-history-max-days';
+import { TEAMS_TRANSCRIPT_HISTORY_STATUS_ROUTE_PATH } from 'src/features/transcripts/constants/teams-transcript-history-status-route-path';
+import { TranscriptImportHistoryCountSummary } from 'src/features/transcripts/front-components/TranscriptImportHistoryCountSummary';
+import { TranscriptImportHistoryProgress } from 'src/features/transcripts/front-components/TranscriptImportHistoryProgress';
+import { TEAMS_TRANSCRIPT_HISTORY_DEFAULT_DAYS } from 'src/features/transcripts/front-components/constants/teams-transcript-history-default-days';
+import { type TeamsTranscriptHistoryRouteRequest } from 'src/features/transcripts/front-components/types/teams-transcript-history-route-request.type';
+import { type TeamsTranscriptHistoryView } from 'src/features/transcripts/front-components/types/teams-transcript-history-view.type';
+import { formatTeamsTranscriptHistoryDate } from 'src/features/transcripts/front-components/utils/format-teams-transcript-history-date';
+import { getTeamsTranscriptHistoryFailureMessage } from 'src/features/transcripts/front-components/utils/get-teams-transcript-history-failure-message';
+import { getTeamsTranscriptHistoryPollDelayMilliseconds } from 'src/features/transcripts/front-components/utils/get-teams-transcript-history-poll-delay-milliseconds';
+import { getTeamsTranscriptHistoryRouteErrorMessage } from 'src/features/transcripts/front-components/utils/get-teams-transcript-history-route-error-message';
+import { getTeamsTranscriptHistoryView } from 'src/features/transcripts/front-components/utils/get-teams-transcript-history-view';
+import { parseTeamsTranscriptHistoryDays } from 'src/features/transcripts/front-components/utils/parse-teams-transcript-history-days';
+import { postTeamsTranscriptHistoryRouteOrThrow } from 'src/features/transcripts/front-components/utils/post-teams-transcript-history-route-or-throw';
+import { type TeamsTranscriptHistoryRouteErrorCode } from 'src/features/transcripts/logic-functions/types/teams-transcript-history-route-error-code.type';
+import { StyledSettingsButton } from 'src/front-components/components/StyledSettingsButton';
+import { StyledSettingsHint } from 'src/front-components/components/StyledSettingsHint';
+import { StyledSettingsText } from 'src/front-components/components/StyledSettingsText';
+import { TimeoutEffect } from 'src/front-components/components/TimeoutEffect';
+
+const StyledSection = styled.section`
+ color: ${() => themeCssVariables.font.color.primary};
+ display: flex;
+ flex-direction: column;
+ font-family: ${() => themeCssVariables.font.family};
+ font-size: ${() => themeCssVariables.font.size.md};
+ gap: ${() => themeCssVariables.spacing[3]};
+`;
+
+const StyledTitle = styled.h2`
+ font-size: ${() => themeCssVariables.font.size.lg};
+ font-weight: ${() => themeCssVariables.font.weight.medium};
+ margin: 0;
+`;
+
+const StyledControl = styled.form`
+ align-items: center;
+ background: ${() => themeCssVariables.background.secondary};
+ border: 1px solid ${() => themeCssVariables.border.color.medium};
+ border-radius: ${() => themeCssVariables.border.radius.md};
+ display: flex;
+ gap: ${() => themeCssVariables.spacing[2]};
+ padding: ${() => themeCssVariables.spacing[4]};
+`;
+
+const StyledDaysInput = styled.input`
+ background: ${() => themeCssVariables.background.primary};
+ border: 1px solid ${() => themeCssVariables.border.color.medium};
+ border-radius: ${() => themeCssVariables.border.radius.sm};
+ color: inherit;
+ font: inherit;
+ padding: ${() => themeCssVariables.spacing[1]}
+ ${() => themeCssVariables.spacing[2]};
+ width: ${() => themeCssVariables.spacing[16]};
+`;
+
+export const TranscriptImportHistorySection = () => {
+ const { t, locale } = useTranslate();
+ const titleId = useId();
+ const daysInputId = useId();
+ const [daysDraft, setDaysDraft] = useState(
+ String(TEAMS_TRANSCRIPT_HISTORY_DEFAULT_DAYS),
+ );
+ const [view, setView] = useState<TeamsTranscriptHistoryView | undefined>();
+ const [loadErrorCode, setLoadErrorCode] = useState<
+ TeamsTranscriptHistoryRouteErrorCode | undefined
+ >();
+ const [isSubmitting, setIsSubmitting] = useState(false);
+ const [pollCount, setPollCount] = useState(0);
+ const latestRequestIdRef = useRef(0);
+
+ const days = parseTeamsTranscriptHistoryDays(daysDraft);
+ const hasLoadError = isDefined(loadErrorCode);
+ const isCounting = view?.kind === 'counting';
+ const isImporting = view?.kind === 'importing';
+ const pollDelayMilliseconds = getTeamsTranscriptHistoryPollDelayMilliseconds({
+ view,
+ loadErrorCode,
+ });
+
+ // A status reply that left before a later request must not overwrite what that request returned.
+ const startRequest = () => {
+ latestRequestIdRef.current += 1;
+
+ return latestRequestIdRef.current;
+ };
+
+ const isLatestRequest = (requestId: number) =>
+ requestId === latestRequestIdRef.current;
+
+ const loadHistory = async () => {
+ const requestId = startRequest();
+
+ try {
+ const result = await postTeamsTranscriptHistoryRouteOrThrow({
+ routePath: TEAMS_TRANSCRIPT_HISTORY_STATUS_ROUTE_PATH,
+ body: {},
+ });
+
+ if (!isLatestRequest(requestId)) {
+ return;
+ }
+
+ if (result.success) {
+ setView(getTeamsTranscriptHistoryView(result));
+ setLoadErrorCode(undefined);
+ } else {
+ setLoadErrorCode(result.errorCode);
+ }
+ } catch {
+ if (isLatestRequest(requestId)) {
+ setLoadErrorCode('unknown');
+ }
+ } finally {
+ setPollCount((previousPollCount) => previousPollCount + 1);
+ }
+ };
+
+ const startHistoryRun = async ({
+ request,
+ unknownErrorMessage,
+ }: {
+ request: TeamsTranscriptHistoryRouteRequest;
+ unknownErrorMessage: string;
+ }) => {
+ if (isSubmitting) {
+ return;
+ }
+
+ setIsSubmitting(true);
+
+ const requestId = startRequest();
+
+ try {
+ const result = await postTeamsTranscriptHistoryRouteOrThrow(request);
+
+ if (result.success) {
+ if (isLatestRequest(requestId)) {
+ setView(getTeamsTranscriptHistoryView(result));
+ setLoadErrorCode(undefined);
+ }
+ } else {
+ enqueueSnackbar({
+ message: getTeamsTranscriptHistoryRouteErrorMessage({
+ errorCode: result.errorCode,
+ unknownErrorMessage,
+ }),
+ variant: 'error',
+ });
+ await loadHistory();
+ }
+ } catch {
+ enqueueSnackbar({ message: unknownErrorMessage, variant: 'error' });
+ await loadHistory();
+ } finally {
+ setIsSubmitting(false);
+ }
+ };
+
+ const handleHistoryRefresh = () => {
+ void loadHistory();
+ };
+
+ const handleCountSubmit = (event: FormEvent<HTMLFormElement>) => {
+ event.preventDefault();
+
+ if (isDefined(days)) {
+ void startHistoryRun({
+ request: {
+ routePath: TEAMS_TRANSCRIPT_HISTORY_COUNT_ROUTE_PATH,
+ body: { days },
+ },
+ unknownErrorMessage: t('Could not start counting.'),
+ });
+ }
+ };
+
+ const handleImportClick = (runId: string) => {
+ void startHistoryRun({
+ request: {
+ routePath: TEAMS_TRANSCRIPT_HISTORY_IMPORT_ROUTE_PATH,
+ body: { runId },
+ },
+ unknownErrorMessage: t('Could not start the import.'),
+ });
+ };
+
+ return (
+ <StyledSection aria-labelledby={titleId}>
+ {isDefined(pollDelayMilliseconds) && (
+ <TimeoutEffect
+ key={pollCount}
+ delayMilliseconds={pollDelayMilliseconds}
+ onTimeout={handleHistoryRefresh}
+ />
+ )}
+ <StyledTitle id={titleId}>{t('Import history')}</StyledTitle>
+ <StyledSettingsText>
+ {t(
+ 'Import the transcripts of your past Teams meetings into Call Recordings. Recordings deleted in Twenty stay deleted.',
+ )}
+ </StyledSettingsText>
+ {hasLoadError && (
+ <>
+ <p role="alert">
+ {getTeamsTranscriptHistoryRouteErrorMessage({
+ errorCode: loadErrorCode,
+ unknownErrorMessage: t('Could not load the import history.'),
+ })}
+ </p>
+ <StyledSettingsButton type="button" onClick={handleHistoryRefresh}>
+ {t('Retry')}
+ </StyledSettingsButton>
+ </>
+ )}
+ {view?.kind === 'stalled' && (
+ <p role="alert">
+ {t('The last run stopped before finishing. Count again to retry.')}
+ </p>
+ )}
+ {view?.kind === 'failed' && (
+ <p role="alert">
+ {getTeamsTranscriptHistoryFailureMessage(view.errorCode)}
+ </p>
+ )}
+ {view?.kind === 'counting' && (
+ <StyledSettingsText>
+ {isDefined(view.checkedThrough)
+ ? t('Counting transcripts... checked back to {date}', {
+ date: formatTeamsTranscriptHistoryDate({
+ date: view.checkedThrough,
+ locale,
+ }),
+ })
+ : t('Counting transcripts...')}
+ </StyledSettingsText>
+ )}
+ {(view?.kind === 'importing' || view?.kind === 'imported') && (
+ <TranscriptImportHistoryProgress view={view} />
+ )}
+ {view?.kind === 'counted' && (
+ <TranscriptImportHistoryCountSummary
+ view={view}
+ isSubmitting={isSubmitting}
+ onImport={() => handleImportClick(view.runId)}
+ />
+ )}
+ {!isImporting && (
+ <>
+ <StyledControl onSubmit={handleCountSubmit}>
+ <StyledDaysInput
+ id={daysInputId}
+ type="number"
+ min={1}
+ max={TEAMS_TRANSCRIPT_HISTORY_MAX_DAYS}
+ step={1}
+ aria-label={t('Days to count')}
+ value={daysDraft}
+ disabled={!isDefined(view) || isCounting || isSubmitting}
+ onChange={(event) => setDaysDraft(event.target.value)}
+ />
+ <label htmlFor={daysInputId}>{t('days')}</label>
+ <StyledSettingsButton
+ type="submit"
+ aria-busy={isCounting || isSubmitting}
+ disabled={
+ !isDefined(view) ||
+ !isDefined(days) ||
+ isCounting ||
+ isSubmitting
+ }
+ >
+ {t('Count transcripts')}
+ </StyledSettingsButton>
+ </StyledControl>
+ {!isDefined(days) && (
+ <p role="alert">
+ {t('Enter a whole number of days between 1 and {maxDays}.', {
+ maxDays: TEAMS_TRANSCRIPT_HISTORY_MAX_DAYS,
+ })}
+ </p>
+ )}
+ <StyledSettingsHint>
+ {t('Connecting imports the last {days} days.', {
+ days: TEAMS_TRANSCRIPT_HISTORY_INITIAL_IMPORT_DAYS,
+ })}
+ </StyledSettingsHint>
+ </>
+ )}
+ </StyledSection>
+ );
+};
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/front-components/TranscriptSettings.tsx b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/TranscriptSettings.tsx
index 5b67cd6274e..457fae2c0e7 100644
--- a/packages/twenty-apps/public/teams/src/features/transcripts/front-components/TranscriptSettings.tsx
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/TranscriptSettings.tsx
@@ -2,6 +2,7 @@ import { useTranslate } from 'twenty-sdk/front-component';
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 { TranscriptImportHistorySection } from 'src/features/transcripts/front-components/TranscriptImportHistorySection';
import { FeatureSettingsSection } from 'src/front-components/components/FeatureSettingsSection';
import { useFeatureSetting } from 'src/front-components/hooks/use-feature-setting';
import { isFeatureEnabled } from 'src/utils/is-feature-enabled';
@@ -13,26 +14,30 @@ export const TranscriptSettings = () => {
variableKey: TRANSCRIPTS_ENABLED_APPLICATION_VARIABLE_KEY,
isAvailable: FEATURE_FLAGS.IS_TRANSCRIPT_IMPORT_ENABLED,
});
+ const isTranscriptImportEnabled = isFeatureEnabled({
+ isAvailable: FEATURE_FLAGS.IS_TRANSCRIPT_IMPORT_ENABLED,
+ settingValue,
+ });
const handleChange = (isEnabled: boolean) => {
void updateSetting(isEnabled);
};
return (
- <FeatureSettingsSection
- title={t('Transcripts')}
- label={t('Enable transcripts')}
- description={t(
- 'Import Microsoft Teams meeting transcripts into this workspace.',
- )}
- isAvailable={FEATURE_FLAGS.IS_TRANSCRIPT_IMPORT_ENABLED}
- isEnabled={isFeatureEnabled({
- isAvailable: FEATURE_FLAGS.IS_TRANSCRIPT_IMPORT_ENABLED,
- settingValue,
- })}
- isSaving={isSaving}
- hasSaveError={hasSaveError}
- onChange={handleChange}
- />
+ <>
+ <FeatureSettingsSection
+ title={t('Transcripts')}
+ label={t('Enable transcripts')}
+ description={t(
+ 'Import Microsoft Teams meeting transcripts into this workspace.',
+ )}
+ isAvailable={FEATURE_FLAGS.IS_TRANSCRIPT_IMPORT_ENABLED}
+ isEnabled={isTranscriptImportEnabled}
+ isSaving={isSaving}
+ hasSaveError={hasSaveError}
+ onChange={handleChange}
+ />
+ {isTranscriptImportEnabled && <TranscriptImportHistorySection />}
+ </>
);
};
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/front-components/__tests__/TranscriptImportHistorySection.test.tsx b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/__tests__/TranscriptImportHistorySection.test.tsx
new file mode 100644
index 00000000000..253e0752f3b
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/__tests__/TranscriptImportHistorySection.test.tsx
@@ -0,0 +1,263 @@
+// @vitest-environment jsdom
+
+import { act, cleanup, render, screen } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { TranscriptImportHistorySection } from 'src/features/transcripts/front-components/TranscriptImportHistorySection';
+
+const { postMock, enqueueSnackbarMock, translate } = vi.hoisted(() => ({
+ postMock: vi.fn(),
+ enqueueSnackbarMock: vi.fn(),
+ translate: (message: string, values?: Record<string, unknown>) =>
+ message.replace(/\{(\w+)\}/g, (_, key: string) => String(values?.[key])),
+}));
+
+vi.mock('twenty-sdk/front-component', () => ({
+ useTranslate: () => ({ t: translate, locale: 'en' }),
+ t: translate,
+ enqueueSnackbar: enqueueSnackbarMock,
+}));
+
+vi.mock('twenty-client-sdk/rest', () => ({
+ RestApiClient: class {
+ post = postMock;
+ },
+}));
+
+const BASE_STATE = {
+ runId: 'run-1',
+ days: 90,
+ windowStart: '2026-06-17T00:00:00.000Z',
+ windowEnd: '2026-09-15T00:00:00.000Z',
+ transcriptCount: 0,
+ alreadyImportedCount: 0,
+ deletedCount: 0,
+ pageCount: 0,
+ importedCount: 0,
+ skippedCount: 0,
+ unavailableCount: 0,
+ updatedAt: '2026-09-15T00:00:00.000Z',
+};
+
+const COUNTED_STATE = {
+ ...BASE_STATE,
+ phase: 'counted',
+ transcriptCount: 40,
+ alreadyImportedCount: 12,
+ deletedCount: 3,
+ pageCount: 7,
+};
+
+const toSuccess = (state: unknown) => ({
+ success: true,
+ state,
+ isStalled: false,
+});
+
+const countCalls = (routeSuffix: string) =>
+ postMock.mock.calls.filter(([path]) => path.endsWith(routeSuffix)).length;
+
+const advanceTime = async (milliseconds = 0) => {
+ let remainingMilliseconds = milliseconds;
+
+ do {
+ const stepMilliseconds = Math.min(500, remainingMilliseconds);
+
+ await act(async () => {
+ await vi.advanceTimersByTimeAsync(stepMilliseconds);
+ });
+ remainingMilliseconds -= stepMilliseconds;
+ } while (remainingMilliseconds > 0);
+};
+
+const getCountButton = () =>
+ screen.getByRole('button', { name: 'Count transcripts' });
+
+describe('TranscriptImportHistorySection', () => {
+ beforeEach(() => {
+ vi.useFakeTimers({ shouldAdvanceTime: true });
+ postMock.mockReset();
+ enqueueSnackbarMock.mockReset();
+ });
+
+ afterEach(() => {
+ cleanup();
+ vi.useRealTimers();
+ });
+
+ it('should count the transcripts, then import them once', async () => {
+ const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime });
+
+ postMock.mockImplementation(async (path: string) => {
+ if (path.endsWith('/count')) {
+ return toSuccess({ ...BASE_STATE, phase: 'counting' });
+ }
+
+ if (path.endsWith('/import')) {
+ return toSuccess({ ...COUNTED_STATE, phase: 'importing' });
+ }
+
+ return countCalls('/status') === 1
+ ? toSuccess(null)
+ : toSuccess(COUNTED_STATE);
+ });
+
+ render(<TranscriptImportHistorySection />);
+ await advanceTime();
+ await user.click(getCountButton());
+ await advanceTime();
+
+ expect(screen.getByText('Counting transcripts...')).toBeTruthy();
+
+ await advanceTime(5_000);
+
+ expect(screen.getByText('To import: 25')).toBeTruthy();
+
+ await user.dblClick(
+ screen.getByRole('button', { name: 'Import transcripts' }),
+ );
+ await advanceTime();
+
+ expect(countCalls('/import')).toBe(1);
+ expect(screen.getByText('Imported 0 of 25')).toBeTruthy();
+ });
+
+ it('should stop polling and offer Retry when the connection is gone', async () => {
+ const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime });
+
+ postMock.mockImplementation(async () =>
+ countCalls('/status') === 1
+ ? toSuccess({ ...BASE_STATE, phase: 'counting' })
+ : { success: false, errorCode: 'not-connected' },
+ );
+
+ render(<TranscriptImportHistorySection />);
+ await advanceTime();
+ await advanceTime(10 * 60_000);
+
+ expect(countCalls('/status')).toBe(2);
+ expect(
+ screen.getByText(
+ 'Add your own Microsoft Teams connection to import its history.',
+ ),
+ ).toBeTruthy();
+
+ postMock.mockResolvedValue(toSuccess(COUNTED_STATE));
+ await user.click(screen.getByRole('button', { name: 'Retry' }));
+ await advanceTime();
+
+ expect(screen.getByText('To import: 25')).toBeTruthy();
+ expect(screen.queryByRole('button', { name: 'Retry' })).toBeNull();
+ });
+
+ it('should keep polling a running import through an unexpected failure without offering a count', async () => {
+ postMock.mockImplementation(async () =>
+ countCalls('/status') === 2
+ ? { success: false, errorCode: 'unknown' }
+ : toSuccess({ ...COUNTED_STATE, phase: 'importing' }),
+ );
+
+ render(<TranscriptImportHistorySection />);
+ await advanceTime();
+ await advanceTime(30_000);
+
+ expect(screen.getByRole('button', { name: 'Retry' })).toBeTruthy();
+ expect(
+ screen.queryByRole('button', { name: 'Count transcripts' }),
+ ).toBeNull();
+
+ await advanceTime(30_000);
+
+ expect(countCalls('/status')).toBe(3);
+ expect(screen.queryByRole('button', { name: 'Retry' })).toBeNull();
+ expect(screen.getByText('Importing transcripts...')).toBeTruthy();
+ });
+
+ it('should ignore a status reply sent before a count started', async () => {
+ const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime });
+ const countingState = {
+ ...BASE_STATE,
+ runId: 'run-2',
+ days: 30,
+ phase: 'counting',
+ };
+ let resolveLateStatus: (value: unknown) => void = () => undefined;
+
+ postMock.mockImplementation(async (path: string) => {
+ if (path.endsWith('/count')) {
+ return toSuccess(countingState);
+ }
+
+ if (path.endsWith('/import')) {
+ return { success: false, errorCode: 'unknown' };
+ }
+
+ switch (countCalls('/status')) {
+ case 1:
+ return toSuccess(COUNTED_STATE);
+ case 2:
+ return { success: false, errorCode: 'unknown' };
+ case 3:
+ return new Promise((resolve) => {
+ resolveLateStatus = resolve;
+ });
+ default:
+ return toSuccess(countingState);
+ }
+ });
+
+ render(<TranscriptImportHistorySection />);
+ await advanceTime();
+ await user.click(
+ screen.getByRole('button', { name: 'Import transcripts' }),
+ );
+ await advanceTime();
+ await user.click(screen.getByRole('button', { name: 'Retry' }));
+ await advanceTime();
+
+ const daysInput = screen.getByRole('spinbutton', { name: 'Days to count' });
+
+ await user.clear(daysInput);
+ await user.type(daysInput, '30');
+ await user.click(getCountButton());
+ await advanceTime();
+ await act(async () => {
+ resolveLateStatus(toSuccess(COUNTED_STATE));
+ });
+ await advanceTime();
+
+ expect(screen.getByText('Counting transcripts...')).toBeTruthy();
+ expect(screen.queryByText('Last 90 days')).toBeNull();
+
+ await advanceTime(5_000);
+
+ expect(countCalls('/status')).toBe(4);
+ });
+
+ it('should only count a whole number of days between 1 and 365', async () => {
+ const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime });
+
+ postMock.mockResolvedValue(toSuccess(null));
+
+ render(<TranscriptImportHistorySection />);
+ await advanceTime();
+
+ const daysInput = screen.getByRole('spinbutton', { name: 'Days to count' });
+
+ for (const days of ['', '0', '366', '1.5']) {
+ await user.clear(daysInput);
+
+ if (days !== '') {
+ await user.type(daysInput, days);
+ }
+
+ expect(getCountButton().hasAttribute('disabled')).toBe(true);
+ }
+
+ await user.clear(daysInput);
+ await user.type(daysInput, '365');
+
+ expect(getCountButton().hasAttribute('disabled')).toBe(false);
+ });
+});
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/front-components/constants/milliseconds-per-minute.ts b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/constants/milliseconds-per-minute.ts
new file mode 100644
index 00000000000..47fce3a26ac
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/constants/milliseconds-per-minute.ts
@@ -0,0 +1 @@
+export const MILLISECONDS_PER_MINUTE = 60 * 1_000;
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/front-components/constants/minutes-per-hour.ts b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/constants/minutes-per-hour.ts
new file mode 100644
index 00000000000..39386b3ebbd
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/constants/minutes-per-hour.ts
@@ -0,0 +1 @@
+export const MINUTES_PER_HOUR = 60;
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/front-components/constants/teams-transcript-history-counting-poll-milliseconds.ts b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/constants/teams-transcript-history-counting-poll-milliseconds.ts
new file mode 100644
index 00000000000..2e192b9f7e4
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/constants/teams-transcript-history-counting-poll-milliseconds.ts
@@ -0,0 +1 @@
+export const TEAMS_TRANSCRIPT_HISTORY_COUNTING_POLL_MILLISECONDS = 5_000;
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/front-components/constants/teams-transcript-history-default-days.ts b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/constants/teams-transcript-history-default-days.ts
new file mode 100644
index 00000000000..23d57916572
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/constants/teams-transcript-history-default-days.ts
@@ -0,0 +1 @@
+export const TEAMS_TRANSCRIPT_HISTORY_DEFAULT_DAYS = 90;
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/front-components/constants/teams-transcript-history-importing-poll-milliseconds.ts b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/constants/teams-transcript-history-importing-poll-milliseconds.ts
new file mode 100644
index 00000000000..9ac65769ffe
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/constants/teams-transcript-history-importing-poll-milliseconds.ts
@@ -0,0 +1 @@
+export const TEAMS_TRANSCRIPT_HISTORY_IMPORTING_POLL_MILLISECONDS = 30_000;
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/front-components/types/teams-transcript-history-import-estimate.type.ts b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/types/teams-transcript-history-import-estimate.type.ts
new file mode 100644
index 00000000000..a4e49f00e0c
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/types/teams-transcript-history-import-estimate.type.ts
@@ -0,0 +1,4 @@
+export type TeamsTranscriptHistoryImportEstimate = {
+ unit: 'minute' | 'hour';
+ count: number;
+};
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/front-components/types/teams-transcript-history-route-request.type.ts b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/types/teams-transcript-history-route-request.type.ts
new file mode 100644
index 00000000000..0d855388633
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/types/teams-transcript-history-route-request.type.ts
@@ -0,0 +1,17 @@
+import { type TEAMS_TRANSCRIPT_HISTORY_COUNT_ROUTE_PATH } from 'src/features/transcripts/constants/teams-transcript-history-count-route-path';
+import { type TEAMS_TRANSCRIPT_HISTORY_IMPORT_ROUTE_PATH } from 'src/features/transcripts/constants/teams-transcript-history-import-route-path';
+import { type TEAMS_TRANSCRIPT_HISTORY_STATUS_ROUTE_PATH } from 'src/features/transcripts/constants/teams-transcript-history-status-route-path';
+
+export type TeamsTranscriptHistoryRouteRequest =
+ | {
+ routePath: typeof TEAMS_TRANSCRIPT_HISTORY_STATUS_ROUTE_PATH;
+ body: Record<string, never>;
+ }
+ | {
+ routePath: typeof TEAMS_TRANSCRIPT_HISTORY_COUNT_ROUTE_PATH;
+ body: { days: number };
+ }
+ | {
+ routePath: typeof TEAMS_TRANSCRIPT_HISTORY_IMPORT_ROUTE_PATH;
+ body: { runId: string };
+ };
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/front-components/types/teams-transcript-history-view.type.ts b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/types/teams-transcript-history-view.type.ts
new file mode 100644
index 00000000000..34c24c5dc97
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/types/teams-transcript-history-view.type.ts
@@ -0,0 +1,26 @@
+import { type TeamsTranscriptHistoryImportEstimate } from 'src/features/transcripts/front-components/types/teams-transcript-history-import-estimate.type';
+import { type TeamsTranscriptHistoryErrorCode } from 'src/features/transcripts/logic-functions/types/teams-transcript-history-error-code.type';
+
+export type TeamsTranscriptHistoryView =
+ | { kind: 'idle' }
+ | { kind: 'stalled' }
+ | { kind: 'failed'; errorCode: TeamsTranscriptHistoryErrorCode }
+ | { kind: 'counting'; checkedThrough?: string }
+ | {
+ kind: 'counted';
+ runId: string;
+ days: number;
+ transcriptCount: number;
+ alreadyImportedCount: number;
+ deletedCount: number;
+ toImportCount: number;
+ importEstimate: TeamsTranscriptHistoryImportEstimate;
+ }
+ | {
+ kind: 'importing' | 'imported';
+ importedCount: number;
+ skippedCount: number;
+ unavailableCount: number;
+ toImportCount?: number;
+ checkedThrough?: string;
+ };
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/__tests__/get-teams-transcript-history-poll-delay-milliseconds.test.ts b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/__tests__/get-teams-transcript-history-poll-delay-milliseconds.test.ts
new file mode 100644
index 00000000000..5f8c1af8639
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/__tests__/get-teams-transcript-history-poll-delay-milliseconds.test.ts
@@ -0,0 +1,75 @@
+import { describe, expect, it } from 'vitest';
+
+import { TEAMS_TRANSCRIPT_HISTORY_COUNTING_POLL_MILLISECONDS } from 'src/features/transcripts/front-components/constants/teams-transcript-history-counting-poll-milliseconds';
+import { TEAMS_TRANSCRIPT_HISTORY_IMPORTING_POLL_MILLISECONDS } from 'src/features/transcripts/front-components/constants/teams-transcript-history-importing-poll-milliseconds';
+import { getTeamsTranscriptHistoryPollDelayMilliseconds } from 'src/features/transcripts/front-components/utils/get-teams-transcript-history-poll-delay-milliseconds';
+
+const IMPORTING_VIEW = {
+ kind: 'importing' as const,
+ importedCount: 0,
+ skippedCount: 0,
+ unavailableCount: 0,
+};
+
+describe('getTeamsTranscriptHistoryPollDelayMilliseconds', () => {
+ it('should load the status right away until the first load fails', () => {
+ expect(
+ getTeamsTranscriptHistoryPollDelayMilliseconds({
+ view: undefined,
+ loadErrorCode: undefined,
+ }),
+ ).toBe(0);
+ expect(
+ getTeamsTranscriptHistoryPollDelayMilliseconds({
+ view: undefined,
+ loadErrorCode: 'unknown',
+ }),
+ ).toBeUndefined();
+ });
+
+ it('should keep polling a running count or import through an unexpected failure', () => {
+ expect(
+ getTeamsTranscriptHistoryPollDelayMilliseconds({
+ view: { kind: 'counting' },
+ loadErrorCode: 'unknown',
+ }),
+ ).toBe(TEAMS_TRANSCRIPT_HISTORY_COUNTING_POLL_MILLISECONDS);
+ expect(
+ getTeamsTranscriptHistoryPollDelayMilliseconds({
+ view: IMPORTING_VIEW,
+ loadErrorCode: undefined,
+ }),
+ ).toBe(TEAMS_TRANSCRIPT_HISTORY_IMPORTING_POLL_MILLISECONDS);
+ });
+
+ it.each([
+ 'not-connected',
+ 'reconnect-required',
+ 'transcripts-not-enabled',
+ ] as const)(
+ 'should stop polling a running import after a %s failure',
+ (loadErrorCode) => {
+ expect(
+ getTeamsTranscriptHistoryPollDelayMilliseconds({
+ view: IMPORTING_VIEW,
+ loadErrorCode,
+ }),
+ ).toBeUndefined();
+ },
+ );
+
+ it('should stop polling once nothing is running', () => {
+ expect(
+ getTeamsTranscriptHistoryPollDelayMilliseconds({
+ view: { kind: 'idle' },
+ loadErrorCode: undefined,
+ }),
+ ).toBeUndefined();
+ expect(
+ getTeamsTranscriptHistoryPollDelayMilliseconds({
+ view: { kind: 'stalled' },
+ loadErrorCode: undefined,
+ }),
+ ).toBeUndefined();
+ });
+});
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/__tests__/get-teams-transcript-history-view.test.ts b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/__tests__/get-teams-transcript-history-view.test.ts
new file mode 100644
index 00000000000..578bd08365b
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/__tests__/get-teams-transcript-history-view.test.ts
@@ -0,0 +1,155 @@
+import { describe, expect, it } from 'vitest';
+
+import { getTeamsTranscriptHistoryView } from 'src/features/transcripts/front-components/utils/get-teams-transcript-history-view';
+
+const STATE = {
+ runId: 'a1b2c3d4e5f60718',
+ days: 90,
+ windowStart: '2026-06-17T00:00:00.000Z',
+ windowEnd: '2026-09-15T00:00:00.000Z',
+ transcriptCount: 0,
+ alreadyImportedCount: 0,
+ deletedCount: 0,
+ pageCount: 0,
+ importedCount: 0,
+ skippedCount: 0,
+ unavailableCount: 0,
+ updatedAt: '2026-09-15T00:00:00.000Z',
+};
+
+describe('getTeamsTranscriptHistoryView', () => {
+ it('should be idle without a run and stalled when the run stopped progressing', () => {
+ expect(
+ getTeamsTranscriptHistoryView({ state: null, isStalled: false }),
+ ).toEqual({ kind: 'idle' });
+ expect(
+ getTeamsTranscriptHistoryView({
+ state: { ...STATE, phase: 'importing' },
+ isStalled: true,
+ }),
+ ).toEqual({ kind: 'stalled' });
+ });
+
+ it('should count the transcripts left to import over the counted window', () => {
+ expect(
+ getTeamsTranscriptHistoryView({
+ state: {
+ ...STATE,
+ phase: 'counted',
+ transcriptCount: 40,
+ alreadyImportedCount: 12,
+ deletedCount: 3,
+ pageCount: 7,
+ },
+ isStalled: false,
+ }),
+ ).toEqual({
+ kind: 'counted',
+ runId: STATE.runId,
+ days: 90,
+ transcriptCount: 40,
+ alreadyImportedCount: 12,
+ deletedCount: 3,
+ toImportCount: 25,
+ importEstimate: { unit: 'minute', count: 7 },
+ });
+ });
+
+ it('should estimate at least one minute and switch to whole hours from 60 minutes', () => {
+ expect(
+ getTeamsTranscriptHistoryView({
+ state: { ...STATE, phase: 'counted' },
+ isStalled: false,
+ }),
+ ).toMatchObject({
+ toImportCount: 0,
+ importEstimate: { unit: 'minute', count: 1 },
+ });
+ expect(
+ getTeamsTranscriptHistoryView({
+ state: { ...STATE, phase: 'counted', pageCount: 59 },
+ isStalled: false,
+ }),
+ ).toMatchObject({ importEstimate: { unit: 'minute', count: 59 } });
+ expect(
+ getTeamsTranscriptHistoryView({
+ state: { ...STATE, phase: 'counted', pageCount: 61 },
+ isStalled: false,
+ }),
+ ).toMatchObject({ importEstimate: { unit: 'hour', count: 2 } });
+ });
+
+ it('should report the count progress while counting', () => {
+ expect(
+ getTeamsTranscriptHistoryView({
+ state: {
+ ...STATE,
+ phase: 'counting',
+ checkedThrough: '2026-08-15T00:00:00.000Z',
+ },
+ isStalled: false,
+ }),
+ ).toEqual({ kind: 'counting', checkedThrough: '2026-08-15T00:00:00.000Z' });
+ });
+
+ it('should compare the import progress to the count when the run was counted', () => {
+ expect(
+ getTeamsTranscriptHistoryView({
+ state: {
+ ...STATE,
+ phase: 'importing',
+ transcriptCount: 40,
+ alreadyImportedCount: 12,
+ deletedCount: 3,
+ importedCount: 10,
+ skippedCount: 4,
+ unavailableCount: 1,
+ },
+ isStalled: false,
+ }),
+ ).toEqual({
+ kind: 'importing',
+ importedCount: 10,
+ skippedCount: 4,
+ unavailableCount: 1,
+ toImportCount: 25,
+ });
+ });
+
+ it('should report how far back the import on connect checked, which has no count', () => {
+ expect(
+ getTeamsTranscriptHistoryView({
+ state: {
+ ...STATE,
+ phase: 'imported',
+ importedCount: 25,
+ skippedCount: 4,
+ unavailableCount: 1,
+ checkedThrough: '2026-08-15T00:00:00.000Z',
+ },
+ isStalled: false,
+ }),
+ ).toEqual({
+ kind: 'imported',
+ importedCount: 25,
+ skippedCount: 4,
+ unavailableCount: 1,
+ checkedThrough: '2026-08-15T00:00:00.000Z',
+ });
+ });
+
+ it('should keep the failure code and treat a missing one as unknown', () => {
+ expect(
+ getTeamsTranscriptHistoryView({
+ state: { ...STATE, phase: 'failed', errorCode: 'reconnect-required' },
+ isStalled: false,
+ }),
+ ).toEqual({ kind: 'failed', errorCode: 'reconnect-required' });
+ expect(
+ getTeamsTranscriptHistoryView({
+ state: { ...STATE, phase: 'failed' },
+ isStalled: false,
+ }),
+ ).toEqual({ kind: 'failed', errorCode: 'unknown' });
+ });
+});
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/__tests__/parse-teams-transcript-history-days.test.ts b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/__tests__/parse-teams-transcript-history-days.test.ts
new file mode 100644
index 00000000000..f6fd6431f9b
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/__tests__/parse-teams-transcript-history-days.test.ts
@@ -0,0 +1,20 @@
+import { describe, expect, it } from 'vitest';
+
+import { parseTeamsTranscriptHistoryDays } from 'src/features/transcripts/front-components/utils/parse-teams-transcript-history-days';
+
+describe('parseTeamsTranscriptHistoryDays', () => {
+ it.each([
+ { text: '1', days: 1 },
+ { text: '365', days: 365 },
+ { text: ' 90 ', days: 90 },
+ ])('should accept $text as $days days', ({ text, days }) => {
+ expect(parseTeamsTranscriptHistoryDays(text)).toBe(days);
+ });
+
+ it.each(['', ' ', '0', '-1', '366', '1.5', '90days', '1e2', '0x1f'])(
+ 'should reject %j',
+ (text) => {
+ expect(parseTeamsTranscriptHistoryDays(text)).toBeUndefined();
+ },
+ );
+});
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/format-teams-transcript-history-date.ts b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/format-teams-transcript-history-date.ts
new file mode 100644
index 00000000000..b21d91ffd6b
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/format-teams-transcript-history-date.ts
@@ -0,0 +1,7 @@
+export const formatTeamsTranscriptHistoryDate = ({
+ date,
+ locale,
+}: {
+ date: string;
+ locale: string;
+}): string => new Date(date).toLocaleDateString(locale);
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/get-teams-transcript-history-failure-message.ts b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/get-teams-transcript-history-failure-message.ts
new file mode 100644
index 00000000000..9530bdbba63
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/get-teams-transcript-history-failure-message.ts
@@ -0,0 +1,24 @@
+import { t } from 'twenty-sdk/front-component';
+
+import { type TeamsTranscriptHistoryErrorCode } from 'src/features/transcripts/logic-functions/types/teams-transcript-history-error-code.type';
+
+export const getTeamsTranscriptHistoryFailureMessage = (
+ errorCode: TeamsTranscriptHistoryErrorCode,
+): string => {
+ switch (errorCode) {
+ case 'reconnect-required':
+ return t(
+ 'The last run stopped because Microsoft Teams must be reconnected. Reconnect it, then count again.',
+ );
+ case 'transcripts-disabled-by-admin':
+ return t(
+ 'The last run stopped because your Microsoft admin turned off transcript access for apps.',
+ );
+ case 'page-limit-reached':
+ return t(
+ 'The last run stopped after too many calendar pages. Count fewer days.',
+ );
+ case 'unknown':
+ return t('The last run failed. Count again to retry.');
+ }
+};
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/get-teams-transcript-history-poll-delay-milliseconds.ts b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/get-teams-transcript-history-poll-delay-milliseconds.ts
new file mode 100644
index 00000000000..f2ca655bebf
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/get-teams-transcript-history-poll-delay-milliseconds.ts
@@ -0,0 +1,32 @@
+import { isDefined } from 'twenty-sdk/utils';
+
+import { TEAMS_TRANSCRIPT_HISTORY_COUNTING_POLL_MILLISECONDS } from 'src/features/transcripts/front-components/constants/teams-transcript-history-counting-poll-milliseconds';
+import { TEAMS_TRANSCRIPT_HISTORY_IMPORTING_POLL_MILLISECONDS } from 'src/features/transcripts/front-components/constants/teams-transcript-history-importing-poll-milliseconds';
+import { type TeamsTranscriptHistoryView } from 'src/features/transcripts/front-components/types/teams-transcript-history-view.type';
+import { type TeamsTranscriptHistoryRouteErrorCode } from 'src/features/transcripts/logic-functions/types/teams-transcript-history-route-error-code.type';
+
+export const getTeamsTranscriptHistoryPollDelayMilliseconds = ({
+ view,
+ loadErrorCode,
+}: {
+ view: TeamsTranscriptHistoryView | undefined;
+ loadErrorCode: TeamsTranscriptHistoryRouteErrorCode | undefined;
+}): number | undefined => {
+ if (!isDefined(view)) {
+ return isDefined(loadErrorCode) ? undefined : 0;
+ }
+
+ // Only an unexpected failure may clear up on its own; the other codes need the member to act first.
+ if (isDefined(loadErrorCode) && loadErrorCode !== 'unknown') {
+ return undefined;
+ }
+
+ switch (view.kind) {
+ case 'counting':
+ return TEAMS_TRANSCRIPT_HISTORY_COUNTING_POLL_MILLISECONDS;
+ case 'importing':
+ return TEAMS_TRANSCRIPT_HISTORY_IMPORTING_POLL_MILLISECONDS;
+ default:
+ return undefined;
+ }
+};
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/get-teams-transcript-history-route-error-message.ts b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/get-teams-transcript-history-route-error-message.ts
new file mode 100644
index 00000000000..c3b6af106a9
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/get-teams-transcript-history-route-error-message.ts
@@ -0,0 +1,33 @@
+import { t } from 'twenty-sdk/front-component';
+
+import { TEAMS_TRANSCRIPT_HISTORY_MAX_DAYS } from 'src/features/transcripts/constants/teams-transcript-history-max-days';
+import { type TeamsTranscriptHistoryRouteErrorCode } from 'src/features/transcripts/logic-functions/types/teams-transcript-history-route-error-code.type';
+
+export const getTeamsTranscriptHistoryRouteErrorMessage = ({
+ errorCode,
+ unknownErrorMessage,
+}: {
+ errorCode: TeamsTranscriptHistoryRouteErrorCode;
+ unknownErrorMessage: string;
+}): string => {
+ switch (errorCode) {
+ case 'transcripts-not-enabled':
+ return t('Turn on transcripts to import their history.');
+ case 'not-connected':
+ return t(
+ 'Add your own Microsoft Teams connection to import its history.',
+ );
+ case 'reconnect-required':
+ return t('Reconnect Microsoft Teams in the app settings.');
+ case 'invalid-days':
+ return t('Enter a whole number of days between 1 and {maxDays}.', {
+ maxDays: TEAMS_TRANSCRIPT_HISTORY_MAX_DAYS,
+ });
+ case 'run-already-active':
+ return t('Transcripts are already being counted or imported.');
+ case 'count-required':
+ return t('Count the transcripts again before importing them.');
+ case 'unknown':
+ return unknownErrorMessage;
+ }
+};
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/get-teams-transcript-history-view.ts b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/get-teams-transcript-history-view.ts
new file mode 100644
index 00000000000..243c3f318c7
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/get-teams-transcript-history-view.ts
@@ -0,0 +1,71 @@
+import { isDefined } from 'twenty-sdk/utils';
+
+import { TEAMS_TRANSCRIPT_HISTORY_IMPORT_PAGE_DELAY_MILLISECONDS } from 'src/features/transcripts/constants/teams-transcript-history-import-page-delay-milliseconds';
+import { MILLISECONDS_PER_MINUTE } from 'src/features/transcripts/front-components/constants/milliseconds-per-minute';
+import { MINUTES_PER_HOUR } from 'src/features/transcripts/front-components/constants/minutes-per-hour';
+import { type TeamsTranscriptHistoryImportEstimate } from 'src/features/transcripts/front-components/types/teams-transcript-history-import-estimate.type';
+import { type TeamsTranscriptHistoryView } from 'src/features/transcripts/front-components/types/teams-transcript-history-view.type';
+import { type TeamsTranscriptHistoryState } from 'src/features/transcripts/logic-functions/types/teams-transcript-history-state.type';
+
+const getImportEstimate = (
+ pageCount: number,
+): TeamsTranscriptHistoryImportEstimate => {
+ const importMinutes = Math.max(
+ 1,
+ Math.ceil(
+ (pageCount * TEAMS_TRANSCRIPT_HISTORY_IMPORT_PAGE_DELAY_MILLISECONDS) /
+ MILLISECONDS_PER_MINUTE,
+ ),
+ );
+
+ return importMinutes < MINUTES_PER_HOUR
+ ? { unit: 'minute', count: importMinutes }
+ : { unit: 'hour', count: Math.ceil(importMinutes / MINUTES_PER_HOUR) };
+};
+
+export const getTeamsTranscriptHistoryView = ({
+ state,
+ isStalled,
+}: {
+ state: TeamsTranscriptHistoryState | null;
+ isStalled: boolean;
+}): TeamsTranscriptHistoryView => {
+ if (!isDefined(state)) {
+ return { kind: 'idle' };
+ }
+
+ if (isStalled) {
+ return { kind: 'stalled' };
+ }
+
+ const toImportCount =
+ state.transcriptCount - state.alreadyImportedCount - state.deletedCount;
+
+ switch (state.phase) {
+ case 'counting':
+ return { kind: 'counting', checkedThrough: state.checkedThrough };
+ case 'counted':
+ return {
+ kind: 'counted',
+ runId: state.runId,
+ days: state.days,
+ transcriptCount: state.transcriptCount,
+ alreadyImportedCount: state.alreadyImportedCount,
+ deletedCount: state.deletedCount,
+ toImportCount,
+ importEstimate: getImportEstimate(state.pageCount),
+ };
+ case 'importing':
+ case 'imported':
+ return {
+ kind: state.phase,
+ importedCount: state.importedCount,
+ skippedCount: state.skippedCount,
+ unavailableCount: state.unavailableCount,
+ toImportCount: toImportCount > 0 ? toImportCount : undefined,
+ checkedThrough: state.checkedThrough,
+ };
+ case 'failed':
+ return { kind: 'failed', errorCode: state.errorCode ?? 'unknown' };
+ }
+};
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/parse-teams-transcript-history-days.ts b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/parse-teams-transcript-history-days.ts
new file mode 100644
index 00000000000..3df5b1fd57f
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/parse-teams-transcript-history-days.ts
@@ -0,0 +1,15 @@
+import { TEAMS_TRANSCRIPT_HISTORY_MAX_DAYS } from 'src/features/transcripts/constants/teams-transcript-history-max-days';
+
+export const parseTeamsTranscriptHistoryDays = (
+ value: string,
+): number | undefined => {
+ if (!/^\d+$/.test(value.trim())) {
+ return undefined;
+ }
+
+ const days = Number(value);
+
+ return days >= 1 && days <= TEAMS_TRANSCRIPT_HISTORY_MAX_DAYS
+ ? days
+ : undefined;
+};
diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/post-teams-transcript-history-route-or-throw.ts b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/post-teams-transcript-history-route-or-throw.ts
new file mode 100644
index 00000000000..276ff1d4919
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/features/transcripts/front-components/utils/post-teams-transcript-history-route-or-throw.ts
@@ -0,0 +1,13 @@
+import { RestApiClient } from 'twenty-client-sdk/rest';
+
+import { type TeamsTranscriptHistoryRouteRequest } from 'src/features/transcripts/front-components/types/teams-transcript-history-route-request.type';
+import { type TeamsTranscriptHistoryRouteResult } from 'src/features/transcripts/logic-functions/types/teams-transcript-history-route-result.type';
+
+export const postTeamsTranscriptHistoryRouteOrThrow = ({
+ routePath,
+ body,
+}: TeamsTranscriptHistoryRouteRequest): Promise<TeamsTranscriptHistoryRouteResult> =>
+ new RestApiClient().post<TeamsTranscriptHistoryRouteResult>(
+ `/s${routePath}`,
+ body,
+ );
diff --git a/packages/twenty-apps/public/teams/src/front-components/components/StyledSettingsButton.tsx b/packages/twenty-apps/public/teams/src/front-components/components/StyledSettingsButton.tsx
new file mode 100644
index 00000000000..84701a469fd
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/front-components/components/StyledSettingsButton.tsx
@@ -0,0 +1,19 @@
+import styled from '@emotion/styled';
+import { themeCssVariables } from 'twenty-ui/theme';
+
+export const StyledSettingsButton = styled.button`
+ background: ${() => themeCssVariables.background.primary};
+ border: 1px solid ${() => themeCssVariables.border.color.medium};
+ border-radius: ${() => themeCssVariables.border.radius.sm};
+ color: inherit;
+ cursor: pointer;
+ font: inherit;
+ padding: ${() => themeCssVariables.spacing[1]}
+ ${() => themeCssVariables.spacing[3]};
+ width: fit-content;
+
+ &:disabled {
+ cursor: default;
+ opacity: 0.5;
+ }
+`;
diff --git a/packages/twenty-apps/public/teams/src/front-components/components/StyledSettingsFigureList.tsx b/packages/twenty-apps/public/teams/src/front-components/components/StyledSettingsFigureList.tsx
new file mode 100644
index 00000000000..6e25f8b859d
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/front-components/components/StyledSettingsFigureList.tsx
@@ -0,0 +1,12 @@
+import styled from '@emotion/styled';
+import { themeCssVariables } from 'twenty-ui/theme';
+
+export const StyledSettingsFigureList = styled.ul`
+ color: ${() => themeCssVariables.font.color.secondary};
+ display: flex;
+ flex-direction: column;
+ gap: ${() => themeCssVariables.spacing[1]};
+ list-style: none;
+ margin: 0;
+ padding: 0;
+`;
diff --git a/packages/twenty-apps/public/teams/src/front-components/components/StyledSettingsHint.tsx b/packages/twenty-apps/public/teams/src/front-components/components/StyledSettingsHint.tsx
new file mode 100644
index 00000000000..215a0fcc4cb
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/front-components/components/StyledSettingsHint.tsx
@@ -0,0 +1,8 @@
+import styled from '@emotion/styled';
+import { themeCssVariables } from 'twenty-ui/theme';
+
+export const StyledSettingsHint = styled.p`
+ color: ${() => themeCssVariables.font.color.tertiary};
+ font-size: ${() => themeCssVariables.font.size.sm};
+ margin: 0;
+`;
diff --git a/packages/twenty-apps/public/teams/src/front-components/components/StyledSettingsText.tsx b/packages/twenty-apps/public/teams/src/front-components/components/StyledSettingsText.tsx
new file mode 100644
index 00000000000..387732bb255
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/front-components/components/StyledSettingsText.tsx
@@ -0,0 +1,8 @@
+import styled from '@emotion/styled';
+import { themeCssVariables } from 'twenty-ui/theme';
+
+export const StyledSettingsText = styled.p`
+ color: ${() => themeCssVariables.font.color.secondary};
+ line-height: ${() => themeCssVariables.text.lineHeight.lg};
+ margin: 0;
+`;
diff --git a/packages/twenty-apps/public/teams/src/front-components/components/TimeoutEffect.tsx b/packages/twenty-apps/public/teams/src/front-components/components/TimeoutEffect.tsx
new file mode 100644
index 00000000000..07dc6570e46
--- /dev/null
+++ b/packages/twenty-apps/public/teams/src/front-components/components/TimeoutEffect.tsx
@@ -0,0 +1,21 @@
+import { useEffect, useState } from 'react';
+
+type TimeoutEffectProps = {
+ delayMilliseconds: number;
+ onTimeout: () => void;
+};
+
+export const TimeoutEffect = ({
+ delayMilliseconds,
+ onTimeout,
+}: TimeoutEffectProps) => {
+ const [initialOnTimeout] = useState(() => onTimeout);
+
+ useEffect(() => {
+ const timeoutId = setTimeout(initialOnTimeout, delayMilliseconds);
+
+ return () => clearTimeout(timeoutId);
+ }, [delayMilliseconds, initialOnTimeout]);
+
+ return null;
+};
diff --git a/packages/twenty-apps/public/teams/src/front-components/components/__tests__/TeamsSettings.test.tsx b/packages/twenty-apps/public/teams/src/front-components/components/__tests__/TeamsSettings.test.tsx
index fd34517b2a1..93930fc1a7b 100644
--- a/packages/twenty-apps/public/teams/src/front-components/components/__tests__/TeamsSettings.test.tsx
+++ b/packages/twenty-apps/public/teams/src/front-components/components/__tests__/TeamsSettings.test.tsx
@@ -41,6 +41,11 @@ vi.mock('twenty-sdk/front-component', () => ({
useTranslate: () => ({ t: (message: string) => message }),
}));
+vi.mock(
+ 'src/features/transcripts/front-components/TranscriptImportHistorySection',
+ () => ({ TranscriptImportHistorySection: () => null }),
+);
+
vi.mock('twenty-client-sdk/metadata', () => ({
MetadataApiClient: class {
query = queryMock;