Skip to content
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
Expand Up @@ -2,6 +2,7 @@

- Rails 8.1 support
- Drop support for rails < 7.0 and ruby < 2.7
- Update to Bot API 9.5

# 0.16.7

Expand Down
45 changes: 38 additions & 7 deletions 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 8.2
# Bot API 9.5

getUpdates
setWebhook
Expand Down Expand Up @@ -27,17 +27,21 @@ sendLocation
sendVenue
sendContact
sendPoll
sendChecklist
sendDice
sendMessageDraft
sendChatAction
setMessageReaction
getUserProfilePhotos
getUserProfileAudios
setUserEmojiStatus
getFile
banChatMember
unbanChatMember
restrictChatMember
promoteChatMember
setChatAdministratorCustomTitle
setChatMemberTag
banChatSenderChat
unbanChatSenderChat
setChatPermissions
Expand Down Expand Up @@ -88,18 +92,50 @@ setMyDescription
getMyDescription
setMyShortDescription
getMyShortDescription
setMyProfilePhoto
removeMyProfilePhoto
setChatMenuButton
getChatMenuButton
setMyDefaultAdministratorRights
getMyDefaultAdministratorRights
getAvailableGifts
sendGift
giftPremiumSubscription
verifyUser
verifyChat
removeUserVerification
removeChatVerification
readBusinessMessage
deleteBusinessMessages
setBusinessAccountName
setBusinessAccountUsername
setBusinessAccountBio
setBusinessAccountProfilePhoto
removeBusinessAccountProfilePhoto
setBusinessAccountGiftSettings
getBusinessAccountStarBalance
transferBusinessAccountStars
getBusinessAccountGifts
getUserGifts
getChatGifts
convertGiftToStars
upgradeGift
transferGift
postStory
repostStory
editStory
deleteStory

editMessageText
editMessageCaption
editMessageMedia
editMessageLiveLocation
stopMessageLiveLocation
editMessageChecklist
editMessageReplyMarkup
stopPoll
approveSuggestedPost
declineSuggestedPost
deleteMessage
deleteMessages

Expand All @@ -119,12 +155,6 @@ setStickerSetTitle
setStickerSetThumbnail
setCustomEmojiStickerSetThumbnail
deleteStickerSet
getAvailableGifts
sendGift
verifyUser
verifyChat
removeUserVerification
removeChatVerification

answerInlineQuery
answerWebAppQuery
Expand All @@ -134,6 +164,7 @@ sendInvoice
createInvoiceLink
answerShippingQuery
answerPreCheckoutQuery
getMyStarBalance
getStarTransactions
refundStarPayment
editUserStarSubscription
Expand Down
15 changes: 11 additions & 4 deletions lib/telegram/bot/client/request_body_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ def format(body, action)
when 'sendMediaGroup'
extract_files_from_array!(body, :media)
when 'editMessageMedia'
replace_field(body, :media) do |value|
files = {}
extract_files_from_hash(value, files).tap { body.merge!(files) }
end
extract_files_from_field!(body, :media)
when 'postStory'
extract_files_from_field!(body, :content)
end
body.each do |key, val|
body[key] = val.to_json if val.is_a?(Hash) || val.is_a?(Array)
Expand All @@ -29,6 +28,14 @@ def format(body, action)

private

# Extracts files from the given field and merges them into the body.
def extract_files_from_field!(body, field_name)
replace_field(body, field_name) do |value|
files = {}
extract_files_from_hash(value, files).tap { body.merge!(files) }
end
end

# Detects field by symbol or string name and replaces it with mapped value.
def replace_field(hash, field_name)
field_name = [field_name.to_sym, field_name.to_s].find { |x| hash.key?(x) }
Expand Down
1 change: 1 addition & 0 deletions lib/telegram/bot/updates_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'logger'
require 'abstract_controller'
require 'active_support/core_ext/string/inflections'
require 'active_support/callbacks'
Expand Down
2 changes: 1 addition & 1 deletion lib/telegram/bot/updates_controller/payload_types.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Generated with bin/fetch-telegram-methods
# Bot API 8.2
# Bot API 9.5
message
edited_message
channel_post
Expand Down
2 changes: 1 addition & 1 deletion lib/telegram/bot/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Telegram
module Bot
VERSION = '0.16.7'
VERSION = '0.16.9'

def self.gem_version
Gem::Version.new VERSION
Expand Down
30 changes: 30 additions & 0 deletions spec/telegram/bot/client/request_body_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,35 @@
it { should eq input }
end
end

context 'with postStory action' do
let(:action) { :postStory }
let(:input) { {content: {a: file, b: 123}, x: 789} }
let(:file) { File.new(__FILE__) }

it 'extracts files to the top-level' do
should eq(
content: {a: 'attach://_file0', b: 123}.to_json,
x: 789,
'_file0' => file,
)
end

context 'and input has string keys' do
let(:input) { super().stringify_keys }
it 'extracts files to the top-level' do
should eq(
'content' => {a: 'attach://_file0', b: 123}.to_json,
'x' => 789,
'_file0' => file,
)
end
end

context 'without content' do
let(:input) { {a: 1, b: '2', c: nil} }
it { should eq input }
end
end
end
end
Loading