Skip to content

Commit dd16c2b

Browse files
authored
refactor: small improvements for cal ai (#23444)
* refactor: small improvements follow up * fix: add docs
1 parent e7779bb commit dd16c2b

6 files changed

Lines changed: 47 additions & 23 deletions

File tree

apps/web/public/static/locales/en/common.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@
817817
"delete_phone_number_confirmation": "Are you sure you want to delete this phone number? This action cannot be undone.",
818818
"yes_delete_phone_number": "Yes, delete phone number",
819819
"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",
820-
"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.",
820+
"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.",
821821
"sip_trunk_username_info_tooltip": "The username used to authenticate the SIP trunk.",
822822
"sip_trunk_password_info_tooltip": "The password used to authenticate the SIP trunk.",
823823
"nickname_info_tooltip": "Nickname of the number. This is for your reference only.",

packages/features/calAIPhone/providers/retellAI/services/AgentService.ts

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { v4 as uuidv4 } from "uuid";
22

3-
import { generateUniqueAPIKey as generateHashedApiKey } from "@calcom/ee/api-keys/lib/apiKeys";
43
import { timeZoneSchema } from "@calcom/lib/dayjs/timeZone.schema";
54
import { HttpError } from "@calcom/lib/http-error";
65
import logger from "@calcom/lib/logger";
7-
import prisma from "@calcom/prisma";
6+
import { PrismaApiKeyRepository } from "@calcom/lib/server/repository/PrismaApiKeyRepository";
87

98
import type {
109
AIPhoneServiceUpdateModelParams,
@@ -27,24 +26,12 @@ export class AgentService {
2726
) {}
2827

2928
private async createApiKey({ userId, teamId }: { userId: number; teamId?: number }) {
30-
const [hashedApiKey, apiKey] = generateHashedApiKey();
31-
await prisma.apiKey.create({
32-
data: {
33-
id: uuidv4(),
34-
userId,
35-
teamId,
36-
// And here we pass a null to expiresAt if never expires is true
37-
expiresAt: null,
38-
hashedKey: hashedApiKey,
39-
note: `Cal AI Phone API Key for agent ${userId} ${teamId ? `for team ${teamId}` : ""}`,
40-
},
29+
return await PrismaApiKeyRepository.createApiKey({
30+
userId,
31+
teamId,
32+
expiresAt: null,
33+
note: `Cal AI Phone API Key for agent ${userId} ${teamId ? `for team ${teamId}` : ""}`,
4134
});
42-
43-
const apiKeyPrefix = process.env.API_KEY_PREFIX ?? "cal_";
44-
45-
const prefixedApiKey = `${apiKeyPrefix}${apiKey}`;
46-
47-
return prefixedApiKey;
4835
}
4936

5037
async getAgent(agentId: string): Promise<AIPhoneServiceAgent<AIPhoneServiceProviderType.RETELL_AI>> {

packages/features/ee/workflows/components/AgentConfigurationSheet.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,12 +934,13 @@ export function AgentConfigurationSheet({
934934
{t("learn_how_to_get_your_terminator")}
935935
</p>
936936
</div>
937-
{/*TODO: Create a doc and link to it */}
938937
<Button
939938
type="button"
940939
color="secondary"
941940
size="base"
942941
EndIcon="external-link"
942+
href="https://cal.com/help/importing/import-numbers"
943+
target="_blank"
943944
className="text-emphasis my-auto">
944945
{t("learn")}
945946
</Button>

packages/lib/formatPhoneNumber.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { parsePhoneNumberWithError } from "libphonenumber-js";
1+
import { parsePhoneNumberWithError } from "libphonenumber-js/max";
22

33
export const formatPhoneNumber = (phoneNumber: string) => {
44
const parsedPhoneNumber = parsePhoneNumberWithError(phoneNumber);

packages/lib/server/repository/PrismaApiKeyRepository.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { v4 as uuidv4 } from "uuid";
2+
3+
import { generateUniqueAPIKey as generateHashedApiKey } from "@calcom/ee/api-keys/lib/apiKeys";
14
import prisma from "@calcom/prisma";
25

36
export class PrismaApiKeyRepository {
@@ -25,4 +28,34 @@ export class PrismaApiKeyRepository {
2528
return true;
2629
});
2730
}
31+
32+
static async createApiKey({
33+
userId,
34+
teamId,
35+
note,
36+
expiresAt,
37+
}: {
38+
userId: number;
39+
teamId?: number;
40+
note?: string;
41+
expiresAt?: Date | null;
42+
}) {
43+
const [hashedApiKey, apiKey] = generateHashedApiKey();
44+
await prisma.apiKey.create({
45+
data: {
46+
id: uuidv4(),
47+
userId,
48+
teamId,
49+
expiresAt,
50+
hashedKey: hashedApiKey,
51+
note: note,
52+
},
53+
});
54+
55+
const apiKeyPrefix = process.env.API_KEY_PREFIX ?? "cal_";
56+
57+
const prefixedApiKey = `${apiKeyPrefix}${apiKey}`;
58+
59+
return prefixedApiKey;
60+
}
2861
}

packages/trpc/server/routers/viewer/workflows/update.handler.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,10 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
803803

804804
if (externalToolErrors.length > 0) {
805805
log.error(`Agent tool update errors for workflow ${id}:`, externalToolErrors);
806-
throw new Error(`${externalToolErrors.join("; ")}`);
806+
throw new TRPCError({
807+
code: "INTERNAL_SERVER_ERROR",
808+
message: externalToolErrors.join("; "),
809+
});
807810
}
808811
}
809812

0 commit comments

Comments
 (0)