0

I'm a Twilio newbie and trying to develop a C# app that will interact with an automated phone tree. The issue is that the beginning of the phone tree is a bit different each time so instead of trying to automate all the different permutations, I'm creating a conference call between the phone tree, the app, and my personal phone number. I'm hoping to answer my phone, interact with the tree until I get to the "automateable" part, and then hang up my call and let the app interact with the conference call from then on.

So far I've been able to create the conference successfully using two CallResource.Create() calls. The issue I'm currently facing is that when I use CallResource.Update() with the tree Sid, once the Twiml is executed, it hangs up on that call resource and I can't figure out why. The call to my phone number is still going but no matter what twiml I send to the tree call resource, it hangs up on it after.

  1. Any help on how to be able to update the call with some twiml without it hanging up
  2. Or, maybe there is a better way to do what I'm looking for all together?

Any advice is appreciated! Below is the code I'm using

Thanks, Sean

    public void MakeCall()
    {
        var accountSid =  ConfigurationManager.AppSettings["TwilioAccountSid"];
        var authToken =  ConfigurationManager.AppSettings["TwilioAuthToken"];
        var mePhoneNumber = ConfigurationManager.AppSettings["MyPhoneNumber"];
        var treePhoneNumber = ConfigurationManager.AppSettings["TreePhoneNumber"];

        var conferenceName = "treeNavigate" + Guid.NewGuid();

        TwilioClient.Init(accountSid, authToken);

        Twimlet treeConferenceTwimlet = new Twimlet();
        treeConferenceTwimlet.Endpoint = "conference";
        treeConferenceTwimlet.Parameters.Add("Name", conferenceName);
        treeConferenceTwimlet.Parameters.Add("Message", "Hi Tree");

        Twimlet meConferenceTwimlet = new Twimlet();
        meConferenceTwimlet.Endpoint = "conference";
        meConferenceTwimlet.Parameters.Add("Name", conferenceName);
        meConferenceTwimlet.Parameters.Add("Message", "Hi Me");

        var meCall = CallResource.Create(
            to: new PhoneNumber(mePhoneNumber),
            from: new PhoneNumber(mePhoneNumber),
            url: new Uri(meConferenceTwimlet.GetFormattedURL()));

        var treeCall = CallResource.Create(
            to: new PhoneNumber(treePhoneNumber),
            from: new PhoneNumber(mePhoneNumber),
            url: new Uri(treeConferenceTwimlet.GetFormattedURL()));
        
        CallResource.Update(
            pathSid: treeCall.Sid,
            twiml: new Twilio.Types.Twiml("<Response><Say>I can hear this on the conference but then it hangs up right after</Say></Response>"));

    }

    public class Twimlet
    {
       private String baseUrl = "http://twimlets.com/";
       public Dictionary<String, String> Parameters { get; set; }
       public String Endpoint { get; set; }

       public Twimlet()
       {
           this.Parameters = new Dictionary<string, string>();
       }

       public String GetFormattedURL()
       {
           return String.Format(
               "{0}{1}?{2}", 
               this.baseUrl, 
               this.Endpoint, 
               String.Join("&", this.Parameters.Select(x => String.Format("{0}={1}", HttpUtility.UrlEncode(x.Key), HttpUtility.UrlEncode(x.Value)))));
       }
   }

1 Answers1

0

Twilio developer evangelist here.

When a Twilio powered phone call executes TwiML it does so until it runs out of TwiML and then hangs up. In this case, when you update the call with new TwiML with only a <Say> element it will speak the words out and then complete.

The way to keep that call on the conference line is to do something once the <Say> is complete. You could, for example, <Pause> for a while.

This doesn't make this a great answer, but I'm not sure what your plans with the call are after this <Say> so it's hard to suggest how you might do this better. If you can explain, I can edit this answer with other suggestions.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • Hello, This is helpful, thanks. So here is how I want it to go: 1) My app connects the phone tree and my cell phone in a conference call. The leg connected to the phone tree just sits there for a while. 2) From my cell phone I put in keypresses to be forwarded to the tree leg to get past the variable section. 3) Once past, I am in a part of the phone tree that is essentially a loop. I want be able to hang up my leg and hit a button in app which would generate a twiml file for each time through the menus, collecting back a confirmation number spoken by the tree to show in my app. – Sean Pinto Dec 16 '21 at 03:32
  • Sounds like the last part is going to require looping of `` until you receive the confirmation code. Does that sound right to you? – philnash Dec 16 '21 at 05:34
  • That sounds right however I am still a bit stuck. My current challenge is that after I do the update to the call between my app and the phone tree, even if I do a super long pause at the end of the TwiML that I am passing, that call is disconnected from the conference for some reason. I would expect – Sean Pinto Dec 22 '21 at 03:34