我的 api 中有 2 个端点,一个用于创建 a Voice conference
,另一个用于将参与者添加到conference
.
第一个是以下并且可以正常工作。
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 指向下面的控制器,它应该将参与者添加到会议中。
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
}
我已启用此号码国家/地区的地理权限,但仍然没有成功。
我错过了什么?