Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: V2 API endpoint create phone call #16528

Merged
merged 18 commits into from
Sep 11, 2024
Merged

Conversation

Udit-takkar
Copy link
Contributor

@Udit-takkar Udit-takkar commented Sep 6, 2024

What does this PR do?

Screenshot 2024-09-10 at 2 25 11 PM

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected) .
  • I have added a Docs issue here if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works [To Be Added Later in follow up PR].

How should this be tested?

DM me for input body and api key

POST:- /api/v2/organizations/{org.id}/teams/{team.id}/event-types/{eventType.id}/create-phone-call

{
    yourPhoneNumber: <PHONE_NUMBER_FROM_RETELL>,
    numberToCall: <NUMBER_YOU_WANT_TO_CALL>,
    calApiKey: <CAL_API_KEY>
}

RETELL_AI_KEY required

Checklist

@Udit-takkar Udit-takkar changed the title refactor: V2 API endpoint create phone call feat: V2 API endpoint create phone call Sep 6, 2024
@keithwillcode keithwillcode added core area: core, team members only enterprise area: enterprise, audit log, organisation, SAML, SSO labels Sep 6, 2024
Copy link

vercel bot commented Sep 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Visit Preview Sep 11, 2024 10:49am
calcom-web-canary ⬜️ Ignored (Inspect) Visit Preview Sep 11, 2024 10:49am

Copy link

linear bot commented Sep 10, 2024

@github-actions github-actions bot added ai area: AI, cal.ai api area: API, enterprise API, access token, OAuth labels Sep 10, 2024
@Udit-takkar Udit-takkar marked this pull request as ready for review September 10, 2024 08:56
@graphite-app graphite-app bot requested a review from a team September 10, 2024 08:56
@dosubot dosubot bot added the ✨ feature New feature or request label Sep 10, 2024
Copy link

graphite-app bot commented Sep 10, 2024

Graphite Automations

"Add consumer team as reviewer" took an action on this PR • (09/10/24)

1 reviewer was added to this PR based on Keith Williams's automation.

@Udit-takkar
Copy link
Contributor Author

Copy link
Member

@alishaz-polymath alishaz-polymath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀


@IsBoolean()
@DocsProperty({ description: "Enabled status", default: true })
enabled = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make typescript happy need to add ! aka enabled!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any ts error on this

Copy link
Contributor

@ThyMinimalDev ThyMinimalDev Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the type is 'true' it should be fine without the ! indeed, ! would be needed if the type was boolean

timeZone: user.timeZone,
profile: { organization: { id: orgId } },
},
input: { ...body, eventTypeId },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are passing eventTypeId to handleCreatePhoneCall which has TCreatePhoneCallSchema for input, but eventTypeId does not exist on that schema.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has eventTypeId. check this code

const requiredFields = z.object({
  yourPhoneNumber: z.string().refine((val) => isValidPhoneNumber(val)),
  numberToCall: z.string().refine((val) => isValidPhoneNumber(val)),
  calApiKey: z.string().trim().min(1, {
    message: "Please enter CAL API Key",
  }),
  eventTypeId: z.number(),
  enabled: z.boolean().default(false),
  templateType: templateTypeEnum,
});

export const createPhoneCallSchema = requiredFields.merge(
  z.object({
    schedulerName: z.string().min(1).optional().nullable(),
    guestName: z
      .string()
      .optional()
      .transform((val) => {
        return !!val ? val : undefined;
      }),
    guestEmail: z
      .string()
      .optional()
      .transform((val) => {
        return !!val ? val : undefined;
      }),
    guestCompany: z
      .string()
      .optional()
      .transform((val) => {
        return !!val ? val : undefined;
      }),
    beginMessage: z.string().optional(),
    generalPrompt: z.string().optional(),
  })
);

Notice we are using merge

