Vonage / vonage-go-sdk

A lightweight library to help Go users everywhere integrate with the Vonage APIs. Issues and PRs all really welcome!!
https://vonage.github.io/vonage-go-sdk/
Apache License 2.0
51 stars 32 forks source link

Example of voice call #8

Closed mauricioklein closed 5 years ago

mauricioklein commented 5 years ago

Hello!

Thanks for your work on this library 😄

I'm having problems setting up a voice call using the library. The problem is in the To attribute, which I don't understand why is a []interface{}.

Here's what I've currently:

    callReq := nexmo.CreateCallRequest{
        To: []interface{}{
            nexmo.PhoneCallEndpoint{
                Type:   "phone",
                Number: myPhoneNumber,
            },
        },
        From:      "1234567890",
        AnswerURL: []string{"https://nexmo-community.github.io/ncco-examples/first_call_talk.json"},
    }

Already tried the phone number directly:

    callReq := nexmo.CreateCallRequest{
        To: []interface{}{phoneNumber},
        From:      "1234567890",
        AnswerURL: []string{"https://nexmo-community.github.io/ncco-examples/first_call_talk.json"},
    }

But always get an error related to marshaling the To attribute:

2018/11/20 18:46:35 Could not decode: {"type":400,"title":"Bad Request","invalid_parameters":[{"reason":"Missing type id when trying to resolve subtype of [simple type, class com.nexmo.vapi.ncco.core.action.endpoint.Endpoint]: missing type id property 'type' (for POJO property 'from')","name":"from"}]}

Could you post an example of a voice call, please?

Thanks in advance for your support!

judy2k commented 5 years ago

Hello! I'll start by saying there's definitely some work to be done on this library - a lot of these structs were autogenerated by a script to get things up and running.

I think in this case (and your error message seems to agree) that the problem isn't being caused by your To value, it's being caused by your From value.

To should be an array of PhoneCallEndpoints in this case, and From should be a single PhoneCallEndpoint. Something more like:


callReq := nexmo.CreateCallRequest{
        To: []interface{}{
            nexmo.PhoneCallEndpoint{
                Type:   "phone",
                Number: myPhoneNumber,
            },
        },
        From:      nexmo.PhoneCallEndpoint{
                Type:   "phone",
                                  Number: "1234567890",
                 },
        AnswerURL: []string{"https://nexmo-community.github.io/ncco-examples/first_call_talk.json"},
    }