在 Dialogflow 中重启对话
Restart a conversation in Dialogflow
你好堆栈溢出社区,
我想请您帮助解决以下问题:
目前我运行正在使用一个 Dialogflow 聊天机器人,它有一些意图并返回一些响应。聊天机器人到目前为止工作完美。为了您的信息,我使用 webhook 来获取回复。
这是我的意图流程的屏幕截图:dialogflow chatbot
我努力做的是让用户有机会从头开始重新运行整个对话。你知道我如何在 Dialogflow 中实现这一点吗?
Python 运行 webhook 的代码片段:
app = Flask(__name__)
# default route
@app.route('/')
def index():
return 'Chatbot is online and running!'
@app.route('/webhook', methods=['GET', 'POST'])
def webhook():
# return response
req = request.get_json(force=True, silent = True)
action = req.get('queryResult').get('action')
intent_name = req.get('queryResult').get('intent').get('displayName')
if action == "get_results" and intent_name == 'KellyMovieBot':
return make_response(jsonify(suggest_movie(req)))
elif action == "ask_question" and intent_name == 'ask_first_time':
return make_response(jsonify(propose_second_movie(req)))
elif action == "thanks_giving_end" and intent_name == "thanks_giving":
return make_response(jsonify(thanks(req)))
elif action == "rerun_conversation" and intent_name == "rerun_conversation":
user_answer = req.get('queryResult').get('parameters').get('user_answer')
if user_answer == "No" or user_answer == "no":
return {'fulfillmentText': "Enjoy your film!"}
elif user_answer == "Yes" or user_answer == "yes":
return {'fulfillmentText': "Let's start again..."}
# run the app
if __name__ == '__main__':
app.run()
注意: 函数 suggest_movie()、propose_second_movie()、thanks() 是为了 return 3 个基于通信流的不同输出。
我想要的是找到正确的语法,以便在用户说 'Yes' 时再次 RERUN 整个对话,否则 Dialogflow 应该结束对话。
如果您能给我任何帮助或建议,我将不胜感激!
您可以通过发送后续事件而不是响应来完成此操作。在这种情况下,当用户回答是时,在您的代码中,您会 return:
{
"followupEventInput": {
"name": "KellyMovieBot",
"languageCode": "en-US"
}
}
确保您的 KellyMovieBot 意图具有相同的事件名称。您不必使用指定的值,但响应中发送的事件名称也应与意图上配置的事件名称相匹配。
https://cloud.google.com/dialogflow/docs/events-custom#invoke_event_from_webhook
你好堆栈溢出社区,
我想请您帮助解决以下问题:
目前我运行正在使用一个 Dialogflow 聊天机器人,它有一些意图并返回一些响应。聊天机器人到目前为止工作完美。为了您的信息,我使用 webhook 来获取回复。
这是我的意图流程的屏幕截图:dialogflow chatbot
我努力做的是让用户有机会从头开始重新运行整个对话。你知道我如何在 Dialogflow 中实现这一点吗?
Python 运行 webhook 的代码片段:
app = Flask(__name__)
# default route
@app.route('/')
def index():
return 'Chatbot is online and running!'
@app.route('/webhook', methods=['GET', 'POST'])
def webhook():
# return response
req = request.get_json(force=True, silent = True)
action = req.get('queryResult').get('action')
intent_name = req.get('queryResult').get('intent').get('displayName')
if action == "get_results" and intent_name == 'KellyMovieBot':
return make_response(jsonify(suggest_movie(req)))
elif action == "ask_question" and intent_name == 'ask_first_time':
return make_response(jsonify(propose_second_movie(req)))
elif action == "thanks_giving_end" and intent_name == "thanks_giving":
return make_response(jsonify(thanks(req)))
elif action == "rerun_conversation" and intent_name == "rerun_conversation":
user_answer = req.get('queryResult').get('parameters').get('user_answer')
if user_answer == "No" or user_answer == "no":
return {'fulfillmentText': "Enjoy your film!"}
elif user_answer == "Yes" or user_answer == "yes":
return {'fulfillmentText': "Let's start again..."}
# run the app
if __name__ == '__main__':
app.run()
注意: 函数 suggest_movie()、propose_second_movie()、thanks() 是为了 return 3 个基于通信流的不同输出。
我想要的是找到正确的语法,以便在用户说 'Yes' 时再次 RERUN 整个对话,否则 Dialogflow 应该结束对话。
如果您能给我任何帮助或建议,我将不胜感激!
您可以通过发送后续事件而不是响应来完成此操作。在这种情况下,当用户回答是时,在您的代码中,您会 return:
{
"followupEventInput": {
"name": "KellyMovieBot",
"languageCode": "en-US"
}
}
确保您的 KellyMovieBot 意图具有相同的事件名称。您不必使用指定的值,但响应中发送的事件名称也应与意图上配置的事件名称相匹配。
https://cloud.google.com/dialogflow/docs/events-custom#invoke_event_from_webhook