Search code examples
node.jstwiliotwilio-programmable-voice

Access Denied when added participant to conference in Twilio Voice


I have 2 endpoints in my api, one to create a Voice conference and another one to add a participant to a conference.

The first one is the following and works correctly.

module.exports.call = function (req, res) {
    let name = 'conf_' + req.body.CallSid

    const twiml = new twilio.twiml.VoiceResponse()
    const dial = twiml.dial({ callerId: req.configuration.twilio.callerId })

    dial.conference(
        {
            endConferenceOnExit: true,
            statusCallbackEvent: 'join',
            statusCallback: `/api/phone/call/${req.body.CallSid}/add-participant/${encodeURIComponent(req.body.phone)}`
        },
        name
    )

    res.set({
        'Content-Type': 'application/xml',
        'Cache-Control': 'public, max-age=0',
    })

    res.send(twiml.toString())
}

As you can see, the statusCallback URL points to the controller below, which should add a participant to the conference.

module.exports.addParticipant = function (req, res) {

    console.log('addParticipant', req.params)

    if (req.body.CallSid === req.params.sid) {
        /* the agent joined, we now call the phone number and add it to the conference */
        conference = client.conferences('conf_' + req.params.sid)
        console.log('conference', conference)
        client
            .conferences('conf_' + req.params.sid)
            .participants.create({
                to: '+34XXXXXXXXX',
                from: req.configuration.twilio.callerId,
                earlyMedia: true,
                endConferenceOnExit: true
            }).then(participant => {
                res.status(200).end()
            })
            .catch(error => {
                console.error(error)
                res.status(500).end()
            })

    } else {
        res.status(200).end()
    }

}

However, I'm getting the following error:

[RestException [Error]: Access Denied] {
  status: 403,
  message: 'Access Denied',
  code: 20006,
  moreInfo: 'https://www.twilio.com/docs/errors/20006',
  detail: undefined
}

I have enabled the geo permissions for this numbers country, but still no success.

What am I missing?


Solution

  • Did you make sure to enable Agent Conference in your Account?

    Voice Conference Settings https://www.twilio.com/console/voice/conferences/settings