Skip to content

Commit

Permalink
Implement Bot API 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
seorgiy committed Nov 24, 2024
1 parent 3c431f5 commit 413efbc
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 5 deletions.
7 changes: 6 additions & 1 deletion lib/telegram/bot/api/endpoints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ class Api
'getStarTransactions' => Types::StarTransactions,
'sendPaidMedia' => Types::Message,
'createChatSubscriptionInviteLink' => Types::ChatInviteLink,
'editChatSubscriptionInviteLink' => Types::ChatInviteLink
'editChatSubscriptionInviteLink' => Types::ChatInviteLink,
'getAvailableGifts' => Types::Gifts,
'sendGift' => Types::Bool,
'savePreparedInlineMessage' => Types::PreparedInlineMessage,
'editUserStarSubscription' => Types::Bool,
'setUserEmojiStatus' => Types::Bool
}.freeze
end
end
Expand Down
15 changes: 15 additions & 0 deletions lib/telegram/bot/types/gift.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 Gift < Base
attribute :id, Types::String
attribute :sticker, Sticker
attribute :star_count, Types::Integer
attribute? :total_count, Types::Integer
attribute? :remaining_count, Types::Integer
end
end
end
end
11 changes: 11 additions & 0 deletions lib/telegram/bot/types/gifts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module Telegram
module Bot
module Types
class Gifts < Base
attribute :gifts, Types::Array.of(Gift)
end
end
end
end
12 changes: 12 additions & 0 deletions lib/telegram/bot/types/prepared_inline_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
class PreparedInlineMessage < Base
attribute :id, Types::String
attribute :expiration_date, Types::Integer
end
end
end
end
3 changes: 3 additions & 0 deletions lib/telegram/bot/types/successful_payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class SuccessfulPayment < Base
attribute :currency, Types::String
attribute :total_amount, Types::Integer
attribute :invoice_payload, Types::String
attribute? :subscription_expiration_date, Types::Integer
attribute? :is_recurring, Types::True
attribute? :is_first_recurring, Types::True
attribute? :shipping_option_id, Types::String
attribute? :order_info, OrderInfo
attribute :telegram_payment_charge_id, Types::String
Expand Down
2 changes: 2 additions & 0 deletions lib/telegram/bot/types/transaction_partner_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ class TransactionPartnerUser < Base
attribute :type, Types::String.constrained(eql: 'user').default('user')
attribute :user, User
attribute? :invoice_payload, Types::String
attribute? :subscription_period, Types::Integer
attribute? :paid_media, Types::Array.of(PaidMedia)
attribute? :paid_media_payload, Types::String
attribute? :gift, Gift
end
end
end
Expand Down
5 changes: 2 additions & 3 deletions rakelib/parse_schema.rake
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require 'openapi3_parser'
DRY_TYPES = %w[string integer float decimal array hash symbol boolean date date_time time range].freeze

desc 'Parse types from public json, should be up to date https://github.com/ark0f/tg-bot-api'
task :parse_schema do
Expand Down Expand Up @@ -41,7 +40,7 @@ task :parse_schema do
attribute[:items] = { type: 'array', items: property_schema.items.items.name }
end

attribute = apply_default(attribute, property_schema)
attribute = apply_default_schema(attribute, property_schema)
[property_name, attribute]
end

Expand All @@ -58,7 +57,7 @@ def required_keys(schema)
schema.required.to_a || []
end

def apply_default(attribute, property_schema)
def apply_default_schema(attribute, property_schema)
attribute[:default] = property_schema.default unless property_schema.default.nil?
# previous line would have been enough, but had to check the description due to issue: https://github.com/kevindew/openapi3_parser/issues/28
attribute[:default] = false if property_schema.description&.include?('Defaults to *false*')
Expand Down
3 changes: 2 additions & 1 deletion rakelib/rebuild_types.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'json'
require 'erb'
DRY_TYPES = %w[string integer float decimal array hash symbol boolean date date_time time range].freeze

desc 'Rebuild types'
task :rebuild_types do
Expand All @@ -10,7 +11,7 @@ task :rebuild_types do
types.each_pair do |name, attributes|
next build_empty_type(name, attributes) if attributes[:type].instance_of?(Array)

attributes.except(:inherited_from).each_pair do |attr_name, properties|
attributes.each_pair do |attr_name, properties|
attributes[attr_name][:type] = add_module_types(properties[:type]) unless properties[:type].is_a?(Array)
if properties[:type].is_a?(Array)
attributes[attr_name][:type] = properties[:type].map do |type|
Expand Down
54 changes: 54 additions & 0 deletions utility/type_attributes.json
Original file line number Diff line number Diff line change
Expand Up @@ -3313,6 +3313,33 @@
"items": "string"
}
},
"Gift": {
"id": {
"type": "string",
"required": true
},
"sticker": {
"type": "Sticker",
"required": true
},
"star_count": {
"type": "integer",
"required": true
},
"total_count": {
"type": "integer"
},
"remaining_count": {
"type": "integer"
}
},
"Gifts": {
"gifts": {
"type": "array",
"required": true,
"items": "Gift"
}
},
"InlineQuery": {
"id": {
"type": "string",
Expand Down Expand Up @@ -4431,6 +4458,16 @@
"type": "string"
}
},
"PreparedInlineMessage": {
"id": {
"type": "string",
"required": true
},
"expiration_date": {
"type": "integer",
"required": true
}
},
"LabeledPrice": {
"label": {
"type": "string",
Expand Down Expand Up @@ -4531,6 +4568,17 @@
"type": "string",
"required": true
},
"subscription_expiration_date": {
"type": "integer"
},
"is_recurring": {
"type": "boolean",
"default": true
},
"is_first_recurring": {
"type": "boolean",
"default": true
},
"shipping_option_id": {
"type": "string"
},
Expand Down Expand Up @@ -4687,12 +4735,18 @@
"invoice_payload": {
"type": "string"
},
"subscription_period": {
"type": "integer"
},
"paid_media": {
"type": "array",
"items": "PaidMedia"
},
"paid_media_payload": {
"type": "string"
},
"gift": {
"type": "Gift"
}
},
"TransactionPartnerFragment": {
Expand Down

0 comments on commit 413efbc

Please sign in to comment.