-module(telega). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/telega.gleam"). -export([get_bot_subject_internal/1, get_client_internal/1, is_webhook_path/2, is_secret_token_valid/2, get_api_config/1, new/4, new_for_polling/1, with_router/2, with_session_settings/2, with_catch_handler/2, set_drop_pending_updates/2, set_max_connections/2, set_ip_address/2, set_allowed_updates/2, set_certificate/2, set_api_client/2, with_nil_session/1, init/1, init_for_polling/1, init_for_polling_nil_session/1, handle_update/2, get_me/1, get_session/1, log_context/3, log_info/2, log_error/2, wait_any/4, wait_command/5, wait_commands/5, wait_text/4, wait_hears/5, wait_message/4, wait_callback_query/5, wait_audio/4, wait_video/4, wait_voice/4, wait_photos/4, wait_number/6, wait_email/4, wait_for/5, wait_choice/5]). -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(AQCP, AQCQ) :: {telega, telega@internal@config:config(), telega@model@types:user(), gleam@erlang@process:subject(telega@bot:bot_message())} | {gleam_phantom, AQCP, AQCQ}. -opaque telega_builder(AQCR, AQCS) :: {telega_builder, telega@internal@config:config(), gleam@option:option(telega@router:router(AQCR, AQCS)), gleam@option:option(telega@bot:session_settings(AQCR, AQCS)), gleam@option:option(fun((telega@bot:context(AQCR, AQCS), AQCS) -> {ok, nil} | {error, AQCS})), gleam@option:option(gleam@erlang@process:subject(telega@bot:bot_message())), gleam@option:option(telega@client:telegram_client()), gleam@option:option(boolean()), gleam@option:option(integer()), gleam@option:option(binary()), gleam@option:option(list(binary())), gleam@option:option(telega@model@types:file())}. -file("src/telega.gleam", 44). ?DOC(false). -spec get_bot_subject_internal(telega(any(), any())) -> gleam@erlang@process:subject(telega@bot:bot_message()). get_bot_subject_internal(Telega) -> erlang:element(4, Telega). -file("src/telega.gleam", 50). ?DOC(false). -spec get_client_internal(telega(any(), any())) -> telega@client:telegram_client(). get_client_internal(Telega) -> erlang:element(5, erlang:element(2, Telega)). -file("src/telega.gleam", 59). ?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", 66). ?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", 71). ?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", 76). ?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, none, none}. -file("src/telega.gleam", 103). ?DOC( " Create a new Telega instance optimized for long polling.\n" "\n" " This is a convenience function for polling bots that don't need webhook configuration.\n" ). -spec new_for_polling(binary()) -> telega_builder(any(), any()). new_for_polling(Token) -> {telega_builder, telega@internal@config:new( Token, <<"https://api.telegram.org"/utf8>>, <<"/webhook"/utf8>>, none ), none, none, none, none, none, none, none, none, none, none}. -file("src/telega.gleam", 127). ?DOC( " Set the router for handling updates.\n" " This is the primary way to handle updates - use router.new() to create a router\n" " and configure it with command handlers, text handlers, middleware, etc.\n" ). -spec with_router(telega_builder(AQDT, AQDU), telega@router:router(AQDT, AQDU)) -> telega_builder(AQDT, AQDU). with_router(Builder, Router) -> {telega_builder, erlang:element(2, Builder), {some, Router}, erlang:element(4, Builder), erlang:element(5, Builder), erlang:element(6, Builder), erlang:element(7, Builder), erlang:element(8, Builder), erlang:element(9, Builder), erlang:element(10, Builder), erlang:element(11, Builder), erlang:element(12, Builder)}. -file("src/telega.gleam", 135). ?DOC(" Set session settings for the bot.\n"). -spec with_session_settings( telega_builder(AQEB, AQEC), telega@bot:session_settings(AQEB, AQEC) ) -> telega_builder(AQEB, AQEC). with_session_settings(Builder, Session_settings) -> {telega_builder, erlang:element(2, Builder), erlang:element(3, Builder), {some, Session_settings}, erlang:element(5, Builder), erlang:element(6, Builder), erlang:element(7, Builder), erlang:element(8, Builder), erlang:element(9, Builder), erlang:element(10, Builder), erlang:element(11, Builder), erlang:element(12, Builder)}. -file("src/telega.gleam", 144). ?DOC( " Set catch handler for system errors (like session persistence failures) and [conversation](/docs/conversation) errors.\n" " This is different from router's catch handler which handles route errors.\n" ). -spec with_catch_handler( telega_builder(AQEJ, AQEK), fun((telega@bot:context(AQEJ, AQEK), AQEK) -> {ok, nil} | {error, AQEK}) ) -> telega_builder(AQEJ, AQEK). with_catch_handler(Builder, Catch_handler) -> {telega_builder, erlang:element(2, Builder), erlang:element(3, Builder), erlang:element(4, Builder), {some, Catch_handler}, erlang:element(6, Builder), erlang:element(7, Builder), erlang:element(8, Builder), erlang:element(9, Builder), erlang:element(10, Builder), erlang:element(11, Builder), erlang:element(12, Builder)}. -file("src/telega.gleam", 152). ?DOC(" Set whether to drop pending updates.\n"). -spec set_drop_pending_updates(telega_builder(AQER, AQES), boolean()) -> telega_builder(AQER, AQES). set_drop_pending_updates(Builder, Drop) -> {telega_builder, erlang:element(2, Builder), erlang:element(3, Builder), erlang:element(4, Builder), erlang:element(5, Builder), erlang:element(6, Builder), erlang:element(7, Builder), {some, Drop}, erlang:element(9, Builder), erlang:element(10, Builder), erlang:element(11, Builder), erlang:element(12, Builder)}. -file("src/telega.gleam", 160). ?DOC(" Set max connections for webhook.\n"). -spec set_max_connections(telega_builder(AQEX, AQEY), integer()) -> telega_builder(AQEX, AQEY). set_max_connections(Builder, Max) -> {telega_builder, erlang:element(2, Builder), erlang:element(3, Builder), erlang:element(4, Builder), erlang:element(5, Builder), erlang:element(6, Builder), erlang:element(7, Builder), erlang:element(8, Builder), {some, Max}, erlang:element(10, Builder), erlang:element(11, Builder), erlang:element(12, Builder)}. -file("src/telega.gleam", 168). ?DOC(" Set IP address for webhook.\n"). -spec set_ip_address(telega_builder(AQFD, AQFE), binary()) -> telega_builder(AQFD, AQFE). set_ip_address(Builder, Ip) -> {telega_builder, erlang:element(2, Builder), erlang:element(3, Builder), erlang:element(4, Builder), erlang:element(5, Builder), erlang:element(6, Builder), erlang:element(7, Builder), erlang:element(8, Builder), erlang:element(9, Builder), {some, Ip}, erlang:element(11, Builder), erlang:element(12, Builder)}. -file("src/telega.gleam", 176). ?DOC(" Set allowed updates for webhook.\n"). -spec set_allowed_updates(telega_builder(AQFJ, AQFK), list(binary())) -> telega_builder(AQFJ, AQFK). set_allowed_updates(Builder, Updates) -> {telega_builder, erlang:element(2, Builder), erlang:element(3, Builder), erlang:element(4, Builder), erlang:element(5, Builder), erlang:element(6, Builder), erlang:element(7, Builder), erlang:element(8, Builder), erlang:element(9, Builder), erlang:element(10, Builder), {some, Updates}, erlang:element(12, Builder)}. -file("src/telega.gleam", 184). ?DOC(" Set certificate for webhook.\n"). -spec set_certificate(telega_builder(AQFQ, AQFR), telega@model@types:file()) -> telega_builder(AQFQ, AQFR). set_certificate(Builder, Cert) -> {telega_builder, erlang:element(2, Builder), erlang:element(3, Builder), erlang:element(4, Builder), erlang:element(5, Builder), erlang:element(6, Builder), erlang:element(7, Builder), erlang:element(8, Builder), erlang:element(9, Builder), erlang:element(10, Builder), erlang:element(11, Builder), {some, Cert}}. -file("src/telega.gleam", 192). ?DOC(" Set a custom API client.\n"). -spec set_api_client( telega_builder(AQFW, AQFX), telega@client:telegram_client() ) -> telega_builder(AQFW, AQFX). set_api_client(Builder, Client) -> {telega_builder, erlang:element(2, Builder), erlang:element(3, Builder), erlang:element(4, Builder), erlang:element(5, Builder), erlang:element(6, Builder), {some, Client}, erlang:element(8, Builder), erlang:element(9, Builder), erlang:element(10, Builder), erlang:element(11, Builder), erlang:element(12, Builder)}. -file("src/telega.gleam", 200). ?DOC(" Set nil session for the bot.\n"). -spec with_nil_session(telega_builder(nil, AQGC)) -> telega_builder(nil, AQGC). with_nil_session(Builder) -> _pipe = Builder, with_session_settings( _pipe, {session_settings, fun(_, _) -> {ok, nil} end, fun(_) -> {ok, none} end, fun() -> nil end} ). -file("src/telega.gleam", 229). ?DOC(" Initialize the bot.\n"). -spec init(telega_builder(AQGO, AQGP)) -> {ok, telega(AQGO, AQGP)} | {error, telega@error:telega_error()}. init(Builder) -> Api_client = gleam@option:unwrap( erlang:element(7, Builder), erlang:element(5, erlang:element(2, Builder)) ), gleam@result:'try'( telega@api:set_webhook( Api_client, {set_webhook_parameters, <<<<(erlang:element(2, erlang:element(2, Builder)))/binary, "/"/utf8>>/binary, (erlang:element(3, erlang:element(2, Builder)))/binary>>, erlang:element(12, Builder), erlang:element(9, Builder), erlang:element(10, Builder), erlang:element(11, Builder), erlang:element(8, 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(Api_client), 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) -> Router = gleam@option:to_result( erlang:element(3, Builder), {router_error, <<"Router is required. Use with_router() to set a router."/utf8>>} ), gleam@result:'try'( Router, fun(Router@1) -> Router_handler = fun( Ctx, Update ) -> telega@router:handle( Router@1, Ctx, Update ) end, Catch_handler = gleam@option:unwrap( erlang:element( 5, Builder ), fun(_, Err) -> {error, Err} end ), Config = begin _record = erlang:element( 2, Builder ), {config, erlang:element( 2, _record ), erlang:element( 3, _record ), erlang:element( 4, _record ), Api_client} end, gleam@result:'try'( telega@bot:start( Registry, Config, Bot_info, Router_handler, Session_settings@1, Catch_handler ), fun(Bot_subject) -> {ok, {telega, Config, Bot_info, Bot_subject}} end ) end ) end ) end ) end ) end ) end ). -file("src/telega.gleam", 288). ?DOC(" Initialize the bot for long polling (doesn't set webhook).\n"). -spec init_for_polling(telega_builder(AQGW, AQGX)) -> {ok, telega(AQGW, AQGX)} | {error, telega@error:telega_error()}. init_for_polling(Builder) -> Api_client = gleam@option:unwrap( erlang:element(7, Builder), erlang:element(5, erlang:element(2, Builder)) ), gleam@result:'try'( begin _pipe = telega@api:get_me(Api_client), gleam@result:map_error(_pipe, fun(Err) -> case Err of {telegram_api_error, 404, _} -> {telegram_api_error, 404, <<"Bot not found. Please check that your BOT_TOKEN is valid and the bot exists. Get a valid token from @BotFather on Telegram."/utf8>>}; {telegram_api_error, 401, _} -> {telegram_api_error, 401, <<"Unauthorized. Your bot token is invalid. Please get a valid token from @BotFather on Telegram."/utf8>>}; _ -> Err end end) end, 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) -> Router = gleam@option:to_result( erlang:element(3, Builder), {actor_error, <<"Router is required. Use with_router() to set a router."/utf8>>} ), gleam@result:'try'( Router, fun(Router@1) -> Router_handler = fun(Ctx, Update) -> telega@router:handle( Router@1, Ctx, Update ) end, Catch_handler = gleam@option:unwrap( erlang:element(5, Builder), fun(_, Err@1) -> {error, Err@1} end ), Config = begin _record = erlang:element(2, Builder), {config, erlang:element(2, _record), erlang:element(3, _record), erlang:element(4, _record), Api_client} end, gleam@result:'try'( telega@bot:start( Registry, Config, Bot_info, Router_handler, Session_settings@1, Catch_handler ), fun(Bot_subject) -> {ok, {telega, Config, Bot_info, Bot_subject}} end ) end ) end ) end ) end ). -file("src/telega.gleam", 214). ?DOC(" Initialize the bot for long polling with nil session.\n"). -spec init_for_polling_nil_session(telega_builder(nil, AQGH)) -> {ok, telega(nil, AQGH)} | {error, telega@error:telega_error()}. init_for_polling_nil_session(Builder) -> _pipe = Builder, _pipe@1 = with_session_settings( _pipe, {session_settings, fun(_, _) -> {ok, nil} end, fun(_) -> {ok, none} end, fun() -> nil end} ), init_for_polling(_pipe@1). -file("src/telega.gleam", 349). ?DOC( " Handle an update.\n" "\n" " This function is useful when you want to handle updates in your own way.\n" ). -spec handle_update(telega(any(), any()), telega@model@types:update()) -> boolean(). handle_update(Telega, Raw_update) -> Update = telega@update:raw_to_update(Raw_update), telega@bot:handle_update(erlang:element(4, Telega), Update). -file("src/telega.gleam", 355). ?DOC(" Get the bot's information.\n"). -spec get_me(telega(any(), any())) -> telega@model@types:user(). get_me(Telega) -> erlang:element(3, Telega). -file("src/telega.gleam", 360). ?DOC(" Get session for the current context.\n"). -spec get_session(telega@bot:context(AQHM, any())) -> AQHM. get_session(Ctx) -> erlang:element(5, Ctx). -file("src/telega.gleam", 365). ?DOC(" Add logging context to the current context.\n"). -spec log_context( telega@bot:context(AQHQ, AQHR), binary(), fun((telega@bot:context(AQHQ, AQHR)) -> {ok, telega@bot:context(AQHQ, AQHR)} | {error, AQHR}) ) -> {ok, telega@bot:context(AQHQ, AQHR)} | {error, AQHR}. log_context(Ctx, Prefix, Fun) -> Ctx_with_log = {context, erlang:element(2, Ctx), erlang:element(3, Ctx), erlang:element(4, Ctx), erlang:element(5, Ctx), erlang:element(6, Ctx), erlang:element(7, Ctx), {some, Prefix}}, Fun(Ctx_with_log). -file("src/telega.gleam", 375). ?DOC(" Context helpers for logging\n"). -spec log_info(telega@bot:context(any(), any()), binary()) -> nil. log_info(Ctx, Message) -> case erlang:element(8, Ctx) of {some, Prefix} -> telega@internal@log:info_d(Prefix, Message); none -> telega@internal@log:info(Message) end. -file("src/telega.gleam", 382). -spec log_error(telega@bot:context(any(), any()), binary()) -> nil. log_error(Ctx, Message) -> case erlang:element(8, Ctx) of {some, Prefix} -> telega@internal@log:error_d(Prefix, Message); none -> telega@internal@log:error(Message) end. -file("src/telega.gleam", 392). ?DOC( " Stops bot message handling from current chat and waits for any update.\n" "\n" " See [conversation](/docs/conversation)\n" ). -spec wait_any( telega@bot:context(AQIO, AQIP), gleam@option:option(telega@bot:handler(AQIO, AQIP)), gleam@option:option(integer()), fun((telega@bot:context(AQIO, AQIP), telega@update:update()) -> {ok, telega@bot:context(AQIO, AQIP)} | {error, AQIP}) ) -> {ok, telega@bot:context(AQIO, AQIP)} | {error, AQIP}. wait_any(Ctx, Handle_else, Timeout, Handler) -> telega@bot:wait_handler(Ctx, {handle_all, Handler}, Handle_else, Timeout). -file("src/telega.gleam", 410). ?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(AQJG, AQJH), binary(), gleam@option:option(telega@bot:handler(AQJG, AQJH)), gleam@option:option(integer()), fun((telega@bot:context(AQJG, AQJH), telega@update:command()) -> {ok, telega@bot:context(AQJG, AQJH)} | {error, AQJH}) ) -> {ok, telega@bot:context(AQJG, AQJH)} | {error, AQJH}. wait_command(Ctx, Command, Handle_else, Timeout, Continue) -> telega@bot:wait_handler( Ctx, {handle_command, Command, Continue}, Handle_else, Timeout ). -file("src/telega.gleam", 429). ?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(AQJY, AQJZ), list(binary()), gleam@option:option(telega@bot:handler(AQJY, AQJZ)), gleam@option:option(integer()), fun((telega@bot:context(AQJY, AQJZ), telega@update:command()) -> {ok, telega@bot:context(AQJY, AQJZ)} | {error, AQJZ}) ) -> {ok, telega@bot:context(AQJY, AQJZ)} | {error, AQJZ}. wait_commands(Ctx, Commands, Handle_else, Timeout, Continue) -> telega@bot:wait_handler( Ctx, {handle_commands, Commands, Continue}, Handle_else, Timeout ). -file("src/telega.gleam", 448). ?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(AQKR, AQKS), gleam@option:option(telega@bot:handler(AQKR, AQKS)), gleam@option:option(integer()), fun((telega@bot:context(AQKR, AQKS), binary()) -> {ok, telega@bot:context(AQKR, AQKS)} | {error, AQKS}) ) -> {ok, telega@bot:context(AQKR, AQKS)} | {error, AQKS}. wait_text(Ctx, Handle_else, Timeout, Continue) -> telega@bot:wait_handler(Ctx, {handle_text, Continue}, Handle_else, Timeout). -file("src/telega.gleam", 466). ?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(AQLJ, AQLK), telega@bot:hears(), gleam@option:option(telega@bot:handler(AQLJ, AQLK)), gleam@option:option(integer()), fun((telega@bot:context(AQLJ, AQLK), binary()) -> {ok, telega@bot:context(AQLJ, AQLK)} | {error, AQLK}) ) -> {ok, telega@bot:context(AQLJ, AQLK)} | {error, AQLK}. wait_hears(Ctx, Hears, Handle_else, Timeout, Continue) -> telega@bot:wait_handler( Ctx, {handle_hears, Hears, Continue}, Handle_else, Timeout ). -file("src/telega.gleam", 485). ?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(AQMB, AQMC), gleam@option:option(telega@bot:handler(AQMB, AQMC)), gleam@option:option(integer()), fun((telega@bot:context(AQMB, AQMC), telega@model@types:message()) -> {ok, telega@bot:context(AQMB, AQMC)} | {error, AQMC}) ) -> {ok, telega@bot:context(AQMB, AQMC)} | {error, AQMC}. wait_message(Ctx, Handle_else, Timeout, Continue) -> telega@bot:wait_handler( Ctx, {handle_message, Continue}, Handle_else, Timeout ). -file("src/telega.gleam", 503). ?DOC( " Stops bot message handling from current chat and waits for a callback query.\n" "\n" " See [conversation](/docs/conversation)\n" ). -spec wait_callback_query( telega@bot:context(AQMT, AQMU), gleam@option:option(telega@bot:callback_query_filter()), gleam@option:option(telega@bot:handler(AQMT, AQMU)), gleam@option:option(integer()), fun((telega@bot:context(AQMT, AQMU), binary(), binary()) -> {ok, telega@bot:context(AQMT, AQMU)} | {error, AQMU}) ) -> {ok, telega@bot:context(AQMT, AQMU)} | {error, AQMU}. wait_callback_query(Ctx, Filter, Handle_else, Timeout, Continue) -> Default_re@1 = case gleam@regexp:from_string(<<".*"/utf8>>) of {ok, Default_re} -> Default_re; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"telega"/utf8>>, function => <<"wait_callback_query"/utf8>>, line => 511, value => _assert_fail, start => 15208, 'end' => 15260, pattern_start => 15219, pattern_end => 15233}) end, Filter_value = gleam@option:unwrap( Filter, {callback_query_filter, Default_re@1} ), telega@bot:wait_handler( Ctx, {handle_callback_query, Filter_value, Continue}, Handle_else, Timeout ). -file("src/telega.gleam", 525). ?DOC( " Stops bot message handling from current chat and waits for an audio.\n" "\n" " See [conversation](/docs/conversation)\n" ). -spec wait_audio( telega@bot:context(AQNM, AQNN), gleam@option:option(telega@bot:handler(AQNM, AQNN)), gleam@option:option(integer()), fun((telega@bot:context(AQNM, AQNN), telega@model@types:audio()) -> {ok, telega@bot:context(AQNM, AQNN)} | {error, AQNN}) ) -> {ok, telega@bot:context(AQNM, AQNN)} | {error, AQNN}. wait_audio(Ctx, Handle_else, Timeout, Continue) -> telega@bot:wait_handler(Ctx, {handle_audio, Continue}, Handle_else, Timeout). -file("src/telega.gleam", 543). ?DOC( " Stops bot message handling from current chat and waits for a video.\n" "\n" " See [conversation](/docs/conversation)\n" ). -spec wait_video( telega@bot:context(AQOE, AQOF), gleam@option:option(telega@bot:handler(AQOE, AQOF)), gleam@option:option(integer()), fun((telega@bot:context(AQOE, AQOF), telega@model@types:video()) -> {ok, telega@bot:context(AQOE, AQOF)} | {error, AQOF}) ) -> {ok, telega@bot:context(AQOE, AQOF)} | {error, AQOF}. wait_video(Ctx, Handle_else, Timeout, Continue) -> telega@bot:wait_handler(Ctx, {handle_video, Continue}, Handle_else, Timeout). -file("src/telega.gleam", 561). ?DOC( " Stops bot message handling from current chat and waits for a voice.\n" "\n" " See [conversation](/docs/conversation)\n" ). -spec wait_voice( telega@bot:context(AQOW, AQOX), gleam@option:option(telega@bot:handler(AQOW, AQOX)), gleam@option:option(integer()), fun((telega@bot:context(AQOW, AQOX), telega@model@types:voice()) -> {ok, telega@bot:context(AQOW, AQOX)} | {error, AQOX}) ) -> {ok, telega@bot:context(AQOW, AQOX)} | {error, AQOX}. wait_voice(Ctx, Handle_else, Timeout, Continue) -> telega@bot:wait_handler(Ctx, {handle_voice, Continue}, Handle_else, Timeout). -file("src/telega.gleam", 579). ?DOC( " Stops bot message handling from current chat and waits for photos.\n" "\n" " See [conversation](/docs/conversation)\n" ). -spec wait_photos( telega@bot:context(AQPO, AQPP), gleam@option:option(telega@bot:handler(AQPO, AQPP)), gleam@option:option(integer()), fun((telega@bot:context(AQPO, AQPP), list(telega@model@types:photo_size())) -> {ok, telega@bot:context(AQPO, AQPP)} | {error, AQPP}) ) -> {ok, telega@bot:context(AQPO, AQPP)} | {error, AQPP}. wait_photos(Ctx, Handle_else, Timeout, Continue) -> telega@bot:wait_handler( Ctx, {handle_photos, Continue}, Handle_else, Timeout ). -file("src/telega.gleam", 617). ?DOC( " Wait for a number with validation.\n" "\n" " This function waits for user to send text that can be parsed as an integer,\n" " with optional min/max validation.\n" "\n" " If validation fails and `or` handler is provided, it will be called.\n" " Otherwise, the function will keep waiting for valid input.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " use ctx, age <- wait_number(\n" " ctx,\n" " min: Some(0),\n" " max: Some(120),\n" " or: Some(bot.HandleText(fn(ctx, invalid) {\n" " reply.with_text(ctx, \"Please enter age between 0 and 120\")\n" " })),\n" " timeout: None,\n" " )\n" " ```\n" "\n" " See [conversation](/docs/conversation)\n" ). -spec wait_number( telega@bot:context(AQQH, AQQI), gleam@option:option(integer()), gleam@option:option(integer()), gleam@option:option(telega@bot:handler(AQQH, AQQI)), gleam@option:option(integer()), fun((telega@bot:context(AQQH, AQQI), integer()) -> {ok, telega@bot:context(AQQH, AQQI)} | {error, AQQI}) ) -> {ok, telega@bot:context(AQQH, AQQI)} | {error, AQQI}. wait_number(Ctx, Min, Max, Handle_else, Timeout, Continue) -> Validation_handler = {handle_text, fun(Ctx@1, Text) -> case gleam_stdlib:parse_int(Text) of {ok, Number} -> Min_ok = case Min of {some, Min_val} -> Number >= Min_val; none -> true end, Max_ok = case Max of {some, Max_val} -> Number =< Max_val; none -> true end, case Min_ok andalso Max_ok of true -> Continue(Ctx@1, Number); false -> wait_number( Ctx@1, Min, Max, Handle_else, Timeout, Continue ) end; {error, _} -> wait_number(Ctx@1, Min, Max, Handle_else, Timeout, Continue) end end}, telega@bot:wait_handler(Ctx, Validation_handler, Handle_else, Timeout). -file("src/telega.gleam", 676). ?DOC( " Wait for email with validation.\n" "\n" " This function waits for user to send text that matches email pattern.\n" "\n" " If validation fails and `or` handler is provided, it will be called.\n" " Otherwise, the function will keep waiting for valid input.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " use ctx, email <- wait_email(\n" " ctx,\n" " or: Some(bot.HandleText(fn(ctx, invalid) {\n" " reply.with_text(ctx, \"Invalid email format. Try again.\")\n" " })),\n" " timeout: None,\n" " )\n" " ```\n" "\n" " See [conversation](/docs/conversation)\n" ). -spec wait_email( telega@bot:context(AQRB, AQRC), gleam@option:option(telega@bot:handler(AQRB, AQRC)), gleam@option:option(integer()), fun((telega@bot:context(AQRB, AQRC), binary()) -> {ok, telega@bot:context(AQRB, AQRC)} | {error, AQRC}) ) -> {ok, telega@bot:context(AQRB, AQRC)} | {error, AQRC}. wait_email(Ctx, Handle_else, Timeout, Continue) -> Email_pattern = <<"^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$"/utf8>>, Validation_handler = {handle_text, fun(Ctx@1, Text) -> case gleam@regexp:from_string(Email_pattern) of {ok, Re} -> case gleam@regexp:check(Re, Text) of true -> Continue(Ctx@1, Text); false -> wait_email(Ctx@1, Handle_else, Timeout, Continue) end; {error, _} -> Continue(Ctx@1, Text) end end}, telega@bot:wait_handler(Ctx, Validation_handler, Handle_else, Timeout). -file("src/telega.gleam", 817). ?DOC( " Wait for update matching custom filter.\n" "\n" " This function waits for any update that passes the provided filter function.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " use ctx, photo_update <- wait_for(\n" " ctx,\n" " filter: fn(upd) {\n" " case upd {\n" " update.PhotoUpdate(..) -> True\n" " _ -> False\n" " }\n" " },\n" " or: Some(bot.HandleAll(fn(ctx, wrong_update) {\n" " reply.with_text(ctx, \"Please send a photo\")\n" " })),\n" " timeout: Some(60_000),\n" " )\n" " ```\n" "\n" " See [conversation](/docs/conversation)\n" ). -spec wait_for( telega@bot:context(AQSN, AQSO), fun((telega@update:update()) -> boolean()), gleam@option:option(telega@bot:handler(AQSN, AQSO)), gleam@option:option(integer()), fun((telega@bot:context(AQSN, AQSO), telega@update:update()) -> {ok, telega@bot:context(AQSN, AQSO)} | {error, AQSO}) ) -> {ok, telega@bot:context(AQSN, AQSO)} | {error, AQSO}. wait_for(Ctx, Filter, Handle_else, Timeout, Continue) -> Filter_handler = {handle_all, fun(Ctx@1, Upd) -> case Filter(Upd) of true -> Continue(Ctx@1, Upd); false -> wait_for(Ctx@1, Filter, Handle_else, Timeout, Continue) end end}, telega@bot:wait_handler(Ctx, Filter_handler, Handle_else, Timeout). -file("src/telega.gleam", 837). -spec list_at(list(AQTF), integer()) -> {ok, AQTF} | {error, nil}. list_at(List, Index) -> case {List, Index} of {[], _} -> {error, nil}; {[Head | _], 0} -> {ok, Head}; {[_ | Tail], N} -> list_at(Tail, N - 1) end. -file("src/telega.gleam", 721). ?DOC( " Wait for user choice from inline keyboard.\n" "\n" " This function creates an inline keyboard with provided options\n" " and waits for user to select one.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " use ctx, color <- wait_choice(\n" " ctx,\n" " [\n" " #(\"🔴 Red\", Red),\n" " #(\"🔵 Blue\", Blue),\n" " #(\"🟢 Green\", Green),\n" " ],\n" " or: None,\n" " timeout: None,\n" " )\n" " ```\n" "\n" " See [conversation](/docs/conversation)\n" ). -spec wait_choice( telega@bot:context(AQRT, AQRU), list({binary(), AQRX}), gleam@option:option(telega@bot:handler(AQRT, AQRU)), gleam@option:option(integer()), fun((telega@bot:context(AQRT, AQRU), AQRX) -> {ok, telega@bot:context(AQRT, AQRU)} | {error, AQRU}) ) -> {ok, telega@bot:context(AQRT, AQRU)} | {error, AQRU}. wait_choice(Ctx, Options, Handle_else, Timeout, Continue) -> Buttons = begin _pipe = Options, gleam@list:index_map( _pipe, fun(Opt, Idx) -> {Label, _} = Opt, Callback_data = erlang:integer_to_binary(Idx), {inline_keyboard_button, Label, none, {some, Callback_data}, none, none, none, none, none, none, none, none} end ) end, Keyboard = {inline_keyboard_markup, [Buttons]}, Send_params = {send_message_parameters, none, {int, erlang:element(3, erlang:element(3, Ctx))}, none, <<""/utf8>>, none, none, none, none, none, none, none, none, {some, {send_message_reply_inline_keyboard_markup_parameters, Keyboard}}}, _ = telega@api:send_message( erlang:element(5, erlang:element(4, Ctx)), Send_params ), wait_callback_query( Ctx, none, Handle_else, Timeout, fun(Ctx@1, _, Data) -> case gleam_stdlib:parse_int(Data) of {ok, Idx@1} -> case list_at(Options, Idx@1) of {ok, {_, Value}} -> Continue(Ctx@1, Value); {error, _} -> wait_choice( Ctx@1, Options, Handle_else, Timeout, Continue ) end; {error, _} -> wait_choice(Ctx@1, Options, Handle_else, Timeout, Continue) end end ).