# `Wardrik.Channel`

A behaviour for chat apps, like Slack, that people reach agents through.

    channels: [slack: {WardrikSlack, token: token, signing_secret: secret}]

Requests to `POST /v1/channels/{channel}/{path}` reach `c:request/2` unchanged, so the channel
can check their signature. To deliver one yourself:

    {:ok, answer} = Wardrik.Channel.deliver(scope,
      channel: "slack",
      path: "events",
      body: body,
      headers: headers
    )

Every callback's options also hold:

  * `:wardrik` - the instance the channel runs under.
  * `:channel` - the channel's name.
  * `:store` - Wardrik's store. Prefix your keys with your package's name.

# `request`

```elixir
@type request() :: %{
  path: String.t(),
  body: String.t(),
  headers: %{required(String.t()) =&gt; String.t()}
}
```

A request from the chat app. `headers` are keyed by lowercase name.

# `response`

```elixir
@type response() :: %{
  status: pos_integer(),
  headers: %{required(String.t()) =&gt; String.t()},
  body: String.t()
}
```

The response sent back to the chat app.

# `child_spec`

```elixir
@callback child_spec(opts :: keyword()) :: Supervisor.child_spec()
```

Returns the child spec the channel runs as.

# `notify`
*optional* 

```elixir
@callback notify(Wardrik.Channel.Notification.t(), opts :: keyword()) ::
  :ok | {:skip, String.t()} | {:error, term()}
```

Posts a `Wardrik.Channel.Notification`, or returns `{:skip, reason}`. Optional.

# `request`

```elixir
@callback request(request(), opts :: keyword()) :: response()
```

Handles a request from the chat app and returns the response.

# `deliver`

```elixir
@spec deliver(Wardrik.Scope.t(), keyword()) ::
  term() | :ok | {:error, Wardrik.Error.t()}
```

Deliver a chat app request to a channel.

    Wardrik.Channel.deliver(scope, channel: "slack", path: "events", body: body, headers: headers)

Passes a request from a chat app such as Slack, unchanged, to the channel with this name. The channel verifies it, for example by its signature, and responds in the format the chat app expects. Returns not_found if no channel with this name accepts requests.

`POST /v1/channels/{channel}/{path}`

---

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