Alexa Flask Ask Yes / No response handling

。_饼干妹妹 提交于 2019-12-03 16:33:08

This is not possible in the suggested way using flask ask. After you call return, you leave your SearchIntent() function and have no way to check the answer or run additional code.
However, you can still make it work: after the user answers your question a new intent is sent and flask-ask calls the according function. By using session attributes, as suggested by @user3872094, you can process your searchterm in this new function. Session attributes are used to preserve user input during a session between different intent requests.
Check this minimal example:

@ask.intent("SearchIntent")
def SearchIntent(searchterm):
    session.attributes['term'] = searchterm
    return question("I understood {}. Is that correct?".format(searchterm))

@ask.intent('AMAZON.YesIntent')
def yes_intent():
    term = session.attributes['term'] 
    return statement("Ok. So your word really was {}.".format(term))

@ask.intent('AMAZON.NoIntent')
def no_intent():    
    return statement("I am sorry I got it wrong.")

Add the Amazon Yes and No intents to your intent_schema:

{
    "intents": [
        {
        "intent": "SearchIntent",
        "slots": [{
            "name": "searchterm",
            "type": "AMAZON.LITERAL"
        }]
        },{
            "intent": "AMAZON.NoIntent"
        }, {
            "intent": "AMAZON.YesIntent"
        }      
    ]
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!