I am attempting to modify the following code to perform a whisper and require the agent who answers to press 1. If they do not answer or do not press 1, the call will then go to voicemail. I need this to be in a function simply because I can't call a Twiml Bin from Studio. Any help would be greatly appreciated. The source of the script below is https://github.com/philnash/useful-twilio-functions/tree/master/hunt.
exports.handler = function(context, event, callback) {
const numbers = context.PHONE_NUMBERS.split(',').map(number => number.trim());
const response = new Twilio.twiml.VoiceResponse();
if (event.DialCallStatus === 'complete') {
// Call was answered and completed
response.hangup();
} else if (event.finished === 'true') {
if (context.FINAL_URL) {
response.redirect(context.FINAL_URL);
} else {
response.hangup();
}
} else {
const numberToDial = event.nextNumber ? event.nextNumber : numbers[0];
const currentNumberIndex = numbers.indexOf(numberToDial);
let url;
if (currentNumberIndex + 1 === numbers.length) {
// No more numbers to call after this.
url = '/hunt?finished=true';
} else {
const nextNumber = numbers[currentNumberIndex + 1];
url = '/hunt?nextNumber=' + encodeURIComponent(nextNumber);
}
const dial = response.dial({ action: url });
dial.number(numberToDial);
}
callback(null, response);
};