Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

478
Visualizações
nodeJS - Unhandled rejection RequestError: Error: socket hang up

I have this code that is working fine for the first part. I'm tryng to send a video to the user after it select what video want to see. The problem is that I'm unable to achive it because I get always this error Unhandled rejection RequestError: Error: socket hang up.

#!/usr/bin/env node 

const TelegramBot = require('node-telegram-bot-api');

const TorrentSearchApi = require('torrent-search-api');

const TorrentStream = require('torrent-stream');

const bot = new TelegramBot('5xxxx', {polling: true});

const providers = TorrentSearchApi.getProviders();

//console.log(providers);

TorrentSearchApi.enablePublicProviders();

let magnetLinks = []
let response = 'Here are your search results: \n';
let engine;
let stream;

// Matches "/echo [whatever]"
bot.onText(/\/search (.+)/, async (msg, match) => {
    // 'msg' is the received Message from Telegram
    // 'match' is the result of executing the regexp above on the text content
    // of the message
    console.log(match[1]);

    TorrentSearchApi.search(match[1], 'All', 10).then( (results) => {
        results.forEach( (item, index) => {
            if( item.seeds > 1 ){
                response += `${index}) ${item.title}\n`;
                magnetLinks.push(item.magnet);
            }
        });
        bot.sendMessage(msg.chat.id, response).then( (message) => {
            bot.sendMessage(msg.chat.id, 'Use the /stream command followed by the number of the torrent file you want to play');
        });
    });
});

bot.onText(/\/stream (.+)/, async (msg, match) => {
    console.log(magnetLinks[match[1]]);
    engine = TorrentStream(magnetLinks[match[1]]);
    engine.on('ready', () => {
        engine.files.forEach( (file) => {
            console.log('filename:', file.name);
            stream = file.createReadStream();
            console.log(stream);
            // stream is readable stream to containing the file content
            bot.sendVideo(msg.chat.id, stream);
        });
    });
});

How I can solve the problem and let the telegram bot send the video file to the user?Is possible to stream a video file with a telegram bot?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda