Skip to content

Conversation

@cubic-dev-local
Copy link

@cubic-dev-local cubic-dev-local bot commented Sep 12, 2025

## What does this PR do?

Screenshot 2025-09-12 at 4 20 08 PM

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • N/A I have updated the developer docs in /docs 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.

How should this be tested?

---

Based on: calcom/cal.com#23788

Summary by cubic

Add web call support to the Retell webhook. For web calls (no phone numbers), we resolve the agent and charge credits to the correct user/team.

  • New Features

    • Handle web_call events by looking up the agent via providerAgentId and charging credits to the associated user or team.
    • Keep skipping inbound phone calls; web calls bypass the direction check.
    • Added unit tests for web calls (agent and team cases, missing data paths).
  • Refactors

    • Extracted credit charging into a helper with a per-minute rate (defaults to $0.29) and rounded-up credits.
    • Made phone fields optional in the schema and improved logging/errors.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 3 files

Prompt for AI agents (all 1 issues)

Understand the root cause of the following 1 issues and fix them.


<file name="apps/web/app/api/webhooks/retell-ai/route.ts">

<violation number="1" location="apps/web/app/api/webhooks/retell-ai/route.ts:122">
The webhook returns a `200 OK` success response even when credit charging fails for critical reasons, such as the agent or phone number not being found. This can lead to silent, unbilled calls and revenue loss, as the failure is only recorded in logs and not propagated as an error state.</violation>
</file>

React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.

}
}

async function handleCallAnalyzed(callData: any) {
Copy link

@cubic-dev-ai cubic-dev-ai bot Sep 12, 2025

Choose a reason for hiding this comment

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

The webhook returns a 200 OK success response even when credit charging fails for critical reasons, such as the agent or phone number not being found. This can lead to silent, unbilled calls and revenue loss, as the failure is only recorded in logs and not propagated as an error state.

Prompt for AI agents
Address the following comment on apps/web/app/api/webhooks/retell-ai/route.ts at line 122:

<comment>The webhook returns a `200 OK` success response even when credit charging fails for critical reasons, such as the agent or phone number not being found. This can lead to silent, unbilled calls and revenue loss, as the failure is only recorded in logs and not propagated as an error state.</comment>

<file context>
@@ -124,15 +117,74 @@ async function handleCallAnalyzed(callData: any) {
   }
+}
+
+async function handleCallAnalyzed(callData: any) {
+  const { from_number, call_id, call_cost, call_type, agent_id } = callData;
 
</file context>

[internal] Confidence score: 10/10

[internal] Posted by: System Design Agent

Fix with Cubic

@github-actions
Copy link

This PR is being marked as stale due to inactivity.

@github-actions github-actions bot added the Stale label Sep 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant