refactor: remove depreceated fields (#19279)

* refactor: remove depreceated fields

* chore: use v2 endpoint

* chore: update V2 Api type

* chore
This commit is contained in:
Udit Takkar
2025-02-13 17:34:33 +02:00
committed by GitHub
parent 5dc81e8677
commit 37f1535e1a
3 changed files with 35 additions and 15 deletions
@@ -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 {
@@ -36,7 +36,11 @@ type initProps = {
generalPrompt: string;
};
const updateAgentWebsocketUrl = async (phoneNumber: string, llmWebsocketUrl: string): Promise<void> => {
const updateAgentWebsocketUrl = async (
phoneNumber: string,
llmWebsocketUrl: string,
llmId: string
): Promise<void> => {
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<TCreateRetellLLMSchema> {
}),
}).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<TGetRetellLLMSchema> {
}),
}).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<TCreatePhoneSchema> {
async execute(): Promise<TCreatePhoneSchema> {
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<TCreatePhoneSchema> {
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");
}
}
}
@@ -44,7 +44,8 @@ export type TCreatePhoneCallSchema = z.infer<typeof createPhoneCallSchema>;
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<typeof ZGetPhoneNumberSchema>;
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<typeof FieldsSchema>;
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({