websocket 我怎么能在接到Twilio电话时给浏览器打电话

6psbrbz9  于 2023-10-20  发布在  其他
关注(0)|答案(1)|浏览(113)

我如何在浏览器上振铃以接收Twilio号码上的呼叫?使用.Net core和ReactJS。

public TwiMLResult Connect()
    {
        var FromNumber = Request.Form["From"];
        var ToNumber = Request.Form["To"];
        var FireBaseToken = Request.Form["FirebaseToken"];
        var Record = Request.Form["Record"];
        var Digits = Request.Form["Digits"];
        var callingDeviceIdentity = Request.Form["callingDeviceIdentity"];

        Dial.RecordEnum recordEnum = Dial.RecordEnum.RecordFromAnswer;

        if (!string.IsNullOrEmpty(Record))
        {
            recordEnum = "do-not-record" == Record.ToString().Trim() ? Dial.RecordEnum.DoNotRecord : Dial.RecordEnum.RecordFromAnswer;
        }

        var response = new VoiceResponse();
        string phoneNumber = ToNumber;

        var dial = new Dial(callerId: FromNumber, record: recordEnum,
            recordingStatusCallback: new Uri(_config["BaseUrlApi"] + "api/Call/OuboundCallRecording"),
            recordingStatusCallbackMethod: Twilio.Http.HttpMethod.Post);

        if (string.IsNullOrEmpty(callingDeviceIdentity))
        {
           // Here I'm receiving a hook from Twilio
        }

}
在if部分,我可以回答“twiml.Say”(“Ahoy,World!“)”但我想在此接收来自浏览器的呼叫并建立连接。
试过这个

// or handle an incoming call

device.on('incoming',call => {});
但无法触发这个密码

euoag5mw

euoag5mw1#

Twilio Voice JavaScript SDK将允许您从浏览器接收和拨打呼出电话。
Twilio提供了一个C# Quickstart和一个NodeJS Quickstart github项目,并提供了非常好的文档来安装和使用。
Twilio Voice JavaScript客户端将处理您的浏览器和Twilio之间的websockets通信。
以下是Twilio.Call文档中的一些示例代码,以供参考:

const device = new Device(token);

// Make an outgoing call
async function makeOutgoingCall() {
  const call = await device.connect();
}

// or handle an incoming call
device.on('incoming', call => {});

相关问题