首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Express中使用dialogflow-fulfillment nodejs

如何在Express中使用dialogflow-fulfillment nodejs
EN

Stack Overflow用户
提问于 2018-06-12 21:31:18
回答 1查看 1.4K关注 0票数 3

我想在Express中使用dialogflow实现库

这是我的代码:

代码语言:javascript
复制
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');
};

这就是错误

代码语言:javascript
复制
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)

你能帮帮我吗?如何在Express中使用dialogflow-fulfillment nodejs库?

EN

回答 1

Stack Overflow用户

发布于 2018-06-12 21:45:48

WebhookClient构造函数接受一个带有字段requestresponse的option对象。你给它们取名为reqres

给定doActions()所需的参数,构造函数行应如下所示

代码语言:javascript
复制
const agent = new WebhookClient({
  request: req,
  response: res
});
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50818512

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档