MessengerExtensions.beginShareFlow()

Messenger Extensions SDK

This method is a part of the Messenger Extensions SDK. For information on including the SDK in your site, see Add Messenger Extensions SDK.

The beginShareFlow() method of the Messenger Extensions SDK allows you to customize the message that is sent when someone shares a page from the webview. For example, you can set the text of the message sent with the shared content, or structure the message using one of the Messenger Platform's templates.

Contents

Method

MessengerExtensions.beginShareFlow(success, error, message, mode)

Example

let message = {
  "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(share_response) {
  // User dismissed without error, but did they share the message?
  if(share_response.is_sent){
    // The user actually did share. 
    // Perhaps close the window w/ requestCloseBrowser().
  }
}, 
function(errorCode, errorMessage) {      
// An error occurred in the process

},
message,
"broadcast");

Parameters

Parameter Type Description

success

Function

Success callback function. Receives the share_response object as an argument.

error

Function

Error callback function. Called if Messenger was unable to initiate the share flow.

message

Object

The message to send that links to the shared content. The message must use one of the following:

  • An image
  • Generic template
  • Media template

mode

String

The type of share flow to initiate:

  • broadcast: Prompts the person to share with other people outside the current conversation.
  • current_thread: Prompts the person to share directly to the conversation the webview was opened from.

share_response Object

The share_response object is passed to the success callback.

{
  "is_sent": true  
}

Properties

Property Type Description

is_sent

Boolean

Will be true if the person successfully shared the webview content, and false if they canceled before completing the share.