0

I want to create a conference to multiple numbers using Twilio and Nodejs.

In my application I want to create a conference from the number I bought from Twilio to multiple numbers.

I am following this link.

My code is as follows

const Twilio = require('twilio');
const client = new Twilio(account_sid, authToken);


mobileArr.forEach(function(number,ind) {
    console.log("mobile array iteration",ind, number);
    client
      .conferences(conferences.title)
      .participants.create({
        to: number,             //number which i want to add to conference
        from: myTwilioNumber,  //number I bought from Twilio
        statusCallback: twilioCallBackUrl,
        statusCallbackMethod: 'POST',
        statusCallbackEvent: ['initiated', 'ringing', 'answered', 'completed'],
        Timeout: '15',
        method: 'GET',
    }, function(err, participant) {
        if (err) {
            console.error('conf failed because: '+ err);
        } else {
           console.log(participants)
        }
    })
})

The issue I am facing is I am not receiving all the webhook callback for all participants I have added to the conference properly.

I want to know that, am I doing it the right way or is there another better way of doing it.

Suppose I add 3 participants to a conference I Should receive a total 12 callBacks from Twilio for 'initiated', 'ringing', 'answered', 'completed' for each individual person I have added to the conference. But on some occasion's this does not happen.

Is there a way through which I can recieve callBacks for conference status as a whole.

Is there a way to pass an array of numbers to create conference instead of adding each number in the forEach loop.

I am new to Twilio please help.

Anand Yadav
  • 479
  • 5
  • 17
  • Are you setting the statusCallback (the `twilioCallBackUrl`) to an absolute or relative URL (as it should be absolute)? Also, do you see anything in the [Twilio console debugger](https://www.twilio.com/console/dev-tools/debugger)? – philnash Apr 30 '18 at 04:05
  • @philnash It's an absolute url, No I do not see anything in the Twilio Debugger console. Please tell me is my approach for initiating conference Right? – Anand Yadav Apr 30 '18 at 05:38
  • Yeah, that approach is correct for making outbound calls to initiate and dial people into a conference. There is no batch calling process, so you do have to loop. Are you finding that your participants are receiving the calls and entering the conference? – philnash Apr 30 '18 at 05:40
  • Yes majority of time all people i add into conference receive calls – Anand Yadav Apr 30 '18 at 05:44
  • @philnash Or is there a better way to do so in nodejs, where in I can pass a array of phone numbers, instead of iterating over a for loop like the [this](https://stackoverflow.com/questions/43885628/adding-multiple-people-to-a-conference-call-from-caller-twilio) link which is in php – Anand Yadav Apr 30 '18 at 05:44
  • No, you do need to loop through the callers, that's the only way to achieve this. So the only issue is that you are not receiving the webhook to the statusCallback URL? – philnash Apr 30 '18 at 05:48
  • @philnash Sorry i have modified my question. – Anand Yadav Apr 30 '18 at 06:01
  • @philnash Is there a way through which I can recieve callBacks for conference status? – Anand Yadav Apr 30 '18 at 06:01
  • When you say "But on some occasion's this does not happen." does that mean you do get the webhook events some of the time? – philnash May 01 '18 at 05:04
  • Yes this what happens, is there a way through which I can receive callBacks only for conference status? – Anand Yadav May 02 '18 at 04:42
  • Have you tried setting a `ConferenceStatusCallback` URL instead? – philnash May 02 '18 at 08:54
  • I will try out and let you know, thanks. – Anand Yadav May 04 '18 at 14:22
  • @philnash thanks worked for me – Anand Yadav May 08 '18 at 07:41

1 Answers1

0

Only a couple of modifications in the code and things are working fine.

Simply add conferenceStatusCallback and conferenceStatusCallback to the above code, implement the desired logic in callbacks.

const Twilio = require('twilio');
const client = new Twilio(account_sid, authToken);


mobileArr.forEach(function(number,ind) {
    console.log("mobile array iteration",ind, number);
    client
      .conferences(conferences.title)
      .participants.create({
        to: number,             //number which i want to add to conference
        from: myTwilioNumber,  //number I bought from Twilio
        statusCallback: callBackUrl,//any logic on call events
        statusCallbackMethod: 'POST',
        statusCallbackEvent: ['initiated', 'ringing', 'answered', 'completed'],
        conferenceStatusCallbackEvent: ['start', 'end','join','leave'],
        conferenceStatusCallback:conferenceCallBackUrl, //any business logic on conference events
        Timeout: '15',
        method: 'GET',
    }, function(err, participant) {
        if (err) {
            console.error('conf failed because: '+ err);
        } else {
           console.log(participants)
        }
    })
})

Thats it. Thanks, philnash.

Anand Yadav
  • 479
  • 5
  • 17