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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With