Alexa Flask Ask Yes / No Answer

I am trying to create a simple Alexa skill using Flask Ask in python.

I have an intention called "SearchIntent" with the word "searchterm" , and the python code looks something like this:

@ask.intent("SearchIntent")
def SearchIntent(searchterm):
    resList = []
    searchterm = searchterm.lower()

    for item in somelist:
        if item.find(searchterm) != -1:
            resList.append(item)


    return question("I Found " + str(len(resList)) + ", Do you want me to list them all?")

I want to check if the answer from the user answers if he says "Yes", than to read all the results:

return statement('\n'.join(resList))

and if the user says no to perform another action

sort of:

...

    return question("I Found " + str(len(resList)) + ", Do you want me to list them all?")

if "return question" == "yes":
   do something
else:
   do something else

I do not want to create a search function in YesIntent again, is it possible to do something like this in the same function?

Thank you in advance!

+4
source share
1 answer

. return SearchIntent() .
, : , , , - . , @user3872094, searchterm . .
:

@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.")

Amazon aim_schema:

{
    "intents": [
        {
        "intent": "SearchIntent",
        "slots": [{
            "name": "searchterm",
            "type": "AMAZON.LITERAL"
        }]
        },{
            "intent": "AMAZON.NoIntent"
        }, {
            "intent": "AMAZON.YesIntent"
        }      
    ]
}
+4

Source: https://habr.com/ru/post/1675830/


All Articles