I have been using DialogFlow v1 before using simply jquery and it was pretty straigh forward working!
Now that I have to switch to V2 I am stuck on how to keep somehow same code but just modify with the V2!
I have been looking at this client library for V2: https://github.com/dialogflow/dialogflow-nodejs-client-v2#using-the-client-library
But I dont wanna use Node.js I just dont want to do somthing like node server.js to run the app, also I am not sure if I can mix jQuery with Node.js.
My previous code v1 looked like this:
fetch(url, {
body: JSON.stringify(data),
// cache: 'no-cache',
// credentials: 'same-origin',
headers: {
'content-type': 'application/json',
"Authorization": "Bearer " + configs.accessToken,
},
method: 'POST',
mode: 'cors',
redirect: 'follow',
referrer: 'no-referrer',
})
.then(response => response.json()) // parses response to JSON
Well I swtiched to ES6 for making http request for dialogflow but I would want the same code to use for V2, is this possible? Also I can no longer see access token for v2, how are we suppose to handle the auth for http calls?
I am really confused with the new V2 and since we switched to Enterprise Edition Account it is a must for us to use v2 and it kinda sucks!
Edit: I am checking this example from documentation:
POST https://dialogflow.googleapis.com/v2beta1/projects/project-name/agent/intents
Headers:
Authorization: Bearer $(gcloud auth print-access-token)
Content-Type: application/json
POST body:
{
'displayName': 'StartStopwatch',
'priority': 500000,
'mlEnabled': true,
'trainingPhrases': [
{
'type': 'EXAMPLE',
'parts': [
{
'text': 'start stopwatch'
}
]
}
],
'action': 'start',
'messages': [
{
'text': {
'text': [
'Stopwatch started'
]
}
}
],
}
But I am somehow confused on this part: Authorization: Bearer $(gcloud auth print-access-token)
where do I get access-token?
I have already done this part: gcloud auth activate-service-account --key-file= which I have no idea what is it doing after activating! I was hoping I would get back some access-token from this, but there seem to be nothing just a message that says Activated Service...