我正在用Twilio构建一个简单的应用程序以创建私人电话会议。这意味着将仅将参加呼叫的特定号码添加到会议中,所有其他号码将被拒绝。我正在使用ngrok将本地托管的项目联机。现在的问题是,无论是否有“ if”声明,任何参加会议的电话号码都可以加入。我只希望“主持人”和“与会者”能够打电话。这是我到目前为止的内容:
var express = require('express');
var http = require('http');
var path = require('path');
var app = express();
const accountSid = 'blah blah blah';
const authToken = 'blah blah blah';
const client = require('twilio')(accountSid, authToken);
const VoiceResponse = require('twilio').twiml.VoiceResponse;
const urlencoded = require('body-parser').urlencoded;
const moderator = "+11234567890";
const attendee = '+10987654321';
app.use(urlencoded({ extended: false }));
app.post('/voice', (request, response) => {
const twiml = new VoiceResponse();
const dial = twiml.dial();
if(request.body.From == attendee || request.body.From == moderator){
dial.conference('Room1234', {
startConferenceOnEnter: true,
endConferenceOnExit: true
});
} else {
twiml.reject()
dial.conference('Room1234', {
startConferenceOnEnter: false
});
}
response.type('text/xml');
response.send(twiml.toString());
});
console.log('Twilio Client app HTTP server running at
http://127.0.0.1:8080');
app.listen(8080);
答案 0 :(得分:0)
在dial()
之后不需要reject()
,请尝试如下操作:
app.post('/voice', (request, response) => {
const twiml = new VoiceResponse();
if (request.body.From === attendee || request.body.From === moderator) {
const dial = twiml.dial();
dial.conference('Room1234', {
startConferenceOnEnter: true,
endConferenceOnExit: true
});
} else {
twiml.reject();
}
response.type('text/xml');
response.send(twiml.toString());
});