The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Add user-scoped Microsoft Teams connection provider (#29427)
nitinca1cd1ee75b6
diff --git a/packages/twenty-apps/public/teams/SETUP.md b/packages/twenty-apps/public/teams/SETUP.mdindex 0a1c5b653ae..804d22f37bc 100644--- a/packages/twenty-apps/public/teams/SETUP.md+++ b/packages/twenty-apps/public/teams/SETUP.md@@ -123,6 +123,14 @@ setup](https://docs.twenty.com/developers/extend/apps/operations/publishing#settOpen **Settings > Applications > Microsoft Teams > Settings**, select**Add connection**, and sign in with your Microsoft work or school account.+This adds a workspace-shared connection.++Members can also add a personal connection from **Settings > App preferences**,+which is behind the `IS_APP_PREFERENCES_ENABLED` workspace feature flag. Each+personal connection imports the meetings its account organizes, so every+organizer connects their own account. Members can only finish connecting once+a Microsoft 365 admin has consented to `OnlineMeetingTranscript.Read.All` for+the organization. Personal connections do not claim a tenant for chat.Transcript imports are on by default. Connecting an account creates a MicrosoftGraph subscription to the transcripts of the meetings that account organizes.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 5f983656362..d105c808b97 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@@ -103,7 +103,7 @@ describe('App installation', () => {);});- it('registers Microsoft OAuth under Teams without configured credentials', async () => {+ it('registers workspace-shared and personal Microsoft OAuth under Teams without configured credentials', async () => {const client = new MetadataApiClient();const result = await client.query({@@ -130,6 +130,7 @@ describe('App installation', () => {name: true,displayName: true,type: true,+ scope: true,oauth: {scopes: true,isClientCredentialsConfigured: true,@@ -137,20 +138,33 @@ describe('App installation', () => {},});- expect(applicationConnectionProviders).toEqual([- {- applicationId: application.id,- name: 'microsoft-teams',- displayName: 'Microsoft Teams',- type: 'oauth',- oauth: {- scopes: expect.arrayContaining([- 'offline_access',- 'https://graph.microsoft.com/OnlineMeetingTranscript.Read.All',- ]),- isClientCredentialsConfigured: false,- },+ const buildExpectedProvider = ({+ name,+ scope,+ }: {+ name: string;+ scope: 'USER' | 'WORKSPACE';+ }) => ({+ applicationId: application.id,+ name,+ displayName: 'Microsoft Teams',+ type: 'oauth',+ scope,+ oauth: {+ scopes: expect.arrayContaining([+ 'offline_access',+ 'https://graph.microsoft.com/OnlineMeetingTranscript.Read.All',+ ]),+ isClientCredentialsConfigured: false,},- ]);+ });++ expect(applicationConnectionProviders).toHaveLength(2);+ expect(applicationConnectionProviders).toEqual(+ expect.arrayContaining([+ buildExpectedProvider({ name: 'microsoft-teams', scope: 'WORKSPACE' }),+ buildExpectedProvider({ name: 'microsoft-teams-user', scope: 'USER' }),+ ]),+ );});});diff --git a/packages/twenty-apps/public/teams/src/features/chat/logic-functions/utils/__tests__/register-teams-connection.test.ts b/packages/twenty-apps/public/teams/src/features/chat/logic-functions/utils/__tests__/register-teams-connection.test.tsindex 62051b4a6a1..1f953c60bb0 100644--- a/packages/twenty-apps/public/teams/src/features/chat/logic-functions/utils/__tests__/register-teams-connection.test.ts+++ b/packages/twenty-apps/public/teams/src/features/chat/logic-functions/utils/__tests__/register-teams-connection.test.ts@@ -49,7 +49,7 @@ describe('registerTeamsConnection', () => {releaseFlags.IS_CHAT_ASSISTANT_RELEASED = true;process.env[CHAT_ENABLED_APPLICATION_VARIABLE_KEY] = 'true';getConnectionMock.mockResolvedValue({- visibility: 'workspace',+ scope: 'WORKSPACE',accessToken: 'graph-token',});fetchGraphJsonMock.mockResolvedValue({ value: [{ id: TENANT_ID }] });@@ -97,7 +97,7 @@ describe('registerTeamsConnection', () => {it('should release the claim instead of claiming when the connection is personal', async () => {getConnectionMock.mockResolvedValue({- visibility: 'user',+ scope: 'USER',accessToken: 'graph-token',});diff --git a/packages/twenty-apps/public/teams/src/features/chat/logic-functions/utils/__tests__/release-teams-connection-tenant.test.ts b/packages/twenty-apps/public/teams/src/features/chat/logic-functions/utils/__tests__/release-teams-connection-tenant.test.tsindex e4dbc5bb337..72d0984d44b 100644--- a/packages/twenty-apps/public/teams/src/features/chat/logic-functions/utils/__tests__/release-teams-connection-tenant.test.ts+++ b/packages/twenty-apps/public/teams/src/features/chat/logic-functions/utils/__tests__/release-teams-connection-tenant.test.ts@@ -4,12 +4,12 @@ import { buildTeamsConnectedAccountTenantKvKey } from 'src/features/chat/logic-fimport { buildTeamsTenantKvKey } from 'src/features/chat/logic-functions/utils/build-teams-tenant-kv-key';import { releaseTeamsConnectionTenant } from 'src/features/chat/logic-functions/utils/release-teams-connection-tenant';-const { kvStore, unreadableKvKeys, kvDeleteMock, listConnectionsMock } =+const { kvStore, unreadableKvKeys, kvDeleteMock, listTeamsConnectionsMock } =vi.hoisted(() => ({kvStore: new Map<string, string | null>(),unreadableKvKeys: new Set<string>(),kvDeleteMock: vi.fn(),- listConnectionsMock: vi.fn(),+ listTeamsConnectionsMock: vi.fn(),}));vi.mock('twenty-sdk/logic-function', () => ({@@ -30,9 +30,13 @@ vi.mock('twenty-sdk/logic-function', () => ({return kvStore.delete(key);},},- listConnections: listConnectionsMock,}));+vi.mock(+ 'src/features/transcripts/logic-functions/utils/list-teams-connections',+ () => ({ listTeamsConnections: listTeamsConnectionsMock }),+);+const TENANT_ID = 'tenant-id';describe('releaseTeamsConnectionTenant', () => {@@ -42,7 +46,7 @@ describe('releaseTeamsConnectionTenant', () => {unreadableKvKeys.clear();kvStore.set(buildTeamsConnectedAccountTenantKvKey('leaving'), TENANT_ID);kvStore.set(buildTeamsTenantKvKey(TENANT_ID), null);- listConnectionsMock.mockResolvedValue([{ id: 'leaving' }]);+ listTeamsConnectionsMock.mockResolvedValue([{ id: 'leaving' }]);});it('should release the tenant claim and forget the connection', async () => {@@ -63,7 +67,7 @@ describe('releaseTeamsConnectionTenant', () => {it('should keep the tenant claimed while another connection in the workspace still holds it', async () => {kvStore.set(buildTeamsConnectedAccountTenantKvKey('staying'), TENANT_ID);- listConnectionsMock.mockResolvedValue([+ listTeamsConnectionsMock.mockResolvedValue([{ id: 'leaving' },{ id: 'staying' },]);@@ -83,7 +87,7 @@ describe('releaseTeamsConnectionTenant', () => {buildTeamsConnectedAccountTenantKvKey('also-leaving'),TENANT_ID,);- listConnectionsMock.mockResolvedValue([+ listTeamsConnectionsMock.mockResolvedValue([{ id: 'leaving' },{ id: 'also-leaving' },]);@@ -103,7 +107,7 @@ describe('releaseTeamsConnectionTenant', () => {});it('should keep the connection tenant for a retry when listing connections fails', async () => {- listConnectionsMock.mockRejectedValue(new Error('refresh failed'));+ listTeamsConnectionsMock.mockRejectedValue(new Error('refresh failed'));await expect(releaseTeamsConnectionTenant({ connectedAccountId: 'leaving' }),@@ -113,7 +117,7 @@ describe('releaseTeamsConnectionTenant', () => {it('should keep the connection tenant for a retry when reading other connections fails', async () => {unreadableKvKeys.add(buildTeamsConnectedAccountTenantKvKey('staying'));- listConnectionsMock.mockResolvedValue([+ listTeamsConnectionsMock.mockResolvedValue([{ id: 'leaving' },{ id: 'staying' },]);@@ -129,7 +133,7 @@ describe('releaseTeamsConnectionTenant', () => {it('should claim the tenant again when a connection takes it while it is being released', async () => {kvStore.set(buildTeamsConnectedAccountTenantKvKey('joining'), TENANT_ID);- listConnectionsMock+ listTeamsConnectionsMock.mockResolvedValueOnce([{ id: 'leaving' }]).mockResolvedValueOnce([{ id: 'leaving' }, { id: 'joining' }]);diff --git a/packages/twenty-apps/public/teams/src/features/chat/logic-functions/utils/register-teams-connection.ts b/packages/twenty-apps/public/teams/src/features/chat/logic-functions/utils/register-teams-connection.tsindex 2bad5da5e5c..1fae85e7b7a 100644--- a/packages/twenty-apps/public/teams/src/features/chat/logic-functions/utils/register-teams-connection.ts+++ b/packages/twenty-apps/public/teams/src/features/chat/logic-functions/utils/register-teams-connection.ts@@ -18,7 +18,7 @@ export const registerTeamsConnection = async ({? await getConnection(connectedAccountId): undefined;- if (connection?.visibility !== 'workspace') {+ if (connection?.scope !== 'WORKSPACE') {await releaseTeamsConnectionTenant({ connectedAccountId });return { claimedTenantId: null };diff --git a/packages/twenty-apps/public/teams/src/features/chat/logic-functions/utils/release-teams-connection-tenant.ts b/packages/twenty-apps/public/teams/src/features/chat/logic-functions/utils/release-teams-connection-tenant.tsindex f3b392a61e0..d1febce7102 100644--- a/packages/twenty-apps/public/teams/src/features/chat/logic-functions/utils/release-teams-connection-tenant.ts+++ b/packages/twenty-apps/public/teams/src/features/chat/logic-functions/utils/release-teams-connection-tenant.ts@@ -1,14 +1,12 @@import { isNonEmptyString } from '@sniptt/guards';-import { kv, listConnections } from 'twenty-sdk/logic-function';+import { kv } from 'twenty-sdk/logic-function';import { buildTeamsConnectedAccountTenantKvKey } from 'src/features/chat/logic-functions/utils/build-teams-connected-account-tenant-kv-key';import { buildTeamsTenantKvKey } from 'src/features/chat/logic-functions/utils/build-teams-tenant-kv-key';-import { TEAMS_PROVIDER_NAME } from 'src/features/transcripts/constants/teams-provider-name';+import { listTeamsConnections } from 'src/features/transcripts/logic-functions/utils/list-teams-connections';const listTeamsConnectionIds = async (): Promise<string[]> =>- (await listConnections({ providerName: TEAMS_PROVIDER_NAME })).map(- (connection) => connection.id,- );+ (await listTeamsConnections()).map((connection) => connection.id);const isTenantHeldByConnections = async ({tenantId,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 d5654c1c84b..7b10f4322a1 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@@ -4,6 +4,7 @@ import {TEAMS_REGISTER_CONNECTION_UNIVERSAL_IDENTIFIER,TEAMS_TENANT_RELEASE_UNIVERSAL_IDENTIFIER,} from 'src/features/chat/constants/universal-identifiers';+import { TEAMS_OAUTH_CONFIG } from 'src/features/transcripts/constants/teams-oauth-config';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';@@ -12,31 +13,12 @@ export default defineConnectionProvider({name: TEAMS_PROVIDER_NAME,displayName: 'Microsoft Teams',type: 'oauth',+ scope: 'WORKSPACE',onConnectLogicFunction: {universalIdentifier: TEAMS_REGISTER_CONNECTION_UNIVERSAL_IDENTIFIER,},onDisconnectLogicFunction: {universalIdentifier: TEAMS_TENANT_RELEASE_UNIVERSAL_IDENTIFIER,},- oauth: {- authorizationEndpoint:- 'https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize',- tokenEndpoint:- 'https://login.microsoftonline.com/organizations/oauth2/v2.0/token',- scopes: [- 'openid',- 'profile',- 'email',- 'offline_access',- 'https://graph.microsoft.com/User.Read',- 'https://graph.microsoft.com/Calendars.ReadBasic',- 'https://graph.microsoft.com/OnlineMeetings.Read',- 'https://graph.microsoft.com/OnlineMeetingTranscript.Read.All',- ],- clientIdVariable: 'MICROSOFT_CLIENT_ID',- clientSecretVariable: 'MICROSOFT_CLIENT_SECRET',- authorizationParams: { prompt: 'select_account' },- tokenRequestContentType: 'form-urlencoded',- usePkce: true,- },+ oauth: TEAMS_OAUTH_CONFIG,});diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/connection-providers/microsoft-teams-user-connection.ts b/packages/twenty-apps/public/teams/src/features/transcripts/connection-providers/microsoft-teams-user-connection.tsnew file mode 100644index 00000000000..2c922a2ef12--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/connection-providers/microsoft-teams-user-connection.ts@@ -0,0 +1,24 @@+import { defineConnectionProvider } from 'twenty-sdk/define';++import {+ TEAMS_REGISTER_CONNECTION_UNIVERSAL_IDENTIFIER,+ TEAMS_TENANT_RELEASE_UNIVERSAL_IDENTIFIER,+} from 'src/features/chat/constants/universal-identifiers';+import { TEAMS_OAUTH_CONFIG } from 'src/features/transcripts/constants/teams-oauth-config';+import { TEAMS_USER_PROVIDER_NAME } from 'src/features/transcripts/constants/teams-user-provider-name';+import { TEAMS_USER_CONNECTION_PROVIDER_UNIVERSAL_IDENTIFIER } from 'src/features/transcripts/constants/universal-identifiers';++export default defineConnectionProvider({+ universalIdentifier: TEAMS_USER_CONNECTION_PROVIDER_UNIVERSAL_IDENTIFIER,+ name: TEAMS_USER_PROVIDER_NAME,+ displayName: 'Microsoft Teams',+ type: 'oauth',+ scope: 'USER',+ onConnectLogicFunction: {+ universalIdentifier: TEAMS_REGISTER_CONNECTION_UNIVERSAL_IDENTIFIER,+ },+ onDisconnectLogicFunction: {+ universalIdentifier: TEAMS_TENANT_RELEASE_UNIVERSAL_IDENTIFIER,+ },+ oauth: TEAMS_OAUTH_CONFIG,+});diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/constants/teams-oauth-config.ts b/packages/twenty-apps/public/teams/src/features/transcripts/constants/teams-oauth-config.tsnew file mode 100644index 00000000000..0b124769025--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/constants/teams-oauth-config.ts@@ -0,0 +1,28 @@+import { type defineConnectionProvider } from 'twenty-sdk/define';++type OAuthConnectionProviderConfig = Extract<+ Parameters<typeof defineConnectionProvider>[0],+ { type: 'oauth' }+>['oauth'];++export const TEAMS_OAUTH_CONFIG: OAuthConnectionProviderConfig = {+ authorizationEndpoint:+ 'https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize',+ tokenEndpoint:+ 'https://login.microsoftonline.com/organizations/oauth2/v2.0/token',+ scopes: [+ 'openid',+ 'profile',+ 'email',+ 'offline_access',+ 'https://graph.microsoft.com/User.Read',+ 'https://graph.microsoft.com/Calendars.ReadBasic',+ 'https://graph.microsoft.com/OnlineMeetings.Read',+ 'https://graph.microsoft.com/OnlineMeetingTranscript.Read.All',+ ],+ clientIdVariable: 'MICROSOFT_CLIENT_ID',+ clientSecretVariable: 'MICROSOFT_CLIENT_SECRET',+ authorizationParams: { prompt: 'select_account' },+ tokenRequestContentType: 'form-urlencoded',+ usePkce: true,+};diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/constants/teams-provider-names.ts b/packages/twenty-apps/public/teams/src/features/transcripts/constants/teams-provider-names.tsnew file mode 100644index 00000000000..64b9e585126--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/constants/teams-provider-names.ts@@ -0,0 +1,7 @@+import { TEAMS_PROVIDER_NAME } from 'src/features/transcripts/constants/teams-provider-name';+import { TEAMS_USER_PROVIDER_NAME } from 'src/features/transcripts/constants/teams-user-provider-name';++export const TEAMS_PROVIDER_NAMES: readonly string[] = [+ TEAMS_PROVIDER_NAME,+ TEAMS_USER_PROVIDER_NAME,+];diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/constants/teams-user-provider-name.ts b/packages/twenty-apps/public/teams/src/features/transcripts/constants/teams-user-provider-name.tsnew file mode 100644index 00000000000..f3237dd4c2e--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/constants/teams-user-provider-name.ts@@ -0,0 +1 @@+export const TEAMS_USER_PROVIDER_NAME = 'microsoft-teams-user';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 f0895a9144b..819c35ccae5 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@@ -4,6 +4,9 @@ export const TRANSCRIPTS_ENABLED_APPLICATION_VARIABLE_UNIVERSAL_IDENTIFIER =export const TEAMS_CONNECTION_PROVIDER_UNIVERSAL_IDENTIFIER ='b81c3c60-2cb1-44b8-9ec6-6f731997f5f0';+export const TEAMS_USER_CONNECTION_PROVIDER_UNIVERSAL_IDENTIFIER =+ 'e274ed1e-518a-4691-a5f9-0b2bf64ff52a';+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/teams-uninstall.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/teams-uninstall.tsindex 3ff7533ac9b..f1747907462 100644--- a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/teams-uninstall.ts+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/teams-uninstall.ts@@ -1,16 +1,13 @@import { defineUninstallLogicFunction } from 'twenty-sdk/define';-import { listConnections } from 'twenty-sdk/logic-function';-import { TEAMS_PROVIDER_NAME } from 'src/features/transcripts/constants/teams-provider-name';import { TEAMS_UNINSTALL_UNIVERSAL_IDENTIFIER } from 'src/features/transcripts/constants/universal-identifiers';+import { listTeamsConnections } from 'src/features/transcripts/logic-functions/utils/list-teams-connections';import { unregisterTeamsTranscriptSubscription } from 'src/features/transcripts/logic-functions/utils/unregister-teams-transcript-subscription';export const teamsUninstallHandler = async (): Promise<{failedConnectionCount: number;}> => {- const connections = await listConnections({- providerName: TEAMS_PROVIDER_NAME,- });+ const connections = await listTeamsConnections();const results = await Promise.allSettled(connections.map((connection) =>unregisterTeamsTranscriptSubscription({diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/__tests__/get-teams-connection-for-request-or-throw.test.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/__tests__/get-teams-connection-for-request-or-throw.test.tsindex 9621809790a..c00ed811aa8 100644--- a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/__tests__/get-teams-connection-for-request-or-throw.test.ts+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/__tests__/get-teams-connection-for-request-or-throw.test.ts@@ -13,20 +13,21 @@ vi.mock('twenty-sdk/logic-function', async (importOriginal) => ({const buildConnection = ({id,- visibility,+ scope,userWorkspaceId,}: {id: string;- visibility: 'user' | 'workspace';+ scope: 'USER' | 'WORKSPACE';userWorkspaceId: string;}) => ({id,- providerName: 'microsoft-teams',+ providerName:+ scope === 'WORKSPACE' ? 'microsoft-teams' : 'microsoft-teams-user',name: id,handle: `${id}@acme.com`,externalAccountId: null,- scope: visibility === 'workspace' ? 'WORKSPACE' : 'USER',- visibility,+ scope,+ visibility: scope === 'WORKSPACE' ? 'workspace' : 'user',userWorkspaceId,workspaceMemberId: null,providerType: 'oauth',@@ -38,7 +39,7 @@ const buildConnection = ({const SHARED_CONNECTION = buildConnection({id: 'shared-connection',- visibility: 'workspace',+ scope: 'WORKSPACE',userWorkspaceId: 'admin',});@@ -48,12 +49,18 @@ describe('getTeamsConnectionForRequestOrThrow', () => {SHARED_CONNECTION,buildConnection({id: 'member-connection',- visibility: 'user',+ scope: 'USER',userWorkspaceId: 'member',}),]);});+ it('should pick the personal connection of the requesting member', async () => {+ await expect(+ getTeamsConnectionForRequestOrThrow({ userWorkspaceId: 'member' }),+ ).resolves.toMatchObject({ id: 'member-connection' });+ });+it('should fall back on the workspace-shared connection by default', async () => {await expect(getTeamsConnectionForRequestOrThrow({ userWorkspaceId: 'other-member' }),diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/__tests__/list-teams-connections.test.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/__tests__/list-teams-connections.test.tsnew file mode 100644index 00000000000..e5782df35ed--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/__tests__/list-teams-connections.test.ts@@ -0,0 +1,32 @@+import { beforeEach, describe, expect, it, vi } from 'vitest';++import { listTeamsConnections } from 'src/features/transcripts/logic-functions/utils/list-teams-connections';++const { listConnectionsMock } = vi.hoisted(() => ({+ listConnectionsMock: vi.fn(),+}));++vi.mock('twenty-sdk/logic-function', async (importOriginal) => ({+ ...(await importOriginal<Record<string, unknown>>()),+ listConnections: listConnectionsMock,+}));++describe('listTeamsConnections', () => {+ beforeEach(() => {+ vi.clearAllMocks();+ });++ it('should list workspace-shared and personal Microsoft Teams connections', async () => {+ listConnectionsMock.mockResolvedValue([+ { id: 'shared-connection', providerName: 'microsoft-teams' },+ { id: 'personal-connection', providerName: 'microsoft-teams-user' },+ { id: 'other-connection', providerName: 'other-provider' },+ ]);++ await expect(listTeamsConnections()).resolves.toEqual([+ { id: 'shared-connection', providerName: 'microsoft-teams' },+ { id: 'personal-connection', providerName: 'microsoft-teams-user' },+ ]);+ expect(listConnectionsMock).toHaveBeenCalledExactlyOnceWith();+ });+});diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/__tests__/process-teams-transcript-history-page-or-throw.test.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/__tests__/process-teams-transcript-history-page-or-throw.test.tsindex 20a779810be..e8bcca12a50 100644--- a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/__tests__/process-teams-transcript-history-page-or-throw.test.ts+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/__tests__/process-teams-transcript-history-page-or-throw.test.ts@@ -13,14 +13,14 @@ const {listTeamsCalendarPageMock,importTeamsTranscriptHistoryPageMock,countTeamsTranscriptHistoryPageMock,- listConnectionsMock,+ listTeamsConnectionsMock,} = vi.hoisted(() => ({kvStore: new Map<string, unknown>(),enqueueJobsMock: vi.fn(),listTeamsCalendarPageMock: vi.fn(),importTeamsTranscriptHistoryPageMock: vi.fn(),countTeamsTranscriptHistoryPageMock: vi.fn(),- listConnectionsMock: vi.fn(),+ listTeamsConnectionsMock: vi.fn(),}));vi.mock('twenty-sdk/logic-function', async (importOriginal) => ({@@ -34,11 +34,15 @@ vi.mock('twenty-sdk/logic-function', async (importOriginal) => ({kvStore.delete(key);},},- listConnections: listConnectionsMock,getConnection: vi.fn().mockResolvedValue({ accessToken: 'token' }),enqueueJobs: enqueueJobsMock,}));+vi.mock(+ 'src/features/transcripts/logic-functions/utils/list-teams-connections',+ () => ({ listTeamsConnections: listTeamsConnectionsMock }),+);+vi.mock('twenty-client-sdk/core', () => ({CoreApiClient: vi.fn(),}));@@ -137,7 +141,7 @@ describe('processTeamsTranscriptHistoryPageOrThrow', () => {kvStore.clear();process.env[TRANSCRIPTS_ENABLED_APPLICATION_VARIABLE_KEY] = 'true';enqueueJobsMock.mockResolvedValue(undefined);- listConnectionsMock.mockResolvedValue([{ id: 'connected-account-1' }]);+ listTeamsConnectionsMock.mockResolvedValue([{ id: 'connected-account-1' }]);listTeamsCalendarPageMock.mockResolvedValue({occurrences: [],nextPageUrl: NEXT_PAGE_URL,@@ -291,7 +295,7 @@ describe('processTeamsTranscriptHistoryPageOrThrow', () => {it('should not leave a run behind for a connection removed while its page was saved', async () => {kvStore.set(STATE_KV_KEY, STATE);- listConnectionsMock.mockResolvedValue([]);+ listTeamsConnectionsMock.mockResolvedValue([]);await expect(processImportPage(JOB)).resolves.toEqual(expect.objectContaining({ skipped: true }),diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/__tests__/start-teams-transcript-history-initial-import-or-throw.test.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/__tests__/start-teams-transcript-history-initial-import-or-throw.test.tsindex 1e1b0c34405..6eef870ab33 100644--- a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/__tests__/start-teams-transcript-history-initial-import-or-throw.test.ts+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/__tests__/start-teams-transcript-history-initial-import-or-throw.test.ts@@ -3,11 +3,13 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { TRANSCRIPTS_ENABLED_APPLICATION_VARIABLE_KEY } from 'src/features/transcripts/constants/transcripts-enabled-application-variable-key';import { startTeamsTranscriptHistoryInitialImportOrThrow } from 'src/features/transcripts/logic-functions/utils/start-teams-transcript-history-initial-import-or-throw';-const { kvStore, enqueueJobsMock, listConnectionsMock } = vi.hoisted(() => ({- kvStore: new Map<string, unknown>(),- enqueueJobsMock: vi.fn(),- listConnectionsMock: vi.fn(),-}));+const { kvStore, enqueueJobsMock, listTeamsConnectionsMock } = vi.hoisted(+ () => ({+ kvStore: new Map<string, unknown>(),+ enqueueJobsMock: vi.fn(),+ listTeamsConnectionsMock: vi.fn(),+ }),+);vi.mock('twenty-sdk/logic-function', async (importOriginal) => ({...(await importOriginal<Record<string, unknown>>()),@@ -21,9 +23,13 @@ vi.mock('twenty-sdk/logic-function', async (importOriginal) => ({},},enqueueJobs: enqueueJobsMock,- listConnections: listConnectionsMock,}));+vi.mock(+ 'src/features/transcripts/logic-functions/utils/list-teams-connections',+ () => ({ listTeamsConnections: listTeamsConnectionsMock }),+);+const CONNECTED_ACCOUNT_ID = 'connected-account-1';const STATE_KV_KEY = `teams-transcript-history:${CONNECTED_ACCOUNT_ID}`;@@ -53,7 +59,7 @@ describe('startTeamsTranscriptHistoryInitialImportOrThrow', () => {kvStore.clear();process.env[TRANSCRIPTS_ENABLED_APPLICATION_VARIABLE_KEY] = 'true';enqueueJobsMock.mockResolvedValue(undefined);- listConnectionsMock.mockResolvedValue([{ id: CONNECTED_ACCOUNT_ID }]);+ listTeamsConnectionsMock.mockResolvedValue([{ id: CONNECTED_ACCOUNT_ID }]);});afterEach(() => {@@ -149,7 +155,7 @@ describe('startTeamsTranscriptHistoryInitialImportOrThrow', () => {});it('should remove the import state of a connection removed while it started', async () => {- listConnectionsMock.mockResolvedValue([]);+ listTeamsConnectionsMock.mockResolvedValue([]);await startInitialImport();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.tsindex 666fa50a887..bfa66e1be36 100644--- 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.ts@@ -1,12 +1,11 @@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';import { TeamsConnectionUnavailableError } from 'src/features/transcripts/logic-functions/types/teams-connection-unavailable-error';+import { listTeamsConnections } from 'src/features/transcripts/logic-functions/utils/list-teams-connections';export const getTeamsConnectionForRequestOrThrow = async (context: Pick<LogicFunctionExecutionContext, 'userWorkspaceId'>,@@ -14,9 +13,7 @@ export const getTeamsConnectionForRequestOrThrow = async (isOwnConnectionRequired = false,}: { isOwnConnectionRequired?: boolean } = {},) => {- const connections = await listConnections({- providerName: TEAMS_PROVIDER_NAME,- });+ const connections = await listTeamsConnections();const connection = findConnectionForRequest(isOwnConnectionRequired? connections.filter(diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/is-teams-connection-listed.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/is-teams-connection-listed.tsindex 528f72ff74a..c555c346b2b 100644--- a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/is-teams-connection-listed.ts+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/is-teams-connection-listed.ts@@ -1,10 +1,8 @@-import { listConnections } from 'twenty-sdk/logic-function';--import { TEAMS_PROVIDER_NAME } from 'src/features/transcripts/constants/teams-provider-name';+import { listTeamsConnections } from 'src/features/transcripts/logic-functions/utils/list-teams-connections';export const isTeamsConnectionListed = async (connectedAccountId: string,): Promise<boolean> =>- (await listConnections({ providerName: TEAMS_PROVIDER_NAME })).some(+ (await listTeamsConnections()).some((connection) => connection.id === connectedAccountId,);diff --git a/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/list-teams-connections.ts b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/list-teams-connections.tsnew file mode 100644index 00000000000..466dab44cd1--- /dev/null+++ b/packages/twenty-apps/public/teams/src/features/transcripts/logic-functions/utils/list-teams-connections.ts@@ -0,0 +1,8 @@+import { type AppConnection, listConnections } from 'twenty-sdk/logic-function';++import { TEAMS_PROVIDER_NAMES } from 'src/features/transcripts/constants/teams-provider-names';++export const listTeamsConnections = async (): Promise<AppConnection[]> =>+ (await listConnections()).filter((connection) =>+ TEAMS_PROVIDER_NAMES.includes(connection.providerName),+ );diff --git a/packages/twenty-apps/public/teams/src/logic-functions/__tests__/teams-health-check.test.ts b/packages/twenty-apps/public/teams/src/logic-functions/__tests__/teams-health-check.test.tsindex 56e69f72868..cc95e66e47a 100644--- a/packages/twenty-apps/public/teams/src/logic-functions/__tests__/teams-health-check.test.ts+++ b/packages/twenty-apps/public/teams/src/logic-functions/__tests__/teams-health-check.test.ts@@ -1,22 +1,46 @@import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import { CHAT_ENABLED_APPLICATION_VARIABLE_KEY } from 'src/features/chat/constants/chat-enabled-application-variable-key';import { TRANSCRIPTS_ENABLED_APPLICATION_VARIABLE_KEY } from 'src/features/transcripts/constants/transcripts-enabled-application-variable-key';import { teamsHealthCheckHandler } from 'src/logic-functions/teams-health-check';-const { listConnectionsMock } = vi.hoisted(() => ({- listConnectionsMock: vi.fn(),+const { listTeamsConnectionsMock, releaseFlags } = vi.hoisted(() => ({+ listTeamsConnectionsMock: vi.fn(),+ releaseFlags: { IS_CHAT_ASSISTANT_RELEASED: false },}));-vi.mock('twenty-sdk/logic-function', async (importOriginal) => ({- ...(await importOriginal<Record<string, unknown>>()),- listConnections: listConnectionsMock,+vi.mock('src/constants/release-flags', () => ({+ RELEASE_FLAGS: releaseFlags,}));+vi.mock(+ 'src/features/transcripts/logic-functions/utils/list-teams-connections',+ () => ({ listTeamsConnections: listTeamsConnectionsMock }),+);++const PERSONAL_CONNECTION = {+ id: 'personal-connection',+ scope: 'USER',+ authFailedAt: null,+};++const WORKSPACE_CONNECTION = {+ id: 'workspace-connection',+ scope: 'WORKSPACE',+ authFailedAt: null,+};++const enableChat = () => {+ releaseFlags.IS_CHAT_ASSISTANT_RELEASED = true;+ vi.stubEnv(CHAT_ENABLED_APPLICATION_VARIABLE_KEY, 'true');+};+describe('teamsHealthCheckHandler', () => {beforeEach(() => {vi.clearAllMocks();+ releaseFlags.IS_CHAT_ASSISTANT_RELEASED = false;vi.stubEnv(TRANSCRIPTS_ENABLED_APPLICATION_VARIABLE_KEY, 'true');- listConnectionsMock.mockResolvedValue([]);+ listTeamsConnectionsMock.mockResolvedValue([]);});afterEach(() => {@@ -31,22 +55,30 @@ describe('teamsHealthCheckHandler', () => {action: { label: 'Add connection', location: '#general' },});- expect(listConnectionsMock).toHaveBeenCalledWith({- providerName: 'microsoft-teams',- });+ expect(listTeamsConnectionsMock).toHaveBeenCalledExactlyOnceWith();});it('should report nothing once a working connection exists', async () => {- listConnectionsMock.mockResolvedValue([+ listTeamsConnectionsMock.mockResolvedValue([{ id: 'connection-1', authFailedAt: '2026-10-01T00:00:00.000Z' },{ id: 'connection-2', authFailedAt: null },]);await expect(teamsHealthCheckHandler()).resolves.toEqual({ status: 'OK' });++ expect(listTeamsConnectionsMock).toHaveBeenCalledExactlyOnceWith();+ });++ it('should let personal connections alone satisfy transcript imports', async () => {+ listTeamsConnectionsMock.mockResolvedValue([PERSONAL_CONNECTION]);++ await expect(teamsHealthCheckHandler()).resolves.toEqual({ status: 'OK' });++ expect(listTeamsConnectionsMock).toHaveBeenCalledExactlyOnceWith();});it('should ask to reconnect when every connection was rejected', async () => {- listConnectionsMock.mockResolvedValue([+ listTeamsConnectionsMock.mockResolvedValue([{ id: 'connection-1', authFailedAt: '2026-10-01T00:00:00.000Z' },]);@@ -56,6 +88,34 @@ describe('teamsHealthCheckHandler', () => {description: expect.stringContaining('Microsoft rejected the stored'),action: { label: 'Manage connection', location: '#general' },});++ expect(listTeamsConnectionsMock).toHaveBeenCalledExactlyOnceWith();+ });++ it('should ask for a workspace connection when chat only has personal ones', async () => {+ enableChat();+ listTeamsConnectionsMock.mockResolvedValue([PERSONAL_CONNECTION]);++ await expect(teamsHealthCheckHandler()).resolves.toEqual({+ status: 'WARNING',+ title: 'Microsoft Teams chat needs a workspace connection',+ description: expect.stringContaining('personal connections do not count'),+ action: { label: 'Add connection', location: '#general' },+ });++ expect(listTeamsConnectionsMock).toHaveBeenCalledExactlyOnceWith();+ });++ it('should report nothing for chat once a workspace connection works', async () => {+ enableChat();+ listTeamsConnectionsMock.mockResolvedValue([+ PERSONAL_CONNECTION,+ WORKSPACE_CONNECTION,+ ]);++ await expect(teamsHealthCheckHandler()).resolves.toEqual({ status: 'OK' });++ expect(listTeamsConnectionsMock).toHaveBeenCalledExactlyOnceWith();});it('should report nothing when no feature needs a connection', async () => {@@ -63,6 +123,6 @@ describe('teamsHealthCheckHandler', () => {await expect(teamsHealthCheckHandler()).resolves.toEqual({ status: 'OK' });- expect(listConnectionsMock).not.toHaveBeenCalled();+ expect(listTeamsConnectionsMock).not.toHaveBeenCalled();});});diff --git a/packages/twenty-apps/public/teams/src/logic-functions/teams-health-check.ts b/packages/twenty-apps/public/teams/src/logic-functions/teams-health-check.tsindex 061b5a63f71..bbb219e64a1 100644--- a/packages/twenty-apps/public/teams/src/logic-functions/teams-health-check.ts+++ b/packages/twenty-apps/public/teams/src/logic-functions/teams-health-check.ts@@ -3,13 +3,12 @@ import {type ApplicationHealthCheckResult,defineHealthCheck,} from 'twenty-sdk/define';-import { listConnections } from 'twenty-sdk/logic-function';import { isDefined } from 'twenty-sdk/utils';import { HEALTH_CHECK_UNIVERSAL_IDENTIFIER } from 'src/constants/universal-identifiers';import { isTeamsChatEnabled } from 'src/features/chat/logic-functions/utils/is-teams-chat-enabled';-import { TEAMS_PROVIDER_NAME } from 'src/features/transcripts/constants/teams-provider-name';import { isTeamsTranscriptImportEnabled } from 'src/features/transcripts/logic-functions/utils/is-teams-transcript-import-enabled';+import { listTeamsConnections } from 'src/features/transcripts/logic-functions/utils/list-teams-connections';export const teamsHealthCheckHandler =async (): Promise<ApplicationHealthCheckResult> => {@@ -17,9 +16,7 @@ export const teamsHealthCheckHandler =return { status: 'OK' };}- const connections = await listConnections({- providerName: TEAMS_PROVIDER_NAME,- });+ const connections = await listTeamsConnections();if (!isNonEmptyArray(connections)) {return {@@ -41,6 +38,21 @@ export const teamsHealthCheckHandler =};}+ const hasWorkingWorkspaceConnection = connections.some(+ (connection) =>+ connection.scope === 'WORKSPACE' && !isDefined(connection.authFailedAt),+ );++ if (isTeamsChatEnabled() && !hasWorkingWorkspaceConnection) {+ return {+ status: 'WARNING',+ title: 'Microsoft Teams chat needs a workspace connection',+ description:+ 'Chat only answers messages from the Microsoft organization of a working workspace-shared connection, and personal connections do not count. Add a workspace connection, or reconnect the existing one, to use chat.',+ action: { label: 'Add connection', location: '#general' },+ };+ }+return { status: 'OK' };};