mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-06-28 08:49:42 +02:00
feat: tansfer calls with aasterisk (#171)
* feat: tansfer calls with aasterisk * chore: format code with pre-commit script * chore: refactor code * refactor: add call strategies, cleanup transfer events * fix: docker compose, add missing files from merge conflicts * chore: update pipecat * docs: restructure & add mintilify pages for tool * chore: upgrade pipecat
This commit is contained in:
parent
9e058699c5
commit
bd07b753cd
19 changed files with 1043 additions and 106 deletions
|
|
@ -1,5 +1,7 @@
|
|||
"use client";
|
||||
|
||||
import {useState } from "react";
|
||||
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
|
|
@ -37,20 +39,46 @@ export function TransferCallToolConfig({
|
|||
timeout,
|
||||
onTimeoutChange,
|
||||
}: TransferCallToolConfigProps) {
|
||||
// Basic E.164 validation pattern
|
||||
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 phoneNumberError = destination && !isValidPhoneNumber(destination);
|
||||
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 (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Transfer Call Configuration</CardTitle>
|
||||
<CardDescription>
|
||||
Configure call transfer settings (Twilio only)
|
||||
Configure call transfer settings. Supports phone numbers (Twilio) and SIP endpoints (Asterisk ARI).
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-6">
|
||||
|
|
@ -80,21 +108,31 @@ export function TransferCallToolConfig({
|
|||
</div>
|
||||
|
||||
<div className="grid gap-2 pt-4 border-t">
|
||||
<Label>Destination Phone Number</Label>
|
||||
<Label>Transfer Destination</Label>
|
||||
<Label className="text-xs text-muted-foreground">
|
||||
Phone number to transfer the call to (E.164 format with country code)
|
||||
{sipMode
|
||||
? "SIP endpoint to transfer the call to (e.g., PJSIP/1234 or SIP/extension@domain.com)"
|
||||
: "Phone number to transfer the call to (E.164 format with country code)"
|
||||
}
|
||||
</Label>
|
||||
<Input
|
||||
value={destination}
|
||||
onChange={(e) => onDestinationChange(e.target.value)}
|
||||
placeholder="+1234567890"
|
||||
className={phoneNumberError ? "border-red-500 focus:border-red-500" : ""}
|
||||
placeholder={sipMode ? "PJSIP/1234 or SIP/extension@domain.com" : "+1234567890"}
|
||||
className={destinationError ? "border-red-500 focus:border-red-500" : ""}
|
||||
/>
|
||||
{phoneNumberError && (
|
||||
{destinationError && (
|
||||
<Label className="text-xs text-red-500">
|
||||
Please enter a valid phone number in E.164 format (e.g., +1234567890)
|
||||
{destinationError}
|
||||
</Label>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
className="text-xs text-muted-foreground hover:text-foreground underline w-fit"
|
||||
onClick={handleSipModeToggle}
|
||||
>
|
||||
{sipMode ? "Use phone number instead" : "Use SIP endpoint instead"}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 pt-4 border-t">
|
||||
|
|
|
|||
|
|
@ -198,10 +198,14 @@ export default function ToolDetailPage() {
|
|||
|
||||
// Validation based on tool type
|
||||
if (tool.category === "transfer_call") {
|
||||
// Validate destination phone number for Transfer Call tools
|
||||
// Validate destination for Transfer Call tools (supports both E.164 and SIP endpoints)
|
||||
const e164Pattern = /^\+[1-9]\d{1,14}$/;
|
||||
if (!transferDestination || !e164Pattern.test(transferDestination)) {
|
||||
setError("Please enter a valid phone number in E.164 format (e.g., +1234567890)");
|
||||
const sipPattern = /^(PJSIP|SIP)\/[\w\-\.@]+$/i;
|
||||
const isValidE164 = e164Pattern.test(transferDestination);
|
||||
const isValidSip = sipPattern.test(transferDestination);
|
||||
|
||||
if (!transferDestination || (!isValidE164 && !isValidSip)) {
|
||||
setError("Please enter a valid phone number (E.164 format) or SIP endpoint (e.g., PJSIP/1234)");
|
||||
return;
|
||||
}
|
||||
} else if (tool.category !== "end_call") {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue