Scheduling infrastructure for absolutely everyone.
refactor: small improvements for cal ai (#23444)
Udit Takkardd16c2b99d9d
diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.jsonindex eacfeff2bf7..4cebb6a1a5c 100644--- a/apps/web/public/static/locales/en/common.json+++ b/apps/web/public/static/locales/en/common.json@@ -817,7 +817,7 @@"delete_phone_number_confirmation": "Are you sure you want to delete this phone number? This action cannot be undone.","yes_delete_phone_number": "Yes, delete phone number","phone_number_info_tooltip": "The number you are trying to import must be in E.164 format (+country code followed by the number, with no spaces or special characters), e.g. +1234567890",- "termination_uri_info_tooltip": "The termination uri to uniquely identify your elastic SIP trunk. This is used for outbound calls. For Twilio elastic SIP trunks it always ends with .pstn.twilio.com.",+ "termination_uri_info_tooltip": "The termination URI to uniquely identify your elastic SIP trunk. This is used for outbound calls. For Twilio elastic SIP trunks it always ends with .pstn.twilio.com.","sip_trunk_username_info_tooltip": "The username used to authenticate the SIP trunk.","sip_trunk_password_info_tooltip": "The password used to authenticate the SIP trunk.","nickname_info_tooltip": "Nickname of the number. This is for your reference only.",diff --git a/packages/features/calAIPhone/providers/retellAI/services/AgentService.ts b/packages/features/calAIPhone/providers/retellAI/services/AgentService.tsindex b10c822f658..283477d20ae 100644--- a/packages/features/calAIPhone/providers/retellAI/services/AgentService.ts+++ b/packages/features/calAIPhone/providers/retellAI/services/AgentService.ts@@ -1,10 +1,9 @@import { v4 as uuidv4 } from "uuid";-import { generateUniqueAPIKey as generateHashedApiKey } from "@calcom/ee/api-keys/lib/apiKeys";import { timeZoneSchema } from "@calcom/lib/dayjs/timeZone.schema";import { HttpError } from "@calcom/lib/http-error";import logger from "@calcom/lib/logger";-import prisma from "@calcom/prisma";+import { PrismaApiKeyRepository } from "@calcom/lib/server/repository/PrismaApiKeyRepository";import type {AIPhoneServiceUpdateModelParams,@@ -27,24 +26,12 @@ export class AgentService {) {}private async createApiKey({ userId, teamId }: { userId: number; teamId?: number }) {- const [hashedApiKey, apiKey] = generateHashedApiKey();- await prisma.apiKey.create({- data: {- id: uuidv4(),- userId,- teamId,- // And here we pass a null to expiresAt if never expires is true- expiresAt: null,- hashedKey: hashedApiKey,- note: `Cal AI Phone API Key for agent ${userId} ${teamId ? `for team ${teamId}` : ""}`,- },+ return await PrismaApiKeyRepository.createApiKey({+ userId,+ teamId,+ expiresAt: null,+ note: `Cal AI Phone API Key for agent ${userId} ${teamId ? `for team ${teamId}` : ""}`,});-- const apiKeyPrefix = process.env.API_KEY_PREFIX ?? "cal_";-- const prefixedApiKey = `${apiKeyPrefix}${apiKey}`;-- return prefixedApiKey;}async getAgent(agentId: string): Promise<AIPhoneServiceAgent<AIPhoneServiceProviderType.RETELL_AI>> {diff --git a/packages/features/ee/workflows/components/AgentConfigurationSheet.tsx b/packages/features/ee/workflows/components/AgentConfigurationSheet.tsxindex b919485c4a0..f2404c9408e 100644--- a/packages/features/ee/workflows/components/AgentConfigurationSheet.tsx+++ b/packages/features/ee/workflows/components/AgentConfigurationSheet.tsx@@ -934,12 +934,13 @@ export function AgentConfigurationSheet({{t("learn_how_to_get_your_terminator")}</p></div>- {/*TODO: Create a doc and link to it */}<Buttontype="button"color="secondary"size="base"EndIcon="external-link"+ href="https://cal.com/help/importing/import-numbers"+ target="_blank"className="text-emphasis my-auto">{t("learn")}</Button>diff --git a/packages/lib/formatPhoneNumber.ts b/packages/lib/formatPhoneNumber.tsindex 0c3c89be091..1fcf66110cd 100644--- a/packages/lib/formatPhoneNumber.ts+++ b/packages/lib/formatPhoneNumber.ts@@ -1,4 +1,4 @@-import { parsePhoneNumberWithError } from "libphonenumber-js";+import { parsePhoneNumberWithError } from "libphonenumber-js/max";export const formatPhoneNumber = (phoneNumber: string) => {const parsedPhoneNumber = parsePhoneNumberWithError(phoneNumber);diff --git a/packages/lib/server/repository/PrismaApiKeyRepository.ts b/packages/lib/server/repository/PrismaApiKeyRepository.tsindex 9e2da8dfa1c..11382f8d263 100644--- a/packages/lib/server/repository/PrismaApiKeyRepository.ts+++ b/packages/lib/server/repository/PrismaApiKeyRepository.ts@@ -1,3 +1,6 @@+import { v4 as uuidv4 } from "uuid";++import { generateUniqueAPIKey as generateHashedApiKey } from "@calcom/ee/api-keys/lib/apiKeys";import prisma from "@calcom/prisma";export class PrismaApiKeyRepository {@@ -25,4 +28,34 @@ export class PrismaApiKeyRepository {return true;});}++ static async createApiKey({+ userId,+ teamId,+ note,+ expiresAt,+ }: {+ userId: number;+ teamId?: number;+ note?: string;+ expiresAt?: Date | null;+ }) {+ const [hashedApiKey, apiKey] = generateHashedApiKey();+ await prisma.apiKey.create({+ data: {+ id: uuidv4(),+ userId,+ teamId,+ expiresAt,+ hashedKey: hashedApiKey,+ note: note,+ },+ });++ const apiKeyPrefix = process.env.API_KEY_PREFIX ?? "cal_";++ const prefixedApiKey = `${apiKeyPrefix}${apiKey}`;++ return prefixedApiKey;+ }}diff --git a/packages/trpc/server/routers/viewer/workflows/update.handler.ts b/packages/trpc/server/routers/viewer/workflows/update.handler.tsindex 50aab6dc7e9..ae360404446 100755--- a/packages/trpc/server/routers/viewer/workflows/update.handler.ts+++ b/packages/trpc/server/routers/viewer/workflows/update.handler.ts@@ -803,7 +803,10 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {if (externalToolErrors.length > 0) {log.error(`Agent tool update errors for workflow ${id}:`, externalToolErrors);- throw new Error(`${externalToolErrors.join("; ")}`);+ throw new TRPCError({+ code: "INTERNAL_SERVER_ERROR",+ message: externalToolErrors.join("; "),+ });}}