开发者

Do KRL rules stop running when a Twilio call ends?

开发者 https://www.devze.com 2023-01-28 10:39 出处:网络
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 开发者

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 开发者_如何学Cin 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消