Skip to content
Advertisement

Node JS Dialogflow error :INVALID_ARGUMENT: Input text not set.?

I encountered the following error while sending POST request to the Node JS code. There was a similar but unanswered 2 years old question in stackoverflow. So I decided to ask.

My code:

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

}

Error i received:

(node:11868) UnhandledPromiseRejectionWarning: Error: 3 INVALID_ARGUMENT: Input text not set.

POST request :

{
 "text":"HI"  
}

Advertisement

Answer

Found the answer

I had missed the header. It was solved after adding the POST header.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement