问题
I would like to install some npm packages into my chatbot but I cant make this working.
package.json file looks as below:
{
"name": "dialogflowFirebaseFulfillment",
"description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
"engines": {
"node": "~6.0"
},
"scripts": {
"start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
"deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
},
"dependencies": {
"actions-on-google": "^1.5.x",
"firebase-admin": "^4.2.1",
"firebase-functions": "^0.5.7",
"apiai": "^4.0.3"
}
}
In index.js I have:
var jsonQuery = require('json-query');
The logs says: dialogflowFirebaseFulfillment Function load error: Code in file index.js can't be loaded. Did you list all required modules in the package.json
Any idea?
回答1:
The error arrived because you didn't include package 'json-query'
run below command after all working fine.
npm install json-query
回答2:
Answer is simpler than you would think (and @Dhaval mentioned it). You only have to include the name of the npm package in package.json
:
{
"some": "crazyPropsFoo",
"engines": {},
"scripts": {},
"dependencies": {
"actions-on-google": "^1.5.x",
"firebase-admin": "~4.1.2",
"firebase-functions": "~0.5",
"npmpackage": "1.8.0", //Here it is
"apiai": "^4.0.3"
}
}
Then require
that package in your index.js
file:
var PackageObj = require("npmpackage").PackageObject;
var yourVar = new PackageObj();
来源:https://stackoverflow.com/questions/48015803/how-to-install-npm-packages-within-google-dialogflow-fullfilment-inline-editor