我有一个功能,可以让你录制,如果你不满意,可以删除你的录音。当您按 * 时,您可以删除您最后的录音。
我的录音代码是:
exports.handler = function(context, event, callback) {
const twiml = new Twilio.twiml.VoiceResponse();
twiml.say('Welcome! Please record your announcement after the beep!');
twiml.say('After your recording, hang up if you are satisfied or press star to delete the newest recording.');
twiml.record({
finishOnKey: '*',
recordingStatusCallback: '/delete',
action: '/delete'
});
callback(null, twiml);
};
删除最后一段录音的代码(/delete):
exports.handler = function(context, event, callback) {
const twiml = new Twilio.twiml.VoiceResponse();
const id = event.RecordingSid;
console.log(id);
console.log(typeof id);
const accountSid = 'AC1775ae53d952710bb1b4e47ea19c009c';
const authToken = {my_token};
const client = require('twilio')(accountSid, authToken);
client.recordings(id)
.remove(function(err, data) {
if (err) {
twiml.say("there is an error");
console.log(err.status);
throw err.message;
} else {
console.log("deleted successfully.");
twiml.say("deleted successfully");
}
})
.then(recording => console.log(recording.sid))
.done();
twiml.say('Your announcement is deleted');
callback(null, twiml);
};
现在,我得到了正确的 id 并且没有错误,但是当我检查录音日志时,录音仍然存在。这是为什么?我需要给它一些时间让它删除吗?
来自的日志console.log(recording.sid)
也没有显示,我不确定为什么它没有执行应该删除记录的整个代码块。
提前致谢!