Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Messenger Bot, send Image Attachment

I'm creating a Facebook bot that has images uploaded to it, and it responds with an image. Can I send the image in an attachment and delete it off my server or do I have to send a URL to the image and keep the image on my server?

like image 843
Carpetfizz Avatar asked Apr 17 '16 05:04

Carpetfizz


People also ask

Can you send attachments in Facebook Messenger?

Sending Attachments. The Messenger Platform allows you to attach assets to messages, including audio, video, images, and files. The maximum attachment size is 25 MB.

How do I get Messenger to send photos?

Send a photo, video, sticker or voice message on MessengerOpen any conversation, then tap the following options at the bottom next to the text box. If you don't see these options, tap next to the text box first. Take and send new photos or videos. Send photos or videos.

Is Messenger API free?

You can get started with the Messaging API for free.


1 Answers

You can use their Upload API to upload your attachments to their servers.

curl -X POST -H "Content-Type: application/json" -d '{
  "message":{
    "attachment":{
      "type":"image", 
      "payload":{
        "url":"http://www.messenger-rocks.com/image.jpg", 
        "is_reusable":true,
      }
    }
  }
}' "https://graph.facebook.com/v2.6/me/message_attachments?access_token=PAGE_ACCESS_TOKEN"

The upload call will respond back an attachment_id which can be used to send the attachment to the user without uploading it again.

curl -X POST -H "Content-Type: application/json" -d '{
  "recipient": {
    "id": "USER_ID"
  },
  "message": {
    "attachment": {
      "type": "image",
      "payload": {
        "attachment_id": "1745504518999123"
      }
    }
  }
}' "https://graph.facebook.com/me/messages?access_token=PAGE_ACCESS_TOKEN"   
like image 89
Alvin Reyes Avatar answered Oct 31 '22 02:10

Alvin Reyes