LemonGateway.Transport behaviour (lemon_gateway v0.1.0)

View Source

Behaviour for transport plugins that receive messages from external sources.

A transport is responsible for:

  • Connecting to an external messaging service (Telegram, Discord, etc.)
  • Converting incoming messages to Jobs
  • Submitting jobs to the gateway

Usage

defmodule MyTransport do
  use LemonGateway.Transport

  @impl true
  def id, do: "mytransport"

  @impl true
  def start_link(opts) do
    GenServer.start_link(__MODULE__, opts, name: __MODULE__)
  end
end

Summary

Callbacks

Returns the child spec for starting this transport under a supervisor.

Returns the unique identifier for this transport.

Starts the transport process.

Callbacks

child_spec(opts)

(optional)
@callback child_spec(opts :: keyword()) :: Supervisor.child_spec()

Returns the child spec for starting this transport under a supervisor.

Optional callback - defaults to a worker spec using start_link/1.

id()

@callback id() :: String.t()

Returns the unique identifier for this transport.

Must be a lowercase string matching ^[a-z][a-z0-9_-]*$.

start_link(opts)

@callback start_link(opts :: keyword()) :: GenServer.on_start()

Starts the transport process.

The transport should start any required polling or connection management. Returns {:ok, pid} on success, :ignore if the transport is disabled, or {:error, reason} on failure.