-
Notifications
You must be signed in to change notification settings - Fork 3
/
WorkflowStep.cs
113 lines (106 loc) · 4.61 KB
/
WorkflowStep.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System.Collections.Generic;
using Amazon.CDK;
using Amazon.CDK.AWS.DynamoDB;
using Amazon.CDK.AWS.SNS;
using Amazon.CDK.AWS.SNS.Subscriptions;
using Amazon.CDK.AWS.SQS;
using Amazon.CDK.AWS.StepFunctions;
using Amazon.CDK.AWS.StepFunctions.Tasks;
using Constructs;
namespace EventDrivenCdk.CustomerContactService
{
public static class WorkflowStep
{
public static SnsPublish NotifyBadReview(Construct scope)
{
var negativeReviewNotification = new Topic(scope, "ReviewNotificationTopic", new TopicProps()
{
DisplayName = "Negative Review Notification",
TopicName = "NegativeReviewNotification"
});
negativeReviewNotification.AddSubscription(new EmailSubscription("", new EmailSubscriptionProps()
{
}));
return new SnsPublish(scope, "NotifyNewBadReview", new SnsPublishProps()
{
Topic = negativeReviewNotification,
Message = TaskInput.FromText("There has been a new negative review"),
ResultPath = "$.snsResult"
});
}
public static SqsSendMessage WaitForCustomerAgentClaim(Construct scope)
{
var awaitingClaimQueue = new Queue(scope, "AwaitingClaimQueue", new QueueProps()
{
QueueName = "AwaitingClaim",
VisibilityTimeout = Duration.Minutes(2)
});
return new SqsSendMessage(scope, "QueueForClaim", new SqsSendMessageProps()
{
Queue = awaitingClaimQueue,
MessageBody = TaskInput.FromObject(new Dictionary<string, object>()
{
{"Token", JsonPath.TaskToken},
{
"Payload", new Dictionary<string, object>()
{
{"emailAddress", JsonPath.StringAt("$.detail.emailAddress")},
{"reviewContent", JsonPath.StringAt("$.detail.reviewContents")},
{"originalReviewContents", JsonPath.StringAt("$.detail.originalReviewContents")},
{"reviewId", JsonPath.StringAt("$.detail.reviewId")},
}
},
}),
ResultPath = "$.claimResponse",
IntegrationPattern = IntegrationPattern.WAIT_FOR_TASK_TOKEN,
});
}
public static DynamoPutItem StoreCustomerServiceClaim(Construct scope)
{
var customerContactTable = new Table(scope, "CustomerContactClaim", new TableProps()
{
TableName = "CustomerContactTable",
PartitionKey = new Attribute()
{
Name = "PK",
Type = AttributeType.STRING
},
BillingMode = BillingMode.PAY_PER_REQUEST
});
return new DynamoPutItem(scope, "StoreCustomerServiceClaim", new DynamoPutItemProps()
{
Table = customerContactTable,
ResultPath = "$.output",
Item = new Dictionary<string, DynamoAttributeValue>(1)
{
{"PK", DynamoAttributeValue.FromString(JsonPath.StringAt("$.detail.reviewId"))},
{
"Data", DynamoAttributeValue.FromMap(new Dictionary<string, DynamoAttributeValue>(3)
{
{
"reviewIdentifier",
DynamoAttributeValue.FromString(JsonPath.StringAt("$.detail.reviewIdentifier"))
},
{
"claimedBy",
DynamoAttributeValue.FromString(JsonPath.StringAt("$.claimResponse.ClaimedBy"))
},
{
"reviewId",
DynamoAttributeValue.FromString(JsonPath.StringAt("$.detail.reviewId"))
},
{
"emailAddress",
DynamoAttributeValue.FromString(JsonPath.StringAt("$.detail.emailAddress"))
},
{
"reviewContents",
DynamoAttributeValue.FromString(JsonPath.StringAt("$.detail.reviewContents"))
},
})
}
},
});
}
}
}