Google Node.js上的操作getDeviceLocation

时间:2018-10-26 22:12:26

标签: node.js dialogflow actions-on-google

我正在使用Google Actions学习Dialogflow,但是对新的Google v2 actions感到迷茫。

我正在尝试获取设备位置,但是我认为正确的方法返回未定义。

我觉得我缺少一些简单的东西,但是我找不到它。

代码是:

const functions = require('firebase- functions');
const { dialogflow, Permission } = require('actions-on-google');
const app = dialogflow();

app.intent('create_log', conv => {
  conv.ask(new Permission({
    context: 'To locate you',
    permissions: 'DEVICE_PRECISE_LOCATION'
  }));
});

app.intent('user_info', (conv, params, granted) => {
  if (granted) {
    const coordinates = app.getDeviceLocation().coordinates;
    if (coordinates) {            
        conv.close(`You are at ${coordinates}`);
    } else {
        // Note: Currently, precise locaton only returns lat/lng coordinates on phones and lat/lng coordinates 
        // and a geocoded coordinates on voice-activated speakers. 
        // Coarse location only works on voice-activated speakers.`enter code here`
        conv.close('Sorry, I could not figure out where you are.');
    }
  } else {
    conv.close('Sorry, I could not figure out where you are.');
  }
});

1 个答案:

答案 0 :(得分:1)

我认为您不需要app上的任何方法,即使该方法存在,因为app可用于所有Intent Handler调用。特定于该会话的信息在传递给Intent Handler的conv参数中。

您可能想要更多类似的东西

const coordinates = conv.device.location;