Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for sending image(file) #9

Open
kengz opened this issue May 11, 2016 · 8 comments
Open

support for sending image(file) #9

kengz opened this issue May 11, 2016 · 8 comments
Assignees

Comments

@kengz
Copy link
Contributor

kengz commented May 11, 2016

Currently hubot-fb supports sending images via urls. Here's the guideline of sending image (file).

Will this be supported?

@chen-ye
Copy link
Owner

chen-ye commented May 11, 2016

@kengz
Copy link
Contributor Author

kengz commented May 11, 2016

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"

@chen-ye
Copy link
Owner

chen-ye commented May 11, 2016

Thats supported via the attachment payload as well - check the data recieved when an image is sent from the user to the bot

@chen-ye
Copy link
Owner

chen-ye commented May 11, 2016

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

@kengz
Copy link
Contributor Author

kengz commented May 12, 2016

ohh thx, will try later, let's close for now.

@kengz kengz closed this as completed May 12, 2016
@kengz
Copy link
Contributor Author

kengz commented May 15, 2016

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});

@chen-ye
Copy link
Owner

chen-ye commented May 15, 2016

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
#9 (comment)

@kengz
Copy link
Contributor Author

kengz commented May 15, 2016

no worries, I'm using that script above now.
yep. hubot-telegram

@kengz kengz reopened this May 15, 2016
@chen-ye chen-ye self-assigned this Jun 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants