【问题标题】:Repeating Dialogflow Intent Until Condition is Met重复 Dialogflow Intent 直到满足条件
【发布时间】:2018-12-29 02:55:04
【问题描述】:

我正在使用 Python 和 Dialogflow V2 API。我想知道如何使用 Python Flask 作为实现来重新提示意图,直到满足条件。我正在填充插槽,然后运行 ​​SQL 查询来验证用户的身份。如果查询返回 false(数据库中不存在身份),那么我想重新运行意图,直到满足条件(找到 userId)。

我尝试查看 JS 文档,但找不到任何 Python 文档来完成这项壮举。

【问题讨论】:

  • 嗯。我想我可能有一个解决方案,但不知道如何实施。如果在前一个意图中运行的查询不满足条件,是否有办法触发回退意图? EX:用户提供姓名后,在数据库中找不到 userId。

标签: python python-3.x flask dialogflow-es dialogflow-es-fulfillment


【解决方案1】:

在执行过程中,如果条件为假,只需回复类似Sorry this username does not exist, please enter the username again.的问题即可

if not username:
    res = json.dumps({
        "fulfillmentText": "Sorry this username does not exist, please enter the username again."
    })

如果您也有一些意图的输入上下文,那么您也需要从实现中设置他的上下文。

req = request.get_json()
if not username:
    res = json.dumps({
        "outputContexts": [
            {
                "name": "{}/contexts/ask-username".format(req['session']),
                "lifespanCount": 1,
            },
        ],
            "fulfillmentText": "Sorry this username does not exist, please enter the username again."
        })

编辑:
要重置参数值,请将参数包含在输出上下文以及 webhook 中,并在 dialogflow 控制台中将 #context.parameter 设置为参数的默认值。
Documentation 用于从上下文设置实体的默认值。

 "outputContexts": [
        {
            "name": "projects/${PROJECT_ID}/agent/sessions/${SESSION_ID}/contexts/ask-username",
            "lifespanCount": 1,
            "parameters": {
                "foo": ""
            }
        }
    ]

希望对你有帮助。

【讨论】:

  • 谢谢@sid8491 如果条件尚未满足,有没有办法“返回”/清除插槽并获得用户的下一个响应?类似于 Rasa NLU 的 UserUtteranceReverted()?
  • @JAWS007 是的,您可以在输出上下文中包含插槽并将其值设置为 NULL,在意图中将插槽的默认值设置为 #context.slot
  • 真棒@sid8491。可能有一些文档吗?谢谢。
猜你喜欢
  • 1970-01-01
  • 2015-07-28
  • 2013-12-28
  • 1970-01-01
  • 2019-11-10
  • 2014-05-03
  • 2018-03-13
  • 2019-11-07
  • 2018-11-09
相关资源
最近更新 更多