[英]sendMessage not defined in Facebook Instant Games Webhook
我已經部署了一個Webhook,以使Messenger機器人在玩家退出游戲時運行。 我正在嘗試實現此功能: https : //developers.facebook.com/docs/games/instant-games/getting-started/bot-setup/#step-3--respond-to-messaging-game-plays-網絡掛接
其他所有工作正常,但是當腳本部署到sendMessage時出現錯誤。 它沒有說:
2019-03-11T15:11:16.289939+00:00 app[web.1]: ReferenceError: sendMessage is not defined
盡管我確實知道此錯誤是因為在腳本的任何地方都沒有定義sendMessage,但是在瀏覽了所有文檔之后,我不確定在sendMessage中到底要寫什么才能使腳本正常工作。
這是我的webhook終點:
// Creates the endpoint for our webhook
app.post('/webhook', (req, res) => {
let body = req.body;
console.log("body post : "+JSON.stringify(body));
// Checks this is an event from a page subscription
if (body.object === 'page') {
// Iterates over each entry - there may be multiple if batched
body.entry.forEach(function(entry) {
console.log(JSON.stringify(entry));
// Gets the message. entry.messaging is an array, but
// will only ever contain one message, so we get index 0
let event = entry.messaging[0];
// Get the sender PSID
let sender_psid = event.sender.id;
console.log('Sender PSID: ' + sender_psid);
if(event.game_play){
var senderId = event.sender.id; // Messenger sender id
var playerId = event.game_play.player_id; // Instant Games player id
var contextId = event.game_play.context_id;
var payload = event.game_play.payload;
sendMessage(
senderId,
contextId,
'Congratulations on your victory!',
'Play Again'
);
} else if (event.postback) {
handlePostback(sender_psid, event.postback);
}
});
// Returns a '200 OK' response to all requests
res.status(200).send('EVENT_RECEIVED');
}
});
請幫忙
您調用沒有實現的sendMessage
方法:
sendMessage(
senderId,
contextId,
'Congratulations on your victory!',
'Play Again'
);
您應該確保具有使用Messenger Send API的此方法的實現。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.