atipugin / telegram-bot-ruby

Ruby wrapper for Telegram's Bot API
https://core.telegram.org/bots/api
Do What The F*ck You Want To Public License
1.35k stars 217 forks source link

Add Telegram::Bot::Api#file #269

Closed JuanKman94 closed 1 year ago

JuanKman94 commented 1 year ago

This method can be used to download media after calling #getFile

Usage

# Select second tallest photo
def select_photo_by_height(notification)
  photos = notification.photo.sort_by(&:height)
  photos[-2]
end

client = ::Telegram::Bot::Client.new(ENV["bot_token"])
photo = select_photo_by_height(notification)
resp = client.api.get_file(file_id: photo.file_id)
raise "Invalid response from telegram: #{JSON.dump(resp)}" unless resp["ok"]

data = client.api.file(resp.dig("result", "file_path")) # binary data
github-actions[bot] commented 1 year ago

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

JuanKman94 commented 1 year ago

@atipugin have you had a chance to look at this? IMO the benefit of having this method is we avoid the boilerplate of opening a new HTTP connection to telegram

github-actions[bot] commented 1 year ago

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.