问题
I have a webpage where I want to use dialogflow chatbot. This is a custom chat window, so I don't want to use one click integration. I am able to access the chat agent V1 API using javascript/ajax (by passing client access token in the request header).
But I don't know how to do it in V2 API. The dialogflow documentation is not clear to me(I have setup Authentication by referring this link. I don't know how to proceed further). I'm not familiar with Google cloud either. So a working sample or a step by step how to access the API guideline will be very much appreciated.
回答1:
You can use Dialogflow Rest APIs, You need to generate access token with Google cloud sdk (scope: cloud platform, dialogflow)
public df_client_call(request) {
var config = {
headers: {
'Authorization': "Bearer " + this.accessToken,
'Content-Type': 'application/json; charset=utf-8'
}
};
return this.http.post(
'https://dialogflow.googleapis.com/v2/projects/' + environment.project_id +
'/agent/sessions/' + sessionId + ':detectIntent',
request,
config
)
}
In the request you have to pass,
{
queryInput: {
text: {
text: action.payload.text,
languageCode: 'en-US',
},
}
}
to trigger Event:,
{
queryInput: {
event: {
name: action.payload.event,
languageCode: 'en-US',
},
}
}
sessionId
=> unique Id for your user
来源:https://stackoverflow.com/questions/48201131/how-to-access-dialogflow-v2-api-from-a-webpage