如何在PreactJS中包含Facebook Messenger Webview Extension

时间:2017-09-23 16:03:46

标签: reactjs facebook-messenger preact

我现在正在使用PreactJS为facebook messenger开发webview。但现在问题是我没有任何解决方案来包含/实现在preactJS中添加Messenger Extensions。我做了如下,但chooseTownship行动完全不起作用。请帮我解决一下。

chooseTownship = (e) => {
    window.extAsyncInit = function() {
        MessengerExtensions.getUserID(function success(uids) {
            var psid = uids.psid;
            var theUrl = "/webhooks/webview?fbUserId=" + psid +  "&townshipId=" + e.target.name + "&townshipName=" + e.target.value;
            fetch(url).then((response) => {
                if (response.status === 200) {
                    MessengerExtensions.requestCloseBrowser(function success() {

                    }, function error(err) {

                    });
                }
            });
        }, function error(err, errorMessage) {
            console.log(errorMessage);
        });
    }
}

componentDidMount() {
    const that = this;
    const url = '/api/townships';

    fetch(url).then((response) => {
        if (response.status >= 400) {
            throw new Error('Bad response from server');
        }
        return response.json();
    }).then((data) => {
        that.setState({
            townships: data.townships
        });
    });

    (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'));
}

0 个答案:

没有答案