-module(telega). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([is_webhook_path/2, is_secret_token_valid/2, get_api_config/1, new/4, handle_all/2, wait_any/4, handle_command/3, wait_command/5, handle_commands/3, wait_commands/5, handle_text/2, wait_text/4, handle_hears/3, wait_hears/5, handle_message/2, wait_message/4, handle_callback_query/3, wait_callback_query/5, handle_voice/2, wait_voice/4, handle_audio/2, wait_audio/4, handle_video/2, wait_video/4, handle_photos/2, wait_photos/4, handle_web_app_data/2, wait_web_app_data/4, with_catch_handler/2, handle_chat_member/2, log_context/3, with_session_settings/4, set_drop_pending_updates/2, set_max_connections/2, set_ip_address/2, set_allowed_updates/2, set_certificate/2, init/1, init_nil_session/1, handle_update/2]). -export_type([telega/2, telega_builder/2]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. -opaque telega(ANLM, ANLN) :: {telega, telega@internal@config:config(), telega@model:user(), gleam@erlang@process:subject(telega@bot:bot_message())} | {gleam_phantom, ANLM, ANLN}. -opaque telega_builder(ANLO, ANLP) :: {telega_builder, telega@internal@config:config(), list(telega@bot:handler(ANLO, ANLP)), gleam@option:option(telega@bot:session_settings(ANLO, ANLP)), gleam@option:option(gleam@erlang@process:subject(telega@bot:bot_message())), gleam@option:option(fun((telega@bot:context(ANLO, ANLP), ANLP) -> {ok, nil} | {error, ANLP})), gleam@option:option(boolean()), gleam@option:option(integer()), gleam@option:option(binary()), gleam@option:option(list(binary())), gleam@option:option(telega@model:file())}. -file("src/telega.gleam", 49). ?DOC( " Check if a path is the webhook path for the bot.\n" "\n" " Useful if you plan to implement own adapter.\n" ). -spec is_webhook_path(telega(any(), any()), binary()) -> boolean(). is_webhook_path(Telega, Path) -> erlang:element(3, erlang:element(2, Telega)) =:= Path. -file("src/telega.gleam", 56). ?DOC( " Check if a secret token is valid.\n" "\n" " Useful if you plan to implement own adapter.\n" ). -spec is_secret_token_valid(telega(any(), any()), binary()) -> boolean(). is_secret_token_valid(Telega, Token) -> erlang:element(4, erlang:element(2, Telega)) =:= Token. -file("src/telega.gleam", 61). ?DOC(" Helper to get the config for API requests.\n"). -spec get_api_config(telega(any(), any())) -> telega@client:telegram_client(). get_api_config(Telega) -> erlang:element(5, erlang:element(2, Telega)). -file("src/telega.gleam", 66). ?DOC(" Create a new Telega instance.\n"). -spec new(binary(), binary(), binary(), gleam@option:option(binary())) -> telega_builder(any(), any()). new(Token, Server_url, Webhook_path, Secret_token) -> Url = telega@internal@utils:normalize_url(Server_url), Webhook_path@1 = telega@internal@utils:normalize_webhook_path(Webhook_path), {telega_builder, telega@internal@config:new(Token, Url, Webhook_path@1, Secret_token), [], none, none, none, none, none, none, none, none}. -file("src/telega.gleam", 90). ?DOC(" Handles all messages.\n"). -spec handle_all( telega_builder(ANMH, ANMI), fun((telega@bot:context(ANMH, ANMI), telega@update:update()) -> {ok, telega@bot:context(ANMH, ANMI)} | {error, ANMI}) ) -> telega_builder(ANMH, ANMI). handle_all(Builder, Handler) -> _record = Builder, {telega_builder, erlang:element(2, _record), [{handle_all, Handler} | erlang:element(3, Builder)], erlang:element(4, _record), erlang:element(5, _record), erlang:element(6, _record), erlang:element(7, _record), erlang:element(8, _record), erlang:element(9, _record), erlang:element(10, _record), erlang:element(11, _record)}. -file("src/telega.gleam", 101). ?DOC( " Stops bot message handling from current chat and waits for any message.\n" "\n" " See [conversation](/docs/conversation)\n" ). -spec wait_any( telega@bot:context(ANMS, ANMT), fun((telega@bot:context(ANMS, ANMT), telega@update:update()) -> {ok, telega@bot:context(ANMS, ANMT)} | {error, ANMT}), gleam@option:option(telega@bot:handler(ANMS, ANMT)), gleam@option:option(integer()) ) -> {ok, telega@bot:context(ANMS, ANMT)} | {error, any()}. wait_any(Ctx, Handler, Handle_else, Timeout) -> telega@bot:wait_handler(Ctx, {handle_all, Handler}, Handle_else, Timeout). -file("src/telega.gleam", 112). ?DOC(" Handles a specific command.\n"). -spec handle_command( telega_builder(ANNF, ANNG), binary(), fun((telega@bot:context(ANNF, ANNG), telega@update:command()) -> {ok, telega@bot:context(ANNF, ANNG)} | {error, ANNG}) ) -> telega_builder(ANNF, ANNG). handle_command(Builder, Command, Handler) -> _record = Builder, {telega_builder, erlang:element(2, _record), [{handle_command, Command, Handler} | erlang:element(3, Builder)], erlang:element(4, _record), erlang:element(5, _record), erlang:element(6, _record), erlang:element(7, _record), erlang:element(8, _record), erlang:element(9, _record), erlang:element(10, _record), erlang:element(11, _record)}. -file("src/telega.gleam", 127). ?DOC( " Stops bot message handling from current chat and waits for a specific command.\n" "\n" " See [conversation](/docs/conversation)\n" ). -spec wait_command( telega@bot:context(ANNQ, ANNR), binary(), fun((telega@bot:context(ANNQ, ANNR), telega@update:command()) -> {ok, telega@bot:context(ANNQ, ANNR)} | {error, ANNR}), gleam@option:option(telega@bot:handler(ANNQ, ANNR)), gleam@option:option(integer()) ) -> {ok, telega@bot:context(ANNQ, ANNR)} | {error, any()}. wait_command(Ctx, Command, Continue, Handle_else, Timeout) -> telega@bot:wait_handler( Ctx, {handle_command, Command, Continue}, Handle_else, Timeout ). -file("src/telega.gleam", 144). ?DOC(" Handles multiple commands.\n"). -spec handle_commands( telega_builder(ANOD, ANOE), list(binary()), fun((telega@bot:context(ANOD, ANOE), telega@update:command()) -> {ok, telega@bot:context(ANOD, ANOE)} | {error, ANOE}) ) -> telega_builder(ANOD, ANOE). handle_commands(Builder, Commands, Handler) -> _record = Builder, {telega_builder, erlang:element(2, _record), [{handle_commands, Commands, Handler} | erlang:element(3, Builder)], erlang:element(4, _record), erlang:element(5, _record), erlang:element(6, _record), erlang:element(7, _record), erlang:element(8, _record), erlang:element(9, _record), erlang:element(10, _record), erlang:element(11, _record)}. -file("src/telega.gleam", 159). ?DOC( " Stops bot message handling from current chat and waits for a specific command.\n" "\n" " See [conversation](/docs/conversation)\n" ). -spec wait_commands( telega@bot:context(ANOP, ANOQ), list(binary()), fun((telega@bot:context(ANOP, ANOQ), telega@update:command()) -> {ok, telega@bot:context(ANOP, ANOQ)} | {error, ANOQ}), gleam@option:option(telega@bot:handler(ANOP, ANOQ)), gleam@option:option(integer()) ) -> {ok, telega@bot:context(ANOP, ANOQ)} | {error, any()}. wait_commands(Ctx, Commands, Continue, Handle_else, Timeout) -> telega@bot:wait_handler( Ctx, {handle_commands, Commands, Continue}, Handle_else, Timeout ). -file("src/telega.gleam", 176). ?DOC(" Handles text messages.\n"). -spec handle_text( telega_builder(ANPD, ANPE), fun((telega@bot:context(ANPD, ANPE), binary()) -> {ok, telega@bot:context(ANPD, ANPE)} | {error, ANPE}) ) -> telega_builder(ANPD, ANPE). handle_text(Builder, Handler) -> _record = Builder, {telega_builder, erlang:element(2, _record), [{handle_text, Handler} | erlang:element(3, Builder)], erlang:element(4, _record), erlang:element(5, _record), erlang:element(6, _record), erlang:element(7, _record), erlang:element(8, _record), erlang:element(9, _record), erlang:element(10, _record), erlang:element(11, _record)}. -file("src/telega.gleam", 187). ?DOC( " Stops bot message handling from current chat and waits for a text message.\n" "\n" " See [conversation](/docs/conversation)\n" ). -spec wait_text( telega@bot:context(ANPO, ANPP), fun((telega@bot:context(ANPO, ANPP), binary()) -> {ok, telega@bot:context(ANPO, ANPP)} | {error, ANPP}), gleam@option:option(telega@bot:handler(ANPO, ANPP)), gleam@option:option(integer()) ) -> {ok, telega@bot:context(ANPO, ANPP)} | {error, any()}. wait_text(Ctx, Continue, Handle_else, Timeout) -> telega@bot:wait_handler(Ctx, {handle_text, Continue}, Handle_else, Timeout). -file("src/telega.gleam", 198). ?DOC(" Handles messages that match the given `Hears`.\n"). -spec handle_hears( telega_builder(ANQB, ANQC), telega@bot:hears(), fun((telega@bot:context(ANQB, ANQC), binary()) -> {ok, telega@bot:context(ANQB, ANQC)} | {error, ANQC}) ) -> telega_builder(ANQB, ANQC). handle_hears(Builder, Hears, Handler) -> _record = Builder, {telega_builder, erlang:element(2, _record), [{handle_hears, Hears, Handler} | erlang:element(3, Builder)], erlang:element(4, _record), erlang:element(5, _record), erlang:element(6, _record), erlang:element(7, _record), erlang:element(8, _record), erlang:element(9, _record), erlang:element(10, _record), erlang:element(11, _record)}. -file("src/telega.gleam", 213). ?DOC( " Stops bot message handling from current chat and waits for a message that matches the given `Hears`.\n" "\n" " See [conversation](/docs/conversation)\n" ). -spec wait_hears( telega@bot:context(ANQM, ANQN), telega@bot:hears(), fun((telega@bot:context(ANQM, ANQN), binary()) -> {ok, telega@bot:context(ANQM, ANQN)} | {error, ANQN}), gleam@option:option(telega@bot:handler(ANQM, ANQN)), gleam@option:option(integer()) ) -> {ok, telega@bot:context(ANQM, ANQN)} | {error, any()}. wait_hears(Ctx, Hears, Continue, Handle_else, Timeout) -> telega@bot:wait_handler( Ctx, {handle_hears, Hears, Continue}, Handle_else, Timeout ). -file("src/telega.gleam", 229). ?DOC(" Handles any message.\n"). -spec handle_message( telega_builder(ANQU, ANQV), fun((telega@bot:context(ANQU, ANQV), telega@model:message()) -> {ok, telega@bot:context(ANQU, ANQV)} | {error, ANQV}) ) -> telega_builder(ANQU, ANQV). handle_message(Builder, Handler) -> _record = Builder, {telega_builder, erlang:element(2, _record), [{handle_message, Handler} | erlang:element(3, Builder)], erlang:element(4, _record), erlang:element(5, _record), erlang:element(6, _record), erlang:element(7, _record), erlang:element(8, _record), erlang:element(9, _record), erlang:element(10, _record), erlang:element(11, _record)}. -file("src/telega.gleam", 243). ?DOC( " Stops bot message handling from current chat and waits for any message.\n" "\n" " See [conversation](/docs/conversation)\n" ). -spec wait_message( telega@bot:context(ANRF, ANRG), fun((telega@bot:context(ANRF, ANRG), telega@model:message()) -> {ok, telega@bot:context(ANRF, ANRG)} | {error, ANRG}), gleam@option:option(telega@bot:handler(ANRF, ANRG)), gleam@option:option(integer()) ) -> {ok, telega@bot:context(ANRF, ANRG)} | {error, any()}. wait_message(Ctx, Continue, Handle_else, Timeout) -> telega@bot:wait_handler( Ctx, {handle_message, Continue}, Handle_else, Timeout ). -file("src/telega.gleam", 260). ?DOC( " Handles messages from inline keyboard callback.\n" "\n" " See [conversation](/docs/conversation)\n" ). -spec handle_callback_query( telega_builder(ANRN, ANRO), telega@bot:callback_query_filter(), fun((telega@bot:context(ANRN, ANRO), binary(), binary()) -> {ok, telega@bot:context(ANRN, ANRO)} | {error, ANRO}) ) -> telega_builder(ANRN, ANRO). handle_callback_query(Builder, Filter, Handler) -> _record = Builder, {telega_builder, erlang:element(2, _record), [{handle_callback_query, Filter, Handler} | erlang:element(3, Builder)], erlang:element(4, _record), erlang:element(5, _record), erlang:element(6, _record), erlang:element(7, _record), erlang:element(8, _record), erlang:element(9, _record), erlang:element(10, _record), erlang:element(11, _record)}. -file("src/telega.gleam", 274). ?DOC( " Wait for a callback query and continue with the given function.\n" "\n" " See [conversation](/docs/conversation)\n" ). -spec wait_callback_query( telega@bot:context(ANRT, ANRU), telega@bot:callback_query_filter(), fun((telega@bot:context(ANRT, ANRU), binary(), binary()) -> {ok, telega@bot:context(ANRT, ANRU)} | {error, ANRU}), gleam@option:option(telega@bot:handler(ANRT, ANRU)), gleam@option:option(integer()) ) -> {ok, telega@bot:context(ANRT, ANRU)} | {error, any()}. wait_callback_query(Ctx, Filter, Continue, Handle_else, Timeout) -> telega@bot:wait_handler( Ctx, {handle_callback_query, Filter, Continue}, Handle_else, Timeout ). -file("src/telega.gleam", 290). ?DOC(" Handles voice messages.\n"). -spec handle_voice( telega_builder(ANSB, ANSC), fun((telega@bot:context(ANSB, ANSC), telega@model:voice()) -> {ok, telega@bot:context(ANSB, ANSC)} | {error, ANSC}) ) -> telega_builder(ANSB, ANSC). handle_voice(Builder, Handler) -> _record = Builder, {telega_builder, erlang:element(2, _record), [{handle_voice, Handler} | erlang:element(3, Builder)], erlang:element(4, _record), erlang:element(5, _record), erlang:element(6, _record), erlang:element(7, _record), erlang:element(8, _record), erlang:element(9, _record), erlang:element(10, _record), erlang:element(11, _record)}. -file("src/telega.gleam", 301). ?DOC( " Stops bot message handling from current chat and waits for a voice message.\n" "\n" " See [conversation](/docs/conversation)\n" ). -spec wait_voice( telega@bot:context(ANSM, ANSN), fun((telega@bot:context(ANSM, ANSN), telega@model:voice()) -> {ok, telega@bot:context(ANSM, ANSN)} | {error, ANSN}), gleam@option:option(telega@bot:handler(ANSM, ANSN)), gleam@option:option(integer()) ) -> {ok, telega@bot:context(ANSM, ANSN)} | {error, any()}. wait_voice(Ctx, Continue, Handle_else, Timeout) -> telega@bot:wait_handler(Ctx, {handle_voice, Continue}, Handle_else, Timeout). -file("src/telega.gleam", 311). ?DOC(" Handles audio messages.\n"). -spec handle_audio( telega_builder(ANSU, ANSV), fun((telega@bot:context(ANSU, ANSV), telega@model:audio()) -> {ok, telega@bot:context(ANSU, ANSV)} | {error, ANSV}) ) -> telega_builder(ANSU, ANSV). handle_audio(Builder, Handler) -> _record = Builder, {telega_builder, erlang:element(2, _record), [{handle_audio, Handler} | erlang:element(3, Builder)], erlang:element(4, _record), erlang:element(5, _record), erlang:element(6, _record), erlang:element(7, _record), erlang:element(8, _record), erlang:element(9, _record), erlang:element(10, _record), erlang:element(11, _record)}. -file("src/telega.gleam", 322). ?DOC( " Stops bot message handling from current chat and waits for an audio message.\n" "\n" " See [conversation](/docs/conversation)\n" ). -spec wait_audio( telega@bot:context(ANTF, ANTG), fun((telega@bot:context(ANTF, ANTG), telega@model:audio()) -> {ok, telega@bot:context(ANTF, ANTG)} | {error, ANTG}), gleam@option:option(telega@bot:handler(ANTF, ANTG)), gleam@option:option(integer()) ) -> {ok, telega@bot:context(ANTF, ANTG)} | {error, any()}. wait_audio(Ctx, Continue, Handle_else, Timeout) -> telega@bot:wait_handler(Ctx, {handle_audio, Continue}, Handle_else, Timeout). -file("src/telega.gleam", 332). ?DOC(" Handles video messages.\n"). -spec handle_video( telega_builder(ANTN, ANTO), fun((telega@bot:context(ANTN, ANTO), telega@model:video()) -> {ok, telega@bot:context(ANTN, ANTO)} | {error, ANTO}) ) -> telega_builder(ANTN, ANTO). handle_video(Builder, Handler) -> _record = Builder, {telega_builder, erlang:element(2, _record), [{handle_video, Handler} | erlang:element(3, Builder)], erlang:element(4, _record), erlang:element(5, _record), erlang:element(6, _record), erlang:element(7, _record), erlang:element(8, _record), erlang:element(9, _record), erlang:element(10, _record), erlang:element(11, _record)}. -file("src/telega.gleam", 343). ?DOC( " Stops bot message handling from current chat and waits for a video message.\n" "\n" " See [conversation](/docs/conversation)\n" ). -spec wait_video( telega@bot:context(ANTY, ANTZ), fun((telega@bot:context(ANTY, ANTZ), telega@model:video()) -> {ok, telega@bot:context(ANTY, ANTZ)} | {error, ANTZ}), gleam@option:option(telega@bot:handler(ANTY, ANTZ)), gleam@option:option(integer()) ) -> {ok, telega@bot:context(ANTY, ANTZ)} | {error, any()}. wait_video(Ctx, Continue, Handle_else, Timeout) -> telega@bot:wait_handler(Ctx, {handle_video, Continue}, Handle_else, Timeout). -file("src/telega.gleam", 353). ?DOC(" Handles photo messages.\n"). -spec handle_photos( telega_builder(ANUG, ANUH), fun((telega@bot:context(ANUG, ANUH), list(telega@model:photo_size())) -> {ok, telega@bot:context(ANUG, ANUH)} | {error, ANUH}) ) -> telega_builder(ANUG, ANUH). handle_photos(Builder, Handler) -> _record = Builder, {telega_builder, erlang:element(2, _record), [{handle_photos, Handler} | erlang:element(3, Builder)], erlang:element(4, _record), erlang:element(5, _record), erlang:element(6, _record), erlang:element(7, _record), erlang:element(8, _record), erlang:element(9, _record), erlang:element(10, _record), erlang:element(11, _record)}. -file("src/telega.gleam", 364). ?DOC( " Stops bot message handling from current chat and waits for a photo message.\n" "\n" " See [conversation](/docs/conversation)\n" ). -spec wait_photos( telega@bot:context(ANUS, ANUT), fun((telega@bot:context(ANUS, ANUT), list(telega@model:photo_size())) -> {ok, telega@bot:context(ANUS, ANUT)} | {error, ANUT}), gleam@option:option(telega@bot:handler(ANUS, ANUT)), gleam@option:option(integer()) ) -> {ok, telega@bot:context(ANUS, ANUT)} | {error, any()}. wait_photos(Ctx, Continue, Handle_else, Timeout) -> telega@bot:wait_handler( Ctx, {handle_photos, Continue}, Handle_else, Timeout ). -file("src/telega.gleam", 379). ?DOC(" Handles web app data messages.\n"). -spec handle_web_app_data( telega_builder(ANVA, ANVB), fun((telega@bot:context(ANVA, ANVB), telega@model:web_app_data()) -> {ok, telega@bot:context(ANVA, ANVB)} | {error, ANVB}) ) -> telega_builder(ANVA, ANVB). handle_web_app_data(Builder, Handler) -> _record = Builder, {telega_builder, erlang:element(2, _record), [{handle_web_app_data, Handler} | erlang:element(3, Builder)], erlang:element(4, _record), erlang:element(5, _record), erlang:element(6, _record), erlang:element(7, _record), erlang:element(8, _record), erlang:element(9, _record), erlang:element(10, _record), erlang:element(11, _record)}. -file("src/telega.gleam", 393). ?DOC( " Stops bot message handling from current chat and waits for a web app data message.\n" "\n" " See [conversation](/docs/conversation)\n" ). -spec wait_web_app_data( telega@bot:context(ANVL, ANVM), fun((telega@bot:context(ANVL, ANVM), telega@model:web_app_data()) -> {ok, telega@bot:context(ANVL, ANVM)} | {error, ANVM}), gleam@option:option(telega@bot:handler(ANVL, ANVM)), gleam@option:option(integer()) ) -> {ok, telega@bot:context(ANVL, ANVM)} | {error, any()}. wait_web_app_data(Ctx, Continue, Handle_else, Timeout) -> telega@bot:wait_handler( Ctx, {handle_web_app_data, Continue}, Handle_else, Timeout ). -file("src/telega.gleam", 411). ?DOC( " Set a catch handler for all handlers.\n" "\n" " If handler returns `Error`, the chat instance will be stopped and the error will be logged\n" " The default handler is `fn(_) -> Ok(Nil)`, which will do nothing if handler returns an error\n" ). -spec with_catch_handler( telega_builder(ANVT, ANVU), fun((telega@bot:context(ANVT, ANVU), ANVU) -> {ok, nil} | {error, ANVU}) ) -> telega_builder(ANVT, ANVU). with_catch_handler(Builder, Catch_handler) -> _record = Builder, {telega_builder, erlang:element(2, _record), erlang:element(3, _record), erlang:element(4, _record), erlang:element(5, _record), {some, Catch_handler}, erlang:element(7, _record), erlang:element(8, _record), erlang:element(9, _record), erlang:element(10, _record), erlang:element(11, _record)}. -file("src/telega.gleam", 419). ?DOC(" Handles chat member update (when user joins/leaves a group). The bot must be an administrator in the chat and must explicitly specify \"chat_member\" in the list of `allowed_updates` to receive these updates.\n"). -spec handle_chat_member( telega_builder(ANWA, ANWB), fun((telega@bot:context(ANWA, ANWB), telega@model:chat_member_updated()) -> {ok, telega@bot:context(ANWA, ANWB)} | {error, ANWB}) ) -> telega_builder(ANWA, ANWB). handle_chat_member(Builder, Handler) -> _record = Builder, {telega_builder, erlang:element(2, _record), [{handle_chat_member, Handler} | erlang:element(3, Builder)], erlang:element(4, _record), erlang:element(5, _record), erlang:element(6, _record), erlang:element(7, _record), erlang:element(8, _record), erlang:element(9, _record), erlang:element(10, _record), erlang:element(11, _record)}. -file("src/telega.gleam", 431). ?DOC(" Log the message and error message if the handler fails.\n"). -spec log_context( telega@bot:context(ANWL, ANWM), binary(), fun(() -> {ok, telega@bot:context(ANWL, ANWM)} | {error, ANWM}) ) -> {ok, telega@bot:context(ANWL, ANWM)} | {error, ANWM}. log_context(Ctx, Prefix, Handler) -> Id = telega@internal@utils:random_string(5), Prefix@1 = <<<<<<<<"["/utf8, Prefix/binary>>/binary, ":"/utf8>>/binary, Id/binary>>/binary, "] "/utf8>>, telega@internal@log:info( <<<>/binary, (telega@update:to_string(erlang:element(3, Ctx)))/binary>> ), Start_time = gleam@time@timestamp:system_time(), Result = begin _pipe = Handler(), gleam@result:map_error( _pipe, fun(E) -> telega@internal@log:error( <<<>/binary, (gleam@string:inspect(E))/binary>> ), E end ) end, End_time = gleam@time@timestamp:system_time(), Time = begin _pipe@1 = Start_time, _pipe@2 = gleam@time@timestamp:difference(_pipe@1, End_time), _pipe@3 = gleam@time@duration:to_seconds(_pipe@2), gleam_stdlib:float_to_string(_pipe@3) end, telega@internal@log:info( <<<<<>/binary, Time/binary>>/binary, " seconds"/utf8>> ), Result. -file("src/telega.gleam", 461). ?DOC(" Construct a session settings.\n"). -spec with_session_settings( telega_builder(AORA, AORB), fun((binary(), AORA) -> {ok, AORA} | {error, AORB}), fun((binary()) -> {ok, gleam@option:option(AORA)} | {error, AORB}), fun(() -> AORA) ) -> telega_builder(AORA, AORB). with_session_settings(Builder, Persist_session, Get_session, Default_session) -> _record = Builder, {telega_builder, erlang:element(2, _record), erlang:element(3, _record), {some, {session_settings, Persist_session, Get_session, Default_session}}, erlang:element(5, _record), erlang:element(6, _record), erlang:element(7, _record), erlang:element(8, _record), erlang:element(9, _record), erlang:element(10, _record), erlang:element(11, _record)}. -file("src/telega.gleam", 496). ?DOC(" Set the drop pending updates flag as set webhook parameter.\n"). -spec set_drop_pending_updates(telega_builder(ANXD, ANXE), boolean()) -> telega_builder(ANXD, ANXE). set_drop_pending_updates(Builder, Drop_pending_updates) -> _record = Builder, {telega_builder, erlang:element(2, _record), erlang:element(3, _record), erlang:element(4, _record), erlang:element(5, _record), erlang:element(6, _record), {some, Drop_pending_updates}, erlang:element(8, _record), erlang:element(9, _record), erlang:element(10, _record), erlang:element(11, _record)}. -file("src/telega.gleam", 504). ?DOC(" Set the max connections as set webhook parameter.\n"). -spec set_max_connections(telega_builder(ANXI, ANXJ), integer()) -> telega_builder(ANXI, ANXJ). set_max_connections(Builder, Max_connections) -> _record = Builder, {telega_builder, erlang:element(2, _record), erlang:element(3, _record), erlang:element(4, _record), erlang:element(5, _record), erlang:element(6, _record), erlang:element(7, _record), {some, Max_connections}, erlang:element(9, _record), erlang:element(10, _record), erlang:element(11, _record)}. -file("src/telega.gleam", 512). ?DOC(" Set the ip address as set webhook parameter.\n"). -spec set_ip_address(telega_builder(ANXN, ANXO), binary()) -> telega_builder(ANXN, ANXO). set_ip_address(Builder, Ip_address) -> _record = Builder, {telega_builder, erlang:element(2, _record), erlang:element(3, _record), erlang:element(4, _record), erlang:element(5, _record), erlang:element(6, _record), erlang:element(7, _record), erlang:element(8, _record), {some, Ip_address}, erlang:element(10, _record), erlang:element(11, _record)}. -file("src/telega.gleam", 520). ?DOC(" Set the allowed updates as set webhook parameter.\n"). -spec set_allowed_updates(telega_builder(ANXS, ANXT), list(binary())) -> telega_builder(ANXS, ANXT). set_allowed_updates(Builder, Allowed_updates) -> _record = Builder, {telega_builder, erlang:element(2, _record), erlang:element(3, _record), erlang:element(4, _record), erlang:element(5, _record), erlang:element(6, _record), erlang:element(7, _record), erlang:element(8, _record), erlang:element(9, _record), {some, Allowed_updates}, erlang:element(11, _record)}. -file("src/telega.gleam", 528). ?DOC(" Set the certificate as set webhook parameter.\n"). -spec set_certificate(telega_builder(ANXY, ANXZ), telega@model:file()) -> telega_builder(ANXY, ANXZ). set_certificate(Builder, Certificate) -> _record = Builder, {telega_builder, erlang:element(2, _record), erlang:element(3, _record), erlang:element(4, _record), erlang:element(5, _record), erlang:element(6, _record), erlang:element(7, _record), erlang:element(8, _record), erlang:element(9, _record), erlang:element(10, _record), {some, Certificate}}. -file("src/telega.gleam", 576). -spec nil_catch_handler(any(), any()) -> {ok, nil} | {error, any()}. nil_catch_handler(_, _) -> {ok, nil}. -file("src/telega.gleam", 538). ?DOC( " Initialize a Telega instance.\n" " This function should be called **only** after all handlers are added to the builder.\n" " It will set the webhook and start handling messages.\n" ). -spec init(telega_builder(any(), any())) -> {ok, telega(any(), any())} | {error, telega@error:telega_error()}. init(Builder) -> gleam@result:'try'( telega@api:set_webhook( erlang:element(5, erlang:element(2, Builder)), {set_webhook_parameters, <<<<(erlang:element(2, erlang:element(2, Builder)))/binary, "/"/utf8>>/binary, (erlang:element(3, erlang:element(2, Builder)))/binary>>, erlang:element(11, Builder), erlang:element(8, Builder), erlang:element(9, Builder), erlang:element(10, Builder), erlang:element(7, Builder), {some, erlang:element(4, erlang:element(2, Builder))}} ), fun(Is_ok) -> gleam@bool:guard( not Is_ok, {error, set_webhook_error}, fun() -> gleam@result:'try'( telega@api:get_me( erlang:element(5, erlang:element(2, Builder)) ), fun(Bot_info) -> Session_settings = gleam@option:to_result( erlang:element(4, Builder), no_session_settings_error ), gleam@result:'try'( Session_settings, fun(Session_settings@1) -> gleam@result:'try'( telega@internal@registry:start(), fun(Registry_subject) -> Catch_handler = gleam@option:lazy_unwrap( erlang:element(6, Builder), fun() -> fun nil_catch_handler/2 end ), gleam@result:'try'( telega@bot:start( Registry_subject, erlang:element(2, Builder), Bot_info, erlang:element(3, Builder), Session_settings@1, Catch_handler ), fun(Bot_subject) -> {ok, {telega, erlang:element( 2, Builder ), Bot_info, Bot_subject}} end ) end ) end ) end ) end ) end ). -file("src/telega.gleam", 479). ?DOC( " Initialize a Telega instance with a `Nil` session.\n" " Useful when you don't need to persist the session.\n" ). -spec init_nil_session(telega_builder(nil, any())) -> {ok, telega(any(), any())} | {error, telega@error:telega_error()}. init_nil_session(Builder) -> Persist_session = fun(_, _) -> {ok, nil} end, Get_session = fun(_) -> {ok, {some, nil}} end, Default_session = fun() -> nil end, _pipe = begin _record = Builder, {telega_builder, erlang:element(2, _record), erlang:element(3, _record), {some, {session_settings, Persist_session, Get_session, Default_session}}, erlang:element(5, _record), erlang:element(6, _record), erlang:element(7, _record), erlang:element(8, _record), erlang:element(9, _record), erlang:element(10, _record), erlang:element(11, _record)} end, init(_pipe). -file("src/telega.gleam", 581). ?DOC(" Handle an update from the Telegram API.\n"). -spec handle_update(telega(any(), any()), telega@model:update()) -> {ok, boolean()} | {error, telega@error:telega_error()}. handle_update(Telega, Raw_update) -> _pipe = telega@update:raw_to_update(Raw_update), telega@bot:handle_update(erlang:element(4, Telega), _pipe).