javascript - 如何解决此 dialogflow 错误 : text input not set?

标签 javascript node.js dialogflow-es

我在向给定的 Nodejs 代码发送以下发布请求时遇到错误。我在这里使用 Dialogflow 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);
  });

POST 请求:

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

关于javascript - 如何解决此 dialogflow 错误 : text input not set?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58085731/

相关文章:

javascript - 将 maxDataPoints 放入 grafana 数据源中

javascript - 无法在 firestore 数据库中添加多个字段,但在添加单个字段时工作正常

javascript - 在 BIRT 中显示修改后的参数值

Javascript - 在函数完成后执行文档调用

node.js - Node 从 axios post 接收 post json

node.js - Socket.IO + Node.js + SSL

node.js - Mongoose 如何结合查找、排序、$ 和

node.js - Dialogflow actions-on-google : Unable to make Rest api calls before setting the response

python - 我无法安装库 grpcio

javascript - 在 JSON 响应中搜索关键字