Skip to content
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
77 changes: 47 additions & 30 deletions MIGRATION-GUIDE.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,20 @@ public interface ConversationService {
ProjectSettingsService projectSettings();

/**
* SinchEventsService Service instance
* Event Destinations Management Service instance
*
* @return service instance for project
* @since 1.3
* @since 2.0
*/
EventDestinationsService eventDestinations();

/**
* Sinch Events helpers instance
*
* @return service instance for project
* @since 2.0
*/
WebhooksService webhooks();
SinchEventsService sinchEvents();

/**
* Templates Service instance
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.sinch.sdk.domains.conversation.api.v1;

import com.sinch.sdk.core.exceptions.ApiMappingException;
import com.sinch.sdk.domains.conversation.models.v1.sinchevents.ConversationSinchEvent;
import java.util.Map;

/**
* Sinch Events service
*
* <p>Callback events are used to get notified about Conversation usage according to your configured
* callback URL
*
* <p>see <a
* href="https://developers.sinch.com/docs/numbers/api-reference/numbers/tag/Numbers-Callbacks/#tag/Numbers-Callbacks/operation/ImportedNumberService_EventsCallback">online
* documentation</a>
*
* @since 2.0
*/
public interface SinchEventsService {

/**
* The Sinch Platform can initiate callback requests to a URL you define (Callback URL) on request
* and result events. All callback requests are signed and the signature is included in the
* Authorization header of the request
*
* <p>By using following function, you can ensure authentication according to received payload
* from your backend
*
* @param secret Secret token to be used to validate received request. See <a href=
* "https://dashboard.sinch.com/convapi/apps">App's webhook configuration onto dashboard</a>
* @param headers Received headers
* @param jsonPayload Received payload
* @return Is authentication validated (true) or not (false)
* <p>see <a
* href="https://developers.sinch.com/docs/conversation/callbacks/#validating-callbacks">online
* documentation</a>
* @since 2.0
*/
boolean validateAuthenticationHeader(
String secret, Map<String, String> headers, String jsonPayload);

/**
* This function can be called to deserialize received payload onto callback onto proper java
* verification event class
*
* @param jsonPayload Received payload to be deserialized
* @return The verification event instance class
* <p>see <a
* href="https://developers.sinch.com/docs/conversation/callbacks/#webhook-triggers">triggered
* events</a>
* @since 2.0
*/
ConversationSinchEvent parseEvent(String jsonPayload) throws ApiMappingException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
import com.sinch.sdk.domains.conversation.api.v1.CapabilityService;
import com.sinch.sdk.domains.conversation.api.v1.ContactsService;
import com.sinch.sdk.domains.conversation.api.v1.ConversationsService;
import com.sinch.sdk.domains.conversation.api.v1.EventDestinationsService;
import com.sinch.sdk.domains.conversation.api.v1.EventsService;
import com.sinch.sdk.domains.conversation.api.v1.MessagesService;
import com.sinch.sdk.domains.conversation.api.v1.ProjectSettingsService;
import com.sinch.sdk.domains.conversation.api.v1.TranscodingService;
import com.sinch.sdk.domains.conversation.api.v1.WebhooksService;
import com.sinch.sdk.domains.conversation.api.v1.adapters.credentials.LineEnterpriseCredentialsMapper;
import com.sinch.sdk.domains.conversation.api.v1.adapters.events.app.AppEventMapper;
import com.sinch.sdk.domains.conversation.api.v1.adapters.events.contactmessage.internal.ContactMessageEventMapper;
Expand Down Expand Up @@ -45,7 +45,6 @@
import com.sinch.sdk.models.ConversationContext;
import com.sinch.sdk.models.UnifiedCredentials;
import java.util.AbstractMap;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.function.Supplier;
Expand Down Expand Up @@ -74,7 +73,8 @@ public class ConversationService
private volatile TranscodingService transcoding;
private volatile CapabilityService capability;
private volatile ProjectSettingsService projectSettings;
private volatile WebhooksService webhooks;
private volatile EventDestinationsService eventDestinations;
private volatile SinchEventsService sinchEvents;
private volatile TemplatesService templates;

static {
Expand All @@ -96,7 +96,7 @@ public ConversationService(

public AppsService apps() {
if (null == this.apps) {
instanceLazyInit(true);
instanceLazyInit();
this.apps =
new AppsServiceImpl(
httpClientSupplier.get(),
Expand All @@ -110,7 +110,7 @@ public AppsService apps() {

public ContactsService contacts() {
if (null == this.contacts) {
instanceLazyInit(true);
instanceLazyInit();
this.contacts =
new ContactsServiceImpl(
httpClientSupplier.get(),
Expand All @@ -124,7 +124,7 @@ public ContactsService contacts() {

public MessagesService messages() {
if (null == this.messages) {
instanceLazyInit(true);
instanceLazyInit();
this.messages =
new MessagesServiceImpl(
httpClientSupplier.get(),
Expand All @@ -138,7 +138,7 @@ public MessagesService messages() {

public ConversationsService conversations() {
if (null == this.conversations) {
instanceLazyInit(true);
instanceLazyInit();
this.conversations =
new ConversationsServiceImpl(
httpClientSupplier.get(),
Expand All @@ -152,7 +152,7 @@ public ConversationsService conversations() {

public EventsService events() {
if (null == this.events) {
instanceLazyInit(true);
instanceLazyInit();
this.events =
new EventsServiceImpl(
httpClientSupplier.get(),
Expand All @@ -166,7 +166,7 @@ public EventsService events() {

public TranscodingService transcoding() {
if (null == this.transcoding) {
instanceLazyInit(true);
instanceLazyInit();
this.transcoding =
new TranscodingServiceImpl(
httpClientSupplier.get(),
Expand All @@ -180,7 +180,7 @@ public TranscodingService transcoding() {

public CapabilityService capability() {
if (null == this.capability) {
instanceLazyInit(true);
instanceLazyInit();
this.capability =
new CapabilityServiceImpl(
httpClientSupplier.get(),
Expand All @@ -199,24 +199,30 @@ public TemplatesService templates() {
return this.templates;
}

public WebhooksService webhooks() {
if (null == this.webhooks) {
instanceLazyInit(false);
this.webhooks =
new WebhooksServiceImpl(
public EventDestinationsService eventDestinations() {
if (null == this.eventDestinations) {
instanceLazyInit();
this.eventDestinations =
new EventDestinationsServiceImpl(
httpClientSupplier.get(),
context.getServer(),
authManagers,
HttpMapper.getInstance(),
uriUUID,
new HmacAuthenticationValidation());
uriUUID);
}
return this.webhooks;
return this.eventDestinations;
}

public SinchEventsService sinchEvents() {
if (null == this.sinchEvents) {
this.sinchEvents = new SinchEventsService(new HmacAuthenticationValidation());
}
return this.sinchEvents;
}

public ProjectSettingsService projectSettings() {
if (null == this.projectSettings) {
instanceLazyInit(true);
instanceLazyInit();
this.projectSettings =
new ProjectSettingsServiceImpl(
httpClientSupplier.get(),
Expand All @@ -228,16 +234,12 @@ public ProjectSettingsService projectSettings() {
return this.projectSettings;
}

private void instanceLazyInit(boolean validateRequired) {
private void instanceLazyInit() {
if (null != this.authManagers) {
return;
}
synchronized (this) {
if (null == this.authManagers) {
if (!validateRequired) {
this.authManagers = Collections.emptyMap();
return;
}
Objects.requireNonNull(
credentials, "Conversation service requires credentials to be defined");
Objects.requireNonNull(context, "Conversation service requires context to be defined");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.sinch.sdk.domains.conversation.api.v1.adapters;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.sinch.sdk.auth.HmacAuthenticationValidation;
import com.sinch.sdk.core.exceptions.ApiMappingException;
import com.sinch.sdk.core.utils.databind.Mapper;
import com.sinch.sdk.domains.conversation.models.v1.sinchevents.ConversationSinchEvent;
import com.sinch.sdk.domains.conversation.models.v1.sinchevents.internal.ConversationSinchEventInternalImpl;
import java.util.Map;

public class SinchEventsService
implements com.sinch.sdk.domains.conversation.api.v1.SinchEventsService {

private final HmacAuthenticationValidation authenticationChecker;

public SinchEventsService(HmacAuthenticationValidation authenticationChecker) {
this.authenticationChecker = authenticationChecker;
}

@Override
public boolean validateAuthenticationHeader(
String secret, Map<String, String> headers, String jsonPayload) {

return authenticationChecker.validateAuthenticationHeader(secret, headers, jsonPayload);
}

@Override
public ConversationSinchEvent parseEvent(String jsonPayload) throws ApiMappingException {
try {
ConversationSinchEventInternalImpl dto =
Mapper.getInstance().readValue(jsonPayload, ConversationSinchEventInternalImpl.class);
return (ConversationSinchEvent) dto.getActualInstance();
} catch (JsonProcessingException e) {
throw new ApiMappingException(jsonPayload, e);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* <code>Webhooks</code> request models
* Conversation models for <code>Event Destinations</code>
*
* @see <a
* href="https://developers.sinch.com/docs/conversation/api-reference/conversation/tag/Webhooks">Webhooks</a>
* @since 1.3
*/
package com.sinch.sdk.domains.conversation.models.v1.webhooks.request;
package com.sinch.sdk.domains.conversation.models.v1.eventdestinations;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* Conversation models for <code>Webhooks</code>
* <code>Event Destinations</code> request models
*
* @see <a
* href="https://developers.sinch.com/docs/conversation/api-reference/conversation/tag/Webhooks">Webhooks</a>
* @since 1.3
*/
package com.sinch.sdk.domains.conversation.models.v1.webhooks;
package com.sinch.sdk.domains.conversation.models.v1.eventdestinations.request;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* <code>Webhooks</code> response models
* <code>Event Destinations</code> response models
*
* @see <a
* href="https://developers.sinch.com/docs/conversation/api-reference/conversation/tag/Webhooks">Webhooks</a>
* @since 1.3
*/
package com.sinch.sdk.domains.conversation.models.v1.webhooks.response;
package com.sinch.sdk.domains.conversation.models.v1.eventdestinations.response;
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*
* <p>To start sending messages you must have a Conversation API app.
*
* <p>The app holds information about the channel credentials and registered webhooks to which the
* API delivers callbacks such as message delivery receipts and contact messages.
* <p>The app holds information about the channel credentials and registered event destinations to
* which the API delivers callbacks such as message delivery receipts and contact messages.
*
* <p>If you don't already have an app please follow the instructions in the getting started guide
* available in the Sinch Dashboard to create one.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
*
* @since 1.3
*/
package com.sinch.sdk.domains.conversation.models.v1.webhooks.events.capability;
package com.sinch.sdk.domains.conversation.models.v1.sinchevents.capability;
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
*
* @since 1.3
*/
package com.sinch.sdk.domains.conversation.models.v1.webhooks.events.channel;
package com.sinch.sdk.domains.conversation.models.v1.sinchevents.channel;
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
*
* @since 1.3
*/
package com.sinch.sdk.domains.conversation.models.v1.webhooks.events.contact;
package com.sinch.sdk.domains.conversation.models.v1.sinchevents.contact;
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
*
* @since 1.3
*/
package com.sinch.sdk.domains.conversation.models.v1.webhooks.events.conversation;
package com.sinch.sdk.domains.conversation.models.v1.sinchevents.conversation;
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
*
* @since 1.3
*/
package com.sinch.sdk.domains.conversation.models.v1.webhooks.events.delivery;
package com.sinch.sdk.domains.conversation.models.v1.sinchevents.delivery;
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
*
* @since 1.3
*/
package com.sinch.sdk.domains.conversation.models.v1.webhooks.events.inbound;
package com.sinch.sdk.domains.conversation.models.v1.sinchevents.inbound;
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
*
* @since 1.3
*/
package com.sinch.sdk.domains.conversation.models.v1.webhooks.events.message;
package com.sinch.sdk.domains.conversation.models.v1.sinchevents.message;
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
*
* @since 1.3
*/
package com.sinch.sdk.domains.conversation.models.v1.webhooks.events.opting;
package com.sinch.sdk.domains.conversation.models.v1.sinchevents.opting;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Conversation models for <code>Sinch Events</code> sent onto callbacks
*
* @see <a href="https://developers.sinch.com/docs/conversation/callbacks">callbacks</a>
* @since 1.3
*/
package com.sinch.sdk.domains.conversation.models.v1.sinchevents;
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
*
* @since 1.3
*/
package com.sinch.sdk.domains.conversation.models.v1.webhooks.events.record;
package com.sinch.sdk.domains.conversation.models.v1.sinchevents.record;
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
*
* @since 1.3
*/
package com.sinch.sdk.domains.conversation.models.v1.webhooks.events.smartconversations;
package com.sinch.sdk.domains.conversation.models.v1.sinchevents.smartconversations;
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
*
* @since 1.3
*/
package com.sinch.sdk.domains.conversation.models.v1.webhooks.events.unsupported;
package com.sinch.sdk.domains.conversation.models.v1.sinchevents.unsupported;

This file was deleted.

Loading
Loading