对话框v2中的exports.example()= functions.https.onRequest((request,response){}

时间:2018-04-27 06:51:17

标签: node.js dialogflow google-assistant-sdk

如何在dialogflow v2中获取请求对象。

我在dialogflow v1中有以下代码,我应该如何在dialogflow v2中使用。我想在dialogflow v2中使用request.body。任何人都可以帮我这个吗?

exports.example()= functions.https.onRequest((request, response) => {  
   const app = new App({request, response});  
   console.log('Request headers: ' + JSON.stringify(request.headers));   
   console.log('Request body: ' + JSON.stringify(request.body)); 
}

1 个答案:

答案 0 :(得分:0)

以下代码摘自Github上https://www.tensorflow.org/api_docs/python/tf/contrib/image/translate之一。这是Dialogflow's samples的Dialogflow参考文档。文档中还有一个WebhookClient

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, 
response) => {
  const agent = new WebhookClient({ request, response });

  function hours (agent) {
    if (currentlyOpen()) {
      agent.add(`We're open now! We close at 5pm today.`);
    } else {
      agent.add(`We're currently closed, but we open every weekday at 9am!`);
    }
  }