-module(telega@update). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/telega/update.gleam"). -export([decode_raw/1, raw_to_update/1, raw/1, to_string/1, type_to_string/1]). -export_type([update/0, command/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. -type update() :: {text_update, integer(), integer(), binary(), telega@model@types:message(), telega@model@types:update()} | {command_update, integer(), integer(), command(), telega@model@types:message(), telega@model@types:update()} | {photo_update, integer(), integer(), list(telega@model@types:photo_size()), telega@model@types:message(), telega@model@types:update()} | {video_update, integer(), integer(), telega@model@types:video(), telega@model@types:message(), telega@model@types:update()} | {audio_update, integer(), integer(), telega@model@types:audio(), telega@model@types:message(), telega@model@types:update()} | {voice_update, integer(), integer(), telega@model@types:voice(), telega@model@types:message(), telega@model@types:update()} | {media_group_update, integer(), integer(), binary(), list(telega@model@types:message()), telega@model@types:update()} | {web_app_update, integer(), integer(), telega@model@types:web_app_data(), telega@model@types:message(), telega@model@types:update()} | {message_update, integer(), integer(), telega@model@types:message(), telega@model@types:update()} | {channel_post_update, integer(), integer(), telega@model@types:message(), telega@model@types:update()} | {edited_message_update, integer(), integer(), telega@model@types:message(), telega@model@types:update()} | {edited_channel_post_update, integer(), integer(), telega@model@types:message(), telega@model@types:update()} | {business_connection_update, integer(), integer(), telega@model@types:business_connection(), telega@model@types:update()} | {business_message_update, integer(), integer(), telega@model@types:message(), telega@model@types:update()} | {edited_business_message_update, integer(), integer(), telega@model@types:message(), telega@model@types:update()} | {deleted_business_message_update, integer(), integer(), telega@model@types:business_messages_deleted(), telega@model@types:update()} | {message_reaction_update, integer(), integer(), telega@model@types:message_reaction_updated(), telega@model@types:update()} | {message_reaction_count_update, integer(), integer(), telega@model@types:message_reaction_count_updated(), telega@model@types:update()} | {inline_query_update, integer(), integer(), telega@model@types:inline_query(), telega@model@types:update()} | {chosen_inline_result_update, integer(), integer(), telega@model@types:chosen_inline_result(), telega@model@types:update()} | {callback_query_update, integer(), integer(), telega@model@types:callback_query(), telega@model@types:update()} | {shipping_query_update, integer(), integer(), telega@model@types:shipping_query(), telega@model@types:update()} | {pre_checkout_query_update, integer(), integer(), telega@model@types:pre_checkout_query(), telega@model@types:update()} | {paid_media_purchase_update, integer(), integer(), telega@model@types:paid_media_purchased(), telega@model@types:update()} | {poll_update, integer(), integer(), telega@model@types:poll(), telega@model@types:update()} | {poll_answer_update, integer(), integer(), telega@model@types:poll_answer(), telega@model@types:update()} | {my_chat_member_update, integer(), integer(), telega@model@types:chat_member_updated(), telega@model@types:update()} | {chat_member_update, integer(), integer(), telega@model@types:chat_member_updated(), telega@model@types:update()} | {chat_join_request_update, integer(), integer(), telega@model@types:chat_join_request(), telega@model@types:update()} | {removed_chat_boost, integer(), integer(), telega@model@types:chat_boost_removed(), telega@model@types:update()} | {managed_bot_update, integer(), integer(), telega@model@types:managed_bot_updated(), telega@model@types:update()} | {guest_message_update, integer(), integer(), telega@model@types:message(), telega@model@types:update()}. -type command() :: {command, binary(), binary(), gleam@option:option(binary())}. -file("src/telega/update.gleam", 228). -spec decode_raw(gleam@dynamic:dynamic_()) -> {ok, telega@model@types:update()} | {error, telega@error:telega_error()}. decode_raw(Json) -> _pipe = gleam@dynamic@decode:run( Json, telega@model@decoder:update_decoder() ), gleam@result:map_error( _pipe, fun(E) -> {decode_update_error, <<<<<<"Cannot decode update: "/utf8, (gleam@string:inspect(Json))/binary>>/binary, " "/utf8>>/binary, (gleam@string:inspect(E))/binary>>} end ). -file("src/telega/update.gleam", 736). -spec get_sender_id(telega@model@types:message()) -> integer(). get_sender_id(Message) -> case {erlang:element(5, Message), erlang:element(6, Message)} of {_, {some, Sender_chat}} -> erlang:element(2, Sender_chat); {{some, User}, _} -> erlang:element(2, User); {_, _} -> erlang:element(2, erlang:element(13, Message)) end. -file("src/telega/update.gleam", 694). -spec new_message_update( telega@model@types:update(), telega@model@types:message() ) -> update(). new_message_update(Raw, Message) -> {message_update, get_sender_id(Message), erlang:element(2, erlang:element(13, Message)), Message, Raw}. -file("src/telega/update.gleam", 607). -spec new_text_update( telega@model@types:update(), telega@model@types:message(), binary() ) -> update(). new_text_update(Raw, Message, Text) -> {text_update, get_sender_id(Message), erlang:element(2, erlang:element(13, Message)), Text, Message, Raw}. -file("src/telega/update.gleam", 761). -spec extract_command(binary()) -> command(). extract_command(Text) -> case gleam@string:split(Text, <<" "/utf8>>) of [Command | Payload] -> {command, Text, gleam@string:drop_start(Command, 1), begin _pipe = Payload, _pipe@1 = gleam@string:join(_pipe, <<" "/utf8>>), {some, _pipe@1} end}; [] -> {command, Text, <<""/utf8>>, none} end. -file("src/telega/update.gleam", 617). -spec new_command_update( telega@model@types:update(), telega@model@types:message(), binary() ) -> update(). new_command_update(Raw, Message, Text) -> {command_update, get_sender_id(Message), erlang:element(2, erlang:element(13, Message)), extract_command(Text), Message, Raw}. -file("src/telega/update.gleam", 744). -spec is_command_entity(telega@model@types:message_entity()) -> boolean(). is_command_entity(Entity) -> (erlang:element(2, Entity) =:= <<"bot_command"/utf8>>) andalso (erlang:element( 3, Entity ) =:= 0). -file("src/telega/update.gleam", 748). -spec is_command_update(binary(), telega@model@types:update()) -> boolean(). is_command_update(Text, Raw_update) -> gleam@bool:guard( not gleam_stdlib:string_starts_with(Text, <<"/"/utf8>>), false, fun() -> case erlang:element(3, Raw_update) of {some, Message} -> case erlang:element(34, Message) of {some, Entities} -> gleam@list:any(Entities, fun is_command_entity/1); none -> false end; none -> false end end ). -file("src/telega/update.gleam", 362). -spec decode_text_message( telega@model@types:update(), telega@model@types:message(), binary() ) -> update(). decode_text_message(Raw_update, Message, Text) -> case is_command_update(Text, Raw_update) of true -> new_command_update(Raw_update, Message, Text); false -> new_text_update(Raw_update, Message, Text) end. -file("src/telega/update.gleam", 671). -spec new_web_app_data_update( telega@model@types:update(), telega@model@types:message(), telega@model@types:web_app_data() ) -> update(). new_web_app_data_update(Raw, Message, Web_app_data) -> {web_app_update, get_sender_id(Message), erlang:element(2, erlang:element(13, Message)), Web_app_data, Message, Raw}. -file("src/telega/update.gleam", 661). -spec new_voice_update( telega@model@types:update(), telega@model@types:message(), telega@model@types:voice() ) -> update(). new_voice_update(Raw, Message, Voice) -> {voice_update, get_sender_id(Message), erlang:element(2, erlang:element(13, Message)), Voice, Message, Raw}. -file("src/telega/update.gleam", 651). -spec new_audio_update( telega@model@types:update(), telega@model@types:message(), telega@model@types:audio() ) -> update(). new_audio_update(Raw, Message, Audio) -> {audio_update, get_sender_id(Message), erlang:element(2, erlang:element(13, Message)), Audio, Message, Raw}. -file("src/telega/update.gleam", 641). -spec new_video_update( telega@model@types:update(), telega@model@types:message(), telega@model@types:video() ) -> update(). new_video_update(Raw, Message, Video) -> {video_update, get_sender_id(Message), erlang:element(2, erlang:element(13, Message)), Video, Message, Raw}. -file("src/telega/update.gleam", 627). -spec new_photo_update( telega@model@types:update(), telega@model@types:message(), list(telega@model@types:photo_size()) ) -> update(). new_photo_update(Raw, Message, Photos) -> {photo_update, get_sender_id(Message), erlang:element(2, erlang:element(13, Message)), Photos, Message, Raw}. -file("src/telega/update.gleam", 342). -spec decode_message_update( telega@model@types:update(), telega@model@types:message() ) -> update(). decode_message_update(Raw_update, Message) -> case {erlang:element(43, Message), erlang:element(46, Message), erlang:element(39, Message), erlang:element(48, Message), erlang:element(114, Message), erlang:element(33, Message)} of {{some, Photos}, _, _, _, _, _} -> new_photo_update(Raw_update, Message, Photos); {_, {some, Video}, _, _, _, _} -> new_video_update(Raw_update, Message, Video); {_, _, {some, Audio}, _, _, _} -> new_audio_update(Raw_update, Message, Audio); {_, _, _, {some, Voice}, _, _} -> new_voice_update(Raw_update, Message, Voice); {_, _, _, _, {some, Web_app_data}, _} -> new_web_app_data_update(Raw_update, Message, Web_app_data); {_, _, _, _, _, {some, Text}} -> decode_text_message(Raw_update, Message, Text); {_, _, _, _, _, none} -> new_message_update(Raw_update, Message) end. -file("src/telega/update.gleam", 977). -spec new_guest_message_update( telega@model@types:update(), telega@model@types:message() ) -> update(). new_guest_message_update(Raw, Guest_message) -> {guest_message_update, get_sender_id(Guest_message), erlang:element(2, erlang:element(13, Guest_message)), Guest_message, Raw}. -file("src/telega/update.gleam", 968). -spec new_managed_bot_update( telega@model@types:update(), telega@model@types:managed_bot_updated() ) -> update(). new_managed_bot_update(Raw, Managed_bot) -> {managed_bot_update, erlang:element(2, erlang:element(2, Managed_bot)), erlang:element(2, erlang:element(2, Managed_bot)), Managed_bot, Raw}. -file("src/telega/update.gleam", 956). -spec new_removed_chat_boost_update( telega@model@types:update(), telega@model@types:chat_boost_removed() ) -> update(). new_removed_chat_boost_update(Raw, Removed_chat_boost) -> {removed_chat_boost, erlang:element(2, erlang:element(2, Removed_chat_boost)), erlang:element(2, erlang:element(2, Removed_chat_boost)), Removed_chat_boost, Raw}. -file("src/telega/update.gleam", 944). -spec new_chat_join_request_update( telega@model@types:update(), telega@model@types:chat_join_request() ) -> update(). new_chat_join_request_update(Raw, Chat_join_request) -> {chat_join_request_update, erlang:element(2, erlang:element(3, Chat_join_request)), erlang:element(2, erlang:element(2, Chat_join_request)), Chat_join_request, Raw}. -file("src/telega/update.gleam", 935). -spec new_chat_member_update( telega@model@types:update(), telega@model@types:chat_member_updated() ) -> update(). new_chat_member_update(Raw, Chat_member) -> {chat_member_update, erlang:element(2, erlang:element(3, Chat_member)), erlang:element(2, erlang:element(2, Chat_member)), Chat_member, Raw}. -file("src/telega/update.gleam", 923). -spec new_my_chat_member_update( telega@model@types:update(), telega@model@types:chat_member_updated() ) -> update(). new_my_chat_member_update(Raw, My_chat_member) -> {my_chat_member_update, erlang:element(2, erlang:element(3, My_chat_member)), erlang:element(2, erlang:element(2, My_chat_member)), My_chat_member, Raw}. -file("src/telega/update.gleam", 891). -spec new_poll_answer_update( telega@model@types:update(), telega@model@types:poll_answer() ) -> update(). new_poll_answer_update(Raw, Poll_answer) -> From_id = case erlang:element(4, Poll_answer) of {some, User} -> erlang:element(2, User); none -> telega@internal@log:warning( <<"PollAnswer received with neither user nor voter_chat. Poll ID: "/utf8, (erlang:element(2, Poll_answer))/binary>> ), 0 end, Chat_id = case erlang:element(3, Poll_answer) of {some, Chat} -> erlang:element(2, Chat); none -> case erlang:element(4, Poll_answer) of {some, User@1} -> erlang:element(2, User@1); none -> telega@internal@log:warning( <<"PollAnswer received with neither user nor voter_chat. Poll ID: "/utf8, (erlang:element(2, Poll_answer))/binary>> ), 0 end end, {poll_answer_update, From_id, Chat_id, Poll_answer, Raw}. -file("src/telega/update.gleam", 884). -spec new_poll_update(telega@model@types:update(), telega@model@types:poll()) -> update(). new_poll_update(Raw, Poll) -> {poll_update, -1, -1, Poll, Raw}. -file("src/telega/update.gleam", 872). -spec new_paid_media_purchase_update( telega@model@types:update(), telega@model@types:paid_media_purchased() ) -> update(). new_paid_media_purchase_update(Raw, Paid_media_purchased) -> {paid_media_purchase_update, erlang:element(2, erlang:element(2, Paid_media_purchased)), erlang:element(2, erlang:element(2, Paid_media_purchased)), Paid_media_purchased, Raw}. -file("src/telega/update.gleam", 860). -spec new_pre_checkout_query_update( telega@model@types:update(), telega@model@types:pre_checkout_query() ) -> update(). new_pre_checkout_query_update(Raw, Pre_checkout_query) -> {pre_checkout_query_update, erlang:element(2, erlang:element(3, Pre_checkout_query)), erlang:element(2, erlang:element(3, Pre_checkout_query)), Pre_checkout_query, Raw}. -file("src/telega/update.gleam", 851). -spec new_shipping_query_update( telega@model@types:update(), telega@model@types:shipping_query() ) -> update(). new_shipping_query_update(Raw, Shipping_query) -> {shipping_query_update, erlang:element(2, erlang:element(3, Shipping_query)), erlang:element(2, erlang:element(3, Shipping_query)), Shipping_query, Raw}. -file("src/telega/update.gleam", 839). -spec new_chosen_inline_result_update( telega@model@types:update(), telega@model@types:chosen_inline_result() ) -> update(). new_chosen_inline_result_update(Raw, Chosen_inline_result) -> {chosen_inline_result_update, erlang:element(2, erlang:element(3, Chosen_inline_result)), erlang:element(2, erlang:element(3, Chosen_inline_result)), Chosen_inline_result, Raw}. -file("src/telega/update.gleam", 830). -spec new_inline_query_update( telega@model@types:update(), telega@model@types:inline_query() ) -> update(). new_inline_query_update(Raw, Inline_query) -> {inline_query_update, erlang:element(2, erlang:element(3, Inline_query)), erlang:element(2, erlang:element(3, Inline_query)), Inline_query, Raw}. -file("src/telega/update.gleam", 818). -spec new_message_reaction_count_update( telega@model@types:update(), telega@model@types:message_reaction_count_updated() ) -> update(). new_message_reaction_count_update(Raw, Message_reaction_count) -> {message_reaction_count_update, erlang:element(2, erlang:element(2, Message_reaction_count)), erlang:element(2, erlang:element(2, Message_reaction_count)), Message_reaction_count, Raw}. -file("src/telega/update.gleam", 802). -spec new_message_reaction_update( telega@model@types:update(), telega@model@types:message_reaction_updated() ) -> update(). new_message_reaction_update(Raw, Message_reaction) -> {message_reaction_update, case {erlang:element(4, Message_reaction), erlang:element(5, Message_reaction)} of {_, {some, Actor_chat}} -> erlang:element(2, Actor_chat); {{some, User}, _} -> erlang:element(2, User); {_, _} -> erlang:element(2, erlang:element(2, Message_reaction)) end, erlang:element(2, erlang:element(2, Message_reaction)), Message_reaction, Raw}. -file("src/telega/update.gleam", 790). -spec new_deleted_business_message_update( telega@model@types:update(), telega@model@types:business_messages_deleted() ) -> update(). new_deleted_business_message_update(Raw, Deleted_business_messages) -> {deleted_business_message_update, erlang:element(2, erlang:element(3, Deleted_business_messages)), erlang:element(2, erlang:element(3, Deleted_business_messages)), Deleted_business_messages, Raw}. -file("src/telega/update.gleam", 775). -spec new_edited_business_message_update( telega@model@types:update(), telega@model@types:message() ) -> update(). new_edited_business_message_update(Raw, Edited_business_message) -> {edited_business_message_update, case erlang:element(5, Edited_business_message) of {some, User} -> erlang:element(2, User); none -> erlang:element(2, erlang:element(13, Edited_business_message)) end, erlang:element(2, erlang:element(13, Edited_business_message)), Edited_business_message, Raw}. -file("src/telega/update.gleam", 724). -spec new_business_message_update( telega@model@types:update(), telega@model@types:message() ) -> update(). new_business_message_update(Raw, Business_message) -> {business_message_update, case erlang:element(5, Business_message) of {some, User} -> erlang:element(2, User); none -> erlang:element(2, erlang:element(13, Business_message)) end, erlang:element(2, erlang:element(13, Business_message)), Business_message, Raw}. -file("src/telega/update.gleam", 712). -spec new_business_connection_update( telega@model@types:update(), telega@model@types:business_connection() ) -> update(). new_business_connection_update(Raw, Business_connection) -> {business_connection_update, erlang:element(2, erlang:element(3, Business_connection)), erlang:element(4, Business_connection), Business_connection, Raw}. -file("src/telega/update.gleam", 703). -spec new_edited_message_update( telega@model@types:update(), telega@model@types:message() ) -> update(). new_edited_message_update(Raw, Edited_message) -> {edited_message_update, get_sender_id(Edited_message), erlang:element(2, erlang:element(13, Edited_message)), Edited_message, Raw}. -file("src/telega/update.gleam", 685). -spec new_channel_post_update( telega@model@types:update(), telega@model@types:message() ) -> update(). new_channel_post_update(Raw, Channel_post) -> {channel_post_update, get_sender_id(Channel_post), erlang:element(2, erlang:element(13, Channel_post)), Channel_post, Raw}. -file("src/telega/update.gleam", 590). -spec new_callback_query_update( telega@model@types:update(), telega@model@types:callback_query() ) -> update(). new_callback_query_update(Raw, Callback_query) -> {callback_query_update, erlang:element(2, erlang:element(3, Callback_query)), case erlang:element(4, Callback_query) of {some, Message} -> case Message of {message_maybe_inaccessible_message, Message@1} -> erlang:element(2, erlang:element(13, Message@1)); {inaccessible_message_maybe_inaccessible_message, Inaccessible} -> erlang:element(2, erlang:element(2, Inaccessible)) end; none -> erlang:element(2, erlang:element(3, Callback_query)) end, Callback_query, Raw}. -file("src/telega/update.gleam", 241). ?DOC(" Decode a update from the Telegram API to `Update` instance.\n"). -spec raw_to_update(telega@model@types:update()) -> update(). raw_to_update(Raw_update) -> case Raw_update of _ when erlang:element(16, Raw_update) =/= none -> Callback_query@1 = case erlang:element(16, Raw_update) of {some, Callback_query} -> Callback_query; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"telega/update"/utf8>>, function => <<"raw_to_update"/utf8>>, line => 244, value => _assert_fail, start => 5741, 'end' => 5800, pattern_start => 5752, pattern_end => 5772}) end, new_callback_query_update(Raw_update, Callback_query@1); _ when erlang:element(5, Raw_update) =/= none -> Channel_post@1 = case erlang:element(5, Raw_update) of {some, Channel_post} -> Channel_post; _assert_fail@1 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"telega/update"/utf8>>, function => <<"raw_to_update"/utf8>>, line => 248, value => _assert_fail@1, start => 5919, 'end' => 5974, pattern_start => 5930, pattern_end => 5948}) end, new_channel_post_update(Raw_update, Channel_post@1); _ when erlang:element(4, Raw_update) =/= none -> Edited_message@1 = case erlang:element(4, Raw_update) of {some, Edited_message} -> Edited_message; _assert_fail@2 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"telega/update"/utf8>>, function => <<"raw_to_update"/utf8>>, line => 252, value => _assert_fail@2, start => 6091, 'end' => 6150, pattern_start => 6102, pattern_end => 6122}) end, new_edited_message_update(Raw_update, Edited_message@1); _ when erlang:element(7, Raw_update) =/= none -> Business_connection@1 = case erlang:element(7, Raw_update) of {some, Business_connection} -> Business_connection; _assert_fail@3 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"telega/update"/utf8>>, function => <<"raw_to_update"/utf8>>, line => 256, value => _assert_fail@3, start => 6276, 'end' => 6345, pattern_start => 6287, pattern_end => 6312}) end, new_business_connection_update(Raw_update, Business_connection@1); _ when erlang:element(8, Raw_update) =/= none -> Business_message@1 = case erlang:element(8, Raw_update) of {some, Business_message} -> Business_message; _assert_fail@4 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"telega/update"/utf8>>, function => <<"raw_to_update"/utf8>>, line => 260, value => _assert_fail@4, start => 6478, 'end' => 6541, pattern_start => 6489, pattern_end => 6511}) end, new_business_message_update(Raw_update, Business_message@1); _ when erlang:element(9, Raw_update) =/= none -> Edited_business_message@1 = case erlang:element(9, Raw_update) of {some, Edited_business_message} -> Edited_business_message; _assert_fail@5 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"telega/update"/utf8>>, function => <<"raw_to_update"/utf8>>, line => 264, value => _assert_fail@5, start => 6675, 'end' => 6760, pattern_start => 6686, pattern_end => 6715}) end, new_edited_business_message_update( Raw_update, Edited_business_message@1 ); _ when erlang:element(10, Raw_update) =/= none -> Deleted_business_messages@1 = case erlang:element(10, Raw_update) of {some, Deleted_business_messages} -> Deleted_business_messages; _assert_fail@6 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"telega/update"/utf8>>, function => <<"raw_to_update"/utf8>>, line => 269, value => _assert_fail@6, start => 6910, 'end' => 6999, pattern_start => 6921, pattern_end => 6952}) end, new_deleted_business_message_update( Raw_update, Deleted_business_messages@1 ); _ when erlang:element(12, Raw_update) =/= none -> Message_reaction@1 = case erlang:element(12, Raw_update) of {some, Message_reaction} -> Message_reaction; _assert_fail@7 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"telega/update"/utf8>>, function => <<"raw_to_update"/utf8>>, line => 274, value => _assert_fail@7, start => 7143, 'end' => 7206, pattern_start => 7154, pattern_end => 7176}) end, new_message_reaction_update(Raw_update, Message_reaction@1); _ when erlang:element(13, Raw_update) =/= none -> Message_reaction_count@1 = case erlang:element(13, Raw_update) of {some, Message_reaction_count} -> Message_reaction_count; _assert_fail@8 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"telega/update"/utf8>>, function => <<"raw_to_update"/utf8>>, line => 278, value => _assert_fail@8, start => 7339, 'end' => 7422, pattern_start => 7350, pattern_end => 7378}) end, new_message_reaction_count_update( Raw_update, Message_reaction_count@1 ); _ when erlang:element(14, Raw_update) =/= none -> Inline_query@1 = case erlang:element(14, Raw_update) of {some, Inline_query} -> Inline_query; _assert_fail@9 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"telega/update"/utf8>>, function => <<"raw_to_update"/utf8>>, line => 283, value => _assert_fail@9, start => 7557, 'end' => 7612, pattern_start => 7568, pattern_end => 7586}) end, new_inline_query_update(Raw_update, Inline_query@1); _ when erlang:element(15, Raw_update) =/= none -> Chosen_inline_result@1 = case erlang:element(15, Raw_update) of {some, Chosen_inline_result} -> Chosen_inline_result; _assert_fail@10 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"telega/update"/utf8>>, function => <<"raw_to_update"/utf8>>, line => 287, value => _assert_fail@10, start => 7735, 'end' => 7806, pattern_start => 7746, pattern_end => 7772}) end, new_chosen_inline_result_update(Raw_update, Chosen_inline_result@1); _ when erlang:element(17, Raw_update) =/= none -> Shipping_query@1 = case erlang:element(17, Raw_update) of {some, Shipping_query} -> Shipping_query; _assert_fail@11 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"telega/update"/utf8>>, function => <<"raw_to_update"/utf8>>, line => 291, value => _assert_fail@11, start => 7939, 'end' => 7998, pattern_start => 7950, pattern_end => 7970}) end, new_shipping_query_update(Raw_update, Shipping_query@1); _ when erlang:element(18, Raw_update) =/= none -> Pre_checkout_query@1 = case erlang:element(18, Raw_update) of {some, Pre_checkout_query} -> Pre_checkout_query; _assert_fail@12 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"telega/update"/utf8>>, function => <<"raw_to_update"/utf8>>, line => 295, value => _assert_fail@12, start => 8123, 'end' => 8190, pattern_start => 8134, pattern_end => 8158}) end, new_pre_checkout_query_update(Raw_update, Pre_checkout_query@1); _ when erlang:element(19, Raw_update) =/= none -> Purchased_paid_media@1 = case erlang:element(19, Raw_update) of {some, Purchased_paid_media} -> Purchased_paid_media; _assert_fail@13 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"telega/update"/utf8>>, function => <<"raw_to_update"/utf8>>, line => 299, value => _assert_fail@13, start => 8325, 'end' => 8396, pattern_start => 8336, pattern_end => 8362}) end, new_paid_media_purchase_update(Raw_update, Purchased_paid_media@1); _ when erlang:element(20, Raw_update) =/= none -> Poll@1 = case erlang:element(20, Raw_update) of {some, Poll} -> Poll; _assert_fail@14 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"telega/update"/utf8>>, function => <<"raw_to_update"/utf8>>, line => 303, value => _assert_fail@14, start => 8518, 'end' => 8557, pattern_start => 8529, pattern_end => 8539}) end, new_poll_update(Raw_update, Poll@1); _ when erlang:element(21, Raw_update) =/= none -> Poll_answer@1 = case erlang:element(21, Raw_update) of {some, Poll_answer} -> Poll_answer; _assert_fail@15 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"telega/update"/utf8>>, function => <<"raw_to_update"/utf8>>, line => 307, value => _assert_fail@15, start => 8655, 'end' => 8708, pattern_start => 8666, pattern_end => 8683}) end, new_poll_answer_update(Raw_update, Poll_answer@1); _ when erlang:element(22, Raw_update) =/= none -> My_chat_member@1 = case erlang:element(22, Raw_update) of {some, My_chat_member} -> My_chat_member; _assert_fail@16 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"telega/update"/utf8>>, function => <<"raw_to_update"/utf8>>, line => 311, value => _assert_fail@16, start => 8823, 'end' => 8882, pattern_start => 8834, pattern_end => 8854}) end, new_my_chat_member_update(Raw_update, My_chat_member@1); _ when erlang:element(23, Raw_update) =/= none -> Chat_member@1 = case erlang:element(23, Raw_update) of {some, Chat_member} -> Chat_member; _assert_fail@17 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"telega/update"/utf8>>, function => <<"raw_to_update"/utf8>>, line => 315, value => _assert_fail@17, start => 9000, 'end' => 9053, pattern_start => 9011, pattern_end => 9028}) end, new_chat_member_update(Raw_update, Chat_member@1); _ when erlang:element(24, Raw_update) =/= none -> Chat_join_request@1 = case erlang:element(24, Raw_update) of {some, Chat_join_request} -> Chat_join_request; _assert_fail@18 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"telega/update"/utf8>>, function => <<"raw_to_update"/utf8>>, line => 319, value => _assert_fail@18, start => 9171, 'end' => 9236, pattern_start => 9182, pattern_end => 9205}) end, new_chat_join_request_update(Raw_update, Chat_join_request@1); _ when erlang:element(26, Raw_update) =/= none -> Removed_chat_boost@1 = case erlang:element(26, Raw_update) of {some, Removed_chat_boost} -> Removed_chat_boost; _assert_fail@19 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"telega/update"/utf8>>, function => <<"raw_to_update"/utf8>>, line => 323, value => _assert_fail@19, start => 9367, 'end' => 9434, pattern_start => 9378, pattern_end => 9402}) end, new_removed_chat_boost_update(Raw_update, Removed_chat_boost@1); _ when erlang:element(27, Raw_update) =/= none -> Managed_bot@1 = case erlang:element(27, Raw_update) of {some, Managed_bot} -> Managed_bot; _assert_fail@20 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"telega/update"/utf8>>, function => <<"raw_to_update"/utf8>>, line => 327, value => _assert_fail@20, start => 9560, 'end' => 9613, pattern_start => 9571, pattern_end => 9588}) end, new_managed_bot_update(Raw_update, Managed_bot@1); _ when erlang:element(11, Raw_update) =/= none -> Guest_message@1 = case erlang:element(11, Raw_update) of {some, Guest_message} -> Guest_message; _assert_fail@21 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"telega/update"/utf8>>, function => <<"raw_to_update"/utf8>>, line => 331, value => _assert_fail@21, start => 9727, 'end' => 9784, pattern_start => 9738, pattern_end => 9757}) end, new_guest_message_update(Raw_update, Guest_message@1); _ when erlang:element(3, Raw_update) =/= none -> Message@1 = case erlang:element(3, Raw_update) of {some, Message} -> Message; _assert_fail@22 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"telega/update"/utf8>>, function => <<"raw_to_update"/utf8>>, line => 335, value => _assert_fail@22, start => 9896, 'end' => 9941, pattern_start => 9907, pattern_end => 9920}) end, decode_message_update(Raw_update, Message@1); _ -> erlang:error(#{gleam_error => panic, message => (<<"Unknown update: "/utf8, (gleam@string:inspect(Raw_update))/binary>>), file => <>, module => <<"telega/update"/utf8>>, function => <<"raw_to_update"/utf8>>, line => 338}) end. -file("src/telega/update.gleam", 376). ?DOC( " Get the original raw `ModelUpdate` behind any typed update. Useful when you\n" " need a field that the typed variant does not surface (e.g. the sender's\n" " `language_code`).\n" ). -spec raw(update()) -> telega@model@types:update(). raw(Update) -> case Update of {text_update, _, _, _, _, Raw} -> Raw; {command_update, _, _, _, _, Raw@1} -> Raw@1; {message_update, _, _, _, Raw@2} -> Raw@2; {photo_update, _, _, _, _, Raw@3} -> Raw@3; {video_update, _, _, _, _, Raw@4} -> Raw@4; {audio_update, _, _, _, _, Raw@5} -> Raw@5; {voice_update, _, _, _, _, Raw@6} -> Raw@6; {media_group_update, _, _, _, _, Raw@7} -> Raw@7; {web_app_update, _, _, _, _, Raw@8} -> Raw@8; {callback_query_update, _, _, _, Raw@9} -> Raw@9; {channel_post_update, _, _, _, Raw@10} -> Raw@10; {edited_message_update, _, _, _, Raw@11} -> Raw@11; {edited_channel_post_update, _, _, _, Raw@12} -> Raw@12; {business_connection_update, _, _, _, Raw@13} -> Raw@13; {business_message_update, _, _, _, Raw@14} -> Raw@14; {chat_join_request_update, _, _, _, Raw@15} -> Raw@15; {chat_member_update, _, _, _, Raw@16} -> Raw@16; {chosen_inline_result_update, _, _, _, Raw@17} -> Raw@17; {deleted_business_message_update, _, _, _, Raw@18} -> Raw@18; {edited_business_message_update, _, _, _, Raw@19} -> Raw@19; {inline_query_update, _, _, _, Raw@20} -> Raw@20; {message_reaction_count_update, _, _, _, Raw@21} -> Raw@21; {message_reaction_update, _, _, _, Raw@22} -> Raw@22; {my_chat_member_update, _, _, _, Raw@23} -> Raw@23; {paid_media_purchase_update, _, _, _, Raw@24} -> Raw@24; {poll_answer_update, _, _, _, Raw@25} -> Raw@25; {poll_update, _, _, _, Raw@26} -> Raw@26; {pre_checkout_query_update, _, _, _, Raw@27} -> Raw@27; {removed_chat_boost, _, _, _, Raw@28} -> Raw@28; {shipping_query_update, _, _, _, Raw@29} -> Raw@29; {managed_bot_update, _, _, _, Raw@30} -> Raw@30; {guest_message_update, _, _, _, Raw@31} -> Raw@31 end. -file("src/telega/update.gleam", 413). -spec to_string(update()) -> binary(). to_string(Update) -> case Update of {command_update, From_id, _, Command, _, _} -> <<<<<<"command \""/utf8, (erlang:element(3, Command))/binary>>/binary, "\" from "/utf8>>/binary, (erlang:integer_to_binary(From_id))/binary>>; {text_update, From_id@1, _, Text, _, _} -> <<<<<<"text \""/utf8, Text/binary>>/binary, "\" from "/utf8>>/binary, (erlang:integer_to_binary(From_id@1))/binary>>; {message_update, From_id@2, _, Message, _} -> <<<<<<"message "/utf8, (erlang:integer_to_binary(erlang:element(2, Message)))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@2))/binary>>; {photo_update, From_id@3, _, _, _, _} -> <<"photo from "/utf8, (erlang:integer_to_binary(From_id@3))/binary>>; {video_update, From_id@4, _, Video, _, _} -> <<<<<<"video "/utf8, (erlang:element(2, Video))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@4))/binary>>; {audio_update, From_id@5, _, Audio, _, _} -> <<<<<<"audio "/utf8, (erlang:element(2, Audio))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@5))/binary>>; {voice_update, From_id@6, _, Voice, _, _} -> <<<<<<"voice "/utf8, (erlang:element(2, Voice))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@6))/binary>>; {media_group_update, From_id@7, _, Media_group_id, Messages, _} -> <<<<<<<<<<"media group "/utf8, Media_group_id/binary>>/binary, " with "/utf8>>/binary, (erlang:integer_to_binary(erlang:length(Messages)))/binary>>/binary, " items from "/utf8>>/binary, (erlang:integer_to_binary(From_id@7))/binary>>; {web_app_update, From_id@8, _, Web_app_data, _, _} -> <<<<<<"web app "/utf8, (erlang:element(2, Web_app_data))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@8))/binary>>; {callback_query_update, From_id@9, _, Query, _} -> <<<<<<"callback query "/utf8, (gleam@option:unwrap( erlang:element(7, Query), <<"no data"/utf8>> ))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@9))/binary>>; {channel_post_update, From_id@10, _, Post, _} -> <<<<<<"channel post "/utf8, (erlang:integer_to_binary(erlang:element(2, Post)))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@10))/binary>>; {edited_message_update, From_id@11, _, Message@1, _} -> <<<<<<"edited message "/utf8, (erlang:integer_to_binary(erlang:element(2, Message@1)))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@11))/binary>>; {edited_channel_post_update, From_id@12, _, Post@1, _} -> <<<<<<"edited channel post "/utf8, (erlang:integer_to_binary(erlang:element(2, Post@1)))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@12))/binary>>; {business_connection_update, From_id@13, _, Business_connection, _} -> <<<<<<"business connection "/utf8, (erlang:element(2, Business_connection))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@13))/binary>>; {business_message_update, From_id@14, _, Message@2, _} -> <<<<<<"business message "/utf8, (erlang:integer_to_binary(erlang:element(2, Message@2)))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@14))/binary>>; {chat_join_request_update, From_id@15, _, Chat_join_request, _} -> <<<<<<"chat join request "/utf8, (erlang:integer_to_binary( erlang:element( 2, erlang:element(2, Chat_join_request) ) ))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@15))/binary>>; {chat_member_update, From_id@16, _, Chat_member_updated, _} -> <<<<<<"chat member update "/utf8, (erlang:integer_to_binary( erlang:element( 2, erlang:element(2, Chat_member_updated) ) ))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@16))/binary>>; {chosen_inline_result_update, From_id@17, _, Chosen_inline_result, _} -> <<<<<<"chosen inline result "/utf8, (erlang:element(2, Chosen_inline_result))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@17))/binary>>; {deleted_business_message_update, From_id@18, _, Business_messages_deleted, _} -> <<<<<<"deleted business message "/utf8, (erlang:integer_to_binary( erlang:element( 2, erlang:element(3, Business_messages_deleted) ) ))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@18))/binary>>; {edited_business_message_update, From_id@19, _, Message@3, _} -> <<<<<<"edited business message "/utf8, (erlang:integer_to_binary(erlang:element(2, Message@3)))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@19))/binary>>; {inline_query_update, From_id@20, _, Inline_query, _} -> <<<<<<"inline query "/utf8, (erlang:element(2, Inline_query))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@20))/binary>>; {message_reaction_count_update, From_id@21, _, Message_reaction_count_updated, _} -> <<<<<<"message reaction count update "/utf8, (erlang:integer_to_binary( erlang:element( 2, erlang:element( 2, Message_reaction_count_updated ) ) ))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@21))/binary>>; {message_reaction_update, From_id@22, _, Message_reaction_updated, _} -> <<<<<<"message reaction update "/utf8, (erlang:integer_to_binary( erlang:element( 2, erlang:element(2, Message_reaction_updated) ) ))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@22))/binary>>; {my_chat_member_update, From_id@23, _, Chat_member_updated@1, _} -> <<<<<<"my chat member update "/utf8, (erlang:integer_to_binary( erlang:element( 2, erlang:element(2, Chat_member_updated@1) ) ))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@23))/binary>>; {paid_media_purchase_update, From_id@24, _, _, _} -> <<"paid media purchase from "/utf8, (erlang:integer_to_binary(From_id@24))/binary>>; {poll_answer_update, From_id@25, _, Poll_answer, _} -> <<<<<<"poll answer "/utf8, (erlang:element(2, Poll_answer))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@25))/binary>>; {poll_update, From_id@26, _, Poll, _} -> <<<<<<"poll "/utf8, (erlang:element(2, Poll))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@26))/binary>>; {pre_checkout_query_update, From_id@27, _, Pre_checkout_query, _} -> <<<<<<"pre checkout query "/utf8, (erlang:element(2, Pre_checkout_query))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@27))/binary>>; {removed_chat_boost, From_id@28, _, Removed_chat_boost, _} -> <<<<<<"removed chat boost "/utf8, (erlang:integer_to_binary( erlang:element( 2, erlang:element(2, Removed_chat_boost) ) ))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@28))/binary>>; {shipping_query_update, From_id@29, _, Shipping_query, _} -> <<<<<<"shipping query "/utf8, (erlang:element(2, Shipping_query))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@29))/binary>>; {managed_bot_update, From_id@30, _, Managed_bot, _} -> <<<<<<"managed bot "/utf8, (erlang:integer_to_binary( erlang:element(2, erlang:element(3, Managed_bot)) ))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@30))/binary>>; {guest_message_update, From_id@31, _, Message@4, _} -> <<<<<<"guest message "/utf8, (erlang:integer_to_binary(erlang:element(2, Message@4)))/binary>>/binary, " from "/utf8>>/binary, (erlang:integer_to_binary(From_id@31))/binary>> end. -file("src/telega/update.gleam", 552). ?DOC( " Returns a short snake_case tag for the update variant,\n" " e.g. `\"text\"`, `\"command\"`, `\"callback_query\"`.\n" " Used as the `update_type` metadata in telemetry events.\n" ). -spec type_to_string(update()) -> binary(). type_to_string(Update) -> case Update of {text_update, _, _, _, _, _} -> <<"text"/utf8>>; {command_update, _, _, _, _, _} -> <<"command"/utf8>>; {photo_update, _, _, _, _, _} -> <<"photo"/utf8>>; {video_update, _, _, _, _, _} -> <<"video"/utf8>>; {audio_update, _, _, _, _, _} -> <<"audio"/utf8>>; {voice_update, _, _, _, _, _} -> <<"voice"/utf8>>; {media_group_update, _, _, _, _, _} -> <<"media_group"/utf8>>; {web_app_update, _, _, _, _, _} -> <<"web_app"/utf8>>; {message_update, _, _, _, _} -> <<"message"/utf8>>; {channel_post_update, _, _, _, _} -> <<"channel_post"/utf8>>; {edited_message_update, _, _, _, _} -> <<"edited_message"/utf8>>; {edited_channel_post_update, _, _, _, _} -> <<"edited_channel_post"/utf8>>; {business_connection_update, _, _, _, _} -> <<"business_connection"/utf8>>; {business_message_update, _, _, _, _} -> <<"business_message"/utf8>>; {edited_business_message_update, _, _, _, _} -> <<"edited_business_message"/utf8>>; {deleted_business_message_update, _, _, _, _} -> <<"deleted_business_message"/utf8>>; {message_reaction_update, _, _, _, _} -> <<"message_reaction"/utf8>>; {message_reaction_count_update, _, _, _, _} -> <<"message_reaction_count"/utf8>>; {inline_query_update, _, _, _, _} -> <<"inline_query"/utf8>>; {chosen_inline_result_update, _, _, _, _} -> <<"chosen_inline_result"/utf8>>; {callback_query_update, _, _, _, _} -> <<"callback_query"/utf8>>; {shipping_query_update, _, _, _, _} -> <<"shipping_query"/utf8>>; {pre_checkout_query_update, _, _, _, _} -> <<"pre_checkout_query"/utf8>>; {paid_media_purchase_update, _, _, _, _} -> <<"paid_media_purchase"/utf8>>; {poll_update, _, _, _, _} -> <<"poll"/utf8>>; {poll_answer_update, _, _, _, _} -> <<"poll_answer"/utf8>>; {my_chat_member_update, _, _, _, _} -> <<"my_chat_member"/utf8>>; {chat_member_update, _, _, _, _} -> <<"chat_member"/utf8>>; {chat_join_request_update, _, _, _, _} -> <<"chat_join_request"/utf8>>; {removed_chat_boost, _, _, _, _} -> <<"removed_chat_boost"/utf8>>; {managed_bot_update, _, _, _, _} -> <<"managed_bot"/utf8>>; {guest_message_update, _, _, _, _} -> <<"guest_message"/utf8>> end.