skip to Main Content

I use the node-telegram-bot-api library. How do I specify the size of the video when sending it?

// where to specify height and width ?
bot.sendVideo(
  chatId,
  video,
  { caption: 'my video' },
  { filename: 'my_file' }, 
)

The telegram API allows you to specify sizes, but it seems to me that the sendVideo method does not allow you to specify them. Is it so?

p.s.: I tried to pass height and width through the option argument.

bot.sendVideo(
    chatId,
    `video`,
    {
        caption: 'my video',
        height: 720,
        width: 1280
    },
    {filename:'my_file'}
)
    .then(res=>{console.log(res)})

but with any parameters of the height and width parameters, I get the same answer.

video: {
    duration: 8,
    width: 1080,
    height: 1920,
    file_name: 'my_video',
    mime_type: 'video/mp4',
    thumb: {
      file_id: '***',
      file_unique_id: '***',
      file_size: 12743,
      width: 180,
      height: 320
    },
    file_id: '***',
    file_unique_id: '***',
    file_size: 4938678
  },

2

Answers


  1. Chosen as BEST ANSWER

    it will work, if you pass the video parameters to options params (the third parameter).

    bot.sendVideo(
        chat_id,
        `${path_to_video}`,
        {
            width: width,
            height: height,
        }
    )
    

    I used the "get-video-dimensions" library so that the video does not change the original parameters. Here is the final code that worked for me:

    const getDimensions = require("get-video-dimensions");
    getDimensions(`${path_to_video}`)
        .then( dimensions => {
            return bot.sendVideo(
                chat_id,
                `${path_to_video}`,
                {
                    width: dimensions.width,
                    height: dimensions.height,
                }
            )
        })
    

  2. If you check the node-telegram-bot-api library’s GitHub repo, you can see that the sendVideo() method accepts an options object as the third parameter that stores additional Telegram query options.

    You’re already passing down an object with a caption key and you could add some more there, like height, width, duration, etc. A complete list of these options is available on the Telegram docs.

    bot.sendVideo(
      chatId,
      video,
      {
        caption: 'my video',
        height: 720,
        width: 1280,
      },
      { filename: 'my_file' }, 
    )
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search