Skip to content

The open alternative to Salesforce, designed for AI.

720 B
Raw Blame
import { isNonEmptyString } from '@sniptt/guards';
import { isDefined } from 'twenty-sdk/utils';

import { findClaimedWorkspaceId } from 'src/logic-functions/utils/find-claimed-workspace-id';

export const resolveTargetWorkspaceId = async (
  teamId: string | undefined,
): Promise<string> => {
  if (!isNonEmptyString(teamId)) {
    throw new Error(
      'Slack request has no team id; cannot resolve the target workspace',
    );
  }

  const claimedWorkspaceId = await findClaimedWorkspaceId(teamId);

  if (!isDefined(claimedWorkspaceId)) {
    throw new Error(
      `No workspace has claimed Slack team ${teamId}. Connect the Slack app in the target workspace first.`,
    );
  }

  return claimedWorkspaceId;
};