简体   繁体   English

如何在 Dialogflow 中为多语言代理实现语言切换?

[英]How to implement a language switch for a multilingual agent in Dialogflow?

I am using Google Dialogflow (with V2 API) and I want to build a bot that can switch between multiple languages if desired by the user.我正在使用 Google Dialogflow(带有 V2 API)并且我想构建一个可以根据用户需要在多种语言之间切换的机器人。

I have set up all intents in different languages and now I want users to be able to select one, eg by sending a simple message or by using a predefined button (this implementation detail is not yet certain but will probably not affect the problem anyway).我已经用不同的语言设置了所有意图,现在我希望用户能够选择一个,例如通过发送一条简单的消息或使用一个预定义的按钮(这个实现细节还不确定,但可能不会影响问题) .

I know that the detectIntent method has a languageCode parameter, which is optional as far as I understand.我知道detectIntent方法有一个languageCode参数,据我所知这是可选的。

In the Dialogflow API environment at developers.google.com/apis-explorer , I can send the following request to my agent:developers.google.com/apis-explorer的 Dialogflow API 环境中,我可以向我的代理发送以下请求:

POST https://dialogflow.googleapis.com/v2/projects/<session>/agent/sessions/new:detectIntent?key={YOUR_API_KEY}

{
 "queryInput": {
  "text": {
   "text": "hi",
   "languageCode": "en-EN"
  }
 }
}

When sending a queryInput including a languageCode , the agent responds in the corresponding language, allowing to switch even mid-conversation, which I think is a great feature.当发送包含languageCodequeryInput时,代理会以相应的语言进行响应,甚至允许在对话中切换,我认为这是一个很棒的功能。

In other words, the language switch works fine in this testing environment, where you can manually send the languageCode parameter with each query, and change it if you want.换句话说,语言切换在此测试环境中运行良好,您可以在每个查询中手动发送languageCode参数,并根据需要更改它。

Now my question is:现在我的问题是:

Is there a way, preferably an easy one, for me to make use of this code?有没有办法,最好是简单的方法,让我使用这段代码?

I'm afraid I would have to set up a full implementation from scratch using JavaScript and HTML in order to get this running.恐怕我必须使用 JavaScript 和 HTML 从头开始设置完整的实现才能运行它。 Currently, I'm thinking about a website with an embedded iframe that lets you alter the Node.JS code somehow.目前,我正在考虑一个带有嵌入式 iframe 的网站,它可以让您以某种方式更改 Node.JS 代码。

Any suggestions are welcome and appreciated.欢迎和赞赏任何建议。 Except, please don't advise me to set up two separate bots, that's not what I'm looking for.除了,请不要建议我设置两个单独的机器人,那不是我想要的。

Alternatively, is there a better way of using Dialogflow to solve this problem?或者,有没有更好的方法使用 Dialogflow 来解决这个问题?

Thank you.谢谢你。

If you are using a Dialogflow integration, you can currently only use one language .如果您使用的是 Dialogflow 集成,则目前只能使用一种语言 If you are implementing your own interface with the end-user, just ask the end-user for their preferred language, and provide the language code with every call to detect intent.如果您要与最终用户实现自己的界面,只需询问最终用户他们的首选语言,并在每次调用时提供语言代码以检测意图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM