如何在Express中使用dialogflow-fulfillment-nodejs [英] How use dialogflow-fulfillment-nodejs with Express

查看:94
本文介绍了如何在Express中使用dialogflow-fulfillment-nodejs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Express中使用对话框流程实现库

I want use dialogflow fulfillment library into Express

这是我的代码:

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)

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

Can you help me? How can I use the dialogflow-fulfillment-nodejs library with Express?

推荐答案

WebhookClient 构造函数采用一个选项对象,该对象具有字段 request response 。您将它们命名为 req res

The WebhookClient constructor takes an option object with fields request and response. You named them req and res.

构造函数给定您必须 doActions()的参数,该行应类似于以下内容:

The constructor line should look something like this given the parameters you have to doActions():

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

这篇关于如何在Express中使用dialogflow-fulfillment-nodejs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