Skip to content

Updating ConnectEvent to better model the Queue attribute. #278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static class ContactData implements Serializable, Cloneable {
private String initiationMethod;
private String instanceArn;
private String previousContactId;
private String queue;
private Queue queue;
private SystemEndpoint systemEndpoint;
}

Expand All @@ -72,6 +72,15 @@ public static class CustomerEndpoint implements Serializable, Cloneable {
private String type;
}

@Data
@Builder(setterPrefix = "with")
@NoArgsConstructor
@AllArgsConstructor
public static class Queue implements Serializable, Cloneable {
private String arn;
private String name;
}

@Data
@Builder(setterPrefix = "with")
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public class LambdaEventSerializers {
ConnectEventMixin.ContactDataMixin.class),
new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.ConnectEvent$CustomerEndpoint",
ConnectEventMixin.CustomerEndpointMixin.class),
new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.ConnectEvent$Queue",
ConnectEventMixin.QueueMixin.class),
new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.ConnectEvent$SystemEndpoint",
ConnectEventMixin.SystemEndpointMixin.class),
new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.DynamodbEvent",
Expand Down Expand Up @@ -161,6 +163,7 @@ public class LambdaEventSerializers {
Arrays.asList(
new NestedClass("com.amazonaws.services.lambda.runtime.events.ConnectEvent$Details"),
new NestedClass("com.amazonaws.services.lambda.runtime.events.ConnectEvent$ContactData"),
new NestedClass("com.amazonaws.services.lambda.runtime.events.ConnectEvent$Queue"),
new NestedClass("com.amazonaws.services.lambda.runtime.events.ConnectEvent$CustomerEndpoint"),
new NestedClass("com.amazonaws.services.lambda.runtime.events.ConnectEvent$SystemEndpoint"))),
new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.DynamodbEvent",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Map;
import java.util.Queue;

