I have an application (Node.js backend and React frontend) which provides a feature of outgoing and incoming calls using Twilio. I would like to add a functionality of voice coaching (optional third person joining actively, passively or whispering (talking only to one other party). I assume I have to transform normal calls into voice conferences to do so and then add a conference participant if required.
The hard part for me is a way to transform a call (or move to) into conference so that there is a conference between Twilio app and a normal mobile phone user (and optional third party - coach). How can this be achieved? My question is regarding both outgoing and incoming calls.
My code for outgoing calls (fired from frontend):
Frontend:
const params = { To: '+48123456789, fromNumber: '+480987654321 };
let call = await device.connect(params);
Backend:
const response = new VoiceResponse();
const dial = response.dial({ callerId: fromNumber, record: "record-from-answer", recordingStatusCallback: "/twilio/voice/record" });
dial.number(req.body.To);
res.set("Content-Type", "text/xml");
res.send(response.toString());
Incoming calls - backend:
const response = new VoiceResponse();
const dial = response.dial({
callerId: req.body.From,
answerOnBridge: true,
record: "record-from-answer",
recordingStatusCallback: "/twilio/voice/record",
});
const client = dial.client();
client.identity('user@mydomain.com');
res.set("Content-Type", "text/xml");
res.send(response.toString());