Facebook Instant Games Webhook 中未定义 sendMessage

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

请帮忙

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

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

您应该确保您有一个使用 Messenger Send API.

的此方法的实现