简体   繁体   English

没有Firebase的Dialogflow Node.js实现

[英]Dialogflow nodejs fulfilment without firebase

I am trying to build my webhooks using nodejs and without using firebase. 我正在尝试使用nodejs而不使用firebase构建我的webhooks。 I found a resource and built my index.js file like this: 我找到了一个资源,并像这样构建了index.js文件:

const express = require('express');
const bodyParser = require('body-parser');
const {
    dialogflow
} = require('actions-on-google');

const PORT = process.env.PORT || 5000;
const app = dialogflow({
    debug: true
});
const server = express()
    .use(bodyParser.urlencoded({
        extended: true
    }))
    .use(bodyParser.json(), app)
    .listen(PORT, () => console.log(`Listening on ${ PORT }`));

// Handle the Dialogflow intent named 'Default Welcome Intent'.
app.intent('Default Welcome Intent', (conv) => {
    const name = conv.user.storage.userName;
    if (!name) {
      // Asks the user's permission to know their name, for personalization.
      conv.ask(new Permission({
        context: 'Hi there, to get to know you better',
        permissions: 'NAME',
      }));
    } else {
      conv.ask(`Hi again, ${name}. What are you looking for?`);
    }
  });

  // Handle the Dialogflow intent named 'actions_intent_PERMISSION'. If user
  // agreed to PERMISSION prompt, then boolean value 'permissionGranted' is true.
  app.intent('actions_intent_PERMISSION', (conv, params, permissionGranted) => {
    if (!permissionGranted) {
      // If the user denied our request, go ahead with the conversation.
      conv.ask(`OK, no worries. What are you looking for?`);
      conv.ask(new Suggestions('Blue', 'Red', 'Green'));
    } else {
      // If the user accepted our request, store their name in
      // the 'conv.user.storage' object for future conversations.
      conv.user.storage.userName = conv.user.name.display;
      conv.ask(`Thanks, ${conv.user.storage.userName}. ` +
        `What are you looking for?`);
      conv.ask(new Suggestions('Blue', 'Red', 'Green'));
    }
  });

  // Handle the Dialogflow NO_INPUT intent.
  // Triggered when the user doesn't provide input to the Action
  app.intent('actions_intent_NO_INPUT', (conv) => {
    // Use the number of reprompts to vary response
    const repromptCount = parseInt(conv.arguments.get('REPROMPT_COUNT'));
    if (repromptCount === 0) {
      conv.ask('Which color would you like to hear about?');
    } else if (repromptCount === 1) {
      conv.ask(`Please say the name of a color.`);
    } else if (conv.arguments.get('IS_FINAL_REPROMPT')) {
      conv.close(`Sorry we're having trouble. Let's ` +
        `try this again later. Goodbye.`);
    }
  });    

module.exports = server;

My NodeJs application just consists of index.js and package.json . 我的NodeJs应用程序仅由index.jspackage.json组成 I did an npm install and then ftped the two files and node_modules to my azure web application. 我进行了npm install ,然后将两个文件和node_modules通过ftp传输到了Azure Web应用程序。 When I tested my google actions application, it gets a webhook error because it can't communicate. 当我测试我的google action应用程序时,由于无法通信而收到了webhook错误。

Can someone tell me what I need to do to get it to work? 有人可以告诉我要使其正常工作需要做什么吗?

PS: This is my package.json : PS:这是我的package.json

{
  "name": "pyb-actions",
  "description": "Actions on Google for PYB",
  "author": "r3plica",
  "private": true,
  "scripts": {
    "lint": "eslint .",
    "start": "npm run shell"
  },
  "dependencies": {
    "actions-on-google": "^2.0.0",
    "express": "^4.16.4",
    "i18n": "^0.8.3"
  },
  "devDependencies": {
    "eslint": "^4.19.0",
    "eslint-config-google": "^0.9.1"
  }
}

Try to create a simpel get-route to test if the problem is related to your server setup or the way you initialize the app. 尝试创建一个简单的get-route来测试问题是否与服务器设置或初始化应用程序的方式有关。

app.get('/', function(request,response) {
  response.json({
    "response": "The server is runnning"
  });
});

Or, try to forward your localhost via ngrok and use that as temporary fulfillment webhook. 或者,尝试通过ngrok转发您的本地主机并将其用作临时实现Webhook。

Here's my index.js for inspiration: 这是我的index.js的启发:

const express = require('express');
const bodyParser = require('body-parser')
const { dialogflow } = require('actions-on-google')
const intents = require('./intents')

const expressApp = express().use(bodyParser.json())
const app = dialogflow()

app.intent('Welcome', intents.welcome)

expressApp.post('/fulfill', (req, resp) => app)

expressApp.listen(process.env.PORT || 3000, '0.0.0.0', () => {
  console.log("server starting " + (process.env.PORT || 3000));
})

Hope it helps 希望能帮助到你

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

相关问题 Dialogflow CX webhook 用于实现使用 nodejs 回复用户 - Dialogflow CX webhook for fulfilment to reply user using nodejs Dialogflow-编码完成时处理用户差异 - Dialogflow - Dealing with user discrepancy when coding fulfilment 如何使用nodejs在对话流实现中将append数据到firebase? - How to append data to firebase in dialogflow fulfillment using nodejs? 使用 request-promise-native 实现 Dialogflow:无法解析响应 - Dialogflow fulfilment using request-promise-native : unable to parse response Dialogflow fulfillment webhook url 支持自签名证书吗? - Dialogflow fulfilment webhook url support self signed certificates? 没有沙箱的 Actions SDK dialogflow nodejs 事务 API 示例 - Actions SDK dialogflow nodejs transactions API example without sandbox 在 Dialogflow Nodejs 中发送图像 - Send Image in Dialogflow Nodejs 如何从参数获取实体并在Dialogflow内联编辑器中创建if条件以实现 - How to get entity from the argument and create if condition in Dialogflow Inline editor for fulfilment 如何在没有Firebase的情况下使用DialogFlow,node.js v2库 - How to use DialogFlow, node.js v2 library without Firebase Dialogflow NodeJS Knowledge IAM 权限 - Dialogflow NodeJS Knowledge IAM permission
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM