javascriptnode.jstelegramtelegram-botnode-telegram-bot-api

How do I specify the dimensions of the video (height, width) when sending telegrams by bot?


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
  },


Solution

  • 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' }, 
    )