【问题标题】:Requesting Device Location from Google Actions using dialogflow使用 dialogflow 从 Google Actions 请求设备位置
【发布时间】:2018-03-21 06:03:53
【问题描述】:

我正在使用对话流开发聊天机器人,以使用谷歌上的操作获取用户的位置,我正在使用服务器端代码,如下所示

const functions = require('firebase-functions');
const DialogflowApp = require('actions-on-google').DialogflowApp;

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {

const requestPermission = (app) => {
  app.askForPermission('To locate you', app.SupportedPermissions.DEVICE_PRECISE_LOCATION);
};

const userInfo = (app) => {
    if (app.isPermissionGranted()) {
        const address = app.getDeviceLocation().address;
        if (address) {            
            app.tell(`You are at ${address}`);
        }
        else {
            // Note: Currently, precise locaton only returns lat/lng coordinates on phones and lat/lng coordinates 
            // and a geocoded address on voice-activated speakers. 
            // Coarse location only works on voice-activated speakers.
            app.tell('Sorry, I could not figure out where you are.');
        }
    } else {
        app.tell('Sorry, I could not figure out where you are.');
    }
};

const app = new DialogflowApp({request, response});
const actions = new Map();
actions.set('request_permission', requestPermission);
actions.set('user_info', userInfo);
app.handleRequest(actions);
}); 

这是用于相同意图的屏幕截图:

一旦触发 request_permission 意图,这将向我的应用程序发送一个动作 request_permission 并根据我的服务器端代码运行帮助方法 askForPermission(...)向 Actions On Google 发送 PLACEHOLDER_FOR_PERMISSION 回复将进一步触发“要找到您,我只需要从 Google 获取您的街道地址。那样行吗?”消息并将其作为对对话流的响应返回,但不是在对话流中接收 PLACEHOLDER_FOR_PERMISSION 作为响应。任何人都可以帮助我在这里缺少什么吗?任何建议。 ...

【问题讨论】:

  • 所以这在 Actions 模拟器中可以正常工作,但在 Dialogflow 模拟器中不行?
  • @NickFelker 是的,这适用于 Google 助理模拟器,但它不适用于其他对话流集成,如网络演示等。
  • 好的,按预期工作。请求权限等一些功能只是 Google 平台上的 Actions 的一部分,而一般 Dialogflow 不具备这些功能。

标签: actions-on-google dialogflow-es google-home


【解决方案1】:

要请求许可,您应该在代理方面,例如 google 帮助或 facebook,并且您的示例仅在 google 帮助上运行良好,但您不能直接在 dialgflow 上对其进行测试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-07
    • 1970-01-01
    • 2019-03-11
    • 2019-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多