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 index 0c694cda..6bceb5a0 100644 --- 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 @@ -4,9 +4,11 @@ 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.request.InjectEventRequest; import com.sinch.sdk.domains.conversation.models.v1.conversation.request.InjectMessageRequest; 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.conversation.response.InjectEventResponse; import com.sinch.sdk.domains.conversation.models.v1.request.MetadataUpdateStrategy; /** @@ -101,4 +103,13 @@ Conversation update( * @since _NEXT_VERSION_ */ void injectMessage(String conversationId, InjectMessageRequest request); + + /** + * This operation injects a conversation event into a specific conversation. + * + * @param conversationId The ID of the conversation. + * @param request Request parameters to inject event + * @since _NEXT_VERSION_ + */ + InjectEventResponse injectEvent(String conversationId, InjectEventRequest request); } 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 index c7ec51aa..31419e3a 100644 --- 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 @@ -17,10 +17,12 @@ 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.request.InjectEventRequest; import com.sinch.sdk.domains.conversation.models.v1.conversation.request.InjectMessageRequest; 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.conversation.response.InjectEventResponse; import com.sinch.sdk.domains.conversation.models.v1.request.MetadataUpdateStrategy; import com.sinch.sdk.models.ConversationContext; import java.util.Collection; @@ -107,6 +109,10 @@ public void injectMessage(String conversationId, InjectMessageRequest request) { getApi().conversationInjectMessage(uriUUID, conversationId, request); } + public InjectEventResponse injectEvent(String conversationId, InjectEventRequest request) { + return getApi().eventsInjectEvent(uriUUID, conversationId, request); + } + private ConversationsListResponse mapForPaging( ConversationsListRequest parameters, ListConversationsResponseInternal _dto) { 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 index 7a3c284b..41901136 100644 --- 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 @@ -20,14 +20,16 @@ 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.InjectEventRequest; import com.sinch.sdk.domains.conversation.models.v1.conversation.request.InjectMessageRequestBase; 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.request.InjectEventDtoTest; +import com.sinch.sdk.domains.conversation.models.v1.conversations.request.InjectMessageDtoTest; import com.sinch.sdk.domains.conversation.models.v1.conversations.response.ConversationRecentMessageDtoTest; -import com.sinch.sdk.domains.conversation.models.v1.messages.request.InjectMessageDtoTest; import com.sinch.sdk.domains.conversation.models.v1.request.MetadataUpdateStrategy; import com.sinch.sdk.models.ConversationContext; import java.util.Collection; @@ -49,6 +51,7 @@ public class ConversationsServiceTest extends ConversationBaseTest { @Captor ArgumentCaptor projectIdCaptor; @Captor ArgumentCaptor conversationIdCaptor; @Captor ArgumentCaptor injectMessageCaptor; + @Captor ArgumentCaptor injectEventCaptor; ConversationsService service; String uriPartID = "foovalue"; @@ -266,4 +269,20 @@ void injectMessage() throws ApiException { TestHelpers.recursiveEquals( injectMessageCaptor.getValue(), InjectMessageDtoTest.injectContactMessage); } + + @Test + void injectEvent() throws ApiException { + + service.injectEvent( + InjectEventDtoTest.injectEvent.getConversationId(), InjectEventDtoTest.injectEvent); + + verify(api) + .eventsInjectEvent( + projectIdCaptor.capture(), conversationIdCaptor.capture(), injectEventCaptor.capture()); + + Assertions.assertThat(projectIdCaptor.getValue()).isEqualTo(uriPartID); + Assertions.assertThat(conversationIdCaptor.getValue()) + .isEqualTo(InjectEventDtoTest.injectEvent.getConversationId()); + TestHelpers.recursiveEquals(injectEventCaptor.getValue(), InjectEventDtoTest.injectEvent); + } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/ConversationApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/ConversationApi.java index bccd1718..951ead89 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/ConversationApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/ConversationApi.java @@ -30,7 +30,7 @@ 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.CreateConversationRequest; -import com.sinch.sdk.domains.conversation.models.v1.conversation.request.InjectConversationEventRequest; +import com.sinch.sdk.domains.conversation.models.v1.conversation.request.InjectEventRequest; import com.sinch.sdk.domains.conversation.models.v1.conversation.request.InjectMessageRequestBase; import com.sinch.sdk.domains.conversation.models.v1.conversation.response.InjectEventResponse; import com.sinch.sdk.domains.conversation.models.v1.request.MetadataUpdateStrategy; @@ -947,14 +947,12 @@ private HttpRequest conversationUpdateConversationRequestBuilder( * Dashboard](https://dashboard.sinch.com/convapi/apps). (required) * @param conversationId The unique ID of the conversation. This is generated by the system. * (required) - * @param injectConversationEventRequest Inject event request (required) + * @param injectEventRequest Inject event request (required) * @return InjectEventResponse * @throws ApiException if fails to make API call */ public InjectEventResponse eventsInjectEvent( - String projectId, - String conversationId, - InjectConversationEventRequest injectConversationEventRequest) + String projectId, String conversationId, InjectEventRequest injectEventRequest) throws ApiException { LOGGER.finest( @@ -966,11 +964,11 @@ public InjectEventResponse eventsInjectEvent( + "conversationId: " + conversationId + ", " - + "injectConversationEventRequest: " - + injectConversationEventRequest); + + "injectEventRequest: " + + injectEventRequest); HttpRequest httpRequest = - eventsInjectEventRequestBuilder(projectId, conversationId, injectConversationEventRequest); + eventsInjectEventRequestBuilder(projectId, conversationId, injectEventRequest); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); @@ -990,9 +988,7 @@ public InjectEventResponse eventsInjectEvent( } private HttpRequest eventsInjectEventRequestBuilder( - String projectId, - String conversationId, - InjectConversationEventRequest injectConversationEventRequest) + String projectId, String conversationId, InjectEventRequest injectEventRequest) throws ApiException { // verify the required parameter 'projectId' is set if (projectId == null) { @@ -1004,12 +1000,11 @@ private HttpRequest eventsInjectEventRequestBuilder( throw new ApiException( 400, "Missing the required parameter 'conversationId' when calling eventsInjectEvent"); } - // verify the required parameter 'injectConversationEventRequest' is set - if (injectConversationEventRequest == null) { + // verify the required parameter 'injectEventRequest' is set + if (injectEventRequest == null) { throw new ApiException( 400, - "Missing the required parameter 'injectConversationEventRequest' when calling" - + " eventsInjectEvent"); + "Missing the required parameter 'injectEventRequest' when calling eventsInjectEvent"); } String localVarPath = @@ -1029,8 +1024,7 @@ private HttpRequest eventsInjectEventRequestBuilder( final Collection localVarContentTypes = Arrays.asList("application/json"); final Collection localVarAuthNames = Arrays.asList("Basic", "oAuth2"); - final String serializedBody = - mapper.serialize(localVarContentTypes, injectConversationEventRequest); + final String serializedBody = mapper.serialize(localVarContentTypes, injectEventRequest); return new HttpRequest( localVarPath, diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/AppMessage.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/AppMessage.java deleted file mode 100644 index 7be149b2..00000000 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/AppMessage.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.conversation.request; - -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.sinch.sdk.domains.conversation.models.v1.messages.internal.AppMessageInternal; - -/** App Message */ -@JsonDeserialize(builder = AppMessageImpl.Builder.class) -public interface AppMessage { - - /** - * Get appMessage - * - * @return appMessage - */ - AppMessageInternal getAppMessage(); - - /** - * Getting builder - * - * @return New Builder instance - */ - static Builder builder() { - return new AppMessageImpl.Builder(); - } - - /** Dedicated Builder */ - interface Builder { - - /** - * see getter - * - * @param appMessage see getter - * @return Current builder - * @see #getAppMessage - */ - Builder setAppMessage(AppMessageInternal appMessage); - - /** - * Create instance - * - * @return The instance build with current builder values - */ - AppMessage build(); - } -} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/AppMessageImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/AppMessageImpl.java deleted file mode 100644 index 285cebca..00000000 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/AppMessageImpl.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.sinch.sdk.domains.conversation.models.v1.conversation.request; - -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.messages.internal.AppMessageInternal; -import java.util.Objects; - -@JsonPropertyOrder({AppMessageImpl.JSON_PROPERTY_APP_MESSAGE}) -@JsonFilter("uninitializedFilter") -@JsonInclude(value = JsonInclude.Include.CUSTOM) -public class AppMessageImpl implements AppMessage { - private static final long serialVersionUID = 1L; - - public static final String JSON_PROPERTY_APP_MESSAGE = "app_message"; - - private OptionalValue appMessage; - - public AppMessageImpl() {} - - protected AppMessageImpl(OptionalValue appMessage) { - this.appMessage = appMessage; - } - - @JsonIgnore - public AppMessageInternal getAppMessage() { - return appMessage.orElse(null); - } - - @JsonProperty(JSON_PROPERTY_APP_MESSAGE) - @JsonInclude(value = JsonInclude.Include.ALWAYS) - public OptionalValue appMessage() { - return appMessage; - } - - /** Return true if this App_Message object is equal to o. */ - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - AppMessageImpl appMessage = (AppMessageImpl) o; - return Objects.equals(this.appMessage, appMessage.appMessage); - } - - @Override - public int hashCode() { - return Objects.hash(appMessage); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class AppMessageImpl {\n"); - sb.append(" appMessage: ").append(toIndentedString(appMessage)).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 AppMessage.Builder { - OptionalValue appMessage = OptionalValue.empty(); - - @JsonProperty(JSON_PROPERTY_APP_MESSAGE) - public Builder setAppMessage(AppMessageInternal appMessage) { - this.appMessage = OptionalValue.of(appMessage); - return this; - } - - public AppMessage build() { - return new AppMessageImpl(appMessage); - } - } -} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/InjectConversationEventRequest.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/InjectConversationEventRequest.java deleted file mode 100644 index c9f93cce..00000000 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/InjectConversationEventRequest.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * 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.conversation.request; - -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.AppEvent; -import java.time.Instant; - -/** Inject Event request */ -@JsonDeserialize(builder = InjectConversationEventRequestImpl.Builder.class) -public interface InjectConversationEventRequest { - - /** - * Get appEvent - * - * @return appEvent - */ - AppEvent 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 InjectConversationEventRequestImpl.Builder(); - } - - /** Dedicated Builder */ - interface Builder { - - /** - * see getter - * - * @param appEvent see getter - * @return Current builder - * @see #getAppEvent - */ - Builder setAppEvent(AppEvent 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 - */ - InjectConversationEventRequest build(); - } -} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/InjectConversationEventRequestImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/InjectConversationEventRequestImpl.java deleted file mode 100644 index 646f85ac..00000000 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/InjectConversationEventRequestImpl.java +++ /dev/null @@ -1,235 +0,0 @@ -package com.sinch.sdk.domains.conversation.models.v1.conversation.request; - -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.AppEvent; -import java.time.Instant; -import java.util.Objects; - -@JsonPropertyOrder({ - InjectConversationEventRequestImpl.JSON_PROPERTY_APP_EVENT, - InjectConversationEventRequestImpl.JSON_PROPERTY_CONVERSATION_ID, - InjectConversationEventRequestImpl.JSON_PROPERTY_CONTACT_ID, - InjectConversationEventRequestImpl.JSON_PROPERTY_CHANNEL_IDENTITY, - InjectConversationEventRequestImpl.JSON_PROPERTY_ACCEPT_TIME, - InjectConversationEventRequestImpl.JSON_PROPERTY_PROCESSING_MODE -}) -@JsonFilter("uninitializedFilter") -@JsonInclude(value = JsonInclude.Include.CUSTOM) -public class InjectConversationEventRequestImpl implements InjectConversationEventRequest { - 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 InjectConversationEventRequestImpl() {} - - protected InjectConversationEventRequestImpl( - 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 AppEvent 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.ALWAYS) - 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 InjectConversationEventRequest object is equal to o. */ - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - InjectConversationEventRequestImpl injectConversationEventRequest = - (InjectConversationEventRequestImpl) o; - return Objects.equals(this.appEvent, injectConversationEventRequest.appEvent) - && Objects.equals(this.conversationId, injectConversationEventRequest.conversationId) - && Objects.equals(this.contactId, injectConversationEventRequest.contactId) - && Objects.equals(this.channelIdentity, injectConversationEventRequest.channelIdentity) - && Objects.equals(this.acceptTime, injectConversationEventRequest.acceptTime) - && Objects.equals(this.processingMode, injectConversationEventRequest.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 InjectConversationEventRequestImpl {\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 InjectConversationEventRequest.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(AppEvent 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 InjectConversationEventRequest build() { - return new InjectConversationEventRequestImpl( - appEvent, conversationId, contactId, channelIdentity, acceptTime, processingMode); - } - } -} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/InjectEventRequest.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/InjectEventRequest.java index 2ae0f9cd..5d97bf8c 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/InjectEventRequest.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/InjectEventRequest.java @@ -13,17 +13,57 @@ package com.sinch.sdk.domains.conversation.models.v1.conversation.request; 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.AppEvent; +import java.time.Instant; -/** Inject Event Request */ +/** Inject Event request */ @JsonDeserialize(builder = InjectEventRequestImpl.Builder.class) public interface InjectEventRequest { /** - * Get event + * Get appEvent * - * @return event + * @return appEvent */ - InjectConversationEventRequest getEvent(); + AppEvent 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 @@ -40,11 +80,56 @@ interface Builder { /** * see getter * - * @param event see getter + * @param appEvent see getter + * @return Current builder + * @see #getAppEvent + */ + Builder setAppEvent(AppEvent 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 #getEvent + * @see #getProcessingMode */ - Builder setEvent(InjectConversationEventRequest event); + Builder setProcessingMode(ProcessingMode processingMode); /** * Create instance diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/InjectEventRequestImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/InjectEventRequestImpl.java index b8168495..bbf5de37 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/InjectEventRequestImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/conversation/request/InjectEventRequestImpl.java @@ -7,36 +7,133 @@ 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.AppEvent; +import java.time.Instant; import java.util.Objects; -@JsonPropertyOrder({InjectEventRequestImpl.JSON_PROPERTY_EVENT}) +@JsonPropertyOrder({ + InjectEventRequestImpl.JSON_PROPERTY_APP_EVENT, + InjectEventRequestImpl.JSON_PROPERTY_CONVERSATION_ID, + InjectEventRequestImpl.JSON_PROPERTY_CONTACT_ID, + InjectEventRequestImpl.JSON_PROPERTY_CHANNEL_IDENTITY, + InjectEventRequestImpl.JSON_PROPERTY_ACCEPT_TIME, + InjectEventRequestImpl.JSON_PROPERTY_PROCESSING_MODE +}) @JsonFilter("uninitializedFilter") @JsonInclude(value = JsonInclude.Include.CUSTOM) public class InjectEventRequestImpl implements InjectEventRequest { private static final long serialVersionUID = 1L; - public static final String JSON_PROPERTY_EVENT = "event"; + public static final String JSON_PROPERTY_APP_EVENT = "app_event"; - private OptionalValue 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 InjectEventRequestImpl() {} - protected InjectEventRequestImpl(OptionalValue event) { - this.event = event; + protected InjectEventRequestImpl( + 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 AppEvent 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 InjectConversationEventRequest getEvent() { - return event.orElse(null); + public Instant getAcceptTime() { + return acceptTime.orElse(null); } - @JsonProperty(JSON_PROPERTY_EVENT) + @JsonProperty(JSON_PROPERTY_ACCEPT_TIME) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + 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 event() { - return event; + public OptionalValue processingMode() { + return processingMode; } - /** Return true if this InjectEventRequest object is equal to o. */ + /** Return true if this InjectConversationEventRequest object is equal to o. */ @Override public boolean equals(Object o) { if (this == o) { @@ -45,20 +142,31 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) { return false; } - InjectEventRequestImpl injectEventRequest = (InjectEventRequestImpl) o; - return Objects.equals(this.event, injectEventRequest.event); + InjectEventRequestImpl injectConversationEventRequest = (InjectEventRequestImpl) o; + return Objects.equals(this.appEvent, injectConversationEventRequest.appEvent) + && Objects.equals(this.conversationId, injectConversationEventRequest.conversationId) + && Objects.equals(this.contactId, injectConversationEventRequest.contactId) + && Objects.equals(this.channelIdentity, injectConversationEventRequest.channelIdentity) + && Objects.equals(this.acceptTime, injectConversationEventRequest.acceptTime) + && Objects.equals(this.processingMode, injectConversationEventRequest.processingMode); } @Override public int hashCode() { - return Objects.hash(event); + return Objects.hash( + appEvent, conversationId, contactId, channelIdentity, acceptTime, processingMode); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class InjectEventRequestImpl {\n"); - sb.append(" event: ").append(toIndentedString(event)).append("\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(); } @@ -75,16 +183,52 @@ private String toIndentedString(Object o) { @JsonPOJOBuilder(withPrefix = "set") static class Builder implements InjectEventRequest.Builder { - OptionalValue event = OptionalValue.empty(); + 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(AppEvent 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_EVENT) - public Builder setEvent(InjectConversationEventRequest event) { - this.event = OptionalValue.of(event); + @JsonProperty(JSON_PROPERTY_PROCESSING_MODE) + public Builder setProcessingMode(ProcessingMode processingMode) { + this.processingMode = OptionalValue.of(processingMode); return this; } public InjectEventRequest build() { - return new InjectEventRequestImpl(event); + return new InjectEventRequestImpl( + appEvent, conversationId, contactId, channelIdentity, acceptTime, processingMode); } } } diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/conversations/request/InjectEventDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/conversations/request/InjectEventDtoTest.java new file mode 100644 index 00000000..309e0435 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/conversations/request/InjectEventDtoTest.java @@ -0,0 +1,37 @@ +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.ChannelIdentityDtoTest; +import com.sinch.sdk.domains.conversation.models.v1.ProcessingMode; +import com.sinch.sdk.domains.conversation.models.v1.conversation.request.InjectEventRequest; +import com.sinch.sdk.domains.conversation.models.v1.events.types.GenericEventDtoTest; +import java.time.Instant; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +@TestWithResources +public class InjectEventDtoTest extends ConversationBaseTest { + + public static InjectEventRequest injectEvent = + InjectEventRequest.builder() + .setAcceptTime(Instant.parse("2024-08-18T14:18:18.117563Z")) + .setAppEvent(GenericEventDtoTest.expectedDto) + .setChannelIdentity(ChannelIdentityDtoTest.expectedDto) + .setConversationId("a conversation Id") + .setProcessingMode(ProcessingMode.CONVERSATION) + .build(); + + @GivenTextResource("/domains/conversation/v1/conversations/request/InjectEventRequestDto.json") + static String jsonInjectEventRequestDto; + + @Test + void serializeInjectEventRequestDto() throws JsonProcessingException, JSONException { + String serializedString = objectMapper.writeValueAsString(injectEvent); + + JSONAssert.assertEquals(jsonInjectEventRequestDto, serializedString, true); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/messages/request/InjectMessageDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/conversations/request/InjectMessageDtoTest.java similarity index 97% rename from openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/messages/request/InjectMessageDtoTest.java rename to openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/conversations/request/InjectMessageDtoTest.java index 73a598c4..94c9e9b5 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/messages/request/InjectMessageDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/conversations/request/InjectMessageDtoTest.java @@ -1,4 +1,4 @@ -package com.sinch.sdk.domains.conversation.models.v1.messages.request; +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; diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/request/InjectEventRequestDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/request/InjectEventRequestDto.json new file mode 100644 index 00000000..5fa225e3 --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/request/InjectEventRequestDto.json @@ -0,0 +1,17 @@ +{ + "app_event": { + "generic_event": { + "payload": { + "payload_key": "payload value" + } + } + }, + "conversation_id": "a conversation Id", + "channel_identity": { + "app_id": "an app id", + "channel": "MESSENGER", + "identity": "an identity" + }, + "accept_time": "2024-08-18T14:18:18.117563Z", + "processing_mode": "CONVERSATION" +} diff --git a/sample-app/src/main/java/com/sinch/sample/conversation/conversations/InjectEvent.java b/sample-app/src/main/java/com/sinch/sample/conversation/conversations/InjectEvent.java new file mode 100644 index 00000000..a8a7fa4b --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/conversation/conversations/InjectEvent.java @@ -0,0 +1,61 @@ +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.ChannelIdentity; +import com.sinch.sdk.domains.conversation.models.v1.ConversationChannel; +import com.sinch.sdk.domains.conversation.models.v1.ProcessingMode; +import com.sinch.sdk.domains.conversation.models.v1.conversation.request.InjectEventRequest; +import com.sinch.sdk.domains.conversation.models.v1.conversation.response.InjectEventResponse; +import com.sinch.sdk.domains.conversation.models.v1.events.AppEvent; +import com.sinch.sdk.domains.conversation.models.v1.events.types.GenericEvent; +import java.io.IOException; +import java.time.Instant; +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Logger; + +public class InjectEvent extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(InjectEvent.class.getName()); + + public InjectEvent() throws IOException {} + + public static void main(String[] args) { + try { + new InjectEvent().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + ConversationsService service = client.conversation().v1().conversations(); + + Map map = new HashMap<>(); + map.put("a property key", "a property value"); + + AppEvent event = GenericEvent.builder().setPayload(map).build(); + + InjectEventRequest request = + InjectEventRequest.builder() + .setAcceptTime(Instant.now()) + .setAppEvent(event) + .setChannelIdentity( + ChannelIdentity.builder() + .setChannel(ConversationChannel.RCS) + .setIdentity(phoneNumber) + .build()) + .setConversationId(conversationId) + .setProcessingMode(ProcessingMode.CONVERSATION) + .build(); + + LOGGER.info("Inject event request: " + request); + + InjectEventResponse response = service.injectEvent(conversationId, request); + + LOGGER.info("Inject event response: " + response); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/conversation/conversations/InjectMessage.java b/sample-app/src/main/java/com/sinch/sample/conversation/conversations/InjectMessage.java index 24949386..cff835ae 100644 --- a/sample-app/src/main/java/com/sinch/sample/conversation/conversations/InjectMessage.java +++ b/sample-app/src/main/java/com/sinch/sample/conversation/conversations/InjectMessage.java @@ -61,7 +61,7 @@ public void run() { .setAcceptTime(Instant.now()) .build(); - LOGGER.info("Update request: " + request); + LOGGER.info("Inject message request: " + request); service.injectMessage(conversationId, request); }