The Send API is the main API used to send messages to users, including text, attachments, structured message templates, sender actions, and more.
A page access token with pages_messaging permission is required to interact with this endpoint.
Apps in Development Mode, are restricted to message people that have a role in the app. Additionally Pages in unpublished status will only be allowed to message people with a role on the Page.
-
Create a Facebook page : https://www.facebook.com/help/104002523024878/
-
Create a Facebook app https://developers.facebook.com/docs/development/create-an-app/
-
Go to your Facebook app dashboard
-
Click on Messenger > Settings
-
Add the page created in Step 1 and generate an Access Token
-
Edit the callback URL, and provide the same Verify Token that you have used in your app.
-
For more details, visit: https://developers.facebook.com/docs/messenger-platform/getting-started/app-setup/
https://developers.facebook.com/docs/messenger-platform/send-messages#send_api_basics
https://graph.facebook.com/v11.0/me/messages?access_token=<PAGE_ACCESS_TOKEN>
curl -X POST -H "Content-Type: application/json" -d '{
"messaging_type": "<MESSAGING_TYPE>",
"recipient": {
"id": "<PSID>"
},
"message": {
"text": "hello, world!"
}
}' "https://graph.facebook.com/v11.0/me/messages?access_token=<PAGE_ACCESS_TOKEN>"
-
The messaging type of the message being sent. https://developers.facebook.com/docs/messenger-platform/send-messages/#messaging_types
-
recipient object
-
message object. Cannot be sent with sender_action.
-
Message state to display to the user:
- typing_on: display the typing bubble
- typing_off: remove the typing bubble
- mark_seen: display the confirmation icon
Cannot be sent with message. Must be sent as a separate request.
When using sender_action, recipient should be the only other property set in the request.
A successful Send API request to a PSID returns a JSON string containing identifiers for the message and its recipient.
{
"recipient_id": "1008372609250235",
"message_id": "m_AG5Hz2Uq7tuwNEhXfYYKj8mJEM_QPpz5jdCK48PnKAjSdjfipqxqMvK8ma6AC8fplwlqLP_5cgXIbu7I3rBN0P"
}