* feat: lang support * fix: type errors * feat: select voice agent * refactor: address feedback * refactor: address feedback * refactor: missing import * fix: types * feat: add inbound calls * chore: formatting * chore * feat: finish inbound call * chore: formatting * fix: update bug * fix: types * refactor: Agent Configuration Sheet (#23930) * refactor: agent configuration sheet * chore: use default phone numbre * refactor: improvements * refactor: improvements * fix: types * fix: feedback * chore: * fix: feedback * fix: prompt * fix: review * fix: review * refactor: class * refactor: class * refactor: rename * Update apps/web/public/static/locales/en/common.json * Update apps/web/public/static/locales/en/common.json * chore: update set value * fix: remove index * fix: type error * fix: update tetss * fix: use logger * refactor: don't use static * fix: type * fix: schema * refactor: --------- Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com>
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import { createDefaultAIPhoneServiceProvider } from "@calcom/features/calAIPhone";
|
|
import { HttpError } from "@calcom/lib/http-error";
|
|
import logger from "@calcom/lib/logger";
|
|
|
|
import { TRPCError } from "@trpc/server";
|
|
|
|
import type { TrpcSessionUser } from "../../../types";
|
|
import type { TSetupInboundAgentInputSchema } from "./setupInboundAgent.schema";
|
|
|
|
type SetupInboundAgentHandlerOptions = {
|
|
ctx: {
|
|
user: NonNullable<TrpcSessionUser>;
|
|
};
|
|
input: TSetupInboundAgentInputSchema;
|
|
};
|
|
|
|
export const setupInboundAgentHandler = async ({ ctx, input }: SetupInboundAgentHandlerOptions) => {
|
|
const log = logger.getSubLogger({ prefix: ["setupInboundAgentHandler"] });
|
|
|
|
try {
|
|
const { phoneNumber, teamId, workflowStepId } = input;
|
|
const userId = ctx.user.id;
|
|
const userTimeZone = ctx.user.timeZone || "UTC";
|
|
|
|
const aiService = createDefaultAIPhoneServiceProvider();
|
|
|
|
const createAgentResult = await aiService.createInboundAgent({
|
|
name: `Inbound Agent - ${phoneNumber}`,
|
|
phoneNumber,
|
|
userId,
|
|
teamId,
|
|
workflowStepId,
|
|
userTimeZone,
|
|
});
|
|
|
|
return {
|
|
success: true,
|
|
agentId: createAgentResult.id,
|
|
message: "Inbound agent configured successfully",
|
|
};
|
|
} catch (error) {
|
|
log.error("Failed to setup inbound agent", { error });
|
|
|
|
if (error instanceof HttpError) {
|
|
throw error;
|
|
}
|
|
|
|
throw new TRPCError({
|
|
code: "INTERNAL_SERVER_ERROR",
|
|
message: "Failed to setup inbound agent",
|
|
});
|
|
}
|
|
};
|