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

The per-chat logic a `Raxol.Gateway.Session` runs.

A handler is initialized once per chat with its route, then handles each
inbound event, optionally returning a rendered message to deliver back.
Any module satisfying `init/2` and `handle_event/2` works;
`Raxol.Gateway.Handler.Lifecycle` (a full TEA app under
`environment: :gateway`) ships with the package.

The optional `terminate/2` runs when the session stops cleanly (idle
timeout, `SessionRouter.stop_session/2`, supervisor shutdown, explicit
stop; the session traps exits so supervisor-driven stops reach it) -- the
hook for a handler that owns linked processes, since a session's `:normal`
exit does not propagate over links. It is best-effort: a brutally killed
session never reaches it.

# `event`

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

# `rendered`

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

# `state`

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

# `handle_event`

```elixir
@callback handle_event(event(), state()) ::
  {:reply, rendered(), state()} | {:noreply, state()}
```

# `init`

```elixir
@callback init(Raxol.Gateway.Route.t(), keyword()) :: {:ok, state()} | {:error, term()}
```

# `terminate`
*optional* 

```elixir
@callback terminate(reason :: term(), state()) :: term()
```

---

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