Closed marcelvanworkum closed 7 years ago
Hmm, as you can see with #152, we've had some unresolved issues with gifs in the past. Unfortunately the error facebook returns doesn't give us much indication as to the nature of the problem.
In your other situation, you're putting a hardcoded meme.jpg in the dirname folder and running `attachment: fs.createReadStream(dirname + '/meme.gif')` and it's working?
It strikes me that your read stream and your write stream don't have their locations specified the same way ("meme.gif")
vs (__dirname + '/meme.gif')
. Not sure why (though I'd hope that wouldn't be a problem)?
I suggested a workaround in #347 that you might find interesting. @ivkos seems to be trying to solve a fairly similar problem, maybe we can pool resources.
Any luck with this issue?
Hey I just got that to work using the code below. I think the issue was using a writeStream instead of simply the response from the get request which is a readstream.
var targetUrl = "http://media.giphy.com/media/JhncGNdBoyeKk/giphy.gif";
var gifRequest = require('http').get(targetUrl, function(gifResponse) {
var message = {
body: "Here's that fresh meme ya ordered!",
attachment: gifResponse
}
api.sendMessage(message, threadID);
});
That's just another way to do it without saving to disk. It seems like waiting for the writeStream to be done works too:
var file = fs.createWriteStream("meme.gif");
var targetUrl = "http://media.giphy.com/media/JhncGNdBoyeKk/giphy.gif";
var gifRequest = require('http').get(targetUrl, function(gifResponse) {
gifResponse.pipe(file);
file.on('finish', function() {
var message = {
body: "Here's that fresh meme ya ordered!",
attachment: fs.createReadStream(__dirname + '/meme.gif')
}
api.sendMessage(message, threadID);
});
});
Since this works I'm closing this issue. Feel free to re-open if you have any other issue.
Trying to replicate Slack's random Giphy integration for my personal chatbot. I am grabbing a gif from their api, downloading that locally, and then trying to send that using your api.
Here is the code I am using to do this:
This results in the following error: (Note I have added the
console.log(data.body);
to the utils.js as mentioned in #152I can upload the gif fine using messenger.com.
Also, if I change
attachment: fs.createReadStream(__dirname + '/meme.gif')
to instead send'/meme.jpg'
with a validmeme.jpg
in that same directory it works perfectly.Is this an issue with the way the api handles gifs, or perhaps am I creating the read stream incorrectly?
Any insight would be greatly appreciated.