当 Twilio 通话结束时,KRL 规则是否会停止运行?

发布于 2024-10-05 20:24:52 字数 757 浏览 5 评论 0 原文

如果我创建幼儿游乐线(请参阅http://blog.tropo.com/2010/11/22/something-fun-and-quick-to-make-the-toddler-amusement-line/)使用 Twilio和 Kynetx 我是否需要在规则集中设置停止条件,或者当呼叫者挂断时评估会结束吗?

// WARNING! Do not use this ruleset!
rule callstart {
  select when twilio callstart
  always { raise explicit event loves_me }
}

rule loves_me {
  select when explicit loves_me
  twilio:say("She loves me.")
  always { raise explicit event loves_me_not }
}

rule loves_me_not {
  select when explicit loves_me_not
  twilio:say("She loves me not.")
  always { raise explicit event loves_me }
}

我的猜测:调用启动规则集运行。来电者挂断电话。 KNS的一小部分人哭了。

If I create a Toddler Amusement Line (see http://blog.tropo.com/2010/11/22/something-fun-and-quick-to-make-the-toddler-amusement-line/) using Twilio and Kynetx do I need to set a stop condition in my ruleset or will the evaluations end when the caller hangs up?

// WARNING! Do not use this ruleset!
rule callstart {
  select when twilio callstart
  always { raise explicit event loves_me }
}

rule loves_me {
  select when explicit loves_me
  twilio:say("She loves me.")
  always { raise explicit event loves_me_not }
}

rule loves_me_not {
  select when explicit loves_me_not
  twilio:say("She loves me not.")
  always { raise explicit event loves_me }
}

My guess: The call starts the ruleset running. The caller rings off. A small part of KNS cries.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

高速公鹿 2024-10-12 20:24:52

实际上,您此处的代码根本不会返回到 Twilio。

Twilio 在呼叫开始时和呼叫期间根据指示引发事件。 twilio:gather_start() 和 twilio:redirect() 等都会发生这种情况。

当您引发显式事件时,任何匹配的规则都将在发送响应之前选择并触发。由于这里的循环,响应将永远不会被发送。测试此功能的一个好方法是从浏览器调用您提供给 twilio 的 webhook,并查看响应。

实现这一点的更好方法是给 Twilio 一条指令,并让它在完成时引发另一个事件。要重写上面的代码:

rule callstart {
  select when twilio callstart
  always { raise explicit event loves_me }
}

rule loves_me {
  select when explicit loves_me or twilio loves_me
  twilio:say("She loves me.");
  always { raise explicit event loves_me_not }
}

rule loves_me_not {
  select when explicit loves_me_not
  {
    twilio:say("She loves me not.");
    twilio:redirect("loves_me");
  {
}

请注意,我仅替换了 raise 显式事件 语句之一。您可以以类似的方式替换所有这些事件,但这会导致向 Kynetx 提出更多的事件,而不是真正需要的事件。这确实是一种平衡,可以根据需要进行调整。

(另请注意loves_me规则的select语句中的OR,以及添加{}以允许在单个规则中执行两个操作。以及操作后的;s。)

当您希望时,这种使用重定向的模式也很有用如果用户在超时之前未选择选项,则重复菜单选项。这显示在 Kynetx 文档中的电话菜单教程中。

Actually, your code here will never return to Twilio at all.

Twilio raises events at call start and during a call when instructed. This happens with a twilio:gather_start() and twilio:redirect() among others.

When you raise an explicit event, any matching rules will select and fire BEFORE the response is sent. Because of your loop here, the response will never be sent. A good way to test this is to call the webhook you give to twilio from a browser, and look at the response.

A better way to make this happen is to give Twilio a piece of instructions, and have it raise another event when finished. To rewrite your code above:

rule callstart {
  select when twilio callstart
  always { raise explicit event loves_me }
}

rule loves_me {
  select when explicit loves_me or twilio loves_me
  twilio:say("She loves me.");
  always { raise explicit event loves_me_not }
}

rule loves_me_not {
  select when explicit loves_me_not
  {
    twilio:say("She loves me not.");
    twilio:redirect("loves_me");
  {
}

Note that I only replaced one of the raise explicit event statements. You could replace all of them in similar manner, but that would result in more events raised to Kynetx then really necessary. It really is a balance and can be adjusted as necessary.

(Also note the OR in the select statement of the loves_me rule, and the addition of {} to allow for two actions in a single rule. And the ;s after actions.)

This pattern of using a redirect is also useful when you wish to repeat menu options, if the user does not choose an option before the timeout. This is shown in the Phone Menu Tutorial in the Kynetx Docs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文