Reputation: 1
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 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)))));
}
}
Upvotes: 0
Views: 576
Reputation: 73027
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.
Upvotes: 0