GenRouter.Conn (gen_router v0.1.10)

Structure which represents connection with Telegram bot. Inspired by %Plug.Conn{}, adapted for bots.

Attributes:

  • skip: system buffer to keep track of skipped scopes;
  • path: route to controller which should handle this object;
  • params: payload which will be passed to controller;
  • assigns: non-parsed data assigned by a system (auth, etc);
  • scope: local scope of current request, clears for each new route;
  • code: response code, we use common HTTP codes, currently only 200 is supported;
  • response: response payload, usually JSON;
  • halted: stop the pipeline execution if conn was settled.

Summary

Functions

Assign variable to current request.

Build Conn object with system fields

Update state and complete the current request.

Put the next path after the current request.

Halt execution pipeline, Conn is settled.

Reset router matching pipeline

Types

t()

@type t() :: %GenRouter.Conn{
  __skip__: term(),
  assigns: term(),
  code: term(),
  halted: term(),
  params: term(),
  path: term(),
  response: term(),
  scope: term()
}

Functions

assign(conn, key, value)

@spec assign(t(), atom(), any()) :: t()

Assign variable to current request.

build(router_module, map)

@spec build(module(), map()) :: t()

Build Conn object with system fields

complete(conn, response \\ :default, scope \\ :default, code \\ :default)

@spec complete(
  t(),
  String.t() | nil | :default,
  map() | :default,
  integer() | :default
) :: t()

Update state and complete the current request.

forward(conn, path \\ "/", scope \\ %{}, opts \\ [])

@spec forward(t(), String.t(), map(), Keyword.t()) :: t()

Put the next path after the current request.

It unhalts settled conn, so all the pipelines will be executed again.

halt(conn)

@spec halt(t()) :: t()

Halt execution pipeline, Conn is settled.

reset_router_matches(conn, router_module)

@spec reset_router_matches(t(), module()) :: t()

Reset router matching pipeline