"use client"; import { AlertCircle } from "lucide-react"; import {useState } from "react"; import type { RecordingResponseSchema } from "@/client/types.gen"; import { RecordingSelect } from "@/components/flow/TextOrAudioInput"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; import { Textarea } from "@/components/ui/textarea"; import { type EndCallMessageType } from "../../config"; export interface TransferCallToolConfigProps { name: string; onNameChange: (name: string) => void; description: string; onDescriptionChange: (description: string) => void; destination: string; onDestinationChange: (destination: string) => void; messageType: EndCallMessageType; onMessageTypeChange: (messageType: EndCallMessageType) => void; customMessage: string; onCustomMessageChange: (message: string) => void; audioRecordingId: string; onAudioRecordingIdChange: (id: string) => void; recordings?: RecordingResponseSchema[]; timeout?: number; // Make optional to match API type onTimeoutChange: (timeout: number) => void; } export function TransferCallToolConfig({ name, onNameChange, description, onDescriptionChange, destination, onDestinationChange, messageType, onMessageTypeChange, customMessage, onCustomMessageChange, audioRecordingId, onAudioRecordingIdChange, recordings = [], timeout, onTimeoutChange, }: TransferCallToolConfigProps) { const [sipMode, setSipMode] = useState(() => /^(PJSIP|SIP)\//i.test(destination)); // Validation patterns const isValidPhoneNumber = (phone: string): boolean => { const e164Pattern = /^\+[1-9]\d{1,14}$/; return e164Pattern.test(phone); }; const isValidSipEndpoint = (endpoint: string): boolean => { const sipPattern = /^(PJSIP|SIP)\/[\w\-\.@]+$/i; return sipPattern.test(endpoint); }; const getValidationError = (): string | null => { if (!destination) return null; if (sipMode) { return isValidSipEndpoint(destination) ? null : "Please enter a valid SIP endpoint (e.g., PJSIP/1234 or SIP/extension@domain.com)"; } else { return isValidPhoneNumber(destination) ? null : "Please enter a valid phone number in E.164 format (e.g., +1234567890)"; } }; const destinationError = getValidationError(); const handleSipModeToggle = () => { setSipMode(!sipMode); onDestinationChange(""); // Clear destination when switching modes }; return ( Transfer Call Configuration Configure call transfer settings. Supports phone numbers (Twilio) and SIP endpoints (Asterisk ARI).
onNameChange(e.target.value)} placeholder="e.g., Transfer Call" />