Twilio to OnSip app error: Dial->Sip: SIP URI DNS does not resolve or resolves to an non-public IP address

Twilio to OnSip app error: Dial->Sip: SIP URI DNS does not resolve or resolves to an non-public IP address

我正在使用 Twilio 为我的公司构建 SIP 拨号解决方案,但我收到一条错误消息 "Dial->Sip: SIP URI DNS does not resolve or resolves to an non-public IP address"。我在 onsip 有一个试用帐户来测试功能,当我调用这个帐号时它失败了。相关的 TwiML 是:

 <?xml version="1.0" encoding="UTF-8"?>
 <Response>
 <Dial callerId="+15555555555">
     <Sip>sip:example@example.onsip.com</Sip>
 </Dial>
 </Response>


就谷歌搜索而言,我认为我可能需要将我的应用程序列入白名单。我也想知道,因为我在本地主机上使用我的应用程序是问题所在,但我使用了 ngrok,但仍然收到错误。

由于本期中列出的已知问题,Twilio 无法与 OnSip 交互:https://support.onsip.com/hc/en-us/articles/204599674-Twillio-and-SRV
希望这会让其他人头疼。

使用 Twilio 的新实现 functions 可以解决这个问题。

像这样的东西应该有用--

const dns = require('dns');

let sipUri = 'xxxxx@onsip.com';
let protocol = 'udp';
let region = 'us2' ;

exports.handler = function(context, event, callback) {    
  var user =   sipUri.split('@')[0];  
  var host =   sipUri.split('@')[1];  

  // generate the TwiML to tell Twilio how to forward this call
  let twiml = new Twilio.twiml.VoiceResponse();

  const dial = twiml.dial();

  dns.resolveSrv('_sip._'+protocol+'.'+host, (err, addresses) => {
    var resolvedhost = addresses[0].name+':'+addresses[0].port;
    dial.sip('sip:'+user+'@'+resolvedhost+';region='+region);
    console.log(twiml.toString());
    // return the TwiML
    callback(null, twiml);
  });
};

这会手动查询主机名以获取 SRV 记录,然后使用返回的第一个结果。不考虑重量和优先级。

Nodejs docs