重复对话流意图,直到满足条件

时间:2018-12-29 02:55:05

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

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

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

1 个答案:

答案 0 :(得分: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中,并将#context.parameter设置为dialogflow控制台中参数的默认值。
Documentation用于根据上下文设置实体的默认值。

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

default value

希望有帮助。