Functions Classic
. The new Services
feature doesn’t support what we need to do yet. Click the red plus and give this any name you want voicemail-recorder
for example.Runtime->Assets
. Select Assets (Classic)
in the sidebar, and upload your file. Make sure it’s public. Once it’s uploaded select the URL in the PATH
field and save it somewhere, you’ll need this in a moment.Functions Classic
menu, and open your function. Let’s give it a PATH
like /voicemail
(this must start with a slash). Underneath in the configuration field make sure Access Control
is disabled, select the Event
to be Incoming Voice Calls
, and then in the Code
box enter the following. Make sure to put your saved asset URL in!exports.handler = function (context, event, callback) {
const twiml = new Twilio.twiml.VoiceResponse()
twiml.play('YOUR FILE') // Put your asset URL in this between the quote marks
twiml.record({
timeout: 10, // The number of seconds of silence to wait before hanging up
transcribe: false, // Change this to true if you want Twilio to try to transcribe your recordings ($)
maxLength: 300, // This is the maximum length that the audio recording can be.
playBeep: true // This tells the function to play a bleep after your message or not.
})
twiml.hangup()
callback(null, twiml)
}
Voice & Fax
options. Select Accept Incoming
and check it’s set only to Voice Calls
. Then where it reads A call comes in
change the first option in the drop down menu to Function
, and now in the Service
menu that appears to the right, select default
, and from the Function path
menu, your path.Calls log->Incoming
menu of your phone number.If you have questions, or can’t get it working, give me a tweet and I’ll see if I can help you out.
It is possible for a hostile actor to attack you by repeatedly calling your number and leaving long messages. Though they will not be able to block legitimate contributors, they can cost you money, and they can cost you time in sifting through the results.
It is also possible for your fun experiment to turn into $1 a month forever unless you turn off your phone number at the end of the project. Make sure to remove any reference to the phone number from your reporting at this point, as otherwise it is possible for another actor to potentially take over the number.