如何解决此对话流错误:未设置文本输入?



我在向给定的 Nodejs 代码发送以下 post 请求时收到错误。我在这里使用对话流API。

错误:

Error: Input text not set.
at Http2CallStream.call.on (/home/user/coding/chatbot/node_modules/@grpc/grpc-js/build/src/client.js:96:45)
at Http2CallStream.emit (events.js:203:15)
at process.nextTick (/home/user/coding/chatbot/node_modules/@grpc/grpc-js/build/src/call-stream.js:71:22)
at process._tickCallback (internal/process/next_tick.js:61:11)

法典:

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);
});

开机自检请求 :

{
"text":"HI"  
}
compare your code with this. Mine works..
const dialogflow = require("dialogflow");
const config = require("../config/keys");
// const { query } = require("express");
const sessionClient = new dialogflow.SessionsClient();
const sessionPath = sessionClient.sessionPath(
config.googleProjectID,
config.dialogFlowSessionID
);
module.exports = (app) => {
app.get("/", (req, res) => {
res.send({ hello: "AusTINE" });
});
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)
.then((responses) => {
console.log("Detected intent");
const result = responses[0].queryResult;
console.log(`  Query: ${result.queryText}`);
console.log(`  Response: ${result.fulfillmentText}`);
if (result.intent) {
console.log(`  Intent: ${result.intent.displayName}`);
} else {
console.log(`  No intent matched.`);
}
})
.catch((err) => {
console.error("ERROR:", err);
});
res.send({ do: "text query" });
});
app.post("/api/df_event_query", (req, res) => {
res.send({ do: "event query" });
});
};