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.
- Any help on how to be able to update the call with some twiml without it hanging up
- 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)))));
}
}