TelegramEx.API (TelegramEx v1.3.0)

Copy Markdown View Source

HTTP wrapper around the Telegram Bot API.

Most application code should use builder modules instead of calling this module directly. See Messages and Media.

Summary

Functions

Answers a callback query from an inline keyboard button.

Fetches updates from Telegram using long polling.

Sends a request to the Telegram Bot API.

Types

request_context()

@type request_context() :: %{
  :chat_id => integer(),
  :token => String.t(),
  :method => String.t(),
  :payload => map(),
  :format => :json | :multipart,
  optional(:message_thread_id) => integer()
}

updates()

@type updates() :: TelegramEx.Types.updates()

Functions

answer_callback_query(token, map)

@spec answer_callback_query(String.t(), TelegramEx.Types.CallbackQuery.t()) ::
  :ok | {:error, any()}

Answers a callback query from an inline keyboard button.

This function should be called after handling a callback query to acknowledge it and optionally show an alert or notification to the user.

Most code should call TelegramEx.Builder.Message.answer_callback_query/2 in a builder pipeline.

get_updates(token, offset)

@spec get_updates(String.t(), integer()) :: {:ok, updates()} | {:error, any()}

Fetches updates from Telegram using long polling.

This function is called internally by TelegramEx.Server to retrieve new messages and callbacks.

request(ctx)

@spec request(request_context()) :: :ok | {:error, term()}

Sends a request to the Telegram Bot API.

Expects a builder context with :chat_id, :token, :method, :payload, and :format.

set_my_commands(commands, token)