Make a Natural Language command ask "are you sure?" before triggering

Learn how to make a natural language command ask you "are you sure" before finally triggering

  1. joaomgcd
    The idea here is that you get a chance to confirm whatever command you want to execute.

    If you decide that you want to change something, Natural Language will ask you the new values and ask you to confirm until you finally do and the command is finally triggered.

    In this example we'll create a command to make your phone say something out loud at a certain speed.
    It'll look something like this:

    In this example we'll be using the commands editor on API.AI instead of the editor in AutoVoice since the API.AI editor is faster to edit multiple stuff in.

    Please note that everything you see here could also be done in AutoVoice alone but would be a bit more cumbersome to setup.

    STEP 1 - CREATE COMMAND TO SAY SOMETHING ON YOUR PHONE


    • In API.AI create a new intent with the name say on phone - start
    • Add a command like say something on my phone and make the something part a variable by highlighting it and choosing the @system.any type
    • Add another command like say something on my phone at speed 5 and make the something part the same variable as the other command and the 5 part a new variable of the type @sys.number-integer
    • Make both variables required
    • Rename the any variable to text
    • Rename the number-integer variable to speed
    • Edit the prompt of the speed variable to What speed do you want to say $text at?
    (i) Notice how you used $text in the prompt? That will be replaced with the actual value of the text variable when this command is being executed for real
    • Make the intent's response be Ok, saying $text on your phone with the speed set to $speed. Are you sure?
    (i) Notice how you're using the value of the text and speed variables in the response.
    • Set the intent's action to say-start
    • Set the intent's output context to say
    /!\ Setting the output context is the key part in making this work. You'll find out why next.
    • Save your intent


    STEP 2 - CREATE COMMAND TO CORRECT INPUT


    • Create a new intent with the name say on phone - no
    • Set the input context to say
    (i) This is the same context that was output on the say on phone - start intent. By setting that as the input context here you'll make sure that this intent will only trigger if that context exists. In other words, this intent will only be considered after the say on phone - start intent was triggered
    • Add a command with just the word no
    • Set the intent action to say-no
    • Manually add the text and speed variables and set their prompts
    • Set the response to Ok, saying $text at speed $speed instead. Is it ok now?
    • Save your intent


    Ok, so now if we say say something on my phone at speed 5 natural language will ask you to confirm. If you say no to that, it'll ask you to say the text and speed again. If you keep saying no, it'll keep asking you.

    Let's create an intent for when you finally say yes.

    STEP 3 - CREATE FINAL COMMAND AFTER CONFIRMATION


    • Create a new intent with the name say on phone - yes
    • Set the input context to say
    • Modify the automatically created output context and give it a 0 lifespan
    (i) By giving it a 0 lifespan you're saying that you want this context to go away after this intent is triggered. This will make this and the say on phone - no intents not be considered anymore because the say context will no longer exist.
    • Add a command with the text yes
    • Manually add the text and speed variables and set their values to #say.text and #say.speed respectively. No prompts are needed because we are sure that these values already exist.
    (i) #say.text and #say.speed are the values of text and speed from the existing say context.
    • Set the command action to say-yes
    • Make the intent's response Ok, I'm making your phone say $text at the speed of $speed! Hurray!
    • Save your intent


    You can now test these commands directly in API.AI to see if they're working well, before actually doing something with them in Tasker:

    STEP 4 - MAKE ASSISTANT NOT FINISH CONVERSATION


    • On your phone open AutoVoice -> Natural Language -> Commands
    • Make both the say on phone - start and the say on phone - no not finish the conversation with the assistant so that you can directly continue talking to AutoVoice when any of these commands are triggered


    STEP 5 - CREATE PROFILE IN TASKER TO SAY SOMETHING ON YOUR PHONE


    • In Tasker create a new profile with the AutoVoice Natural Language event condition
    • Select the say on phone - yes command from the list
    • In the task add a flash action just to confirm that the task is running
    • Add a Say action and set the Text to %text and the Speed to %speed (disable beginner mode in Tasker if you can't use a variable for the speed like in the video)
    • Back out of Tasker to save


    STEP 6 - TEST


    If everything's setup correctly you should be able to say stuff like in this video :cool:


    STEP Extra - CHANGE ONLY THE SPEED


    You might want to only change a certain variable in the command so here's how you can change just the speed in this example:

    • Create a new intent called say on phone - change speed
    • Set the input context to say
    • Add a command like change the speed
    • Manually add the text parameter and set its value to #say.text. This will set the value of $text directly to the one in the context and not ask you about it
    • Manually add the speed parameter but don't set its value. Instead set a prompt for it, so that this intent will ask you for its value when triggered
    • Set the action to say-change-speed
    • Set the reponse to Ok, speed changed to $speed. I'm making your phone say $text at that speed. Is it ok now?
    • Save your intent
    • Test the new change speed intent directly on API.AI to see if it's working correctly
    • In AutoVoice -> Natural Language -> Commands make this new command also not finish the conversation with the assistant.


    If you want to skip creating the natural language commands yourself or if you want to have a pre-made base to work on, here are the 4 commands used in this tutorial that you can import directly into AutoVoice:
    say on phone - start
    say on phone - no
    say on phone - yes
    say on phone - change speed