diff --git a/client/src/main/com/sinch/sdk/domains/conversation/api/v1/ConversationService.java b/client/src/main/com/sinch/sdk/domains/conversation/api/v1/ConversationService.java index e182c1a8c..69e79be40 100644 --- a/client/src/main/com/sinch/sdk/domains/conversation/api/v1/ConversationService.java +++ b/client/src/main/com/sinch/sdk/domains/conversation/api/v1/ConversationService.java @@ -33,6 +33,14 @@ public interface ConversationService { */ MessagesService messages(); + /** + * Conversations Service instance + * + * @return service instance for project + * @since _NEXT_VERSION_ + */ + ConversationsService conversations(); + /** * WebHooksService Service instance * diff --git a/client/src/main/com/sinch/sdk/domains/conversation/api/v1/ConversationsService.java b/client/src/main/com/sinch/sdk/domains/conversation/api/v1/ConversationsService.java new file mode 100644 index 000000000..be9fea6d4 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/conversation/api/v1/ConversationsService.java @@ -0,0 +1,93 @@ +package com.sinch.sdk.domains.conversation.api.v1; + +import com.sinch.sdk.domains.conversation.models.v1.conversation.Conversation; +import com.sinch.sdk.domains.conversation.models.v1.conversation.request.ConversationsListRecentRequest; +import com.sinch.sdk.domains.conversation.models.v1.conversation.request.ConversationsListRequest; +import com.sinch.sdk.domains.conversation.models.v1.conversation.request.CreateConversationRequest; +import com.sinch.sdk.domains.conversation.models.v1.conversation.response.ConversationsListRecentResponse; +import com.sinch.sdk.domains.conversation.models.v1.conversation.response.ConversationsListResponse; +import com.sinch.sdk.domains.conversation.models.v1.request.MetadataUpdateStrategy; + +/** + * Service for working with the conversation log + * + * @see online + * documentation + * @since _NEXT_VERSION_ + */ +public interface ConversationsService { + + /** + * Creates a new empty conversation. + * + *

It is generally not needed to create a conversation explicitly since sending or receiving a + * message automatically creates a new conversation if it does not already exist between the given + * app and contact. + * + *

Creating empty conversation is useful if the metadata of the conversation should be + * populated when the first message in the conversation is a contact message or the first message + * in the conversation comes out-of-band and needs to be injected with InjectMessage. + * + * @param request Conversation request for creation + * @return Created conversation + * @since _NEXT_VERSION_ + */ + Conversation create(CreateConversationRequest request); + + /** + * Retrieves a conversation by id. A conversation has two participating entities, an app and a + * contact. + * + * @param conversationId The unique ID of the conversation. + * @return Conversation details + * @since _NEXT_VERSION_ + */ + Conversation get(String conversationId); + + /** + * This operation lists all conversations that are associated with an app and/or a contact. + * + * @param request Request parameters + * @since _NEXT_VERSION_ + */ + ConversationsListResponse list(ConversationsListRequest request); + + /** + * This operation lists conversations and their most recent message, ordered by when the most + * recent message was sent for that conversation. + * + * @param request Request parameters + * @since _NEXT_VERSION_ + */ + ConversationsListRecentResponse listRecent(ConversationsListRecentRequest request); + + /** + * This operation stops the referenced conversation, if the conversation is still active. + * + *

A new conversation will be created if a new message is exchanged between the app or contact + * that was part of the stopped conversation. + * + * @param conversationId The unique ID of the conversation. + * @since _NEXT_VERSION_ + */ + void stopActive(String conversationId); + + /** + * Deletes a conversation together with all the messages sent as part of the conversation. + * + * @param conversationId The unique ID of the conversation. + * @since _NEXT_VERSION_ + */ + void delete(String conversationId); + + /** + * This operation updates a conversation which can, for instance, be used to update the metadata + * associated with a conversation. + * + * @param request Conversation instance with fields to be updated + * @return Update conversation + */ + Conversation update( + String conversationId, MetadataUpdateStrategy updateStrategy, Conversation request); +} diff --git a/client/src/main/com/sinch/sdk/domains/conversation/api/v1/adapters/ConversationService.java b/client/src/main/com/sinch/sdk/domains/conversation/api/v1/adapters/ConversationService.java index 8d58084cc..7c685ade3 100644 --- a/client/src/main/com/sinch/sdk/domains/conversation/api/v1/adapters/ConversationService.java +++ b/client/src/main/com/sinch/sdk/domains/conversation/api/v1/adapters/ConversationService.java @@ -45,6 +45,8 @@ public class ConversationService private AppService app; private ContactService contact; private MessagesService messages; + private ConversationsService conversations; + private WebHooksService webhooks; static { @@ -115,6 +117,13 @@ public WebHooksService webhooks() { return this.webhooks; } + public ConversationsService conversations() { + if (null == this.conversations) { + this.conversations = new ConversationsService(uriUUID, context, httpClient, authManagers); + } + return this.conversations; + } + static final class LocalLazyInit { private LocalLazyInit() { diff --git a/client/src/main/com/sinch/sdk/domains/conversation/api/v1/adapters/ConversationsService.java b/client/src/main/com/sinch/sdk/domains/conversation/api/v1/adapters/ConversationsService.java new file mode 100644 index 000000000..c4eb246e4 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/conversation/api/v1/adapters/ConversationsService.java @@ -0,0 +1,136 @@ +package com.sinch.sdk.domains.conversation.api.v1.adapters; + +import com.sinch.sdk.core.http.AuthManager; +import com.sinch.sdk.core.http.HttpClient; +import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.core.models.pagination.Page; +import com.sinch.sdk.core.models.pagination.TokenPageNavigator; +import com.sinch.sdk.core.utils.Pair; +import com.sinch.sdk.domains.conversation.api.v1.internal.ConversationApi; +import com.sinch.sdk.domains.conversation.models.v1.ConversationChannel; +import com.sinch.sdk.domains.conversation.models.v1.conversation.Conversation; +import com.sinch.sdk.domains.conversation.models.v1.conversation.internal.ListConversationsResponseInternal; +import com.sinch.sdk.domains.conversation.models.v1.conversation.internal.ListConversationsResponseInternalImpl; +import com.sinch.sdk.domains.conversation.models.v1.conversation.internal.ListRecentConversationsResponseInternal; +import com.sinch.sdk.domains.conversation.models.v1.conversation.internal.ListRecentConversationsResponseInternalImpl; +import com.sinch.sdk.domains.conversation.models.v1.conversation.request.ConversationsListRecentRequest; +import com.sinch.sdk.domains.conversation.models.v1.conversation.request.ConversationsListRecentRequest.OrderEnum; +import com.sinch.sdk.domains.conversation.models.v1.conversation.request.ConversationsListRequest; +import com.sinch.sdk.domains.conversation.models.v1.conversation.request.CreateConversationRequest; +import com.sinch.sdk.domains.conversation.models.v1.conversation.response.ConversationRecentMessage; +import com.sinch.sdk.domains.conversation.models.v1.conversation.response.ConversationsListRecentResponse; +import com.sinch.sdk.domains.conversation.models.v1.conversation.response.ConversationsListResponse; +import com.sinch.sdk.domains.conversation.models.v1.request.MetadataUpdateStrategy; +import com.sinch.sdk.models.ConversationContext; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; + +public class ConversationsService + implements com.sinch.sdk.domains.conversation.api.v1.ConversationsService { + + private final String uriUUID; + private final ConversationApi api; + + public ConversationsService( + String uriUUID, + ConversationContext context, + HttpClient httpClient, + Map authManagers) { + this.uriUUID = uriUUID; + this.api = new ConversationApi(httpClient, context.getServer(), authManagers, new HttpMapper()); + } + + protected ConversationApi getApi() { + return this.api; + } + + public Conversation create(CreateConversationRequest request) { + return getApi().conversationCreateConversation(uriUUID, request); + } + + public Conversation get(String conversationId) { + return getApi().conversationGetConversation(uriUUID, conversationId); + } + + public ConversationsListResponse list(ConversationsListRequest parameters) { + + Boolean onlyActive = parameters.getOnlyActive().orElse(null); + String contactId = parameters.getContactId().orElse(null); + String appId = parameters.getAppId().orElse(null); + + Integer pageSize = parameters.getPageSize().orElse(null); + String pageToken = parameters.getPageToken().orElse(null); + ConversationChannel activeChannel = parameters.getActiveChannel().orElse(null); + + ListConversationsResponseInternal response = + getApi() + .conversationListConversations( + uriUUID, onlyActive, appId, contactId, pageSize, pageToken, activeChannel); + + return mapForPaging(parameters, response); + } + + public ConversationsListRecentResponse listRecent(ConversationsListRecentRequest parameters) { + + Boolean onlyActive = parameters.getOnlyActive().orElse(null); + String appId = parameters.getAppId().orElse(null); + + Integer pageSize = parameters.getPageSize().orElse(null); + String pageToken = parameters.getPageToken().orElse(null); + String order = parameters.getOrder().map(OrderEnum::value).orElse(null); + + ListRecentConversationsResponseInternal response = + getApi() + .conversationListRecentConversations( + uriUUID, appId, onlyActive, pageSize, pageToken, order); + + return mapForPaging(parameters, response); + } + + public void stopActive(String conversationId) { + getApi().conversationStopActiveConversation(uriUUID, conversationId); + } + + public void delete(String conversationId) { + getApi().conversationDeleteConversation(uriUUID, conversationId); + } + + public Conversation update( + String conversationId, MetadataUpdateStrategy updateStrategy, Conversation request) { + return getApi() + .conversationUpdateConversation(uriUUID, conversationId, request, null, updateStrategy); + } + + private ConversationsListResponse mapForPaging( + ConversationsListRequest parameters, ListConversationsResponseInternal _dto) { + + ListConversationsResponseInternalImpl dto = (ListConversationsResponseInternalImpl) _dto; + + String nextPageToken = dto.nextPageToken().orElse(null); + Collection list = dto.conversations().orElse(Collections.emptyList()); + + Pair, TokenPageNavigator> paginated = + new Pair<>(list, new TokenPageNavigator(nextPageToken)); + + return new ConversationsListResponse( + this, new Page<>(parameters, paginated.getLeft(), paginated.getRight())); + } + + private ConversationsListRecentResponse mapForPaging( + ConversationsListRecentRequest parameters, ListRecentConversationsResponseInternal _dto) { + + ListRecentConversationsResponseInternalImpl dto = + (ListRecentConversationsResponseInternalImpl) _dto; + + String nextPageToken = dto.nextPageToken().orElse(null); + Collection list = + dto.conversations().orElse(Collections.emptyList()); + + Pair, TokenPageNavigator> paginated = + new Pair<>(list, new TokenPageNavigator(nextPageToken)); + + return new ConversationsListRecentResponse( + this, new Page<>(parameters, paginated.getLeft(), paginated.getRight())); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/ConversationsListRecentRequest.java b/client/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/ConversationsListRecentRequest.java new file mode 100644 index 000000000..e856d37d6 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/ConversationsListRecentRequest.java @@ -0,0 +1,144 @@ +package com.sinch.sdk.domains.conversation.models.v1.conversation.request; + +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import java.util.Arrays; +import java.util.Optional; +import java.util.stream.Stream; + +/** + * Parameters request to list recent messages from a conversation + * + * @see online + * documentation + * @since _NEXT_VERSION_ + */ +public interface ConversationsListRecentRequest { + + /** + * Filtering onto active conversations only or not + * + *

True if only active conversations should be listed. + * + * @default False + * @return Only active filter + */ + Optional getOnlyActive(); + + /** + * Id of the application. + * + * @return application id + */ + Optional getAppId(); + + /** + * Maximum number of conversations to fetch. + * + *

Defaults to 10 and the maximum is 50. + * + * @default 10 + * @return Page size + */ + Optional getPageSize(); + + /** + * Next page token previously returned if any. + * + *

When specifying this token, make sure to use the same values for the other parameters from + * the request that originated the token, otherwise the paged results may be inconsistent. + * + * @return Page token + */ + Optional getPageToken(); + + /** + * Only fetch conversations from the active channel + * + * @return Channel to filtered on + */ + Optional getOrder(); + + public class OrderEnum extends EnumDynamic { + public static final OrderEnum ASC = new OrderEnum("ASC"); + public static final OrderEnum DESC = new OrderEnum("DESC"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>(OrderEnum.class, OrderEnum::new, Arrays.asList(ASC, DESC)); + + private OrderEnum(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static OrderEnum from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(OrderEnum e) { + return ENUM_SUPPORT.valueOf(e); + } + } + + static Builder builder() { + return new ConversationsListRecentRequestImpl.Builder(); + } + + static Builder builder(ConversationsListRecentRequest parameters) { + return new ConversationsListRecentRequestImpl.Builder(parameters); + } + + interface Builder { + + /** + * see getter + * + * @param onlyActive see getter + * @return Current builder + * @see #setOnlyActive(Boolean) () + */ + Builder setOnlyActive(Boolean onlyActive); + + /** + * see getter + * + * @param appId see getter + * @return Current builder + * @see #getAppId() + */ + Builder setAppId(String appId); + + /** + * see getter + * + * @param pageSize see getter + * @return Current builder + * @see #getPageSize() + */ + Builder setPageSize(Integer pageSize); + + /** + * see getter + * + * @param pageToken see getter + * @return Current builder + * @see #getPageToken() + */ + Builder setPageToken(String pageToken); + + /** + * see getter + * + * @param order see getter + * @return Current builder + * @see #getOrder() () + */ + Builder setOrder(OrderEnum order); + + ConversationsListRecentRequest build(); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/ConversationsListRecentRequestImpl.java b/client/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/ConversationsListRecentRequestImpl.java new file mode 100644 index 000000000..8d7c9169d --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/ConversationsListRecentRequestImpl.java @@ -0,0 +1,108 @@ +package com.sinch.sdk.domains.conversation.models.v1.conversation.request; + +import java.util.Optional; + +public class ConversationsListRecentRequestImpl implements ConversationsListRecentRequest { + + final Boolean onlyActive; + final String appId; + final Integer pageSize; + final String pageToken; + final OrderEnum order; + + public ConversationsListRecentRequestImpl( + Boolean onlyActive, String appId, Integer pageSize, String pageToken, OrderEnum order) { + this.onlyActive = onlyActive; + this.appId = appId; + this.pageSize = pageSize; + this.pageToken = pageToken; + this.order = order; + } + + @Override + public Optional getOnlyActive() { + return Optional.ofNullable(onlyActive); + } + + @Override + public Optional getAppId() { + return Optional.ofNullable(appId); + } + + @Override + public Optional getPageSize() { + return Optional.ofNullable(pageSize); + } + + @Override + public Optional getPageToken() { + return Optional.ofNullable(pageToken); + } + + @Override + public Optional getOrder() { + return Optional.ofNullable(order); + } + + public static Builder builder() { + return new Builder(); + } + + public static Builder builder(ConversationsListRecentRequest parameters) { + return new Builder(parameters); + } + + public static class Builder implements ConversationsListRecentRequest.Builder { + + Boolean onlyActive; + String appId; + Integer pageSize; + String pageToken; + OrderEnum order; + + Builder() {} + + Builder(ConversationsListRecentRequest parameters) { + + parameters.getOnlyActive().ifPresent(this::setOnlyActive); + parameters.getAppId().ifPresent(this::setAppId); + parameters.getPageSize().ifPresent(this::setPageSize); + parameters.getPageToken().ifPresent(this::setPageToken); + parameters.getOrder().ifPresent(this::setOrder); + } + + @Override + public Builder setOnlyActive(Boolean onlyActive) { + this.onlyActive = onlyActive; + return this; + } + + @Override + public Builder setAppId(String appId) { + this.appId = appId; + return this; + } + + @Override + public Builder setPageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + @Override + public Builder setPageToken(String pageToken) { + this.pageToken = pageToken; + return this; + } + + @Override + public Builder setOrder(OrderEnum order) { + this.order = order; + return this; + } + + public ConversationsListRecentRequest build() { + return new ConversationsListRecentRequestImpl(onlyActive, appId, pageSize, pageToken, order); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/ConversationsListRequest.java b/client/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/ConversationsListRequest.java new file mode 100644 index 000000000..5812001b2 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/ConversationsListRequest.java @@ -0,0 +1,138 @@ +package com.sinch.sdk.domains.conversation.models.v1.conversation.request; + +import com.sinch.sdk.domains.conversation.models.v1.ConversationChannel; +import java.util.Optional; + +/** + * Parameters request to list messages + * + * @see online + * documentation + * @since _NEXT_VERSION_ + */ +public interface ConversationsListRequest { + + /** + * Filtering onto active conversations only or not + * + *

True if only active conversations should be listed. + * + * @return Only active filter + */ + Optional getOnlyActive(); + + /** + * Resource name (ID) of the contact. + * + *

Note that either app_id or contact_id is required in order for the + * operation to function correctly. + * + * @return contact id + */ + Optional getContactId(); + + /** + * Id of the application. + * + *

Note that either app_id or contact_id is required in order for the + * operation to function correctly. + * + * @return application id + */ + Optional getAppId(); + + /** + * Maximum number of conversations to fetch. + * + *

Defaults to 10 and the maximum is 20. + * + * @default 10 + * @return Page size + */ + Optional getPageSize(); + + /** + * Next page token previously returned if any. + * + *

When specifying this token, make sure to use the same values for the other parameters from + * the request that originated the token, otherwise the paged results may be inconsistent. + * + * @return Page token + */ + Optional getPageToken(); + + /** + * Only fetch conversations from the active channel + * + * @return Channel to filtered on + */ + Optional getActiveChannel(); + + static Builder builder() { + return new ConversationsListRequestImpl.Builder(); + } + + static Builder builder(ConversationsListRequest parameters) { + return new ConversationsListRequestImpl.Builder(parameters); + } + + interface Builder { + + /** + * see getter + * + * @param onlyActive see getter + * @return Current builder + * @see #setOnlyActive(Boolean) () + */ + Builder setOnlyActive(Boolean onlyActive); + + /** + * see getter + * + * @param contactId see getter + * @return Current builder + * @see #getContactId() + */ + Builder setContactId(String contactId); + + /** + * see getter + * + * @param appId see getter + * @return Current builder + * @see #getAppId() + */ + Builder setAppId(String appId); + + /** + * see getter + * + * @param pageSize see getter + * @return Current builder + * @see #getPageSize() + */ + Builder setPageSize(Integer pageSize); + + /** + * see getter + * + * @param pageToken see getter + * @return Current builder + * @see #getPageToken() + */ + Builder setPageToken(String pageToken); + + /** + * see getter + * + * @param channel see getter + * @return Current builder + * @see #getActiveChannel() + */ + Builder setActiveChannel(ConversationChannel channel); + + ConversationsListRequest build(); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/ConversationsListRequestImpl.java b/client/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/ConversationsListRequestImpl.java new file mode 100644 index 000000000..847e90b9a --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/ConversationsListRequestImpl.java @@ -0,0 +1,130 @@ +package com.sinch.sdk.domains.conversation.models.v1.conversation.request; + +import com.sinch.sdk.domains.conversation.models.v1.ConversationChannel; +import java.util.Optional; + +public class ConversationsListRequestImpl implements ConversationsListRequest { + + final Boolean onlyActive; + final String contactId; + final String appId; + final Integer pageSize; + final String pageToken; + final ConversationChannel activeChannel; + + public ConversationsListRequestImpl( + Boolean onlyActive, + String contactId, + String appId, + Integer pageSize, + String pageToken, + ConversationChannel activeChannel) { + this.onlyActive = onlyActive; + this.contactId = contactId; + this.appId = appId; + this.pageSize = pageSize; + this.pageToken = pageToken; + this.activeChannel = activeChannel; + } + + @Override + public Optional getOnlyActive() { + return Optional.ofNullable(onlyActive); + } + + @Override + public Optional getContactId() { + return Optional.ofNullable(contactId); + } + + @Override + public Optional getAppId() { + return Optional.ofNullable(appId); + } + + @Override + public Optional getPageSize() { + return Optional.ofNullable(pageSize); + } + + @Override + public Optional getPageToken() { + return Optional.ofNullable(pageToken); + } + + @Override + public Optional getActiveChannel() { + return Optional.ofNullable(activeChannel); + } + + public static Builder builder() { + return new Builder(); + } + + public static Builder builder(ConversationsListRequest parameters) { + return new Builder(parameters); + } + + public static class Builder implements ConversationsListRequest.Builder { + + Boolean onlyActive; + String contactId; + String appId; + Integer pageSize; + String pageToken; + ConversationChannel activeChannel; + + Builder() {} + + Builder(ConversationsListRequest parameters) { + + parameters.getOnlyActive().ifPresent(this::setOnlyActive); + parameters.getContactId().ifPresent(this::setContactId); + parameters.getAppId().ifPresent(this::setAppId); + parameters.getPageSize().ifPresent(this::setPageSize); + parameters.getPageToken().ifPresent(this::setPageToken); + parameters.getActiveChannel().ifPresent(this::setActiveChannel); + } + + @Override + public Builder setOnlyActive(Boolean onlyActive) { + this.onlyActive = onlyActive; + return this; + } + + @Override + public Builder setContactId(String contactId) { + this.contactId = contactId; + return this; + } + + @Override + public Builder setAppId(String appId) { + this.appId = appId; + return this; + } + + @Override + public Builder setPageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + @Override + public Builder setPageToken(String pageToken) { + this.pageToken = pageToken; + return this; + } + + @Override + public Builder setActiveChannel(ConversationChannel channel) { + this.activeChannel = channel; + return this; + } + + public ConversationsListRequest build() { + return new ConversationsListRequestImpl( + onlyActive, contactId, appId, pageSize, pageToken, activeChannel); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ConversationsListRecentResponse.java b/client/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ConversationsListRecentResponse.java new file mode 100644 index 000000000..c74aca5e1 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ConversationsListRecentResponse.java @@ -0,0 +1,53 @@ +package com.sinch.sdk.domains.conversation.models.v1.conversation.response; + +import com.sinch.sdk.core.models.pagination.ListResponse; +import com.sinch.sdk.core.models.pagination.Page; +import com.sinch.sdk.core.utils.StringUtil; +import com.sinch.sdk.domains.conversation.api.v1.ConversationsService; +import com.sinch.sdk.domains.conversation.models.v1.conversation.request.ConversationsListRecentRequest; +import java.util.Collection; +import java.util.NoSuchElementException; + +/** + * Recent messages and conversation response + * + * @since _NEXT_VERSION_ + */ +public class ConversationsListRecentResponse extends ListResponse { + + private final Page page; + private final ConversationsService service; + + public ConversationsListRecentResponse( + ConversationsService service, + Page page) { + this.service = service; + this.page = page; + } + + @Override + public boolean hasNextPage() { + return (null != page.getNextPageToken() && !StringUtil.isEmpty(page.getNextPageToken())); + } + + @Override + public ConversationsListRecentResponse nextPage() { + if (!hasNextPage()) { + throw new NoSuchElementException("Reached the last page of the API response"); + } + ConversationsListRecentRequest.Builder newParameters = + ConversationsListRecentRequest.builder(page.getParameters()); + newParameters.setPageToken(page.getNextPageToken()); + return service.listRecent(newParameters.build()); + } + + @Override + public Collection getContent() { + return page.getEntities(); + } + + @Override + public String toString() { + return "ConversationsListRecentResponse{" + "page=" + page + '}'; + } +} diff --git a/client/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ConversationsListResponse.java b/client/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ConversationsListResponse.java new file mode 100644 index 000000000..40651f59f --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ConversationsListResponse.java @@ -0,0 +1,53 @@ +package com.sinch.sdk.domains.conversation.models.v1.conversation.response; + +import com.sinch.sdk.core.models.pagination.ListResponse; +import com.sinch.sdk.core.models.pagination.Page; +import com.sinch.sdk.core.utils.StringUtil; +import com.sinch.sdk.domains.conversation.api.v1.ConversationsService; +import com.sinch.sdk.domains.conversation.models.v1.conversation.Conversation; +import com.sinch.sdk.domains.conversation.models.v1.conversation.request.ConversationsListRequest; +import java.util.Collection; +import java.util.NoSuchElementException; + +/** + * Lists all conversations response + * + * @since _NEXT_VERSION_ + */ +public class ConversationsListResponse extends ListResponse { + + private final Page page; + private final ConversationsService service; + + public ConversationsListResponse( + ConversationsService service, Page page) { + this.service = service; + this.page = page; + } + + @Override + public boolean hasNextPage() { + return (null != page.getNextPageToken() && !StringUtil.isEmpty(page.getNextPageToken())); + } + + @Override + public ConversationsListResponse nextPage() { + if (!hasNextPage()) { + throw new NoSuchElementException("Reached the last page of the API response"); + } + ConversationsListRequest.Builder newParameters = + ConversationsListRequest.builder(page.getParameters()); + newParameters.setPageToken(page.getNextPageToken()); + return service.list(newParameters.build()); + } + + @Override + public Collection getContent() { + return page.getEntities(); + } + + @Override + public String toString() { + return "ConversationsListResponse{" + "page=" + page + '}'; + } +} diff --git a/client/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/AppMessageImpl.java b/client/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/AppMessageImpl.java index 7d22dbbda..82a38a817 100644 --- a/client/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/AppMessageImpl.java +++ b/client/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/AppMessageImpl.java @@ -74,7 +74,7 @@ public OptionalValue agent() { @Override public String toString() { - return "AppMessageWithExtensionsImpl{" + return "AppMessageImpl{" + "message=" + message + ", explicitChannelMessage=" diff --git a/client/src/test/java/com/sinch/sdk/domains/conversation/api/v1/adapters/ConversationsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/conversation/api/v1/adapters/ConversationsServiceTest.java new file mode 100644 index 000000000..00c41ee0f --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/conversation/api/v1/adapters/ConversationsServiceTest.java @@ -0,0 +1,246 @@ +package com.sinch.sdk.domains.conversation.api.v1.adapters; + +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.AuthManager; +import com.sinch.sdk.core.http.HttpClient; +import com.sinch.sdk.domains.conversation.api.v1.internal.ConversationApi; +import com.sinch.sdk.domains.conversation.models.v1.ConversationChannel; +import com.sinch.sdk.domains.conversation.models.v1.conversation.Conversation; +import com.sinch.sdk.domains.conversation.models.v1.conversation.internal.ListConversationsResponseInternal; +import com.sinch.sdk.domains.conversation.models.v1.conversation.internal.ListRecentConversationsResponseInternal; +import com.sinch.sdk.domains.conversation.models.v1.conversation.request.ConversationsListRecentRequest; +import com.sinch.sdk.domains.conversation.models.v1.conversation.request.ConversationsListRecentRequest.OrderEnum; +import com.sinch.sdk.domains.conversation.models.v1.conversation.request.ConversationsListRequest; +import com.sinch.sdk.domains.conversation.models.v1.conversation.response.ConversationRecentMessage; +import com.sinch.sdk.domains.conversation.models.v1.conversation.response.ConversationsListRecentResponse; +import com.sinch.sdk.domains.conversation.models.v1.conversation.response.ConversationsListResponse; +import com.sinch.sdk.domains.conversation.models.v1.conversations.ConversationDtoTest; +import com.sinch.sdk.domains.conversation.models.v1.conversations.request.CreateConversationRequestTest; +import com.sinch.sdk.domains.conversation.models.v1.conversations.response.ConversationRecentMessageDtoTest; +import com.sinch.sdk.domains.conversation.models.v1.request.MetadataUpdateStrategy; +import com.sinch.sdk.models.ConversationContext; +import java.util.Collection; +import java.util.Map; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; + +@TestWithResources +public class ConversationsServiceTest extends ConversationBaseTest { + + @Mock ConversationContext context; + @Mock ConversationApi api; + @Mock HttpClient httpClient; + @Mock Map authManagers; + @Captor ArgumentCaptor projectIdCaptor; + @Captor ArgumentCaptor conversationIdCaptor; + + ConversationsService service; + String uriPartID = "foovalue"; + + @BeforeEach + public void initMocks() { + service = spy(new ConversationsService(uriPartID, context, httpClient, authManagers)); + doReturn(api).when(service).getApi(); + } + + @GivenJsonResource( + "/domains/conversation/v1/conversations/response/ConversationsListResponse-page-0.json") + ListConversationsResponseInternal conversationsListPage0; + + @GivenJsonResource( + "/domains/conversation/v1/conversations/response/ConversationsListResponse-page-1.json") + ListConversationsResponseInternal conversationsListPage1; + + @GivenJsonResource( + "/domains/conversation/v1/conversations/response/ConversationsListResponse-page-2.json") + ListConversationsResponseInternal conversationsListPage2; + + @GivenJsonResource( + "/domains/conversation/v1/conversations/response/ConversationsListRecentResponse-page-0.json") + ListRecentConversationsResponseInternal conversationsRecentListPage0; + + @GivenJsonResource( + "/domains/conversation/v1/conversations/response/ConversationsListRecentResponse-page-1.json") + ListRecentConversationsResponseInternal conversationsRecentListPage1; + + @Test + void create() throws ApiException { + + when(api.conversationCreateConversation( + eq(uriPartID), eq(CreateConversationRequestTest.createConversationRequestDto))) + .thenReturn(ConversationDtoTest.conversation); + + Conversation response = + service.create(CreateConversationRequestTest.createConversationRequestDto); + + TestHelpers.recursiveEquals(response, ConversationDtoTest.conversation); + } + + @Test + void get() throws ApiException { + + when(api.conversationGetConversation( + eq(uriPartID), eq(ConversationDtoTest.conversation.getId()))) + .thenReturn(ConversationDtoTest.conversation); + + Conversation response = service.get(ConversationDtoTest.conversation.getId()); + + TestHelpers.recursiveEquals(response, ConversationDtoTest.conversation); + } + + @Test + void list() throws ApiException { + + when(api.conversationListConversations( + eq(uriPartID), + eq(true), + eq("conversation app Id"), + eq("contact id"), + eq(1), + eq(null), + eq(ConversationChannel.MESSENGER))) + .thenReturn(conversationsListPage0); + + when(api.conversationListConversations( + eq(uriPartID), + eq(true), + eq("conversation app Id"), + eq("contact id"), + eq(1), + eq("ChowMUo1NUVOVERUSFlGQVlKMFE1WFpaSktSVhIaMDFITkIzMzY0UFdCQkcyR1paV1ZWVDNERDI="), + eq(ConversationChannel.MESSENGER))) + .thenReturn(conversationsListPage1); + + when(api.conversationListConversations( + eq(uriPartID), + eq(true), + eq("conversation app Id"), + eq("contact id"), + eq(1), + eq("ChowMUo1NUVBSk1FNDZQMlI4SFIxRjVZRjYxWhIaMDFITkIzMzY0UFdCQkcyR1paV1ZWVDNERDI="), + eq(ConversationChannel.MESSENGER))) + .thenReturn(conversationsListPage2); + ConversationsListRequest request = + ConversationsListRequest.builder() + .setOnlyActive(true) + .setAppId("conversation app Id") + .setContactId("contact id") + .setPageSize(1) + .setActiveChannel(ConversationChannel.MESSENGER) + .build(); + + ConversationsListResponse response0 = service.list(request); + Collection content = response0.getContent(); + Assertions.assertThat(content.size()).isEqualTo(1); + TestHelpers.recursiveEquals( + content.stream().findFirst().orElse(null), ConversationDtoTest.conversation); + Assertions.assertThat(response0.hasNextPage()).isEqualTo(true); + + ConversationsListResponse response1 = response0.nextPage(); + content = response1.getContent(); + Assertions.assertThat(content.size()).isEqualTo(1); + TestHelpers.recursiveEquals( + content.stream().findFirst().orElse(null), ConversationDtoTest.conversation); + Assertions.assertThat(response1.hasNextPage()).isEqualTo(true); + + ConversationsListResponse response2 = response1.nextPage(); + content = response2.getContent(); + Assertions.assertThat(content.size()).isEqualTo(0); + Assertions.assertThat(response2.hasNextPage()).isEqualTo(false); + } + + @Test + void listRecent() throws ApiException { + + when(api.conversationListRecentConversations( + eq(uriPartID), eq("conversation app Id"), eq(true), eq(1), eq(null), eq("ASC"))) + .thenReturn(conversationsRecentListPage0); + + when(api.conversationListRecentConversations( + eq(uriPartID), eq("conversation app Id"), eq(true), eq(1), eq("1"), eq("ASC"))) + .thenReturn(conversationsRecentListPage1); + + ConversationsListRecentRequest request = + ConversationsListRecentRequest.builder() + .setAppId("conversation app Id") + .setOnlyActive(true) + .setPageSize(1) + .setOrder(OrderEnum.ASC) + .build(); + + ConversationsListRecentResponse response0 = service.listRecent(request); + Collection content = response0.getContent(); + Assertions.assertThat(content.size()).isEqualTo(1); + TestHelpers.recursiveEquals( + content.stream().findFirst().orElse(null), + ConversationRecentMessageDtoTest.conversationRecentMessage); + Assertions.assertThat(response0.hasNextPage()).isEqualTo(true); + + ConversationsListRecentResponse response1 = response0.nextPage(); + content = response1.getContent(); + Assertions.assertThat(content.size()).isEqualTo(1); + TestHelpers.recursiveEquals( + content.stream().findFirst().orElse(null), + ConversationRecentMessageDtoTest.conversationRecentMessage); + Assertions.assertThat(response1.hasNextPage()).isEqualTo(false); + } + + @Test + void stopActive() throws ApiException { + + service.stopActive(ConversationDtoTest.conversation.getId()); + + verify(api) + .conversationStopActiveConversation( + projectIdCaptor.capture(), conversationIdCaptor.capture()); + + Assertions.assertThat(projectIdCaptor.getValue()).isEqualTo(uriPartID); + Assertions.assertThat(conversationIdCaptor.getValue()) + .isEqualTo(ConversationDtoTest.conversation.getId()); + } + + @Test + void delete() throws ApiException { + + service.delete(ConversationDtoTest.conversation.getId()); + + verify(api) + .conversationDeleteConversation(projectIdCaptor.capture(), conversationIdCaptor.capture()); + + Assertions.assertThat(projectIdCaptor.getValue()).isEqualTo(uriPartID); + Assertions.assertThat(conversationIdCaptor.getValue()) + .isEqualTo(ConversationDtoTest.conversation.getId()); + } + + @Test + void update() throws ApiException { + when(api.conversationUpdateConversation( + eq(uriPartID), + eq(ConversationDtoTest.conversation.getId()), + eq(ConversationDtoTest.conversation), + eq(null), + eq(MetadataUpdateStrategy.MERGE_PATCH))) + .thenReturn(ConversationDtoTest.conversation); + + Conversation response = + service.update( + ConversationDtoTest.conversation.getId(), + MetadataUpdateStrategy.MERGE_PATCH, + ConversationDtoTest.conversation); + + TestHelpers.recursiveEquals(response, ConversationDtoTest.conversation); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/Conversation.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/Conversation.java index 9f7f15de5..afe05840b 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/Conversation.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/Conversation.java @@ -53,21 +53,6 @@ public interface Conversation { */ String getContactId(); - /** - * The ID of the conversation. - * - * @return id - */ - String getId(); - - /** - * The timestamp of the latest message in the conversation. The timestamp will be Thursday January - * 01, 1970 00:00:00 UTC if the conversation contains no messages. - * - * @return lastReceived - */ - Instant getLastReceived(); - /** * Arbitrary data set by the Conversation API clients. Up to 1024 characters long. NOTE: This * field has been deprecated due to changes in the system architecture or functionality. It is no @@ -75,7 +60,9 @@ public interface Conversation { * field in new code. * * @return metadata + * @deprecated */ + @Deprecated String getMetadata(); /** @@ -93,6 +80,21 @@ public interface Conversation { */ String getCorrelationId(); + /** + * The ID of the conversation. + * + * @return id + */ + String getId(); + + /** + * The timestamp of the latest message in the conversation. The timestamp will be Thursday January + * 01, 1970 00:00:00 UTC if the conversation contains no messages. + * + * @return lastReceived + */ + Instant getLastReceived(); + /** * Getting builder * @@ -144,47 +146,48 @@ interface Builder { /** * see getter * - * @param id see getter + * @param metadata see getter * @return Current builder - * @see #getId + * @see #getMetadata */ - Builder setId(String id); + @Deprecated + Builder setMetadata(String metadata); /** * see getter * - * @param lastReceived see getter + * @param metadataJson see getter * @return Current builder - * @see #getLastReceived + * @see #getMetadataJson */ - Builder setLastReceived(Instant lastReceived); + Builder setMetadataJson(Object metadataJson); /** * see getter * - * @param metadata see getter + * @param correlationId see getter * @return Current builder - * @see #getMetadata + * @see #getCorrelationId */ - Builder setMetadata(String metadata); + Builder setCorrelationId(String correlationId); /** * see getter * - * @param metadataJson see getter + * @param id see getter * @return Current builder - * @see #getMetadataJson + * @see #getId */ - Builder setMetadataJson(Object metadataJson); + Builder setId(String id); /** * see getter * - * @param correlationId see getter + * @param lastReceived see getter * @return Current builder - * @see #getCorrelationId + * @see #getLastReceived */ - Builder setCorrelationId(String correlationId); + Builder setLastReceived(Instant lastReceived); /** * Create instance diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/ConversationImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/ConversationImpl.java index 858b0e80a..750bbd15d 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/ConversationImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/ConversationImpl.java @@ -16,11 +16,11 @@ ConversationImpl.JSON_PROPERTY_ACTIVE_CHANNEL, ConversationImpl.JSON_PROPERTY_APP_ID, ConversationImpl.JSON_PROPERTY_CONTACT_ID, - ConversationImpl.JSON_PROPERTY_ID, - ConversationImpl.JSON_PROPERTY_LAST_RECEIVED, ConversationImpl.JSON_PROPERTY_METADATA, ConversationImpl.JSON_PROPERTY_METADATA_JSON, - ConversationImpl.JSON_PROPERTY_CORRELATION_ID + ConversationImpl.JSON_PROPERTY_CORRELATION_ID, + ConversationImpl.JSON_PROPERTY_ID, + ConversationImpl.JSON_PROPERTY_LAST_RECEIVED }) @JsonFilter("uninitializedFilter") @JsonInclude(value = JsonInclude.Include.CUSTOM) @@ -43,14 +43,6 @@ public class ConversationImpl implements Conversation { private OptionalValue contactId; - public static final String JSON_PROPERTY_ID = "id"; - - private OptionalValue id; - - public static final String JSON_PROPERTY_LAST_RECEIVED = "last_received"; - - private OptionalValue lastReceived; - public static final String JSON_PROPERTY_METADATA = "metadata"; private OptionalValue metadata; @@ -63,6 +55,14 @@ public class ConversationImpl implements Conversation { private OptionalValue correlationId; + public static final String JSON_PROPERTY_ID = "id"; + + private OptionalValue id; + + public static final String JSON_PROPERTY_LAST_RECEIVED = "last_received"; + + private OptionalValue lastReceived; + public ConversationImpl() {} protected ConversationImpl( @@ -70,20 +70,20 @@ protected ConversationImpl( OptionalValue activeChannel, OptionalValue appId, OptionalValue contactId, - OptionalValue id, - OptionalValue lastReceived, OptionalValue metadata, OptionalValue metadataJson, - OptionalValue correlationId) { + OptionalValue correlationId, + OptionalValue id, + OptionalValue lastReceived) { this.active = active; this.activeChannel = activeChannel; this.appId = appId; this.contactId = contactId; - this.id = id; - this.lastReceived = lastReceived; this.metadata = metadata; this.metadataJson = metadataJson; this.correlationId = correlationId; + this.id = id; + this.lastReceived = lastReceived; } @JsonIgnore @@ -130,28 +130,6 @@ public OptionalValue contactId() { return contactId; } - @JsonIgnore - public String getId() { - return id.orElse(null); - } - - @JsonProperty(JSON_PROPERTY_ID) - @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public OptionalValue id() { - return id; - } - - @JsonIgnore - public Instant getLastReceived() { - return lastReceived.orElse(null); - } - - @JsonProperty(JSON_PROPERTY_LAST_RECEIVED) - @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public OptionalValue lastReceived() { - return lastReceived; - } - @JsonIgnore public String getMetadata() { return metadata.orElse(null); @@ -185,6 +163,28 @@ public OptionalValue correlationId() { return correlationId; } + @JsonIgnore + public String getId() { + return id.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_ID) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue id() { + return id; + } + + @JsonIgnore + public Instant getLastReceived() { + return lastReceived.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_LAST_RECEIVED) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue lastReceived() { + return lastReceived; + } + /** Return true if this Conversation object is equal to o. */ @Override public boolean equals(Object o) { @@ -199,11 +199,11 @@ public boolean equals(Object o) { && Objects.equals(this.activeChannel, conversation.activeChannel) && Objects.equals(this.appId, conversation.appId) && Objects.equals(this.contactId, conversation.contactId) - && Objects.equals(this.id, conversation.id) - && Objects.equals(this.lastReceived, conversation.lastReceived) && Objects.equals(this.metadata, conversation.metadata) && Objects.equals(this.metadataJson, conversation.metadataJson) - && Objects.equals(this.correlationId, conversation.correlationId); + && Objects.equals(this.correlationId, conversation.correlationId) + && Objects.equals(this.id, conversation.id) + && Objects.equals(this.lastReceived, conversation.lastReceived); } @Override @@ -213,11 +213,11 @@ public int hashCode() { activeChannel, appId, contactId, - id, - lastReceived, metadata, metadataJson, - correlationId); + correlationId, + id, + lastReceived); } @Override @@ -228,11 +228,11 @@ public String toString() { sb.append(" activeChannel: ").append(toIndentedString(activeChannel)).append("\n"); sb.append(" appId: ").append(toIndentedString(appId)).append("\n"); sb.append(" contactId: ").append(toIndentedString(contactId)).append("\n"); - sb.append(" id: ").append(toIndentedString(id)).append("\n"); - sb.append(" lastReceived: ").append(toIndentedString(lastReceived)).append("\n"); sb.append(" metadata: ").append(toIndentedString(metadata)).append("\n"); sb.append(" metadataJson: ").append(toIndentedString(metadataJson)).append("\n"); sb.append(" correlationId: ").append(toIndentedString(correlationId)).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" lastReceived: ").append(toIndentedString(lastReceived)).append("\n"); sb.append("}"); return sb.toString(); } @@ -253,11 +253,11 @@ static class Builder implements Conversation.Builder { OptionalValue activeChannel = OptionalValue.empty(); OptionalValue appId = OptionalValue.empty(); OptionalValue contactId = OptionalValue.empty(); - OptionalValue id = OptionalValue.empty(); - OptionalValue lastReceived = OptionalValue.empty(); OptionalValue metadata = OptionalValue.empty(); OptionalValue metadataJson = OptionalValue.empty(); OptionalValue correlationId = OptionalValue.empty(); + OptionalValue id = OptionalValue.empty(); + OptionalValue lastReceived = OptionalValue.empty(); @JsonProperty(JSON_PROPERTY_ACTIVE) public Builder setActive(Boolean active) { @@ -283,18 +283,6 @@ public Builder setContactId(String contactId) { return this; } - @JsonProperty(JSON_PROPERTY_ID) - public Builder setId(String id) { - this.id = OptionalValue.of(id); - return this; - } - - @JsonProperty(JSON_PROPERTY_LAST_RECEIVED) - public Builder setLastReceived(Instant lastReceived) { - this.lastReceived = OptionalValue.of(lastReceived); - return this; - } - @JsonProperty(JSON_PROPERTY_METADATA) public Builder setMetadata(String metadata) { this.metadata = OptionalValue.of(metadata); @@ -313,17 +301,29 @@ public Builder setCorrelationId(String correlationId) { return this; } + @JsonProperty(JSON_PROPERTY_ID) + public Builder setId(String id) { + this.id = OptionalValue.of(id); + return this; + } + + @JsonProperty(JSON_PROPERTY_LAST_RECEIVED) + public Builder setLastReceived(Instant lastReceived) { + this.lastReceived = OptionalValue.of(lastReceived); + return this; + } + public Conversation build() { return new ConversationImpl( active, activeChannel, appId, contactId, - id, - lastReceived, metadata, metadataJson, - correlationId); + correlationId, + id, + lastReceived); } } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ListConversationsResponse.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/internal/ListConversationsResponseInternal.java similarity index 87% rename from openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ListConversationsResponse.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/internal/ListConversationsResponseInternal.java index 451c3c7b9..fc573eacb 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ListConversationsResponse.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/internal/ListConversationsResponseInternal.java @@ -10,15 +10,15 @@ * Do not edit the class manually. */ -package com.sinch.sdk.domains.conversation.models.v1.conversation.response; +package com.sinch.sdk.domains.conversation.models.v1.conversation.internal; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.sinch.sdk.domains.conversation.models.v1.conversation.Conversation; import java.util.List; -/** ListConversationsResponse */ -@JsonDeserialize(builder = ListConversationsResponseImpl.Builder.class) -public interface ListConversationsResponse { +/** ListConversationsResponseInternal */ +@JsonDeserialize(builder = ListConversationsResponseInternalImpl.Builder.class) +public interface ListConversationsResponseInternal { /** * List of conversations matching the search query. @@ -47,7 +47,7 @@ public interface ListConversationsResponse { * @return New Builder instance */ static Builder builder() { - return new ListConversationsResponseImpl.Builder(); + return new ListConversationsResponseInternalImpl.Builder(); } /** Dedicated Builder */ @@ -85,6 +85,6 @@ interface Builder { * * @return The instance build with current builder values */ - ListConversationsResponse build(); + ListConversationsResponseInternal build(); } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ListConversationsResponseImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/internal/ListConversationsResponseInternalImpl.java similarity index 83% rename from openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ListConversationsResponseImpl.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/internal/ListConversationsResponseInternalImpl.java index 833c53a6a..4593847d8 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ListConversationsResponseImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/internal/ListConversationsResponseInternalImpl.java @@ -1,4 +1,4 @@ -package com.sinch.sdk.domains.conversation.models.v1.conversation.response; +package com.sinch.sdk.domains.conversation.models.v1.conversation.internal; import com.fasterxml.jackson.annotation.JsonFilter; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -12,13 +12,13 @@ import java.util.Objects; @JsonPropertyOrder({ - ListConversationsResponseImpl.JSON_PROPERTY_CONVERSATIONS, - ListConversationsResponseImpl.JSON_PROPERTY_NEXT_PAGE_TOKEN, - ListConversationsResponseImpl.JSON_PROPERTY_TOTAL_SIZE + ListConversationsResponseInternalImpl.JSON_PROPERTY_CONVERSATIONS, + ListConversationsResponseInternalImpl.JSON_PROPERTY_NEXT_PAGE_TOKEN, + ListConversationsResponseInternalImpl.JSON_PROPERTY_TOTAL_SIZE }) @JsonFilter("uninitializedFilter") @JsonInclude(value = JsonInclude.Include.CUSTOM) -public class ListConversationsResponseImpl implements ListConversationsResponse { +public class ListConversationsResponseInternalImpl implements ListConversationsResponseInternal { private static final long serialVersionUID = 1L; public static final String JSON_PROPERTY_CONVERSATIONS = "conversations"; @@ -33,9 +33,9 @@ public class ListConversationsResponseImpl implements ListConversationsResponse private OptionalValue totalSize; - public ListConversationsResponseImpl() {} + public ListConversationsResponseInternalImpl() {} - protected ListConversationsResponseImpl( + protected ListConversationsResponseInternalImpl( OptionalValue> conversations, OptionalValue nextPageToken, OptionalValue totalSize) { @@ -86,7 +86,8 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) { return false; } - ListConversationsResponseImpl listConversationsResponse = (ListConversationsResponseImpl) o; + ListConversationsResponseInternalImpl listConversationsResponse = + (ListConversationsResponseInternalImpl) o; return Objects.equals(this.conversations, listConversationsResponse.conversations) && Objects.equals(this.nextPageToken, listConversationsResponse.nextPageToken) && Objects.equals(this.totalSize, listConversationsResponse.totalSize); @@ -100,7 +101,7 @@ public int hashCode() { @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("class ListConversationsResponseImpl {\n"); + sb.append("class ListConversationsResponseInternalImpl {\n"); sb.append(" conversations: ").append(toIndentedString(conversations)).append("\n"); sb.append(" nextPageToken: ").append(toIndentedString(nextPageToken)).append("\n"); sb.append(" totalSize: ").append(toIndentedString(totalSize)).append("\n"); @@ -119,7 +120,7 @@ private String toIndentedString(Object o) { } @JsonPOJOBuilder(withPrefix = "set") - static class Builder implements ListConversationsResponse.Builder { + static class Builder implements ListConversationsResponseInternal.Builder { OptionalValue> conversations = OptionalValue.empty(); OptionalValue nextPageToken = OptionalValue.empty(); OptionalValue totalSize = OptionalValue.empty(); @@ -142,8 +143,8 @@ public Builder setTotalSize(Integer totalSize) { return this; } - public ListConversationsResponse build() { - return new ListConversationsResponseImpl(conversations, nextPageToken, totalSize); + public ListConversationsResponseInternal build() { + return new ListConversationsResponseInternalImpl(conversations, nextPageToken, totalSize); } } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ListRecentConversationsResponse.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/internal/ListRecentConversationsResponseInternal.java similarity index 82% rename from openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ListRecentConversationsResponse.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/internal/ListRecentConversationsResponseInternal.java index 32a7f38c2..0b53996dd 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ListRecentConversationsResponse.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/internal/ListRecentConversationsResponseInternal.java @@ -10,14 +10,15 @@ * Do not edit the class manually. */ -package com.sinch.sdk.domains.conversation.models.v1.conversation.response; +package com.sinch.sdk.domains.conversation.models.v1.conversation.internal; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.domains.conversation.models.v1.conversation.response.ConversationRecentMessage; import java.util.List; -/** ListRecentConversationsResponse */ -@JsonDeserialize(builder = ListRecentConversationsResponseImpl.Builder.class) -public interface ListRecentConversationsResponse { +/** ListRecentConversationsResponseInternal */ +@JsonDeserialize(builder = ListRecentConversationsResponseInternalImpl.Builder.class) +public interface ListRecentConversationsResponseInternal { /** * List of recent converesations @@ -46,7 +47,7 @@ public interface ListRecentConversationsResponse { * @return New Builder instance */ static Builder builder() { - return new ListRecentConversationsResponseImpl.Builder(); + return new ListRecentConversationsResponseInternalImpl.Builder(); } /** Dedicated Builder */ @@ -84,6 +85,6 @@ interface Builder { * * @return The instance build with current builder values */ - ListRecentConversationsResponse build(); + ListRecentConversationsResponseInternal build(); } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ListRecentConversationsResponseImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/internal/ListRecentConversationsResponseInternalImpl.java similarity index 81% rename from openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ListRecentConversationsResponseImpl.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/internal/ListRecentConversationsResponseInternalImpl.java index 5750ccbee..107dc2b94 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ListRecentConversationsResponseImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/internal/ListRecentConversationsResponseInternalImpl.java @@ -1,4 +1,4 @@ -package com.sinch.sdk.domains.conversation.models.v1.conversation.response; +package com.sinch.sdk.domains.conversation.models.v1.conversation.internal; import com.fasterxml.jackson.annotation.JsonFilter; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -7,17 +7,19 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.conversation.models.v1.conversation.response.ConversationRecentMessage; import java.util.List; import java.util.Objects; @JsonPropertyOrder({ - ListRecentConversationsResponseImpl.JSON_PROPERTY_CONVERSATIONS, - ListRecentConversationsResponseImpl.JSON_PROPERTY_NEXT_PAGE_TOKEN, - ListRecentConversationsResponseImpl.JSON_PROPERTY_TOTAL_SIZE + ListRecentConversationsResponseInternalImpl.JSON_PROPERTY_CONVERSATIONS, + ListRecentConversationsResponseInternalImpl.JSON_PROPERTY_NEXT_PAGE_TOKEN, + ListRecentConversationsResponseInternalImpl.JSON_PROPERTY_TOTAL_SIZE }) @JsonFilter("uninitializedFilter") @JsonInclude(value = JsonInclude.Include.CUSTOM) -public class ListRecentConversationsResponseImpl implements ListRecentConversationsResponse { +public class ListRecentConversationsResponseInternalImpl + implements ListRecentConversationsResponseInternal { private static final long serialVersionUID = 1L; public static final String JSON_PROPERTY_CONVERSATIONS = "conversations"; @@ -32,9 +34,9 @@ public class ListRecentConversationsResponseImpl implements ListRecentConversati private OptionalValue totalSize; - public ListRecentConversationsResponseImpl() {} + public ListRecentConversationsResponseInternalImpl() {} - protected ListRecentConversationsResponseImpl( + protected ListRecentConversationsResponseInternalImpl( OptionalValue> conversations, OptionalValue nextPageToken, OptionalValue totalSize) { @@ -85,8 +87,8 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) { return false; } - ListRecentConversationsResponseImpl listRecentConversationsResponse = - (ListRecentConversationsResponseImpl) o; + ListRecentConversationsResponseInternalImpl listRecentConversationsResponse = + (ListRecentConversationsResponseInternalImpl) o; return Objects.equals(this.conversations, listRecentConversationsResponse.conversations) && Objects.equals(this.nextPageToken, listRecentConversationsResponse.nextPageToken) && Objects.equals(this.totalSize, listRecentConversationsResponse.totalSize); @@ -100,7 +102,7 @@ public int hashCode() { @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("class ListRecentConversationsResponseImpl {\n"); + sb.append("class ListRecentConversationsResponseInternalImpl {\n"); sb.append(" conversations: ").append(toIndentedString(conversations)).append("\n"); sb.append(" nextPageToken: ").append(toIndentedString(nextPageToken)).append("\n"); sb.append(" totalSize: ").append(toIndentedString(totalSize)).append("\n"); @@ -119,7 +121,7 @@ private String toIndentedString(Object o) { } @JsonPOJOBuilder(withPrefix = "set") - static class Builder implements ListRecentConversationsResponse.Builder { + static class Builder implements ListRecentConversationsResponseInternal.Builder { OptionalValue> conversations = OptionalValue.empty(); OptionalValue nextPageToken = OptionalValue.empty(); OptionalValue totalSize = OptionalValue.empty(); @@ -142,8 +144,9 @@ public Builder setTotalSize(Integer totalSize) { return this; } - public ListRecentConversationsResponse build() { - return new ListRecentConversationsResponseImpl(conversations, nextPageToken, totalSize); + public ListRecentConversationsResponseInternal build() { + return new ListRecentConversationsResponseInternalImpl( + conversations, nextPageToken, totalSize); } } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/CreateConversationRequest.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/CreateConversationRequest.java index 1ea649c73..2c2d125a6 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/CreateConversationRequest.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/CreateConversationRequest.java @@ -48,17 +48,15 @@ public interface CreateConversationRequest { String getContactId(); /** - * The ID of the conversation. - * - * @return id - */ - String getId(); - - /** - * Arbitrary data set by the Conversation API clients. Up to 1024 characters long. + * Arbitrary data set by the Conversation API clients. Up to 1024 characters long. NOTE: This + * field has been deprecated due to changes in the system architecture or functionality. It is no + * longer actively maintained and may be removed in future versions. Please avoid relying on this + * field in new code. * * @return metadata + * @deprecated */ + @Deprecated String getMetadata(); /** @@ -69,6 +67,13 @@ public interface CreateConversationRequest { */ Object getMetadataJson(); + /** + * Arbitrary correlation ID related to the MT message set by the Conversation API user. + * + * @return correlationId + */ + String getCorrelationId(); + /** * Getting builder * @@ -117,15 +122,6 @@ interface Builder { */ Builder setContactId(String contactId); - /** - * see getter - * - * @param id see getter - * @return Current builder - * @see #getId - */ - Builder setId(String id); - /** * see getter * @@ -133,6 +129,7 @@ interface Builder { * @return Current builder * @see #getMetadata */ + @Deprecated Builder setMetadata(String metadata); /** @@ -144,6 +141,15 @@ interface Builder { */ Builder setMetadataJson(Object metadataJson); + /** + * see getter + * + * @param correlationId see getter + * @return Current builder + * @see #getCorrelationId + */ + Builder setCorrelationId(String correlationId); + /** * Create instance * diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/CreateConversationRequestImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/CreateConversationRequestImpl.java index 00dcd50cf..2d9e4ddae 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/CreateConversationRequestImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/CreateConversationRequestImpl.java @@ -15,9 +15,9 @@ CreateConversationRequestImpl.JSON_PROPERTY_ACTIVE_CHANNEL, CreateConversationRequestImpl.JSON_PROPERTY_APP_ID, CreateConversationRequestImpl.JSON_PROPERTY_CONTACT_ID, - CreateConversationRequestImpl.JSON_PROPERTY_ID, CreateConversationRequestImpl.JSON_PROPERTY_METADATA, - CreateConversationRequestImpl.JSON_PROPERTY_METADATA_JSON + CreateConversationRequestImpl.JSON_PROPERTY_METADATA_JSON, + CreateConversationRequestImpl.JSON_PROPERTY_CORRELATION_ID }) @JsonFilter("uninitializedFilter") @JsonInclude(value = JsonInclude.Include.CUSTOM) @@ -40,10 +40,6 @@ public class CreateConversationRequestImpl implements CreateConversationRequest private OptionalValue contactId; - public static final String JSON_PROPERTY_ID = "id"; - - private OptionalValue id; - public static final String JSON_PROPERTY_METADATA = "metadata"; private OptionalValue metadata; @@ -52,6 +48,10 @@ public class CreateConversationRequestImpl implements CreateConversationRequest private OptionalValue metadataJson; + public static final String JSON_PROPERTY_CORRELATION_ID = "correlation_id"; + + private OptionalValue correlationId; + public CreateConversationRequestImpl() {} protected CreateConversationRequestImpl( @@ -59,16 +59,16 @@ protected CreateConversationRequestImpl( OptionalValue activeChannel, OptionalValue appId, OptionalValue contactId, - OptionalValue id, OptionalValue metadata, - OptionalValue metadataJson) { + OptionalValue metadataJson, + OptionalValue correlationId) { this.active = active; this.activeChannel = activeChannel; this.appId = appId; this.contactId = contactId; - this.id = id; this.metadata = metadata; this.metadataJson = metadataJson; + this.correlationId = correlationId; } @JsonIgnore @@ -115,17 +115,6 @@ public OptionalValue contactId() { return contactId; } - @JsonIgnore - public String getId() { - return id.orElse(null); - } - - @JsonProperty(JSON_PROPERTY_ID) - @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public OptionalValue id() { - return id; - } - @JsonIgnore public String getMetadata() { return metadata.orElse(null); @@ -148,6 +137,17 @@ public OptionalValue metadataJson() { return metadataJson; } + @JsonIgnore + public String getCorrelationId() { + return correlationId.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CORRELATION_ID) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue correlationId() { + return correlationId; + } + /** Return true if this CreateConversationRequest object is equal to o. */ @Override public boolean equals(Object o) { @@ -162,14 +162,15 @@ public boolean equals(Object o) { && Objects.equals(this.activeChannel, createConversationRequest.activeChannel) && Objects.equals(this.appId, createConversationRequest.appId) && Objects.equals(this.contactId, createConversationRequest.contactId) - && Objects.equals(this.id, createConversationRequest.id) && Objects.equals(this.metadata, createConversationRequest.metadata) - && Objects.equals(this.metadataJson, createConversationRequest.metadataJson); + && Objects.equals(this.metadataJson, createConversationRequest.metadataJson) + && Objects.equals(this.correlationId, createConversationRequest.correlationId); } @Override public int hashCode() { - return Objects.hash(active, activeChannel, appId, contactId, id, metadata, metadataJson); + return Objects.hash( + active, activeChannel, appId, contactId, metadata, metadataJson, correlationId); } @Override @@ -180,9 +181,9 @@ public String toString() { sb.append(" activeChannel: ").append(toIndentedString(activeChannel)).append("\n"); sb.append(" appId: ").append(toIndentedString(appId)).append("\n"); sb.append(" contactId: ").append(toIndentedString(contactId)).append("\n"); - sb.append(" id: ").append(toIndentedString(id)).append("\n"); sb.append(" metadata: ").append(toIndentedString(metadata)).append("\n"); sb.append(" metadataJson: ").append(toIndentedString(metadataJson)).append("\n"); + sb.append(" correlationId: ").append(toIndentedString(correlationId)).append("\n"); sb.append("}"); return sb.toString(); } @@ -203,9 +204,9 @@ static class Builder implements CreateConversationRequest.Builder { OptionalValue activeChannel = OptionalValue.empty(); OptionalValue appId = OptionalValue.empty(); OptionalValue contactId = OptionalValue.empty(); - OptionalValue id = OptionalValue.empty(); OptionalValue metadata = OptionalValue.empty(); OptionalValue metadataJson = OptionalValue.empty(); + OptionalValue correlationId = OptionalValue.empty(); @JsonProperty(JSON_PROPERTY_ACTIVE) public Builder setActive(Boolean active) { @@ -231,12 +232,6 @@ public Builder setContactId(String contactId) { return this; } - @JsonProperty(JSON_PROPERTY_ID) - public Builder setId(String id) { - this.id = OptionalValue.of(id); - return this; - } - @JsonProperty(JSON_PROPERTY_METADATA) public Builder setMetadata(String metadata) { this.metadata = OptionalValue.of(metadata); @@ -249,9 +244,15 @@ public Builder setMetadataJson(Object metadataJson) { return this; } + @JsonProperty(JSON_PROPERTY_CORRELATION_ID) + public Builder setCorrelationId(String correlationId) { + this.correlationId = OptionalValue.of(correlationId); + return this; + } + public CreateConversationRequest build() { return new CreateConversationRequestImpl( - active, activeChannel, appId, contactId, id, metadata, metadataJson); + active, activeChannel, appId, contactId, metadata, metadataJson, correlationId); } } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ConversationRecentMessage.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ConversationRecentMessage.java index e88744ad3..068145676 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ConversationRecentMessage.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ConversationRecentMessage.java @@ -14,7 +14,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.sinch.sdk.domains.conversation.models.v1.conversation.Conversation; -import com.sinch.sdk.domains.conversation.models.v1.internal.ConversationMessageInternal; +import com.sinch.sdk.domains.conversation.models.v1.messages.ConversationMessage; /** ConversationRecentMessage */ @JsonDeserialize(builder = ConversationRecentMessageImpl.Builder.class) @@ -32,7 +32,7 @@ public interface ConversationRecentMessage { * * @return lastMessage */ - ConversationMessageInternal getLastMessage(); + ConversationMessage getLastMessage(); /** * Getting builder @@ -62,7 +62,7 @@ interface Builder { * @return Current builder * @see #getLastMessage */ - Builder setLastMessage(ConversationMessageInternal lastMessage); + Builder setLastMessage(ConversationMessage lastMessage); /** * Create instance diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ConversationRecentMessageImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ConversationRecentMessageImpl.java index c1c793211..e4ac4bc8b 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ConversationRecentMessageImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/response/ConversationRecentMessageImpl.java @@ -8,7 +8,7 @@ import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.sinch.sdk.core.models.OptionalValue; import com.sinch.sdk.domains.conversation.models.v1.conversation.Conversation; -import com.sinch.sdk.domains.conversation.models.v1.internal.ConversationMessageInternal; +import com.sinch.sdk.domains.conversation.models.v1.messages.ConversationMessage; import java.util.Objects; @JsonPropertyOrder({ @@ -26,13 +26,12 @@ public class ConversationRecentMessageImpl implements ConversationRecentMessage public static final String JSON_PROPERTY_LAST_MESSAGE = "last_message"; - private OptionalValue lastMessage; + private OptionalValue lastMessage; public ConversationRecentMessageImpl() {} protected ConversationRecentMessageImpl( - OptionalValue conversation, - OptionalValue lastMessage) { + OptionalValue conversation, OptionalValue lastMessage) { this.conversation = conversation; this.lastMessage = lastMessage; } @@ -49,13 +48,13 @@ public OptionalValue conversation() { } @JsonIgnore - public ConversationMessageInternal getLastMessage() { + public ConversationMessage getLastMessage() { return lastMessage.orElse(null); } @JsonProperty(JSON_PROPERTY_LAST_MESSAGE) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public OptionalValue lastMessage() { + public OptionalValue lastMessage() { return lastMessage; } @@ -101,7 +100,7 @@ private String toIndentedString(Object o) { @JsonPOJOBuilder(withPrefix = "set") static class Builder implements ConversationRecentMessage.Builder { OptionalValue conversation = OptionalValue.empty(); - OptionalValue lastMessage = OptionalValue.empty(); + OptionalValue lastMessage = OptionalValue.empty(); @JsonProperty(JSON_PROPERTY_CONVERSATION) public Builder setConversation(Conversation conversation) { @@ -110,7 +109,7 @@ public Builder setConversation(Conversation conversation) { } @JsonProperty(JSON_PROPERTY_LAST_MESSAGE) - public Builder setLastMessage(ConversationMessageInternal lastMessage) { + public Builder setLastMessage(ConversationMessage lastMessage) { this.lastMessage = OptionalValue.of(lastMessage); return this; } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/events/ConversationEvent.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/events/ConversationEvent.java index a54e42fe0..a2e6a9836 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/events/ConversationEvent.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/events/ConversationEvent.java @@ -29,20 +29,6 @@ public interface ConversationEvent { */ AppEvent getAppEvent(); - /** - * Get direction - * - * @return direction - */ - ConversationDirection getDirection(); - - /** - * The ID of the event. - * - * @return id - */ - String getId(); - /** * Optional. The ID of the event's conversation. Will not be present for apps in Dispatch Mode. * @@ -65,7 +51,8 @@ public interface ConversationEvent { ChannelIdentity getChannelIdentity(); /** - * Get acceptTime + * The processed time of the message in UTC timezone. Must be less than current_time and greater + * than (current_time - 30 days). * * @return acceptTime */ @@ -78,6 +65,20 @@ public interface ConversationEvent { */ ProcessingMode getProcessingMode(); + /** + * Get direction + * + * @return direction + */ + ConversationDirection getDirection(); + + /** + * The ID of the event. + * + * @return id + */ + String getId(); + /** * Getting builder * @@ -99,24 +100,6 @@ interface Builder { */ Builder setAppEvent(AppEvent appEvent); - /** - * see getter - * - * @param direction see getter - * @return Current builder - * @see #getDirection - */ - Builder setDirection(ConversationDirection direction); - - /** - * see getter - * - * @param id see getter - * @return Current builder - * @see #getId - */ - Builder setId(String id); - /** * see getter * @@ -162,6 +145,24 @@ interface Builder { */ Builder setProcessingMode(ProcessingMode processingMode); + /** + * see getter + * + * @param direction see getter + * @return Current builder + * @see #getDirection + */ + Builder setDirection(ConversationDirection direction); + + /** + * see getter + * + * @param id see getter + * @return Current builder + * @see #getId + */ + Builder setId(String id); + /** * Create instance * diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/events/ConversationEventBase.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/events/ConversationEventBase.java new file mode 100644 index 000000000..0b2ec2bde --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/events/ConversationEventBase.java @@ -0,0 +1,141 @@ +/* + * Conversation API | Sinch + * Send and receive messages globally over SMS, RCS, WhatsApp, Viber Business, Facebook messenger and other popular channels using the Sinch Conversation API. The Conversation API endpoint uses built-in transcoding to give you the power of conversation across all supported channels and, if required, full control over channel specific features. + * + * The version of the OpenAPI document: 1.0 + * Contact: support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.conversation.models.v1.events; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.domains.conversation.models.v1.ChannelIdentity; +import com.sinch.sdk.domains.conversation.models.v1.ProcessingMode; +import com.sinch.sdk.domains.conversation.models.v1.events.internal.AppEventInternal; +import java.time.Instant; + +/** Common properties to ConversationEvent management */ +@JsonDeserialize(builder = ConversationEventBaseImpl.Builder.class) +public interface ConversationEventBase { + + /** + * Get appEvent + * + * @return appEvent + */ + AppEventInternal getAppEvent(); + + /** + * Optional. The ID of the event's conversation. Will not be present for apps in Dispatch Mode. + * + * @return conversationId + */ + String getConversationId(); + + /** + * Optional. The ID of the contact. Will not be present for apps in Dispatch Mode. + * + * @return contactId + */ + String getContactId(); + + /** + * Get channelIdentity + * + * @return channelIdentity + */ + ChannelIdentity getChannelIdentity(); + + /** + * The processed time of the message in UTC timezone. Must be less than current_time and greater + * than (current_time - 30 days). + * + * @return acceptTime + */ + Instant getAcceptTime(); + + /** + * Get processingMode + * + * @return processingMode + */ + ProcessingMode getProcessingMode(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new ConversationEventBaseImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param appEvent see getter + * @return Current builder + * @see #getAppEvent + */ + Builder setAppEvent(AppEventInternal appEvent); + + /** + * see getter + * + * @param conversationId see getter + * @return Current builder + * @see #getConversationId + */ + Builder setConversationId(String conversationId); + + /** + * see getter + * + * @param contactId see getter + * @return Current builder + * @see #getContactId + */ + Builder setContactId(String contactId); + + /** + * see getter + * + * @param channelIdentity see getter + * @return Current builder + * @see #getChannelIdentity + */ + Builder setChannelIdentity(ChannelIdentity channelIdentity); + + /** + * see getter + * + * @param acceptTime see getter + * @return Current builder + * @see #getAcceptTime + */ + Builder setAcceptTime(Instant acceptTime); + + /** + * see getter + * + * @param processingMode see getter + * @return Current builder + * @see #getProcessingMode + */ + Builder setProcessingMode(ProcessingMode processingMode); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + ConversationEventBase build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/events/ConversationEventBaseImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/events/ConversationEventBaseImpl.java new file mode 100644 index 000000000..0c73dbba6 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/events/ConversationEventBaseImpl.java @@ -0,0 +1,234 @@ +package com.sinch.sdk.domains.conversation.models.v1.events; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.conversation.models.v1.ChannelIdentity; +import com.sinch.sdk.domains.conversation.models.v1.ProcessingMode; +import com.sinch.sdk.domains.conversation.models.v1.events.internal.AppEventInternal; +import java.time.Instant; +import java.util.Objects; + +@JsonPropertyOrder({ + ConversationEventBaseImpl.JSON_PROPERTY_APP_EVENT, + ConversationEventBaseImpl.JSON_PROPERTY_CONVERSATION_ID, + ConversationEventBaseImpl.JSON_PROPERTY_CONTACT_ID, + ConversationEventBaseImpl.JSON_PROPERTY_CHANNEL_IDENTITY, + ConversationEventBaseImpl.JSON_PROPERTY_ACCEPT_TIME, + ConversationEventBaseImpl.JSON_PROPERTY_PROCESSING_MODE +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class ConversationEventBaseImpl implements ConversationEventBase { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_APP_EVENT = "app_event"; + + private OptionalValue appEvent; + + public static final String JSON_PROPERTY_CONVERSATION_ID = "conversation_id"; + + private OptionalValue conversationId; + + public static final String JSON_PROPERTY_CONTACT_ID = "contact_id"; + + private OptionalValue contactId; + + public static final String JSON_PROPERTY_CHANNEL_IDENTITY = "channel_identity"; + + private OptionalValue channelIdentity; + + public static final String JSON_PROPERTY_ACCEPT_TIME = "accept_time"; + + private OptionalValue acceptTime; + + public static final String JSON_PROPERTY_PROCESSING_MODE = "processing_mode"; + + private OptionalValue processingMode; + + public ConversationEventBaseImpl() {} + + protected ConversationEventBaseImpl( + OptionalValue appEvent, + OptionalValue conversationId, + OptionalValue contactId, + OptionalValue channelIdentity, + OptionalValue acceptTime, + OptionalValue processingMode) { + this.appEvent = appEvent; + this.conversationId = conversationId; + this.contactId = contactId; + this.channelIdentity = channelIdentity; + this.acceptTime = acceptTime; + this.processingMode = processingMode; + } + + @JsonIgnore + public AppEventInternal getAppEvent() { + return appEvent.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_APP_EVENT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue appEvent() { + return appEvent; + } + + @JsonIgnore + public String getConversationId() { + return conversationId.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CONVERSATION_ID) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue conversationId() { + return conversationId; + } + + @JsonIgnore + public String getContactId() { + return contactId.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CONTACT_ID) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue contactId() { + return contactId; + } + + @JsonIgnore + public ChannelIdentity getChannelIdentity() { + return channelIdentity.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CHANNEL_IDENTITY) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue channelIdentity() { + return channelIdentity; + } + + @JsonIgnore + public Instant getAcceptTime() { + return acceptTime.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_ACCEPT_TIME) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue acceptTime() { + return acceptTime; + } + + @JsonIgnore + public ProcessingMode getProcessingMode() { + return processingMode.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_PROCESSING_MODE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue processingMode() { + return processingMode; + } + + /** Return true if this ConversationEventBase object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ConversationEventBaseImpl conversationEventBase = (ConversationEventBaseImpl) o; + return Objects.equals(this.appEvent, conversationEventBase.appEvent) + && Objects.equals(this.conversationId, conversationEventBase.conversationId) + && Objects.equals(this.contactId, conversationEventBase.contactId) + && Objects.equals(this.channelIdentity, conversationEventBase.channelIdentity) + && Objects.equals(this.acceptTime, conversationEventBase.acceptTime) + && Objects.equals(this.processingMode, conversationEventBase.processingMode); + } + + @Override + public int hashCode() { + return Objects.hash( + appEvent, conversationId, contactId, channelIdentity, acceptTime, processingMode); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ConversationEventBaseImpl {\n"); + sb.append(" appEvent: ").append(toIndentedString(appEvent)).append("\n"); + sb.append(" conversationId: ").append(toIndentedString(conversationId)).append("\n"); + sb.append(" contactId: ").append(toIndentedString(contactId)).append("\n"); + sb.append(" channelIdentity: ").append(toIndentedString(channelIdentity)).append("\n"); + sb.append(" acceptTime: ").append(toIndentedString(acceptTime)).append("\n"); + sb.append(" processingMode: ").append(toIndentedString(processingMode)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements ConversationEventBase.Builder { + OptionalValue appEvent = OptionalValue.empty(); + OptionalValue conversationId = OptionalValue.empty(); + OptionalValue contactId = OptionalValue.empty(); + OptionalValue channelIdentity = OptionalValue.empty(); + OptionalValue acceptTime = OptionalValue.empty(); + OptionalValue processingMode = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_APP_EVENT) + public Builder setAppEvent(AppEventInternal appEvent) { + this.appEvent = OptionalValue.of(appEvent); + return this; + } + + @JsonProperty(JSON_PROPERTY_CONVERSATION_ID) + public Builder setConversationId(String conversationId) { + this.conversationId = OptionalValue.of(conversationId); + return this; + } + + @JsonProperty(JSON_PROPERTY_CONTACT_ID) + public Builder setContactId(String contactId) { + this.contactId = OptionalValue.of(contactId); + return this; + } + + @JsonProperty(JSON_PROPERTY_CHANNEL_IDENTITY) + public Builder setChannelIdentity(ChannelIdentity channelIdentity) { + this.channelIdentity = OptionalValue.of(channelIdentity); + return this; + } + + @JsonProperty(JSON_PROPERTY_ACCEPT_TIME) + public Builder setAcceptTime(Instant acceptTime) { + this.acceptTime = OptionalValue.of(acceptTime); + return this; + } + + @JsonProperty(JSON_PROPERTY_PROCESSING_MODE) + public Builder setProcessingMode(ProcessingMode processingMode) { + this.processingMode = OptionalValue.of(processingMode); + return this; + } + + public ConversationEventBase build() { + return new ConversationEventBaseImpl( + appEvent, conversationId, contactId, channelIdentity, acceptTime, processingMode); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/events/ConversationEventImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/events/ConversationEventImpl.java index 9a25c771b..c78579d27 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/events/ConversationEventImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/events/ConversationEventImpl.java @@ -15,13 +15,13 @@ @JsonPropertyOrder({ ConversationEventImpl.JSON_PROPERTY_APP_EVENT, - ConversationEventImpl.JSON_PROPERTY_DIRECTION, - ConversationEventImpl.JSON_PROPERTY_ID, ConversationEventImpl.JSON_PROPERTY_CONVERSATION_ID, ConversationEventImpl.JSON_PROPERTY_CONTACT_ID, ConversationEventImpl.JSON_PROPERTY_CHANNEL_IDENTITY, ConversationEventImpl.JSON_PROPERTY_ACCEPT_TIME, - ConversationEventImpl.JSON_PROPERTY_PROCESSING_MODE + ConversationEventImpl.JSON_PROPERTY_PROCESSING_MODE, + ConversationEventImpl.JSON_PROPERTY_DIRECTION, + ConversationEventImpl.JSON_PROPERTY_ID }) @JsonFilter("uninitializedFilter") @JsonInclude(value = JsonInclude.Include.CUSTOM) @@ -32,14 +32,6 @@ public class ConversationEventImpl implements ConversationEvent { private OptionalValue appEvent; - public static final String JSON_PROPERTY_DIRECTION = "direction"; - - private OptionalValue direction; - - public static final String JSON_PROPERTY_ID = "id"; - - private OptionalValue id; - public static final String JSON_PROPERTY_CONVERSATION_ID = "conversation_id"; private OptionalValue conversationId; @@ -60,25 +52,33 @@ public class ConversationEventImpl implements ConversationEvent { private OptionalValue processingMode; + public static final String JSON_PROPERTY_DIRECTION = "direction"; + + private OptionalValue direction; + + public static final String JSON_PROPERTY_ID = "id"; + + private OptionalValue id; + public ConversationEventImpl() {} protected ConversationEventImpl( OptionalValue appEvent, - OptionalValue direction, - OptionalValue id, OptionalValue conversationId, OptionalValue contactId, OptionalValue channelIdentity, OptionalValue acceptTime, - OptionalValue processingMode) { + OptionalValue processingMode, + OptionalValue direction, + OptionalValue id) { this.appEvent = appEvent; - this.direction = direction; - this.id = id; this.conversationId = conversationId; this.contactId = contactId; this.channelIdentity = channelIdentity; this.acceptTime = acceptTime; this.processingMode = processingMode; + this.direction = direction; + this.id = id; } @JsonIgnore @@ -92,28 +92,6 @@ public OptionalValue appEvent() { return appEvent; } - @JsonIgnore - public ConversationDirection getDirection() { - return direction.orElse(null); - } - - @JsonProperty(JSON_PROPERTY_DIRECTION) - @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public OptionalValue direction() { - return direction; - } - - @JsonIgnore - public String getId() { - return id.orElse(null); - } - - @JsonProperty(JSON_PROPERTY_ID) - @JsonInclude(value = JsonInclude.Include.ALWAYS) - public OptionalValue id() { - return id; - } - @JsonIgnore public String getConversationId() { return conversationId.orElse(null); @@ -169,6 +147,28 @@ public OptionalValue processingMode() { return processingMode; } + @JsonIgnore + public ConversationDirection getDirection() { + return direction.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_DIRECTION) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue direction() { + return direction; + } + + @JsonIgnore + public String getId() { + return id.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_ID) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue id() { + return id; + } + /** Return true if this ConversationEvent object is equal to o. */ @Override public boolean equals(Object o) { @@ -180,26 +180,26 @@ public boolean equals(Object o) { } ConversationEventImpl conversationEvent = (ConversationEventImpl) o; return Objects.equals(this.appEvent, conversationEvent.appEvent) - && Objects.equals(this.direction, conversationEvent.direction) - && Objects.equals(this.id, conversationEvent.id) && Objects.equals(this.conversationId, conversationEvent.conversationId) && Objects.equals(this.contactId, conversationEvent.contactId) && Objects.equals(this.channelIdentity, conversationEvent.channelIdentity) && Objects.equals(this.acceptTime, conversationEvent.acceptTime) - && Objects.equals(this.processingMode, conversationEvent.processingMode); + && Objects.equals(this.processingMode, conversationEvent.processingMode) + && Objects.equals(this.direction, conversationEvent.direction) + && Objects.equals(this.id, conversationEvent.id); } @Override public int hashCode() { return Objects.hash( appEvent, - direction, - id, conversationId, contactId, channelIdentity, acceptTime, - processingMode); + processingMode, + direction, + id); } @Override @@ -207,13 +207,13 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class ConversationEventImpl {\n"); sb.append(" appEvent: ").append(toIndentedString(appEvent)).append("\n"); - sb.append(" direction: ").append(toIndentedString(direction)).append("\n"); - sb.append(" id: ").append(toIndentedString(id)).append("\n"); sb.append(" conversationId: ").append(toIndentedString(conversationId)).append("\n"); sb.append(" contactId: ").append(toIndentedString(contactId)).append("\n"); sb.append(" channelIdentity: ").append(toIndentedString(channelIdentity)).append("\n"); sb.append(" acceptTime: ").append(toIndentedString(acceptTime)).append("\n"); sb.append(" processingMode: ").append(toIndentedString(processingMode)).append("\n"); + sb.append(" direction: ").append(toIndentedString(direction)).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); sb.append("}"); return sb.toString(); } @@ -231,13 +231,13 @@ private String toIndentedString(Object o) { @JsonPOJOBuilder(withPrefix = "set") static class Builder implements ConversationEvent.Builder { OptionalValue appEvent = OptionalValue.empty(); - OptionalValue direction = OptionalValue.empty(); - OptionalValue id = OptionalValue.empty(); OptionalValue conversationId = OptionalValue.empty(); OptionalValue contactId = OptionalValue.empty(); OptionalValue channelIdentity = OptionalValue.empty(); OptionalValue acceptTime = OptionalValue.empty(); OptionalValue processingMode = OptionalValue.empty(); + OptionalValue direction = OptionalValue.empty(); + OptionalValue id = OptionalValue.empty(); @JsonProperty(JSON_PROPERTY_APP_EVENT) public Builder setAppEvent(AppEvent appEvent) { @@ -245,18 +245,6 @@ public Builder setAppEvent(AppEvent appEvent) { return this; } - @JsonProperty(JSON_PROPERTY_DIRECTION) - public Builder setDirection(ConversationDirection direction) { - this.direction = OptionalValue.of(direction); - return this; - } - - @JsonProperty(JSON_PROPERTY_ID) - public Builder setId(String id) { - this.id = OptionalValue.of(id); - return this; - } - @JsonProperty(JSON_PROPERTY_CONVERSATION_ID) public Builder setConversationId(String conversationId) { this.conversationId = OptionalValue.of(conversationId); @@ -287,16 +275,28 @@ public Builder setProcessingMode(ProcessingMode processingMode) { return this; } + @JsonProperty(JSON_PROPERTY_DIRECTION) + public Builder setDirection(ConversationDirection direction) { + this.direction = OptionalValue.of(direction); + return this; + } + + @JsonProperty(JSON_PROPERTY_ID) + public Builder setId(String id) { + this.id = OptionalValue.of(id); + return this; + } + public ConversationEvent build() { return new ConversationEventImpl( appEvent, - direction, - id, conversationId, contactId, channelIdentity, acceptTime, - processingMode); + processingMode, + direction, + id); } } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/request/SendMessageRequest.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/request/SendMessageRequest.java index 8ac41b6c2..462e37ef4 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/request/SendMessageRequest.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/request/SendMessageRequest.java @@ -17,6 +17,7 @@ import com.sinch.sdk.domains.conversation.models.v1.Recipient; import com.sinch.sdk.domains.conversation.models.v1.messages.AppMessage; import com.sinch.sdk.domains.conversation.models.v1.messages.AppMessageBody; +import com.sinch.sdk.domains.conversation.models.v1.request.MetadataUpdateStrategy; import java.util.List; import java.util.Map; diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/request/SendMessageRequestImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/request/SendMessageRequestImpl.java index 1de198984..ae0ad306d 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/request/SendMessageRequestImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/request/SendMessageRequestImpl.java @@ -11,6 +11,7 @@ import com.sinch.sdk.domains.conversation.models.v1.Recipient; import com.sinch.sdk.domains.conversation.models.v1.messages.AppMessage; import com.sinch.sdk.domains.conversation.models.v1.messages.AppMessageBody; +import com.sinch.sdk.domains.conversation.models.v1.request.MetadataUpdateStrategy; import java.util.List; import java.util.Map; import java.util.Objects; diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/request/MetadataUpdateStrategy.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/request/MetadataUpdateStrategy.java similarity index 95% rename from openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/request/MetadataUpdateStrategy.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/request/MetadataUpdateStrategy.java index 069735dad..01382975c 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/request/MetadataUpdateStrategy.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/request/MetadataUpdateStrategy.java @@ -1,4 +1,4 @@ -package com.sinch.sdk.domains.conversation.models.v1.messages.request; +package com.sinch.sdk.domains.conversation.models.v1.request; import com.sinch.sdk.core.utils.EnumDynamic; import com.sinch.sdk.core.utils.EnumSupportDynamic; diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/conversation/ConversationDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/conversations/ConversationDtoTest.java similarity index 56% rename from openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/conversation/ConversationDtoTest.java rename to openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/conversations/ConversationDtoTest.java index be1e53dcf..27b0507af 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/conversation/ConversationDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/conversations/ConversationDtoTest.java @@ -1,19 +1,23 @@ -package com.sinch.sdk.domains.conversation.models.v1.conversation; +package com.sinch.sdk.domains.conversation.models.v1.conversations; -import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.fasterxml.jackson.core.JsonProcessingException; import com.sinch.sdk.core.TestHelpers; import com.sinch.sdk.domains.conversation.api.v1.adapters.ConversationBaseTest; import com.sinch.sdk.domains.conversation.models.v1.ConversationChannel; +import com.sinch.sdk.domains.conversation.models.v1.conversation.Conversation; import java.time.Instant; import java.util.Collections; +import org.json.JSONException; import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; @TestWithResources public class ConversationDtoTest extends ConversationBaseTest { - @GivenJsonResource("domains/conversation/v1/conversation/ConversationDto.json") - Conversation dto; + @GivenTextResource("domains/conversation/v1/conversations/ConversationDto.json") + String jsonConversation; public static Conversation conversation = Conversation.builder() @@ -29,7 +33,16 @@ public class ConversationDtoTest extends ConversationBaseTest { .build(); @Test - void deserialize() { - TestHelpers.recursiveEquals(dto, conversation); + void serialize() throws JsonProcessingException, JSONException { + String serializedString = objectMapper.writeValueAsString(conversation); + + JSONAssert.assertEquals(jsonConversation, serializedString, true); + } + + @Test + void deserialize() throws JsonProcessingException { + Object deserialized = objectMapper.readValue(jsonConversation, Conversation.class); + + TestHelpers.recursiveEquals(deserialized, conversation); } } diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/conversations/request/CreateConversationRequestTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/conversations/request/CreateConversationRequestTest.java new file mode 100644 index 000000000..ddf9b00a9 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/conversations/request/CreateConversationRequestTest.java @@ -0,0 +1,39 @@ +package com.sinch.sdk.domains.conversation.models.v1.conversations.request; + +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.sinch.sdk.domains.conversation.api.v1.adapters.ConversationBaseTest; +import com.sinch.sdk.domains.conversation.models.v1.ConversationChannel; +import com.sinch.sdk.domains.conversation.models.v1.conversation.request.CreateConversationRequest; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.text.TextMessage; +import java.util.Collections; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +@TestWithResources +public class CreateConversationRequestTest extends ConversationBaseTest { + + public static CreateConversationRequest createConversationRequestDto = + CreateConversationRequest.builder() + .setActive(true) + .setActiveChannel(ConversationChannel.WHATSAPP) + .setAppId("conversation app Id") + .setContactId("contact ID") + .setMetadata("metadata value") + .setMetadataJson(Collections.singletonMap("metadata_json_key", "metadata json value")) + .setCorrelationId("correlation id value") + .build(); + + @GivenTextResource( + "/domains/conversation/v1/conversations/request/CreateConversationRequestDto.json") + static String jsonCreateConversationRequestDto; + + @Test + void serialize() throws JsonProcessingException, JSONException { + String serializedString = objectMapper.writeValueAsString(createConversationRequestDto); + + JSONAssert.assertEquals(jsonCreateConversationRequestDto, serializedString, true); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/conversations/response/ConversationRecentMessageDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/conversations/response/ConversationRecentMessageDtoTest.java new file mode 100644 index 000000000..cf2c01fcf --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/conversations/response/ConversationRecentMessageDtoTest.java @@ -0,0 +1,42 @@ +package com.sinch.sdk.domains.conversation.models.v1.conversations.response; + +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.domains.conversation.api.v1.adapters.ConversationBaseTest; +import com.sinch.sdk.domains.conversation.models.v1.conversation.response.ConversationRecentMessage; +import com.sinch.sdk.domains.conversation.models.v1.conversations.ConversationDtoTest; +import com.sinch.sdk.domains.conversation.models.v1.messages.ConversationMessageDtoTest; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +@TestWithResources +public class ConversationRecentMessageDtoTest extends ConversationBaseTest { + + @GivenTextResource( + "domains/conversation/v1/conversations/response/ConversationRecentMessageDto.json") + String jsonConversationRecentMessageDto; + + public static ConversationRecentMessage conversationRecentMessage = + ConversationRecentMessage.builder() + .setConversation(ConversationDtoTest.conversation) + .setLastMessage(ConversationMessageDtoTest.contactConversationMessage) + .build(); + + @Test + void serialize() throws JsonProcessingException, JSONException { + String serializedString = objectMapper.writeValueAsString(conversationRecentMessage); + + JSONAssert.assertEquals(jsonConversationRecentMessageDto, serializedString, true); + } + + @Test + void deserialize() throws JsonProcessingException { + Object deserialized = + objectMapper.readValue(jsonConversationRecentMessageDto, ConversationRecentMessage.class); + + TestHelpers.recursiveEquals(deserialized, conversationRecentMessage); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/messages/request/SendMessageDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/messages/request/SendMessageDtoTest.java index 5118750e0..7285967c3 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/messages/request/SendMessageDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/messages/request/SendMessageDtoTest.java @@ -17,6 +17,7 @@ import com.sinch.sdk.domains.conversation.models.v1.messages.types.media.MediaMessage; import com.sinch.sdk.domains.conversation.models.v1.messages.types.template.TemplateMessage; import com.sinch.sdk.domains.conversation.models.v1.messages.types.text.TextMessage; +import com.sinch.sdk.domains.conversation.models.v1.request.MetadataUpdateStrategy; import java.util.Collections; import java.util.HashMap; import java.util.Map; diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/webhooks/events/conversation/ConversationDeleteEventDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/webhooks/events/conversation/ConversationDeleteEventDtoTest.java index d5ec54c84..2a05471fa 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/webhooks/events/conversation/ConversationDeleteEventDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/webhooks/events/conversation/ConversationDeleteEventDtoTest.java @@ -4,7 +4,7 @@ import com.adelean.inject.resources.junit.jupiter.TestWithResources; import com.sinch.sdk.core.TestHelpers; import com.sinch.sdk.domains.conversation.api.v1.adapters.ConversationBaseTest; -import com.sinch.sdk.domains.conversation.models.v1.conversation.ConversationDtoTest; +import com.sinch.sdk.domains.conversation.models.v1.conversations.ConversationDtoTest; import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.internal.ConversationEventInternal; import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.internal.ConversationEventInternalImpl; import java.time.Instant; diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/webhooks/events/conversation/ConversationStartEventDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/webhooks/events/conversation/ConversationStartEventDtoTest.java index 9f9800d0f..a8e84bb01 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/webhooks/events/conversation/ConversationStartEventDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/webhooks/events/conversation/ConversationStartEventDtoTest.java @@ -4,7 +4,7 @@ import com.adelean.inject.resources.junit.jupiter.TestWithResources; import com.sinch.sdk.core.TestHelpers; import com.sinch.sdk.domains.conversation.api.v1.adapters.ConversationBaseTest; -import com.sinch.sdk.domains.conversation.models.v1.conversation.ConversationDtoTest; +import com.sinch.sdk.domains.conversation.models.v1.conversations.ConversationDtoTest; import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.internal.ConversationEventInternal; import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.internal.ConversationEventInternalImpl; import java.time.Instant; diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/webhooks/events/conversation/ConversationStopEventDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/webhooks/events/conversation/ConversationStopEventDtoTest.java index 45724095e..1f38208f3 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/webhooks/events/conversation/ConversationStopEventDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/webhooks/events/conversation/ConversationStopEventDtoTest.java @@ -4,7 +4,7 @@ import com.adelean.inject.resources.junit.jupiter.TestWithResources; import com.sinch.sdk.core.TestHelpers; import com.sinch.sdk.domains.conversation.api.v1.adapters.ConversationBaseTest; -import com.sinch.sdk.domains.conversation.models.v1.conversation.ConversationDtoTest; +import com.sinch.sdk.domains.conversation.models.v1.conversations.ConversationDtoTest; import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.internal.ConversationEventInternal; import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.internal.ConversationEventInternalImpl; import java.time.Instant; diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/conversation/ConversationDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/ConversationDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/conversation/v1/conversation/ConversationDto.json rename to openapi-contracts/src/test/resources/domains/conversation/v1/conversations/ConversationDto.json diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/request/CreateConversationRequestDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/request/CreateConversationRequestDto.json new file mode 100644 index 000000000..1f278f72d --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/request/CreateConversationRequestDto.json @@ -0,0 +1,11 @@ +{ + "active": true, + "active_channel": "WHATSAPP", + "app_id": "conversation app Id", + "contact_id": "contact ID", + "metadata": "metadata value", + "metadata_json": { + "metadata_json_key": "metadata json value" + }, + "correlation_id": "correlation id value" +} \ No newline at end of file diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/response/ConversationRecentMessageDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/response/ConversationRecentMessageDto.json new file mode 100644 index 000000000..4476b8a09 --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/response/ConversationRecentMessageDto.json @@ -0,0 +1,44 @@ +{ + "conversation": { + "active": true, + "active_channel": "WHATSAPP", + "app_id": "conversation app Id", + "contact_id": "contact ID", + "id": "a conversation id", + "last_received": "2020-11-17T15:00:00Z", + "metadata": "metadata value", + "metadata_json": { + "metadata_json_key": "metadata json value" + }, + "correlation_id": "correlation id value" + }, + "last_message": { + "accept_time": "2020-11-17T16:05:51.724083Z", + "channel_identity": { + "app_id": "an app id", + "channel": "MESSENGER", + "identity": "an identity" + }, + "contact_id": "contact id value", + "conversation_id": "conversation id value", + "direction": "TO_APP", + "id": "id value", + "metadata": "metadata value", + "injected": true, + "sender_id": "sender id", + "processing_mode": "CONVERSATION", + "contact_message": { + "location_message": { + "coordinates": { + "latitude": 47.627980, + "longitude": -2.822915 + }, + "title": "title value", + "label": "label value" + }, + "reply_to": { + "message_id": "message id value" + } + } + } +} diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/response/ConversationsListRecentResponse-page-0.json b/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/response/ConversationsListRecentResponse-page-0.json new file mode 100644 index 000000000..d69edcc17 --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/response/ConversationsListRecentResponse-page-0.json @@ -0,0 +1,50 @@ +{ + "conversations": [ + { + "conversation": { + "active": true, + "active_channel": "WHATSAPP", + "app_id": "conversation app Id", + "contact_id": "contact ID", + "id": "a conversation id", + "last_received": "2020-11-17T15:00:00Z", + "metadata": "metadata value", + "metadata_json": { + "metadata_json_key": "metadata json value" + }, + "correlation_id": "correlation id value" + }, + "last_message": { + "accept_time": "2020-11-17T16:05:51.724083Z", + "channel_identity": { + "app_id": "an app id", + "channel": "MESSENGER", + "identity": "an identity" + }, + "contact_id": "contact id value", + "conversation_id": "conversation id value", + "direction": "TO_APP", + "id": "id value", + "metadata": "metadata value", + "injected": true, + "sender_id": "sender id", + "processing_mode": "CONVERSATION", + "contact_message": { + "location_message": { + "coordinates": { + "latitude": 47.627980, + "longitude": -2.822915 + }, + "title": "title value", + "label": "label value" + }, + "reply_to": { + "message_id": "message id value" + } + } + } + } + ], + "next_page_token": "1", + "total_size": 2 +} diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/response/ConversationsListRecentResponse-page-1.json b/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/response/ConversationsListRecentResponse-page-1.json new file mode 100644 index 000000000..44512dc17 --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/response/ConversationsListRecentResponse-page-1.json @@ -0,0 +1,50 @@ +{ + "conversations": [ + { + "conversation": { + "active": true, + "active_channel": "WHATSAPP", + "app_id": "conversation app Id", + "contact_id": "contact ID", + "id": "a conversation id", + "last_received": "2020-11-17T15:00:00Z", + "metadata": "metadata value", + "metadata_json": { + "metadata_json_key": "metadata json value" + }, + "correlation_id": "correlation id value" + }, + "last_message": { + "accept_time": "2020-11-17T16:05:51.724083Z", + "channel_identity": { + "app_id": "an app id", + "channel": "MESSENGER", + "identity": "an identity" + }, + "contact_id": "contact id value", + "conversation_id": "conversation id value", + "direction": "TO_APP", + "id": "id value", + "metadata": "metadata value", + "injected": true, + "sender_id": "sender id", + "processing_mode": "CONVERSATION", + "contact_message": { + "location_message": { + "coordinates": { + "latitude": 47.627980, + "longitude": -2.822915 + }, + "title": "title value", + "label": "label value" + }, + "reply_to": { + "message_id": "message id value" + } + } + } + } + ], + "next_page_token": "", + "total_size": 2 +} diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/response/ConversationsListResponse-page-0.json b/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/response/ConversationsListResponse-page-0.json new file mode 100644 index 000000000..908a4b329 --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/response/ConversationsListResponse-page-0.json @@ -0,0 +1,19 @@ +{ + "conversations": [ + { + "active": true, + "active_channel": "WHATSAPP", + "app_id": "conversation app Id", + "contact_id": "contact ID", + "id": "a conversation id", + "last_received": "2020-11-17T15:00:00Z", + "metadata": "metadata value", + "metadata_json": { + "metadata_json_key": "metadata json value" + }, + "correlation_id": "correlation id value" + } + ], + "next_page_token": "ChowMUo1NUVOVERUSFlGQVlKMFE1WFpaSktSVhIaMDFITkIzMzY0UFdCQkcyR1paV1ZWVDNERDI=", + "total_size": 2 +} diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/response/ConversationsListResponse-page-1.json b/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/response/ConversationsListResponse-page-1.json new file mode 100644 index 000000000..1f4ca8771 --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/response/ConversationsListResponse-page-1.json @@ -0,0 +1,19 @@ +{ + "conversations": [ + { + "active": true, + "active_channel": "WHATSAPP", + "app_id": "conversation app Id", + "contact_id": "contact ID", + "id": "a conversation id", + "last_received": "2020-11-17T15:00:00Z", + "metadata": "metadata value", + "metadata_json": { + "metadata_json_key": "metadata json value" + }, + "correlation_id": "correlation id value" + } + ], + "next_page_token": "ChowMUo1NUVBSk1FNDZQMlI4SFIxRjVZRjYxWhIaMDFITkIzMzY0UFdCQkcyR1paV1ZWVDNERDI=", + "total_size": 0 +} diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/response/ConversationsListResponse-page-2.json b/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/response/ConversationsListResponse-page-2.json new file mode 100644 index 000000000..864d3c4f9 --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/response/ConversationsListResponse-page-2.json @@ -0,0 +1,6 @@ +{ + "conversations": [ + ], + "next_page_token": "", + "total_size": 0 +} diff --git a/sample-app/src/main/java/com/sinch/sample/BaseApplication.java b/sample-app/src/main/java/com/sinch/sample/BaseApplication.java index 6a73ff9d6..0c53dd71d 100644 --- a/sample-app/src/main/java/com/sinch/sample/BaseApplication.java +++ b/sample-app/src/main/java/com/sinch/sample/BaseApplication.java @@ -16,6 +16,7 @@ public abstract class BaseApplication { public static final String CONFERENCE_ID_KEY = "CONFERENCE_ID"; private static final String CALL_ID_KEY = "CALL_ID"; private static final String VERIFICATION_ID_KEY = "VERIFICATION_ID"; + private static final String CONVERSATION_ID_KEY = "CONVERSATION_ID"; private static final String CONVERSATION_APP_ID_KEY = "CONVERSATION_APP_ID"; private static final String CONVERSATION_CONTACT_ID_KEY = "CONVERSATION_CONTACT_ID"; private static final String CONVERSATION_MESSAGE_ID_KEY = "CONVERSATION_MESSAGE_ID"; @@ -34,6 +35,7 @@ public abstract class BaseApplication { protected String conferenceId; protected String callId; protected String verificationId; + protected String conversationId; protected String conversationAppId; protected String conversationContactId; protected String conversationMessageId; @@ -66,6 +68,7 @@ protected BaseApplication() throws IOException { virtualPhoneNumber = getConfigValue(VIRTUAL_PHONE_NUMBER_KEY); // Conversation related settings + conversationId = getConfigValue(CONVERSATION_ID_KEY); conversationAppId = getConfigValue(CONVERSATION_APP_ID_KEY); conversationContactId = getConfigValue(CONVERSATION_CONTACT_ID_KEY); conversationMessageId = getConfigValue(CONVERSATION_MESSAGE_ID_KEY); diff --git a/sample-app/src/main/java/com/sinch/sample/conversation/conversations/Create.java b/sample-app/src/main/java/com/sinch/sample/conversation/conversations/Create.java new file mode 100644 index 000000000..d4c6fe46f --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/conversation/conversations/Create.java @@ -0,0 +1,40 @@ +package com.sinch.sample.conversation.conversations; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.conversation.api.v1.ConversationsService; +import com.sinch.sdk.domains.conversation.models.v1.conversation.Conversation; +import com.sinch.sdk.domains.conversation.models.v1.conversation.request.CreateConversationRequest; +import java.io.IOException; +import java.util.logging.Logger; + +public class Create extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(Create.class.getName()); + + public Create() throws IOException {} + + public static void main(String[] args) { + try { + new Create().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + ConversationsService service = client.conversation().v1().conversations(); + + CreateConversationRequest request = + CreateConversationRequest.builder() + .setAppId(conversationAppId) + .setContactId(conversationContactId) + .build(); + LOGGER.info("Create conversation: " + request); + + Conversation result = service.create(request); + + LOGGER.info("Response: " + result); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/conversation/conversations/Delete.java b/sample-app/src/main/java/com/sinch/sample/conversation/conversations/Delete.java new file mode 100644 index 000000000..218005aed --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/conversation/conversations/Delete.java @@ -0,0 +1,31 @@ +package com.sinch.sample.conversation.conversations; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.conversation.api.v1.ConversationsService; +import java.io.IOException; +import java.util.logging.Logger; + +public class Delete extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(Delete.class.getName()); + + public Delete() throws IOException {} + + public static void main(String[] args) { + try { + new Delete().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + ConversationsService service = client.conversation().v1().conversations(); + + LOGGER.info("Deleting conversation: " + conversationId); + + service.delete("01J3F0MYWZEQQ3Z5DEY2JTMJ1S"); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/conversation/conversations/Get.java b/sample-app/src/main/java/com/sinch/sample/conversation/conversations/Get.java new file mode 100644 index 000000000..371001573 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/conversation/conversations/Get.java @@ -0,0 +1,34 @@ +package com.sinch.sample.conversation.conversations; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.conversation.api.v1.ConversationsService; +import com.sinch.sdk.domains.conversation.models.v1.conversation.Conversation; +import java.io.IOException; +import java.util.logging.Logger; + +public class Get extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(Get.class.getName()); + + public Get() throws IOException {} + + public static void main(String[] args) { + try { + new Get().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + ConversationsService service = client.conversation().v1().conversations(); + + LOGGER.info("Get conversation: " + conversationId); + + Conversation result = service.get(conversationId); + + LOGGER.info("Response: " + result); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/conversation/conversations/List.java b/sample-app/src/main/java/com/sinch/sample/conversation/conversations/List.java new file mode 100644 index 000000000..1dd0e0a59 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/conversation/conversations/List.java @@ -0,0 +1,54 @@ +package com.sinch.sample.conversation.conversations; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.conversation.api.v1.ConversationsService; +import com.sinch.sdk.domains.conversation.models.v1.conversation.request.ConversationsListRequest; +import com.sinch.sdk.domains.conversation.models.v1.conversation.response.ConversationsListResponse; +import java.io.IOException; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.logging.Logger; + +public class List extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(List.class.getName()); + + public List() throws IOException {} + + public static void main(String[] args) { + try { + new List().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + ConversationsService service = client.conversation().v1().conversations(); + + LOGGER.info("List conversations for appID:" + conversationAppId); + + ConversationsListRequest request = + ConversationsListRequest.builder() + .setPageSize(1) + .setOnlyActive(false) + .setAppId(conversationAppId) + .build(); + ConversationsListResponse response = service.list(request); + + LOGGER.info("Response (by stream)"); + + AtomicInteger index = new AtomicInteger(); + response.stream() + .peek( + a -> + LOGGER.info( + String.format( + "Conversation %d (id '%s'): %s", index.incrementAndGet(), a.getId(), a))) + .forEach( + a -> { + /* just here to consume the stream*/ + }); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/conversation/conversations/ListRecent.java b/sample-app/src/main/java/com/sinch/sample/conversation/conversations/ListRecent.java new file mode 100644 index 000000000..ab35b3a0f --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/conversation/conversations/ListRecent.java @@ -0,0 +1,50 @@ +package com.sinch.sample.conversation.conversations; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.conversation.api.v1.ConversationsService; +import com.sinch.sdk.domains.conversation.models.v1.conversation.request.ConversationsListRecentRequest; +import com.sinch.sdk.domains.conversation.models.v1.conversation.response.ConversationsListRecentResponse; +import java.io.IOException; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.logging.Logger; + +public class ListRecent extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(ListRecent.class.getName()); + + public ListRecent() throws IOException {} + + public static void main(String[] args) { + try { + new ListRecent().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + ConversationsService service = client.conversation().v1().conversations(); + + LOGGER.info("List recent conversations for appID:" + conversationAppId); + + ConversationsListRecentRequest request = + ConversationsListRecentRequest.builder() + .setOnlyActive(false) + .setAppId(conversationAppId) + .setPageSize(1) + .build(); + ConversationsListRecentResponse response = service.listRecent(request); + + LOGGER.info("Response (by stream)"); + + AtomicInteger index = new AtomicInteger(); + response.stream() + .peek(a -> LOGGER.info(String.format("Conversation %d : %s", index.incrementAndGet(), a))) + .forEach( + a -> { + /* just here to consume the stream*/ + }); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/conversation/conversations/StopActive.java b/sample-app/src/main/java/com/sinch/sample/conversation/conversations/StopActive.java new file mode 100644 index 000000000..f14afcd98 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/conversation/conversations/StopActive.java @@ -0,0 +1,31 @@ +package com.sinch.sample.conversation.conversations; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.conversation.api.v1.ConversationsService; +import java.io.IOException; +import java.util.logging.Logger; + +public class StopActive extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(StopActive.class.getName()); + + public StopActive() throws IOException {} + + public static void main(String[] args) { + try { + new StopActive().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + ConversationsService service = client.conversation().v1().conversations(); + + LOGGER.info("Stop conversation: " + conversationId); + + service.stopActive(conversationId); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/conversation/conversations/Update.java b/sample-app/src/main/java/com/sinch/sample/conversation/conversations/Update.java new file mode 100644 index 000000000..0dd244e3d --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/conversation/conversations/Update.java @@ -0,0 +1,44 @@ +package com.sinch.sample.conversation.conversations; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.conversation.api.v1.ConversationsService; +import com.sinch.sdk.domains.conversation.models.v1.conversation.Conversation; +import com.sinch.sdk.domains.conversation.models.v1.request.MetadataUpdateStrategy; +import java.io.IOException; +import java.util.Collections; +import java.util.logging.Logger; + +public class Update extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(Update.class.getName()); + + public Update() throws IOException {} + + public static void main(String[] args) { + try { + new Update().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + ConversationsService service = client.conversation().v1().conversations(); + + LOGGER.info("Before: " + service.get(conversationId)); + + Conversation request = + Conversation.builder() + .setCorrelationId("correlation ID value") + .setMetadataJson(Collections.emptyMap()) + .setActive(true) + .build(); + LOGGER.info("Update request: " + request); + + Conversation result = service.update(conversationId, MetadataUpdateStrategy.REPLACE, request); + + LOGGER.info("Response: " + result); + } +}