commands
ReferenceCommands are tappable keywords that a user can invoke at any time to perform specific actions within the Messenger experience. Users can invoke multiple commands in a single message. For example, if your travel assistant supports commands such as flights and hotels, a message from a user might be, "Help me book flights and hotels to Mexico for the last week of December." Messenger automatically highlights the commands in the composer as the user taps them. These commands then trigger a webhook to send the list of commands invoked by the user. Only the command name(s) will be sent to your app via webhook. Your app can then use the webhook as confirmation of the user's intent to run a command, and parse the message text appropriately.
Users can invoke commands in three ways, as seen in the screenshots above:
The Commands menu appears automatically when you set up Commands. No further action is needed on your part.
A key difference between Commands and the Persistent Menu is that tapping a Persistent Menu item sends the keyword to the thread, whereas tapping a Command sends the command to the composer, allowing the user to add additional context.
commands
Format"commands": [ { "locale": "default", "commands": [ { "name": "flights", "description": "Find real-time flights and fares" }, { "name": "hotels", "description": "Find real-time hotel rooms and rates" }, { "name": "currency", "description": "Find real-time currency exchange rates" }, { "name": "weather", "description": "Find real-time weather reports and forecasts" } ] } ]
You may provide default and localized commands, to be displayed based on the user's locale. To do this, specify a separate object in the commands
array for each locale. To specify the locale for each object, set the locale
property to a supported locale:
"commands": [ { "locale": "default", "commands": [...] }, { "locale": "zh_CN", "commands": [...] } ]
Property | Type | Description |
---|---|---|
| String | Locale of the You must at least specify commands for the default locale, which will be displayed if no provided locale matches the user's locale. See the list of supported locales |
| Array< | An array of commands to display to users in the provided locale. The array should contain a minimum of 1 and a maximum of 100 commands. |
command
objectProperty | Type | Description |
---|---|---|
| String | The name of the command. Keep it short and easy for users to remember. The command should not begin with a Minimum of 1 and maximum of 32 characters. |
| String | Description of the command. Use the description to educate users about what the command does and how to use it. Minimum of 1 and maximum of 64 characters. |
curl -X GET "https://graph.facebook.com/v21.0
/me/messenger_profile?fields=commands&access_token=<PAGE_ACCESS_TOKEN>"
{ "data": [ { "commands": [ { "locale": "default", "commands": [ { "name": "flights", "description": "Find real-time flights and fares" }, { "name": "hotels", "description": "Find real-time hotel rooms and rates" }, { "name": "currency", "description": "Find real-time currency exchange rates" }, { "name": "weather", "description": "Find real-time weather reports and forecasts" } ] } ] } ] }
The following POST request could be used to set or update commands.
curl -X POST -H "Content-Type: application/json" -d '{
"commands": [
{
"locale": "default",
"commands": [
{
"name": "flights",
"description": "Find real-time flights and fares"
},
{
"name": "hotels",
"description": "Find real-time hotel rooms and rates"
},
{
"name": "currency",
"description": "Find real-time currency exchange rates"
},
{
"name": "weather",
"description": "Find real-time weather reports and forecasts"
}
]
}
]
}' "https://graph.facebook.com/v21.0
/me/messenger_profile?access_token=<PAGE_ACCESS_TOKEN>"
{ "result": "success" }
Calls to the Messenger Profile API are limited to 10 API calls per 10 minutes interval. This rate limit is enforced per Page.