.NET

Ajouter un appel à l'action

Dans le contrôleur vocal, ajoutez un nouveau HTTP POST route. Vous l'utiliserez pour passer un appel sortant avec un NCCO stream action. Cette action permet de lire le fichier audio situé à l'adresse STREAM_URL dans l'appel.

Cette opération va placer un appel et passer une action unique dans cet appel, qui va lire le fichier audio situé à l'adresse STREAM_URL dans l'appel.

À des fins de test, utilisez https://raw.githubusercontent.com/nexmo-community/ncco-examples/gh-pages/assets/welcome_to_nexmo.mp3

Ajoutez le code suivant au fichier VoiceController classe :

[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");
}