首页 > 解决方案 > 请求许可时的错误响应

问题描述

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

意图:

 "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 控制台日志,并且“Fulfillment”-Slider“为此事件启用 webhook 调用”已打开。

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

标签: node.jsdialogflow-esactions-on-googlegoogle-assistant-sdkfulfillment

解决方案


推荐阅读