Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何在Express中使用dialogflow实现节点_Node.js_Express_Dialogflow Es - Fatal编程技术网

Node.js 如何在Express中使用dialogflow实现节点

Node.js 如何在Express中使用dialogflow实现节点,node.js,express,dialogflow-es,Node.js,Express,Dialogflow Es,我想在Express中使用dialogflow实现库 这是我的代码: 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()

我想在Express中使用dialogflow实现库

这是我的代码:

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');
};
这就是错误所在

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)
你能帮我吗?
如何将dialogflow fulfillment nodejs库与Express一起使用?

WebhookClient构造函数使用带有字段
request
response
的option对象。您将它们命名为
req
res

考虑到必须使用的参数
doActions()
,构造函数行应该是这样的:


您需要使用主体解析器。看看这个例子:谢谢,伙计。这就是我要找的
const agent = new WebhookClient({
  request: req,
  response: res
});