Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TelegramApiException with SendMediaGroup #86

Closed
mich-h opened this issue Feb 19, 2020 · 0 comments
Closed

TelegramApiException with SendMediaGroup #86

mich-h opened this issue Feb 19, 2020 · 0 comments
Labels

Comments

@mich-h
Copy link

mich-h commented Feb 19, 2020

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.

@ex0ns ex0ns added the bug label Apr 5, 2021
mmvpm added a commit to mmvpm/telegram that referenced this issue Jun 2, 2024
@ex0ns ex0ns closed this as completed in fd52d33 Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants