Current section

Files

Jump to
telega src telega@dialog@types.erl
Raw

src/telega@dialog@types.erl

-module(telega@dialog@types).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/telega/dialog/types.gleam").
-export([new_store/0, store_get/2, store_set/3, encode_store/1, decode_store/1, default_labels/0]).
-export_type([rendered_window/0, dialog_media/0, dialog_button/0, dialog_action/1, action_event/0, window/4, keyboard_widget/4, widget_ctx/4, widget_result/1, widget_store/0, labels/0, dialog_build_error/0]).
-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(
" Shared type definitions for the declarative dialog system.\n"
"\n"
" A dialog is a set of windows; a window is a pure render function plus\n"
" event handlers. See `telega/dialog` for the builder API and the full\n"
" guide.\n"
).
-type rendered_window() :: {rendered_window,
telega@format:formatted_text(),
list(list(dialog_button())),
gleam@option:option(dialog_media())}.
-type dialog_media() :: {photo_media, binary(), boolean()} |
{video_media, binary(), boolean()} |
{animation_media, binary()} |
{document_media, binary()}.
-type dialog_button() :: {action_button, binary(), binary()} |
{action_arg_button, binary(), binary(), binary()} |
{url_button, binary(), binary()} |
{web_app_button, binary(), binary()} |
{noop_button, binary()}.
-type dialog_action(AVCZ) :: {stay, AVCZ} |
{goto, binary(), AVCZ} |
{back, AVCZ} |
{done, AVCZ} |
{start_sub, binary(), gleam@dict:dict(binary(), binary()), AVCZ}.
-type action_event() :: {action_event, binary(), gleam@option:option(binary())}.
-type window(AVDA, AVDB, AVDC, AVDD) :: {window,
binary(),
fun((AVDA, telega@bot:context(AVDB, AVDC, AVDD)) -> rendered_window()),
fun((AVDA, action_event(), telega@bot:context(AVDB, AVDC, AVDD)) -> {ok,
dialog_action(AVDA)} |
{error, AVDC}),
gleam@option:option(fun((AVDA, binary(), telega@bot:context(AVDB, AVDC, AVDD)) -> {ok,
dialog_action(AVDA)} |
{error, AVDC})),
list(keyboard_widget(AVDA, AVDB, AVDC, AVDD)),
gleam@option:option(fun((AVDA, gleam@dict:dict(binary(), binary()), telega@bot:context(AVDB, AVDC, AVDD)) -> {ok,
dialog_action(AVDA)} |
{error, AVDC}))}.
-type keyboard_widget(AVDE, AVDF, AVDG, AVDH) :: {keyboard_widget,
binary(),
fun((widget_ctx(AVDE, AVDF, AVDG, AVDH)) -> list(list(dialog_button()))),
fun((widget_ctx(AVDE, AVDF, AVDG, AVDH), binary(), gleam@option:option(binary())) -> {ok,
widget_result(AVDE)} |
{error, AVDG}),
list(binary()),
list(binary())}.
-type widget_ctx(AVDI, AVDJ, AVDK, AVDL) :: {widget_ctx,
AVDI,
widget_store(),
labels(),
telega@bot:context(AVDJ, AVDK, AVDL)}.
-type widget_result(AVDM) :: {store_updated, widget_store()} |
{emit, dialog_action(AVDM)}.
-opaque widget_store() :: {widget_store, gleam@dict:dict(binary(), binary())}.
-type labels() :: {labels,
binary(),
binary(),
binary(),
binary(),
binary(),
binary(),
binary(),
binary(),
binary()}.
-type dialog_build_error() :: {duplicate_window_id, binary()} |
{unknown_window_reference, binary(), binary()} |
{callback_data_too_long, binary(), binary(), integer()} |
no_windows |
{unknown_initial_window, binary()} |
{duplicate_widget_id, binary(), binary()} |
{reserved_id_character, binary(), binary()} |
{duplicate_sub_dialog_id, binary()} |
{nested_sub_dialog, binary()}.
-file("src/telega/dialog/types.gleam", 170).
-spec new_store() -> widget_store().
new_store() ->
{widget_store, maps:new()}.
-file("src/telega/dialog/types.gleam", 174).
-spec store_get(widget_store(), binary()) -> gleam@option:option(binary()).
store_get(Store, Key) ->
_pipe = gleam_stdlib:map_get(erlang:element(2, Store), Key),
gleam@option:from_result(_pipe).
-file("src/telega/dialog/types.gleam", 178).
-spec store_set(widget_store(), binary(), binary()) -> widget_store().
store_set(Store, Key, Value) ->
{widget_store, gleam@dict:insert(erlang:element(2, Store), Key, Value)}.
-file("src/telega/dialog/types.gleam", 189).
?DOC(false).
-spec encode_store(widget_store()) -> binary().
encode_store(Store) ->
_pipe = erlang:element(2, Store),
_pipe@1 = maps:to_list(_pipe),
_pipe@2 = gleam@list:map(
_pipe@1,
fun(Entry) ->
{erlang:element(1, Entry),
gleam@json:string(erlang:element(2, Entry))}
end
),
_pipe@3 = gleam@json:object(_pipe@2),
gleam@json:to_string(_pipe@3).
-file("src/telega/dialog/types.gleam", 198).
?DOC(false).
-spec decode_store(binary()) -> {ok, widget_store()} | {error, nil}.
decode_store(Raw) ->
_pipe = gleam@json:parse(
Raw,
gleam@dynamic@decode:dict(
{decoder, fun gleam@dynamic@decode:decode_string/1},
{decoder, fun gleam@dynamic@decode:decode_string/1}
)
),
_pipe@1 = gleam@result:map(
_pipe,
fun(Field@0) -> {widget_store, Field@0} end
),
gleam@result:replace_error(_pipe@1, nil).
-file("src/telega/dialog/types.gleam", 223).
-spec default_labels() -> labels().
default_labels() ->
{labels,
<<"‹"/utf8>>,
<<"›"/utf8>>,
<<"{current}/{total}"/utf8>>,
<<"● "/utf8>>,
<<"○ "/utf8>>,
<<"☑ "/utf8>>,
<<"☐ "/utf8>>,
<<"✓"/utf8>>,
<<"⏳"/utf8>>}.