Skip to content

Commit

Permalink
Merge pull request #120 from sinch/DEXP-237-inject-event
Browse files Browse the repository at this point in the history
Support 'injectEvent' API
  • Loading branch information
JPPortier authored Aug 19, 2024
2 parents f1355af + babf65a commit cb434a0
Show file tree
Hide file tree
Showing 15 changed files with 421 additions and 571 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -49,6 +51,7 @@ public class ConversationsServiceTest extends ConversationBaseTest {
@Captor ArgumentCaptor<String> projectIdCaptor;
@Captor ArgumentCaptor<String> conversationIdCaptor;
@Captor ArgumentCaptor<InjectMessageRequestBase> injectMessageCaptor;
@Captor ArgumentCaptor<InjectEventRequest> injectEventCaptor;

ConversationsService service;
String uriPartID = "foovalue";
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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 =
Expand All @@ -1029,8 +1024,7 @@ private HttpRequest eventsInjectEventRequestBuilder(
final Collection<String> localVarContentTypes = Arrays.asList("application/json");

final Collection<String> localVarAuthNames = Arrays.asList("Basic", "oAuth2");
final String serializedBody =
mapper.serialize(localVarContentTypes, injectConversationEventRequest);
final String serializedBody = mapper.serialize(localVarContentTypes, injectEventRequest);

return new HttpRequest(
localVarPath,
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit cb434a0

Please sign in to comment.