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:
JavaScript
x
35
35
1
const dialogflow=require('dialogflow');
2
const config=require('../config/keys');
3
4
const sessionClient = new dialogflow.SessionsClient();
5
const sessionPath = sessionClient.sessionPath(config.googleProjectID,config.dialogFlowSessionID)
6
//console.log(process.env.GOOGLE_APPLICATION_CREDENTIALS);
7
8
module.exports = app => {
9
10
app.get('/', (req, res) => {
11
res.send({'hello':'jhonny'})
12
})
13
app.post('/api/df_text_query', async (req, res) => {
14
const request = {
15
session: sessionPath,
16
queryInput: {
17
text: {
18
text: req.body.text,
19
languageCode: config.dialogFlowSessionLanguageCode,
20
},
21
},
22
};
23
24
let responses = await sessionClient
25
.detectIntent(request)
26
res.send(responses[0].queryResult)
27
});
28
29
30
app.post('/api/df_event_query', (req, res) => {
31
res.send({'do':'event query'})
32
})
33
34
}
35
Error i received:
JavaScript
1
2
1
(node:11868) UnhandledPromiseRejectionWarning: Error: 3 INVALID_ARGUMENT: Input text not set.
2
POST request :
JavaScript
1
4
1
{
2
"text":"HI"
3
}
4
Advertisement
Answer
Found the answer
I had missed the header. It was solved after adding the POST header.