Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Voice API to use DynamicEndpoint #490

Merged
merged 7 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions src/main/java/com/vonage/client/incoming/CallEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,15 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.vonage.client.VonageUnexpectedException;
import java.io.IOException;
import com.vonage.client.Jsonable;
import java.util.Date;

@JsonIgnoreProperties(ignoreUnknown = true)
public class CallEvent {
private String conversationUuid;
private String callUuid;
public class CallEvent implements Jsonable {
private String conversationUuid, callUuid, from, to, uuid, detail;
private CallDirection direction;
private String from;
private CallStatus status;
private Date timestamp;
private String to;
private String uuid;
private String detail;
private CallStatusDetail detailEnum;

@JsonProperty("conversation_uuid")
Expand All @@ -42,43 +35,51 @@ public String getConversationUuid() {
}

@JsonProperty("call_uuid")
public String getCallUuid() { return callUuid; }
public String getCallUuid() {
return callUuid;
}

@JsonProperty("direction")
public CallDirection getDirection() {
return direction;
}

@JsonProperty("from")
public String getFrom() {
return from;
}

@JsonProperty("status")
public CallStatus getStatus() {
return status;
}

@JsonProperty("timestamp")
public Date getTimestamp() {
return timestamp;
}

@JsonProperty("to")
public String getTo() {
return to;
}

@JsonProperty("uuid")
public String getUuid() {
return uuid;
}

public String getDetail() { return detail; }
@JsonProperty("detail")
public String getDetail() {
return detail;
}

@JsonIgnore
public CallStatusDetail getDetailEnum() { return CallStatusDetail.fromString(detail); }
public CallStatusDetail getDetailEnum() {
return CallStatusDetail.fromString(detail);
}

public static CallEvent fromJson(String json) {
try {
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(json, CallEvent.class);
} catch (IOException jpe) {
throw new VonageUnexpectedException("Failed to produce CallEvent from json.", jpe);
}
return Jsonable.fromJson(json, CallEvent.class);
}
}
4 changes: 3 additions & 1 deletion src/main/java/com/vonage/client/incoming/DtmfResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@
*/
package com.vonage.client.incoming;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

@JsonIgnoreProperties(ignoreUnknown = true)
public class DtmfResult {

private String digits;
private boolean timedOut;

/**
*
* @return The buttons pressed by the user
*/
@JsonProperty("digits")
public String getDigits() {
return digits;
}
Expand Down
31 changes: 13 additions & 18 deletions src/main/java/com/vonage/client/incoming/InputEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,20 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.vonage.client.VonageUnexpectedException;
import java.io.IOException;
import com.vonage.client.Jsonable;
import java.util.Date;


@JsonIgnoreProperties(ignoreUnknown = true)
public class InputEvent {
private String uuid;
private String conversationUuid;
public class InputEvent implements Jsonable {
private String uuid, conversationUuid, to, from;
private DtmfResult dtmf;
private Date timestamp;
private String to;
private String from;
private SpeechResults speech;

/**
* @return The unique identifier for this call
*/
@JsonProperty("uuid")
public String getUuid() {
return uuid;
}
Expand All @@ -49,47 +44,47 @@ public String getConversationUuid() {
}

/**
* @return DTMF capturing retults.
* @return DTMF capturing results.
*/
@JsonProperty("dtmf")
public DtmfResult getDtmf() {
return dtmf;
}

/**
* @return Timestamp (ISO 8601 format)
*/
@JsonProperty("timestamp")
public Date getTimestamp() {
return timestamp;
}

/**
* @return The number the call was made to
*/
public String getTo(){
@JsonProperty("to")
public String getTo() {
return to;
}

/**
* @return The number the call came from
*/
public String getFrom(){
@JsonProperty("from")
public String getFrom() {
return from;
}

/**
* @return Speech recognition results
* @since 6.0.0
*/
@JsonProperty("speech")
public SpeechResults getSpeech() {
return speech;
}

public static InputEvent fromJson(String json) {
try {
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(json, InputEvent.class);
} catch (IOException jpe) {
throw new VonageUnexpectedException("Failed to produce InputEvent from json.", jpe);
}
return Jsonable.fromJson(json, InputEvent.class);
}
}
40 changes: 24 additions & 16 deletions src/main/java/com/vonage/client/incoming/MessageEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.vonage.client.Jsonable;
import com.vonage.client.VonageUnexpectedException;
import java.io.IOException;
import java.text.DateFormat;
Expand All @@ -26,43 +27,39 @@
import java.util.TimeZone;

@JsonIgnoreProperties(ignoreUnknown = true)
public class MessageEvent {
private String msisdn;
private String to;
private String messageId;
private String text;
public class MessageEvent implements Jsonable {
private String msisdn, to, messageId, text, keyword, timestamp, nonce, data, udh;
private MessageType type;
private String keyword;
private Date messageTimestamp;
private String timestamp;
private String nonce;
private Boolean concat;
private int concatRef;
private int concatTotal;
private int concatPart;
private String data;
private String udh;
private int concatRef, concatTotal, concatPart;

@JsonProperty("msisdn")
public String getMsisdn() {
return msisdn;
}

@JsonProperty("to")
public String getTo() {
return to;
}

@JsonProperty("messageId")
public String getMessageId() {
return messageId;
}

@JsonProperty("text")
public String getText() {
return text;
}

@JsonProperty("type")
public MessageType getType() {
return type;
}

@JsonProperty("keyword")
public String getKeyword() {
return keyword;
}
Expand All @@ -72,14 +69,17 @@ public Date getMessageTimestamp() {
return messageTimestamp;
}

@JsonProperty("timestamp")
public String getTimestamp() {
return timestamp;
}

@JsonProperty("nonce")
public String getNonce() {
return nonce;
}

@JsonProperty("concat")
public Boolean getConcat() {
return concat;
}
Expand All @@ -99,24 +99,32 @@ public int getConcatPart() {
return concatPart;
}

@JsonProperty("data")
public String getData() {
return data;
}

@JsonProperty("udh")
public String getUdh() {
return udh;
}

public static MessageEvent fromJson(String json) {
@Override
public void updateFromJson(String json) {
try {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

ObjectMapper mapper = new ObjectMapper();
mapper.setDateFormat(dateFormat);
return mapper.readValue(json, MessageEvent.class);
} catch (IOException jpe) {
mapper.readerForUpdating(this).readValue(json, MessageEvent.class);
}
catch (IOException jpe) {
throw new VonageUnexpectedException("Failed to produce MessageEvent from json.", jpe);
}
}

public static MessageEvent fromJson(String json) {
return Jsonable.fromJson(json, MessageEvent.class);
}
}
13 changes: 3 additions & 10 deletions src/main/java/com/vonage/client/incoming/NotifyEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.vonage.client.VonageUnexpectedException;
import java.io.IOException;
import com.vonage.client.Jsonable;
import java.util.Date;
import java.util.Map;

@JsonIgnoreProperties(ignoreUnknown = true)
public class NotifyEvent {
public class NotifyEvent implements Jsonable {
@JsonProperty(value = "conversation_uuid")
private String conversationUuid;
private Date timestamp;
Expand Down Expand Up @@ -64,11 +62,6 @@ public String toString() {
}

public static NotifyEvent fromJson(String json) {
try {
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(json, NotifyEvent.class);
} catch (IOException e) {
throw new VonageUnexpectedException("Failed to convert NotifyEvent from json.", e);
}
return Jsonable.fromJson(json, NotifyEvent.class);
}
}
23 changes: 7 additions & 16 deletions src/main/java/com/vonage/client/incoming/RecordEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,14 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.vonage.client.VonageUnexpectedException;
import java.io.IOException;
import com.vonage.client.Jsonable;
import java.util.Date;

@JsonIgnoreProperties(ignoreUnknown = true)
public class RecordEvent {
private Date startTime;
private String url;
public class RecordEvent implements Jsonable {
private Date startTime, endTime, timestamp;
private String url, uuid, conversationUuid;
private int size;
private String uuid;
private Date endTime;
private String conversationUuid;
private Date timestamp;

@JsonProperty("start_time")
public Date getStartTime() {
Expand All @@ -42,6 +36,7 @@ public String getUrl() {
return url;
}

@JsonProperty("size")
public int getSize() {
return size;
}
Expand All @@ -61,16 +56,12 @@ public String getConversationUuid() {
return conversationUuid;
}

@JsonProperty("timestamp")
public Date getTimestamp() {
return timestamp;
}

public static RecordEvent fromJson(String json) {
try {
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(json, RecordEvent.class);
} catch (IOException jpe) {
throw new VonageUnexpectedException("Failed to produce RecordEvent from json.", jpe);
}
return Jsonable.fromJson(json, RecordEvent.class);
}
}
Loading
Loading