little help w/ Gather verb

Jul 30, 2010 at 2:21 PM

Hi - Thanks for creating this project.

I can't get the Example #3 to work correctly. It compiles but at run time I get an object ref error Verb g = r.Append...

Also, can you confirm I understand the call flow:

1) dial twilio phone #

2) twilio opens web page (in my case /default.aspx)

3) page_load ... do I need to check for "Digits" in the Form collection?

protected void Page_Load(object sender, EventArgs e)    

{        Response r = new Response();
        if (Request.Form.Get("Digits") != null)        

            r.AddSay("thank you");
       Verb g = r.Append(new Gather(new GatherNumDigits(4)));
r.Append(new Say("Please enter your number"));
r.Append(new Redirect());


Thanks for any help!

Jul 30, 2010 at 6:59 PM
Edited Jul 30, 2010 at 7:02 PM

I'll separate responses into a couple postings here.

Regarding Example#3: Wow, you're right. I must have lost some code there. Here's the fix:

Open VerbGather.cs. Add the following to the bottom of the Gather class:

protected override List<string> AllowedNestedVerbNames
        return new List<string>() { 

Still in Gather, replace the _children property with this:

protected override List<Verb> _children

Now, open Verb.cs, go to method "public virtual Verb Append( Verb verb )".
Change From:

if ( AllowedNestedVerbNames.Count == 0 )


 if ( AllowedNestedVerbNames == null || AllowedNestedVerbNames.Count == 0 )

I believe that should fix the issue, and these changes will be in the next build. Thanks for reporting it!

Do you think I should add execution of Examples methods to Samples.Win? Or should I move it to the Tests project?

Finally, the XML resulting from this example is a little different than what's shown in Example.cs. I'll update all of those in the next cut.

Please let me know how this works for you.

Jul 30, 2010 at 7:04 PM

Ran out of time. Response to your flow question will be posted this weekend (within next 2 days).

Sep 23, 2010 at 2:03 PM

TonyGravagno thanks for posting fix for AllowedNestedVerbNames.count. It saved lot of my time.

Sep 23, 2010 at 9:29 PM

I'm just happy people are using the software. :)

BTW, I never did completely respond to jyjohnson about Gather. There are a few things in his code sample that aren't quite right.
I'll hit that this weekend. Weekday time is always limited.

Sep 23, 2010 at 9:53 PM

Thanks Tony! I think I am set for now. BTW - have you had a chance to look at the new API version? I changed the constant to the new version, and the code appears to work fine (but, I have only tested a few functions).

Thanks for creating this!

Sep 24, 2010 at 6:40 PM

I posted a new note on the new API yesterday. Let's take this discussion there, just to make sure people looking at that thread don't miss important info.

If you like TSL.NET, be sure to tell Twilio. I appreciate your support!

Sep 27, 2010 at 5:04 AM

jyjohnson is set for now but I'd still like to comment on the original note in this thread:

Your understanding of the flow is correct:

- You get a call to your aspx, you do a Gather, and return.
- You get another call to the same page, you get Digits from the Form and operate on that data.

If you're doing this several times then you may want to use some sort of state mechanism so that you know where you are in the discussion with that client. You can add a GatherAction object in the Gather constructor, passing in the URL to the same page you're on, and add a query string value like "Step=2".  You'll see that pattern in one of the samples. You can also store session state using the Form Caller value as a key.

Now, there is a bug in your code: If you append a new Gather, processing stops there in the phone call to await input. If the Gather times-out, execution falls-through to your Say statement where you're saying "Please enter your number". That's not what you want of course. To fix this, append the Say to your gather object and not to the Response. Also note that you should probably return the derived class instead of the base class. So:

Rather than Verb g = r.Append(new Gather...) and then r.Append(new Say...)
Use: Gather g = r.Append(new Gather...) and then g.Append(new Say...)

Note that you can't g.Append when g is a Verb because it's AllowedNestedVerbNames will reject it. The Gather class's AllowedNestedVerbNames includes Pause, Play, and Say, per the Twilio docs.

No Redirect is required after that unless you want a redirect if the Gather fails.  If you want to do something after a Gather failure, sure, try Say("Sorry, time is up!") then r.Redirect(handleTimeoutUrl).

I hope I'm not cutting too many corners there in an attempt to be brief. If that doesn't make sense please don't hesitate to ask for clarification.