-
Notifications
You must be signed in to change notification settings - Fork 1
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
Email SeS implementation #19
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work here! Left some general comments
formatted_string = json.dumps(class_dict) # Try to convert to a JSON string | ||
except (TypeError, ValueError) as e: | ||
# Handle errors and return a message instead | ||
return f"Error in converting data to JSON: {e}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're planning on using this as the basis of other template data, I think we should propagate the error instead of gracefully failing, especially if this is being sent by email.
|
||
|
||
@dataclass | ||
class EmailContent(Generic[T]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: let's call T EmailData
or EmailPayload
to be more concrete
Cool use of generics in this situation though!
T = TypeVar("T") | ||
|
||
|
||
class TemplateData(ABC): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be able to move this to a schema file? Given that routes
is using this too, maybe we should treat this the same as a schema.
date: str | ||
|
||
|
||
class EmailTemplate(Enum): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we name this EmailTemplateType
to signal that it's an enum?
def send_email( | ||
self, recipient: str, subject: str, body_html: str, body_text: str | ||
) -> dict: | ||
def send_email(self, template: EmailTemplate, content: EmailContent) -> dict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto template
vs templateType
, as template could be a full formed template class.
aws_secret_key: str, | ||
region: str, | ||
source_email: str, | ||
is_sandbox: bool = True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does is_sandbox
do? For quick glancers, would you be able to leave a comment describing this option.
try: | ||
self._verify_email(content.recipient) | ||
|
||
self.ses_client.get_template(TemplateName=template.value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this line do right now? Should it be getting a response value?
|
||
self.ses_client.get_template(TemplateName=template.value) | ||
|
||
template_data = content.data.get_formatted_string() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Imo you should group this with self._verify_email(content.recipient)
, I got confused for a second reading the code given that get_template
doesn't return anything right now.
return "" | ||
|
||
|
||
templates_metadata = load_templates_metadata(TEMPLATES_FILE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this into ensure_ses_templates
template = { | ||
"TemplateName": template_metadata["TemplateName"], | ||
"SubjectPart": template_metadata["SubjectPart"], | ||
"TextPart": text_part, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: needed when user can't see HTML content, but HTML is default. https://docs.aws.amazon.com/ses/latest/APIReference/API_Template.html
Notion ticket link
Setup Email System
NOTE THIS IS A PR for feedback not to merge.
Will be removing email.py route as its simply there right now for testing
will be removing todos and adding comments
will be removing any prints or updating them to logs
Implementation description
Process to create a new Email Template to use:
backend/app/utilities/ses/ses_templates.json
to include template name subject and absolute paths to the above fileses_templates.json
fileTodo
Steps to test
/email/send-test
email route when running the be on localWhat should reviewers focus on?
Checklist