简体   繁体   English

如何使用dialogflow-fulfillment-nodejs与Express

[英]How use dialogflow-fulfillment-nodejs with Express

I want use dialogflow fulfillment library into Express 我想使用dialogflow实现库进入Express

This is my code: 这是我的代码:

import * as express from 'express';
import * as bodyParser from 'body-parser';
import * as dialogflowController from './controllers/dialogflow';

const app: express.Application = express();
app.use(bodyParser.json());
app.post('/echo', dialogflowController.doActions);
const http = require('http');
const httpServer = http.createServer(app);
httpServer.listen(80, function () { // ascolta sulla porta 80 per comando: ngrok http 80
  console.log('HTTP Started!');
});



// dialogflowController controller unit

import { Request, Response, NextFunction } from 'express';
const { WebhookClient, Card, Suggestion } = require('dialogflow-fulfillment');


export let doActions = (req: Request, res: Response, next: NextFunction) => {
  console.log('here it works');
  const agent = new WebhookClient({ req, res });
  console.log('crashes to the previous line');
};

And this is the error 这就是错误

Error: Request can NOT be empty.
[Node]     at new WebhookClient (D:\Progetti\node_modules\dialogflow-fulfillment\src\dialogflow-fulfillment.js:58:13)
[Node]     at exports.doActions (D:\Progetti\dist\controllers\dialogflow.js:14:19)
[Node]     at Layer.handle [as handle_request] (D:\Progetti\node_modules\express\lib\router\layer.js:95:5)

Can you help me? 你能帮助我吗? How can I use the dialogflow-fulfillment-nodejs library with Express? 如何在Express中使用dialogflow-fulfillment-nodejs库?

The WebhookClient constructor takes an option object with fields request and response . WebhookClient构造函数接受带有字段requestresponse的选项对象。 You named them req and res . 你把它们命名为reqres

The constructor line should look something like this given the parameters you have to doActions() : 在给定doActions()参数的情况下,构造函数行看起来应该是这样的:

const agent = new WebhookClient({
  request: req,
  response: res
});

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

相关问题 如何使用Node.js或Python在对话框流实现中使用custom_payload - How to use custom_payload in dialogflow fulfillment using nodejs or python 如何在对话流实现中使用 OR 运算符 - How to use OR operator in dialogflow fulfillment 如何使用 nodejs 在 Dialogflow 中处理 webhook 实现 - How to handle webhook fulfillment in Dialogflow using nodejs 如何使用nodejs在对话流实现中将append数据到firebase? - How to append data to firebase in dialogflow fulfillment using nodejs? dialogflow-fulfillment-library和express,该如何处理? - dialogflow-fulfillment-library and express, what to res on? 如何在 Dialogflow 实现内联中多次使用 web 抓取? 以及如何在履行内联代码中检测错误? - How to use multiple time web scraping in Dialogflow fulfillment inline? and how to detect error at fulfillment inline code? 如何从nodejs中的内部函数调用外部函数? 我正在为 Google 对话流实现编码 - How to call outer function from inner function in nodejs? I am coding for Google dialogflow fulfillment 如何在nodejs-dialogflow中使用Dialogflow环境(beta功能) - How to use Dialogflow environments (beta feature) in nodejs-dialogflow 如何制作多语言Dialogflow Webhook /实现? - How to make a multiple language Dialogflow webhook/fulfillment? 如何通过代码在DialogFlow实现中创建意图? - How to create intent in DialogFlow Fulfillment by code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM