I'm trying to implement a simple Simulring with a Wisper in Twilio Functions. Everything is working perfect with one exception. When the agent accepts the call and has a conversation with the caller, if the agent disconnects first, the caller is still routed to the voicemail prompt.
I can take out my if/else bit, but then nobody gets the voicemail even when the agent fails to pick up.
I need to detect if the agent hangs up, then add a hangup action and/or detect if the agent does not accept the call and route those properly to the voicemail. But I'm doing something wrong...
There are three parts to the function but here's the main bit:
`/dial-function
`exports.handler = function(context, event, callback) {
var response = new Twilio.twiml.VoiceResponse();
var dial = response.dial({
answerOnBridge: 'true'
});
dial.number({
url: '',
statusCallback: '/dial',
statusCallbackEvent: ['completed'] // Receive status callback when the dialed call ends
}, '+1xxx'); // Phone number to forward the call
// Hang up the call if the dialed call is disconnected
if (event.DialCallStatus === 'completed') {
response.hangup();
return callback(null, response);
} else {
(event.DialCallStatus !== 'completed')
// Play voicemail message
response.play('/busy.mp3');
// Record voicemail after timeout
response.record({
timeout: 10,
playBeep: true,
finishOnKey: '1',
action: '/forwardVM',
method: 'POST'
});
return callback(null, response);
}
};`
These shouldnt matter for troubleshooting since they work perfect but I will include in case anyone needs the assist:
`/confirm-call
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
let gather = twiml.gather({
numDigits: 1,
action: '/connect'
})
gather.say('GradePower Valrico call, press any key to accept.'); //Here you can add any message you want to say
twiml.say("Sorry, I haven’t received any response. Good bye!")
twiml.hangup()
return callback(null, twiml);
};`
and
`/connect
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
twiml.say('Connecting');
return callback(null, twiml);
};`