From 37f1535e1a6037f55c87a12842ee8a7d3a360630 Mon Sep 17 00:00:00 2001 From: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Date: Thu, 13 Feb 2025 21:04:33 +0530 Subject: [PATCH] refactor: remove depreceated fields (#19279) * refactor: remove depreceated fields * chore: use v2 endpoint * chore: update V2 Api type * chore --- .../outputs/create-phone-call.output.ts | 5 +-- .../ee/cal-ai-phone/retellAIService.ts | 34 ++++++++++++++----- .../features/ee/cal-ai-phone/zod-utils.ts | 11 +++--- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/apps/api/v2/src/ee/event-types/event-types_2024_06_14/outputs/create-phone-call.output.ts b/apps/api/v2/src/ee/event-types/event-types_2024_06_14/outputs/create-phone-call.output.ts index ac4c2dd965..897292e381 100644 --- a/apps/api/v2/src/ee/event-types/event-types_2024_06_14/outputs/create-phone-call.output.ts +++ b/apps/api/v2/src/ee/event-types/event-types_2024_06_14/outputs/create-phone-call.output.ts @@ -1,6 +1,6 @@ import { ApiProperty } from "@nestjs/swagger"; import { Type } from "class-transformer"; -import { IsEnum, IsString, ValidateNested } from "class-validator"; +import { IsEnum, IsString, ValidateNested, IsOptional } from "class-validator"; import { SUCCESS_STATUS, ERROR_STATUS } from "@calcom/platform-constants"; @@ -10,8 +10,9 @@ class Data { callId!: string; @IsString() + @IsOptional() @ApiProperty() - agentId!: string; + agentId?: string; } export class CreatePhoneCallOutput { diff --git a/packages/features/ee/cal-ai-phone/retellAIService.ts b/packages/features/ee/cal-ai-phone/retellAIService.ts index b903c8883f..7453163495 100644 --- a/packages/features/ee/cal-ai-phone/retellAIService.ts +++ b/packages/features/ee/cal-ai-phone/retellAIService.ts @@ -36,7 +36,11 @@ type initProps = { generalPrompt: string; }; -const updateAgentWebsocketUrl = async (phoneNumber: string, llmWebsocketUrl: string): Promise => { +const updateAgentWebsocketUrl = async ( + phoneNumber: string, + llmWebsocketUrl: string, + llmId: string +): Promise => { try { const phoneNumberDetails = await fetcher(`/get-phone-number/${phoneNumber}`).then( ZGetPhoneNumberSchema.parse @@ -45,7 +49,11 @@ const updateAgentWebsocketUrl = async (phoneNumber: string, llmWebsocketUrl: str await fetcher(`/update-agent/${phoneNumberDetails.outbound_agent_id}`, { method: "PATCH", body: JSON.stringify({ - llm_websocket_url: llmWebsocketUrl, + response_engined: { + type: "retell-llm", + llm_websocket_url: llmWebsocketUrl, + llm_id: llmId, + }, }), }); } catch (error) { @@ -94,8 +102,12 @@ class CreateRetellLLMCommand implements Command { }), }).then(ZCreateRetellLLMSchema.parse); - const llmWebSocketUrlToBeUpdated = createdRetellLLM.llm_websocket_url; - await updateAgentWebsocketUrl(this.props.yourPhoneNumber, llmWebSocketUrlToBeUpdated); + const llmWebSocketUrlToBeUpdated = createdRetellLLM.inbound_dynamic_variables_webhook_url; + await updateAgentWebsocketUrl( + this.props.yourPhoneNumber, + llmWebSocketUrlToBeUpdated, + createdRetellLLM.llm_id + ); return createdRetellLLM; } catch (error) { @@ -133,8 +145,12 @@ class UpdateRetellLLMCommand implements Command { }), }).then(ZGetRetellLLMSchema.parse); - const llmWebSocketUrlToBeUpdated = updatedRetellLLM.llm_websocket_url; - await updateAgentWebsocketUrl(this.props.yourPhoneNumber, llmWebSocketUrlToBeUpdated); + const llmWebSocketUrlToBeUpdated = updatedRetellLLM.inbound_dynamic_variables_webhook_url; + await updateAgentWebsocketUrl( + this.props.yourPhoneNumber, + llmWebSocketUrlToBeUpdated, + updatedRetellLLM.llm_id + ); return updatedRetellLLM; } catch (err) { @@ -172,7 +188,7 @@ class CreateRetellPhoneCallCommand implements Command { async execute(): Promise { try { - const createPhoneCallRes = await fetcher("/create-phone-call", { + const createPhoneCallRes = await fetcher("/v2/create-phone-call", { method: "POST", body: JSON.stringify({ from_number: this.props.yourPhoneNumber, @@ -187,8 +203,8 @@ class CreateRetellPhoneCallCommand implements Command { return createPhoneCallRes; } catch (err) { - log.error("Unable to Get Phone number", safeStringify(err)); - throw new Error("Something went wrong! Unable to Get Phone number"); + log.error("Unable to create phone call", safeStringify(err)); + throw new Error("Something went wrong! Unable to create phone call"); } } } diff --git a/packages/features/ee/cal-ai-phone/zod-utils.ts b/packages/features/ee/cal-ai-phone/zod-utils.ts index 16452a296e..2e0c54c774 100644 --- a/packages/features/ee/cal-ai-phone/zod-utils.ts +++ b/packages/features/ee/cal-ai-phone/zod-utils.ts @@ -44,7 +44,8 @@ export type TCreatePhoneCallSchema = z.infer; export const ZGetPhoneNumberSchema = z .object({ - agent_id: z.string(), + agent_id: z.string().optional(), + nickname: z.string(), inbound_agent_id: z.string(), outbound_agent_id: z.string(), error_message: z.string().optional(), @@ -56,7 +57,7 @@ export type TGetPhoneNumberSchema = z.infer; export const ZCreatePhoneSchema = z .object({ call_id: z.string(), - agent_id: z.string(), + agent_id: z.string().optional(), }) .passthrough(); @@ -121,7 +122,8 @@ export type Fields = z.infer; export const ZCreateRetellLLMSchema = z .object({ llm_id: z.string(), - llm_websocket_url: z.string(), + llm_websocket_url: z.string().optional(), + inbound_dynamic_variables_webhook_url: z.string(), }) .passthrough(); @@ -132,7 +134,8 @@ export const ZGetRetellLLMSchema = z general_prompt: z.string(), begin_message: z.string().nullable().optional(), llm_id: z.string(), - llm_websocket_url: z.string(), + llm_websocket_url: z.string().optional(), + inbound_dynamic_variables_webhook_url: z.string(), general_tools: z.array( z .object({