sendMessage未在Facebook Instant Games Webhook中定义

问题描述 投票:0回答:1

当玩家退出我的游戏时,我已经部署了一个webhook来使Messenger机器人运行。我正在尝试实现这个:https://developers.facebook.com/docs/games/instant-games/getting-started/bot-setup/#step-3--respond-to-messaging-game-plays-webhooks

其他一切正常,但是当脚本部署到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');
} 
});

请帮忙

facebook facebook-messenger-bot facebook-instant-games
1个回答
1
投票

你调用一个没有实现的方法sendMessage

sendMessage(
  senderId, 
  contextId, 
  'Congratulations on your victory!', 
  'Play Again'
);

您应确保您拥有使用Messenger Send API的此方法的实现。

© www.soinside.com 2019 - 2024. All rights reserved.