Mayur Choudhary
Mayur Choudhary

Reputation: 31

How to solve this dialogflow error : text input not set?

I am getting an error while sending the following post request to the given Nodejs code. I am using Dialogflow API here.

Error :

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)

CODE :

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 request :

{
 "text":"HI"  
}

Upvotes: 3

Views: 1177

Answers (1)

Bazz_code
Bazz_code

Reputation: 11

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

Upvotes: 1

Related Questions