我正在尝试编写一个简单的 Twilio 设置,该设置将进行出站呼叫,记录用户的语音消息并立即将其重播给他。我创建了两个函数:startcall
和msgin
. StartCall调用用户并在调用的参数中指定MsgIn 。然后, MsgIn有两种主要的操作模式:最初,当没有附加录音时,它会返回一个 TwiML 响应,开始录音,然后当作为带有适当参数的 webhook 调用时,它会回放录音并挂断。至少这是它应该做的。url
根据我对文档的理解,我必须将 webhook 附加到,因为调用 webhookrecordingStatusCallback
时可能还没有记录。action
然而,虽然函数控制台显示两个 webhook 都已执行,但调用日志只显示了一个后续调用(对应于),其msgin
值为空,并且调用确实挂断了,没有回放录音。我在这里想念什么?event.RecordingStatus
action
// 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, "");
}
};