I'm trying to use the Twilio Programmable Voice JavaScript SDK to make an outbound call with a statusCallback and statusCallbackEvent so I can update another system after the call is completed.
Here's my code.
async function makeOutgoingCall() {
const params = {
// get the phone number to call from the DOM
To: phoneNumberInput.value,
CallerId: myCallerId,
statusCallback: OutBoundCallbackURL,
statusCallbackEvent: 'completed'
};
console.log(params);
if (device) {
log(`Attempting to call ${params.To} from caller id: ${params.CallerId} ...`);
// Twilio.Device.connect() returns a Call object
const call = await device.connect({ params });
dtmf_1.onclick = function(){call.sendDigits('1')};
dtmf_2.onclick = function(){call.sendDigits('2')};
dtmf_3.onclick = function(){call.sendDigits('3')};
dtmf_4.onclick = function(){call.sendDigits('4')};
dtmf_5.onclick = function(){call.sendDigits('5')};
dtmf_6.onclick = function(){call.sendDigits('6')};
dtmf_7.onclick = function(){call.sendDigits('7')};
dtmf_8.onclick = function(){call.sendDigits('8')};
dtmf_9.onclick = function(){call.sendDigits('9')};
dtmf_0.onclick = function(){call.sendDigits('0')};
dtmf_s.onclick = function(){call.sendDigits('*')};
dtmf_h.onclick = function(){call.sendDigits('#')};
/*
* add listeners to the Call
* "accepted" means the call has finished connecting and the state is now "open"
*/
call.on('accept', updateUIAcceptedOutgoingCall);
call.on('disconnect', updateUIDisconnectedOutgoingCall);
call.on('cancel', updateUIDisconnectedOutgoingCall);
call.on('reject', updateUIDisconnectedOutgoingCall);
outgoingCallHangupButton.onclick = () => {
log('Hanging up ...');
call.disconnect();
};
} else {
log('Unable to make call.');
}
}
I'd like it to send back TwiML like this:
<Response>
<Dial answerOnBridge="true" callerId="+19876543210">
<Number
statusCallbackEvent="completed"
statusCallback="https://myapp.com/calls/events"
statusCallbackMethod="POST">
+12349013030
</Number>
</Dial>
</Response>
But it's sending back this:
<Response>
<Dial answerOnBridge="true" callerId="+19876543210">
<Number>+1123456789</Number>
</Dial>
</Response>
I can't find a list of possible parameters for device.connect(). Not even sure that's what I need to edit.
Can someone help me out?