Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot api 7.0 #229

Merged
merged 1 commit into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased

- Update to Bot API 7.0
- Add `# frozen_string_literal: true` to all source files.

# 0.16.1
Expand Down
7 changes: 6 additions & 1 deletion lib/telegram/bot/client/api_methods.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Generated with bin/fetch-telegram-methods
# Bot API 6.8
# Bot API 7.0

getUpdates
setWebhook
Expand All @@ -11,7 +11,9 @@ logOut
close
sendMessage
forwardMessage
forwardMessages
copyMessage
copyMessages
sendPhoto
sendAudio
sendDocument
Expand All @@ -26,6 +28,7 @@ sendContact
sendPoll
sendDice
sendChatAction
setMessageReaction
getUserProfilePhotos
getFile
banChatMember
Expand Down Expand Up @@ -70,6 +73,7 @@ hideGeneralForumTopic
unhideGeneralForumTopic
unpinAllGeneralForumTopicMessages
answerCallbackQuery
getUserChatBoosts
setMyCommands
deleteMyCommands
getMyCommands
Expand All @@ -92,6 +96,7 @@ stopMessageLiveLocation
editMessageReplyMarkup
stopPoll
deleteMessage
deleteMessages

sendSticker
getStickerSet
Expand Down
33 changes: 28 additions & 5 deletions lib/telegram/bot/updates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ class UpdatesController < AbstractController::Base # rubocop:disable Metrics/Cla

extend Session::ConfigMethods

PAYLOAD_TYPES = %w[
PAYLOAD_TYPES = Set.new(%w[
message
edited_message
channel_post
edited_channel_post
message_reaction
message_reaction_count
inline_query
chosen_inline_result
callback_query
Expand All @@ -104,7 +106,9 @@ class UpdatesController < AbstractController::Base # rubocop:disable Metrics/Cla
my_chat_member
chat_member
chat_join_request
].freeze
chat_boost
removed_chat_boost
].freeze)

class << self
# Initialize controller and process update.
Expand All @@ -113,9 +117,28 @@ def dispatch(*args)
end

def payload_from_update(update)
update && PAYLOAD_TYPES.find do |type|
item = update[type]
return [item, type] if item
case update
when nil then nil
when Hash
# faster lookup for the case when telegram-bot-types is not used
update.find do |type, item|
return [item, type] if PAYLOAD_TYPES.include?(type)
end
else
payload_from_typed_update(update)
end
end

private

def payload_from_typed_update(update)
PAYLOAD_TYPES.find do |type|
begin
item = update[type]
return [item, type] if item
rescue Exception # rubocop:disable Lint/RescueException
# dry-rb raises exception if field is not defined in schema
end
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions spec/telegram/bot/updates_controller/typed_update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
my_chat_member
chat_member
chat_join_request

# TODO: remove when added to telegram-bot-types
message_reaction
message_reaction_count
chat_boost
removed_chat_boost
]).
map { |x| [x, Telegram::Bot::Types.const_get(x.camelize)] }.to_h.
merge(
Expand Down