/
sponsor-ad-copy-reminder.asl.json
165 lines (165 loc) · 5.05 KB
/
sponsor-ad-copy-reminder.asl.json
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
{
"Comment": "Send an email reminder to the sponsor of the newsletter for a new ad copy",
"StartAt": "Get Calendar",
"States": {
"Get Calendar": {
"Type": "Task",
"Parameters": {
"Bucket": "${Bucket}",
"Key": "sponsors/sponsor-calendar.json"
},
"Resource": "${S3GetObject}",
"ResultSelector": {
"schedule.$": "States.StringToJson($.Body)"
},
"Next": "Get Upcoming Sponsored Slot"
},
"Get Upcoming Sponsored Slot": {
"Type": "Task",
"Resource": "${LambdaInvoke}",
"Parameters": {
"Payload.$": "$",
"FunctionName": "${GetNextNewsletterDateFunction}"
},
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException"
],
"IntervalSeconds": 2,
"MaxAttempts": 6,
"BackoffRate": 2
}
],
"Next": "Has Sponsor?"
},
"Has Sponsor?": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.Payload.slot",
"IsPresent": true,
"Next": "Get Sponsor List"
}
],
"Default": "Nothing To Do"
},
"Get Sponsor List": {
"Type": "Task",
"Parameters": {
"Bucket": "${Bucket}",
"Key": "sponsors/sponsors.json"
},
"Resource": "${S3GetObject}",
"ResultSelector": {
"list.$": "States.StringToJson($.Body)"
},
"ResultPath": "$.sponsors",
"Next": "Format State"
},
"Format State": {
"Type": "Pass",
"Parameters": {
"slot.$": "$.Payload.slot",
"sponsors.$": "$.sponsors.list.sponsors"
},
"Next": "Find Sponsor"
},
"Find Sponsor": {
"Type": "Map",
"End": true,
"Iterator": {
"StartAt": "Is Correct Sponsor?",
"States": {
"Is Correct Sponsor?": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.sponsor.name",
"StringEqualsPath": "$.slot.sponsor",
"Next": "Send Email To Sponsor"
}
],
"Default": "End"
},
"Send Email To Sponsor": {
"Type": "Task",
"Resource": "${LambdaInvoke}",
"OutputPath": "$.Payload",
"Parameters": {
"FunctionName": "${SendEmailFunction}",
"Payload": {
"to.$": "$.sponsor.contact.email",
"subject.$": "States.Format('${NewsletterName} Ad Copy Reminder ({})', $.slot.date)",
"text.$": "States.Format('Happy Wednesday {}!\r\rThis is a friendly reminder to submit your ad copy for your upcoming sponsored ad in the ${NewsletterName} newsletter by Friday at 8pm CST. \r\n\r\nFor the issue released on {}, you can send your ad copy by replying to this email. If you want to use the same copy as the previous issue, no further action is required. \r\n\r\nIf you have an issues meeting the deadline or have any other questions, please let me know as soon as possible.\r\n\r\nHave a great rest of your week!', $.sponsor.contact.name, $.slot.date)"
}
},
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException",
"Lambda.TooManyRequestsException"
],
"IntervalSeconds": 2,
"MaxAttempts": 6,
"BackoffRate": 2
}
],
"End": true,
"Catch": [
{
"ErrorEquals": [
"States.ALL"
],
"Next": "Notify Of Failure"
}
]
},
"Notify Of Failure": {
"Type": "Task",
"Resource": "${LambdaInvoke}",
"OutputPath": "$.Payload",
"Parameters": {
"FunctionName": "${SendEmailFunction}",
"Payload": {
"to": "${AdminEmail}",
"subject": "Failed To Send Email Reminder",
"text": "Something went wrong trying to notify the sponsor of this week's newsletter ad copy."
}
},
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException",
"Lambda.TooManyRequestsException"
],
"IntervalSeconds": 2,
"MaxAttempts": 6,
"BackoffRate": 2
}
],
"Next": "End"
},
"End": {
"Type": "Pass",
"End": true
}
}
},
"ItemsPath": "$.sponsors",
"Parameters": {
"sponsor.$": "$$.Map.Item.Value",
"slot.$": "$.slot"
}
},
"Nothing To Do": {
"Type": "Succeed"
}
}
}