我正在用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);

最佳答案

您不需要在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());
});

关于node.js - 私有(private)电话 session ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55861275/

10-16 09:44