javascript - 节点 JS Dialogflow 错误:INVALID_ARGUMENT:未设置输入文本。?
问题描述
在向 Node JS 代码发送 POST 请求时遇到以下错误。在 stackoverflow 中有一个类似但未回答的 2 年前的问题。所以我决定问问。
我的代码:
const dialogflow=require('dialogflow');
const config=require('../config/keys');
const sessionClient = new dialogflow.SessionsClient();
const sessionPath = sessionClient.sessionPath(config.googleProjectID,config.dialogFlowSessionID)
//console.log(process.env.GOOGLE_APPLICATION_CREDENTIALS);
module.exports = app => {
app.get('/', (req, res) => {
res.send({'hello':'jhonny'})
})
app.post('/api/df_text_query', async (req, res) => {
const request = {
session: sessionPath,
queryInput: {
text: {
text: req.body.text,
languageCode: config.dialogFlowSessionLanguageCode,
},
},
};
let responses = await sessionClient
.detectIntent(request)
res.send(responses[0].queryResult)
});
app.post('/api/df_event_query', (req, res) => {
res.send({'do':'event query'})
})
}
我收到的错误:
(node:11868) UnhandledPromiseRejectionWarning: Error: 3 INVALID_ARGUMENT: Input text not set.
发布请求:
{
"text":"HI"
}
解决方案
找到了答案
我错过了头球。添加 POST 标头后已解决。
推荐阅读
- java - 使用 JOptionPane 在 Java 中执行 while 循环
- javascript - 有没有办法在反应功能组件中另一个值发生变化时自动重新渲染一个 div
- wso2 - 我可以使用 WSO2 身份服务器来限制 MQTT 订阅者可以收集的主题吗?
- javascript - 使用 Kendo 2020 上传拖放 Outlook 电子邮件问题 - 删除收件箱中的电子邮件
- firebase - Flutter:从 TextField 获取值并在函数中使用它们
- kotlin - 为什么类型转换器不起作用?机器人房间
- laravel - 数据库中的混合时区,指定哪些列存储在 UTC 与本地时区
- android - 有什么方法可以打开从 android /data/data 中提取的 .db 文件?
- python - 如何通过 Python 中的 id 呈现 django CMS 插件的 HTML
- asp.net-core - dotnet core 生成带有数据种子的迁移脚本