Facebook Messenger API“请求正文未定义”

时间:2016-04-13 15:18:02

标签: facebook

按照标准文档执行完所有步骤后,我的webhook中的req.body未定义:

app.post('/webhook/', function(req, res) {  
    console.log("message received " + req.body);
    if(!req.body){
        console.log("no request body found");
        res.sendStatus(200);
        return;
    }

    messaging_events = req.body.entry[0].messaging;
    for (i = 0; i < messaging_events.length; i++) {
        event = req.body.entry[0].messaging[i];
        sender = event.sender.id;
        console.log("sender " + event.sender + ", message " + event.message.text);
        if (event.message && event.message.text) {
            text = event.message.text;
            // Handle a text message from this sender
            sendTextMessage(sender, "Text received, echo: "+ text.substring(0, 200));
        }
    }

    res.sendStatus(200);
});

修改

在我测试之前,我是否需要批准机器人?我的Facebook页面也是直播

0 个答案:

没有答案