【问题标题】:How to get the current location of a user in Dialogflow chatbot?如何在 Dialogflow 聊天机器人中获取用户的当前位置?
【发布时间】:2020-08-08 14:39:55
【问题描述】:

我正在尝试在 Dialogflow 中获取用户位置,但目前无法获取。

我找到了有关如何使用 Google 帮助在 Dialogflow 中获取位置的信息,例如 article。问题是我只想用聊天机器人来做这件事并在那里得到回应。我也尝试了下面的代码,但仍然无法正常工作:

'use strict';

const functions = require('firebase-functions');
const admin = require('firebase-admin');


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 });
  console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
  console.log('Dialogflow Request body: ' + JSON.stringify(request.body));

   function requestPermission(agent) {
    agent.requestSource = agent.ACTIONS_ON_GOOGLE;
    let conv = agent.conv();
    console.log('conv '+conv);
    conv.ask(new Permission({
    context: 'to locate you',
    permissions: 'DEVICE_PRECISE_LOCATION',
    }));
    agent.add(conv); // Please add this

    }

  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?`);
  }



  let intentMap = new Map();
  intentMap.set('Default Welcome Intent', welcome);
  intentMap.set('Default Fallback Intent', fallback);

  intentMap.set('request_permission', requestPermission);

  agent.handleRequest(intentMap);
});

我添加了一个意图调用“request_permission”。如有任何帮助或建议,我将不胜感激。

【问题讨论】:

    标签: dialogflow-es dialogflow-es-fulfillment


    【解决方案1】:

    Dialogflow 中没有通用的解决方案来获取位置。并非所有使用 Dialogflow 的系统都可以自动传输位置,而其他系统则通过消息使用不同的方式。

    Actions on Google 的解决方案仅适用于 Google 助理。

    【讨论】:

      猜你喜欢
      • 2016-09-13
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多