telegram_bot_api_http behaviour (telegram_bot_api v2.9.0)

View Source

Summary

Types

'BodyFormat'()

-type 'BodyFormat'() :: string() | binary().

from()

-type from() :: {Client :: pid(), Tag :: reply_tag()}.

'HttpOption'()

-type 'HttpOption'() ::
          {timeout, timeout()} |
          {connect_timeout, timeout()} |
          {ssl, [ssl_ls_option()]} |
          {autoredirect, boolean()} |
          {proxy_auth, {string(), string()}} |
          {version, 'HttpVersion'()} |
          {relaxed, boolean()}.

'HttpVersion'()

-type 'HttpVersion'() :: string().

http_endpoint()

-type http_endpoint() :: binary().

Base URL of the HTTP(S) API endpoint. This address is used for all API requests.

Examples:

  <<"https://api.telegram.org">>
  <<"https://mysite">>
  <<"http://mysite:8081">>
  <<"http://1.2.3.4:8081">>

http_option()

-type http_option() :: ['HttpOption'(), ...].

http_port()

-type http_port() :: pos_integer().

http_proxy()

-type http_proxy() :: undefined | {string(), http_port()}.

http_timeout()

-type http_timeout() :: timeout().

ipv4()

-type ipv4() :: {0..255, 0..255, 0..255, 0..255}.

module_name()

-type module_name() :: telegram_bot_api_http | atom().

'OptionRequest'()

-type 'OptionRequest'() ::
          {sync, boolean()} |
          {stream, 'StreamTo'()} |
          {body_format, 'BodyFormat'()} |
          {full_result, boolean()} |
          {headers_as_is, boolean()} |
          {socket_opts, [term()]} |
          {receiver, 'Receiver'()} |
          {ipv6_host_with_brackets, boolean()}.

option_request()

-type option_request() :: ['OptionRequest'(), ...].

'Receiver'()

-type 'Receiver'() ::
          {telegram_bot_api_http, async_receiver, [pid]} |
          pid() |
          {ReceiverModule :: atom(), ReceiverFunction :: atom(), ReceiverArgs :: list()} |
          term().

reply_tag()

result()

-type result() ::
          {ok, HttpCode :: integer(), Json :: map(), State :: state()} |
          {ok, Ref :: reference(), State :: state()} |
          {error, Err :: term(), State :: state()}.

'StreamTo'()

-type 'StreamTo'() :: none | self | {self, once} | file:name_all().

ssl_ls_option()

-type ssl_ls_option() :: term().

state()

-type state() ::
          #{token := binary(),
            http_module := module_name(),
            http_option := http_option(),
            option_request := ['OptionRequest'(), ...],
            http_endpoint := http_endpoint(),
            http_proxy => http_proxy(),
            _ => term()}.

Callbacks

download(HttpEndpoint, FilePath, StreamTo, Async, From, State)

-callback download(HttpEndpoint :: binary(),
                   FilePath :: binary(),
                   StreamTo :: telegram_bot_api_file:name_all(),
                   Async :: boolean(),
                   From :: from(),
                   State :: state()) ->
                      result().

init(State)

-callback init(State :: state()) -> StateNew :: state().

multipart(HttpEndpoint, Method, Data, Async, From, State)

-callback multipart(HttpEndpoint :: binary(),
                    Method :: binary(),
                    Data :: map(),
                    Async :: boolean(),
                    From :: from(),
                    State :: state()) ->
                       result().

raw(HttpEndpoint, Method, Data, Async, From, State)

-callback raw(HttpEndpoint :: binary(),
              Method :: binary(),
              Data :: map(),
              Async :: boolean(),
              From :: from(),
              State :: state()) ->
                 result().

set_proxy(HttpProfile, HttpProxy)

-callback set_proxy(HttpProfile :: atom(), HttpProxy :: http_proxy()) -> ok | {error, Reason :: term()}.

terminate(State)

-callback terminate(State :: state()) -> ok.

Functions

async_receiver/2

download(HttpEndpoint, FilePath, StreamTo, Async, From, State)

-spec download(HttpEndpoint :: binary(),
               FilePath :: binary(),
               StreamTo :: telegram_bot_api_file:name_all(),
               Async :: boolean(),
               From :: from(),
               State :: state()) ->
                  result() | {ok, saved_to_file, state()}.

init(State)

-spec init(State :: state()) -> StateNew :: state().

multipart(HttpEndpoint, Method, Data, Async, From, State)

-spec multipart(HttpEndpoint :: binary(),
                Method :: binary(),
                Data :: map(),
                Async :: boolean(),
                From :: from(),
                State :: state()) ->
                   result().

raw(HttpEndpoint, Method, Data, Async, From, State)

-spec raw(HttpEndpoint :: binary(),
          Method :: binary(),
          Data :: map(),
          Async :: boolean(),
          From :: from(),
          State :: state()) ->
             result().

set_proxy(HttpProfile, HttpProxy)

-spec set_proxy(HttpProfile :: atom(), HttpProxy :: http_proxy()) -> ok | {error, Reason :: term()}.

terminate(State)

-spec terminate(State :: state()) -> ok.