Data Dill
Data Dill

Reputation: 415

How to check if Twilio conference call has >1 person?

I need to know how to check an existing conference bridge to see how many users are currently in the call. If this is not possible, simply being able to see that a conference is open or not would probably achieve the same thing.

Explanation: I have a twilio flow that creates a conference with a hard coded value of "123". If a user calls in and nobody is in the conference, I want it to place the user in the conference and continue on with the rest of the flow. However, if 2 or more users are already in the conference and a 3rd user calls in, I would like to have that 3rd user be placed in the conference and have nothing else execute.

// This is your new function. To start, set the name and path on the left.

exports.handler = function(context, event, callback) {
  // Here's an example of setting up some TWiML to respond to with this function
    const client = context.getTwilioClient();
  let syncServiceSid = 'mySyncSid';
  

  var participants
  participants = client.conferences('12345') 
    .participants 
    .list({limit: 20})
    .then(participants => participants.forEach(p => console.log(JSON.stringify(participants))));

  // This callback is what is returned in response to this function being invoked.
  // It's really important! E.g. you might respond with TWiML here for a voice or SMS response.
  // Or you might return JSON data to a studio flow. Don't forget it!
  return callback(null, participants);
};

Upvotes: 0

Views: 225

Answers (1)

yvesonline
yvesonline

Reputation: 4857

I need to know how to check an existing conference bridge to see how many users are currently in the call.

You can use the Conference Participant Resource to retrieve the number of participants, in Python this would look like this (where CFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX is your conference sid):

from twilio.rest import Client
client = Client(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)
participants = client.conferences('CFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \
                     .participants \
                     .list(limit=20)

The documentation has code examples for other programming languages.

Upvotes: 1

Related Questions