Skip to content

The open alternative to Salesforce, designed for AI.

617 B
Raw Blame
import { isDefined } from 'twenty-shared/utils';

import { type AgentChatChannel } from '@/ai/types/AgentChatChannel';

export const getAiChatThreadChannelIdOutsideInbox = ({
  threadChannelId,
  channels,
}: {
  threadChannelId: string | null | undefined;
  channels: AgentChatChannel[] | null;
}) => {
  if (!isDefined(threadChannelId)) {
    return null;
  }

  if (!isDefined(channels)) {
    return threadChannelId;
  }

  const isThreadChannelAccessible = channels.some(
    ({ id, isAccessible }) => isAccessible && id === threadChannelId,
  );

  return isThreadChannelAccessible ? threadChannelId : null;
};