team-telnyx / telnyx-java

Java SDK for the Telnyx API
10 stars 20 forks source link

OutboundMessage model defines wrong type for 'from number' #11

Closed woodleyi closed 4 years ago

woodleyi commented 4 years ago

Refer to OutboundMessage#from.

The type specified for the from field in this model class is a String. Problem: the API response returns a full JSON object for this field. This is the from response I receive from the createMessage API:

"from": {
    "phone_number": "+16149548364",
    "carrier": "Telnyx",
    "line_type": "Wireless"
}

Full API response:

{
  "data": {
    "record_type": "message",
    "direction": "outbound",
    "id": "40317551-08e0-4d71-b8f5-9f4cd210e166",
    "type": "SMS",
    "organization_id": "5d6e3d2b-27b1-4b36-889c-67d17ebf9f9a",
    "messaging_profile_id": "46e43174-0f1a-4e1a-87e7-1aadffc50ce1",
    "from": {
      "phone_number": "+16149548364",
      "carrier": "Telnyx",
      "line_type": "Wireless"
    },
    "to": [
      {
        "phone_number": "REDACTED",
        "status": "queued",
        "carrier": "NEW CINGULAR WIRELESS PCS, LLC",
        "line_type": "Wireless"
      }
    ],
    "cc": [],
    "text": "hello world",
    "media": [],
    "webhook_url": "https://hooked.updoxtest.com/telnyx/inbound",
    "webhook_failover_url": "",
    "encoding": "GSM-7",
    "parts": 1,
    "tags": [],
    "cost": null,
    "received_at": "2020-10-22T15:58:57.790+00:00",
    "sent_at": null,
    "completed_at": null,
    "valid_until": "2020-10-22T16:58:57.790+00:00",
    "errors": []
  }
}

Java code to reproduce:

final NewMessage message = new NewMessage();
message.setFrom("-YOUR FROM NUMBER-");
message.setTo("-YOUR TO NUMBER-");
message.setText("hello world");

final ApiClient apiClient = new ApiClient();
apiClient.setAccessToken("-YOUR API TOKEN-");
final MessagesApi messagesApi = new MessagesApi(apiClient);

try {
    final CreateMessageResponse response = messagesApi.createMessage(message);
    System.out.println(response.getData().getId());
} catch (final ApiException e) {
    e.printStackTrace();
}

Exception raised:

java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 9 column 14 path $.data.from
    at com.google.gson.stream.JsonReader.nextString(JsonReader.java:826)
    at com.google.gson.internal.bind.TypeAdapters$16.read(TypeAdapters.java:402)
    at com.google.gson.internal.bind.TypeAdapters$16.read(TypeAdapters.java:390)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
    at com.google.gson.Gson.fromJson(Gson.java:932)
    at com.google.gson.Gson.fromJson(Gson.java:897)
    at com.google.gson.Gson.fromJson(Gson.java:846)
    at io.swagger.client.JSON.deserialize(JSON.java:165)
    at io.swagger.client.ApiClient.deserialize(ApiClient.java:710)
    at io.swagger.client.ApiClient.handleResponse(ApiClient.java:913)
    at io.swagger.client.ApiClient.execute(ApiClient.java:840)
    at io.swagger.client.api.MessagesApi.createMessageWithHttpInfo(MessagesApi.java:266)
    at io.swagger.client.api.MessagesApi.createMessage(MessagesApi.java:252)
d-telnyx commented 4 years ago

@woodleyi & @jon-adams noted.

We're also very close to an official v2-SDK that has some breaking changes, but overall should be a better and cleaner experience (also includes a fix for this issues)

In the meantime; we'll get the v1 patched up to the correct from object.

Thanks!

d-telnyx commented 4 years ago

Resolved in v1.3 with new object OutboundMessageFrom.

However, I very recommend checking out v2.1.0 for the latest changes. It's a mostly straightforward upgrade; though does have some changes.

Checkout the sample: https://github.com/team-telnyx/demo-java-telnyx and the tests for an idea on what's new.

Also, you can @dant me in the Telnyx Slackif you have any questions! Cheers