且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将消息从Facebook Webview发送回给机器人

更新时间:2023-11-19 12:26:10

如果我理解正确的问题,则可以设置一个触发消息发送的API端点,并在`MessengerExtensions的成功回调中命中该端点.requestCloseBrowser().

If I'm understand the question right, you could set up an API endpoint that triggers a message send, and hit that endpoint in the success callback of ` MessengerExtensions.requestCloseBrowser().

使用jQuery和节点的express模块​​的示例:

Example using jQuery and node's express module:

Webview:

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

服务器:

app.post('/sendOnWebviewClose', (req, res) => {
  let psid = req.body.psid;
  sendMessage(psid);
})