.NET

Añadir acción de llamada

En el controlador Voice añada un nuevo HTTP POST ruta. Se utilizará para realizar una llamada saliente con una OCNC stream acción. Esta acción reproducirá el archivo de audio situado en la carpeta STREAM_URL en la llamada.

Esto realizará una llamada, y pasará una única acción a esa llamada que reproducirá el archivo de audio ubicado en el campo STREAM_URL en la llamada.

Para las pruebas, utilice https://raw.githubusercontent.com/nexmo-community/ncco-examples/gh-pages/assets/welcome_to_nexmo.mp3

Añada el siguiente código al archivo VoiceController clase:

[HttpPost]
public IActionResult MakePhoneCall(string toNumber, string fromNumber)
{
    const string STREAM_URL = "https://raw.githubusercontent.com/nexmo-community/ncco-examples/gh-pages/assets/welcome_to_nexmo.mp3";
    var appId = _config["APPLICATION_ID"];
    var privateKeyPath = _config["PRIVATE_KEY_PATH"];

    var streamAction = new StreamAction{ StreamUrl = new string[] { STREAM_URL }};
    var ncco = new Ncco(streamAction);

    var toEndpoint = new PhoneEndpoint{Number=toNumber};
    var fromEndpoint = new PhoneEndpoint{Number=fromNumber};

    var credentials = Credentials.FromAppIdAndPrivateKeyPath(appId, privateKeyPath);
    var client = new VoiceClient(credentials);
    var callRequest = new CallCommand { To = new []{toEndpoint}, From = fromEndpoint, Ncco= ncco};
    var call = client.CreateCall(callRequest);
    ViewBag.Uuid = call.Uuid;
    return View("Index");
}