Facebook has a tool called the Messenger Extensions SDK, which allows you to control the webview, and also get the user id.

First off, you have to whitelist your domain via platform. And then include the following javascript onto the site that's being loaded into the webview.

(function (d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) { return; }
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.com/en_US/messenger.Extensions.js";
    fjs.parentNode.insertBefore(js, fjs);
}(document, "script", "Messenger"));

window.extAsyncInit = function () {
    alert("Getting PSID")
    // the Messenger Extensions JS SDK is done loading
    MessengerExtensions.getUserID(function success(uids) {
        var psid = uids.psid;//This is your page scoped sender_id
        alert("This is the user's psid " + psid);
    }, function error(err) {
        alert("Messenger Extension Error: " + err);
    });
};

Boom, you now have a working webview in your bot. Hopefully you received an alert.

To learn more about the Messenger Extensions SDK, check out Facebook's documentation.

Did this answer your question?