How to install npm packages within Google Dialogflow Fullfilment Inline Editor

让人想犯罪 __ 提交于 2019-12-07 08:55:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!