Vonage / vonage-dotnet-code-snippets

.NET code samples for using Nexmo
MIT License
11 stars 21 forks source link

Transfer a call sample code #39

Closed icebeam7 closed 5 years ago

icebeam7 commented 5 years ago

According to the Voice API Reference, there are 6 possible actions that can be used to modify an in-progress call: hangup, mute, unmute, earmuff, unearmuff, and transfer.

The VoiceController shows how to perform all but the last action, so I would like to contribute to the repository by implementing the transfer call sample code.

icebeam7 commented 5 years ago

Ok, so I've implemented the following code but I receive a value cannot be null exception:

var result = Client.Call.Edit(NEXMO_CALL_UUID, new Call.CallEditCommand
{
     action = "transfer",
     destination = "{\"type\": \"ncco\", \"url\": [\"https://developer.nexmo.com/ncco/transfer.json\"]}"
});

The problem seems to be the serialization process done by the API regarding the destination property (because of the quotes). This element is declared as string, but I think it should be an instance of some class (which in turn would be correctly serialized and used by the API without any problem).

Could somebody please confirm this or point me in the right direction?

I have also tried other code for the destinationproperty, but the result remains the same:

destination = JsonConvert.SerializeObject(new { type = "ncco", url = new[] { "https://developer.nexmo.com/ncco/transfer.json" } })

RabebOthmani commented 5 years ago

Hi @icebeam7 , Indeed there was an issue with the Edit call command and this now is fixed in V3.2.4 . So the code for transfer would look like this now :

var result = Client.Call.Edit(NEXMO_CALL_UUID, new Call.CallEditCommand
            {
                Action = "transfer",
                Destination = new Call.Destination
                {
                    Type = "ncco",
                    Url = new[] { "LINK_TO_NEW_NCCO" }
                }

Please feel free to PR this and I'm looking forward for more contributions from you :)

RabebOthmani commented 5 years ago

https://github.com/nexmo-community/nexmo-dotnet-quickstart/commit/73ce946ee9097abbb7de5dca7b9d146bf9e87440