/**
* Jackson annotations for ConnectEvent
Expand Down Expand Up @@ -65,7 +66,7 @@ public abstract class ContactDataMixin {
@JsonProperty("PreviousContactId") abstract void setPreviousContactId(String previousContactId);

// needed because Jackson expects "queue" instead of "Queue"
@JsonProperty("Queue") abstract String getQueue();
@JsonProperty("Queue") abstract Queue getQueue();
@JsonProperty("Queue") abstract void setQueue(String queue);

// needed because Jackson expects "systemEndpoint" instead of "SystemEndpoint"
Expand All @@ -85,6 +86,17 @@ public abstract class CustomerEndpointMixin {
@JsonProperty("Type") abstract void setType(String type);
}

public abstract class QueueMixin {

// needed because Jackson expects "arn" instead of "ARN"
@JsonProperty("ARN") abstract String getArn();
@JsonProperty("ARN") abstract void setArn(String arn);

// needed because Jackson expects "name" instead of "Name"
@JsonProperty("Name") abstract String getName();
@JsonProperty("Name") abstract void setName(String name);
}

public abstract class SystemEndpointMixin {

// needed because Jackson expects "address" instead of "Address"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ public void testConfigEvent() throws IOException {
assertJsonEqual(expected, actual);
}

@Test
public void testConnectEvent() throws IOException {
String expected = readEvent("connect_event.json");
String actual = deserializeSerializeJsonToString(expected, ConnectEvent.class);

assertJsonEqual(expected, actual);
}

@Test
public void testDynamodbEvent() throws IOException {
String expected = readEvent("dynamodb_event.json");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"Details": {
"ContactData": {
"Attributes": {},
"Channel": "VOICE",
"ContactId": "4a573372-1f28-4e26-b97b-XXXXXXXXXXX",
"CustomerEndpoint": {
"Address": "+1234567890",
"Type": "TELEPHONE_NUMBER"
},
"InitialContactId": "4a573372-1f28-4e26-b97b-XXXXXXXXXXX",
"InitiationMethod": "INBOUND | OUTBOUND | TRANSFER | CALLBACK",
"InstanceARN": "arn:aws:connect:aws-region:1234567890:instance/c8c0e68d-2200-4265-82c0-XXXXXXXXXX",
"PreviousContactId": "4a573372-1f28-4e26-b97b-XXXXXXXXXXX",
"Queue": {
"ARN": "arn:aws:connect:eu-west-2:111111111111:instance/cccccccc-bbbb-dddd-eeee-ffffffffffff/queue/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"Name": "PasswordReset"
},
"SystemEndpoint": {
"Address": "+1234567890",
"Type": "TELEPHONE_NUMBER"
}
},
"Parameters": {
"sentAttributeKey": "sentAttributeValue"
}
},
"Name": "ContactFlowEvent"
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,22 @@ public void testLoadConnectEvent() {
ConnectEvent.ContactData contactData = event.getDetails().getContactData();
assertThat(contactData)
.returns("VOICE", from(ConnectEvent.ContactData::getChannel))
.returns("5ca32fbd-8f92-46af-92a5-6b0f970f0efe", from(ConnectEvent.ContactData::getContactId))
.returns("6ca32fbd-8f92-46af-92a5-6b0f970f0efe", from(ConnectEvent.ContactData::getInitialContactId))
.returns("API", from(ConnectEvent.ContactData::getInitiationMethod))
.returns("arn:aws:connect:eu-central-1:123456789012:instance/9308c2a1-9bc6-4cea-8290-6c0b4a6d38fa", from(ConnectEvent.ContactData::getInstanceArn))
.returns("4ca32fbd-8f92-46af-92a5-6b0f970f0efe", from(ConnectEvent.ContactData::getPreviousContactId));
.returns("4a573372-1f28-4e26-b97b-XXXXXXXXXXX", from(ConnectEvent.ContactData::getContactId))
.returns("4a573372-1f28-4e26-b97b-XXXXXXXXXXX", from(ConnectEvent.ContactData::getInitialContactId))
.returns("INBOUND | OUTBOUND | TRANSFER | CALLBACK", from(ConnectEvent.ContactData::getInitiationMethod))
.returns("arn:aws:connect:aws-region:1234567890:instance/c8c0e68d-2200-4265-82c0-XXXXXXXXXX", from(ConnectEvent.ContactData::getInstanceArn))
.returns("4a573372-1f28-4e26-b97b-XXXXXXXXXXX", from(ConnectEvent.ContactData::getPreviousContactId));

assertThat(contactData.getQueue())
.returns("arn:aws:connect:eu-west-2:111111111111:instance/cccccccc-bbbb-dddd-eeee-ffffffffffff/queue/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", from(ConnectEvent.Queue::getArn))
.returns("PasswordReset", from(ConnectEvent.Queue::getName));

assertThat(contactData.getCustomerEndpoint())
.returns("+11234567890",from(ConnectEvent.CustomerEndpoint::getAddress))
.returns("+1234567890",from(ConnectEvent.CustomerEndpoint::getAddress))
.returns("TELEPHONE_NUMBER",from(ConnectEvent.CustomerEndpoint::getType));

assertThat(contactData.getSystemEndpoint())
.returns("+21234567890",from(ConnectEvent.SystemEndpoint::getAddress))
.returns("+1234567890",from(ConnectEvent.SystemEndpoint::getAddress))
.returns("TELEPHONE_NUMBER",from(ConnectEvent.SystemEndpoint::getType));
}

Expand Down
30 changes: 13 additions & 17 deletions aws-lambda-java-tests/src/test/resources/connect_event.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,26 @@
"ContactData": {
"Attributes": {},
"Channel": "VOICE",
"ContactId": "5ca32fbd-8f92-46af-92a5-6b0f970f0efe",
"ContactId": "4a573372-1f28-4e26-b97b-XXXXXXXXXXX",
"CustomerEndpoint": {
"Address": "+11234567890",
"Address": "+1234567890",
"Type": "TELEPHONE_NUMBER"
},
"InitialContactId": "6ca32fbd-8f92-46af-92a5-6b0f970f0efe",
"InitiationMethod": "API",
"InstanceARN": "arn:aws:connect:eu-central-1:123456789012:instance/9308c2a1-9bc6-4cea-8290-6c0b4a6d38fa",
"MediaStreams": {
"Customer": {
"Audio": {
"StartFragmentNumber": "91343852333181432392682062622220590765191907586",
"StartTimestamp": "1565781909613",
"StreamARN": "arn:aws:kinesisvideo:eu-central-1:123456789012:stream/connect-contact-a3d73b84-ce0e-479a-a9dc-5637c9d30ac9/1565272947806"
}
}
"InitialContactId": "4a573372-1f28-4e26-b97b-XXXXXXXXXXX",
"InitiationMethod": "INBOUND | OUTBOUND | TRANSFER | CALLBACK",
"InstanceARN": "arn:aws:connect:aws-region:1234567890:instance/c8c0e68d-2200-4265-82c0-XXXXXXXXXX",
"PreviousContactId": "4a573372-1f28-4e26-b97b-XXXXXXXXXXX",
"Queue": {
"ARN": "arn:aws:connect:eu-west-2:111111111111:instance/cccccccc-bbbb-dddd-eeee-ffffffffffff/queue/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"Name": "PasswordReset"
},
"PreviousContactId": "4ca32fbd-8f92-46af-92a5-6b0f970f0efe",
"Queue": null,
"SystemEndpoint": {
"Address": "+21234567890",
"Address": "+1234567890",
"Type": "TELEPHONE_NUMBER"
}
},
"Parameters": {}
"Parameters": {
"sentAttributeKey": "sentAttributeValue"
}
}
}