Search code examples
node.jsherokutwiliotwilio-apitwilio-twiml

Why do I get a list of undefined conferences from client.conferences.each()?


Running a Node/Twilio app on Heroku. I want to put a participant into a conference, and then get information about the conference that the participant is in.

Here is how I return the Twiml that puts the participant into the conference:

//response parameter is a VoiceResponse
function addConferenceToResponse(response,params){
    baseUrl=APP_URL+'ivr/conferenceControl';
    console.log("addConferenceToResponse: baseUrl "+baseUrl);

    //serializes the parameter array and adds it the the GET request
    url=addArrayToGetRequest(baseUrl,params,"params");

    const dial = response.dial({
        action: url,
        method: 'GET',
        hangupOnStar: true
    });
    dial.conference(params.conferenceName,{
        statusCallbackEvent:'start end join leave',
        statusCallback:APP_URL+'ivr/statusChangeConference',
        statusCallbackMethod:'GET',
        waitUrl:waitUrl,
        waitMethod:'GET'
    });

    return response.toString();
}

Following the model here, I have a function for returning a list of conference statuses and FriendlyNames:

function listConferences(){
    client.conferences.each((conference) => {
        console.log("list conferences: " + conference.status);
        console.log("list conferences: " + conference.friendly_name);
    })
}

which I call in the conference's StatusCallback like this:

router.get('/statusChangeConference',(req,res)=>{
    status=req.query.StatusCallbackEvent;
    if (status=="participant-join"){
        handler.listConferences();
    }
    sendValue=doSomethingToGetASendValue();
    if (sendValue!=null){
        res.send(sendValue);
    }
});

listConferences() ends up returning hundreds of lines of:

2018-03-31T21:39:41.734717+00:00 app[web.1]: list conferences: completed
2018-03-31T21:39:41.734769+00:00 app[web.1]: list conferences: undefined

Which means, I think, that it's returning all past conferences, which now no longer have FriendlyNames I guess? But the current, active conference is not shown in this list. So maybe this StatusCallbackEvent is getting executed before Twilio has a chance to enter the conference into its database.

How can I get the properties of the currently active conference(s)? One thing I'm trying to do is redirect all remaining conference participants to another URL if one of them leaves, and that doesn't seem possible without being able to get the current conference and do something like:

client.conferences.each(conference=>{
    conference.participants.each(participant=>{
        client.calls(participant.CallSid).update({
            //url redirect stuff here
        });
    });
});

But I can't do that if I can't get the currently active conferences.


Solution

  • I'm not sure why, but when I add search options, I successfully locate the conference that I'm interested in:

    exports.listConferences=function listConferences(friendlyName){
    
        const opts = {status: 'in-progress',
                        friendlyName:friendlyName};
    
        client.conferences.each(opts,(conference) => {
            console.log("listing conference properties: ");
            Object.entries(conference).forEach(
                ([key, value]) => console.log(key, value)
            );
        });
    }
    

    It could be that it was turning up in the list before and I just didn't spot it amidst all the completed conferences.