重新启动Dialogflow中的对话

Hello堆栈溢出社区,

在以下问题上,我需要您的帮助:

当前,我正在运行一个Dialogflow聊天机器人,该聊天机器人具有一些意图并返回一些响应。到目前为止,聊天机器人的运行状况十分理想。对于您的信息,我使用webhook来获取回复。

这是我的意图流程的屏幕截图:dialogflow chatbot

我要做的就是让用户有机会从头开始重新运行整个对话。您知道如何在Dialogflow中实现这一目标吗?

运行webhook的Python代码段:

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(),promise_second_movie(),thank()是创建的三个函数,用于根据通信流返回3个不同的输出。

我想要的是找到正确的语法,如果用户说“是”,它将允许我再次重新运行整个对话,否则Dialogflow应该结束对话。

我将不胜感激,或者建议您可以给我!

caindeck 回答:重新启动Dialogflow中的对话

您可以通过发送跟进事件而不是响应来执行此操作。在这种情况下,当用户回答是时,在您的代码中,您将返回:

{
   "followupEventInput": {
        "name": "KellyMovieBot","languageCode": "en-US"
   }
}

确保您的KellyMovieBot意图具有相同的事件名称。您不必使用指定的值,但是响应中发送的事件名称也应该与意图上配置的事件名称匹配。

https://cloud.google.com/dialogflow/docs/events-custom#invoke_event_from_webhook

本文链接:https://www.f2er.com/3128550.html

大家都在问