Raxol.Gateway.Adapter behaviour (RaxolGateway v0.2.0)

Copy Markdown View Source

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.

Summary

Types

config()

@type config() :: term()

conn()

@type conn() :: term()

event()

@type event() :: term()

raw()

@type raw() :: term()

rendered()

@type rendered() :: term()

Callbacks

connect(config)

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

disconnect(conn)

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

normalize_event(raw)

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

platform()

@callback platform() :: atom()

send_message(conn, t, rendered)

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