简体   繁体   中英

API.ai looping on purpose

I have my API.ai getting an answer from the user and sending it to a JS webhook, in which I check whether their answer is correct. I want to make it so that if they get the answer wrong it'll ask repeatedly until they get it right. How would I achieve this, can I set an output context in my webhook if the user answer fails the comparison (which doesn't activate if they get it correct)?

You could use this as a template. The actual implementation details for retrieving result and requesting server if result is okay are contained respectively in the functions getAnswer and checkResultOK .

The use of a callback in checkResultOK makes it possible for checkResultOK to work asynchronously (in this case trivially so by adding a slight delay).

You could also use Promises if you prefer, but you'll need a library like Q or bluebird .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM