要求许可时出现格式错误的响应

时间:2018-10-20 17:25:02

标签: node.js dialogflow actions-on-google google-assistant-sdk fulfillment

我正在努力创建一个非常基本的示例,要求用户许可。设置是

意图:

 "request_permission":
   - phrase "where am I?"
   - action: "request_permission"
   - events: <empty>
 "user_info":
   - phrase: <empty>
   - action: "user_info"
   - events: "actions_intent_PERMISSION" 

在使用node.js履行库的官方示例之后,我写道:

'use strict';

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

const app = dialogflow({debug: true});

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

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const agent = new WebhookClient({ request, response });
  const app = new DialogflowApp({request, response});

  function welcome_intent(agent) {agent.add(`welcome intent`); }
  function fallback_intent(agent) {agent.add(`fallback intent.`); }

  function request_permission(agent){
    let conv = agent.conv();
    conv.ask(new Permission({
      context: 'I need your location',
      permissions: 'DEVICE_COARSE_LOCATION'
    }))
    agent.add(conv);
  }

  function user_info(agent){
    if (app.isPermissionGranted()) {
      const zipCode = app.getDeviceLocation().zipCode;
      if (zipCode) {
          app.tell(`your zip code ise ${zipCode}`);
      } else {
          app.tell('I cannot tell your zip code.');
      }
    } else {
        app.tell('Without permission I cannot tell the zip code');
    }
  }

  let intentMap = new Map();
  intentMap.set('Default Welcome Intent', welcome_intent);
  intentMap.set('Default Fallback Intent', fallback_intent);
  intentMap.set('request_permission', request_permission);
  intentMap.set('user_info', user_info);
  agent.handleRequest(intentMap);
});

仍然,当启动模拟器并激活我的应用程序,然后问“我在哪里?”时,我得到

MalformedResponse
'final_response' must be set.

是的,我确实检查了Firebase控制台日志,并且“实现”-滑块“为此事件启用webhook调用”已打开。

在这里我不会问是否有一个V2兼容的示例具有非常基本的权限请求。我知道Dialogflow v2 API + Actions v2 API: MalformedResponse 'final_response' must be set

中的答案

0 个答案:

没有答案