Skip to content

Commit

Permalink
rework send email state machine (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
MEPalma authored Nov 26, 2024
1 parent cc77d27 commit 30ad79a
Showing 1 changed file with 58 additions and 47 deletions.
105 changes: 58 additions & 47 deletions configurations/statemachine.json
Original file line number Diff line number Diff line change
@@ -1,56 +1,67 @@
{
"StartAt": "CheckEmail",
"States": {
"CheckEmail": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.Email",
"IsPresent": true,
"Next": "SendEmail"
}
],
"Default": "NoEmailProvided"
},
"SendEmail": {
"Type": "Task",
"Resource": "arn:aws:states:::aws-sdk:sesv2:sendEmail",
"Parameters": {
"FromEmailAddress": "[email protected]",
"Destination": {
"ToAddresses": ["$.Email"]
"QueryLanguage": "JSONata",
"StartAt": "CheckEmail",
"States": {
"CheckEmail": {
"Type": "Choice",
"Choices": [
{
"Condition": "{% $exists($states.input.Email) %}",
"Assign": {
"email": "{% $states.input.Email %}",
"username": "{% $states.input.Username %}",
"score": "{% $states.input.Score %}"
},
"Content": {
"Simple": {
"Subject": {
"Data": "Your Quiz Results",
"Next": "SendEmail"
}
],
"Default": "NoEmailProvided"
},
"SendEmail": {
"Type": "Task",
"Resource": "arn:aws:states:::aws-sdk:sesv2:sendEmail",
"Arguments": {
"FromEmailAddress": "[email protected]",
"Destination": {
"ToAddresses": [
"{% $email %}"
]
},
"Content": {
"Simple": {
"Subject": {
"Data": "Your Quiz Results",
"Charset": "UTF-8"
},
"Body": {
"Html": {
"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>' %}",
"Charset": "UTF-8"
},
"Body": {
"Html": {
"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)",
"Charset": "UTF-8"
}
}
}
}
},
"End": true,
"Catch": [
{
"ErrorEquals": ["States.ALL"],
"Next": "EmailFailed"
}
]
},
"NoEmailProvided": {
"Type": "Succeed"
}
},
"EmailFailed": {
"Type": "Fail",
"Error": "EmailSendingFailed",
"Cause": "Failed to send email."
}
"End": true,
"Catch": [
{
"ErrorEquals": [
"States.ALL"
],
"Assign": {
"send_email_error": "{% $states.errorOutput %}"
},
"Next": "EmailFailed"
}
]
},
"NoEmailProvided": {
"Type": "Succeed"
},
"EmailFailed": {
"Type": "Fail",
"Error": "EmailSendingFailed",
"Cause": "{% $string($send_email_error) %}"
}
}
}

0 comments on commit 30ad79a

Please sign in to comment.