Customized Sharing from the Webview
Users can already share from the webview if they like a piece of content from your bot.
But you may wish to customize the experience more. For instance, you might want to control the formatting of the resulting bubble and give the recipient a specific call to action (e.g. "Buy", "Play). Or you may wish to direct the recipient into some specific flow (e.g. filling out an RSVP or taking a survey) that's hosted at a different URL than the one the sender is seeing.
Messages sent from the share button can also be customized in a similar fashion via the share_contents attribute.
Policy Reminder Messages shared via these APIs are subject to Facebook Platform Policy. Bots may not incentivize sharing or lead users to share in a deceptive manner.
beginShareFlow()
beginShareFlow() lets you begin a share. Call it from a "Share" button on your page, passing in the message you want to share.
The user will then be presented with a dialog where they can preview the message contents, enter a message, and choose which friends or groups to send it to.
In addition to the contents you specify, the message will automatically include an attribution link for the recipient to try your bot.
Here's a full example of calling it:
<script>
var messageToShare = {
"attachment":{
"type":"template",
"payload":{
"template_type":"generic",
"elements": [{
"title":"I took Peter's 'Which Hat Are You?' Quiz",
"image_url": "https://bot.peters-hats.com/img/hats/fez.jpg",
"subtitle": "My result: Fez",
"default_action":{
"type":"web_url",
"url": "https://bot.peters-hats.com/view_quiz_results.php?user=24601"
},
"buttons":[{
"type":"web_url",
"url":"https://bot.peters-hats.com/hatquiz.php?referer=24601",
"title":"Take the Quiz"
}]
}]
}
}
};
MessengerExtensions.beginShareFlow(function success(response) {
// Share successful
}, function error(errorCode, errorMessage) {
// The user was not able to share
},
messageToShare,
"broadcast");
</script>The function takes the following parameters:
Parameters
| Parameter | Description | Type | Required |
|---|---|---|---|
success callback | This function will be called if the share is successful. | Function | Yes |
error callback | This function will be called if there is an error or the user cancels. | Function | Yes |
message contents | This specifies the message bubble that will be shared. | Object (see below) | Yes |
mode | The mode to share in. | Either | Yes |
Message Contents
Note that the object specifying the message in beginShareFlow() is identical to that of the send API. However, with this API, several restrictions apply when using this API.
The message may only be of the following types:
- A generic template. The format is identical to that specified in the Send API docs. However, only up to one button is allowed, and it must be a URL button.
Share Modes
The mode parameter allows two choices:
broadcast mode is recommended for inside the bot itself, as well as for users encountering content from your bot via shared links.
current_thread mode is recommended for use inside Chat Extensions.

Response
The response object passed to the success callback tells you the result of the share. If the user finished their share, you may wish to proceed to another stage or close the webview.
| Parameter | Description | Type |
|---|---|---|
| Whether the user ultimately did decide to share the content. | Boolean |