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 218 forks source link

Doesn`t work edit_message_media #212

Closed maxutor closed 1 year ago

maxutor commented 4 years ago

I sending photo:

photo = Faraday::UploadIO.new('app/first_image.jpeg', 'image/jpeg') bot.api.send_photo(chat_id: message.chat.id, photo: photo, caption: "Main menu")

and then I`m trying to change that photo:

photo = Telegram::Bot::Types::InputMediaPhoto.new photo.media = Faraday::UploadIO.new('app/images.jpeg', 'image/jpeg') bot.api.edit_message_media( chat_id: message.from.id, message_id: message.message.message_id, media: { type: 'photo', media: photo }.to_json

And that didn`t work I have such error:

Telegram API has returned the error. (ok: "false", error_code: "400", description: "Bad Request: can't parse InputMedia: Can't parse media JSON object") (Telegram::Bot::Exceptions::ResponseError)

I`m doing smth wrong or what?

agent-pikachu commented 4 years ago

Not sure about Faraday::UploadIO, haven't used it. In my case it were URLs and this worked:

media: {
  'type': 'photo',
  'media': '<url>'
}.to_json
maxutor commented 4 years ago

Not sure about Faraday::UploadIO, haven't used it. In my case it were URLs and this worked:

media: {
  'type': 'photo',
  'media': '<url>'
}.to_json

Thank you, but I knew about that option. I'm just looking for a way to do tht without url.

seorgiy commented 3 years ago

Hey from future! I figured out :) The trick is giving one more param named exactly as you set in "attach://" string.

photo = Telegram::Bot::Types::InputMediaPhoto.new
photo.media = "attach://image"
photo.type = 'photo'
photo.caption = 'some text description'
photo.parse_mode = 'html'

bot.api.edit_message_media(
  chat_id: 13213131,
  message_id: 21313131, 
  media: photo.to_json, 
  image: Faraday::UploadIO.new( SomeImageFile, 'image', "image.jpg")
  )
github-actions[bot] commented 1 year ago

This issue 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.