Schmavery / facebook-chat-api

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

fs.createReadStream from URL #831

Open hoangvu12 opened 4 years ago

hoangvu12 commented 4 years ago

I want to send attachments without downloading it locally. So I wonder if there is anyway to create a readable stream from a given url. This is what I've tried so far...

const url =
  'https://preview.redd.it/jcqql8h8x1351.jpg?width=640&crop=smart&auto=webp&s=61148c911a1d5155e7d1451105d18241671cf5f0';

request({
  uri: url,
}).on('response', function (response) {
  api.sendMessage({ attachment: response }, event.threadID);
});

Sorry for my bad english ;)

BadAimWeeb commented 4 years ago

Try using built-in https module.

const url = 'https://preview.redd.it/jcqql8h8x1351.jpg?width=640&crop=smart&auto=webp&s=61148c911a1d5155e7d1451105d18241671cf5f0';

https.get(url).on('response', (stream) {
  api.sendMessage({ attachments: [stream] }, event.threadID);
});
hoangvu12 commented 4 years ago

Try using built-in https module.

const url = 'https://preview.redd.it/jcqql8h8x1351.jpg?width=640&crop=smart&auto=webp&s=61148c911a1d5155e7d1451105d18241671cf5f0';

https.get(url).on('response', (stream) {
  api.sendMessage({ attachments: [stream] }, event.threadID);
});

Thank you for your reply.

I think your code is a bit wrong.

const url = 'https://preview.redd.it/jcqql8h8x1351.jpg?width=640&crop=smart&auto=webp&s=61148c911a1d5155e7d1451105d18241671cf5f0';

https.get(url).on('response', (stream) => {
  api.sendMessage({ attachment: [stream] }, event.threadID);
});

I've tried your way, but it seems it didn't work for me.

Thanks anyway :)

BadAimWeeb commented 4 years ago

Try using built-in https module.

const url = 'https://preview.redd.it/jcqql8h8x1351.jpg?width=640&crop=smart&auto=webp&s=61148c911a1d5155e7d1451105d18241671cf5f0';

https.get(url).on('response', (stream) {
  api.sendMessage({ attachments: [stream] }, event.threadID);
});

Thank you for your reply.

I think your code is a bit wrong.

const url = 'https://preview.redd.it/jcqql8h8x1351.jpg?width=640&crop=smart&auto=webp&s=61148c911a1d5155e7d1451105d18241671cf5f0';

https.get(url).on('response', (stream) => {
  api.sendMessage({ attachment: [stream] }, event.threadID);
});

I've tried your way, but it seems it didn't work for me.

Thanks anyway :)

attachments, not attachment

hoangvu12 commented 4 years ago

Try using built-in https module.

const url = 'https://preview.redd.it/jcqql8h8x1351.jpg?width=640&crop=smart&auto=webp&s=61148c911a1d5155e7d1451105d18241671cf5f0';

https.get(url).on('response', (stream) {
  api.sendMessage({ attachments: [stream] }, event.threadID);
});

Thank you for your reply. I think your code is a bit wrong.

const url = 'https://preview.redd.it/jcqql8h8x1351.jpg?width=640&crop=smart&auto=webp&s=61148c911a1d5155e7d1451105d18241671cf5f0';

https.get(url).on('response', (stream) => {
  api.sendMessage({ attachment: [stream] }, event.threadID);
});

I've tried your way, but it seems it didn't work for me. Thanks anyway :)

attachments, not attachment https://github.com/Schmavery/facebook-chat-api/blob/master/DOCS.md#apisendmessagemessage-threadid-callback-messageid

I don't find anything said about attachments in api.sendMessage.

if you want to send multiple attachments, then the array should do it's job

huynhbao commented 3 years ago

How to add stream to array to send multiple attachments?