When using SendMediaGroup, I'm getting TelegramApiException: Bad Request: can't parse InputMedia: media not found (whether I use a file_id string or an InputFile with attach://).
Here is an example bot:
import cats.instances.future._
import cats.syntax.functor._
import com.bot4s.telegram.api.RequestHandler
import com.bot4s.telegram.api.declarative.Commands
import com.bot4s.telegram.clients.FutureSttpClient
import com.bot4s.telegram.future.{Polling, TelegramBot}
import com.bot4s.telegram.methods.{SendMediaGroup, SendPhoto}
import com.bot4s.telegram.models.{InputFile, InputMedia, InputMediaPhoto}
import com.softwaremill.sttp._
import com.softwaremill.sttp.okhttp.OkHttpFutureBackend
import slogging.{LogLevel, LoggerConfig, PrintLoggerFactory}
import scala.concurrent.duration.Duration
import scala.concurrent.{Await, Future}
object Test extends App {
val bot = new TelegramBot with Polling with Commands[Future] {
LoggerConfig.factory = PrintLoggerFactory()
LoggerConfig.level = LogLevel.TRACE
implicit val backend: SttpBackend[Future, Nothing] = OkHttpFutureBackend()
override val client: RequestHandler[Future] = new FutureSttpClient("709304299:AAGLZB_awq8eWa1J06V862yGKQF5seAs5Lk")
onCommand("single") { implicit msg =>
request(SendPhoto(msg.source, InputFile("AgACAgIAAxkBAAIBmF5NlVQVb6iPrSZWAonh4PnZm_GMAALtrjEbORhoSkLApyEUFBhoPA1xkS4AAwEAAwIAA3gAA5wVAAIYBA"))).void
}
onCommand("fileid") { implicit msg =>
val array: Array[InputMedia] = Array(
InputMediaPhoto("AgACAgIAAxkBAAIBmF5NlVQVb6iPrSZWAonh4PnZm_GMAALtrjEbORhoSkLApyEUFBhoPA1xkS4AAwEAAwIAA3gAA5wVAAIYBA", None),
InputMediaPhoto("AgACAgIAAxkBAAIBmF5NlVQVb6iPrSZWAonh4PnZm_GMAALtrjEbORhoSkLApyEUFBhoPA1xkS4AAwEAAwIAA3gAA5wVAAIYBA", None)
)
request(SendMediaGroup(msg.source, array)).void
}
onCommand("attach") { implicit msg =>
val file: Future[Array[Byte]] = sttp.get(uri"https://raw.githubusercontent.com/bot4s/telegram/master/logo.png").response(ResponseAsByteArray).send().map(_.unsafeBody)
val media: Future[Array[InputMedia]] = file.map(content =>
Array(
InputMediaPhoto("attach://file_attach", Some(InputFile("name1", content))),
InputMediaPhoto("attach://file_attach_name", Some(InputFile("name2", content)))
)
)
media.flatMap(array => request(SendMediaGroup(msg.source, array))).void
}
onCommand("attach2") { implicit msg =>
// this example (attach AND fileid) isnt correct according to the bot api, I tried it anyway:
// or pass “attach://<file_attach_name>” to upload a new one using multipart/form-data under <file_attach_name> name
val array: Array[InputMedia] = Array(
InputMediaPhoto("attach://file_attach", Some(InputFile("AgACAgIAAxkBAAIBmF5NlVQVb6iPrSZWAonh4PnZm_GMAALtrjEbORhoSkLApyEUFBhoPA1xkS4AAwEAAwIAA3gAA5wVAAIYBA"))),
InputMediaPhoto("attach://file_attach_name", Some(InputFile("AgACAgIAAxkBAAIBmF5NlVQVb6iPrSZWAonh4PnZm_GMAALtrjEbORhoSkLApyEUFBhoPA1xkS4AAwEAAwIAA3gAA5wVAAIYBA")))
)
request(SendMediaGroup(msg.source, array)).void
}
}
val eol = bot.run()
println("Press [ENTER] to shutdown the bot, it may take a few seconds...")
scala.io.StdIn.readLine()
bot.shutdown() // initiate shutdown
// Wait for the bot end-of-life
Await.result(eol, Duration.Inf)
}
With the OkHttpFutureBackend the fileid example did not log a response.
With the AsyncHttpClientFutureBackend all examples had a TelegramApiException: Bad Request: can't parse InputMedia: media not found as response.
When using SendMediaGroup, I'm getting
TelegramApiException: Bad Request: can't parse InputMedia: media not found(whether I use a file_id string or an InputFile with attach://).Here is an example bot:
With the OkHttpFutureBackend the fileid example did not log a response.
With the AsyncHttpClientFutureBackend all examples had a
TelegramApiException: Bad Request: can't parse InputMedia: media not foundas response.