Last active
June 16, 2019 18:26
-
-
Save atbaker/eba9bfd7d8c1443dd951ac3b4cd3eae4 to your computer and use it in GitHub Desktop.
Create your own voicemail with Twilio and Node.js https://twitter.com/andrewtorkbaker/status/1140310282255790080
This file contains hidden or 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
// Remember to add "/voicemail-record" as the path for your function in the field above! | |
exports.handler = function(context, event, callback) { | |
// Initialize our TwiML response. What's TwiML? Learn more here: | |
// https://www.twilio.com/docs/glossary/what-is-twilio-markup-language-twiml | |
let twiml = new Twilio.twiml.VoiceResponse(); | |
// <Say> a message to the caller first (feel free to customize it!) | |
twiml.say({ | |
voice: "alice" | |
}, "The person you called is unable to answer the phone. Please leave a message after the beep."); | |
// And then <Record> the caller's message and ask Twilio to transcribe it | |
twiml.record({ | |
maxLength: 120, // 2 minutes max length | |
transcribe: true, | |
transcribeCallback: "/voicemail-transcription" | |
}); | |
// Say goodbye and end the call if the caller hasn't hung up already | |
twiml.say({ | |
voice: "alice" | |
}, "Thank you. Goodbye."); | |
twiml.hangup() | |
// Return our TwiML response | |
callback(null, twiml); | |
}; |
This file contains hidden or 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
// Remember to add "/voicemail-transcription" as the path for your function in the field above! | |
exports.handler = function(context, event, callback) { | |
// Get our Twilio REST API client | |
let client = context.getTwilioClient(); | |
// Create the body of our text message | |
let body = `You have a new voicemail from ${event.From}: | |
"${event.TranscriptionText}" | |
Recording: ${event.RecordingUrl}`; | |
// Send a text message to ourselves with the transcription and a link to | |
// the recording. Be sure to use E.164 format for the 'to' and 'from' | |
// numbers: https://www.twilio.com/docs/glossary/what-e164 | |
client.messages.create({ | |
to: '+15555555555', // Your phone number goes here | |
from: '+19999999999', // Your Twilio phone number goes here | |
body: body | |
}, function(err, result) { | |
// No need to return anything this time | |
callback(); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment