在 Dialogflow 中看不到位置权限

Cannot see the location permission in Dialogflow

我正在尝试检索用户在 Dialogfow 中的位置。在文档和博客之后,这就是我在 index.js 实现文件中编写的内容。

const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const {Permission} = require('actions-on-google');

process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const agent = new WebhookClient({ request, response });
  //const agent = new dialogflow();
  console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
  console.log('Dialogflow Request body: ' + JSON.stringify(request.body));

  function welcome(agent) {
    agent.add(`Welcome to my agent!`);
  }

  function fallback(agent) {
    agent.add(`I didn't understand`);
    agent.add(`I'm sorry, can you try again?`);
  }

  const requestPermission = (agent) => {
    //agent.add("Locaation access!");
    //agent.add(new Permission({permissions:'NAME', context:''}));
    agent.requestSource = agent.ACTIONS_ON_GOOGLE;
    const conv = agent.conv();
    conv.ask(new Permission({
        context: '',
        permissions: 'DEVICE_PRECISE_LOCATION',
    }));
    console.log(conv);
    agent.add(conv);
    agent.add("Apple");
  };

  const userInfo = (agent) => {
    if(agent.isPermissionGranted()){
        const address = agent.getDeviceLocation().address;
        if (address){
          agent.add("You are at ${address}");
        }
        else{
            agent.add("Cannot locate you");
        }
    }
    else{
        agent.add("Cannot locate you");
    }
  };

  let intentMap = new Map();
  intentMap.set('Default Welcome Intent', welcome);
  intentMap.set('Default Fallback Intent', fallback);
  intentMap.set('request_permission',requestPermission);
  intentMap.set('user_info', userInfo);
  // intentMap.set('your intent name here', yourFunctionHandler);
  // intentMap.set('your intent name here', googleAssistantHandler);
  agent.handleRequest(intentMap);
});

编辑 这是我收到的 JSON 回复。 原始 API 响应:

{
  "responseId": "RESPONSE-ID",
  "queryResult": {
    "queryText": "locate",
    "action": "request_permission",
    "parameters": {},
    "allRequiredParamsPresent": true,
    "fulfillmentMessages": [
      {
        "platform": "ACTIONS_ON_GOOGLE",
        "simpleResponses": {
          "simpleResponses": [
            {
              "textToSpeech": "Apple",
              "displayText": "Apple"
            }
          ]
        }
      }
    ],
    "webhookPayload": {
      "google": {
        "systemIntent": {
          "intent": "actions.intent.PERMISSION",
          "data": {
            "optContext": "",
            "@type": "type.googleapis.com/google.actions.v2.PermissionValueSpec",
            "permissions": [
              "DEVICE_PRECISE_LOCATION"
            ]
          }
        },
        "expectUserResponse": true
      }
    },
    "intent": {
      "name": "projects/MY_PROJECT_NAME",
      "displayName": "request_permission"
    },
    "intentDetectionConfidence": 1,
    "diagnosticInfo": {
      "webhook_latency_ms": 3564
    },
    "languageCode": "en"
  },
  "webhookStatus": {
    "message": "Webhook execution successful"
  }
}

履行请求:

{
  "responseId": "RESPONSE-ID",
  "queryResult": {
    "queryText": "locate",
    "action": "request_permission",
    "parameters": {},
    "allRequiredParamsPresent": true,
    "fulfillmentMessages": [
      {
        "text": {
          "text": [
            ""
          ]
        }
      }
    ],
    "intent": {
      "name": "PROJECT-NAME",
      "displayName": "request_permission"
    },
    "intentDetectionConfidence": 1,
    "languageCode": "en"
  },
  "originalDetectIntentRequest": {
    "payload": {}
  },
  "session": "SESSION-ID"
}

履行响应:

illmentMessages": [
    {
      "platform": "ACTIONS_ON_GOOGLE",
      "simpleResponses": {
        "simpleResponses": [
          {
            "textToSpeech": "Apple",
            "displayText": "Apple"
          }
        ]
      }
    }
  ],
  "payload": {
    "google": {
      "expectUserResponse": true,
      "systemIntent": {
        "intent": "actions.intent.PERMISSION",
        "data": {
          "@type": "type.googleapis.com/google.actions.v2.PermissionValueSpec",
          "optContext": "",
          "permissions": [
            "DEVICE_PRECISE_LOCATION"
          ]
        }
      }
    }
  },
  "outputContexts": []
}

我认为这个回答是正确的。但屏幕上没有添加任何内容。它在屏幕上显示,

控制台也没有任何错误。但是当我尝试代理时我什么也没得到。 在原始响应中,存在 action.intent.PERMISSION 但为什么未添加或代理要求 yes/no?

仅当您将 Google 上的操作与 Google 智能助理一起使用时,位置权限才有效。您还需要使用 Actions on Google 模拟器对其进行测试 - 单击显示 "See how it works in Google Assistant".

的位置

它不适用于其他 Dialogflow 集成(例如 Facebook 或 Slack),也不适用于 Dialogflow 模拟器(页面右侧的模拟器)。