Skip to content

Commit

Permalink
feature (Conversation/Template): Conversation Server Template dedicat…
Browse files Browse the repository at this point in the history
…ed BL entry points by event type
  • Loading branch information
JPPortier committed Sep 27, 2024
1 parent d40e99b commit 699a1b7
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,28 @@
import com.sinch.sdk.SinchClient;
import com.sinch.sdk.domains.conversation.api.v1.WebHooksService;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.ConversationWebhookEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.capability.CapabilityEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.channel.ChannelEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.contact.ContactCreateEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.contact.ContactDeleteEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.contact.ContactIdentitiesDuplicationEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.contact.ContactMergeEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.contact.ContactUpdateEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.conversation.ConversationDeleteEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.conversation.ConversationStartEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.conversation.ConversationStopEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.delivery.EventDeliveryReceiptEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.delivery.MessageDeliveryReceiptEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.inbound.InboundEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.message.MessageInboundEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.message.MessageSubmitEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.opting.OptInEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.opting.OptOutEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.record.RecordNotificationEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.smartconversations.MessageInboundSmartConversationRedactionEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.smartconversations.SmartConversationsEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.unsupported.UnsupportedCallbackEvent;
import java.util.Map;
import java.util.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
Expand All @@ -19,8 +39,6 @@
@RestController("Conversation")
public class Controller {

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

private final SinchClient sinchClient;
private final ServerBusinessLogic webhooksBusinessLogic;

Expand Down Expand Up @@ -54,7 +72,33 @@ public ResponseEntity<Void> ConversationEvent(
ConversationWebhookEvent event = webhooks.parseEvent(body);

// let business layer process the request
webhooksBusinessLogic.conversationEvent(event);
switch (event) {
case CapabilityEvent e -> webhooksBusinessLogic.handleCapabilityEvent(e);
case ChannelEvent e -> webhooksBusinessLogic.handleChannelEvent(e);
case ContactCreateEvent e -> webhooksBusinessLogic.handleContactCreateEvent(e);
case ContactDeleteEvent e -> webhooksBusinessLogic.handleContactDeleteEvent(e);
case ContactIdentitiesDuplicationEvent e ->
webhooksBusinessLogic.handleContactIdentitiesDuplicationEvent(e);
case ContactMergeEvent e -> webhooksBusinessLogic.handleContactMergeEvent(e);
case ContactUpdateEvent e -> webhooksBusinessLogic.handleContactUpdateEvent(e);
case ConversationDeleteEvent e -> webhooksBusinessLogic.handleConversationDeleteEvent(e);
case ConversationStartEvent e -> webhooksBusinessLogic.handleConversationStartEvent(e);
case ConversationStopEvent e -> webhooksBusinessLogic.handleConversationStopEvent(e);
case EventDeliveryReceiptEvent e -> webhooksBusinessLogic.handleEventDeliveryReceiptEvent(e);
case InboundEvent e -> webhooksBusinessLogic.handleInboundEvent(e);
case MessageDeliveryReceiptEvent e ->
webhooksBusinessLogic.handleMessageDeliveryReceiptEvent(e);
case MessageInboundEvent e -> webhooksBusinessLogic.handleMessageInboundEvent(e);
case MessageInboundSmartConversationRedactionEvent e ->
webhooksBusinessLogic.handleMessageInboundSmartConversationRedactionEvent(e);
case MessageSubmitEvent e -> webhooksBusinessLogic.handleMessageSubmitEvent(e);
case OptInEvent e -> webhooksBusinessLogic.handleOptInEvent(e);
case OptOutEvent e -> webhooksBusinessLogic.handleOptOutEvent(e);
case RecordNotificationEvent e -> webhooksBusinessLogic.handleRecordNotificationEvent(e);
case SmartConversationsEvent e -> webhooksBusinessLogic.handleSmartConversationsEvent(e);
case UnsupportedCallbackEvent e -> webhooksBusinessLogic.handleUnsupportedCallbackEvent(e);
default -> throw new IllegalStateException("Unexpected value: " + event);
}

return ResponseEntity.ok().build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
package com.mycompany.app.conversation;

import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.ConversationWebhookEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.capability.CapabilityEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.channel.ChannelEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.contact.ContactCreateEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.contact.ContactDeleteEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.contact.ContactIdentitiesDuplicationEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.contact.ContactMergeEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.contact.ContactUpdateEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.conversation.ConversationDeleteEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.conversation.ConversationStartEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.conversation.ConversationStopEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.delivery.EventDeliveryReceiptEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.delivery.MessageDeliveryReceiptEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.inbound.InboundEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.message.MessageInboundEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.message.MessageSubmitEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.opting.OptInEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.opting.OptOutEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.record.RecordNotificationEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.smartconversations.MessageInboundSmartConversationRedactionEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.smartconversations.SmartConversationsEvent;
import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.unsupported.UnsupportedCallbackEvent;
import java.util.logging.Logger;
import org.springframework.stereotype.Component;

Expand All @@ -9,7 +29,108 @@ public class ServerBusinessLogic {

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

public void conversationEvent(ConversationWebhookEvent event) {
public void handleCapabilityEvent(CapabilityEvent event) {

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

public void handleChannelEvent(ChannelEvent event) {

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

public void handleContactCreateEvent(ContactCreateEvent event) {

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

public void handleContactDeleteEvent(ContactDeleteEvent event) {

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

public void handleContactIdentitiesDuplicationEvent(ContactIdentitiesDuplicationEvent event) {

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

public void handleContactMergeEvent(ContactMergeEvent event) {

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

public void handleContactUpdateEvent(ContactUpdateEvent event) {

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

public void handleConversationDeleteEvent(ConversationDeleteEvent event) {

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

public void handleConversationStartEvent(ConversationStartEvent event) {

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

public void handleConversationStopEvent(ConversationStopEvent event) {

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

public void handleEventDeliveryReceiptEvent(EventDeliveryReceiptEvent event) {

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

public void handleInboundEvent(InboundEvent event) {

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

public void handleMessageDeliveryReceiptEvent(MessageDeliveryReceiptEvent event) {

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

public void handleMessageInboundEvent(MessageInboundEvent event) {

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

public void handleMessageInboundSmartConversationRedactionEvent(
MessageInboundSmartConversationRedactionEvent event) {

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

public void handleMessageSubmitEvent(MessageSubmitEvent event) {

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

public void handleOptInEvent(OptInEvent event) {

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

public void handleOptOutEvent(OptOutEvent event) {

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

public void handleRecordNotificationEvent(RecordNotificationEvent event) {

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

public void handleSmartConversationsEvent(SmartConversationsEvent event) {

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

public void handleUnsupportedCallbackEvent(UnsupportedCallbackEvent event) {

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

0 comments on commit 699a1b7

Please sign in to comment.