feat: add web phone call for cal ai (#23527)

* feat: add web phone call for cal ai

* fix: web call

* refactor: improvements

* chore

* refactor: web call improvements

* chore: error message

* refactor: improvements

* fix: err

* refactor: feedback and improvements

* fix: type errors

* refactor: hasAvailable

* chore: use orgid

* fix: types

---------

Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
Udit TakkarandPeer Richelsen authored and GitHub committed 2025-09-10 12:41:10 -03:00
1 parent 2e96600529
commit a8a3e48465
22 files changed
+1043 -44

No files matched your search

@@ -327,6 +327,21 @@ export interface AIPhoneServiceProvider<T extends AIPhoneServiceProviderType = A
message: string;
}>;
/**
* Create a web call
*/
createWebCall(params: {
agentId: string;
userId: number;
teamId?: number;
timeZone: string;
eventTypeId: number;
}): Promise<{
callId: string;
accessToken: string;
agentId: string;
}>;
/**
* Update tools from event type ID
*/
@@ -266,6 +266,20 @@ export class RetellAIPhoneServiceProvider
return await this.service.createTestCall(params);
}
async createWebCall(params: {
agentId: string;
userId: number;
teamId?: number;
timeZone: string;
eventTypeId: number;
}): Promise<{
callId: string;
accessToken: string;
agentId: string;
}> {
return await this.service.createWebCall(params);
}
async updateToolsFromAgentId(
agentId: string,
data: { eventTypeId: number | null; timeZone: string; userId: number | null; teamId?: number | null }
@@ -220,6 +220,16 @@ export class RetellAIService {
return this.callService.createTestCall(params);
}
async createWebCall(params: {
agentId: string;
userId: number;
teamId?: number;
timeZone: string;
eventTypeId: number;
}) {
return this.callService.createWebCall(params);
}
async generatePhoneNumberCheckoutSession(params: {
userId: number;
teamId?: number;
@@ -12,6 +12,7 @@ import type {
RetellAgent,
CreatePhoneNumberParams,
CreatePhoneCallParams,
CreateWebCallParams,
ImportPhoneNumberParams,
} from "./types";
@@ -234,4 +235,17 @@ export class RetellSDKClient implements RetellAIRepository {
throw error;
}
}
async createWebCall(data: CreateWebCallParams) {
try {
const response = await this.client.call.createWebCall({
agent_id: data.agentId,
retell_llm_dynamic_variables: data.dynamicVariables,
});
return response;
} catch (error) {
this.logger.error("Failed to create web call", { error });
throw error;
}
}
}
@@ -166,6 +166,93 @@ export class CallService {
};
}
async createWebCall({
agentId,
userId,
teamId,
timeZone,
eventTypeId,
}: {
agentId: string;
userId: number;
teamId?: number;
timeZone: string;
eventTypeId: number;
}) {
if (!agentId?.trim()) {
throw new HttpError({
statusCode: 400,
message: "Agent ID is required and cannot be empty",
});
}
await this.validateCreditsForTestCall({ userId, teamId });
await checkRateLimitAndThrowError({
rateLimitingType: "core",
identifier: `web-call:${userId}`,
});
const agent = await this.agentRepository.findByIdWithCallAccess({
id: agentId,
userId,
});
if (!agent) {
throw new HttpError({
statusCode: 404,
message: "Agent not found or you don't have permission to use it.",
});
}
if (!agent.providerAgentId) {
throw new HttpError({
statusCode: 400,
message: "Agent provider ID not found.",
});
}
const dynamicVariables = {
EVENT_NAME: "Web Call Test with Agent",
EVENT_DATE: "Monday, January 15, 2025",
EVENT_TIME: "2:00 PM",
EVENT_END_TIME: "2:30 PM",
TIMEZONE: timeZone,
LOCATION: "Web Call",
ORGANIZER_NAME: "Cal.com AI Agent",
ATTENDEE_NAME: "Test User",
ATTENDEE_FIRST_NAME: "Test",
ATTENDEE_LAST_NAME: "User",
ATTENDEE_EMAIL: "[email protected]",
ATTENDEE_TIMEZONE: timeZone,
ADDITIONAL_NOTES: "This is a test web call to verify the AI phone agent",
EVENT_START_TIME_IN_ATTENDEE_TIMEZONE: "2:00 PM",
EVENT_END_TIME_IN_ATTENDEE_TIMEZONE: "2:30 PM",
eventTypeId: eventTypeId.toString(),
};
try {
const webCall = await this.retellRepository.createWebCall({
agentId: agent.providerAgentId,
dynamicVariables,
});
return {
callId: webCall.call_id,
accessToken: webCall.access_token,
agentId: webCall.agent_id,
};
} catch (error) {
this.logger.error("Failed to create web call in external AI service", {
agentId: agent.providerAgentId,
error,
});
throw new HttpError({
statusCode: 500,
message: "Failed to create web call",
});
}
}
private async validateCreditsForTestCall({ userId, teamId }: { userId: number; teamId?: number }) {
try {
const { CreditService } = await import("@calcom/features/ee/billing/credit-service");
@@ -86,6 +86,11 @@ export type CreatePhoneCallParams = {
toNumber: string;
dynamicVariables?: RetellDynamicVariables;
};
export type CreateWebCallParams = {
agentId: string;
dynamicVariables?: RetellDynamicVariables;
};
export type UpdatePhoneNumberParams = Retell.PhoneNumberUpdateParams;
export type ImportPhoneNumberParams = Retell.PhoneNumberImportParams;
export type RetellLLMGeneralTools = Retell.LlmCreateParams["general_tools"];
@@ -171,4 +176,7 @@ export interface RetellAIRepository {
// Call operations
createPhoneCall(data: CreatePhoneCallParams): Promise<RetellCall>;
createWebCall(
data: CreateWebCallParams
): Promise<{ call_id: string; access_token: string; agent_id: string }>;
}
@@ -42,7 +42,8 @@ import { Tooltip } from "@calcom/ui/components/tooltip";
import { DYNAMIC_TEXT_VARIABLES } from "../lib/constants";
import type { FormValues } from "../pages/workflow";
import { TestAgentDialog } from "./TestAgentDialog";
import { TestPhoneCallDialog } from "./TestPhoneCallDialog";
import { WebCallDialog } from "./WebCallDialog";
// Utility functions for prompt display
const cleanPromptForDisplay = (prompt: string): string => {
@@ -114,6 +115,7 @@ type AgentConfigurationSheetProps = {
onUpdate: (data: AgentFormValues) => void;
readOnly?: boolean;
teamId?: number;
isOrganization?: boolean;
workflowId?: string;
workflowStepId?: number;
activeTab?: "prompt" | "phoneNumber";
@@ -129,6 +131,7 @@ export function AgentConfigurationSheet({
onUpdate,
readOnly = false,
teamId,
isOrganization = false,
workflowId,
workflowStepId: _workflowStepId,
form,
@@ -141,6 +144,7 @@ export function AgentConfigurationSheet({
const [isImportDialogOpen, setIsImportDialogOpen] = useState(false);
const [showAdvancedFields, setShowAdvancedFields] = useState(false);
const [isTestAgentDialogOpen, setIsTestAgentDialogOpen] = useState(false);
const [isWebCallDialogOpen, setIsWebCallDialogOpen] = useState(false);
const [cancellingNumberId, setCancellingNumberId] = useState<number | null>(null);
const [numberToDelete, setNumberToDelete] = useState<string | null>(null);
// const [toolDialogOpen, setToolDialogOpen] = useState(false);
@@ -593,13 +597,39 @@ export function AgentConfigurationSheet({
</div>
</div>
<div className="flex items-center gap-1">
<Button
color="secondary"
onClick={() => setIsTestAgentDialogOpen(true)}
className="rounded-[10px]"
disabled={readOnly}>
{t("test_agent")}
</Button>
<Dropdown>
<DropdownMenuTrigger asChild>
<Button
color="secondary"
className="rounded-[10px]"
disabled={readOnly}
EndIcon="chevron-down">
{t("test_agent")}
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem>
<DropdownItem
type="button"
StartIcon="phone"
onClick={() => {
setIsTestAgentDialogOpen(true);
}}>
{t("phone_call")}
</DropdownItem>
</DropdownMenuItem>
<DropdownMenuItem>
<DropdownItem
type="button"
StartIcon="monitor"
onClick={() => {
setIsWebCallDialogOpen(true);
}}>
{t("web_call")}
</DropdownItem>
</DropdownMenuItem>
</DropdownMenuContent>
</Dropdown>
<Dropdown>
<DropdownMenuTrigger asChild>
<Button type="button" color="secondary" variant="icon" StartIcon="ellipsis" />
@@ -964,7 +994,7 @@ export function AgentConfigurationSheet({
</Dialog>
{agentId && (
<TestAgentDialog
<TestPhoneCallDialog
open={isTestAgentDialogOpen}
onOpenChange={setIsTestAgentDialogOpen}
agentId={agentId}
@@ -973,6 +1003,17 @@ export function AgentConfigurationSheet({
/>
)}
{agentId && (
<WebCallDialog
open={isWebCallDialogOpen}
onOpenChange={setIsWebCallDialogOpen}
agentId={agentId}
teamId={teamId}
isOrganization={isOrganization}
form={form}
/>
)}
<UIDialog open={cancellingNumberId !== null} onOpenChange={() => setCancellingNumberId(null)}>
<ConfirmationDialogContent
isPending={cancelSubscriptionMutation.isPending}
@@ -13,7 +13,7 @@ import { showToast } from "@calcom/ui/components/toast";
import type { FormValues } from "../pages/workflow";
interface TestAgentDialogProps {
interface TestPhoneCallDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
agentId: string;
@@ -21,7 +21,7 @@ interface TestAgentDialogProps {
form: UseFormReturn<FormValues>;
}
export function TestAgentDialog({ open, onOpenChange, agentId, teamId, form }: TestAgentDialogProps) {
export function TestPhoneCallDialog({ open, onOpenChange, agentId, teamId, form }: TestPhoneCallDialogProps) {
const { t } = useLocale();
const [testPhoneNumber, setTestPhoneNumber] = useState("");
@@ -58,8 +58,7 @@ export function TestAgentDialog({ open, onOpenChange, agentId, teamId, form }: T
};
return (
// Without modal={false}, the screen freezes when Sheet is open
<Dialog open={open} onOpenChange={onOpenChange} modal={false}>
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent
type="creation"
title={t("test_cal_ai_agent")}
@@ -0,0 +1,477 @@
import Link from "next/link";
import { useState, useEffect, useRef, useCallback } from "react";
import type { UseFormReturn } from "react-hook-form";
import type { RetellWebClient } from "retell-client-js-sdk";
import { Dialog } from "@calcom/features/components/controlled-dialog";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { trpc } from "@calcom/trpc/react";
import { Alert } from "@calcom/ui/components/alert";
import { Button } from "@calcom/ui/components/button";
import { DialogContent, DialogFooter } from "@calcom/ui/components/dialog";
import { Icon } from "@calcom/ui/components/icon";
import { showToast } from "@calcom/ui/components/toast";
import { Tooltip } from "@calcom/ui/components/tooltip";
import type { FormValues } from "../pages/workflow";
interface WebCallDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
agentId: string;
teamId?: number;
isOrganization?: boolean;
form: UseFormReturn<FormValues>;
}
interface TranscriptEntry {
speaker: "agent" | "user";
text: string;
timestamp: Date;
}
type CallStatus = "idle" | "connecting" | "active" | "ended" | "error";
export function WebCallDialog({
open,
onOpenChange,
agentId,
teamId,
isOrganization = false,
form,
}: WebCallDialogProps) {
const { t } = useLocale();
const [callStatus, setCallStatus] = useState<CallStatus>("idle");
const [transcript, setTranscript] = useState<TranscriptEntry[]>([]);
const [isMuted, setIsMuted] = useState(false);
const [callDuration, setCallDuration] = useState(0);
const [error, setError] = useState<string | null>(null);
const retellWebClientRef = useRef<RetellWebClient | null>(null);
const callStartTimeRef = useRef<Date | null>(null);
const durationIntervalRef = useRef<NodeJS.Timeout | null>(null);
const transcriptEndRef = useRef<HTMLDivElement>(null);
const callStatusRef = useRef<CallStatus>("idle");
const { data: hasCredits, isLoading: creditsLoading } = trpc.viewer.credits.hasAvailableCredits.useQuery(
{ teamId },
{ enabled: open }
);
const getBillingPath = () => {
if (!teamId) return "/settings/billing";
return isOrganization ? "/settings/organizations/billing" : `/settings/teams/${teamId}/billing`;
};
const createWebCallMutation = trpc.viewer.aiVoiceAgent.createWebCall.useMutation({
onSuccess: async (data) => {
try {
await startWebCall(data.accessToken);
} catch (error) {
console.error("Failed to start web call:", error);
setCallStatus("error");
setError(t("failed_to_start_web_call_try_again"));
}
},
onError: (error: { message: string }) => {
setCallStatus("error");
setError(error.message);
showToast(error.message, "error");
},
});
const startWebCall = async (accessToken: string) => {
try {
const { RetellWebClient } = await import("retell-client-js-sdk");
const retellWebClient = new RetellWebClient();
retellWebClientRef.current = retellWebClient;
retellWebClient.on("call_started", () => {
callStartTimeRef.current = new Date();
callStatusRef.current = "active";
setCallStatus("active");
startDurationTimer();
});
retellWebClient.on("call_ended", () => {
setCallStatus("ended");
stopDurationTimer();
});
retellWebClient.on("agent_start_talking", () => {
console.log("Agent started talking");
});
retellWebClient.on("agent_stop_talking", () => {
console.log("Agent stopped talking");
});
retellWebClient.on("update", (update: { transcript?: Array<{ role: string; content: string }> }) => {
console.log("📝 Received update event:", update);
if (update.transcript && Array.isArray(update.transcript)) {
console.log("📜 Transcript array received:", update.transcript);
try {
const newEntries: TranscriptEntry[] = update.transcript
.map((entry) => {
if (!entry.role || !entry.content) {
console.warn("⚠️ Invalid transcript entry:", entry);
return null;
}
const mappedEntry = {
speaker: entry.role === "agent" ? "agent" : "user",
text: entry.content,
timestamp: new Date(),
};
console.log("✅ Mapped transcript entry:", mappedEntry);
return mappedEntry;
})
.filter(Boolean) as TranscriptEntry[];
console.log("🔄 Setting transcript with entries:", newEntries.length, "entries");
console.log("📋 Current transcript state has:", transcript.length, "entries");
setTranscript(newEntries);
} catch (error) {
console.error("❌ Error processing transcript update:", error);
}
} else {
console.log(
"🚫 No transcript data in update or transcript is not an array:",
typeof update.transcript
);
}
});
retellWebClient.on("error", (error: Error | { message?: string }) => {
console.error("Web call error:", error);
setCallStatus("error");
setError(t("call_encountered_error_try_again"));
stopDurationTimer();
});
setCallStatus("connecting");
await retellWebClient.startCall({
accessToken: accessToken,
sampleRate: 24000,
emitRawAudioSamples: false,
});
} catch (error) {
console.error("Error starting web call:", error);
setCallStatus("error");
setError(t("failed_initialize_web_call_microphone_permissions"));
}
};
const startDurationTimer = useCallback(() => {
if (durationIntervalRef.current) {
clearInterval(durationIntervalRef.current);
durationIntervalRef.current = null;
}
if (!callStartTimeRef.current) {
return;
}
durationIntervalRef.current = setInterval(() => {
if (callStartTimeRef.current) {
const now = Date.now();
const startTime = callStartTimeRef.current.getTime();
const duration = Math.floor((now - startTime) / 1000);
if (duration >= 0) {
setCallDuration(duration);
}
}
}, 1000);
}, []);
const stopDurationTimer = () => {
if (durationIntervalRef.current) {
clearInterval(durationIntervalRef.current);
durationIntervalRef.current = null;
}
};
const handleStartCall = () => {
const firstEventTypeId = form.getValues("activeOn")?.[0]?.value;
if (!firstEventTypeId) {
showToast(t("choose_at_least_one_event_type_test_call"), "error");
return;
}
if (agentId) {
setError(null);
setTranscript([]);
setCallDuration(0);
createWebCallMutation.mutate({
agentId: agentId,
teamId: teamId,
eventTypeId: parseInt(firstEventTypeId, 10),
});
}
};
const handleEndCall = async () => {
if (retellWebClientRef.current && callStatus === "active") {
try {
await retellWebClientRef.current.stopCall();
setCallStatus("ended");
stopDurationTimer();
} catch (error) {
console.error("Error ending call:", error);
}
}
};
const handleToggleMute = async () => {
if (retellWebClientRef.current && callStatus === "active") {
try {
if (isMuted) {
await retellWebClientRef.current.unmute();
} else {
await retellWebClientRef.current.mute();
}
setIsMuted(!isMuted);
} catch (error) {
console.error("Error toggling mute:", error);
}
}
};
const formatDuration = (seconds: number) => {
const mins = Math.floor(seconds / 60);
const secs = seconds % 60;
return `${mins.toString().padStart(2, "0")}:${secs.toString().padStart(2, "0")}`;
};
const getStatusIcon = () => {
switch (callStatus) {
case "connecting":
return <Icon name="loader" className="h-4 w-4 animate-spin rounded-full" />;
case "active":
return <Icon name="phone" className="text-success h-4 w-4" />;
case "ended":
return <Icon name="phone-off" className="text-muted h-4 w-4" />;
case "error":
return <Icon name="triangle-alert" className="text-error h-4 w-4" />;
default:
return <Icon name="phone" className="text-subtle h-4 w-4" />;
}
};
const getStatusText = () => {
switch (callStatus) {
case "connecting":
return t("connecting_to_agent");
case "active":
return `${t("call_active")} - ${formatDuration(callDuration)}`;
case "ended":
return `${t("call_ended")} - ${formatDuration(callDuration)}`;
case "error":
return t("call_error");
default:
return t("ready_to_start_call");
}
};
useEffect(() => {
if (transcriptEndRef.current) {
// eslint-disable-next-line @calcom/eslint/no-scroll-into-view-embed
transcriptEndRef.current.scrollIntoView({ behavior: "smooth" });
}
}, [transcript]);
useEffect(() => {
return () => {
stopDurationTimer();
if (retellWebClientRef.current && callStatus === "active") {
try {
retellWebClientRef.current.stopCall();
} catch (error) {
console.error("Error stopping call during cleanup:", error);
}
}
};
}, [callStatus]);
useEffect(() => {
callStatusRef.current = callStatus;
if (callStatus === "active" && callStartTimeRef.current && !durationIntervalRef.current) {
startDurationTimer();
}
}, [callStatus, startDurationTimer]);
useEffect(() => {
return () => {
stopDurationTimer();
};
}, []);
const resetDialogState = () => {
setCallStatus("idle");
callStatusRef.current = "idle";
setTranscript([]);
setIsMuted(false);
setCallDuration(0);
setError(null);
callStartTimeRef.current = null;
stopDurationTimer();
retellWebClientRef.current = null;
};
return (
<Dialog
open={open}
onOpenChange={(open) => {
if (!open) {
if (retellWebClientRef.current) {
try {
retellWebClientRef.current.stopCall();
} catch (e) {
console.error("Error stopping call on close:", e);
}
}
resetDialogState();
}
onOpenChange(open);
}}>
<DialogContent
enableOverflow
type="creation"
title={t("web_call")}
description={t("test_your_agent_with_web_call")}>
{!creditsLoading && (
<Alert
severity="info"
CustomIcon="info"
title={t("credits_required")}
message={
hasCredits ? (
t("web_call_credits_info")
) : (
<>
{t("web_call_no_credits")}{" "}
<Link href={getBillingPath()} className="text-semantic-info underline">
{t("purchase_credits")}
</Link>
</>
)
}
/>
)}
<div className="mt-2 flex items-center justify-between rounded-lg border p-3">
<div className="flex items-center gap-2">
{getStatusIcon()}
<span className="text-sm font-medium">{getStatusText()}</span>
</div>
{callStatus === "active" && (
<div className="flex items-center gap-2">
<div className="bg-error h-2 w-2 animate-pulse rounded-full" />
<span className="text-subtle text-xs">{t("live")}</span>
</div>
)}
</div>
<div className="mt-2 rounded-lg border p-3 placeholder:min-h-[300px]">
<div className="mb-3 flex items-center justify-between">
<h4 className="text-sm font-medium">{t("transcript")}</h4>
{transcript.length > 0 && (
<Button
type="button"
color="secondary"
size="sm"
variant="icon"
onClick={() => setTranscript([])}
disabled={callStatus === "active"}>
<Icon name="trash" className="h-4 w-4" />
</Button>
)}
</div>
<div className="h-60 space-y-3 overflow-y-auto p-2">
{transcript.length === 0 ? (
<div className="flex h-40 items-center justify-center text-center">
<div>
<Icon name="message-circle" className="text-subtle mx-auto h-8 w-8" />
<p className="text-subtle mt-2 text-sm">
{callStatus === "idle"
? t("start_call_to_see_conversation")
: t("waiting_for_conversation")}
</p>
</div>
</div>
) : (
transcript.map((entry, index) => (
<div
key={index}
className={`flex gap-2 ${entry.speaker === "agent" ? "justify-start" : "justify-end"}`}>
<div
className={`max-w-[80%] rounded-lg px-3 py-2 text-sm ${
entry.speaker === "agent"
? "border-brand bg-brand/10 text-brand-emphasis border"
: "border-subtle bg-subtle text-emphasis border"
}`}>
<div className="mb-1 flex items-center gap-2">
<span className="text-xs font-medium">
{entry.speaker === "agent" ? t("ai_agent") : t("you")}
</span>
</div>
<p>{entry.text}</p>
</div>
</div>
))
)}
<div ref={transcriptEndRef} />
</div>
</div>
{error && callStatus === "error" && (
<div className="border-error bg-error/10 rounded-lg p-3">
<div className="flex items-center gap-2">
<Icon name="triangle-alert" className="text-error h-6 w-6" />
<span className="text-error text-sm">{error}</span>
</div>
</div>
)}
<DialogFooter showDivider className="mt-6">
<div className="flex gap-2">
{callStatus === "active" && (
<Button type="button" color="secondary" onClick={handleToggleMute} variant="icon">
<Icon name={isMuted ? "mic-off" : "mic"} className="h-4 w-4" />
</Button>
)}
{callStatus === "idle" ||
callStatus === "error" ||
callStatus === "ended" ||
callStatus === "connecting" ? (
<Tooltip content={!hasCredits ? t("credits_required_tooltip") : undefined}>
<Button
type="button"
onClick={handleStartCall}
loading={createWebCallMutation.isPending || callStatus === "connecting"}
disabled={!hasCredits || createWebCallMutation.isPending || callStatus === "connecting"}>
<Icon name="phone" className="mr-2 h-4 w-4" />
{callStatus === "connecting" ? t("connecting") : t("start_web_call")}
</Button>
</Tooltip>
) : (
<Button
type="button"
color="destructive"
onClick={handleEndCall}
disabled={callStatus !== "active"}>
<Icon name="phone-off" className="mr-2 h-4 w-4" />
{t("end_call")}
</Button>
)}
</div>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
@@ -64,8 +64,9 @@ import emailRatingTemplate from "../lib/reminders/templates/emailRatingTemplate"
import emailReminderTemplate from "../lib/reminders/templates/emailReminderTemplate";
import type { FormValues } from "../pages/workflow";
import { AgentConfigurationSheet } from "./AgentConfigurationSheet";
import { TestAgentDialog } from "./TestAgentDialog";
import { TestPhoneCallDialog } from "./TestPhoneCallDialog";
import { TimeTimeUnitInput } from "./TimeTimeUnitInput";
import { WebCallDialog } from "./WebCallDialog";
type User = RouterOutputs["viewer"]["me"]["get"];
@@ -209,6 +210,7 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
const verifiedEmails = _verifiedEmails || [];
const [isAdditionalInputsDialogOpen, setIsAdditionalInputsDialogOpen] = useState(false);
const [isTestAgentDialogOpen, setIsTestAgentDialogOpen] = useState(false);
const [isWebCallDialogOpen, setIsWebCallDialogOpen] = useState(false);
const [isUnsubscribeDialogOpen, setIsUnsubscribeDialogOpen] = useState(false);
const [isDeleteStepDialogOpen, setIsDeleteStepDialogOpen] = useState(false);
@@ -800,26 +802,57 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
</div>
<div className="flex items-center gap-1">
{arePhoneNumbersActive.length > 0 ? (
<Button
color="secondary"
onClick={() => setIsTestAgentDialogOpen(true)}
disabled={props.readOnly || !arePhoneNumbersActive.length}>
<Icon name="phone" className="mr-2 h-4 w-4" />
{t("test_agent")}
</Button>
<Dropdown>
<DropdownMenuTrigger asChild>
<Button
color="secondary"
className="rounded-[10px]"
disabled={props.readOnly}
EndIcon="chevron-down">
{t("test_agent")}
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem>
<DropdownItem
type="button"
StartIcon="phone"
onClick={() => setIsTestAgentDialogOpen(true)}>
{t("phone_call")}
</DropdownItem>
</DropdownMenuItem>
<DropdownMenuItem>
<DropdownItem
type="button"
StartIcon="monitor"
onClick={() => setIsWebCallDialogOpen(true)}>
{t("web_call")}
</DropdownItem>
</DropdownMenuItem>
</DropdownMenuContent>
</Dropdown>
) : (
<Button
color="secondary"
onClick={() => {
setAgentConfigurationSheet((prev) => ({
...prev,
open: true,
activeTab: "phoneNumber",
}));
}}
disabled={props.readOnly}>
{t("connect_phone_number")}
</Button>
<>
<Button
color="secondary"
onClick={() => {
setAgentConfigurationSheet((prev) => ({
...prev,
open: true,
activeTab: "phoneNumber",
}));
}}
disabled={props.readOnly}>
{t("connect_phone_number")}
</Button>
<Button
color="secondary"
onClick={() => setIsWebCallDialogOpen(true)}
disabled={props.readOnly}
StartIcon="monitor">
{t("test_web_call")}
</Button>
</>
)}
<Dropdown>
<DropdownMenuTrigger asChild>
@@ -1447,6 +1480,7 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
}}
readOnly={props.readOnly}
teamId={teamId}
isOrganization={props.isOrganization}
workflowId={params?.workflow as string}
workflowStepId={step?.id}
form={form}
@@ -1454,7 +1488,7 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
)}
{stepAgentId && (
<TestAgentDialog
<TestPhoneCallDialog
open={isTestAgentDialogOpen}
onOpenChange={setIsTestAgentDialogOpen}
agentId={stepAgentId}
@@ -1463,6 +1497,17 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
/>
)}
{stepAgentId && (
<WebCallDialog
open={isWebCallDialogOpen}
onOpenChange={setIsWebCallDialogOpen}
agentId={stepAgentId}
teamId={teamId}
isOrganization={props.isOrganization}
form={form}
/>
)}
{/* Unsubscribe Confirmation Dialog */}
<Dialog open={isUnsubscribeDialogOpen} onOpenChange={setIsUnsubscribeDialogOpen}>
<DialogContent type="creation" title={t("unsubscribe_phone_number")}>