import { useState } from "react"; import { useMutation } from "@tanstack/react-query"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { chatEndpointsApi, type ChatEndpoint, type ChatEndpointSetupAction, } from "@/api/chatEndpoints"; import { sanitizedSetupErrorMessage } from "./chat-setup-error"; export function PhotonConnectStep({ endpoint, agentName, repairing, pending, onAction, }: { endpoint: ChatEndpoint; agentName: string; repairing: boolean; pending: boolean; onAction( action: ChatEndpointSetupAction, values?: Record, ): void; }) { const [projectId, setProjectId] = useState(endpoint.providerAccountId ?? ""); const [projectSecret, setProjectSecret] = useState(""); const [lineId, setLineId] = useState(""); const inspection = useMutation({ mutationFn: () => chatEndpointsApi.inspectPhoton(endpoint.id, { projectId: projectId.trim(), projectSecret, }), onSuccess: (result) => { const eligible = result.lines.filter((line) => line.eligible); setLineId(eligible.length === 1 ? eligible[0].lineId : ""); }, }); const resetInspection = () => { inspection.reset(); setLineId(""); }; return (

Connect iMessage Photon

Connect {agentName} to Photon Cloud. Pro supports direct messages through a shared line. Dedicated numbers also support individually enabled groups.

Photon dashboard {" · "} Photon line setup

{repairing && (

Reconnect keeps this project and{" "} {endpoint.photonAllocation === "shared" ? "shared DM allocation" : endpoint.botExternalId ?? "dedicated number"}. Leave the secret blank to reuse the saved connection.

)} {inspection.error ? (

{sanitizedSetupErrorMessage(inspection.error, { projectSecret })}

) : null} {inspection.data && (
{inspection.data.allocation === "shared" ? "Shared DMs" : "Dedicated numbers"} in {inspection.data.projectName} {!inspection.data.eligible && (

{inspection.data.allocation === "shared" ? "This shared project already belongs to another channel. Use a separate Photon project for each agent." : "No eligible dedicated number is available. Check the line allocation in Photon and existing Paperclip channels."}

)} {inspection.data.allocation === "shared" && inspection.data.eligible && (

Direct messages only. Enroll each test sender in your Photon project's Users page, then use the number Photon assigns to that sender. Paperclip identity linking is still required. Groups cannot be enabled on this channel.

)} {inspection.data.lines.map((line) => ( ))}
)}
); }