Skip to content

Commit d32cbe8

Browse files
authored
fix: Format email text as html (#94)
1 parent ab1efae commit d32cbe8

5 files changed

Lines changed: 54 additions & 11 deletions

File tree

app/poetry.lock

Lines changed: 29 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ en-core-web-lg = {url = "https://github.com/explosion/spacy-models/releases/down
3636
pypdf = "^6.1.3"
3737
arize-phoenix = "^11.37.0"
3838
pip = ">=25.3"
39+
markdown = "^3.10"
3940

4041
[tool.poetry.group.dev.dependencies]
4142
certifi = "^2025.8.3"
@@ -56,6 +57,7 @@ setuptools = "^78.1.1"
5657
debugpy = "^1.8.1"
5758
ruff = "^0.4.9"
5859
types-requests = "^2.32.4.20250913"
60+
types-markdown = "^3.9.0.20250906"
5961

6062
[build-system]
6163
requires = ["poetry-core>=1.0.0"]

app/src/common/components.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ def run(
199199
return {"replies": [ChatMessage.from_assistant(response.output_text)]}
200200

201201

202+
EMAIL_INTRO = """\
203+
Hello,
204+
205+
Here is your personalized report with resources your case manager recommends to support your goals.
206+
You've already taken a great first step by exploring these options.
207+
208+
**Your next step**: Look over the resources to see contact info and details about how to get started.
209+
"""
210+
211+
202212
@component
203213
class EmailResult:
204214
"""
@@ -210,7 +220,7 @@ def run(self, email: str, json_dict: dict) -> dict:
210220
logger.info("Emailing result to %s", email)
211221
logger.debug("JSON content:\n%s", json.dumps(json_dict, indent=2))
212222
formatted_resources = self.format_resources(json_dict.get("resources", []))
213-
message = f"Here are the resources you requested:\n\n{formatted_resources}"
223+
message = f"{EMAIL_INTRO}\n{formatted_resources}"
214224

215225
# Send email via AWS SES
216226
subject = "Your Requested Resources"
@@ -225,14 +235,13 @@ def format_resources(self, resources: list[dict]) -> str:
225235
def format_resource(self, resource: dict) -> str:
226236
return "\n".join(
227237
[
228-
f"{resource.get('name', 'Unnamed Resource')}",
238+
f"### {resource.get('name', 'Unnamed Resource')}",
229239
f"- Referral Type: {resource.get('referral_type', 'None')}",
230240
f"- Description: {resource.get('description', 'None')}",
231241
f"- Website: {resource.get('website', 'None')}",
232242
f"- Phone: {', '.join(resource.get('phones', ['None']))}",
233243
f"- Email: {', '.join(resource.get('emails', ['None']))}",
234244
f"- Addresses: {', '.join(resource.get('addresses', ['None']))}",
235-
f"- Justification: {resource.get('justification', 'None')}",
236245
]
237246
)
238247

app/src/common/send_email.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22

33
import boto3
4+
import markdown
45
from botocore.exceptions import ClientError
56

67
from src.app_config import config
@@ -32,7 +33,7 @@ def send_email(recipient: str, subject: str, body: str) -> bool:
3233
"Simple": {
3334
"Subject": {"Data": subject, "Charset": "UTF-8"},
3435
"Body": {
35-
"Html": {"Data": body, "Charset": "UTF-8"},
36+
"Html": {"Data": markdown.markdown(body), "Charset": "UTF-8"},
3637
"Text": {"Data": body, "Charset": "UTF-8"},
3738
},
3839
}

app/tests/src/common/test_components.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,25 +115,28 @@ def test_EmailResult(enable_factory_create, db_session: db.Session, monkeypatch)
115115
assert output["email"] == "test@example.com"
116116
assert output["message"] == dedent(
117117
"""\
118-
Here are the resources you requested:
118+
Hello,
119119
120-
Resource 1
120+
Here is your personalized report with resources your case manager recommends to support your goals.
121+
You've already taken a great first step by exploring these options.
122+
123+
**Your next step**: Look over the resources to see contact info and details about how to get started.
124+
125+
### Resource 1
121126
- Referral Type: external
122127
- Description: Description for Resource 1
123128
- Website: http://resource1.com
124129
- Phone: 555-1234
125130
- Email: resource1@example.com
126131
- Addresses: 123 Main St
127-
- Justification: Justification for Resource 1
128132
129-
Resource 2
133+
### Resource 2
130134
- Referral Type: None
131135
- Description: None
132136
- Website: None
133137
- Phone: None
134138
- Email: None
135-
- Addresses: None
136-
- Justification: None"""
139+
- Addresses: None"""
137140
)
138141

139142

0 commit comments

Comments
 (0)