0

I am struggling on creating a very basic example asking the user for permission. The setup is

Intents:

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

Following the official example using the node.js fulfillment library, I write:

'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);
});

Still, when starting the simulator and activating my app and then asking "where am I?" I get

MalformedResponse
'final_response' must be set.

And yes, I did check the firebase console logs and the "Fulfillment"-Slider "Enable webhook call for this event" is on.

I wouldn't ask here if there would a V2 compatible example with a very basic permission request. I am aware of the answer in Dialogflow v2 API + Actions v2 API: MalformedResponse 'final_response' must be set

Patwie
  • 4,360
  • 1
  • 21
  • 41
  • This seems similar to a duplicate of this question, with the core issue being a mix of Actions on Google and Dialogflow. – Nick Felker Oct 20 '18 at 20:30
  • https://stackoverflow.com/questions/52833499/getting-device-location-as-empty-in-dialogflow-webhook-request/52841084?noredirect=1#comment92610661_52841084 – Nick Felker Oct 20 '18 at 20:30

0 Answers0