为什么我从client.conferences.each()获得未定义会议的列表?

时间:2018-03-31 21:58:34

标签: node.js heroku twilio twilio-api twiml

在Heroku上运行Node / Twilio应用程序。我想让参加者参加会议,然后获取参与者所在会议的相关信息。

以下是我如何返回将参加者加入会议的Twiml:

//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();
}

在模型here之后,我有一个返回会议状态列表和FriendlyNames的功能:

function listConferences(){
    client.conferences.each((conference) => {
        console.log("list conferences: " + conference.status);
        console.log("list conferences: " + conference.friendly_name);
    })
}
我打电话给会议的StatusCallback就像这样:

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

listConferences()最终会返回数百行:

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

我认为,这意味着它已经回归所有过去的会议,我现在不再拥有FriendlyNames了?但目前的活跃会议未在此列表中显示。因此,在Twilio有机会将会议进入其数据库之前,这个StatusCallbackEvent可能会被执行。

如何获取当前活动会议的属性?我试图做的一件事是将所有剩余的会议参与者重定向到另一个URL,如果其中一个离开,并且在没有能够获得当前会议的情况下似乎无法做到:

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

但如果我无法获得当前活跃的会议,我就无法做到。

1 个答案:

答案 0 :(得分:1)

我不确定原因,但是当我添加搜索选项时,我成功找到了我感兴趣的会议:

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)
        );
    });
}

可能是它之前出现在列表中,我只是没有在所有已完成的会议中发现它。