Skip to content

Commit

Permalink
feat: implement Bot API 7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
atipugin committed Jan 10, 2024
1 parent f47aa75 commit 6b286cd
Show file tree
Hide file tree
Showing 40 changed files with 922 additions and 81 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ Gemfile.lock
.bundle/
.env
pkg/
tmp/
vendor/bundle/
5 changes: 5 additions & 0 deletions lib/telegram/bot/api/endpoints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/telegram/bot/types/callback_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions lib/telegram/bot/types/chat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions lib/telegram/bot/types/chat_boost.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions lib/telegram/bot/types/chat_boost_removed.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions lib/telegram/bot/types/chat_boost_source.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions lib/telegram/bot/types/chat_boost_source_gift_code.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions lib/telegram/bot/types/chat_boost_source_giveaway.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions lib/telegram/bot/types/chat_boost_source_premium.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions lib/telegram/bot/types/chat_boost_updated.rb
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions lib/telegram/bot/types/external_reply_info.rb
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions lib/telegram/bot/types/giveaway.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions lib/telegram/bot/types/giveaway_completed.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions lib/telegram/bot/types/giveaway_created.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

module Telegram
module Bot
module Types
class GiveawayCreated < Base
end
end
end
end
21 changes: 21 additions & 0 deletions lib/telegram/bot/types/giveaway_winners.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions lib/telegram/bot/types/inaccessible_message.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lib/telegram/bot/types/input_text_message_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/telegram/bot/types/keyboard_button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions lib/telegram/bot/types/link_preview_options.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions lib/telegram/bot/types/maybe_inaccessible_message.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module Telegram
module Bot
module Types
MaybeInaccessibleMessage = ( # rubocop:disable Naming/ConstantName
Message |
InaccessibleMessage
)
end
end
end
18 changes: 10 additions & 8 deletions lib/telegram/bot/types/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,20 @@ 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
attribute? :media_group_id, Types::String
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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit 6b286cd

Please sign in to comment.