简体   繁体   English

如何在 DialogFlow 的 Package.json 文件中添加新的依赖项?

[英]How to add new dependency in Package.json file in DialogFlow?

I just started creating a chatbot and I want it to be multilingual.我刚开始创建一个聊天机器人,我希望它是多语言的。 So, I am using i18n module for the same.所以,我同样使用i18n 模块 I added it's dependency in the package.json but now it is showing an error:我在 package.json 中添加了它的依赖项,但现在显示错误:

The deployment of your Cloud Function failed:
Build failed: Build error details not available

This is my package.json file:这是我的 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": "8"
  },
  "scripts": {
    "start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
    "deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
  },
  "dependencies": {
    "actions-on-google": "^2.2.0",
    "firebase-admin": "^5.13.1",
    "firebase-functions": "^2.0.2",
    "dialogflow": "^0.6.0",
    "dialogflow-fulfillment": "^0.5.0"
  }
},
 {
  "name": "i18n",
  "description": "lightweight translation module with dynamic json storage",
  "version": "0.8.4",
  "homepage": "http://github.com/mashpie/i18n-node",
  "repository": {
    "type": "git",
    "url": "http://github.com/mashpie/i18n-node.git"
  },
  "author": "Marcus Spiegel <marcus.spiegel@gmail.com>",
  "main": "./index",
  "keywords": [
    "template",
    "i18n",
    "l10n"
  ],
  "directories": {
    "lib": "."
  },
  "dependencies": {
    "debug": "*",
    "make-plural": "^6.0.1",
    "math-interval-parser": "^2.0.1",
    "messageformat": "^2.3.0",
    "mustache": "*",
    "sprintf-js": "^1.1.2"
  },
  "devDependencies": {
    "async": "^3.1.0",
    "cookie-parser": "^1.4.4",
    "express": "^4.16.4",
    "jshint": "*",
    "mocha": "^6.2.2",
    "should": "*",
    "sinon": "*",
    "url": "^0.11.0",
    "zombie": "*"
  },
  "engines": {
    "node": ">=0.10.0"
  },
  "scripts": {
    "jshint": "jshint --verbose .",
    "test": "npm run jshint && mocha --exit",
    "test-ci": "npm run jshint && istanbul cover mocha -- --exit"
  },
  "license": "MIT"
}]

And this is my index.js file:这是我的 index.js 文件:

// See https://github.com/dialogflow/dialogflow-fulfillment-nodejs
// for Dialogflow fulfillment library docs, samples, and to report issues
'use strict';

const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const i18n= require('i18n');

process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements

i18n.configure({
    locales : ['en-IN','hi-IN-1'],
    directory : '',
    defaultLocale : 'en-IN'
});

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const agent = new WebhookClient({ request, response });
  console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
  console.log('Dialogflow Request body: ' + JSON.stringify(request.body));

  function welcome(agent) {
    agent.add(`Welcome to my agent!`);
  }

  function fallback(agent) {
    agent.add(`I didn't understand`);
    agent.add(`I'm sorry, can you try again?`);
  }

  function About(agent){
    agent.add(`We are a company!`);
  }

  // // Uncomment and edit to make your own intent handler
  // // uncomment `intentMap.set('your intent name here', yourFunctionHandler);`
  // // below to get this function to be run when a Dialogflow intent is matched
  // function yourFunctionHandler(agent) {
  //   agent.add(`This message is from Dialogflow's Cloud Functions for Firebase editor!`);
  //   agent.add(new Card({
  //       title: `Title: this is a card title`,
  //       imageUrl: 'https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png',
  //       text: `This is the body text of a card.  You can even use line\n  breaks and emoji! 💁`,
  //       buttonText: 'This is a button',
  //       buttonUrl: 'https://assistant.google.com/'
  //     })
  //   );
  //   agent.add(new Suggestion(`Quick Reply`));
  //   agent.add(new Suggestion(`Suggestion`));
  //   agent.setContext({ name: 'weather', lifespan: 2, parameters: { city: 'Rome' }});
  // }

  // // Uncomment and edit to make your own Google Assistant intent handler
  // // uncomment `intentMap.set('your intent name here', googleAssistantHandler);`
  // // below to get this function to be run when a Dialogflow intent is matched
  // function googleAssistantHandler(agent) {
  //   let conv = agent.conv(); // Get Actions on Google library conv instance
  //   conv.ask('Hello from the Actions on Google client library!') // Use Actions on Google library
  //   agent.add(conv); // Add Actions on Google library responses to your agent's response
  // }
  // // See https://github.com/dialogflow/fulfillment-actions-library-nodejs
  // // for a complete Dialogflow fulfillment library Actions on Google client library v2 integration sample

  // Run the proper function handler based on the matched Dialogflow intent name
  let intentMap = new Map();
  intentMap.set('Default Welcome Intent', welcome);
  intentMap.set('Default Fallback Intent', fallback);
   intentMap.set('About the company', About);
  // intentMap.set('your intent name here', googleAssistantHandler);
  agent.handleRequest(intentMap);
});

Most probably, the error is in the JSON file.最有可能的错误是在 JSON 文件中。 Can anybody please help me with this?有人可以帮我解决这个问题吗?

You appear to be using multiple objects in a list inside your package.json file, I'm not sure if this is how package.json files are meant to work.您似乎在 package.json 文件中的列表中使用了多个对象,我不确定 package.json 文件是否应该这样工作。

[{

},{

}]

Could you try compress all your sections down into a single object, eg.您能否尝试将所有部分压缩成一个对象,例如。

{

}

ie, move dependencies into a single section etc.即,将依赖项移动到单个部分等。

You can add the npm package: i18n to your dependencies object in package.json like this:您可以将 npm package: i18n 添加到 package.json 中的依赖项对象,如下所示:

"dependencies": {
  "actions-on-google": "^2.2.0",
  "firebase-admin": "^5.13.1",
  "firebase-functions": "^2.0.2",
  "dialogflow": "^0.6.0",
  "dialogflow-fulfillment": "^0.5.0",
  "i18n" : "^0.8.4"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在以后向package.json添加依赖项 - How to add dependency to package.json later 如何在 package.json 中添加新脚本 - How to add a new script in package.json 如果第二个项目的package.json不在项目的根目录中,如何在package.json中添加github依赖关系 - How to add github dependency in package.json if package.json of second project not in the root of the project 如何在我的package.json中添加非npm依赖项? - How to add a non-npm dependency to my package.json? 如何配置package.json以添加“自编译二进制文件”作为依赖项? - How to configure package.json to add a “self compiled binary” as a dependency? 在现有的package.json中安装新的依赖项 - Installing a new dependency in existing package.json Dialogflow Package.json 更新 - Dialogflow Package.json Updates package.json —在删除package.json之后,如何在package.json文件的&#39;dependencies&#39;和&#39;devDependencies&#39;中添加已安装的软件包? - package.json — How to add already installed packages in 'dependencies' and 'devDependencies' in package.json file after delete package.json? 如何在package.json中为gitrepository定义依赖项? - How to define dependency in package.json for gitrepository? 安装新模块后如何刷新 package.json 文件? - how to refresh package.json file after install a new module?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM