hubot-fb
hubot-fb copied to clipboard
support for sending image(file)
Currently hubot-fb supports sending images via urls. Here's the guideline of sending image (file).
Will this be supported?
already supported! see https://github.com/chen-ye/hubot-fb#sending-rich-messages-templates-images
sorry was a bit vague bout that. I meant to ask about sending image via filedata
, as in
curl \
-F recipient='{"id":"USER_ID"}' \
-F message='{"attachment":{"type":"image", "payload":{}}}' \
-F filedata=@/tmp/testpng.png \
"https://graph.facebook.com/v2.6/me/messages?access_token=PAGE_ACCESS_TOKEN"
Thats supported via the attachment payload as well - check the data recieved when an image is sent from the user to the bot
I tested using
robot.on "fb_richMsg", (envelope) ->
res = new Response robot, envelope, undefined
res.envelope.fb = {
richMsg: {
attachment: envelope.attachments[0]
}
}
res.send()
Which echos back rich mesages
ohh thx, will try later, let's close for now.
update: the method you showed above still works only for sending url of image, not the buffer stream of your local file. For example, run image transformation from facebook: take image from user, transform to output, send that file back to people.
Luckily this can be done by plain HTTP request now:
var formData = {
recipient: `{"id":"${envelope.user.id}"}`,
message: '{"attachment":{"type":"image", "payload":{}}}',
filedata: fs.createReadStream(outFilepath)
}
request.post({url:'https://graph.facebook.com/v2.6/me/messages?access_token='+process.env.FB_PAGE_TOKEN, formData: formData});
Ok! I'm currently on a weekend vacation, but I can take a look at adding this functionality Tuesday. Do you know how other adapters which support file upload do this at the api level? On May 15, 2016 18:47, "Wah Loon Keng" [email protected] wrote:
update: the method you showed above still works only for sending url of image, not the buffer stream of your local file. For example, run image transformation from facebook: take image from user, transform to output, send that file back to people.
Luckily this can be done by plain HTTP request now:
var formData = { recipient:
{"id":"${envelope.user.id}"}
, message: '{"attachment":{"type":"image", "payload":{}}}', filedata: fs.createReadStream(outFilepath) }request.post({url:'https://graph.facebook.com/v2.6/me/messages?access_token='+process.env.FB_PAGE_TOKEN, formData: formData});— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/chen-ye/hubot-fb/issues/9#issuecomment-219293418
no worries, I'm using that script above now. yep. hubot-telegram