I'm trying to write a simple Twilio setup that will make an outbound call, record a user's voice message and immediately replay it back to him. I have created two functions: startcall
and msgin
. StartCall calls the user and specifies MsgIn in the call's url
parameter. MsgIn then has two main modes of operation: initially when there is no recording attached it returns a TwiML response starting the recording, and later when called as a webhook with the appropriate parameter it plays the recording back and hangs up. At least that's what it should do.
According to my understanding of the documentation, I have to attach a webhook to recordingStatusCallback
, as the recording may not yet be available when action
webhook is invoked. However, while the function console indicates that both webhooks are executed, the call log only shows one follow-up invocation of msgin
with a null value for event.RecordingStatus
(which corresponds to action
), and the call indeed hangs up without playing the recording back. What am I missing here?
// this function's path is /msgin
exports.handler = function(context, event, callback) {
if (!event.RecordingStatus && !event.RecordingUrl) {
let twiml = new Twilio.twiml.VoiceResponse();
console.log("Initial MsgIn");
twiml.say({ voice: 'man', language: 'en-us' }, 'Leave your message');
twiml.record({
playBeep: false,
transcribe: false,
trim: "trim-silence",
timeout: 1,
recordingStatusCallback: "/msgin",
recordingStatusCallbackEvent: "completed",
action: "/msgin"
});
console.log("Recording started");
callback(null, twiml);
}
else if (event.RecordingStatus == "completed") {
let twiml = new Twilio.twiml.VoiceResponse();
console.log("Supposedly callback");
twiml.say({ voice: 'man', language: 'en-us' }, 'You said');
twiml.play(event.RecordingUrl);
twiml.hangup();
callback(null, twiml);
}
else {
console.log("Supposedly action");
callback(null, "");
}
};