Nadia. Context
(nadia v1.3.0)
View Source
Convenience helpers for working with incoming Telegram updates.
Nadia.Context does not replace the raw Bot API wrappers. It extracts the
common message, chat, and user values from an update and provides small reply
helpers that delegate to existing Nadia functions.
Summary
Functions
Answers the context's callback query.
Returns the effective chat id for an update or context.
Returns the chat most directly associated with an update or context.
Returns the message most directly associated with an update or context.
Returns the user most directly associated with an update or context.
Builds a context from a parsed Telegram update.
Sends a text message to the context's effective chat.
Types
@type t() :: %Nadia.Context{ callback_query: Nadia.Model.CallbackQuery.t() | nil, chat: Nadia.Model.Chat.t() | nil, chat_id: integer() | binary() | nil, client: Nadia.Client.t() | nil, from: Nadia.Model.User.t() | nil, inline_query: Nadia.Model.InlineQuery.t() | nil, message: Nadia.Model.Message.t() | nil, message_id: integer() | nil, update: Nadia.Model.Update.t() }
Functions
@spec answer_callback( t(), keyword() ) :: :ok | {:error, Nadia.Model.Error.t()}
Answers the context's callback query.
Returns the same result shape as Nadia.answer_callback_query/2.
@spec chat_id(t() | Nadia.Model.Update.t()) :: integer() | binary() | nil
Returns the effective chat id for an update or context.
@spec effective_chat(t() | Nadia.Model.Update.t()) :: Nadia.Model.Chat.t() | nil
Returns the chat most directly associated with an update or context.
@spec effective_message(t() | Nadia.Model.Update.t()) :: Nadia.Model.Message.t() | nil
Returns the message most directly associated with an update or context.
Callback query messages are considered effective messages so callback-driven handlers can reply to the chat that produced the callback.
@spec effective_user(t() | Nadia.Model.Update.t()) :: Nadia.Model.User.t() | nil
Returns the user most directly associated with an update or context.
@spec new(Nadia.Model.Update.t(), Nadia.Client.t() | keyword() | map() | nil) :: t()
Builds a context from a parsed Telegram update.
The second argument may be a %Nadia.Client{} or options containing
:client. When no client is supplied, reply helpers use Nadia's existing
application-config based wrappers.
@spec reply(t(), binary(), keyword()) :: {:ok, Nadia.Model.Message.t()} | {:error, Nadia.Model.Error.t()}
Sends a text message to the context's effective chat.
Returns the same result shape as Nadia.send_message/3.