plugins/gateways/telegram/handler

Text message handler for Telegram. Receives incoming messages, runs the agent loop, and sends replies. Also handles approval callback queries from inline keyboards.

Approval flow (async, non-blocking):

  1. Tool returns NeedsApproval → loop calls make_approval_handler
  2. Approval handler saves request to PD, sends buttons, returns tool.Defer
  3. Loop returns AwaitingApproval — session history is NOT updated
  4. Callback handler receives user choice: a) Approved: caches approval in PD, executes tool, builds synthetic history, re-runs loop — LLM sees the tool result and continues. b) Denied: builds synthetic history with an error result, re-runs loop — LLM sees the denial and can adapt.

Values

pub fn new_router(
  conn: sqlight.Connection,
  client: client.Client,
  tool_defs: List(tool_def.ToolDefinition),
  max_rounds: Int,
  guardrail: behaviours.Guardrail,
  log: behaviours.Logger,
  db_connector: behaviours.DbConnector,
  db_path: String,
) -> router.Router(session.Session, String)

Build a Router that handles incoming text messages and approval callbacks.

Search Document