8

I can manage Page Conversations (read, write) in help with Facebook Graph API. But it seems to be impossible to add any attachments to my direct messages.

https://developers.facebook.com/docs/graph-api/reference/conversation/messages

I see only "message" parameter in documentation. So, is there any way how to do it?

phwd
  • 19,975
  • 5
  • 50
  • 78
Jakub Mach
  • 1,109
  • 3
  • 10
  • 19

2 Answers2

2

As @Niraj Shah mentioned above, the attachment sending feature is undocumented (for the time of this post, GraphAPI v2.12), but exists and works if you will post the source field:

PHP:

$fb =
    new Facebook([
        'app_id' => 'your app id',
        'app_secret' => 'your app secret',
        'default_graph_version' => 'v2.12',
        'default_access_token' => 'your page token',
    ]);

$response =
    $fb->post(
        "/{$conversationId}/messages",
        [
            'message' => '',
            'source' => $fb->fileToUpload($attachmentFileName),
        ]
    );

The message field can be empty to send an attachment only.

Alexander Pravdin
  • 4,982
  • 3
  • 27
  • 30
0

As the documentation points out, the API only supports the message parameter. So only text can be sent in a message, and attachments are not supported. However, you can try sending the source or url parameter in your API call and see if Facebook adds it to the message (it could be a undocumented feature).

Niraj Shah
  • 15,087
  • 3
  • 41
  • 60