user: { timeZone: string; id: number; profile?: { organization?: { id?: number } } };
input: TCreatePhoneCallSchema;
}) => {
if (!!!user?.profile?.organization) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a tripple shabang !!! ? We could just have if(!user?.profile?.organization) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both are same. Let me replace it if it's harder to read.

packages/features/handleCreatePhoneCall.ts Outdated Show resolved Hide resolved

// If no retell LLM is associated with the event type, create one
if (!aiPhoneCallConfig.llmId) {
const createdRetellLLM = await retellAI.createRetellLLMAndUpdateWebsocketUrl();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the code in this block statement could be abstracted in function to make code more readable.

Copy link
Contributor

github-actions bot commented Sep 11, 2024

E2E results are ready!

Copy link

socket-security bot commented Sep 11, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@formkit/auto-animate@1.0.0-beta.5 None 0 35.4 kB justin-schroeder
npm/bcryptjs@2.4.3 None 0 221 kB dcode
npm/ical.js@1.5.0 None 0 669 kB kewisch

🚮 Removed packages: npm/@babel/code-frame@7.22.13, npm/@bcoe/v8-coverage@0.2.3, npm/@humanwhocodes/module-importer@1.0.1, npm/@humanwhocodes/object-schema@1.2.1, npm/@nodelib/fs.scandir@2.1.5, npm/@nodelib/fs.stat@2.0.5, npm/@nodelib/fs.walk@1.2.8, npm/@tsconfig/node10@1.0.8, npm/@tsconfig/node12@1.0.9, npm/@tsconfig/node14@1.0.1, npm/@tsconfig/node16@1.0.2, npm/@types/istanbul-lib-report@3.0.0, npm/@types/ms@0.7.31, npm/acorn-jsx@5.3.2, npm/acorn-walk@8.2.0, npm/acorn@8.8.0, npm/ajv@6.12.6, npm/ansi-colors@4.1.3, npm/arg@4.1.3, npm/array-union@2.1.0, npm/base64-js@1.5.1, npm/call-bind@1.0.2, npm/callsites@3.1.0, npm/chownr@2.0.0, npm/ci-info@3.3.0, npm/cli-spinners@2.6.1, npm/cli-width@3.0.0, npm/color-convert@2.0.1, npm/concat-stream@2.0.0, npm/convert-source-map@2.0.0, npm/create-require@1.1.1, npm/cross-spawn@7.0.3, npm/debug@4.3.4, npm/deepmerge@4.2.2, npm/define-properties@1.1.4, npm/detect-indent@6.1.0, npm/dir-glob@3.0.1, npm/doctrine@3.0.0, npm/encoding@0.1.13, npm/env-paths@2.2.1, npm/err-code@2.0.3, npm/error-ex@1.3.2, npm/es-shim-unscopables@1.0.0, npm/es-to-primitive@1.2.1, npm/escalade@3.1.1, npm/eslint-utils@3.0.0, npm/espree@9.4.1, npm/esprima@4.0.1, npm/esquery@1.4.0, npm/esrecurse@4.3.0, npm/esutils@2.0.3, npm/events@3.3.0, npm/execa@5.1.1, npm/fast-deep-equal@3.1.3, npm/fast-glob@3.2.11, npm/fast-json-stable-stringify@2.1.0, npm/fast-levenshtein@2.0.6, npm/file-entry-cache@6.0.1, npm/find-up@5.0.0, npm/flat-cache@3.0.4, npm/fsevents@2.3.2, npm/function-bind@1.1.1, npm/function.prototype.name@1.1.5, npm/functions-have-names@1.2.3, npm/get-caller-file@2.0.5, npm/get-package-type@0.1.0, npm/get-stream@6.0.1, npm/get-symbol-description@1.0.0, npm/globby@11.1.0, npm/grapheme-splitter@1.0.4, npm/has-bigints@1.0.2, npm/has-property-descriptors@1.0.0, npm/has-symbols@1.0.3, npm/has-tostringtag@1.0.0, npm/has@1.0.3, npm/html-escaper@2.0.2, npm/http-cache-semantics@4.1.1, npm/human-signals@2.1.0, npm/ieee754@1.2.1, npm/import-fresh@3.3.0, npm/imurmurhash@0.1.4, npm/indent-string@4.0.0, npm/inherits@2.0.4, npm/internal-slot@1.0.3, npm/is-arrayish@0.2.1, npm/is-callable@1.2.4, npm/is-extglob@2.1.1, npm/is-fullwidth-code-point@3.0.0, npm/is-glob@4.0.3, npm/is-lambda@1.0.1, npm/is-negative-zero@2.0.2, npm/is-number@7.0.0, npm/is-path-inside@3.0.3, npm/is-regex@1.1.4, npm/is-shared-array-buffer@1.0.2, npm/is-string@1.0.7, npm/is-weakref@1.0.2, npm/istanbul-lib-coverage@3.2.0, npm/istanbul-lib-report@3.0.0, npm/istanbul-reports@3.1.4, npm/jose@4.15.9, npm/js-tokens@4.0.0, npm/json-stable-stringify-without-jsonify@1.0.1, npm/jsonc-parser@3.2.0, npm/levn@0.4.1, npm/locate-path@6.0.0, npm/lodash.merge@4.6.2, npm/lodash@4.17.21, npm/luxon@3.3.0, npm/make-dir@3.1.0, npm/make-error@1.3.6, npm/merge-stream@2.0.0, npm/merge2@1.4.1, npm/mimic-fn@2.1.0, npm/minipass-flush@1.0.5, npm/minipass-pipeline@1.2.4, npm/minipass-sized@1.0.3, npm/minizlib@2.1.2, npm/mkdirp@1.0.4, npm/ms@2.1.2, npm/mute-stream@0.0.8, npm/natural-compare@1.4.0, npm/negotiator@0.6.3, npm/normalize-path@3.0.0, npm/npm-run-path@4.0.1, npm/object-inspect@1.12.2, npm/object-keys@1.1.1, npm/once@1.4.0, npm/onetime@5.1.2, npm/optionator@0.9.1, npm/p-limit@3.1.0, npm/p-locate@5.0.0, npm/parent-module@1.0.1, npm/parse-json@5.2.0, npm/path-parse@1.0.7, npm/path-type@4.0.0, npm/picocolors@1.0.0, npm/picomatch@2.3.1, npm/prelude-ls@1.2.1, npm/promise-inflight@1.0.1, npm/promise-retry@2.0.1, npm/queue-microtask@1.2.3, npm/react-is@18.2.0, npm/regexp.prototype.flags@1.4.3, npm/regexpp@3.2.0, npm/require-directory@2.1.1, npm/resolve-from@4.0.0, npm/retry@0.12.0, npm/reusify@1.0.4, npm/rfdc@1.3.0, npm/rimraf@3.0.2, npm/run-async@2.4.1, npm/run-parallel@1.2.0, npm/safer-buffer@2.1.2, npm/side-channel@1.0.4, npm/sisteransi@1.0.5, npm/slash@3.0.0, npm/smart-buffer@4.2.0, npm/source-map-js@1.0.2, npm/spdx-exceptions@2.3.0, npm/spdx-expression-parse@3.0.1, npm/string-width@4.2.3, npm/string.prototype.trimend@1.0.5, npm/string.prototype.trimstart@1.0.5, npm/string_decoder@1.3.0, npm/strip-bom@3.0.0, npm/strip-final-newline@2.0.0, npm/supports-preserve-symlinks-flag@1.0.0, npm/terminal-link@2.1.1, npm/test-exclude@6.0.0, npm/text-table@0.2.0, npm/to-regex-range@5.0.1, npm/type-check@0.4.0, npm/type-detect@4.0.8, npm/typedarray@0.0.6, npm/unbox-primitive@1.0.2, npm/uri-js@4.4.1, npm/util-deprecate@1.0.2, npm/validate-npm-package-license@3.0.4, npm/which-boxed-primitive@1.0.2, npm/wrappy@1.0.2, npm/xtend@4.0.2, npm/yaml@1.10.2, npm/yn@3.1.1

View full report↗︎

@PeerRich PeerRich enabled auto-merge (squash) September 11, 2024 10:50
@PeerRich PeerRich merged commit 4d53f32 into main Sep 11, 2024
37 checks passed
@PeerRich PeerRich deleted the refactor/create-phone-call-api branch September 11, 2024 11:11
ThyMinimalDev added a commit that referenced this pull request Sep 13, 2024
* refactor: V2 API endpoint create phone call

* fix: type err

* fix: type and build err

* chore: change default value

* chore: move it to another route

* test: for create phone call

* chore: undo constant

* chore: remove test

* fix: make begin_message optional

* chore: improvements

* chore: begin message

* chore: remove unused import

* chore: bump platform libraries with handleCreatePhoneCall

* chore: improvement

---------

Co-authored-by: Keith Williams <keithwillcode@gmail.com>
Co-authored-by: Benny Joo <sldisek783@gmail.com>
Co-authored-by: Morgan Vernay <morgan@cal.com>
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ai area: AI, cal.ai api area: API, enterprise API, access token, OAuth core area: core, team members only enterprise area: enterprise, audit log, organisation, SAML, SSO ✨ feature New feature or request High priority Created by Linear-GitHub Sync ready-for-e2e
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CAL-4299] create ai phone call api endpoint
7 participants