sendMediaGroup in telegram by ruby

Viewed 42

I want to send some photos in one message by my bot in telegram. I use

bot.api.sendMediaGroup(chat_id: message.from.id,
media: [
           {
                type: 'photo', 
                photo: arr_r[z].to_s
           }, 
           {
                type: 'photo', 
                photo: arr_r[z].to_s
            }
    ])

and have an error

Telegram API has returned the error. (ok: "false", error_code: "400", description: "Bad Request: media not found") (Telegram::Bot::Exceptions::ResponseError)

I try to write another code

media_arr = {media: arr_r[z].to_s}
bot.api.sendMediaGroup(chat_id: message.from.id, type: 'photo', media: "#{media_arr}")

and have

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

In bouth variants arr_r = ["", "AgABLABLABLABLABLAlbjJaiYhDuK_m9n4a8_q50WAAKsvDEb-xS4SCfgmSDNS2GZAQADAgADcwADKQQ"]

So now i don't know how to fix it... I'm hope for your help.

1 Answers

So, and now i know good answer

media_arr = [
                 {
                      type: 'photo', #there you cac write your type of your media, like 'video', 'photo', 'audio'
                      media: "BlAblAbLaBlAblAbLaBlAblAbLaBlAblAbLaBlAblAbLaBlAblAbLaBlAblAbLa" # It is uniqie file_id information
                 }, 
                 {
                      type: 'photo',
                      media: 
                      "BlAblAbLaBlAblAbLaBlAblAbLaBlAblAbLaBlAblAbLaBlAblAbLaBlAblAbLa" # It is uniqie file_id information
                  }
              ]

bot.api.sendMediaGroup(chat_id: message.from.id, type: 'photo', media: media_arr) # there you send all your media in one message
Related