# `KapsoEx.WhatsApp.Calls`
[🔗](https://github.com/rocket4ce/kapso_ex/blob/v0.1.0/lib/kapso_ex/whatsapp/calls.ex#L1)

[WhatsApp Calling](https://docs.kapso.ai/docs/whatsapp/calling/overview):
call logs, call actions and call permissions.

Calls are negotiated with WebRTC SDP: you send an SDP offer to start an
outbound call, and an SDP answer to accept an inbound one (received in the
call webhook).

# `result`

```elixir
@type result() :: {:ok, map()} | {:error, KapsoEx.Error.t()}
```

# `accept`

```elixir
@spec accept(KapsoEx.Client.t(), String.t(), String.t(), String.t(), keyword()) ::
  result()
```

Accepts an inbound call with an SDP answer. Options as in `connect/5`.

# `action`

```elixir
@spec action(KapsoEx.Client.t(), String.t(), map() | keyword()) :: result()
```

Performs a raw call action. `attrs` needs at least `:action`
(`"connect"`, `"pre_accept"`, `"accept"`, `"reject"` or `"terminate"`).

# `connect`

```elixir
@spec connect(KapsoEx.Client.t(), String.t(), String.t(), String.t(), keyword()) ::
  result()
```

Starts an outbound call to `to` with an SDP offer.

Check `get_permissions/3` first: the user must have granted permission.

## Options

  * `:biz_opaque_callback_data` - echoed back in call webhooks.
  * `:recording` - e.g. `%{status: "ENABLED"}`.
  * `:transcription` - e.g. `%{status: "ENABLED"}`.

# `get_permissions`

```elixir
@spec get_permissions(KapsoEx.Client.t(), String.t(), map() | keyword()) :: result()
```

Gets the call permission state with a user. Params: `user_wa_id` (phone
number) or `recipient` (business-scoped user ID).

Before dialing, check that `actions` has `start_call` with
`can_perform_action: true`.

# `list`

```elixir
@spec list(KapsoEx.Client.t(), String.t(), map() | keyword()) :: result()
```

Lists calls. Params: `call_id`, `direction`, `status`, `since`, `until`,
`limit`, `before`, `after`, `fields`.

# `pre_accept`

```elixir
@spec pre_accept(KapsoEx.Client.t(), String.t(), String.t(), String.t()) :: result()
```

Pre-accepts an inbound call with an SDP answer, to start media setup early.

# `reject`

```elixir
@spec reject(KapsoEx.Client.t(), String.t(), String.t()) :: result()
```

Rejects an inbound call.

# `terminate`

```elixir
@spec terminate(KapsoEx.Client.t(), String.t(), String.t()) :: result()
```

Ends an ongoing call.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
