> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kapso.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Make outbound calls

> Check Calling permission and initiate a WhatsApp voice call through Kapso

## Check permission before dialing

Complete [Calling setup](https://docs.kapso.ai/docs/whatsapp/calling/overview.md) and connect a working media server first. Working inbound calls don't mean you can call out: outbound also depends on the recipient's permission and country availability.

Pass the recipient's number with country code, digits only (no `+` or separators):

```bash theme={null}
curl --fail-with-body --get \
  "https://api.kapso.ai/meta/whatsapp/$META_GRAPH_VERSION/$WHATSAPP_PHONE_NUMBER_ID/call_permissions" \
  -H "X-API-Key: $KAPSO_API_KEY" \
  --data-urlencode "user_wa_id=$RECIPIENT_PHONE_NUMBER"
```

If you only have a [business-scoped user ID](https://docs.kapso.ai/docs/whatsapp/business-scoped-user-ids.md) from the webhook, use `recipient=BSUID` instead of `user_wa_id` here, and `recipient` instead of `to` when sending the permission request or dialing.

Check the `start_call` action, not just `permission.status`:

```javascript theme={null}
const canCall = permissionResponse.actions?.some(
  action => action.action_name === 'start_call' && action.can_perform_action === true
);
```

If it's `false`, don't dial. [Request permission](#request-permission-in-whatsapp), then check again. Meta's limits can block a call even while permission is granted; see [Meta's permission docs](https://developers.facebook.com/documentation/business-messaging/whatsapp/calling/user-call-permissions) for current flows and limits.

> [!NOTE]
>
> The TypeScript SDK uses camelCase fields: `actionName` and `canPerformAction`. The REST response uses snake\_case. See [SDK calls](https://docs.kapso.ai/docs/whatsapp/typescript-sdk/calls.md).

## Request permission in WhatsApp

Inside an open customer service window, check that `send_call_permission_request` has `can_perform_action: true`, then send a free-form request:

```bash theme={null}
jq -n --arg to "$RECIPIENT_PHONE_NUMBER" \
  '{messaging_product:"whatsapp",to:$to,type:"interactive",interactive:{
    type:"call_permission_request",action:{name:"call_permission_request"},
    body:{text:"May we call you to confirm your appointment?"}
  }}' \
  | curl --fail-with-body \
    "https://api.kapso.ai/meta/whatsapp/$META_GRAPH_VERSION/$WHATSAPP_PHONE_NUMBER_ID/messages" \
    -H "X-API-Key: $KAPSO_API_KEY" \
    -H "Content-Type: application/json" \
    --data-binary @-
```

Replies arrive on the `messages` field as `interactive.call_permission_reply`, so handle them on the same Meta webhook as your calls. Match them by `from` and/or `from_user_id`; the phone number can be missing. The message being delivered or read doesn't grant permission: wait for the recipient to approve, then check `start_call` again.

Outside the window, use a [template permission request](https://developers.facebook.com/documentation/business-messaging/whatsapp/calling/user-call-permissions#free-form-vs-template-call-permission-request-message). Create the template through `/meta/whatsapp/{version}/{waba_id}/message_templates` with a `BODY` explaining why you want to call and a `call_permission_request` component. Once Meta approves it, send it through the number's `/messages` endpoint. A regular quick-reply button doesn't grant Calling permission.

## Send a real SDP offer

Create a WebRTC peer connection that sends and receives audio, set its local SDP offer with the ICE candidates your deployment needs, and keep the connection alive while the call rings.

Here `offerSdp` comes from your media server, and `recipientPhoneNumber` is the number you just checked:

```javascript theme={null}
const attemptId = crypto.randomUUID();
// Persist attemptId with your pending media session before sending the request.
const response = await fetch(
  `https://api.kapso.ai/meta/whatsapp/${process.env.META_GRAPH_VERSION}/${process.env.WHATSAPP_PHONE_NUMBER_ID}/calls`,
  {
    method: 'POST',
    headers: { 'X-API-Key': process.env.KAPSO_API_KEY, 'Content-Type': 'application/json' },
    body: JSON.stringify({
      messaging_product: 'whatsapp',
      action: 'connect',
      to: recipientPhoneNumber,
      session: { sdp_type: 'offer', sdp: offerSdp },
      biz_opaque_callback_data: attemptId
    })
  }
);

if (!response.ok) throw new Error(`Calling failed: HTTP ${response.status}`);
const result = await response.json();
const callId = result.calls?.[0]?.id;
if (!callId) throw new Error('No call ID returned; check the provider outcome before retrying');
```

To record or transcribe the call, add `recording` and/or `transcription` to this `connect` body. See [Recordings and transcripts](https://docs.kapso.ai/docs/whatsapp/calling/recordings-and-transcripts.md).

Map the returned call ID to your pending media session. A successful `connect` response only means the request was accepted, not that the recipient answered or that audio flows. Don't auto-retry after a timeout or unclear response: the first request may already have created a billed call.

## Apply the answer webhook

Use the same signed Meta receiver as for inbound calls. Route by `direction` and SDP type:

| Event | Your action |
| - | - |
| `connect`, `USER_INITIATED`, SDP `offer` | Create an inbound session and send `pre_accept` / `accept`. |
| `connect`, `BUSINESS_INITIATED`, SDP `answer` | Find the pending outbound session by `call.id` and set its remote SDP answer. |
| `statuses[]`: `RINGING` | Keep the pending session silent. |
| `statuses[]`: `ACCEPTED` | Match `status.id` to the call ID, clear the ringing timeout, and greet when media is connected. |
| `statuses[]`: `REJECTED` | Release the pending session without starting an agent. |
| `statuses[]`: `COMPLETED` | Record the terminal outcome; this does not prove pickup. |
| `terminate` | Stop the matching session and release media resources. |

The SDP answer can arrive while the phone is still ringing. Apply it to the pending connection right away, but don't greet until the matching `ACCEPTED` status.

* Don't treat an outbound answer as a new inbound offer.
* If an answer or status arrives before the dial response returns the call ID, buffer it briefly by call ID and apply it once the session is mapped.
* Set a timeout to clean up unanswered calls, and clear it on `ACCEPTED` so it can't cut off an answered call.
* Ignore duplicate or late events after termination.

## Test outbound calls

Use a consenting test recipient and check these cases separately:

1. Revoke permission in WhatsApp. Confirm your app refuses to dial when `start_call` is unavailable.
2. Send a permission request, approve it on the handset, and check `start_call` again.
3. Answer a call. Verify two-way audio, the intended tool, and caller hangup.
4. Answer another call and let the agent end it. Verify your bridge sends `terminate` and releases the pipeline and media connection.
5. Decline a call, then leave another unanswered. Neither should start an agent; both must release the pending media connection.
6. Read each saved call through [List calls](https://docs.kapso.ai/api/meta/whatsapp/calls/list-calls.md) and match it to the webhook sequence by call ID.

`COMPLETED` alone doesn't mean the call was answered. In handset tests, Meta also sent it for declined and unanswered calls, without start/end times or duration. Track `RINGING`, `ACCEPTED`, and `REJECTED` to tell those outcomes apart.

## Billing and troubleshooting

Meta charges business-initiated calls by destination country and monthly volume, in 6-second pulses. See [Calling pricing](https://docs.kapso.ai/docs/whatsapp/pricing-faq.md#how-is-whatsapp-calling-billed).

Permission, country availability, and Kapso billing are checked separately. Having permission doesn't get past an insufficient-balance or billing-readiness error from the proxy. A billing error comes from the dial request, not your webhook, so don't remove the webhook to debug one.

See [Call actions](https://docs.kapso.ai/api/meta/whatsapp/calls/perform-call-action.md), [Call permission state](https://docs.kapso.ai/api/meta/whatsapp/calls/get-call-permission-state.md), and [Meta business-initiated calls](https://developers.facebook.com/documentation/business-messaging/whatsapp/calling/business-initiated-calls).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.