Will Regex work for Voice -Split Based On Widget

Viewed 49

Twilio Studio does not have a Widget that I would call CONTAINS ANY so I am trying to create a test using the Regex option and in a voice context. For example, if the phrase could be get the mail or open the mail or open mail, then I could create 3 separate Contains Conditions and route them to the same branch element. But I would like to just have one Condition that would check for any Contains.

This is not a big problem for just a few possibilities but with many possibilities the Studio Flow Chart gets very messy and there is a lot of adding additional Conditions.

It would be nice to just make the Condition be a Regex condition that "fakes" the missing CONTAINS ANY condition.

I use regx101 code/syntax creator to develop Regex code and test it. The following code checks out legitimate in rex101 but doesn't work in Twilio studio.

/get the mail|open the mail|open mail/mg

Realizing that syntax is everything. I must be overlooking something very important. Or Regex conditions just will never work with voice.

I have attached a screenshot of the Studio CONDITION that doesn't work.

I have also pasted in the section of JSON code generated by Studio but with different phrases than my example.

I need help in making this work.

"next": "say_play_1", "event": "match", "conditions": [ { "friendly_name": "If value regex /open the flower|get flower/mg", "arguments": [ "{{widgets.gather_mailbox_answer.SpeechResult}}" ], "type": "regex", "value": "/open the flower|get flower/mg"

Condition Box from the Studio Flow in question

1 Answers

The documentation for the Split Based On... widget says:

Omit leading and trailing slashes with the Regex Predicate.

Admittedly, it said this right at the bottom of the page, but I've edited it so that this warning now appears next to the definition of the Regex predicate.

So, you should use the regex .*(get the mail|open the mail|open mail).* to implement a Contains Any predicate for your options.

This does, of course, drop the options you added. Dropping g shouldn't be a problem, since the split widget is looking for a boolean response to the predicate, so as soon as one of your options is found it is true. The m might be a bit more difficult. I was testing with text messages rather than voice and when I used multiple lines it didn't match. However, you are working with voice and I don't believe the Gather Input widget will add newlines to the captured speech, so it should also not be a problem.

Related