I have a problem with my chatbot Application. I just don't find the mistake why I can't call the dialogflow api with my request from code tough it works with the exact same request from postman. Even the dialogflow support says that the request is correct.
Can it be blocked somehow from dialogflow? Or does it not automatically change the javascript code into a json object?
Below I send you the code of my application (code snippet 1), the actual result from the code request (code snippet 2), the wanted result as it comes back when I use postman (code snippet 3), and the screenshot of the intent in dialogflow (screenshot 1).
code snippet 1: code of my application
const fetchAnswerFromDialogflow = async (userInput, currentChatbotInEdit) => {
const config = {
headers: {
Authorization: "Bearer " + clientToken,
"Content-Type": "application/json; charset=utf-8",
},
};
const request = {
queryParams: {
contexts: [
{
name:
`projects/myteachingbot-arxmxd/agent/sessions/myteachingbot-session${state.sessionId}/contexts/Chatbotcontext726`,
lifespanCount: 1,
},
{
name:
`projects/myteachingbot-arxmxd/agent/sessions/myteachingbot-session${state.sessionId}/contexts/Chatbotcontext7262`
inputContext1,
lifespanCount: 1,
},
],
resetContexts: true,
},
queryInput: {
text: {
text: userInput,
languageCode: "en-US",
},
},
};
try {
const res = await axios.post(
`https://dialogflow.googleapis.com/v2/projects/myteachingbot-arxmxd/agent/sessions/myteachingbot-session${state.sessionId}:detectIntent`,
request,
config
);
console.log(res);
}
code snippet 2: the actual result from the code request
{
"responseId": "8a9ead3d-f3ea-4a75-b110-257454069382-425db6e2",
"queryResult": {
"queryText": "start",
"parameters": {},
"languageCode": "en"
}
}
code snippet 3: the wanted result that I get returned from postman:
{
"responseId": "f8ea7646-576a-4789-a88f-d0f80416de84-425db6e2",
"queryResult": {
"queryText": "start",
"parameters": {},
"allRequiredParamsPresent": true,
"fulfillmentText": "Frage 1",
"fulfillmentMessages": [
{
"text": {
"text": [
"Frage 1"
]
}
}
],
"intent": {
"name": "projects/myteachingbot-arxmxd/agent/intents/70aa4273-5368-4a40-acc3-484c8ad415df",
"displayName": "Frage7261"
},
"intentDetectionConfidence": 1,
"languageCode": "en"
}
}