LemonRouter.AgentEndpoints (lemon_router v0.1.0)

View Source

Persistent endpoint aliases for agent routing.

Endpoints map friendly names (for example "ops-room") to a canonical route:

%{
  channel_id: "telegram",
  account_id: "default",
  peer_kind: :group,
  peer_id: "-100123456",
  thread_id: "42"
}

In addition to stored aliases, this module resolves Telegram shorthand targets:

  • tg:<chat_id>
  • tg:<chat_id>/<topic_id>
  • tg:<chat_id>#<topic_id>
  • telegram:<chat_id>
  • telegram:<chat_id>/<topic_id>
  • optional account prefix: tg:<account_id>@<chat_id>/<topic_id>

Summary

Types

endpoint()

@type endpoint() :: %{
  id: binary(),
  agent_id: binary(),
  name: binary(),
  description: binary() | nil,
  route: route(),
  target: binary(),
  session_key: binary(),
  created_at_ms: integer(),
  updated_at_ms: integer()
}

resolve_result()

@type resolve_result() :: %{
  route: route(),
  endpoint: endpoint() | nil,
  target: binary()
}

route()

@type route() :: %{
  channel_id: binary(),
  account_id: binary(),
  peer_kind: :dm | :group | :channel | :unknown,
  peer_id: binary(),
  thread_id: binary() | nil
}

Functions

delete(agent_id, name)

@spec delete(binary(), binary()) :: :ok | {:error, term()}

get(agent_id, name)

@spec get(binary(), binary()) :: {:ok, endpoint()} | {:error, :not_found}

list(opts \\ [])

@spec list(keyword()) :: [endpoint()]

put(agent_id, name, target, opts \\ [])

@spec put(binary(), binary(), term(), keyword()) ::
  {:ok, endpoint()} | {:error, term()}

resolve(agent_id, target, opts \\ [])

@spec resolve(binary(), term(), keyword()) ::
  {:ok, resolve_result()} | {:error, term()}

Resolve a target into a canonical route.

Target can be:

  • endpoint alias name (stored under agent_id)
  • Telegram shorthand string (tg:...)
  • route map

route_filter(route)

@spec route_filter(route()) :: map()

route_session_key(agent_id, route)

@spec route_session_key(binary(), route()) :: binary()

route_signature(route)

@spec route_signature(route()) ::
  {binary(), binary(), atom(), binary(), binary() | nil}