The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
import { defineLogicFunction } from 'twenty-sdk/define';
import { TEAMS_TENANT_RELEASE_UNIVERSAL_IDENTIFIER } from 'src/features/chat/constants/universal-identifiers';
import { releaseTeamsConnectionTenant } from 'src/features/chat/logic-functions/utils/release-teams-connection-tenant';
import { deleteTeamsTranscriptHistoryKvKeys } from 'src/features/transcripts/logic-functions/utils/delete-teams-transcript-history-kv-keys';
import { unregisterTeamsTranscriptSubscription } from 'src/features/transcripts/logic-functions/utils/unregister-teams-transcript-subscription';
export const teamsTenantReleaseHandler = async (payload: {
connectedAccountId: string;
}) => {
const [tenantRelease, transcriptUnregistration, transcriptHistoryDeletion] =
await Promise.allSettled([
releaseTeamsConnectionTenant(payload),
unregisterTeamsTranscriptSubscription(payload),
deleteTeamsTranscriptHistoryKvKeys(payload),
]);
if (tenantRelease.status === 'rejected') {
throw tenantRelease.reason;
}
if (transcriptUnregistration.status === 'rejected') {
throw transcriptUnregistration.reason;
}
if (transcriptHistoryDeletion.status === 'rejected') {
throw transcriptHistoryDeletion.reason;
}
return { ...tenantRelease.value, ...transcriptUnregistration.value };
};
export default defineLogicFunction({
universalIdentifier: TEAMS_TENANT_RELEASE_UNIVERSAL_IDENTIFIER,
name: 'teams-tenant-release',
description:
'Runs when a Microsoft Teams connection is removed. Releases the teams-tenant:<tenant_id> claim that connection took, unless another connection in this workspace still holds the same tenant, so another workspace can connect it. Also deletes the Microsoft Graph transcript subscription and the transcript history import state of that connection.',
timeoutSeconds: 30,
handler: teamsTenantReleaseHandler,
});