messenger-bot icon indicating copy to clipboard operation
messenger-bot copied to clipboard

Add support for uploading files

Open remixz opened this issue 9 years ago • 3 comments

Facebook just recently added the ability to upload files (images, audio, videos, or a generic file) for a message, instead of having to specify a URL for an attachment.

  • https://developers.facebook.com/docs/messenger-platform/send-api-reference/image-attachment
  • https://developers.facebook.com/docs/messenger-platform/send-api-reference/audio-attachment
  • https://developers.facebook.com/docs/messenger-platform/send-api-reference/video-attachment
  • https://developers.facebook.com/docs/messenger-platform/send-api-reference/file-attachment

They all share the same format of it being a multipart POST form, with the file being under the key of filedata. For our sendMessage / reply, we should have some sort of special key in the payload that accepts the same inputs as request does for multipart forms (https://github.com/request/request#forms), and is then added to the request as filedata.

remixz avatar Jul 01 '16 18:07 remixz

any update on this?

bitcoinvsalts avatar Feb 16 '17 22:02 bitcoinvsalts

Highly interested

danielnjoo avatar Sep 16 '17 22:09 danielnjoo

I've just created a PR using the Facebook Attachment Upload API: Add Attachment Upload API method.

You can use it as below:

bot.getAttachmentUploadId("https://images.pexels.com/photos/63324/california-road-highway-mountains-63324.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260", true, "image", (err, body) => {
    // ...
});

With this function you get a attachment_id which is usable with the Media Template Reference.

baudev avatar Jun 08 '18 09:06 baudev