嗨,我试图通过获取用户许可来获取设备的粗略位置。但是我需要在不反复询问许可的情况下获取每个Webhook请求的设备位置详细信息,所以我有点困惑如何做到这一点。
这是我尝试的以下代码。
const {Permission} = require('actions-on-google');
const {WebhookClient} = require('dialogflow-fulfillment');
const agent = new WebhookClient({ request: req, response: res });
function x(agent){
conv.ask(new Permission({context:'To Locate You',permissions:'DEVICE_COARSE_LOCATION'}));
}
function userinfo(agent){
var conv=agent.conv();
var resp=conv.arguments.get('PERMISSION');
console.log(conv.device.location);
if(resp){
var country=conv.device.location.country;
var speech="you are located in "+country;
conv.ask(speech);
agent.add(conv);
}else{
conv.ask('Sorry, I could not figure out where you are');
agent.add(conv);
}
}
答案 0 :(得分:0)
请检查辅助功能here。您需要执行以下操作:
actions_intent_PERMISSION
放入该意图来创建第二个意图,以捕获用户对意图的响应。首先要获得许可
app.intent('FIRST_INTENT_NAME', (conv) => {
// Choose one or more supported permissions to request:
// NAME, DEVICE_PRECISE_LOCATION, DEVICE_COARSE_LOCATION
const options = {
context: 'To address you by name and know your location',
// Ask for more than one permission. User can authorize all or none.
permissions: ['NAME', 'DEVICE_PRECISE_LOCATION'],
};
conv.ask(new Permission(options));
});
第二意图捕获结果
app.intent('SECOND_INTENT_NAME', (conv, params, confirmationGranted) => {
const {name} = conv.user;
if (confirmationGranted) {
if (name) {
conv.ask(`I'll send the driver you're way now ${name.display}.`);
}
}
});
有关代码示例的确切信息,请查看this GitHubb example link。