简体   繁体   中英

DialogFlow Webhook : Error: EROFS: read-only file system, open '.node-xmlhttprequest-sync-2'

I'm creating DialogFlow app and deployed fulfillment with Cloud Functions for Firebase which uses XMLHttpRequest. But following error occurred.

Error: EROFS: read-only file system, open '.node-xmlhttprequest-sync-2' at Error (native) at Object.fs.openSync (fs.js:642:18) at Object.fs.writeFileSync (fs.js:1348:33) at send (/user_code/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:477:10)

My code is something like this.

'use strict';

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

const DialogflowApp = require('actions-on-google').DialogflowApp; 
const XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
const googleAssistantRequest = 'google';

const Actions = {
  UNRECOGNIZED_DEEP_LINK: 'deeplink.unknown',
  TEST_HTTPREQUEST: 'test.httprequest'
};

const testHttpRequest = app => {
    var req = new XMLHttpRequest();
    req.open('GET', 'http://www.google.com', false);
    req.send(); 
    if (req.status === 200) {
      console.log(req.responseText);
    }
}

const actionMap = new Map();
actionMap.set(Actions.TEST_HTTPREQUEST, testHttpRequest);

exports.mytestapp = functions.https.onRequest((request, response) => {
  const app = new DialogflowApp({ request, response });
  console.log(`Request headers: ${JSON.stringify(request.headers)}`);
  console.log(`Request body: ${JSON.stringify(request.body)}`);
  app.handleRequest(actionMap);
});

Does anyone have idea on how to solve this error?

Your function testHttpRequest needs to use app to respond to the user's request from Dialogflow. Use the ask or tell methods to respond to the request. For example after the if statement in testHttpRequest you could add:

app.tell('This response came from Cloud Functions for Firebase!');

which tells the Action on Google client library to send the string as a response to your request when you call your Assistant app from the Action on Google simulator or Google Assistant device (see Action on Google testing docs).

You may also be running into a issue with action names. The action you refer to in your fulfillment here ( deeplink.unknown and test.httprequest ) must also be list as an action in an intent in your Dialogflow agent otherwise your code will never be triggered. The Google Assistant also requires a welcome intent. By default the welcome intent in Dialogflow has an action of input.welcome which is not included in your code so you code may not be trigger until you match the actions listed in your code and in your Dialogflow agent.

Furthermore external HTTP calls (outside the Google's network) are not permitted on Cloud Functions without setting up billing first .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM