Schmavery / facebook-chat-api

Unofficial Facebook Chat API for Nodejs
MIT License
1.93k stars 596 forks source link

Can't send .mp4 file using sendMessage #823

Open m1ra11 opened 4 years ago

m1ra11 commented 4 years ago

This is the code:

const readline = require('readline');
const path = require('path');
const fs = require('fs');
const ytdl = require('ytdl-core');
const login = require('facebook-chat-api');

const url = 'https://www.youtube.com/watch?v=NI7LbI5BcqY';
const output = path.resolve(__dirname, 'video.mp4');

const video = ytdl(url);
let starttime;
video.pipe(fs.createWriteStream(output));
video.on('end', () => {
  login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
    if (err) return console.log(err);
    api.setOptions({
      selfListen: true,
      logLevel: 'silent',
      updatePresence: false,
      userAgent:
          'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36',
    });
    api.sendMessage({
      body: 'Test',
      attachment: fs.createReadStream(output),
    }, '100051567751317');
  });
});

The file is fully downloaded and able to watch in media player, but I can't send it to facebook's user for some reason

Please help. Thank you

BadAimWeeb commented 4 years ago

attachments, not attachment. also you need to put the stream in an array.

m1ra11 commented 4 years ago

attachments, not attachment. also you need to put the stream in an a

attachments, not attachment. also you need to put the stream in an array.

Thank you, I forgot to say but my code works when I try videos with 2-3 minutes length, others didn't works. Also I tried to reduce the video size to lower than size limit, but it still didn't works