diff --git a/client/src/main/com/sinch/sdk/domains/common/adapters/converters/OffsetDateTimeDtoConverter.java b/client/src/main/com/sinch/sdk/domains/common/adapters/converters/OffsetDateTimeDtoConverter.java
new file mode 100644
index 000000000..e9151b54b
--- /dev/null
+++ b/client/src/main/com/sinch/sdk/domains/common/adapters/converters/OffsetDateTimeDtoConverter.java
@@ -0,0 +1,11 @@
+package com.sinch.sdk.domains.common.adapters.converters;
+
+import java.time.Instant;
+import java.time.OffsetDateTime;
+
+public class OffsetDateTimeDtoConverter {
+
+ public static Instant convert(OffsetDateTime dto) {
+ return null != dto ? dto.toInstant() : null;
+ }
+}
diff --git a/client/src/main/com/sinch/sdk/domains/verification/WebHooksService.java b/client/src/main/com/sinch/sdk/domains/verification/WebHooksService.java
index a9d98db13..70e29d483 100644
--- a/client/src/main/com/sinch/sdk/domains/verification/WebHooksService.java
+++ b/client/src/main/com/sinch/sdk/domains/verification/WebHooksService.java
@@ -51,7 +51,7 @@ boolean validateAuthenticatedRequest(
VerificationEvent unserializeVerificationEvent(String jsonPayload) throws ApiMappingException;
/**
- * This function can be called to serialize a verification response to be send as JSON
+ * This function can be called to serialize a verification response to be sent as JSON
*
* @param response The response to be serialized
* @return The JSON string to be sent
diff --git a/client/src/main/com/sinch/sdk/domains/voice/CallsService.java b/client/src/main/com/sinch/sdk/domains/voice/CallsService.java
index 8c3260076..d8357c3fe 100644
--- a/client/src/main/com/sinch/sdk/domains/voice/CallsService.java
+++ b/client/src/main/com/sinch/sdk/domains/voice/CallsService.java
@@ -1,8 +1,8 @@
package com.sinch.sdk.domains.voice;
import com.sinch.sdk.domains.voice.models.CallLegType;
-import com.sinch.sdk.domains.voice.models.requests.CallsUpdateRequestParameters;
import com.sinch.sdk.domains.voice.models.response.CallInformation;
+import com.sinch.sdk.domains.voice.models.svaml.SVAMLControl;
/**
* Using the Calls service, you can manage on-going calls or retrieve information about a call.
@@ -37,7 +37,7 @@ public interface CallsService {
* @param callId The unique identifier of the call. This value is generated by the system
* @param parameters Tasks to be used related to this call
*/
- void update(String callId, CallsUpdateRequestParameters parameters);
+ void update(String callId, SVAMLControl parameters);
/**
* This method is used to manage ongoing, connected calls. This method is only used when using the
@@ -51,6 +51,5 @@ public interface CallsService {
* @param callId The unique identifier of the call. This value is generated by the system
* @param parameters Tasks to be used related to this call
*/
- void manageWithCallLeg(
- String callId, CallLegType callLeg, CallsUpdateRequestParameters parameters);
+ void manageWithCallLeg(String callId, CallLegType callLeg, SVAMLControl parameters);
}
diff --git a/client/src/main/com/sinch/sdk/domains/voice/VoiceService.java b/client/src/main/com/sinch/sdk/domains/voice/VoiceService.java
index 47684f9eb..fd69b3109 100644
--- a/client/src/main/com/sinch/sdk/domains/voice/VoiceService.java
+++ b/client/src/main/com/sinch/sdk/domains/voice/VoiceService.java
@@ -40,4 +40,12 @@ public interface VoiceService {
* @since 1.0
*/
ApplicationsService applications();
+
+ /**
+ * Webhooks helpers instance
+ *
+ * @return instance service related to webhooks helpers
+ * @since 1.0
+ */
+ WebHooksService webhooks();
}
diff --git a/client/src/main/com/sinch/sdk/domains/voice/WebHooksService.java b/client/src/main/com/sinch/sdk/domains/voice/WebHooksService.java
new file mode 100644
index 000000000..8ca79fa06
--- /dev/null
+++ b/client/src/main/com/sinch/sdk/domains/voice/WebHooksService.java
@@ -0,0 +1,59 @@
+package com.sinch.sdk.domains.voice;
+
+import com.sinch.sdk.core.exceptions.ApiMappingException;
+import com.sinch.sdk.domains.voice.models.svaml.SVAMLControl;
+import com.sinch.sdk.domains.voice.models.webhooks.WebhooksEvent;
+import java.util.Map;
+
+/**
+ * Webhooks service
+ *
+ * @see https://developers.sinch.com/docs/voice/api-reference/voice/tag/Callbacks/
+ * @since 1.0
+ */
+public interface WebHooksService {
+
+ /**
+ * The Sinch Platform can initiate callback requests to a URL you define (Callback URL) on request
+ * and result events. All callback requests are signed using your Application key and secret pair
+ * found on your dashboard. The signature is included in the Authorization header of the request
+ *
+ *
By using following function, you can ensure authentication according to received payload
+ * from your backend
+ *
+ * @param method The HTTP method used ot handle the callback
+ * @param path The path to you backend endpoint used for callback
+ * @param headers Received headers
+ * @param jsonPayload Received payload
+ * @return Is authentication is validated (true) or not (false)
+ *
see https://developers.sinch.com/docs/voice/api-reference/authentication/callback-signed-request/
+ * @since 1.0
+ */
+ boolean validateAuthenticatedRequest(
+ String method, String path, Map headers, String jsonPayload);
+
+ /**
+ * This function can be called to deserialize received payload onto callback onto proper java
+ * Voice event class
+ *
+ * @param jsonPayload Received payload to be deserialized
+ * @return The Voice event instance class
+ * see https://developers.sinch.com/docs/voice/api-reference/voice/tag/Callbacks/
+ * @since 1.0
+ */
+ WebhooksEvent unserializeWebhooksEvent(String jsonPayload) throws ApiMappingException;
+
+ /**
+ * This function can be called to serialize a Voice response to be sent as JSON
+ *
+ * @param response The response to be serialized
+ * @return The JSON string to be sent
+ *
see https://developers.sinch.com/docs/voice/api-reference/voice/tag/Callbacks/
+ * @since 1.0
+ */
+ String serializeWebhooksResponse(SVAMLControl response) throws ApiMappingException;
+}
diff --git a/client/src/main/com/sinch/sdk/domains/voice/adapters/CallsService.java b/client/src/main/com/sinch/sdk/domains/voice/adapters/CallsService.java
index 4cc4eb2b4..7c5a94f0b 100644
--- a/client/src/main/com/sinch/sdk/domains/voice/adapters/CallsService.java
+++ b/client/src/main/com/sinch/sdk/domains/voice/adapters/CallsService.java
@@ -6,8 +6,8 @@
import com.sinch.sdk.domains.voice.adapters.api.v1.CallsApi;
import com.sinch.sdk.domains.voice.adapters.converters.CallsDtoConverter;
import com.sinch.sdk.domains.voice.models.CallLegType;
-import com.sinch.sdk.domains.voice.models.requests.CallsUpdateRequestParameters;
import com.sinch.sdk.domains.voice.models.response.CallInformation;
+import com.sinch.sdk.domains.voice.models.svaml.SVAMLControl;
import com.sinch.sdk.models.Configuration;
import java.util.Map;
@@ -30,12 +30,11 @@ public CallInformation get(String callId) {
return CallsDtoConverter.convert(getApi().callingGetCallResult(callId));
}
- public void update(String callId, CallsUpdateRequestParameters parameters) {
+ public void update(String callId, SVAMLControl parameters) {
getApi().callingUpdateCall(callId, CallsDtoConverter.convert(parameters));
}
- public void manageWithCallLeg(
- String callId, CallLegType callLeg, CallsUpdateRequestParameters parameters) {
+ public void manageWithCallLeg(String callId, CallLegType callLeg, SVAMLControl parameters) {
getApi()
.callingManageCallWithCallLeg(
callId, callLeg.value(), CallsDtoConverter.convert(parameters));
diff --git a/client/src/main/com/sinch/sdk/domains/voice/adapters/VoiceService.java b/client/src/main/com/sinch/sdk/domains/voice/adapters/VoiceService.java
index 44dc334a6..51e98d717 100644
--- a/client/src/main/com/sinch/sdk/domains/voice/adapters/VoiceService.java
+++ b/client/src/main/com/sinch/sdk/domains/voice/adapters/VoiceService.java
@@ -7,6 +7,7 @@
import com.sinch.sdk.core.http.HttpClient;
import com.sinch.sdk.domains.voice.ApplicationsService;
import com.sinch.sdk.domains.voice.CalloutsService;
+import com.sinch.sdk.domains.voice.WebHooksService;
import com.sinch.sdk.models.Configuration;
import java.util.Map;
import java.util.Objects;
@@ -26,6 +27,7 @@ public class VoiceService implements com.sinch.sdk.domains.voice.VoiceService {
private ConferencesService conferences;
private CallsService calls;
private ApplicationsService applications;
+ private WebHooksService webhooks;
private Map clientAuthManagers;
private Map webhooksAuthManagers;
@@ -99,6 +101,15 @@ public ApplicationsService applications() {
return this.applications;
}
+ public WebHooksService webhooks() {
+ checkCredentials();
+ if (null == this.webhooks) {
+ this.webhooks =
+ new com.sinch.sdk.domains.voice.adapters.WebHooksService(webhooksAuthManagers);
+ }
+ return this.webhooks;
+ }
+
private void checkCredentials() throws ApiAuthException {
if (null == clientAuthManagers || clientAuthManagers.isEmpty()) {
throw new ApiAuthException(
diff --git a/client/src/main/com/sinch/sdk/domains/voice/adapters/WebHooksService.java b/client/src/main/com/sinch/sdk/domains/voice/adapters/WebHooksService.java
new file mode 100644
index 000000000..ac89e8322
--- /dev/null
+++ b/client/src/main/com/sinch/sdk/domains/voice/adapters/WebHooksService.java
@@ -0,0 +1,72 @@
+package com.sinch.sdk.domains.voice.adapters;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.sinch.sdk.core.exceptions.ApiMappingException;
+import com.sinch.sdk.core.http.AuthManager;
+import com.sinch.sdk.core.utils.databind.Mapper;
+import com.sinch.sdk.domains.voice.adapters.converters.CallsDtoConverter;
+import com.sinch.sdk.domains.voice.adapters.converters.WebhooksEventDtoConverter;
+import com.sinch.sdk.domains.voice.models.dto.v1.SVAMLRequestBodyDto;
+import com.sinch.sdk.domains.voice.models.dto.v1.WebhooksEventDto;
+import com.sinch.sdk.domains.voice.models.svaml.SVAMLControl;
+import com.sinch.sdk.domains.voice.models.webhooks.WebhooksEvent;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.logging.Logger;
+
+public class WebHooksService implements com.sinch.sdk.domains.voice.WebHooksService {
+ private static final Logger LOGGER = Logger.getLogger(WebHooksService.class.getName());
+
+ private final Map authManagers;
+
+ public WebHooksService(Map authManagers) {
+ this.authManagers = authManagers;
+ }
+
+ public boolean validateAuthenticatedRequest(
+ String method, String path, Map headers, String jsonPayload) {
+
+ // convert header keys to use case-insensitive map keys
+ Map caseInsensitiveHeaders = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ caseInsensitiveHeaders.putAll(headers);
+
+ String authorizationHeader = caseInsensitiveHeaders.get("Authorization");
+
+ // no authorization required
+ if (null == authorizationHeader) {
+ return true;
+ }
+
+ String[] split = authorizationHeader.split(" ");
+ String authorizationKeyword = split.length > 0 ? split[0] : "";
+
+ AuthManager authManager = authManagers.get(authorizationKeyword);
+ if (null == authManager) {
+ // unknown auth manager
+ LOGGER.severe(
+ String.format("Auth manager for authorization '%s' not found", authorizationKeyword));
+ return false;
+ }
+ return authManager.validateAuthenticatedRequest(method, path, headers, jsonPayload);
+ }
+
+ @Override
+ public WebhooksEvent unserializeWebhooksEvent(String jsonPayload) throws ApiMappingException {
+ try {
+ WebhooksEventDto o = Mapper.getInstance().readValue(jsonPayload, WebhooksEventDto.class);
+ return WebhooksEventDtoConverter.convert(o);
+ } catch (JsonProcessingException e) {
+ throw new ApiMappingException(jsonPayload, e);
+ }
+ }
+
+ @Override
+ public String serializeWebhooksResponse(SVAMLControl response) throws ApiMappingException {
+ SVAMLRequestBodyDto dto = CallsDtoConverter.convert(response);
+ try {
+ return Mapper.getInstance().writeValueAsString(dto);
+ } catch (JsonProcessingException e) {
+ throw new ApiMappingException(response.toString(), e);
+ }
+ }
+}
diff --git a/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/CalloutsDtoConverter.java b/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/CalloutsDtoConverter.java
index fcf9a91d3..d5d8582c8 100644
--- a/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/CalloutsDtoConverter.java
+++ b/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/CalloutsDtoConverter.java
@@ -7,6 +7,7 @@
import com.sinch.sdk.domains.voice.models.dto.v1.ConferenceCalloutRequestConferenceDtmfOptionsDto;
import com.sinch.sdk.domains.voice.models.dto.v1.ConferenceCalloutRequestDto;
import com.sinch.sdk.domains.voice.models.dto.v1.CustomCalloutRequestDto;
+import com.sinch.sdk.domains.voice.models.dto.v1.DomainDto;
import com.sinch.sdk.domains.voice.models.dto.v1.GetCalloutResponseObjDto;
import com.sinch.sdk.domains.voice.models.dto.v1.TtsCalloutRequestDto;
import com.sinch.sdk.domains.voice.models.requests.CalloutRequestParameters;
@@ -56,7 +57,7 @@ private static CalloutRequestDto convert(CalloutRequestParametersConference clie
client.getEnablePie().ifPresent(dto::setEnablePie);
client.getLocale().ifPresent(dto::setLocale);
client.getGreeting().ifPresent(dto::setGreeting);
- client.getMohClass().ifPresent(f -> dto.setMohClass(EnumDynamicConverter.convert(f)));
+ client.getMusicOnHold().ifPresent(f -> dto.setMohClass(EnumDynamicConverter.convert(f)));
client.getDomain().ifPresent(f -> dto.setDomain(EnumDynamicConverter.convert(f)));
return new CalloutRequestDto()
@@ -76,7 +77,9 @@ private static CalloutRequestDto convert(CalloutRequestParametersTTS client) {
client.getEnableDice().ifPresent(dto::setEnableDice);
client.getEnablePie().ifPresent(dto::setEnablePie);
client.getLocale().ifPresent(dto::setLocale);
- client.getDomain().ifPresent(f -> dto.setDomain(EnumDynamicConverter.convert(f)));
+ client
+ .getDomain()
+ .ifPresent(f -> dto.setDomain(DomainDto.fromValue(EnumDynamicConverter.convert(f))));
client.getText().ifPresent(dto::setText);
client.getPrompts().ifPresent(dto::setPrompts);
@@ -93,9 +96,9 @@ private static CalloutRequestDto convert(CalloutRequestParametersCustom client)
client.getCustom().ifPresent(dto::setCustom);
client.getMaxDuration().ifPresent(dto::setMaxDuration);
- client.getIce().ifPresent(dto::setIce);
- client.getAce().ifPresent(dto::setAce);
- client.getPie().ifPresent(dto::setPie);
+ client.getIce().ifPresent(f -> dto.setIce(ControlDtoConverter.convert(f)));
+ client.getAce().ifPresent(f -> dto.setAce(ControlDtoConverter.convert(f)));
+ client.getPie().ifPresent(f -> dto.setPie(ControlDtoConverter.convert(f)));
return new CalloutRequestDto().method(MethodEnum.CUSTOMCALLOUT.getValue()).customCallout(dto);
}
diff --git a/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/CallsDtoConverter.java b/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/CallsDtoConverter.java
index 26ad71b6c..bd7643431 100644
--- a/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/CallsDtoConverter.java
+++ b/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/CallsDtoConverter.java
@@ -1,13 +1,13 @@
package com.sinch.sdk.domains.voice.adapters.converters;
+import com.sinch.sdk.domains.voice.models.CallReasonType;
+import com.sinch.sdk.domains.voice.models.CallResultType;
import com.sinch.sdk.domains.voice.models.DomainType;
import com.sinch.sdk.domains.voice.models.dto.v1.GetCallResponseObjDto;
import com.sinch.sdk.domains.voice.models.dto.v1.SVAMLRequestBodyDto;
-import com.sinch.sdk.domains.voice.models.requests.CallsUpdateRequestParameters;
import com.sinch.sdk.domains.voice.models.response.CallInformation;
-import com.sinch.sdk.domains.voice.models.response.CallReasonType;
-import com.sinch.sdk.domains.voice.models.response.CallResultType;
import com.sinch.sdk.domains.voice.models.response.CallStatusType;
+import com.sinch.sdk.domains.voice.models.svaml.SVAMLControl;
public class CallsDtoConverter {
@@ -22,7 +22,7 @@ public static CallInformation convert(GetCallResponseObjDto dto) {
.setCallId(dto.getCallId())
.setDuration(dto.getDuration())
.setStatus(null != dto.getStatus() ? CallStatusType.from(dto.getStatus()) : null)
- .setResult(null != dto.getResult() ? CallResultType.from(dto.getResult()) : null)
+ .setResult(null != dto.getResult() ? CallResultType.from(dto.getResult().getValue()) : null)
.setReason(null != dto.getReason() ? CallReasonType.from(dto.getReason()) : null)
.setTimeStamp(null != dto.getTimestamp() ? dto.getTimestamp().toInstant() : null)
.setCustom(null != dto.getCustom() ? dto.getCustom() : null)
@@ -31,15 +31,16 @@ public static CallInformation convert(GetCallResponseObjDto dto) {
.build();
}
- public static SVAMLRequestBodyDto convert(CallsUpdateRequestParameters client) {
+ public static SVAMLRequestBodyDto convert(SVAMLControl client) {
if (null == client) {
return null;
}
SVAMLRequestBodyDto dto = new SVAMLRequestBodyDto();
- dto.instructions(SAVMLInstructionDtoConverter.convert(client.getInstructions()));
- dto.action(SAVMLActionDtoConverter.convert(client.getAction()));
-
+ client
+ .getInstructions()
+ .ifPresent(f -> dto.instructions(SVAMLInstructionDtoConverter.convert(f)));
+ client.getAction().ifPresent(f -> dto.action(SVAMLActionDtoConverter.convert(f)));
return dto;
}
}
diff --git a/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/ConferencesDtoConverter.java b/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/ConferencesDtoConverter.java
index 8eaeb1765..65680ba52 100644
--- a/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/ConferencesDtoConverter.java
+++ b/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/ConferencesDtoConverter.java
@@ -37,7 +37,7 @@ public static ManageConferenceParticipantRequestDto convert(
ManageConferenceParticipantRequestDto dto = new ManageConferenceParticipantRequestDto();
client.getCommand().ifPresent(f -> dto.command(EnumDynamicConverter.convert(f)));
- client.getMoh().ifPresent(f -> dto.moh(EnumDynamicConverter.convert(f)));
+ client.getMusicOnHold().ifPresent(f -> dto.moh(EnumDynamicConverter.convert(f)));
return dto;
}
}
diff --git a/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/ControlDtoConverter.java b/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/ControlDtoConverter.java
new file mode 100644
index 000000000..6fe7dd93b
--- /dev/null
+++ b/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/ControlDtoConverter.java
@@ -0,0 +1,40 @@
+package com.sinch.sdk.domains.voice.adapters.converters;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.sinch.sdk.core.exceptions.ApiMappingException;
+import com.sinch.sdk.core.utils.databind.Mapper;
+import com.sinch.sdk.domains.voice.models.requests.Control;
+import com.sinch.sdk.domains.voice.models.requests.ControlUrl;
+import com.sinch.sdk.domains.voice.models.svaml.SVAMLControl;
+import java.util.logging.Logger;
+
+public class ControlDtoConverter {
+
+ private static final Logger LOGGER = Logger.getLogger(SVAMLActionDtoConverter.class.getName());
+
+ public static String convert(Control client) {
+ if (null == client) {
+ return null;
+ }
+ String dto;
+ if (client instanceof SVAMLControl) {
+ SVAMLControl value = (SVAMLControl) client;
+ dto = convertControlToEscapedJSON(value);
+ } else if (client instanceof ControlUrl) {
+ ControlUrl value = (ControlUrl) client;
+ dto = value.getURL();
+ } else {
+ LOGGER.severe(String.format("Unexpected class '%s'", client.getClass()));
+ dto = client.toString();
+ }
+ return dto;
+ }
+
+ private static String convertControlToEscapedJSON(SVAMLControl client) {
+ try {
+ return Mapper.getInstance().writeValueAsString(CallsDtoConverter.convert(client));
+ } catch (JsonProcessingException e) {
+ throw new ApiMappingException(client.toString(), e);
+ }
+ }
+}
diff --git a/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/DestinationDtoConverter.java b/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/DestinationDtoConverter.java
index 4f4ea9d88..e339412aa 100644
--- a/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/DestinationDtoConverter.java
+++ b/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/DestinationDtoConverter.java
@@ -2,6 +2,7 @@
import com.sinch.sdk.domains.voice.models.Destination;
import com.sinch.sdk.domains.voice.models.DestinationNumber;
+import com.sinch.sdk.domains.voice.models.DestinationNumberType;
import com.sinch.sdk.domains.voice.models.DestinationSip;
import com.sinch.sdk.domains.voice.models.DestinationUser;
import com.sinch.sdk.domains.voice.models.dto.v1.DestinationDto;
@@ -11,6 +12,7 @@
import java.util.logging.Logger;
public class DestinationDtoConverter {
+
private static final Logger LOGGER = Logger.getLogger(DestinationDtoConverter.class.getName());
public static DestinationDto convert(Destination client) {
@@ -18,18 +20,34 @@ public static DestinationDto convert(Destination client) {
if (null == client) {
return null;
}
+ DestinationTypeDto type = null;
+ String endpoint = null;
if (client instanceof DestinationNumber) {
DestinationNumber destination = (DestinationNumber) client;
- dto.type(DestinationTypeDto.NUMBER).endpoint(destination.getPhoneNumber().stringValue());
+ DestinationNumberType clientType = destination.getType();
+ if (clientType == DestinationNumberType.DID) {
+ type = DestinationTypeDto.DID;
+ } else if (clientType == DestinationNumberType.PSTN) {
+ type = DestinationTypeDto.NUMBER;
+ } else {
+ LOGGER.severe(String.format("Unexpected type '%s'", destination.getType()));
+ return dto;
+ }
+ endpoint = destination.getPhoneNumber().stringValue();
} else if (client instanceof DestinationUser) {
DestinationUser destination = (DestinationUser) client;
- dto.type(DestinationTypeDto.USERNAME).endpoint(destination.getUserName());
+ type = DestinationTypeDto.USERNAME;
+ endpoint = destination.getUserName();
} else if (client instanceof DestinationSip) {
DestinationSip destination = (DestinationSip) client;
- dto.type(DestinationTypeDto.SIP).endpoint(destination.getSIPAddress());
+ type = DestinationTypeDto.SIP;
+ endpoint = destination.getSIPAddress();
} else {
LOGGER.severe(String.format("Unexpected class '%s'", client.getClass()));
}
+ if (null != type && endpoint != null) {
+ dto.type(type).endpoint(endpoint);
+ }
return dto;
}
@@ -38,10 +56,20 @@ public static Destination convert(DestinationDto dto) {
return null;
}
Destination destination = null;
- if (Objects.equals(dto.getType(), DestinationTypeDto.NUMBER2)) {
- destination = new DestinationNumber(E164PhoneNumber.valueOf(dto.getEndpoint()));
- } else if (Objects.equals(dto.getType(), DestinationTypeDto.USERNAME2)) {
+ if (Objects.equals(dto.getType(), DestinationTypeDto.NUMBER)
+ || Objects.equals(dto.getType(), DestinationTypeDto.NUMBER2)) {
+ destination =
+ new DestinationNumber(
+ E164PhoneNumber.valueOf(dto.getEndpoint()), DestinationNumberType.PSTN);
+ } else if (Objects.equals(dto.getType(), DestinationTypeDto.USERNAME)
+ || Objects.equals(dto.getType(), DestinationTypeDto.USERNAME2)) {
destination = new DestinationUser(dto.getEndpoint());
+ } else if (Objects.equals(dto.getType(), DestinationTypeDto.SIP)) {
+ destination = new DestinationSip(dto.getEndpoint());
+ } else if (Objects.equals(dto.getType(), DestinationTypeDto.DID)) {
+ destination =
+ new DestinationNumber(
+ E164PhoneNumber.valueOf(dto.getEndpoint()), DestinationNumberType.DID);
} else {
LOGGER.severe(String.format("Unexpected type value '%s'", dto.getType()));
}
diff --git a/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/DomainTypeDtoConverter.java b/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/DomainTypeDtoConverter.java
new file mode 100644
index 000000000..36df521e0
--- /dev/null
+++ b/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/DomainTypeDtoConverter.java
@@ -0,0 +1,21 @@
+package com.sinch.sdk.domains.voice.adapters.converters;
+
+import com.sinch.sdk.domains.voice.models.DomainType;
+import com.sinch.sdk.domains.voice.models.dto.v1.DomainDto;
+
+public class DomainTypeDtoConverter {
+
+ public static DomainType convert(String dto) {
+ if (null == dto) {
+ return null;
+ }
+ return DomainType.from(dto.toLowerCase());
+ }
+
+ public static DomainType convert(DomainDto dto) {
+ if (null == dto) {
+ return null;
+ }
+ return DomainType.from(dto.getValue().toLowerCase());
+ }
+}
diff --git a/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/SAVMLActionDtoConverter.java b/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/SVAMLActionDtoConverter.java
similarity index 69%
rename from client/src/main/com/sinch/sdk/domains/voice/adapters/converters/SAVMLActionDtoConverter.java
rename to client/src/main/com/sinch/sdk/domains/voice/adapters/converters/SVAMLActionDtoConverter.java
index c70f57447..e1a35983c 100644
--- a/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/SAVMLActionDtoConverter.java
+++ b/client/src/main/com/sinch/sdk/domains/voice/adapters/converters/SVAMLActionDtoConverter.java
@@ -29,13 +29,14 @@
import com.sinch.sdk.domains.voice.models.svaml.AnsweringMachineDetection;
import com.sinch.sdk.domains.voice.models.svaml.Menu;
import com.sinch.sdk.domains.voice.models.svaml.MenuOption;
+import com.sinch.sdk.domains.voice.models.svaml.MenuOptionAction;
import java.util.Collection;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;
-public class SAVMLActionDtoConverter {
- private static final Logger LOGGER = Logger.getLogger(SAVMLActionDtoConverter.class.getName());
+public class SVAMLActionDtoConverter {
+ private static final Logger LOGGER = Logger.getLogger(SVAMLActionDtoConverter.class.getName());
public static SvamlActionDto convert(Action client) {
if (null == client) {
@@ -82,9 +83,9 @@ private static SvamlActionConnectConfDto convertAction(ActionConnectConference c
}
SvamlActionConnectConfDto dto = new SvamlActionConnectConfDto();
dto.setName(SvamlActionConnectConfDto.NameEnum.CONNECTCONF.getValue());
- dto.setConferenceId(client.getConferenceId());
- dto.setMoh(EnumDynamicConverter.convert(client.getMoh()));
- dto.setConferenceDtmfOptions(convert(client.getDtfmOptions()));
+ client.getConferenceId().ifPresent(dto::setConferenceId);
+ client.getMusicOnHold().ifPresent(f -> dto.setMoh(EnumDynamicConverter.convert(f)));
+ client.getDtfmOptions().ifPresent(f -> dto.setConferenceDtmfOptions(convert(f)));
return dto;
}
@@ -94,8 +95,8 @@ private static SvamlActionConnectMxpDto convertAction(ActionConnectMxp client) {
}
SvamlActionConnectMxpDto dto = new SvamlActionConnectMxpDto();
dto.setName(SvamlActionConnectMxpDto.NameEnum.CONNECTMXP.getValue());
- dto.setDestination(DestinationDtoConverter.convert(client.getDestination()));
- dto.setCallheaders(convertHeaderCollection(client.getCallheaders()));
+ client.getDestination().ifPresent(f -> dto.setDestination(DestinationDtoConverter.convert(f)));
+ client.getCallheaders().ifPresent(f -> dto.setCallheaders(convertHeaderCollection(f)));
return dto;
}
@@ -105,15 +106,17 @@ private static SvamlActionConnectPstnDto convertAction(ActionConnectPstn client)
}
SvamlActionConnectPstnDto dto = new SvamlActionConnectPstnDto();
dto.setName(SvamlActionConnectPstnDto.NameEnum.CONNECTPSTN.getValue());
- dto.setNumber(E164PhoneNumberDtoConverter.convert(client.getNumber()));
- dto.setLocale(client.getLocale());
- dto.setMaxDuration(client.getMaxDuration());
- dto.setDialTimeout(client.getDialTimeout());
- dto.setCli(client.getCli());
- dto.setSuppressCallbacks(client.getSuppressCallbacks());
- dto.setDtmf(DualToneMultiFrequencyDtoConverter.convert(client.getDtmf()));
- dto.setIndications(EnumDynamicConverter.convert(client.getIndications()));
- dto.setAmd(convert(client.getAnsweringMachineDetectionEnabled()));
+ client.getNumber().ifPresent(f -> dto.setNumber(E164PhoneNumberDtoConverter.convert(f)));
+ client.getLocale().ifPresent(dto::setLocale);
+ client.getMaxDuration().ifPresent(dto::setMaxDuration);
+ client.getDialTimeout().ifPresent(dto::setDialTimeout);
+ client.getCli().ifPresent(dto::setCli);
+ client.getSuppressCallbacks().ifPresent(dto::setSuppressCallbacks);
+ client
+ .getDualToneMultiFrequency()
+ .ifPresent(f -> dto.setDtmf(DualToneMultiFrequencyDtoConverter.convert(f)));
+ client.getIndications().ifPresent(f -> dto.setIndications(EnumDynamicConverter.convert(f)));
+ client.getAnsweringMachineDetection().ifPresent(f -> dto.setAmd(convert(f)));
return dto;
}
@@ -123,13 +126,13 @@ private static SvamlActionConnectSipDto convertAction(ActionConnectSip client) {
}
SvamlActionConnectSipDto dto = new SvamlActionConnectSipDto();
dto.setName(SvamlActionConnectSipDto.NameEnum.CONNECTSIP.getValue());
- dto.setDestination(DestinationDtoConverter.convert(client.getDestination()));
- dto.setMaxDuration(client.getMaxDuration());
- dto.setCli(client.getCli());
- dto.setTransport(EnumDynamicConverter.convert(client.getTransport()));
- dto.setSuppressCallbacks(client.getSuppressCallbacks());
- dto.setCallHeaders(convertHeaderCollection(client.getCallheaders()));
- dto.setMoh(EnumDynamicConverter.convert(client.getMoh()));
+ client.getDestination().ifPresent(f -> dto.setDestination(DestinationDtoConverter.convert(f)));
+ client.getMaxDuration().ifPresent(dto::setMaxDuration);
+ client.getCli().ifPresent(dto::setCli);
+ client.getTransport().ifPresent(f -> dto.setTransport(EnumDynamicConverter.convert(f)));
+ client.getSuppressCallbacks().ifPresent(dto::setSuppressCallbacks);
+ client.getCallHeaders().ifPresent(f -> dto.setCallHeaders(convertHeaderCollection(f)));
+ client.getMusicOnHold().ifPresent(f -> dto.setMoh(EnumDynamicConverter.convert(f)));
return dto;
}
@@ -157,10 +160,11 @@ private static SvamlActionParkDto convertAction(ActionPark client) {
}
SvamlActionParkDto dto = new SvamlActionParkDto();
dto.setName(SvamlActionParkDto.NameEnum.PARK.getValue());
- dto.setLocale(client.getLocale());
- dto.setIntroPrompt(client.getIntroPrompt());
- dto.setHoldPrompt(client.getHoldPrompt());
- dto.setMaxDuration(client.getMaxDuration());
+ client.getLocale().ifPresent(dto::setLocale);
+ client.getIntroPrompt().ifPresent(dto::setIntroPrompt);
+ client.getHoldPrompt().ifPresent(dto::setHoldPrompt);
+ client.getMaxDuration().ifPresent(dto::setMaxDuration);
+
return dto;
}
@@ -170,11 +174,11 @@ private static SvamlActionRunMenuDto convertAction(ActionRunMenu client) {
}
SvamlActionRunMenuDto dto = new SvamlActionRunMenuDto();
dto.setName(SvamlActionRunMenuDto.NameEnum.RUNMENU.getValue());
- dto.setBarge(client.getBarge());
- dto.setLocale(client.getLocale());
- dto.setMainMenu(client.getMainMenu());
- dto.setEnableVoice(client.getEnableVoice());
- dto.setMenus(convertMenuCollection(client.getMenus()));
+ client.getBarge().ifPresent(dto::setBarge);
+ client.getLocale().ifPresent(dto::setLocale);
+ client.getMainMenu().ifPresent(dto::setMainMenu);
+ client.getEnableVoice().ifPresent(dto::setEnableVoice);
+ client.getMenus().ifPresent(f -> dto.setMenus(convertMenuCollection(f)));
return dto;
}
@@ -207,7 +211,8 @@ private static SvamlActionConnectPstnAmdDto convert(AnsweringMachineDetection cl
}
SvamlActionConnectPstnAmdDto dto = new SvamlActionConnectPstnAmdDto();
- dto.setEnabled(client.getEnabled());
+
+ client.getEnabled().ifPresent(dto::setEnabled);
return dto;
}
@@ -215,7 +220,7 @@ private static List convertMenuCollection(Collection