Skip to content
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

feat: added support for html email #2785

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"joi-strict": "3.0.1",
"lambda-async": "3.0.0",
"lambda-cfn-hook": "3.0.5",
"lambda-monitor-logger": "5.0.1",
"lambda-monitor-logger": "5.1.0",
"lodash.get": "4.4.2",
"lru-cache-ext": "4.0.0",
"object-scan": "19.0.5",
Expand Down
4 changes: 2 additions & 2 deletions src/logic/logger/message/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default ({ logEvent }) => {
}
try {
const {
from, to, subject, body
from, to, subject, body, html = false
} = JSON.parse(logEvent.message);
request.enqueue({
method: 'POST',
Expand All @@ -19,7 +19,7 @@ export default ({ logEvent }) => {
from: { email: from },
personalizations: [{ to: [{ email: to }] }],
subject,
content: [{ type: 'text/plain', value: body }],
content: [{ type: html === true ? 'text/html' : 'text/plain', value: body }],
tracking_settings: {
click_tracking: {
enable: false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[
{
"scope": "https://api.sendgrid.com:443",
"method": "POST",
"path": "/v3/mail/send",
"body": {
"from": {
"email": "source@test.com"
},
"personalizations": [
{
"to": [
{
"email": "target@test.com"
}
]
}
],
"subject": "subject text",
"content": [
{
"type": "text/html",
"value": "body text"
}
],
"tracking_settings": {
"click_tracking": {
"enable": false
}
}
},
"status": 202,
"response": "",
"responseIsBinary": false
}
]
53 changes: 53 additions & 0 deletions test/lambda/tests/processLogs/email-html.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"handler": "processLogs",
"envVars": {
"SENDGRID_API_KEY": "SENDGRID_API_KEY"
},
"timestamp": 1559595312,
"success": true,
"timeout": 10000,
"allowedOutOfOrderRecordings": [
"POST https://api.datadoghq.com:443/api/v1/distribution_points?api_key=DATADOG_API_KEY"
],
"expect": {
"to.deep.equal()": {
"messageType": "DATA_MESSAGE",
"owner": "783629116497",
"logGroup": "/aws/lambda/peg-solitiare-dev-overview",
"logStream": "2017/11/23/[$LATEST]e680fe32c6ba48ce8c3a377a25cd488e",
"subscriptionFilters": [
"NoneFilter"
],
"logEvents": [
{
"id": "33705477413970201536500575666792700703924347154117689346",
"timestamp": 1511405879665,
"message": "2017-11-23T02:57:59.665Z 1c2a7f3e-cffa-11e7-aa7b-d3cd50f70cb0 EMAIL: {\"from\":\"source@test.com\",\"to\":\"target@test.com\",\"subject\":\"subject text\",\"body\":\"body text\",\"html\":true}\n\n"
}
]
}
},
"logs": {
"to.deep.equal()": []
},
"event": {
"awslogs": {
"data|JSON.stringify|toGzip|toBase64": {
"messageType": "DATA_MESSAGE",
"owner": "783629116497",
"logGroup": "/aws/lambda/peg-solitiare-dev-overview",
"logStream": "2017/11/23/[$LATEST]e680fe32c6ba48ce8c3a377a25cd488e",
"subscriptionFilters": [
"NoneFilter"
],
"logEvents": [
{
"id": "33705477413970201536500575666792700703924347154117689346",
"timestamp": 1511405879665,
"message": "2017-11-23T02:57:59.665Z 1c2a7f3e-cffa-11e7-aa7b-d3cd50f70cb0 EMAIL: {\"from\":\"source@test.com\",\"to\":\"target@test.com\",\"subject\":\"subject text\",\"body\":\"body text\",\"html\":true}\n\n"
}
]
}
}
}
}
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4138,6 +4138,13 @@ lambda-monitor-logger@5.0.1:
dependencies:
joi-strict "3.0.0"

lambda-monitor-logger@5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/lambda-monitor-logger/-/lambda-monitor-logger-5.1.0.tgz#59ec500340c1567954336017b720b819280650e6"
integrity sha512-M+f1/RrCDnBBkZ0nwrYLFG2h/BeXQDwKZ+T6TPAEmpQ48WNn7suRPQgQRdypZ3nKJmvk0cQmusIEKoj9XyxiWA==
dependencies:
joi-strict "3.0.0"

lambda-tdd@7.0.7:
version "7.0.7"
resolved "https://registry.yarnpkg.com/lambda-tdd/-/lambda-tdd-7.0.7.tgz#ce198313360d8035089a6507788362027dfeb5b4"
Expand Down