简体   繁体   English

API.ai故意循环

[英]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. 我的API.ai从用户那里得到答案,并将其发送到JS webhook,在其中检查他们的答案是否正确。 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)? 我将如何实现这一点,如果用户的回答未能通过比较(如果他们的回答正确就不会激活),我可以在webhook中设置输出上下文吗?

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 . getAnswercheckResultOK函数分别包含用于检索结果和请求服务器(如果结果正常)的实际实现细节。

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). 在checkResultOK中使用回调可以使checkResultOK异步工作(在这种情况下,通过添加一些延迟可以轻松实现)。

You could also use Promises if you prefer, but you'll need a library like Q or bluebird . 如果愿意,也可以使用Promises,但是需要Qbluebird之类的库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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