This document explains how to message a person who commented on Page posts or messaged your Page.
You will need:
pages_read_engagement
permissionpages_read_user_content
permission pages_messaging
permissionMODERATE
task on the Page that is being queried.Send a private message to a visitor who wrote a post on your Page or commented on a Page post.
can_reply_privately
must be true
.Send a GET
request to the /{page-id}/feed
endpoint with the can_reply_privately
, from
, 'message
, and comments
fields:
curl -i -X GET "https://graph.facebook.com/{page-id}/feed/ ?fields=can_reply_privately,from,message,comments{can_reply_privately,from,message} &access_token={page-access-token}"
On success, your app will receive the following response:
{ "data": [ { // Page post with a Comment "can_reply_privately": false, //Can't reply to your own post "from": { "name": "Clean Slate Page", "id": "{page-id}" }, "message": "Hello World!", //Page post message "comments": { "data": [ { "can_reply_privately": true, //Can reply to a visitor comment "from": { "name": "Cindy Hoover", "id": "{user-id}" }, "message": "Keep up the good work!", //Comment on the post "id": "{comment-id}" } ], }, "id": "{page-post-id}" }, { //Page post by a Page visitor "can_reply_privately": true, //Can reply to a visitor post "from": { "name": "Cinder Hoover", "id": "156407155145863" }, "message": "Hello Clean Slate Page!" //Visitor post message "id": "1983306698425200_2883179105104617" } ], }
Send a POST
request to the {page-id}/messages
endpoint where recipient
is the comment_id:{comment-id}
or post_id:{page-post-id}
of the comment or post the visitor made on your Page:
curl -i -X POST "https://graph.facebook.com/{page-id}/messages ?recipient={post_id:{page-post-id}} &message={text:Thanks, Cindy!} &message_type=RESPONSE &access_token={page-access-token}"
Send a GET
request to the /{page-id}/conversations
endpoint:
curl -i -X GET "https://graph.facebook.com/{page-id}/conversations ?fields=id,messages{message,from} access_token={page_access_token}"
On success, your app receives this response:
{ "data": [ { "id": "t_100023297371310", // The Conversation ID "messages": { "data": [ { "message": "Thanks, Kerry!", "from": { "name": "Page Name", "email": "{page-id}@facebook.com", "id": "{page-id}" }, "id": "m_glADDQqH2yRWzcXI2wu7_S7ARkXcpFndCC-noYLufbGR-TfBy6yyEts5PwqLia1qJ_3OorlB55QgxG5EuERP8g" //The Message ID }, { "message": "I love coffee! Keep up the good work!", "from": { "name": "Kerry Smith", "email": "{user-id}@facebook.com", "id": "{user-id}" }, "id": "m_P7PeTWv6ctJ7QIw1MPzLbi7ARkXcpFndCC-noYLufbGLZo92oEJnqRfo605ScNxzaqBCWlOk1nlpqM73OZqYdQ" }, ... ] }
Send a POST
request to the conversation_id/messages
endpoint and set the message
parameter to your message text.
curl -i -X POST "https://graph.facebook.com/{conversation-id}/messages &message=Thanks, Kerry! &access_token={page_access_token}"
On success, your app receives this response:
{ "id": "m_P7PeTW...", "uuid": "P7PeTWv6..." }