Twilio (TwiML): Dial another phone

2019-08-09 15:47发布

问题:

I would like to connect two phone numbers in that flow:

Person_1 is answering the call. a voice message played and ask him if he willing to enter the conference call. only if Person_1 accepting the conference call will be initiated:

This is what I am trying to do:

Intro.chtml:

<Response>
   <Gather numDigits="1" action="StartConferenceCall.chtml" method="GET">
       <Say>Press 1 to start the conference call</Say>
   </Gather>
</Response>

StartConferenceCall.chtml:

@{
    var digits = Request["Digits"];
    if(digits == "1")
    {
       <Response>
        <Dial>   // I would like to dial the second person

            <Conference beep="false" record="record-from-start"  
               Room 1234
            </Conference>
        </Dial>
      </Response>
    }
    else
    {
       <Hangup/>
    }

}

Is it possible to add the second number inside the <Dial> tag ?

回答1:

Twilio developer evangelist here.

Because you've changed the original question, I deleted my previous answer and put together another example for you.

Because you want to start the call yourself and get the user to press 1 in case they want to accept the question, you're going to want to use the REST API. Specifically, you want to initiate a new call that will then prompt the user to press the button. The code below is C#.

public void CallUser(){
    var client = new TwilioRestClient(AccountSid,AuthToken);
    client.InitiateOutboundCall("from", "to", "/Call");
    client.InitiateOutboundCall("from", "to", "/Conference");
}

On the code above I am initiating two calls. One to the customer, and one to the other person that should be on the line. you can change the logic for that if you want, but in the interest of simplifying things, I am initiating both calls at the same time.

The first call will then drop the user on the menu where they will be able to press 1 to join the call.

public IActionResult Call()
{
    var twiml = new TwilioResponse();
    return TwiML(twiml.BeginGather(new { action = "/Conference", numDigits = "1" }).Say("Press 1 to start the conference call").EndGather());
}

Both calls are then redirected to /conference, where the conference room is either created or joined. you can have logic to check whether the user dialled 1 here.

public IActionResult Conference()
{
    var twiml = new TwilioResponse();
    return TwiML(twiml.DialConference("Room 1234"));
}

Hope this helps you



标签: twilio twiml