要通过Twilio从笔记本电话拨打电话号码我创建了ASP.NET-MVC 5.2应用程序。
我可以拨打电话拨打电话,但我不知道如何实现现场语音(能够通话)连接,而不仅仅是播放音乐。
我在HomeController
内创建了一个操作方法:
public ActionResult Call(string to) {
client = new TwilioRestClient(Settings.AccountSid, Settings.AuthToken);
var result = client.InitiateOutboundCall(Settings.TwilioNumber, to, "http://twimlets.com/message?Message%5B0%5D=http://demo.kevinwhinnery.com/audio/zelda.mp3"); //it causes to play zelda theme when call is answered by callee
if (result.RestException != null) {
return new System.Web.Mvc.HttpStatusCodeResult(500, result.RestException.Message);
}
return Content("Call enroute!");
}
public ActionResult Index() {
return View();
}
此操作方法由Ajax调用调用。
当我点击Views\Home\Index.csthml
的按钮时:
<form>
<p>Enter your mobile phone number:</p>
<input id="to" type="text"
placeholder="ex: +16518675309" />
<button>Send me a message</button>
</form>
调用以下脚本,将<input id="to">
中的电话号码传递给public ActionResult Call(string to)
中的操作方法HomeController
:
$('form button').on('click', function(e) {
e.preventDefault();
// expect just a string of text back from the server
var url = '/call';
$.ajax(url, { //invokes call action method
method:'POST',
dataType:'text',
data:{
to:$('#to').val()//passes the number argument to the action method
},
success: function(data) {
showFlash(data);
},
error: function(jqxhr) {
alert('There was an error sending a request to the server');
}
})
});
这会启动指定号码的电话,即48123456789
,其中48
是国家/地区代码。当被叫方回答呼叫时,将播放塞尔达主题。(http://twimlets.com/message?Message%5B0%5D=http://demo.kevinwhinnery.com/audio/zelda.mp3)
而不是我想通过笔记本(它有内置麦克风)与我打电话的人交谈,让这个人说话。简而言之,我希望有现场的声音。
问题:如何在ASP.NET-MVC 5.x中使用Twilio实现实时语音电话呼叫?
Settings.AccountSid
和Settings.AuthToken
是我的凭据:
public static class Settings
{
public static string AccountSid { get { return "A###############0"; } }
public static string AuthToken { get { return "e###############0"; } }
public static string TwilioNumber { get { return "4########1"; } }
}
答案 0 :(得分:1)
Twilio传道者在这里。
如果您想通过浏览器拨打电话,则需要查看使用Twilio Client for JavaScript:
https://www.twilio.com/docs/quickstart/csharp/client
这将允许您从浏览器拨打VoIP电话到Twilio。一旦呼叫到达Twilio,您就可以将该呼叫与另一个Twilio客户端,SIP端点或PSTN电话进行桥接:
https://www.twilio.com/docs/quickstart/csharp/client/outgoing-calls
希望有所帮助。
答案 1 :(得分:0)
这样做的方法是使用Dial Twiml https://www.twilio.com/docs/api/twiml/dial Dial可以选择其中一种选项;电话号码,SIP URL或Twilio客户端标识符。拨号的一个例子是https://www.twilio.com/labs/twimlets/callme提供的CallMe twimlet,它看起来像下面的
<Response>
<Dial>
<Number>+44.........</Number>
</Dial>
</Response>
如果您已经在笔记本电脑上安装了软电话,那么您可以拨打它。如果你有Skype,你可以使用你的Skype电话号码。
如果您没有安装软电话,您可以随时使用Twilio客户端https://www.twilio.com/client并在网络浏览器中运行。