node.js - 在 Twilio Voice 中将参与者添加到 session 时访问被拒绝

标签 node.js twilio twilio-programmable-voice

我的 API 中有 2 个端点,一个用于创建语音 session ,另一个用于向 session 添加参与者。

第一个如下并且工作正常。

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

如您所见,statusCallback URL 指向下面的 Controller ,该 Controller 应将参与者添加到 session 中。

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

}

但是,我收到以下错误:

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

我已启用该号码国家/地区的地理权限,但仍然没有成功。

我错过了什么?

最佳答案

您确定在您的帐户中启用了代理 session 吗?

语音 session 设置 https://www.twilio.com/console/voice/conferences/settings

关于node.js - 在 Twilio Voice 中将参与者添加到 session 时访问被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58938686/

相关文章:

javascript - Twilio 视频——无视频和静音方法

node.js - 如何从 Twilio 可编程语音功能中发送短信

node.js - Promise 的 Mocha 单元测试抛出错误

javascript - Twilio 到 OnSip 应用程序错误 : Dial->Sip: SIP URI DNS does not resolve or resolves to an non-public IP address

node.js - 无法在中间件中获取 JWT token

php - 如何接收发送到 twilio 号码的短信

jwt - 功能 token 无效或丢失 Twilio

ios - 在 iOS 应用程序中接收可编程语音调用的 Twilio 调用者姓名

mysql - 如何执行 Sequelize 连接

javascript - 使用上下文包装应用程序组件并获取 TypeError : (destructured parameter) is undefined