Skip to content

Commit

Permalink
feat (Voice): Move to Voice 'V1' design
Browse files Browse the repository at this point in the history
  • Loading branch information
JPPortier committed Oct 11, 2024
1 parent 035b386 commit 9ae5d94
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion templates/client/src/main/java/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static void main(String[] args) {
// (see https://developers.sinch.com/docs/voice)
// comment if unused
if (client.getConfiguration().getApplicationCredentials().isPresent()) {
VoiceQuickStart voice = new VoiceQuickStart(client.voice());
VoiceQuickStart voice = new VoiceQuickStart(client.voice().v1());
}

} catch (Exception e) {
Expand Down
2 changes: 1 addition & 1 deletion templates/client/src/main/java/voice/Snippet.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package voice;

import com.sinch.sdk.domains.voice.VoiceService;
import com.sinch.sdk.domains.voice.api.v1.VoiceService;
import java.util.logging.Logger;

public class Snippet {
Expand Down
2 changes: 1 addition & 1 deletion templates/client/src/main/java/voice/VoiceQuickStart.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package voice;

import com.sinch.sdk.domains.voice.VoiceService;
import com.sinch.sdk.domains.voice.api.v1.VoiceService;

public class VoiceQuickStart {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.mycompany.app.voice;

import com.sinch.sdk.SinchClient;
import com.sinch.sdk.domains.voice.WebHooksService;
import com.sinch.sdk.domains.voice.models.webhooks.AnsweredCallEvent;
import com.sinch.sdk.domains.voice.models.webhooks.DisconnectCallEvent;
import com.sinch.sdk.domains.voice.models.webhooks.IncomingCallEvent;
import com.sinch.sdk.domains.voice.models.webhooks.NotifyEvent;
import com.sinch.sdk.domains.voice.models.webhooks.PromptInputEvent;
import com.sinch.sdk.domains.voice.api.v1.WebHooksService;
import com.sinch.sdk.domains.voice.models.v1.webhooks.AnsweredCallEvent;
import com.sinch.sdk.domains.voice.models.v1.webhooks.DisconnectedCallEvent;
import com.sinch.sdk.domains.voice.models.v1.webhooks.IncomingCallEvent;
import com.sinch.sdk.domains.voice.models.v1.webhooks.NotificationEvent;
import com.sinch.sdk.domains.voice.models.v1.webhooks.PromptInputEvent;
import java.util.Map;
import java.util.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -39,11 +39,11 @@ public Controller(SinchClient sinchClient, ServerBusinessLogic webhooksBusinessL
public ResponseEntity<String> VoiceEvent(
@RequestHeader Map<String, String> headers, @RequestBody String body) {

WebHooksService webhooks = sinchClient.voice().webhooks();
WebHooksService webhooks = sinchClient.voice().v1().webhooks();

// ensure valid authentication to handle request
var validAuth =
webhooks.validateAuthenticatedRequest(
webhooks.validateAuthenticationHeader(
// The HTTP verb this controller is managing
"POST",
// The URI this controller is managing
Expand All @@ -59,22 +59,22 @@ public ResponseEntity<String> VoiceEvent(
}

// decode the payload request
var event = webhooks.unserializeWebhooksEvent(body);
var event = webhooks.parseEvent(body);

// let business layer process the request
var response =
switch (event) {
case IncomingCallEvent e -> webhooksBusinessLogic.incoming(e);
case AnsweredCallEvent e -> webhooksBusinessLogic.answered(e);
case DisconnectCallEvent e -> {
case DisconnectedCallEvent e -> {
webhooksBusinessLogic.disconnect(e);
yield null;
}
case PromptInputEvent e -> {
webhooksBusinessLogic.prompt(e);
yield null;
}
case NotifyEvent e -> {
case NotificationEvent e -> {
webhooksBusinessLogic.notify(e);
yield null;
}
Expand All @@ -83,7 +83,7 @@ public ResponseEntity<String> VoiceEvent(

String serializedResponse = "";
if (null != response) {
serializedResponse = webhooks.serializeWebhooksResponse(response);
serializedResponse = webhooks.serializeResponse(response);
}

LOGGER.finest("JSON response: " + serializedResponse);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.mycompany.app.voice;

import com.sinch.sdk.domains.voice.models.svaml.SVAMLControl;
import com.sinch.sdk.domains.voice.models.webhooks.AnsweredCallEvent;
import com.sinch.sdk.domains.voice.models.webhooks.DisconnectCallEvent;
import com.sinch.sdk.domains.voice.models.webhooks.IncomingCallEvent;
import com.sinch.sdk.domains.voice.models.webhooks.NotifyEvent;
import com.sinch.sdk.domains.voice.models.webhooks.PromptInputEvent;
import com.sinch.sdk.domains.voice.models.v1.svaml.SvamlControl;
import com.sinch.sdk.domains.voice.models.v1.webhooks.AnsweredCallEvent;
import com.sinch.sdk.domains.voice.models.v1.webhooks.DisconnectedCallEvent;
import com.sinch.sdk.domains.voice.models.v1.webhooks.IncomingCallEvent;
import com.sinch.sdk.domains.voice.models.v1.webhooks.NotificationEvent;
import com.sinch.sdk.domains.voice.models.v1.webhooks.PromptInputEvent;
import java.util.logging.Logger;
import org.springframework.stereotype.Component;

Expand All @@ -14,21 +14,21 @@ public class ServerBusinessLogic {

private static final Logger LOGGER = Logger.getLogger(ServerBusinessLogic.class.getName());

public SVAMLControl incoming(IncomingCallEvent event) {
public SvamlControl incoming(IncomingCallEvent event) {

LOGGER.info("Handle event :" + event);

return SVAMLControl.builder().build();
return SvamlControl.builder().build();
}

public SVAMLControl answered(AnsweredCallEvent event) {
public SvamlControl answered(AnsweredCallEvent event) {

LOGGER.info("Handle event: " + event);

return SVAMLControl.builder().build();
return SvamlControl.builder().build();
}

public void disconnect(DisconnectCallEvent event) {
public void disconnect(DisconnectedCallEvent event) {

LOGGER.info("Handle event: " + event);
}
Expand All @@ -38,7 +38,7 @@ public void prompt(PromptInputEvent event) {
LOGGER.info("Handle event: " + event);
}

public void notify(NotifyEvent event) {
public void notify(NotificationEvent event) {

LOGGER.info("Handle event: " + event);
}
Expand Down

0 comments on commit 9ae5d94

Please sign in to comment.