# `KapsoEx.Platform.Flows`
[🔗](https://github.com/rocket4ce/kapso_ex/blob/v0.1.0/lib/kapso_ex/platform/flows.ex#L1)

WhatsApp Flows managed by Kapso: versions, publishing, encryption and
data endpoints (serverless functions that serve dynamic flow data).

See [Flows in Kapso](https://docs.kapso.ai/docs/whatsapp/flows/kapso-integration).
To send a flow, use `KapsoEx.WhatsApp.Messages.send_flow/6`.

# `result`

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

# `attach_data_endpoint`

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

Attaches an existing deployed function as the flow's data endpoint and
registers it with Meta. Several flows can share one function.

# `create`

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

Creates a flow. Attributes: `phone_number_id` (required), `name`,
`flow_json` (a map; defaults to a basic welcome screen) and `publish`.

# `create_version`

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

Uploads new flow JSON as a new version and syncs it with Meta.

## Options

  * `:phone_number_id`

# `deploy_data_endpoint`

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

Deploys the data endpoint function.

# `function_invocations`

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

Gets recent invocations of the data endpoint function. Params: `status`, `limit`.

# `function_logs`

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

Gets logs of the data endpoint function (shared functions include every
flow's activity). Params: `limit`.

# `get`

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

Gets a flow.

# `get_data_endpoint`

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

Gets the data endpoint function of a flow.

# `get_version`

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

Gets a flow version, including its flow JSON.

# `list`

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

Lists flows, most recent first.

Params: `status`, `business_account_id`, `phone_number_id`,
`name_contains`, `created_after`, `created_before`, `page`, `per_page`.

# `list_versions`

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

Lists flow versions, most recent first. Params: `page`, `per_page`.

# `publish`

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

Publishes a draft flow. Published flows cannot be unpublished. Attributes: `phone_number_id`.

# `put_data_endpoint`

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

Creates or updates the data endpoint function code (JavaScript). Deploy
it with `deploy_data_endpoint/2` and register it with
`register_data_endpoint/2`.

# `register_data_endpoint`

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

Registers the deployed data endpoint URL with Meta. Requires flows encryption.

# `setup_encryption`

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

Sets up flows encryption for the flow's WABA, required by data
endpoints. Attributes: `phone_number_id`.

---

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