如何从网页访问Dialogflow V2 API? [英] How to access Dialogflow V2 API from a webpage?
问题描述
我有一个网页,我想在其中使用dialogflow chatbot.这是一个自定义的聊天窗口,因此我不想使用一键式集成.我可以使用javascript/ajax访问聊天代理 V1 API (通过在请求标头中传递客户端访问令牌).
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).
但是我不知道如何在 V2 API 中做到这一点.对我而言,dialogflow文档不清晰(我通过引用此链接.我不知道如何继续操作.我也不熟悉Google Cloud.因此,非常感谢您了解一个工作示例或逐步访问API指南的方法.
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.
推荐答案
您可以使用Dialogflow Rest API,您需要使用Google cloud sdk(范围:云平台,dialogflow)生成访问令牌
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',
},
}
}
触发事件:
{
queryInput: {
event: {
name: action.payload.event,
languageCode: 'en-US',
},
}
}
sessionId
=>您的用户的唯一ID
sessionId
=> unique Id for your user
这篇关于如何从网页访问Dialogflow V2 API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!