Skip to content

Commit 30ad79a

Browse files
authored
rework send email state machine (#17)
1 parent cc77d27 commit 30ad79a

File tree

1 file changed

+58
-47
lines changed

1 file changed

+58
-47
lines changed

configurations/statemachine.json

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,67 @@
11
{
2-
"StartAt": "CheckEmail",
3-
"States": {
4-
"CheckEmail": {
5-
"Type": "Choice",
6-
"Choices": [
7-
{
8-
"Variable": "$.Email",
9-
"IsPresent": true,
10-
"Next": "SendEmail"
11-
}
12-
],
13-
"Default": "NoEmailProvided"
14-
},
15-
"SendEmail": {
16-
"Type": "Task",
17-
"Resource": "arn:aws:states:::aws-sdk:sesv2:sendEmail",
18-
"Parameters": {
19-
"FromEmailAddress": "[email protected]",
20-
"Destination": {
21-
"ToAddresses": ["$.Email"]
2+
"QueryLanguage": "JSONata",
3+
"StartAt": "CheckEmail",
4+
"States": {
5+
"CheckEmail": {
6+
"Type": "Choice",
7+
"Choices": [
8+
{
9+
"Condition": "{% $exists($states.input.Email) %}",
10+
"Assign": {
11+
"email": "{% $states.input.Email %}",
12+
"username": "{% $states.input.Username %}",
13+
"score": "{% $states.input.Score %}"
2214
},
23-
"Content": {
24-
"Simple": {
25-
"Subject": {
26-
"Data": "Your Quiz Results",
15+
"Next": "SendEmail"
16+
}
17+
],
18+
"Default": "NoEmailProvided"
19+
},
20+
"SendEmail": {
21+
"Type": "Task",
22+
"Resource": "arn:aws:states:::aws-sdk:sesv2:sendEmail",
23+
"Arguments": {
24+
"FromEmailAddress": "[email protected]",
25+
"Destination": {
26+
"ToAddresses": [
27+
"{% $email %}"
28+
]
29+
},
30+
"Content": {
31+
"Simple": {
32+
"Subject": {
33+
"Data": "Your Quiz Results",
34+
"Charset": "UTF-8"
35+
},
36+
"Body": {
37+
"Html": {
38+
"Data": "{% '<html><body><h2>Hello ' & $username & '</h2><p>Congratulations on completing the quiz!</p><p><strong>Your Score:</strong> ' & $score & '.</p><p>Best regards,<br/>LocalStack Team</p></body></html>' %}",
2739
"Charset": "UTF-8"
28-
},
29-
"Body": {
30-
"Html": {
31-
"Data.$": "States.Format('<html><body><h2>Hello {}</h2><p>Congratulations on completing the quiz!</p><p><strong>Your Score:</strong> {}.</p><p>Best regards,<br/>LocalStack Team</p></body></html>', $.Username, $.Score)",
32-
"Charset": "UTF-8"
33-
}
3440
}
3541
}
3642
}
37-
},
38-
"End": true,
39-
"Catch": [
40-
{
41-
"ErrorEquals": ["States.ALL"],
42-
"Next": "EmailFailed"
43-
}
44-
]
45-
},
46-
"NoEmailProvided": {
47-
"Type": "Succeed"
43+
}
4844
},
49-
"EmailFailed": {
50-
"Type": "Fail",
51-
"Error": "EmailSendingFailed",
52-
"Cause": "Failed to send email."
53-
}
45+
"End": true,
46+
"Catch": [
47+
{
48+
"ErrorEquals": [
49+
"States.ALL"
50+
],
51+
"Assign": {
52+
"send_email_error": "{% $states.errorOutput %}"
53+
},
54+
"Next": "EmailFailed"
55+
}
56+
]
57+
},
58+
"NoEmailProvided": {
59+
"Type": "Succeed"
60+
},
61+
"EmailFailed": {
62+
"Type": "Fail",
63+
"Error": "EmailSendingFailed",
64+
"Cause": "{% $string($send_email_error) %}"
5465
}
5566
}
56-
67+
}

0 commit comments

Comments
 (0)