Skip to content

Commit 8e68b41

Browse files
authored
Merge pull request #60 from DEFRA/fix/DF-330-reply-to
Set replyTo for confirmation email
2 parents a2c989d + a780399 commit 8e68b41

6 files changed

Lines changed: 50 additions & 30 deletions

File tree

README.md

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,32 @@
22

33
Core delivery platform Node.js Backend Template.
44

5-
- [Requirements](#requirements)
6-
- [Node.js](#nodejs)
7-
- [Local development](#local-development)
8-
- [Setup](#setup)
9-
- [Development](#development)
10-
- [Testing](#testing)
11-
- [Production](#production)
12-
- [Npm scripts](#npm-scripts)
13-
- [Update dependencies](#update-dependencies)
14-
- [Formatting](#formatting)
15-
- [Windows prettier issue](#windows-prettier-issue)
16-
- [API endpoints](#api-endpoints)
17-
- [Development helpers](#development-helpers)
18-
- [Proxy](#proxy)
19-
- [Docker](#docker)
20-
- [Development image](#development-image)
21-
- [Production image](#production-image)
22-
- [Docker Compose](#docker-compose)
23-
- [Dependabot](#dependabot)
24-
- [SonarCloud](#sonarcloud)
25-
- [Licence](#licence)
26-
- [About the licence](#about-the-licence)
5+
- [forms-notify-listener](#forms-notify-listener)
6+
- [Requirements](#requirements)
7+
- [Node.js](#nodejs)
8+
- [Local development](#local-development)
9+
- [Setup](#setup)
10+
- [Development](#development)
11+
- [Development](#development-1)
12+
- [Testing](#testing)
13+
- [Production](#production)
14+
- [Notes on SQS queue configuration](#notes-on-sqs-queue-configuration)
15+
- [Queue configuration in forms-audit-api](#queue-configuration-in-forms-audit-api)
16+
- [Npm scripts](#npm-scripts)
17+
- [Update dependencies](#update-dependencies)
18+
- [Formatting](#formatting)
19+
- [Windows prettier issue](#windows-prettier-issue)
20+
- [API endpoints](#api-endpoints)
21+
- [Development helpers](#development-helpers)
22+
- [Proxy](#proxy)
23+
- [Docker](#docker)
24+
- [Development image](#development-image)
25+
- [Production image](#production-image)
26+
- [Docker Compose](#docker-compose)
27+
- [Dependabot](#dependabot)
28+
- [SonarCloud](#sonarcloud)
29+
- [Licence](#licence)
30+
- [About the licence](#about-the-licence)
2731

2832
## Requirements
2933

@@ -64,6 +68,7 @@ AWS_SECRET_ACCESS_KEY=dummy
6468
RECEIVE_MESSAGE_TIMEOUT_MS=5000
6569
NOTIFY_TEMPLATE_ID=3d448938-8a8b-40c2-a3de-414597f976e1
6670
NOTIFY_API_KEY=[your api key]
71+
NOTIFY_REPLY_TO_ID=462e5ac0-28f1-4e51-9d8e-8d8c31f59f6a
6772
RECEIVE_MESSAGE_TIMEOUT_MS=5000
6873
MANAGER_URL=http://localhost:3001
6974
DESIGNER_URL=http://localhost:3000

jest.setup.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
process.env.MANAGER_URL = 'http://manager'
22
process.env.DESIGNER_URL = 'http://designer'
33
process.env.NOTIFY_TEMPLATE_ID = '2d48d7f9-32ae-43be-9bf1-8bf5cd7bfc17'
4+
process.env.NOTIFY_REPLY_TO_ID = '462e5ac0-28f1-4e51-9d8e-8d8c31f59f6a'
45
process.env.NOTIFY_API_KEY = 'dummy'
6+
process.env.NOTIFY_CONFIRMATION_REPLY_TO_ID = 'dummy'

src/config/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,24 @@ export const config = convict({
110110
* Email outputs
111111
* Email outputs will use notify to send an email to a single inbox.
112112
*/
113+
/** @type {SchemaObj<string>} */
113114
notifyTemplateId: {
114115
format: String,
115116
default: null,
116117
env: 'NOTIFY_TEMPLATE_ID'
117118
},
119+
/** @type {SchemaObj<string>} */
118120
notifyAPIKey: {
119121
format: String,
120122
default: null,
121123
env: 'NOTIFY_API_KEY'
122124
},
125+
/** @type {SchemaObj<string>} */
126+
notifyReplyToId: {
127+
format: String,
128+
default: null,
129+
env: 'NOTIFY_REPLY_TO_ID'
130+
},
123131

124132
/**
125133
* API integrations

src/lib/notify.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { token } from '@hapi/jwt'
33
import { config } from '~/src/config/index.js'
44
import { postJson } from '~/src/lib/fetch.js'
55

6-
// @ts-expect-error - incorrect typings in convict
7-
const notifyAPIKey = /** @type {string} */ (config.get('notifyAPIKey'))
6+
const notifyAPIKey = config.get('notifyAPIKey')
87

98
const API_KEY_SUBSTRING_REDUCTION = 36
109
const SERVICE_ID_SUBSTRING_REDUCTION = 73
@@ -31,6 +30,7 @@ const serviceId = /** @type {string} */ (
3130
* templateId: string
3231
* emailAddress: string
3332
* personalisation: { subject: string; body: string }
33+
* notifyReplyToId?: string
3434
* }} SendNotificationArgs
3535
*/
3636

@@ -56,13 +56,14 @@ const NOTIFICATIONS_URL = new URL(
5656
* @returns {Promise<{response: object, body: unknown}>}
5757
*/
5858
export async function sendNotification(args) {
59-
const { templateId, emailAddress, personalisation } = args
59+
const { templateId, emailAddress, personalisation, notifyReplyToId } = args
6060

6161
return postJson(NOTIFICATIONS_URL, {
6262
payload: {
6363
template_id: templateId,
6464
email_address: emailAddress,
65-
personalisation
65+
personalisation,
66+
email_reply_to_id: notifyReplyToId
6667
},
6768
headers: {
6869
Authorization: 'Bearer ' + createToken(serviceId, apiKeyId)

src/service/notify.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import { sendNotification } from '~/src/lib/notify.js'
88
import { getFormatter } from '~/src/service/mappers/formatters/index.js'
99
import { getUserConfirmationEmailBody } from '~/src/service/mappers/user-confirmation.js'
1010

11-
// @ts-expect-error - incorrect typings in convict
12-
const templateId = /** @type {string} */ (config.get('notifyTemplateId'))
11+
const templateId = config.get('notifyTemplateId')
12+
13+
const notifyReplyToId = config.get('notifyReplyToId')
1314

1415
const logger = createLogger()
1516

@@ -168,7 +169,8 @@ export async function sendUserConfirmationEmail(formSubmissionMessage) {
168169
personalisation: {
169170
subject,
170171
body: getUserConfirmationEmailBody(formName, new Date(), metadata)
171-
}
172+
},
173+
notifyReplyToId
172174
})
173175

174176
logger.info(logTags, 'User confirmation email sent successfully')

src/service/notify.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jest.mock('~/src/config/index.js', () => ({
4242
config: {
4343
get: jest.fn((key) => {
4444
if (key === 'notifyTemplateId') return 'notify-template-id-1'
45+
if (key === 'notifyReplyToId') return 'notify-reply-to-id-1'
4546
return 'mock-value'
4647
})
4748
}
@@ -678,7 +679,8 @@ describe('notify', () => {
678679
personalisation: {
679680
subject: 'Form submitted to Defra',
680681
body: expect.any(String)
681-
}
682+
},
683+
notifyReplyToId: 'notify-reply-to-id-1'
682684
})
683685
const sendNotificationBody = JSON.parse(
684686
Buffer.from(

0 commit comments

Comments
 (0)