TELEGRAM: 400 Bad Request: wrong type of the web page content

2.8k Views Asked by At

While sending documents via external link in telegram bot I am getting error of "Unhandled rejection Error: ETELEGRAM: 400 Bad Request: wrong type of the web page content". I just don't understand why this error occured? P.S I'm using node.js library called node-telegram-bot-api to send requests.

`

bot.sendMediaGroup(
  config.CHANNEL_ID,
  [
    {
      type: "photo",
      media: imgUrl,
      caption: movie,
      parse_mode: "HTML",
    },
    {
      type: "photo",
      media: screenshots[0],
    },
    {
      type: "photo",
      media: screenshots[1],
    },
    {
      type: "video",
      media: videoArray[0].url,
    },
  ],
  {
    disable_notification: true,
  }
);

`

5

There are 5 best solutions below

0
On

There are content types that Telegram does not accept . Like .webp .....

async function downloadAndSaveThumbnail(videoInfo) {
  const thumbnailExtension = path.extname(videoInfo.thumbnail).toLowerCase();
  
  if (thumbnailExtension !== '.png' && thumbnailExtension !== '.jpg') {
    const savedThumbnailPath = `media/${cleanTitle(videoInfo.title)}.png`;
    const thumbnailStream = fs.createWriteStream(savedThumbnailPath);

    const thumbnailResponse = await axios.get(videoInfo.thumbnail, { responseType: 'stream' });
    await new Promise((resolve, reject) => {
      thumbnailResponse.data.pipe(thumbnailStream);
      thumbnailStream.on('finish', resolve);
      thumbnailStream.on('error', reject);
    });

    return savedThumbnailPath;
  } else {
    return videoInfo.thumbnail;
  }
}

(by default application/octet-stream)

0
On

in my case i built an array with images but set two times the root domain for the image source, like this https://something.com/https://something.com/img/asdf.jpg

2
On

In my issue i tried to send webp image in my media group. When i deleted, it morking.

0
On

I had the same issue when sending photos via public URLs.

I tried the same request using InputFile as multipart/form-data, and it worked.

https://core.telegram.org/bots/api#inputfile

Maybe not all URLs have the correct MIME type required by Telegram Bot API.

0
On

Here's what helped in my situation: I added one slash symbol ("/") where the image link contains only one slash symbol ("/").

In my case it worked.