Skip to content

Instantly share code, notes, and snippets.

@jmadden
Last active July 19, 2023 22:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jmadden/70e7e48e2bff894dbfd463b78e36321c to your computer and use it in GitHub Desktop.
Save jmadden/70e7e48e2bff894dbfd463b78e36321c to your computer and use it in GitHub Desktop.
Voice mail system using Twilio Functions
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
const OWNER = '+1##########'; //Your mobile number.
if(event.From == OWNER){
const gather = twiml.gather({
action:'/callOut'
});
gather.say("Please enter the phone number you'd like to call followed by the pound sign.");
} else {
twiml.sms({from:'+1##########', to:'+1##########'}, `You received a call from ${event.From}.`); //from = Twilio phone number. to = your mobile number.
dial = twiml.dial({
callerId:'+1##########', //Your Twilio phone number.
action:'/vmail'
});
dial.number({
url:'/whisper'
}, OWNER);
}
callback(null, twiml);
};
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
dial = twiml.dial({
callerId:'+1##########' //Your Twilio number.
});
dial.number("+"+event.Digits);
callback(null, twiml);
};
<?xml version="1.0" encoding="UTF-8"?>
<Response />
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
if(event.Digits && event.Digits === null ){
twiml.hangup();
} else {
twiml.say("Your call is now being connected.");
}
callback(null, twiml);
};
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
if (event.DialCallStatus === "completed" || event.DialCallStatus === "answered") {
twiml.hangup();
}
//Change this to reflect your own personal message.
twiml.say("You have reached my voice mail. Please leave a message.");
//Or use play to play a recorded message
//twiml.play("https://your-url.io/voicemail.mp3");
twiml.record({
action: "empty-response.xml", //Use a link to a TwiML Bin for this value.
method: "GET",
maxLength: "200",
recordingStatusCallback: "/vmlink"
});
twiml.sms({from:'+1##########', to:'+1##########'}, `The last caller did not leave a VMail.`);
callback(null, twiml);
};
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
let gather = twiml.gather({
action: "/gather-results",
numDigits: "1",
timeout: "10"
});
gather.say({loop:"2"}, 'You have an incoming call. Press any number key to accept the call, or hang up to send the caller to voice mail.');
twiml.hangup();
callback(null, twiml);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment