我正在使用Python和Dialogflow V2 API。我想知道如何在使用Python Flask作为实现满足条件之前重新提示意图。我要填充插槽,然后运行SQL查询以验证用户的身份。如果查询返回false(数据库中不存在标识),那么我想重新运行该意图,直到满足条件(找到了userId)。
我尝试查看JS文档,但是找不到任何Python文档来完成这一壮举。
答案 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": ""
}
}
]
希望有帮助。