Created
November 3, 2017 18:33
-
-
Save armiiller/d62accc5c13bcd1a9447fc754df85966 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('starting function'); | |
const qs = require('qs'); | |
const VoiceReponse = require('twilio').twiml.VoiceResponse; | |
exports.handle = function(e, ctx, cb) { | |
console.log('processing event: %j', e) | |
var twiml = new VoiceReponse(); | |
var noanswerurl = process.env.NOANSWERURL || null; | |
var thanksformessageurl = process.env.THANKSFORMESSAGEURL || null; | |
var recordingstatuscallback = process.env.RECORDINGSTATUSURL || '/recordstatus'; | |
var messagemaxlength = process.env.MESSAGEMAXLENGTH ? parseInt(process.env.MESSAGEMAXLENGTH) : 30; | |
var body = {}; | |
if(e && e.reqbody){ | |
body = qs.parse(e.reqbody); | |
} | |
switch(body.DialCallStatus){ | |
case 'no-answer': | |
if(noanswerurl){ | |
twiml.play(noanswerurl); | |
}else { | |
twiml.say("Sorry we couldn't get to the phone, please leave a message after the beep."); | |
} | |
twiml.record({ maxLength: messagemaxlength, recordingStatusCallback: recordingstatuscallback}); | |
break; | |
default: | |
if(thanksformessageurl){ | |
twiml.play(thanksformessageurl); | |
} else { | |
twiml.say("Thanks for your message! We will get back to you soon. Goodbye."); | |
} | |
twiml.hangup(); | |
break; | |
} | |
var responseBody = twiml.toString(); | |
var response = { | |
statusCode: 200, | |
body: responseBody | |
}; | |
cb(null, response); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment