Nadia. Webhook
(nadia v1.4.0)
View Source
Framework-neutral helpers for receiving Telegram webhook updates.
Nadia does not require Plug or Phoenix. Web frameworks can pass the raw request body and request headers to this module, then translate the result into the framework's response type.
Nadia.Webhook.dispatch_body(
raw_body,
MyApp.Bot,
headers: request_headers,
secret_token: System.fetch_env!("TELEGRAM_WEBHOOK_SECRET"),
client: Nadia.Client.from_config(:support)
)The Telegram secret token check uses the
x-telegram-bot-api-secret-token header. If no :secret_token is supplied,
verification is skipped.
Summary
Functions
Builds a Nadia.Context from a webhook body after optional secret validation.
Dispatches a raw webhook body to a Nadia handler or route list.
Parses a raw Telegram webhook request body into an update.
Parses a raw Telegram webhook request body into an update, raising on invalid JSON or invalid update shapes.
Returns the Telegram webhook secret token header name.
Verifies Telegram's optional webhook secret token header.
Types
Functions
@spec context(binary() | map() | Nadia.Model.Update.t(), [option()] | map()) :: {:ok, Nadia.Context.t()} | {:error, term()}
Builds a Nadia.Context from a webhook body after optional secret validation.
@spec dispatch_body( binary() | map() | Nadia.Model.Update.t(), module() | [Nadia.Dispatcher.route()], [option()] | map() ) :: term() | {:error, term()}
Dispatches a raw webhook body to a Nadia handler or route list.
Returns parser or secret verification errors as {:error, reason}. Handler
results are returned unchanged, and handler exceptions bubble to the caller.
@spec parse_body(binary() | map() | Nadia.Model.Update.t()) :: {:ok, Nadia.Model.Update.t()} | {:error, term()}
Parses a raw Telegram webhook request body into an update.
@spec parse_body!(binary() | map() | Nadia.Model.Update.t()) :: Nadia.Model.Update.t()
Parses a raw Telegram webhook request body into an update, raising on invalid JSON or invalid update shapes.
@spec secret_token_header() :: binary()
Returns the Telegram webhook secret token header name.
Verifies Telegram's optional webhook secret token header.
Passing nil as the expected secret disables verification. Header names are
matched case-insensitively.