# `Raxol.Gateway.Adapter`
[🔗](https://github.com/DROOdotFOO/raxol/blob/raxol_gateway-v0.2.0/lib/raxol/gateway/adapter.ex#L1)

The contract every platform implements to plug into the gateway.

An adapter owns only platform I/O and translation. Routing, sessions, auth, and
history live in the gateway, so adding a platform is implementing these five
callbacks:

  * `connect/1` -- open the platform connection, returning an opaque handle.
  * `disconnect/1` -- close it.
  * `platform/0` -- the platform's atom id (`:telegram`, `:discord`, ...).
  * `normalize_event/1` -- map a raw inbound payload to `{:ok, route, event}`
    or `:ignore`. `event` is whatever a `Raxol.Gateway.Handler` expects.
  * `send_message/3` -- deliver a rendered outbound message to a route.

`Raxol.Gateway.Adapter.InMemory` is a reference implementation.

## Stability

Frozen: these five callbacks are the stable contract every platform
adapter builds against, including adapters that live outside this repo.
Additions must be optional callbacks; existing callbacks do not change
shape.

# `config`

```elixir
@type config() :: term()
```

# `conn`

```elixir
@type conn() :: term()
```

# `event`

```elixir
@type event() :: term()
```

# `raw`

```elixir
@type raw() :: term()
```

# `rendered`

```elixir
@type rendered() :: term()
```

# `connect`

```elixir
@callback connect(config()) :: {:ok, conn()} | {:error, term()}
```

# `disconnect`

```elixir
@callback disconnect(conn()) :: :ok
```

# `normalize_event`

```elixir
@callback normalize_event(raw()) :: {:ok, Raxol.Gateway.Route.t(), event()} | :ignore
```

# `platform`

```elixir
@callback platform() :: atom()
```

# `send_message`

```elixir
@callback send_message(conn(), Raxol.Gateway.Route.t(), rendered()) ::
  :ok | {:error, term()}
```

---

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