Search code examples
twiliotwilio-phptwilio-api

Twilio outbound call to conference


I need help. I have an agent and client situation. If the Agent make an outbound call and the client answer it, There is a button on my system which should redirect the both of the agent and client to a conference. The below code is my function which dial the number that is input by the agent.

function dialCall(num)
{
   params = {"phoneNumber": num, "record":"record-from-answer", "callStatus":"call", "callerId": callerId, "caller":agent_id};
   conn = Twilio.Device.connect(params);
   initializeStatus('Busy');
   isDialCall = true;
   return conn;
}

So the question is is it possible to put the caller and callee to the conference at the same time?


Solution

  • It is absolutely possible to do that . In the code you mentioned above Twilio.Device.connect(params) invokes the Voice URL associated with the TwiML App in your account .

    This Voice URL could do the function of dialing both the caller and calle in the same conference by doing the following two things

    1. Dial the caller in conference by giving back the TwiML Response <Dial><Conference>
    2. Initiate a REST API Call to destination with URL set to an endpoint that dials him to the same conference.

    A sample code (nodejs ) is listed below

    app.get("/handleOutgoingAsConference",function(i_Req,o_Res)
    {
      var ivrTwilRes = new twilio.TwimlResponse();
      var agentNum=i_Req.query.phoneNumber;
      /*read other params here */ 
      ivrTwilRes.dial(
        function(node) {
          node.conference('Conference_Caller_Callee', { beep:'false' , endConferenceOnExit:'true'})
        }
      );
      var restClient = new twilio.RestClient(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN);
      restClient.calls.create(
        {
          url: "/justDialIntoConference",
          to: agentNum,
          from: "+yourCallerId",
          method: "GET",
        }, 
        function(err, call) 
        {
          if(err)
            {
              console.log(err.message);
            }
        }
      ); 
      o_Res.set('Content-Type','text/xml');
      o_Res.send(ivrTwilRes.toString());
    });
    
    app.get("/justDialIntoConference",function(i_Req,o_Res)
    {
      var ivrTwilRes = new twilio.TwimlResponse();
      ivrTwilRes.dial(
        function(node) {
          node.conference('Conference_Caller_Callee', { beep:'false' , endConferenceOnExit:'true'})
        }
      );
      o_Res.set('Content-Type','text/xml');
      o_Res.send(ivrTwilRes.toString());
    });
    

    You could combine the above two functions , I have kept it separate for the sake of simplicity .

    Hope it helps