Packages

BEAM-native coding agent substrate for Elixir/OTP projects

Current section

Files

Jump to
vibe lib vibe gateway telegram backend.ex
Raw

lib/vibe/gateway/telegram/backend.ex

defmodule Vibe.Gateway.Telegram.Backend do
@moduledoc """
Telegram implementation of the generic gateway backend contract.
The backend ties together Telegram config, update normalization, authorization,
and outbound adapter selection while keeping ExGram and Bot API semantics out
of the generic gateway runtime.
"""
@behaviour Vibe.Gateway.Backend
alias Vibe.Gateway.Message
alias Vibe.Gateway.Telegram.{Adapter, Authorization, Config, Polling, Update}
@impl true
def load_config(opts), do: Config.load(opts)
@impl true
def normalize(update, %Config{} = config) do
Update.normalize(update,
bot_id: Map.get(config, :bot_id),
bot_username: Map.get(config, :bot_username)
)
end
@impl true
def authorized?(%Message{} = message, trigger, %Config{} = config) do
Authorization.authorized?(message.source, config) and
Authorization.trigger_allowed?(message.source, trigger, config)
end
@impl true
def outbound_adapter(%Config{}), do: Adapter
@impl true
def child_specs(%Config{method: :polling} = config, runtime) do
[
%{
id: :telegram_polling,
start: {Polling, :start_link, [[config: config, runtime: runtime, name: polling_name()]]}
}
]
end
def child_specs(%Config{}, _runtime), do: []
defp polling_name,
do: {:via, Registry, {Vibe.Registry, {:gateway_transport, :telegram_polling}}}
end