Reputation: 4773
I am trying to connect two calls using Twilio
conference.
I was following the instructions I got from: link
This is what I want to achieve:
After the first person is answering the call he can dial #1 and the system will create a conference with a second person.
My problem:
The first call is finished instead of starting the conference.
Here is what I have so far:
// the first user is online and click #1.
// now he redirects to StartConferenceCall()
public ActionResult StartConferenceCall(int userNumber)
{
var digits = Request["Digits"]; // twilio send the dial number as"Ditits"
if (digits == "1")
{
var twilService = new TwiMlService();
var client = new TwilioRestClient(accountSid, authToken);
var options = new CallOptions
{
To = userNumber,
From = twilioNumber,
};
client.InitiateOutboundCall(options);
var twiml = new TwilioResponse();
twiml.DialConference("Room1",
new { muted = true, beep = false, waitMethod = "GET" },
new { timeLimit = 30 }
);
}
if (digits == "hangup") // when the call finished twilio send "hangup" as "Digits"
{
// do something when the conference ended.
}
return View();
}
I created an empty view because without it I am getting an error from twilio:
An upstream server returned an invalid response.
Upvotes: 0
Views: 390
Reputation: 10366
Twilio evangelist here.
Couple of suggestions:
First, it does not look like you are actually returning the TwiML you create in the action method. When you load the StartConferenceCall
route in a browser you should see the TwiML (which is really just XML) returned.
Second, since it looks like you are using ASP.NET MVC for this, I'd suggest installing the Twilio.Mvc nuget package and then changing your controller to derive from TwilioController
. Doing this will let you use the TwiML method like this:
public ActionMethod StartConferenceCall(string Digits) {
var response = new TwilioResponse();
response.DialConference( ... );
return TwiML(response);
}
The TwiML
method converts the TwilioResponse object into XML and sets the content-type header of the HTTP response to XML. This TwiML will drop your first caller into the Conference call.
This would also let you remove the empty cshtml file view.
Now to get the second caller into the same conference you'll need to change your CallOptions object to also specify the Url parameter.
var options = new CallOptions
{
To = userNumber,
From = twilioNumber,
Url = "http://example.com/connectSecondCaller"
};
When the second call answers, Twilio will make an HTTP request to this URL and let you return some TwiML that drops the second caller into the same conference room.
So you might ask, how do you know which conference room to put the second caller in? One way would be to pass the name of the conference room that you create for the first caller to the TwiML executed when the second caller answers viathe URL:
var options = new CallOptions
{
To = userNumber,
From = twilioNumber,
Url = "http://example.com/connectSecondCaller?name=myconferenceroom"
};
Hope that helps.
Upvotes: 1