MessengerExtensions.askPermission() Reference

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 askPermission() method of the Messenger Extensions SDK allows you to request a specific permission from the person that opened the webview. When called, a dialog asking them to grant the requested permission will be displayed.

Contents

Available Permissions

When a person begins a conversation with the bot for the first time, these permissions are implicitly granted. There may be other situations where only one (or neither) is granted, such as encountering the bot via a plugin or ad, or encountering a page shared by a friend using a bot.

Permission Scope Description

user_profile

Per user, per bot.

Once granted, the developer may call the user profile API to obtain more information about the user.

user_messaging

Per user, per bot.

Once granted, the bot may message the user personally in a user-to-bot thread.

Method

MessengerExtensions.askPermission(success, error, permission)

Example

MessengerExtensions.askPermission(
  function(permission_response) {
    // Person grants or rejects the asked permission.
    let permissions = permission_response.permissions; // list of all permissions granted
    let isGranted = permission_response.isGranted;

    if (isGranted) {
      // User has granted user_profile permission
    }
    
  }, function(errorCode, errorMessage) {
    // Error occurred
  },
  "user_profile"
);

Parameters

Parameter Type Description

success

Function

Success callback function. Called if the person grants or rejects the permission request. Receives the permission_response object as an argument.

error

Function

Error callback function. Called if Messenger was unable to request the permission.

permission

String

The permission you want to request.

permission_response Object

The permission_response object is passed to the success callback.

{
  "isGranted":true,
  "permissions":[
    "user_profile",
    "user_messaging"
  ]
}

Properties

Property Type Description

isGranted

Boolean

true if the person granted the requested permission. false if the person denied the requested permission.

permissions

Array<String>

A list of the permissions that are currently granted.