0

I am having trouble getting the getRawInput() method to capture user input after it's initial call. I would like the user to choose and action, and then the assistant to respond with a question, which the user has to answer to go forward. For example, a user would like to transfer money from a checking account to a savings account would say "I would like to make a transfer." The assistant will ask "Which account would you like to transfer from." The user would respond with the account they would like to transfer from. The issue seems to be that assistant isn't taking the second input, and I get the error "Action: {name of my action} isn’t responding right now. Try again soon." Please let me know if there is a better way or a more appropriate method to call for in-line dialogues.

Here is the code I'm trying to execute:

else if (assistant.getRawInput() === 'I want to make a transfer') {
    let inputPrompt = assistant.buildInputPrompt(true, 'Sure, which account would you like to transfer from? You can say checking or savings.');
    assistant.ask(inputPrompt);
    if(assistant.getRawInput() === 'checking') {
        let transFrom = 'checking';
        let transTo = 'savings';
        let inputPrompt = assistant.buildInputPrompt(true, 'You are going to make a transfer from your ' + transFrom + ' account to your ' + transTo + ' account. What is the amount you would like to transfer?');
        assistant.ask(inputPrompt);
        let amtInput = assistant.getRawInput();
        let amt = parseInt(amtInput);
        transferMoney(transFrom, transTo, amt);
        inputPrompt = assistant.buildInputPrompt(true, 'Cool, you have transfered ' + amt + ' dollars from your ' + transFrom + ' account to your ' + transTo + ' account. Your new balance is ' + customer1.chkBal + ' dollars in your ' + transFrom + ' account and  ' + customer1.savBal + ' in your ' + transTo + ' account.');
        assistant.ask(inputPrompt);
    } else if (assistant.getRawInput() === 'savings') {
        let transFrom = 'savings';
        let transTo = 'checking';
        let inputPrompt = assistant.buildInputPrompt(true, 'You are going to make a transfer from your ' + transFrom + ' account to your ' + transTo + ' account. What is the amount you would like to transfer?');
        assistant.ask(inputPrompt);
        let amtInput = assistant.getRawInput();
        let amt = parseInt(amtInput);
        transferMoney(transFrom, transTo, amt);
        inputPrompt = assistant.buildInputPrompt(true, 'Cool, you have transfered ' + amt + ' dollars from your ' + transFrom + ' account to your ' + transTo + ' account. Your new balance is ' + customer1.chkBal + ' dollars in your ' + transFrom +' account and  ' + customer1.savBal + ' in your ' + transTo + ' account.');
        assistant.ask(inputPrompt);
    }

1 Answers1

1

You haven't indicated if you are using API.AI or the Actions API directly, but it sounds like you're using the Actions API. It also looks like you're writing the function linearly - as if you're expecting assistant.ask() to stop the program and wait for a reply from the user. This isn't how assistant.ask(), or Actions in general, work.

Think of the Google Home as a web browser, and your Action will be running on a web server somewhere. assistant.ask() is equivalent to sending back a message to the browser and closing the connection (but not closing the microphone). There is no additional processing that can be done, so having statements after the ask() doesn't make sense.

If you're using the Actions API directly, you'll need to keep track of where in the conversation you are (the state - or what questions have been asked so far and what answers you've gotten) and execute different code paths appropriately.

You may be more interested in API.AI, which lets you build the conversations more interactively and indicate only which commands will need to send your webhook the information. Using API.AI, your programming logic doesn't need to keep track of where in the conversation you are - you build the state machine and conversation path through API.AI.

Prisoner
  • 49,922
  • 7
  • 53
  • 105