0

I have a telegram bot

bot.on("message", async function onAudio(msg) {
  const chatId = msg.chat.id
  const youtubeLink = msg.text
  // console.log(text);

  if (youtubeLink) {
    bot.sendMessage(chatId, 'Received your Link');
    const stream = ytdl(youtubeLink, {
      quality: "lowestaudio",
      filter: "audioonly",
    })
    bot.sendAudio(chatId, stream)
  }

})

bot.on('polling_error', (error) => {
  console.log(error.code);  // => 'EFATAL'
});

constant stream is readable

So when i test this code it's can't send audio file to bot

I think file is large for sending and try this one

stream.on('data', (chunk) => {
  bot.sendAudio(chatId, chunk)
})

this code is sending audio with chunks and i get small parts in my bot

How can i send audio to my bot ?

arzumanyan_25
  • 53
  • 1
  • 5

0 Answers0