我正在使用Twilio JS SDK客户端创建软件电话解决方案...
因此,我的服务器端PHP脚本接收到入站,从而使该Twiml使调用入队:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say language="pt-BR">Olá Rodrigo, em breve você será atendido.</Say>
<Enqueue action="http://xxxx/_api/external/twilio/ura_queueaction.php" waitUrl="http://xxxx/_api/external/twilio/ura_wait.php">CAcb486a96ecd4f458ac0287568d122035</Enqueue>
</Response>
....因此,在呼叫排队之后,我的webhook被呼叫,现在我有了该呼叫的queuesid:
QueueSid "QU34063a138b999bfb28c0b732e84a5a7f"
......现在,我的内部通知系统在Intranet中通知了我的内部用户,因此,使用twilio设备对象,我需要将此本地“代理”连接到该排队的呼叫...我正尝试使用:
var params = {
To: queuesid
};
if (device) {
device.connect(params);
}
在控制台上未返回任何错误,并且我收到一条消息,表明该呼叫已发起,但立即断开连接...我也尝试将第一个入站呼叫的callid作为参数发送,结果相同。
我在Internet上搜索该设备的可能“参数”列表。connect(“ PARAMS ”)....什么都没找到。
这里有好心人可以帮助我吗?
答案 0 :(得分:0)
当我对电话进行排队时,我将其命名为“ queue-” ...,例如:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say language="pt-BR">Olá Rodrigo, em breve você será atendido.</Say>
<Enqueue action="http://xxxx/_api/external/twilio/ura_queueaction.php" waitUrl="http://xxxxx/_api/external/twilio/ura_wait.php">queue-CAdc202422b5cadcda115bb44912920e3e</Enqueue>
</Response>
所以,我将twilio功能代码更改为:
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';
re = /^(.*?)-(.*?)+$/;
var myRe = new RegExp(re, "g");
var type = myRe[0];
var destin = myRe[1];
const dial = twiml.dial({
callerId: context.CALLER_ID,
});
if(type == "phone"){
dial['number']({}, destin);
}
if(type == "client"){
dial['client']({}, destin);
}
if(type == "queue"){
twiml.dial().queue(event.To)
}
//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);
}
但是即使那样,我仍然无法接通排队的电话。...有任何线索吗?
答案 1 :(得分:0)
我做到了!
问题确实在twilio函数上...在这里,解决方案:
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';
re = /^(.*?)-(.*)+$/;
var myRe = re.exec(event.To);
var type = myRe[1];
var destin = myRe[2];
if(type == "phone"){
const dial = twiml.dial({
callerId: context.CALLER_ID,
record: 'record-from-ringing-dual'
});
dial['number']({}, destin);
}
if(type == "client"){
const dial = twiml.dial({
callerId: context.CALLER_ID,
record: 'record-from-ringing-dual'
});
dial['client']({}, destin);
}
if(type == "queue"){
const dial = twiml.dial({
callerId: context.CALLER_ID,
record: 'record-from-ringing-dual'
});
dial['queue']({url: 'http://xxxx/_api/external/twilio/ura_dequeue.php?queue='+destin}, event.To);
//console.log(myRe);
}
//dial[attr]({}, event.To);
} else {
twiml.say('Thanks for calling!');
}
callback(null, twiml);
};