Current section

Files

Jump to
telega src telega@reply.erl
Raw

src/telega@reply.erl

-module(telega@reply).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/telega/reply.gleam").
-export([with_text/2, with_markup/3, with_formatted/2, with_html/2, with_markdown/2, with_markdown_v2/2, with_formatted_markup/3, with_dice/2, edit_text/2, edit_text_formatted/3, forward/2, answer_callback_query/2, with_file_link/2, with_poll/3, with_invoice/6, with_sticker/2, with_media_group/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.
?MODULEDOC(
" `reply` provides a convenient way to send messages to the active chat.\n"
" It uses the `Context` object to access the chat ID and other necessary information.\n"
).
-file("src/telega/reply.gleam", 25).
?DOC(
" Use this method to send text messages.\n"
"\n"
" **Official reference:** https://core.telegram.org/bots/api#sendmessage\n"
).
-spec with_text(telega@bot:context(any(), any()), binary()) -> {ok,
telega@model@types:message()} |
{error, telega@error:telega_error()}.
with_text(Ctx, Text) ->
telega@api:send_message(
erlang:element(5, erlang:element(4, Ctx)),
{send_message_parameters,
none,
{str, erlang:element(2, Ctx)},
none,
Text,
none,
none,
none,
none,
none,
none,
none,
none,
none}
).
-file("src/telega/reply.gleam", 52).
?DOC(
" Use this method to send text messages with keyboard markup.\n"
"\n"
" **Official reference:** https://core.telegram.org/bots/api#sendmessage\n"
).
-spec with_markup(
telega@bot:context(any(), any()),
binary(),
telega@model@types:send_message_reply_markup_parameters()
) -> {ok, telega@model@types:message()} | {error, telega@error:telega_error()}.
with_markup(Ctx, Text, Reply_markup) ->
telega@api:send_message(
erlang:element(5, erlang:element(4, Ctx)),
{send_message_parameters,
none,
{str, erlang:element(2, Ctx)},
none,
Text,
none,
none,
none,
none,
none,
none,
none,
none,
{some, Reply_markup}}
).
-file("src/telega/reply.gleam", 88).
?DOC(
" Use this method to send formatted text messages.\n"
"\n"
" ## Example\n"
" ```gleam\n"
" let formatted = format.build()\n"
" |> format.bold_text(\"Important!\")\n"
" |> format.to_formatted()\n"
" reply.with_formatted(ctx, formatted)\n"
" ```\n"
"\n"
" **Official reference:** https://core.telegram.org/bots/api#sendmessage\n"
).
-spec with_formatted(
telega@bot:context(any(), any()),
telega@format:formatted_text()
) -> {ok, telega@model@types:message()} | {error, telega@error:telega_error()}.
with_formatted(Ctx, Formatted) ->
{Text, Parse_mode} = telega@format:render(Formatted),
telega@api:send_message(
erlang:element(5, erlang:element(4, Ctx)),
{send_message_parameters,
none,
{str, erlang:element(2, Ctx)},
none,
Text,
{some, telega@format:parse_mode_to_string(Parse_mode)},
none,
none,
none,
none,
none,
none,
none,
none}
).
-file("src/telega/reply.gleam", 123).
?DOC(
" Use this method to send HTML formatted text messages.\n"
"\n"
" ## Example\n"
" ```gleam\n"
" let html = format.bold(\"Hello\") <> \" \" <> format.italic(\"World\")\n"
" reply.with_html(ctx, html)\n"
" ```\n"
"\n"
" **Official reference:** https://core.telegram.org/bots/api#sendmessage\n"
).
-spec with_html(telega@bot:context(any(), any()), binary()) -> {ok,
telega@model@types:message()} |
{error, telega@error:telega_error()}.
with_html(Ctx, Html) ->
telega@api:send_message(
erlang:element(5, erlang:element(4, Ctx)),
{send_message_parameters,
none,
{str, erlang:element(2, Ctx)},
none,
Html,
{some, <<"HTML"/utf8>>},
none,
none,
none,
none,
none,
none,
none,
none}
).
-file("src/telega/reply.gleam", 155).
?DOC(
" Use this method to send Markdown formatted text messages.\n"
"\n"
" ## Example\n"
" ```gleam\n"
" reply.with_markdown(ctx, \"*Bold* _Italic_\")\n"
" ```\n"
"\n"
" **Official reference:** https://core.telegram.org/bots/api#sendmessage\n"
).
-spec with_markdown(telega@bot:context(any(), any()), binary()) -> {ok,
telega@model@types:message()} |
{error, telega@error:telega_error()}.
with_markdown(Ctx, Markdown) ->
telega@api:send_message(
erlang:element(5, erlang:element(4, Ctx)),
{send_message_parameters,
none,
{str, erlang:element(2, Ctx)},
none,
Markdown,
{some, <<"Markdown"/utf8>>},
none,
none,
none,
none,
none,
none,
none,
none}
).
-file("src/telega/reply.gleam", 187).
?DOC(
" Use this method to send MarkdownV2 formatted text messages.\n"
"\n"
" ## Example\n"
" ```gleam\n"
" reply.with_markdown_v2(ctx, \"*Bold* _Italic_ __Underline__\")\n"
" ```\n"
"\n"
" **Official reference:** https://core.telegram.org/bots/api#sendmessage\n"
).
-spec with_markdown_v2(telega@bot:context(any(), any()), binary()) -> {ok,
telega@model@types:message()} |
{error, telega@error:telega_error()}.
with_markdown_v2(Ctx, Markdown) ->
telega@api:send_message(
erlang:element(5, erlang:element(4, Ctx)),
{send_message_parameters,
none,
{str, erlang:element(2, Ctx)},
none,
Markdown,
{some, <<"MarkdownV2"/utf8>>},
none,
none,
none,
none,
none,
none,
none,
none}
).
-file("src/telega/reply.gleam", 214).
?DOC(
" Use this method to send formatted text messages with keyboard markup.\n"
"\n"
" **Official reference:** https://core.telegram.org/bots/api#sendmessage\n"
).
-spec with_formatted_markup(
telega@bot:context(any(), any()),
telega@format:formatted_text(),
telega@model@types:send_message_reply_markup_parameters()
) -> {ok, telega@model@types:message()} | {error, telega@error:telega_error()}.
with_formatted_markup(Ctx, Formatted, Reply_markup) ->
{Text, Parse_mode} = telega@format:render(Formatted),
telega@api:send_message(
erlang:element(5, erlang:element(4, Ctx)),
{send_message_parameters,
none,
{str, erlang:element(2, Ctx)},
none,
Text,
{some, telega@format:parse_mode_to_string(Parse_mode)},
none,
none,
none,
none,
none,
none,
none,
{some, Reply_markup}}
).
-file("src/telega/reply.gleam", 244).
?DOC(
" Use this method to send an animated emoji that will display a random value.\n"
"\n"
" **Official reference:** https://core.telegram.org/bots/api#senddice\n"
).
-spec with_dice(
telega@bot:context(any(), any()),
gleam@option:option(telega@model@types:send_dice_parameters())
) -> {ok, telega@model@types:message()} | {error, telega@error:telega_error()}.
with_dice(Ctx, Parameters) ->
Parameters@1 = begin
_pipe = Parameters,
gleam@option:lazy_unwrap(
_pipe,
fun() ->
{send_dice_parameters,
{str, erlang:element(2, Ctx)},
none,
none,
none,
none,
none}
end
)
end,
telega@api:send_dice(
erlang:element(5, erlang:element(4, Ctx)),
Parameters@1
).
-file("src/telega/reply.gleam", 268).
?DOC(
" Use this method to edit text and game messages.\n"
" On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned.\n"
"\n"
" **Official reference:** https://core.telegram.org/bots/api#editmessagetext\n"
).
-spec edit_text(
telega@bot:context(any(), any()),
telega@model@types:edit_message_text_parameters()
) -> {ok, telega@model@types:message()} | {error, telega@error:telega_error()}.
edit_text(Ctx, Parameters) ->
telega@api:edit_message_text(
erlang:element(5, erlang:element(4, Ctx)),
Parameters
).
-file("src/telega/reply.gleam", 278).
?DOC(
" Use this method to edit formatted text messages.\n"
"\n"
" **Official reference:** https://core.telegram.org/bots/api#editmessagetext\n"
).
-spec edit_text_formatted(
telega@bot:context(any(), any()),
integer(),
telega@format:formatted_text()
) -> {ok, telega@model@types:message()} | {error, telega@error:telega_error()}.
edit_text_formatted(Ctx, Message_id, Formatted) ->
{Text, Parse_mode} = telega@format:render(Formatted),
Parameters = {edit_message_text_parameters,
{some, {str, erlang:element(2, Ctx)}},
{some, Message_id},
none,
Text,
{some, telega@format:parse_mode_to_string(Parse_mode)},
none,
none,
none},
telega@api:edit_message_text(
erlang:element(5, erlang:element(4, Ctx)),
Parameters
).
-file("src/telega/reply.gleam", 304).
?DOC(
" Use this method to forward messages of any kind. Service messages and messages with protected content can't be forwarded.\n"
" On success, the sent Message is returned.\n"
"\n"
" **Official reference:** https://core.telegram.org/bots/api#forwardmessage\n"
).
-spec forward(
telega@bot:context(any(), any()),
telega@model@types:forward_message_parameters()
) -> {ok, telega@model@types:message()} | {error, telega@error:telega_error()}.
forward(Ctx, Parameters) ->
telega@api:forward_message(
erlang:element(5, erlang:element(4, Ctx)),
Parameters
).
-file("src/telega/reply.gleam", 316).
?DOC(
" Use this method to send answers to callback queries sent from inline keyboards.\n"
" The answer will be displayed to the user as a notification at the top of the chat screen or as an alert.\n"
" On success, _True_ is returned.\n"
"\n"
" **Official reference:** https://core.telegram.org/bots/api#answercallbackquery\n"
).
-spec answer_callback_query(
telega@bot:context(any(), any()),
telega@model@types:answer_callback_query_parameters()
) -> {ok, boolean()} | {error, telega@error:telega_error()}.
answer_callback_query(Ctx, Parameters) ->
telega@api:answer_callback_query(
erlang:element(5, erlang:element(4, Ctx)),
Parameters
).
-file("src/telega/reply.gleam", 324).
?DOC(" Get download link for the file.\n").
-spec with_file_link(telega@bot:context(any(), any()), binary()) -> {ok,
binary()} |
{error, telega@error:telega_error()}.
with_file_link(Ctx, File_id) ->
gleam@result:'try'(
telega@api:get_file(erlang:element(5, erlang:element(4, Ctx)), File_id),
fun(File) ->
gleam@result:'try'(
gleam@option:to_result(
erlang:element(5, File),
file_not_found_error
),
fun(File_path) ->
{ok,
<<<<<<<<(telega@client:get_api_url(
erlang:element(
5,
erlang:element(4, Ctx)
)
))/binary,
"/file/bot"/utf8>>/binary,
(erlang:element(4, erlang:element(4, Ctx)))/binary>>/binary,
"/"/utf8>>/binary,
File_path/binary>>}
end
)
end
).
-file("src/telega/reply.gleam", 346).
?DOC(
" Use this method to send a native poll.\n"
"\n"
" **Official reference:** https://core.telegram.org/bots/api#sendpoll\n"
).
-spec with_poll(telega@bot:context(any(), any()), binary(), list(binary())) -> {ok,
telega@model@types:message()} |
{error, telega@error:telega_error()}.
with_poll(Ctx, Question, Options) ->
telega@api:send_poll(
erlang:element(5, erlang:element(4, Ctx)),
{send_poll_parameters,
{str, erlang:element(2, Ctx)},
none,
none,
Question,
none,
none,
Options,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none}
).
-file("src/telega/reply.gleam", 395).
?DOC(
" Use this method to send an invoice.\n"
"\n"
" **Official reference:** https://core.telegram.org/bots/api#sendinvoice\n"
).
-spec with_invoice(
telega@bot:context(any(), any()),
binary(),
binary(),
binary(),
binary(),
list({binary(), integer()})
) -> {ok, telega@model@types:message()} | {error, telega@error:telega_error()}.
with_invoice(Ctx, Title, Description, Payload, Currency, Prices) ->
telega@api:send_invoice(
erlang:element(5, erlang:element(4, Ctx)),
{send_invoice_parameters,
{str, erlang:element(2, Ctx)},
none,
Title,
Description,
Payload,
none,
Currency,
gleam@list:map(
Prices,
fun(Price) ->
{Label, Amount} = Price,
{labeled_price, Label, Amount}
end
),
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none,
none}
).
-file("src/telega/reply.gleam", 445).
?DOC(
" Use this method to send a sticker.\n"
"\n"
" **Official reference:** https://core.telegram.org/bots/api#sendsticker\n"
).
-spec with_sticker(
telega@bot:context(any(), any()),
telega@model@types:file_or_string()
) -> {ok, telega@model@types:message()} | {error, telega@error:telega_error()}.
with_sticker(Ctx, Sticker) ->
telega@api:send_sticker(
erlang:element(5, erlang:element(4, Ctx)),
{send_sticker_parameters,
{str, erlang:element(2, Ctx)},
none,
none,
Sticker,
none,
none,
none,
none,
none,
none,
none}
).
-file("src/telega/reply.gleam", 488).
?DOC(
" Use this method to send a group of photos, videos, documents or audios as an album.\n"
" Documents and audio files can be only grouped in an album with messages of the same type.\n"
" Returns a list of messages that were sent.\n"
"\n"
" ## Example\n"
" ```gleam\n"
" let media_group = media_group.new()\n"
" |> media_group.add_photo(\"https://example.com/photo1.jpg\", None)\n"
" |> media_group.add_photo(\"https://example.com/photo2.jpg\", Some(\n"
" media_group.PhotoOptions(\n"
" caption: Some(\"Second photo\"),\n"
" parse_mode: Some(\"Markdown\"),\n"
" ..media_group.default_photo_options()\n"
" )\n"
" ))\n"
" |> media_group.build()\n"
"\n"
" reply.with_media_group(ctx, media_group)\n"
" ```\n"
"\n"
" **Official reference:** https://core.telegram.org/bots/api#sendmediagroup\n"
).
-spec with_media_group(
telega@bot:context(any(), any()),
list(telega@model@types:input_media())
) -> {ok, list(telega@model@types:message())} |
{error, telega@error:telega_error()}.
with_media_group(Ctx, Media) ->
telega@api:send_media_group(
erlang:element(5, erlang:element(4, Ctx)),
{send_media_group_parameters,
{str, erlang:element(2, Ctx)},
none,
none,
Media,
none,
none,
none,
none,
none}
).