Twilio developer evangelist here.
You can absolutely connect two people in the way that you describe.
First up, to generate the call you need to use the REST API. I noticed you tagged the post with node.js, so you can make this easy on yourself by using the Twilio Node library. You need to provide 3 parameters, your Twilio number that you are dialling from, the number you want to dial and a URL. I'll come to the URL after the code you need:
var accountSid = 'YOUR_ACCOUNT_SID';
var authToken = 'YOUR_AUTH_TOKEN';
var client = require('twilio')(accountSid, authToken);
client.calls.create({
url: 'http://example.com/connect',
to: 'AGENT_NUMBER',
from: 'YOUR_TWILIO_NUMBER'
}, function(err, call) {
if (err) { console.error('There was a problem starting the call: ', err); }
console.log(`Call with sid: ${call.sid} was started`);
});
The URL you supply should point at your application to an endpoint that will return some TwiML that tells Twilio what to do next with the call. In this case, we want to connect the call onto the client's number, so we will use <Dial>
. Imagining that you are using Express as the server, your endpoint would look a bit like this:
const VoiceResponse = require('twilio').twiml.VoiceResponse;
app.post('/connect', (req, res) => {
const response = new VoiceResponse();
const dial = response.dial();
dial.number('CLIENT_NUMBER');
res.send(response.toString());
});
This TwiML will tell Twilio to connect the call to the CLIENT_NUMBER and your agent and client will be talking.
Let me know if that helps at all.