api.ai looping the same intent with different input

Viewed 980

I am using API.AI to implement the assistant app, but now I found it's hard to looping on the same intent to collect different user input (correct me if my expression is wrong, will explain it in details.) The problem is, I have a list of elements, and each time I want to assign exact one element to one person (collected via use input Assistant.getArgument()), however, I want it speaks to the user every time like 'who do you want to assign element X to?' (X refers to the name of element in the list). My current implementation is, creating a separate function, make it ask the question and then do the collect input/assignment in the other function using a while loop, at the end of while body call the ask function, but it doesn't work as API.AI gives Not Available in the response. Any ideas on how to do this? Let me know if the there is something unclear.

Here is just a brief code snippet for showing what's the issue is & what I want to achieve. I want to make it asks 4 times in API.AI, get user input, and store them all in to the output string.

var output = '';

    function do_sth(assistant){
        let get_name_input = assistant.getArgument('name');
        output = output + get_name_input + '.';
    }

    function test_repeat(assistant){
        for(let i = 0; i < 4; i++){
            assistant.ask('What is the name?');
            do_sth(assistant);
        }
    }
2 Answers
Related