From 5c700609924a838e6c790fd8c536d1583abaf104 Mon Sep 17 00:00:00 2001 From: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Date: Tue, 16 Sep 2025 20:15:11 +0530 Subject: [PATCH] feat: voice and language support in cal.ai (#23865) * feat: lang support * fix: type errors * feat: select voice agent * refactor: address feedback * refactor: address feedback * refactor: missing import * fix: types --- apps/web/public/icons/sprite.svg | 7 + apps/web/public/static/locales/en/common.json | 8 + .../interfaces/AIPhoneService.interface.ts | 9 + .../retellAI/RetellAIPhoneServiceProvider.ts | 7 +- .../providers/retellAI/RetellAIService.ts | 8 + .../providers/retellAI/RetellSDKClient.ts | 13 ++ .../calAIPhone/providers/retellAI/index.ts | 4 + .../retellAI/services/AgentService.ts | 14 +- .../retellAI/services/VoiceService.ts | 30 +++ .../calAIPhone/providers/retellAI/types.ts | 4 + .../components/AgentConfigurationSheet.tsx | 99 +++++++- .../components/VoiceSelectionDialog.tsx | 217 ++++++++++++++++++ .../ee/workflows/components/WebCallDialog.tsx | 3 +- .../ee/workflows/hooks/useVoicePreview.ts | 78 +++++++ .../routers/viewer/aiVoiceAgent/_router.ts | 8 + .../viewer/aiVoiceAgent/listVoices.handler.ts | 15 ++ .../viewer/aiVoiceAgent/update.handler.ts | 1 + .../viewer/aiVoiceAgent/update.schema.ts | 42 ++++ packages/ui/components/icon/icon-list.mjs | 2 + packages/ui/components/icon/icon-names.ts | 2 + 20 files changed, 563 insertions(+), 8 deletions(-) create mode 100644 packages/features/calAIPhone/providers/retellAI/services/VoiceService.ts create mode 100644 packages/features/ee/workflows/components/VoiceSelectionDialog.tsx create mode 100644 packages/features/ee/workflows/hooks/useVoicePreview.ts create mode 100644 packages/trpc/server/routers/viewer/aiVoiceAgent/listVoices.handler.ts diff --git a/apps/web/public/icons/sprite.svg b/apps/web/public/icons/sprite.svg index 805a734f80..182b16ee59 100644 --- a/apps/web/public/icons/sprite.svg +++ b/apps/web/public/icons/sprite.svg @@ -512,6 +512,10 @@ + + + + @@ -533,6 +537,9 @@ + + + diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index 6ab68e9423..1225495428 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -3704,5 +3704,13 @@ "start_from_scratch_description": "Create your own workflow from scratch.", "cal_ai_template_title": "Cal.ai template", "cal_ai_template_description": "AI agents that book meetings, send reminders, and follow up!", + "voice": "Voice", + "select_voice": "Select Voice", + "select_voice_for_agent": "Select a voice for your agent", + "choose_a_voice_for_your_agent": "Choose a voice for your agent", + "trait": "Trait", + "voice_id": "Voice ID", + "use_voice": "Use Voice", + "current_voice": "Current Voice", "ADD_NEW_STRINGS_ABOVE_THIS_LINE_TO_PREVENT_MERGE_CONFLICTS": "↑↑↑↑↑↑↑↑↑↑↑↑↑ Add your new strings above here ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑" } diff --git a/packages/features/calAIPhone/interfaces/AIPhoneService.interface.ts b/packages/features/calAIPhone/interfaces/AIPhoneService.interface.ts index 6a703503ad..8371517361 100644 --- a/packages/features/calAIPhone/interfaces/AIPhoneService.interface.ts +++ b/packages/features/calAIPhone/interfaces/AIPhoneService.interface.ts @@ -96,6 +96,9 @@ export type AIPhoneServiceListCallsResponse< T extends AIPhoneServiceProviderType = AIPhoneServiceProviderType > = AIPhoneServiceProviderTypeMap[T]["ListCallsResponse"]; +export type AIPhoneServiceVoice = + AIPhoneServiceProviderTypeMap[T]["Voice"]; + export interface AIPhoneServiceDeletion { modelId?: string; agentId?: string; @@ -311,6 +314,7 @@ export interface AIPhoneServiceProvider; voiceId?: string; + language?: string; }): Promise<{ message: string }>; /** @@ -374,6 +378,11 @@ export interface AIPhoneServiceProvider>; + + /** + * List available voices + */ + listVoices(): Promise[]>; } /** diff --git a/packages/features/calAIPhone/providers/retellAI/RetellAIPhoneServiceProvider.ts b/packages/features/calAIPhone/providers/retellAI/RetellAIPhoneServiceProvider.ts index 5e280cff82..a4d513cae5 100644 --- a/packages/features/calAIPhone/providers/retellAI/RetellAIPhoneServiceProvider.ts +++ b/packages/features/calAIPhone/providers/retellAI/RetellAIPhoneServiceProvider.ts @@ -22,7 +22,7 @@ import type { AgentRepositoryInterface } from "../interfaces/AgentRepositoryInte import type { PhoneNumberRepositoryInterface } from "../interfaces/PhoneNumberRepositoryInterface"; import type { TransactionInterface } from "../interfaces/TransactionInterface"; import { RetellAIService } from "./RetellAIService"; -import type { RetellAIRepository } from "./types"; +import type { RetellAIRepository, Language } from "./types"; export class RetellAIPhoneServiceProvider implements AIPhoneServiceProvider @@ -243,6 +243,7 @@ export class RetellAIPhoneServiceProvider beginMessage?: string | null; generalTools?: AIPhoneServiceTools; voiceId?: string; + language?: Language; }): Promise<{ message: string }> { return await this.service.updateAgentConfiguration(params); } @@ -302,4 +303,8 @@ export class RetellAIPhoneServiceProvider }) { return await this.service.listCalls(params); } + + async listVoices() { + return await this.service.listVoices(); + } } diff --git a/packages/features/calAIPhone/providers/retellAI/RetellAIService.ts b/packages/features/calAIPhone/providers/retellAI/RetellAIService.ts index 850e59c8f6..c0e1952775 100644 --- a/packages/features/calAIPhone/providers/retellAI/RetellAIService.ts +++ b/packages/features/calAIPhone/providers/retellAI/RetellAIService.ts @@ -12,6 +12,7 @@ import { AgentService } from "./services/AgentService"; import { BillingService } from "./services/BillingService"; import { CallService } from "./services/CallService"; import { PhoneNumberService } from "./services/PhoneNumberService"; +import { VoiceService } from "./services/VoiceService"; import type { RetellLLM, RetellCall, @@ -32,6 +33,7 @@ export class RetellAIService { private billingService: BillingService; private callService: CallService; private phoneNumberService: PhoneNumberService; + private voiceService: VoiceService; constructor( private repository: RetellAIRepository, @@ -49,6 +51,7 @@ export class RetellAIService { phoneNumberRepository, transactionManager ); + this.voiceService = new VoiceService(repository); // Inject RetellAIService reference into CallService this.callService.setRetellAIService(this); @@ -171,6 +174,7 @@ export class RetellAIService { beginMessage?: string | null; generalTools?: RetellLLMGeneralTools; voiceId?: string; + language?: Language; }) { return this.agentService.updateAgentConfiguration({ ...params, @@ -254,4 +258,8 @@ export class RetellAIService { }) { return this.callService.listCalls(params); } + + async listVoices() { + return this.voiceService.listVoices(); + } } diff --git a/packages/features/calAIPhone/providers/retellAI/RetellSDKClient.ts b/packages/features/calAIPhone/providers/retellAI/RetellSDKClient.ts index 89b3234e98..3bc5eb7282 100644 --- a/packages/features/calAIPhone/providers/retellAI/RetellSDKClient.ts +++ b/packages/features/calAIPhone/providers/retellAI/RetellSDKClient.ts @@ -16,6 +16,7 @@ import type { ImportPhoneNumberParams, RetellCallListParams, RetellCallListResponse, + RetellVoice, } from "./types"; const RETELL_API_KEY = process.env.RETELL_AI_KEY; @@ -270,4 +271,16 @@ export class RetellSDKClient implements RetellAIRepository { throw error; } } + + async listVoices(): Promise { + + try { + const response = await this.client.voice.list(); + + return response; + } catch (error) { + this.logger.error("Failed to list voices", { error }); + throw error; + } + } } diff --git a/packages/features/calAIPhone/providers/retellAI/index.ts b/packages/features/calAIPhone/providers/retellAI/index.ts index 139280b91c..c08deecd18 100644 --- a/packages/features/calAIPhone/providers/retellAI/index.ts +++ b/packages/features/calAIPhone/providers/retellAI/index.ts @@ -21,6 +21,7 @@ import type { RetellDynamicVariables, RetellCallListParams, RetellCallListResponse, + RetellVoice, } from "./types"; export { RetellAIService } from "./RetellAIService"; @@ -30,6 +31,7 @@ export { AgentService } from "./services/AgentService"; export { BillingService } from "./services/BillingService"; export { CallService } from "./services/CallService"; export { PhoneNumberService } from "./services/PhoneNumberService"; +export { VoiceService } from "./services/VoiceService"; export { RetellAIPhoneServiceProvider } from "./RetellAIPhoneServiceProvider"; export { RetellAIPhoneServiceProviderFactory } from "./RetellAIPhoneServiceProviderFactory"; @@ -65,6 +67,7 @@ export type { RetellDynamicVariables, RetellCallListParams, RetellCallListResponse, + RetellVoice, }; export interface RetellAIPhoneServiceProviderTypeMap { @@ -83,6 +86,7 @@ export interface RetellAIPhoneServiceProviderTypeMap { AgentWithDetails: RetellAgentWithDetails; ListCallsParams: RetellCallListParams; ListCallsResponse: RetellCallListResponse; + Voice: RetellVoice; } // ===== USAGE EXAMPLES ===== diff --git a/packages/features/calAIPhone/providers/retellAI/services/AgentService.ts b/packages/features/calAIPhone/providers/retellAI/services/AgentService.ts index 666c326f64..6c867c9c56 100644 --- a/packages/features/calAIPhone/providers/retellAI/services/AgentService.ts +++ b/packages/features/calAIPhone/providers/retellAI/services/AgentService.ts @@ -507,6 +507,7 @@ export class AgentService { beginMessage, generalTools, voiceId, + language, updateLLMConfiguration, }: { id: string; @@ -517,6 +518,7 @@ export class AgentService { beginMessage?: string | null; generalTools?: AIPhoneServiceTools; voiceId?: string; + language?: Language; updateLLMConfiguration: ( llmId: string, data: AIPhoneServiceUpdateModelParams @@ -539,7 +541,8 @@ export class AgentService { generalPrompt !== undefined || beginMessage !== undefined || generalTools !== undefined || - voiceId !== undefined; + voiceId !== undefined || + language !== undefined; if (hasRetellUpdates) { try { @@ -558,10 +561,11 @@ export class AgentService { await updateLLMConfiguration(llmId, llmUpdateData); } - if (voiceId) { - await this.updateAgent(agent.providerAgentId, { - voice_id: voiceId, - }); + if (voiceId || language) { + const agentUpdateData: Parameters[1] = {}; + if (voiceId) agentUpdateData.voice_id = voiceId; + if (language) agentUpdateData.language = language; + await this.updateAgent(agent.providerAgentId, agentUpdateData); } } catch (error) { this.logger.error("Failed to update agent configuration in external AI service", { diff --git a/packages/features/calAIPhone/providers/retellAI/services/VoiceService.ts b/packages/features/calAIPhone/providers/retellAI/services/VoiceService.ts new file mode 100644 index 0000000000..d96aa71e15 --- /dev/null +++ b/packages/features/calAIPhone/providers/retellAI/services/VoiceService.ts @@ -0,0 +1,30 @@ +import { HttpError } from "@calcom/lib/http-error"; +import logger from "@calcom/lib/logger"; + +import type { RetellAIRepository, RetellVoice } from "../types"; + +export class VoiceService { + private logger = logger.getSubLogger({ prefix: ["VoiceService"] }); + + constructor(private retellRepository: RetellAIRepository) {} + + async listVoices(): Promise { + try { + const voices = await this.retellRepository.listVoices(); + + this.logger.info("Retrieved voices successfully", { + count: voices.length, + }); + + return voices; + } catch (error) { + this.logger.error("Failed to list voices from external AI service", { + error, + }); + throw new HttpError({ + statusCode: 500, + message: "Failed to retrieve available voices. Please try again.", + }); + } + } +} \ No newline at end of file diff --git a/packages/features/calAIPhone/providers/retellAI/types.ts b/packages/features/calAIPhone/providers/retellAI/types.ts index 4ff785c4b9..67ee01fac5 100644 --- a/packages/features/calAIPhone/providers/retellAI/types.ts +++ b/packages/features/calAIPhone/providers/retellAI/types.ts @@ -6,6 +6,7 @@ export type RetellLLM = Retell.LlmResponse; export type RetellPhoneNumber = Retell.PhoneNumberResponse; export type RetellCall = Retell.PhoneCallResponse; export type RetellDynamicVariables = { [key: string]: unknown }; +export type RetellVoice = Retell.VoiceResponse; export type RetellAgent = Retell.AgentResponse; @@ -186,4 +187,7 @@ export interface RetellAIRepository { createWebCall( data: CreateWebCallParams ): Promise<{ call_id: string; access_token: string; agent_id: string }>; + + // Voice operations + listVoices(): Promise; } diff --git a/packages/features/ee/workflows/components/AgentConfigurationSheet.tsx b/packages/features/ee/workflows/components/AgentConfigurationSheet.tsx index 5d1101bbb1..41b35a4a4f 100644 --- a/packages/features/ee/workflows/components/AgentConfigurationSheet.tsx +++ b/packages/features/ee/workflows/components/AgentConfigurationSheet.tsx @@ -6,6 +6,7 @@ import type { UseFormReturn } from "react-hook-form"; import { z } from "zod"; import { Dialog } from "@calcom/features/components/controlled-dialog"; +import type { Language } from "@calcom/features/calAIPhone/providers/retellAI/types"; import { CAL_AI_PHONE_NUMBER_MONTHLY_PRICE } from "@calcom/lib/constants"; import { formatPhoneNumber } from "@calcom/lib/formatPhoneNumber"; import { useLocale } from "@calcom/lib/hooks/useLocale"; @@ -27,7 +28,7 @@ import { } from "@calcom/ui/components/dropdown"; import { AddVariablesDropdown } from "@calcom/ui/components/editor"; import { ToggleGroup, Switch } from "@calcom/ui/components/form"; -import { Label, TextArea, Input, TextField, Form } from "@calcom/ui/components/form"; +import { Label, TextArea, Input, TextField, Form, Select } from "@calcom/ui/components/form"; import { Icon } from "@calcom/ui/components/icon"; import { Sheet, @@ -43,6 +44,7 @@ import { Tooltip } from "@calcom/ui/components/tooltip"; import { DYNAMIC_TEXT_VARIABLES } from "../lib/constants"; import type { FormValues } from "../pages/workflow"; import { TestPhoneCallDialog } from "./TestPhoneCallDialog"; +import { VoiceSelectionDialog } from "./VoiceSelectionDialog"; import { WebCallDialog } from "./WebCallDialog"; // Utility functions for prompt display @@ -68,10 +70,52 @@ const restorePromptComplexity = (prompt: string): string => { return restoredPrompt; }; +// Language options for the dropdown +const LANGUAGE_OPTIONS = [ + { value: "en-US", label: "English (US)" }, + { value: "en-IN", label: "English (India)" }, + { value: "en-GB", label: "English (UK)" }, + { value: "en-AU", label: "English (Australia)" }, + { value: "en-NZ", label: "English (New Zealand)" }, + { value: "de-DE", label: "German" }, + { value: "es-ES", label: "Spanish (Spain)" }, + { value: "es-419", label: "Spanish (Latin America)" }, + { value: "hi-IN", label: "Hindi" }, + { value: "fr-FR", label: "French (France)" }, + { value: "fr-CA", label: "French (Canada)" }, + { value: "ja-JP", label: "Japanese" }, + { value: "pt-PT", label: "Portuguese (Portugal)" }, + { value: "pt-BR", label: "Portuguese (Brazil)" }, + { value: "zh-CN", label: "Chinese (Simplified)" }, + { value: "ru-RU", label: "Russian" }, + { value: "it-IT", label: "Italian" }, + { value: "ko-KR", label: "Korean" }, + { value: "nl-NL", label: "Dutch (Netherlands)" }, + { value: "nl-BE", label: "Dutch (Belgium)" }, + { value: "pl-PL", label: "Polish" }, + { value: "tr-TR", label: "Turkish" }, + { value: "th-TH", label: "Thai" }, + { value: "vi-VN", label: "Vietnamese" }, + { value: "ro-RO", label: "Romanian" }, + { value: "bg-BG", label: "Bulgarian" }, + { value: "ca-ES", label: "Catalan" }, + { value: "da-DK", label: "Danish" }, + { value: "fi-FI", label: "Finnish" }, + { value: "el-GR", label: "Greek" }, + { value: "hu-HU", label: "Hungarian" }, + { value: "id-ID", label: "Indonesian" }, + { value: "no-NO", label: "Norwegian" }, + { value: "sk-SK", label: "Slovak" }, + { value: "sv-SE", label: "Swedish" }, + { value: "multi", label: "Multilingual" }, +]; + const agentSchema = z.object({ generalPrompt: z.string().min(1, "General prompt is required"), beginMessage: z.string().min(1, "Begin message is required"), numberToCall: z.string().optional(), + language: z.string().optional(), + voiceId: z.string().optional(), generalTools: z .array( z.object({ @@ -145,6 +189,7 @@ export function AgentConfigurationSheet({ const [showAdvancedFields, setShowAdvancedFields] = useState(false); const [isTestAgentDialogOpen, setIsTestAgentDialogOpen] = useState(false); const [isWebCallDialogOpen, setIsWebCallDialogOpen] = useState(false); + const [isVoiceDialogOpen, setIsVoiceDialogOpen] = useState(false); const [cancellingNumberId, setCancellingNumberId] = useState(null); const [numberToDelete, setNumberToDelete] = useState(null); // const [toolDialogOpen, setToolDialogOpen] = useState(false); @@ -159,6 +204,8 @@ export function AgentConfigurationSheet({ generalPrompt: "", beginMessage: "", numberToCall: "", + language: "en-US", + voiceId: "", generalTools: [], }, }); @@ -170,6 +217,8 @@ export function AgentConfigurationSheet({ generalPrompt: cleanPromptForDisplay(retellData.generalPrompt || ""), beginMessage: retellData.beginMessage || "", numberToCall: "", + language: retellData.language || "en-US", + voiceId: retellData.voiceId || "", generalTools: retellData.generalTools || [], }); } @@ -289,6 +338,8 @@ export function AgentConfigurationSheet({ const updatePayload = { generalPrompt: restorePromptComplexity(data.generalPrompt), beginMessage: data.beginMessage, + language: data.language as Language, + voiceId: data.voiceId, // Don't include generalTools - they are managed by the backend }; @@ -434,6 +485,43 @@ export function AgentConfigurationSheet({ {activeTab === "prompt" && (
+
+ + ( +