-module(telega_httpc). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/telega_httpc.gleam"). -export([fetch_adapter/1, fetch_bits_adapter/1, new/1, new_with_queue/1]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. ?MODULEDOC( " httpc adapter for the Telega Telegram Bot Library.\n" "\n" " Provides a `TelegramClient` that uses `gleam_httpc` as the HTTP backend.\n" "\n" " ```gleam\n" " import telega\n" " import telega_httpc\n" "\n" " pub fn main() {\n" " let client = telega_httpc.new(\"BOT_TOKEN\")\n" " let assert Ok(_bot) =\n" " telega.new_for_polling(client)\n" " |> telega.with_router(router)\n" " |> telega.init_for_polling_nil_session()\n" " }\n" " ```\n" ). -file("src/telega_httpc.gleam", 47). ?DOC( " The httpc fetch adapter for JSON API requests.\n" "\n" " Exposed so you can use it with `client.set_fetch_client` if needed.\n" ). -spec fetch_adapter(gleam@http@request:request(binary())) -> {ok, gleam@http@response:response(binary())} | {error, telega@error:telega_error()}. fetch_adapter(Req) -> _pipe = gleam@httpc:send(Req), gleam@result:map_error( _pipe, fun(Err) -> {fetch_error, gleam@string:inspect(Err)} end ). -file("src/telega_httpc.gleam", 57). ?DOC( " The httpc fetch adapter for binary file downloads.\n" "\n" " Exposed so you can use it with `client.set_fetch_bits_client` if needed.\n" ). -spec fetch_bits_adapter(gleam@http@request:request(bitstring())) -> {ok, gleam@http@response:response(bitstring())} | {error, telega@error:telega_error()}. fetch_bits_adapter(Req) -> _pipe = gleam@httpc:send_bits(Req), gleam@result:map_error( _pipe, fun(Err) -> {fetch_error, gleam@string:inspect(Err)} end ). -file("src/telega_httpc.gleam", 31). ?DOC( " Create a new Telegram client using httpc as the HTTP backend.\n" "\n" " This sets up both `FetchClient` (for JSON API calls) and\n" " `FetchBitsClient` (for binary file downloads).\n" ). -spec new(binary()) -> telega@client:telegram_client(). new(Token) -> _pipe = telega@client:new(Token, fun fetch_adapter/1), telega@client:set_fetch_bits_client(_pipe, fun fetch_bits_adapter/1). -file("src/telega_httpc.gleam", 37). ?DOC(" Create a new Telegram client with httpc and default request queue.\n"). -spec new_with_queue(binary()) -> {ok, telega@client:telegram_client()} | {error, telega@error:telega_error()}. new_with_queue(Token) -> _pipe = telega@client:new_with_queue(Token, fun fetch_adapter/1), gleam@result:map( _pipe, fun(_capture) -> telega@client:set_fetch_bits_client( _capture, fun fetch_bits_adapter/1 ) end ).