【发布时间】:2019-06-06 06:08:30
【问题描述】:
您好,我正在为我的公司开发 Twilio 应用程序,但我还是个新手。我有以下功能向我的 Twilio 应用程序发出出站连接请求。事情是我的公司希望能够在每次通话结束时记录通话持续时间,为此我需要检索子通话 SID。我从一些人那里听说这只能从后端实现。我现在只是使用标准的 Twilio 功能,其中包括他们的 Twilio 客户端快速入门。谁能告诉我必须添加什么才能返回子 SID?
//Here's the Front End function
export function twilioCall(num, device) {
return dispatch => {
device.on('connect', () => {
let status = device.status();
if(status === 'busy') {
dispatch({type:CALL_STATUS, payload: true})
}
});
device.on('disconnect', () => {
let status = device.status();
if(status === 'ready') {
dispatch({type:CALL_STATUS, payload: false})
}
});
const params = {
To: num
};
device.connect(params)
};
};
//And the Back End Function
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
if(event.To) {
// Wrap the phone number or client name in the appropriate TwiML verb
// if is a valid phone number
const attr = isAValidPhoneNumber(event.To) ? 'number' : 'client';
const dial = twiml.dial({
callerId: context.CALLER_ID,
});
dial[attr]({}, event.To);
} else {
twiml.say('Thanks for calling!');
}
callback(null, twiml);
};
/**
* Checks if the given value is valid as phone number
* @param {Number|String} number
* @return {Boolean}
*/
function isAValidPhoneNumber(number) {
return /^[\d\+\-\(\) ]+$/.test(number);
}
【问题讨论】:
标签: javascript reactjs twilio