如何在Google Dialogflow Fullfilment内联编辑器中安装npm软件包

时间:2017-12-28 23:50:34

标签: javascript node.js firebase google-cloud-functions package.json

我想在我的聊天机器人中安装一些npm软件包,但我无法使其正常工作。

package.json文件如下所示:

{
  "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"
  }
}

在index.js中我有:

var jsonQuery = require('json-query');

日志说: dialogflowFirebaseFulfillment函数加载错误:无法加载文件index.js中的代码。您是否在package.json

中列出了所有必需的模块

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

错误到了,因为您没有包含' json-query'

在所有工作正常后运行以下命令。

 function getItinerary (){ 
    $.ajax({
        url: 'php/itinerary.php',
        type: 'POST',
        dataType: 'json',
        data: {action: 'LOAD'}, //Here put two mode keys and values, userId and attractionId like {userId: '<value here required by your server>',attractionId: '<value here required by your server>'}
        success: function(data) {
            console.log(data);
            alert('request successful');
        },
        error: function () {
            alert('Network or Server error');
        }
    });
}

答案 1 :(得分:0)

答案比你想象的要简单(@Dhaval提到它)。您只需在package.json中包含npm包的名称:

{
"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"
  }
}

然后require index.js文件中的var PackageObj = require("npmpackage").PackageObject; var yourVar = new PackageObj(); 个包:

Select2