-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Expand file tree
/
Copy pathcreate.handler.ts
More file actions
35 lines (29 loc) · 1.22 KB
/
create.handler.ts
File metadata and controls
35 lines (29 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { createDefaultAIPhoneServiceProvider } from "@calcom/features/calAIPhone";
import type { RetellLLMGeneralTools } from "@calcom/features/calAIPhone/providers/retellAI/types";
import { calAIPhoneWorkflowTemplates } from "@calcom/features/calAIPhone/workflowTemplates";
import type { TrpcSessionUser } from "../../../types";
import type { TCreateInputSchema } from "./create.schema";
type CreateHandlerOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
};
input: TCreateInputSchema;
};
export const createHandler = async ({ ctx, input }: CreateHandlerOptions) => {
const { teamId, name, workflowStepId, templateWorkflowId, ...retellConfig } = input;
const aiService = createDefaultAIPhoneServiceProvider();
const generalPrompt = templateWorkflowId
? calAIPhoneWorkflowTemplates?.[templateWorkflowId as keyof typeof calAIPhoneWorkflowTemplates]
?.generalPrompt
: undefined;
return await aiService.createAgent({
name,
userId: ctx.user.id,
teamId,
workflowStepId,
generalPrompt: generalPrompt ?? retellConfig.generalPrompt,
beginMessage: retellConfig.beginMessage,
generalTools: retellConfig.generalTools as RetellLLMGeneralTools,
userTimeZone: ctx.user.timeZone,
});
};