MalformedResponse при запросе разрешения - PullRequest
0 голосов
/ 20 октября 2018

Я пытаюсь создать очень простой пример, запрашивающий у пользователя разрешение.Настройка:

Содержание:

 "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 "Включить вызов веб-крюка для этого события" включен.

Я бы не спрашивалздесь, если бы был V2-совместимый пример с очень простым запросом разрешения.Мне известен ответ в Dialogflow v2 API + Actions v2 API: MalformedResponse 'final_response' должен быть установлен

...