From 6b286cd13a93304348ce1b449b962fee6a15b49c Mon Sep 17 00:00:00 2001 From: Alexander Tipugin Date: Wed, 10 Jan 2024 18:12:03 +0300 Subject: [PATCH 1/3] feat: implement Bot API 7.0 --- .gitignore | 1 + lib/telegram/bot/api/endpoints.rb | 5 + lib/telegram/bot/types/callback_query.rb | 2 +- lib/telegram/bot/types/chat.rb | 6 + lib/telegram/bot/types/chat_boost.rb | 14 + lib/telegram/bot/types/chat_boost_removed.rb | 14 + lib/telegram/bot/types/chat_boost_source.rb | 13 + .../bot/types/chat_boost_source_gift_code.rb | 12 + .../bot/types/chat_boost_source_giveaway.rb | 14 + .../bot/types/chat_boost_source_premium.rb | 12 + lib/telegram/bot/types/chat_boost_updated.rb | 12 + lib/telegram/bot/types/external_reply_info.rb | 33 ++ lib/telegram/bot/types/giveaway.rb | 18 + lib/telegram/bot/types/giveaway_completed.rb | 13 + lib/telegram/bot/types/giveaway_created.rb | 10 + lib/telegram/bot/types/giveaway_winners.rb | 21 + .../bot/types/inaccessible_message.rb | 13 + .../bot/types/input_text_message_content.rb | 2 +- lib/telegram/bot/types/keyboard_button.rb | 2 +- ...er.rb => keyboard_button_request_users.rb} | 3 +- .../bot/types/link_preview_options.rb | 15 + .../bot/types/maybe_inaccessible_message.rb | 12 + lib/telegram/bot/types/message.rb | 18 +- lib/telegram/bot/types/message_origin.rb | 14 + .../bot/types/message_origin_channel.rb | 15 + lib/telegram/bot/types/message_origin_chat.rb | 14 + .../bot/types/message_origin_hidden_user.rb | 13 + lib/telegram/bot/types/message_origin_user.rb | 13 + .../types/message_reaction_count_updated.rb | 14 + .../bot/types/message_reaction_updated.rb | 17 + lib/telegram/bot/types/reaction_count.rb | 12 + lib/telegram/bot/types/reaction_type.rb | 12 + .../bot/types/reaction_type_custom_emoji.rb | 12 + lib/telegram/bot/types/reaction_type_emoji.rb | 12 + lib/telegram/bot/types/reply_parameters.rb | 17 + lib/telegram/bot/types/text_quote.rb | 14 + lib/telegram/bot/types/update.rb | 4 + lib/telegram/bot/types/user_chat_boosts.rb | 11 + .../types/{user_shared.rb => users_shared.rb} | 4 +- spec/support/type_attributes.yml | 540 +++++++++++++++--- 40 files changed, 922 insertions(+), 81 deletions(-) create mode 100644 lib/telegram/bot/types/chat_boost.rb create mode 100644 lib/telegram/bot/types/chat_boost_removed.rb create mode 100644 lib/telegram/bot/types/chat_boost_source.rb create mode 100644 lib/telegram/bot/types/chat_boost_source_gift_code.rb create mode 100644 lib/telegram/bot/types/chat_boost_source_giveaway.rb create mode 100644 lib/telegram/bot/types/chat_boost_source_premium.rb create mode 100644 lib/telegram/bot/types/chat_boost_updated.rb create mode 100644 lib/telegram/bot/types/external_reply_info.rb create mode 100644 lib/telegram/bot/types/giveaway.rb create mode 100644 lib/telegram/bot/types/giveaway_completed.rb create mode 100644 lib/telegram/bot/types/giveaway_created.rb create mode 100644 lib/telegram/bot/types/giveaway_winners.rb create mode 100644 lib/telegram/bot/types/inaccessible_message.rb rename lib/telegram/bot/types/{keyboard_button_request_user.rb => keyboard_button_request_users.rb} (72%) create mode 100644 lib/telegram/bot/types/link_preview_options.rb create mode 100644 lib/telegram/bot/types/maybe_inaccessible_message.rb create mode 100644 lib/telegram/bot/types/message_origin.rb create mode 100644 lib/telegram/bot/types/message_origin_channel.rb create mode 100644 lib/telegram/bot/types/message_origin_chat.rb create mode 100644 lib/telegram/bot/types/message_origin_hidden_user.rb create mode 100644 lib/telegram/bot/types/message_origin_user.rb create mode 100644 lib/telegram/bot/types/message_reaction_count_updated.rb create mode 100644 lib/telegram/bot/types/message_reaction_updated.rb create mode 100644 lib/telegram/bot/types/reaction_count.rb create mode 100644 lib/telegram/bot/types/reaction_type.rb create mode 100644 lib/telegram/bot/types/reaction_type_custom_emoji.rb create mode 100644 lib/telegram/bot/types/reaction_type_emoji.rb create mode 100644 lib/telegram/bot/types/reply_parameters.rb create mode 100644 lib/telegram/bot/types/text_quote.rb create mode 100644 lib/telegram/bot/types/user_chat_boosts.rb rename lib/telegram/bot/types/{user_shared.rb => users_shared.rb} (62%) diff --git a/.gitignore b/.gitignore index 47b26377..e1f93c0e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ Gemfile.lock .bundle/ .env pkg/ +tmp/ vendor/bundle/ diff --git a/lib/telegram/bot/api/endpoints.rb b/lib/telegram/bot/api/endpoints.rb index c2406d6a..212677da 100644 --- a/lib/telegram/bot/api/endpoints.rb +++ b/lib/telegram/bot/api/endpoints.rb @@ -11,6 +11,7 @@ class Api 'getMe' => Types::User, 'sendMessage' => Types::Message, 'forwardMessage' => Types::Message, + 'forwardMessages' => Types::Array.of(Types::MessageId), 'sendPhoto' => Types::Message, 'sendAudio' => Types::Message, 'sendDocument' => Types::Message, @@ -24,6 +25,7 @@ class Api 'sendVenue' => Types::Message, 'sendContact' => Types::Message, 'sendChatAction' => Types::Bool, + 'setMessageReaction' => Types::Bool, 'getUserProfilePhotos' => Types::UserProfilePhotos, 'getFile' => Types::File, 'banChatMember' => Types::Bool, @@ -45,10 +47,12 @@ class Api 'setChatStickerSet' => Types::Bool, 'deleteChatStickerSet' => Types::Bool, 'answerCallbackQuery' => Types::Bool, + 'getUserChatBoosts' => Types::UserChatBoosts, 'editMessageText' => Types::Message | Types::Bool, 'editMessageCaption' => Types::Message | Types::Bool, 'editMessageReplyMarkup' => Types::Message | Types::Bool, 'deleteMessage' => Types::Bool, + 'deleteMessages' => Types::Bool, 'sendSticker' => Types::Message, 'getStickerSet' => Types::StickerSet, 'uploadStickerFile' => Types::File, @@ -78,6 +82,7 @@ class Api 'logOut' => Types::Bool, 'close' => Types::Bool, 'copyMessage' => Types::MessageId, + 'copyMessages' => Types::Array.of(Types::MessageId), 'createChatInviteLink' => Types::ChatInviteLink, 'editChatInviteLink' => Types::ChatInviteLink, 'revokeChatInviteLink' => Types::ChatInviteLink, diff --git a/lib/telegram/bot/types/callback_query.rb b/lib/telegram/bot/types/callback_query.rb index 0023873d..3991fcb6 100644 --- a/lib/telegram/bot/types/callback_query.rb +++ b/lib/telegram/bot/types/callback_query.rb @@ -6,7 +6,7 @@ module Types class CallbackQuery < Base attribute :id, Types::String attribute :from, User - attribute? :message, Message + attribute? :message, MaybeInaccessibleMessage attribute? :inline_message_id, Types::String attribute :chat_instance, Types::String attribute? :data, Types::String diff --git a/lib/telegram/bot/types/chat.rb b/lib/telegram/bot/types/chat.rb index 11cef653..f5db6a61 100644 --- a/lib/telegram/bot/types/chat.rb +++ b/lib/telegram/bot/types/chat.rb @@ -13,6 +13,11 @@ class Chat < Base attribute? :is_forum, Types::True attribute? :photo, ChatPhoto attribute? :active_usernames, Types::Array.of(Types::String) + attribute? :available_reactions, Types::Array.of(ReactionType) + attribute? :accent_color_id, Types::Integer + attribute? :background_custom_emoji_id, Types::String + attribute? :profile_accent_color_id, Types::Integer + attribute? :profile_background_custom_emoji_id, Types::String attribute? :emoji_status_custom_emoji_id, Types::String attribute? :emoji_status_expiration_date, Types::Integer attribute? :bio, Types::String @@ -29,6 +34,7 @@ class Chat < Base attribute? :has_aggressive_anti_spam_enabled, Types::True attribute? :has_hidden_members, Types::True attribute? :has_protected_content, Types::True + attribute? :has_visible_history, Types::True attribute? :sticker_set_name, Types::String attribute? :can_set_sticker_set, Types::True attribute? :linked_chat_id, Types::Integer diff --git a/lib/telegram/bot/types/chat_boost.rb b/lib/telegram/bot/types/chat_boost.rb new file mode 100644 index 00000000..dbe37d79 --- /dev/null +++ b/lib/telegram/bot/types/chat_boost.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class ChatBoost < Base + attribute :boost_id, Types::String + attribute :add_date, Types::Integer + attribute :expiration_date, Types::Integer + attribute :source, ChatBoostSource + end + end + end +end diff --git a/lib/telegram/bot/types/chat_boost_removed.rb b/lib/telegram/bot/types/chat_boost_removed.rb new file mode 100644 index 00000000..dae389c5 --- /dev/null +++ b/lib/telegram/bot/types/chat_boost_removed.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class ChatBoostRemoved < Base + attribute :chat, Chat + attribute :boost_id, Types::String + attribute :remove_date, Types::Integer + attribute :source, ChatBoostSource + end + end + end +end diff --git a/lib/telegram/bot/types/chat_boost_source.rb b/lib/telegram/bot/types/chat_boost_source.rb new file mode 100644 index 00000000..097509db --- /dev/null +++ b/lib/telegram/bot/types/chat_boost_source.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + ChatBoostSource = ( # rubocop:disable Naming/ConstantName + ChatBoostSourcePremium | + ChatBoostSourceGiftCode | + ChatBoostSourceGiveaway + ) + end + end +end diff --git a/lib/telegram/bot/types/chat_boost_source_gift_code.rb b/lib/telegram/bot/types/chat_boost_source_gift_code.rb new file mode 100644 index 00000000..323c9a3e --- /dev/null +++ b/lib/telegram/bot/types/chat_boost_source_gift_code.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class ChatBoostSourceGiftCode < Base + attribute :source, Types::String.constrained(eql: 'gift_code').default('gift_code') + attribute :user, User + end + end + end +end diff --git a/lib/telegram/bot/types/chat_boost_source_giveaway.rb b/lib/telegram/bot/types/chat_boost_source_giveaway.rb new file mode 100644 index 00000000..bdfbfe45 --- /dev/null +++ b/lib/telegram/bot/types/chat_boost_source_giveaway.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class ChatBoostSourceGiveaway < Base + attribute :source, Types::String.constrained(eql: 'giveaway').default('giveaway') + attribute :giveaway_message_id, Types::Integer + attribute? :user, User + attribute? :is_unclaimed, Types::True + end + end + end +end diff --git a/lib/telegram/bot/types/chat_boost_source_premium.rb b/lib/telegram/bot/types/chat_boost_source_premium.rb new file mode 100644 index 00000000..4ff8416f --- /dev/null +++ b/lib/telegram/bot/types/chat_boost_source_premium.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class ChatBoostSourcePremium < Base + attribute :source, Types::String.constrained(eql: 'premium').default('premium') + attribute :user, User + end + end + end +end diff --git a/lib/telegram/bot/types/chat_boost_updated.rb b/lib/telegram/bot/types/chat_boost_updated.rb new file mode 100644 index 00000000..a2e29481 --- /dev/null +++ b/lib/telegram/bot/types/chat_boost_updated.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class ChatBoostUpdated < Base + attribute :chat, Chat + attribute :boost, ChatBoost + end + end + end +end diff --git a/lib/telegram/bot/types/external_reply_info.rb b/lib/telegram/bot/types/external_reply_info.rb new file mode 100644 index 00000000..1f17b5b6 --- /dev/null +++ b/lib/telegram/bot/types/external_reply_info.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class ExternalReplyInfo < Base + attribute :origin, MessageOrigin + attribute? :chat, Chat + attribute? :message_id, Types::Integer + attribute? :link_preview_options, LinkPreviewOptions + attribute? :animation, Animation + attribute? :audio, Audio + attribute? :document, Document + attribute? :photo, Types::Array.of(PhotoSize) + attribute? :sticker, Sticker + attribute? :story, Story + attribute? :video, Video + attribute? :video_note, VideoNote + attribute? :voice, Voice + attribute? :has_media_spoiler, Types::True + attribute? :contact, Contact + attribute? :dice, Dice + attribute? :game, Game + attribute? :giveaway, Giveaway + attribute? :giveaway_winners, GiveawayWinners + attribute? :invoice, Invoice + attribute? :location, Location + attribute? :poll, Poll + attribute? :venue, Venue + end + end + end +end diff --git a/lib/telegram/bot/types/giveaway.rb b/lib/telegram/bot/types/giveaway.rb new file mode 100644 index 00000000..2d14c4a8 --- /dev/null +++ b/lib/telegram/bot/types/giveaway.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class Giveaway < Base + attribute :chats, Types::Array.of(Chat) + attribute :winners_selection_date, Types::Integer + attribute :winner_count, Types::Integer + attribute? :only_new_members, Types::True + attribute? :has_public_winners, Types::True + attribute? :prize_description, Types::String + attribute? :country_codes, Types::Array.of(Types::String) + attribute? :premium_subscription_month_count, Types::Integer + end + end + end +end diff --git a/lib/telegram/bot/types/giveaway_completed.rb b/lib/telegram/bot/types/giveaway_completed.rb new file mode 100644 index 00000000..a953d1e0 --- /dev/null +++ b/lib/telegram/bot/types/giveaway_completed.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class GiveawayCompleted < Base + attribute :winner_count, Types::Integer + attribute? :unclaimed_prize_count, Types::Integer + attribute? :giveaway_message, Message + end + end + end +end diff --git a/lib/telegram/bot/types/giveaway_created.rb b/lib/telegram/bot/types/giveaway_created.rb new file mode 100644 index 00000000..8843504e --- /dev/null +++ b/lib/telegram/bot/types/giveaway_created.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class GiveawayCreated < Base + end + end + end +end diff --git a/lib/telegram/bot/types/giveaway_winners.rb b/lib/telegram/bot/types/giveaway_winners.rb new file mode 100644 index 00000000..93351960 --- /dev/null +++ b/lib/telegram/bot/types/giveaway_winners.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class GiveawayWinners < Base + attribute :chat, Chat + attribute :giveaway_message_id, Types::Integer + attribute :winners_selection_date, Types::Integer + attribute :winner_count, Types::Integer + attribute :winners, Types::Array.of(User) + attribute? :additional_chat_count, Types::Integer + attribute? :premium_subscription_month_count, Types::Integer + attribute? :unclaimed_prize_count, Types::Integer + attribute? :only_new_members, Types::True + attribute? :was_refunded, Types::True + attribute? :prize_description, Types::String + end + end + end +end diff --git a/lib/telegram/bot/types/inaccessible_message.rb b/lib/telegram/bot/types/inaccessible_message.rb new file mode 100644 index 00000000..829ef76a --- /dev/null +++ b/lib/telegram/bot/types/inaccessible_message.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class InaccessibleMessage < Base + attribute :chat, Chat + attribute :message_id, Types::Integer + attribute :date, Types::Integer + end + end + end +end diff --git a/lib/telegram/bot/types/input_text_message_content.rb b/lib/telegram/bot/types/input_text_message_content.rb index f014ad54..8c02dcf2 100644 --- a/lib/telegram/bot/types/input_text_message_content.rb +++ b/lib/telegram/bot/types/input_text_message_content.rb @@ -7,7 +7,7 @@ class InputTextMessageContent < InputMessageContent attribute :message_text, Types::String attribute? :parse_mode, Types::String attribute? :entities, Types::Array.of(MessageEntity) - attribute? :disable_web_page_preview, Types::Bool + attribute? :link_preview_options, LinkPreviewOptions end end end diff --git a/lib/telegram/bot/types/keyboard_button.rb b/lib/telegram/bot/types/keyboard_button.rb index 4ac4c765..5bbd3d63 100644 --- a/lib/telegram/bot/types/keyboard_button.rb +++ b/lib/telegram/bot/types/keyboard_button.rb @@ -5,7 +5,7 @@ module Bot module Types class KeyboardButton < Base attribute :text, Types::String - attribute? :request_user, KeyboardButtonRequestUser + attribute? :request_users, KeyboardButtonRequestUsers attribute? :request_chat, KeyboardButtonRequestChat attribute? :request_contact, Types::Bool attribute? :request_location, Types::Bool diff --git a/lib/telegram/bot/types/keyboard_button_request_user.rb b/lib/telegram/bot/types/keyboard_button_request_users.rb similarity index 72% rename from lib/telegram/bot/types/keyboard_button_request_user.rb rename to lib/telegram/bot/types/keyboard_button_request_users.rb index 736ea772..49ec5ed3 100644 --- a/lib/telegram/bot/types/keyboard_button_request_user.rb +++ b/lib/telegram/bot/types/keyboard_button_request_users.rb @@ -3,10 +3,11 @@ module Telegram module Bot module Types - class KeyboardButtonRequestUser < Base + class KeyboardButtonRequestUsers < Base attribute :request_id, Types::Integer attribute? :user_is_bot, Types::Bool attribute? :user_is_premium, Types::Bool + attribute? :max_quantity, Types::Integer end end end diff --git a/lib/telegram/bot/types/link_preview_options.rb b/lib/telegram/bot/types/link_preview_options.rb new file mode 100644 index 00000000..57070575 --- /dev/null +++ b/lib/telegram/bot/types/link_preview_options.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class LinkPreviewOptions < Base + attribute? :is_disabled, Types::Bool + attribute? :url, Types::String + attribute? :prefer_small_media, Types::Bool + attribute? :prefer_large_media, Types::Bool + attribute? :show_above_text, Types::Bool + end + end + end +end diff --git a/lib/telegram/bot/types/maybe_inaccessible_message.rb b/lib/telegram/bot/types/maybe_inaccessible_message.rb new file mode 100644 index 00000000..3380b0d2 --- /dev/null +++ b/lib/telegram/bot/types/maybe_inaccessible_message.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + MaybeInaccessibleMessage = ( # rubocop:disable Naming/ConstantName + Message | + InaccessibleMessage + ) + end + end +end diff --git a/lib/telegram/bot/types/message.rb b/lib/telegram/bot/types/message.rb index 377f3aa2..8de0349d 100644 --- a/lib/telegram/bot/types/message.rb +++ b/lib/telegram/bot/types/message.rb @@ -10,15 +10,12 @@ class Message < Base attribute? :sender_chat, Chat attribute :date, Types::Integer attribute :chat, Chat - attribute? :forward_from, User - attribute? :forward_from_chat, Chat - attribute? :forward_from_message_id, Types::Integer - attribute? :forward_signature, Types::String - attribute? :forward_sender_name, Types::String - attribute? :forward_date, Types::Integer + attribute? :forward_origin, MessageOrigin attribute? :is_topic_message, Types::True attribute? :is_automatic_forward, Types::True attribute? :reply_to_message, Message + attribute? :external_reply, ExternalReplyInfo + attribute? :quote, TextQuote attribute? :via_bot, User attribute? :edit_date, Types::Integer attribute? :has_protected_content, Types::True @@ -26,6 +23,7 @@ class Message < Base attribute? :author_signature, Types::String attribute? :text, Types::String attribute? :entities, Types::Array.of(MessageEntity) + attribute? :link_preview_options, LinkPreviewOptions attribute? :animation, Animation attribute? :audio, Audio attribute? :document, Document @@ -55,10 +53,10 @@ class Message < Base attribute? :message_auto_delete_timer_changed, MessageAutoDeleteTimerChanged attribute? :migrate_to_chat_id, Types::Integer attribute? :migrate_from_chat_id, Types::Integer - attribute? :pinned_message, Message + attribute? :pinned_message, MaybeInaccessibleMessage attribute? :invoice, Invoice attribute? :successful_payment, SuccessfulPayment - attribute? :user_shared, UserShared + attribute? :users_shared, UsersShared attribute? :chat_shared, ChatShared attribute? :connected_website, Types::String attribute? :write_access_allowed, WriteAccessAllowed @@ -70,6 +68,10 @@ class Message < Base attribute? :forum_topic_reopened, ForumTopicReopened attribute? :general_forum_topic_hidden, GeneralForumTopicHidden attribute? :general_forum_topic_unhidden, GeneralForumTopicUnhidden + attribute? :giveaway_created, GiveawayCreated + attribute? :giveaway, Giveaway + attribute? :giveaway_winners, GiveawayWinners + attribute? :giveaway_completed, GiveawayCompleted attribute? :video_chat_scheduled, VideoChatScheduled attribute? :video_chat_started, VideoChatStarted attribute? :video_chat_ended, VideoChatEnded diff --git a/lib/telegram/bot/types/message_origin.rb b/lib/telegram/bot/types/message_origin.rb new file mode 100644 index 00000000..a3a89137 --- /dev/null +++ b/lib/telegram/bot/types/message_origin.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + MessageOrigin = ( # rubocop:disable Naming/ConstantName + MessageOriginUser | + MessageOriginHiddenUser | + MessageOriginChat | + MessageOriginChannel + ) + end + end +end diff --git a/lib/telegram/bot/types/message_origin_channel.rb b/lib/telegram/bot/types/message_origin_channel.rb new file mode 100644 index 00000000..a4935b5f --- /dev/null +++ b/lib/telegram/bot/types/message_origin_channel.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class MessageOriginChannel < Base + attribute :type, Types::String.constrained(eql: 'channel').default('channel') + attribute :date, Types::Integer + attribute :chat, Chat + attribute :message_id, Types::Integer + attribute? :author_signature, Types::String + end + end + end +end diff --git a/lib/telegram/bot/types/message_origin_chat.rb b/lib/telegram/bot/types/message_origin_chat.rb new file mode 100644 index 00000000..9406f9b4 --- /dev/null +++ b/lib/telegram/bot/types/message_origin_chat.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class MessageOriginChat < Base + attribute :type, Types::String.constrained(eql: 'chat').default('chat') + attribute :date, Types::Integer + attribute :sender_chat, Chat + attribute? :author_signature, Types::String + end + end + end +end diff --git a/lib/telegram/bot/types/message_origin_hidden_user.rb b/lib/telegram/bot/types/message_origin_hidden_user.rb new file mode 100644 index 00000000..4323ab57 --- /dev/null +++ b/lib/telegram/bot/types/message_origin_hidden_user.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class MessageOriginHiddenUser < Base + attribute :type, Types::String.constrained(eql: 'hidden_user').default('hidden_user') + attribute :date, Types::Integer + attribute :sender_user_name, Types::String + end + end + end +end diff --git a/lib/telegram/bot/types/message_origin_user.rb b/lib/telegram/bot/types/message_origin_user.rb new file mode 100644 index 00000000..9ca9eda4 --- /dev/null +++ b/lib/telegram/bot/types/message_origin_user.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class MessageOriginUser < Base + attribute :type, Types::String.constrained(eql: 'user').default('user') + attribute :date, Types::Integer + attribute :sender_user, User + end + end + end +end diff --git a/lib/telegram/bot/types/message_reaction_count_updated.rb b/lib/telegram/bot/types/message_reaction_count_updated.rb new file mode 100644 index 00000000..1b66ec17 --- /dev/null +++ b/lib/telegram/bot/types/message_reaction_count_updated.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class MessageReactionCountUpdated < Base + attribute :chat, Chat + attribute :message_id, Types::Integer + attribute :date, Types::Integer + attribute :reactions, Types::Array.of(ReactionCount) + end + end + end +end diff --git a/lib/telegram/bot/types/message_reaction_updated.rb b/lib/telegram/bot/types/message_reaction_updated.rb new file mode 100644 index 00000000..ba77a055 --- /dev/null +++ b/lib/telegram/bot/types/message_reaction_updated.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class MessageReactionUpdated < Base + attribute :chat, Chat + attribute :message_id, Types::Integer + attribute? :user, User + attribute? :actor_chat, Chat + attribute :date, Types::Integer + attribute :old_reaction, Types::Array.of(ReactionType) + attribute :new_reaction, Types::Array.of(ReactionType) + end + end + end +end diff --git a/lib/telegram/bot/types/reaction_count.rb b/lib/telegram/bot/types/reaction_count.rb new file mode 100644 index 00000000..a0ac284a --- /dev/null +++ b/lib/telegram/bot/types/reaction_count.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class ReactionCount < Base + attribute :type, ReactionType + attribute :total_count, Types::Integer + end + end + end +end diff --git a/lib/telegram/bot/types/reaction_type.rb b/lib/telegram/bot/types/reaction_type.rb new file mode 100644 index 00000000..50203e5a --- /dev/null +++ b/lib/telegram/bot/types/reaction_type.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + ReactionType = ( # rubocop:disable Naming/ConstantName + ReactionTypeEmoji | + ReactionTypeCustomEmoji + ) + end + end +end diff --git a/lib/telegram/bot/types/reaction_type_custom_emoji.rb b/lib/telegram/bot/types/reaction_type_custom_emoji.rb new file mode 100644 index 00000000..24a4114c --- /dev/null +++ b/lib/telegram/bot/types/reaction_type_custom_emoji.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class ReactionTypeCustomEmoji < Base + attribute :type, Types::String.constrained(eql: 'custom_emoji').default('custom_emoji') + attribute :custom_emoji_id, Types::String + end + end + end +end diff --git a/lib/telegram/bot/types/reaction_type_emoji.rb b/lib/telegram/bot/types/reaction_type_emoji.rb new file mode 100644 index 00000000..a3f0563a --- /dev/null +++ b/lib/telegram/bot/types/reaction_type_emoji.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class ReactionTypeEmoji < Base + attribute :type, Types::String.constrained(eql: 'emoji').default('emoji') + attribute :emoji, Types::String + end + end + end +end diff --git a/lib/telegram/bot/types/reply_parameters.rb b/lib/telegram/bot/types/reply_parameters.rb new file mode 100644 index 00000000..76057450 --- /dev/null +++ b/lib/telegram/bot/types/reply_parameters.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class ReplyParameters < Base + attribute :message_id, Types::Integer + attribute? :chat_id, Types::Integer | Types::String + attribute? :allow_sending_without_reply, Types::Bool + attribute? :quote, Types::String + attribute? :quote_parse_mode, Types::String + attribute? :quote_entities, Types::Array.of(MessageEntity) + attribute? :quote_position, Types::Integer + end + end + end +end diff --git a/lib/telegram/bot/types/text_quote.rb b/lib/telegram/bot/types/text_quote.rb new file mode 100644 index 00000000..0dbe83e5 --- /dev/null +++ b/lib/telegram/bot/types/text_quote.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class TextQuote < Base + attribute :text, Types::String + attribute? :entities, Types::Array.of(MessageEntity) + attribute :position, Types::Integer + attribute? :is_manual, Types::True + end + end + end +end diff --git a/lib/telegram/bot/types/update.rb b/lib/telegram/bot/types/update.rb index 81a27525..3b8cf453 100644 --- a/lib/telegram/bot/types/update.rb +++ b/lib/telegram/bot/types/update.rb @@ -9,6 +9,8 @@ class Update < Base attribute? :edited_message, Message attribute? :channel_post, Message attribute? :edited_channel_post, Message + attribute? :message_reaction, MessageReactionUpdated + attribute? :message_reaction_count, MessageReactionCountUpdated attribute? :inline_query, InlineQuery attribute? :chosen_inline_result, ChosenInlineResult attribute? :callback_query, CallbackQuery @@ -19,6 +21,8 @@ class Update < Base attribute? :my_chat_member, ChatMemberUpdated attribute? :chat_member, ChatMemberUpdated attribute? :chat_join_request, ChatJoinRequest + attribute? :chat_boost, ChatBoostUpdated + attribute? :removed_chat_boost, ChatBoostRemoved def current_message @current_message ||= diff --git a/lib/telegram/bot/types/user_chat_boosts.rb b/lib/telegram/bot/types/user_chat_boosts.rb new file mode 100644 index 00000000..a88ec30b --- /dev/null +++ b/lib/telegram/bot/types/user_chat_boosts.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Telegram + module Bot + module Types + class UserChatBoosts < Base + attribute :boosts, Types::Array.of(ChatBoost) + end + end + end +end diff --git a/lib/telegram/bot/types/user_shared.rb b/lib/telegram/bot/types/users_shared.rb similarity index 62% rename from lib/telegram/bot/types/user_shared.rb rename to lib/telegram/bot/types/users_shared.rb index 92940d79..59d686e9 100644 --- a/lib/telegram/bot/types/user_shared.rb +++ b/lib/telegram/bot/types/users_shared.rb @@ -3,9 +3,9 @@ module Telegram module Bot module Types - class UserShared < Base + class UsersShared < Base attribute :request_id, Types::Integer - attribute :user_id, Types::Integer + attribute :user_ids, Types::Array.of(Types::Integer) end end end diff --git a/spec/support/type_attributes.yml b/spec/support/type_attributes.yml index 0eb523ab..b6436220 100644 --- a/spec/support/type_attributes.yml +++ b/spec/support/type_attributes.yml @@ -9,6 +9,28 @@ ShippingOption: - name: prices type: Array of LabeledPrice required: true +ReplyParameters: +- name: message_id + type: Integer + required: true +- name: chat_id + type: Integer or String + required: false +- name: allow_sending_without_reply + type: Boolean + required: false +- name: quote + type: String + required: false +- name: quote_parse_mode + type: String + required: false +- name: quote_entities + type: Array of MessageEntity + required: false +- name: quote_position + type: Integer + required: false ReplyKeyboardRemove: - name: remove_keyboard type: 'True' @@ -193,7 +215,7 @@ KeyboardButtonRequestChat: - name: bot_is_member type: Boolean required: false -KeyboardButtonRequestUser: +KeyboardButtonRequestUsers: - name: request_id type: Integer required: true @@ -203,12 +225,15 @@ KeyboardButtonRequestUser: - name: user_is_premium type: Boolean required: false +- name: max_quantity + type: Integer + required: false KeyboardButton: - name: text type: String required: true -- name: request_user - type: KeyboardButtonRequestUser +- name: request_users + type: KeyboardButtonRequestUsers required: false - name: request_chat type: KeyboardButtonRequestChat @@ -260,8 +285,8 @@ InputTextMessageContent: - name: entities type: Array of MessageEntity required: false -- name: disable_web_page_preview - type: Boolean +- name: link_preview_options + type: LinkPreviewOptions required: false InputMediaVideo: - name: type @@ -1270,18 +1295,6 @@ BotDescription: type: String required: true BotName: -- name: name - type: String - required: true -BotShortDescription: -- name: short_description - type: String - required: true -BotDescription: -- name: description - type: String - required: true -BotName: - name: name type: String required: true @@ -1356,10 +1369,6 @@ SentWebAppMessage: - name: inline_message_id type: String required: false -MessageId: -- name: message_id - type: Integer - required: true BotCommand: - name: command type: String @@ -1399,6 +1408,10 @@ StickerSet: - name: thumbnail type: PhotoSize required: false +UserChatBoosts: +- name: boosts + type: Array of ChatBoost + required: true UserProfilePhotos: - name: total_count type: Integer @@ -1406,6 +1419,10 @@ UserProfilePhotos: - name: photos type: Array of Array of PhotoSize required: true +MessageId: +- name: message_id + type: Integer + required: true WebhookInfo: - name: url type: String @@ -1434,6 +1451,69 @@ WebhookInfo: - name: allowed_updates type: Array of String required: false +ChatBoostRemoved: +- name: chat + type: Chat + required: true +- name: boost_id + type: String + required: true +- name: remove_date + type: Integer + required: true +- name: source + type: ChatBoostSource + required: true +ChatBoostSourceGiveaway: +- name: source + type: String + required: true + required_value: giveaway +- name: giveaway_message_id + type: Integer + required: true +- name: user + type: User + required: false +- name: is_unclaimed + type: 'True' + required: false +ChatBoostSourceGiftCode: +- name: source + type: String + required: true + required_value: gift_code +- name: user + type: User + required: true +ChatBoostSourcePremium: +- name: source + type: String + required: true + required_value: premium +- name: user + type: User + required: true +ChatBoost: +- name: boost_id + type: String + required: true +- name: add_date + type: Integer + required: true +- name: expiration_date + type: Integer + required: true +- name: source + type: ChatBoostSource + required: true +ChatBoostUpdated: +- name: chat + type: Chat + required: true +- name: boost + type: ChatBoost + required: true ChatJoinRequest: - name: chat type: Chat @@ -1715,7 +1795,7 @@ CallbackQuery: type: User required: true - name: message - type: Message + type: MaybeInaccessibleMessage required: false - name: inline_message_id type: String @@ -1764,6 +1844,48 @@ InlineQuery: - name: location type: Location required: false +ReactionCount: +- name: type + type: ReactionType + required: true +- name: total_count + type: Integer + required: true +MessageReactionCountUpdated: +- name: chat + type: Chat + required: true +- name: message_id + type: Integer + required: true +- name: date + type: Integer + required: true +- name: reactions + type: Array of ReactionCount + required: true +MessageReactionUpdated: +- name: chat + type: Chat + required: true +- name: message_id + type: Integer + required: true +- name: user + type: User + required: false +- name: actor_chat + type: Chat + required: false +- name: date + type: Integer + required: true +- name: old_reaction + type: Array of ReactionType + required: true +- name: new_reaction + type: Array of ReactionType + required: true CallbackGame: [] SwitchInlineQueryChosenChat: - name: query @@ -1853,6 +1975,17 @@ VideoChatScheduled: - name: start_date type: Integer required: true +GiveawayCompleted: +- name: winner_count + type: Integer + required: true +- name: unclaimed_prize_count + type: Integer + required: false +- name: giveaway_message + type: Message + required: false +GiveawayCreated: [] GeneralForumTopicUnhidden: [] GeneralForumTopicHidden: [] ForumTopicReopened: [] @@ -1962,12 +2095,12 @@ ChatShared: - name: chat_id type: Integer required: true -UserShared: +UsersShared: - name: request_id type: Integer required: true -- name: user_id - type: Integer +- name: user_ids + type: Array of Integer required: true ShippingAddress: - name: country_code @@ -2023,26 +2156,33 @@ SuccessfulPayment: - name: provider_payment_charge_id type: String required: true -Invoice: -- name: title - type: String - required: true -- name: description - type: String - required: true -- name: start_parameter - type: String +InaccessibleMessage: +- name: chat + type: Chat required: true -- name: currency - type: String +- name: message_id + type: Integer required: true -- name: total_amount +- name: date type: Integer required: true MessageAutoDeleteTimerChanged: - name: message_auto_delete_time type: Integer required: true +TextQuote: +- name: text + type: String + required: true +- name: entities + type: Array of MessageEntity + required: false +- name: position + type: Integer + required: true +- name: is_manual + type: 'True' + required: false Venue: - name: location type: Location @@ -2112,6 +2252,103 @@ Poll: - name: close_date type: Integer required: false +Invoice: +- name: title + type: String + required: true +- name: description + type: String + required: true +- name: start_parameter + type: String + required: true +- name: currency + type: String + required: true +- name: total_amount + type: Integer + required: true +GiveawayWinners: +- name: chat + type: Chat + required: true +- name: giveaway_message_id + type: Integer + required: true +- name: winners_selection_date + type: Integer + required: true +- name: winner_count + type: Integer + required: true +- name: winners + type: Array of User + required: true +- name: additional_chat_count + type: Integer + required: false +- name: premium_subscription_month_count + type: Integer + required: false +- name: unclaimed_prize_count + type: Integer + required: false +- name: only_new_members + type: 'True' + required: false +- name: was_refunded + type: 'True' + required: false +- name: prize_description + type: String + required: false +Giveaway: +- name: chats + type: Array of Chat + required: true +- name: winners_selection_date + type: Integer + required: true +- name: winner_count + type: Integer + required: true +- name: only_new_members + type: 'True' + required: false +- name: has_public_winners + type: 'True' + required: false +- name: prize_description + type: String + required: false +- name: country_codes + type: Array of String + required: false +- name: premium_subscription_month_count + type: Integer + required: false +MessageEntity: +- name: type + type: String + required: true +- name: offset + type: Integer + required: true +- name: length + type: Integer + required: true +- name: url + type: String + required: false +- name: user + type: User + required: false +- name: language + type: String + required: false +- name: custom_emoji_id + type: String + required: false Game: - name: title type: String @@ -2381,28 +2618,145 @@ Animation: - name: file_size type: Integer required: false -MessageEntity: +LinkPreviewOptions: +- name: is_disabled + type: Boolean + required: false +- name: url + type: String + required: false +- name: prefer_small_media + type: Boolean + required: false +- name: prefer_large_media + type: Boolean + required: false +- name: show_above_text + type: Boolean + required: false +ExternalReplyInfo: +- name: origin + type: MessageOrigin + required: true +- name: chat + type: Chat + required: false +- name: message_id + type: Integer + required: false +- name: link_preview_options + type: LinkPreviewOptions + required: false +- name: animation + type: Animation + required: false +- name: audio + type: Audio + required: false +- name: document + type: Document + required: false +- name: photo + type: Array of PhotoSize + required: false +- name: sticker + type: Sticker + required: false +- name: story + type: Story + required: false +- name: video + type: Video + required: false +- name: video_note + type: VideoNote + required: false +- name: voice + type: Voice + required: false +- name: has_media_spoiler + type: 'True' + required: false +- name: contact + type: Contact + required: false +- name: dice + type: Dice + required: false +- name: game + type: Game + required: false +- name: giveaway + type: Giveaway + required: false +- name: giveaway_winners + type: GiveawayWinners + required: false +- name: invoice + type: Invoice + required: false +- name: location + type: Location + required: false +- name: poll + type: Poll + required: false +- name: venue + type: Venue + required: false +MessageOriginChannel: - name: type type: String required: true -- name: offset + required_value: channel +- name: date type: Integer required: true -- name: length +- name: chat + type: Chat + required: true +- name: message_id type: Integer required: true -- name: url +- name: author_signature type: String required: false -- name: user - type: User - required: false -- name: language +MessageOriginChat: +- name: type type: String - required: false -- name: custom_emoji_id + required: true + required_value: chat +- name: date + type: Integer + required: true +- name: sender_chat + type: Chat + required: true +- name: author_signature type: String required: false +MessageOriginHiddenUser: +- name: type + type: String + required: true + required_value: hidden_user +- name: date + type: Integer + required: true +- name: sender_user_name + type: String + required: true +MessageOriginUser: +- name: type + type: String + required: true + required_value: user +- name: date + type: Integer + required: true +- name: sender_user + type: User + required: true Location: - name: longitude type: Float @@ -2472,6 +2826,22 @@ ChatPermissions: - name: can_manage_topics type: Boolean required: false +ReactionTypeCustomEmoji: +- name: type + type: String + required: true + required_value: custom_emoji +- name: custom_emoji_id + type: String + required: true +ReactionTypeEmoji: +- name: type + type: String + required: true + required_value: emoji +- name: emoji + type: String + required: true ChatPhoto: - name: small_file_id type: String @@ -2513,6 +2883,21 @@ Chat: - name: active_usernames type: Array of String required: false +- name: available_reactions + type: Array of ReactionType + required: false +- name: accent_color_id + type: Integer + required: false +- name: background_custom_emoji_id + type: String + required: false +- name: profile_accent_color_id + type: Integer + required: false +- name: profile_background_custom_emoji_id + type: String + required: false - name: emoji_status_custom_emoji_id type: String required: false @@ -2561,6 +2946,9 @@ Chat: - name: has_protected_content type: 'True' required: false +- name: has_visible_history + type: 'True' + required: false - name: sticker_set_name type: String required: false @@ -2626,23 +3014,8 @@ Message: - name: chat type: Chat required: true -- name: forward_from - type: User - required: false -- name: forward_from_chat - type: Chat - required: false -- name: forward_from_message_id - type: Integer - required: false -- name: forward_signature - type: String - required: false -- name: forward_sender_name - type: String - required: false -- name: forward_date - type: Integer +- name: forward_origin + type: MessageOrigin required: false - name: is_topic_message type: 'True' @@ -2653,6 +3026,12 @@ Message: - name: reply_to_message type: Message required: false +- name: external_reply + type: ExternalReplyInfo + required: false +- name: quote + type: TextQuote + required: false - name: via_bot type: User required: false @@ -2674,6 +3053,9 @@ Message: - name: entities type: Array of MessageEntity required: false +- name: link_preview_options + type: LinkPreviewOptions + required: false - name: animation type: Animation required: false @@ -2762,7 +3144,7 @@ Message: type: Integer required: false - name: pinned_message - type: Message + type: MaybeInaccessibleMessage required: false - name: invoice type: Invoice @@ -2770,8 +3152,8 @@ Message: - name: successful_payment type: SuccessfulPayment required: false -- name: user_shared - type: UserShared +- name: users_shared + type: UsersShared required: false - name: chat_shared type: ChatShared @@ -2806,6 +3188,18 @@ Message: - name: general_forum_topic_unhidden type: GeneralForumTopicUnhidden required: false +- name: giveaway_created + type: GiveawayCreated + required: false +- name: giveaway + type: Giveaway + required: false +- name: giveaway_winners + type: GiveawayWinners + required: false +- name: giveaway_completed + type: GiveawayCompleted + required: false - name: video_chat_scheduled type: VideoChatScheduled required: false @@ -2840,6 +3234,12 @@ Update: - name: edited_channel_post type: Message required: false +- name: message_reaction + type: MessageReactionUpdated + required: false +- name: message_reaction_count + type: MessageReactionCountUpdated + required: false - name: inline_query type: InlineQuery required: false @@ -2870,3 +3270,9 @@ Update: - name: chat_join_request type: ChatJoinRequest required: false +- name: chat_boost + type: ChatBoostUpdated + required: false +- name: removed_chat_boost + type: ChatBoostRemoved + required: false From 2b4399097cb63f0bffc622b4564759d1974bb926 Mon Sep 17 00:00:00 2001 From: Alexander Tipugin Date: Thu, 11 Jan 2024 18:53:23 +0300 Subject: [PATCH 2/3] feat: add constraints/defaults for `max_quantity` --- lib/telegram/bot/types/keyboard_button_request_users.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/telegram/bot/types/keyboard_button_request_users.rb b/lib/telegram/bot/types/keyboard_button_request_users.rb index 49ec5ed3..90b11d54 100644 --- a/lib/telegram/bot/types/keyboard_button_request_users.rb +++ b/lib/telegram/bot/types/keyboard_button_request_users.rb @@ -7,7 +7,7 @@ class KeyboardButtonRequestUsers < Base attribute :request_id, Types::Integer attribute? :user_is_bot, Types::Bool attribute? :user_is_premium, Types::Bool - attribute? :max_quantity, Types::Integer + attribute? :max_quantity, Types::Integer.constrained(gteq: 1, lteq: 10).default(1) end end end From 36efcb4ea7328e0ab7e9c99e3d1a16df4045324b Mon Sep 17 00:00:00 2001 From: Alexander Tipugin Date: Thu, 11 Jan 2024 19:16:59 +0300 Subject: [PATCH 3/3] test: fix spec by removing `max_quantity` constraints (for now) --- lib/telegram/bot/types/keyboard_button_request_users.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/telegram/bot/types/keyboard_button_request_users.rb b/lib/telegram/bot/types/keyboard_button_request_users.rb index 90b11d54..3b950358 100644 --- a/lib/telegram/bot/types/keyboard_button_request_users.rb +++ b/lib/telegram/bot/types/keyboard_button_request_users.rb @@ -7,7 +7,7 @@ class KeyboardButtonRequestUsers < Base attribute :request_id, Types::Integer attribute? :user_is_bot, Types::Bool attribute? :user_is_premium, Types::Bool - attribute? :max_quantity, Types::Integer.constrained(gteq: 1, lteq: 10).default(1) + attribute? :max_quantity, Types::Integer.default(1) end end end