[英]Dialogflow: Use parameters that are set in fulfillment
I am using Dialogflow with a custom server as backend server, sending JSONs once in a while for fulfilment.我将 Dialogflow 与自定义服务器一起用作后端服务器,偶尔发送 JSON 以实现。
As an example, I want to make a very simple login in my system.例如,我想在我的系统中进行一个非常简单的登录。 For that, I have an intent, "session.login", that has one required parameter, namely username:
为此,我有一个意图,“session.login”,它有一个必需的参数,即用户名:
That intent has fulfilment enabled, and my backend simply checks if the given parameter username
exists in a database, and then either forwards (using a followup-event) to another intent "login-failed", or "login-success": {"followupEventInput": {"name": "login-failed", "languageCode": "en"}}
.该意图已启用,我的后端只是检查数据库中是否存在给定的参数
username
,然后(使用后续事件)转发到另一个意图“登录失败”或“登录成功”: {"followupEventInput": {"name": "login-failed", "languageCode": "en"}}
。
This all works so far, but now I simply want this intent to be able to say something like "hello, $username":到目前为止,这一切都有效,但现在我只想让这个意图能够说“你好,$用户名”之类的东西:
However I don't manage to do this, as the parameter username seems to be gone by then.但是我无法做到这一点,因为那时参数 username 似乎已经消失了。 When I try the code as given above, Actions on Google fails, meaning my bot leaves the conversation and I get the error
MalformedResponse expected_inputs[0].input_prompt.rich_initial_prompt: 'rich_response' must contain at least one item.
当我尝试上面给出的代码时,Actions on Google 失败,这意味着我的机器人离开了对话,我收到错误
MalformedResponse expected_inputs[0].input_prompt.rich_initial_prompt: 'rich_response' must contain at least one item.
I tried sending the information about the parameter back from my fulfilment server, such that my new response forwarding me to the session.login.success intent would look like this: {'outputContexts': [{'lifespanCount': 5, 'name': 'projects/MY_AGENT/MY_SESSION/contexts/login-incomplete', 'parameters': {'username': 'aron'}}], 'followupEventInput': {'languageCode': 'en', 'name': 'login-success'}}
, but this doesn't help either.我尝试从我的执行服务器发回有关参数的信息,以便我将我转发到 session.login.success 意图的新响应如下所示:
{'outputContexts': [{'lifespanCount': 5, 'name': 'projects/MY_AGENT/MY_SESSION/contexts/login-incomplete', 'parameters': {'username': 'aron'}}], 'followupEventInput': {'languageCode': 'en', 'name': 'login-success'}}
,但这也无济于事。
If anybody has any help on how to do this that would be great, thanks!如果有人对如何做到这一点有任何帮助,那就太好了,谢谢!
Figured it out myself.我自己想出来的。
First of all, I don't need to set a new parameter at all, and just need to use the #oldcontext.oldparameter in my response, and secondly, if one dereferences from a context, there's no need for the dollar-sign anymore:首先,我根本不需要设置新参数,只需要在响应中使用 #oldcontext.oldparameter,其次,如果从上下文中取消引用,则不再需要美元符号:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.