Skip to content

Commit 2026938

Browse files
committed
Add functionality for displaying params in email
This takes input from the user and displays it in a preview email template for sending out comms for planned maintenance, unexpected extension to planned maintenance and an outage with a few presets
1 parent 7cee5e8 commit 2026938

File tree

6 files changed

+135
-0
lines changed

6 files changed

+135
-0
lines changed
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import fs from "fs"
2+
import path from "path"
3+
import { confirm } from "@inquirer/prompts"
4+
import nunjucks from "nunjucks"
5+
6+
export const outage = async (outageType: string) => {
7+
const templateFile = "outage.txt"
8+
const templatePath = path.join("./commands/user-comms/templates", templateFile)
9+
const templateContent = fs.readFileSync(templatePath, "utf-8")
10+
11+
const renderedEmail = nunjucks.renderString(templateContent, {
12+
outageType: outageType
13+
})
14+
15+
console.log("\n=== Preview Email ===\n")
16+
console.log(renderedEmail)
17+
18+
const answer = await confirm({ message: "Do you want to use this template?" })
19+
20+
if (!answer) {
21+
process.exit(1)
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import fs from "fs"
2+
import path from "path"
3+
import { input, confirm } from "@inquirer/prompts"
4+
import nunjucks from "nunjucks"
5+
import { parse, format, isValid } from "date-fns"
6+
7+
export const pncMaintenance = async () => {
8+
const templateFile = "pnc-maintenance.txt"
9+
const templatePath = path.join("./commands/user-comms/templates", templateFile)
10+
const templateContent = fs.readFileSync(templatePath, "utf-8")
11+
12+
const dateInput = await input({ message: "Enter the date (dd/MM/yyyy)" })
13+
const startTime = await input({ message: "Enter start time (HH:mm)" })
14+
const endTime = await input({ message: "Enter end time (HH:mm)" })
15+
16+
const parsedDate = parse(dateInput, "dd/MM/yyyy", new Date())
17+
18+
if (!isValid(parsedDate)) {
19+
console.error("Invalid date format. Please use 'dd/MM/yyyy' (e.g., '17/03/2025').")
20+
return
21+
}
22+
23+
const formattedDate = format(parsedDate, "EEEE d MMMM yyyy")
24+
25+
const renderedEmail = nunjucks.renderString(templateContent, {
26+
date: formattedDate,
27+
startTime: startTime,
28+
endTime: endTime
29+
})
30+
31+
console.log("\n=== Preview Email ===\n")
32+
console.log(renderedEmail)
33+
34+
const answer = await confirm({ message: "Do you want to use this template?" })
35+
36+
if (!answer) {
37+
process.exit(1)
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import fs from "fs"
2+
import path from "path"
3+
import { confirm, select } from "@inquirer/prompts"
4+
import nunjucks from "nunjucks"
5+
6+
export const pncMaintenanceExtended = async () => {
7+
const templateFile = "pnc-maintenance-extended.txt"
8+
const templatePath = path.join("./commands/user-comms/templates", templateFile)
9+
const templateContent = fs.readFileSync(templatePath, "utf-8")
10+
11+
const extendedTimeFrameInput = await select({
12+
message: "Select a time frame",
13+
choices: [
14+
{
15+
name: "1 hour",
16+
value: "1 hour",
17+
description: "The extended time frame is estimated at 1 hour"
18+
},
19+
{
20+
name: "2 hour",
21+
value: "2 hour",
22+
description: "The extended time frame is estimated at 2 hour"
23+
}
24+
]
25+
})
26+
27+
const renderedEmail = nunjucks.renderString(templateContent, {
28+
extendedTimeFrame: extendedTimeFrameInput
29+
})
30+
31+
console.log("\n=== Preview Email ===\n")
32+
console.log(renderedEmail)
33+
34+
const answer = await confirm({ message: "Do you want to use this template?" })
35+
36+
if (!answer) {
37+
process.exit(1)
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Hello {{ firstName | default("first-name") }},
2+
3+
We wanted to inform you that the {{ outageType }} is currently experiencing a loss of service. We apologise for any inconvenience this may cause.
4+
5+
We will keep you informed of any updates as soon as we receive them.
6+
7+
If you have any questions, please feel free to contact us at moj-bichard7@madetech.com.
8+
9+
Thank you for your patience and understanding.
10+
11+
Many thanks,
12+
The Bichard 7 Support team
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Hello {{ firstName | default("first-name") }},
2+
3+
We regret to inform you that the PNC planned maintenance has be unexpectedly extended.
4+
We have been informed that the on going work should be resolved in {{ extendedTimeFrame }}
5+
6+
This is an estimated time, so we apologise for the inconvenience and appreciate your patience.
7+
We will keep you informed on any changes
8+
9+
Thank you,
10+
The Bichard 7 Support team
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Hello {{ firstName | default("first-name") }},
2+
3+
As a part of ongoing work to maintain and improve Bichard 7 and the PNC, there will be an impact on service during the following window:
4+
5+
{{ day }} {{ date }} {{ startTime }} - {{ endTime }}
6+
7+
During this window, the PNC will be unavailable. Any messages submitted will cause an error message to be displayed and will need to be resubmitted after the change window.
8+
9+
We apologise for the inconvenience and appreciate your patience.
10+
11+
Thank you,
12+
The Bichard 7 Support team

0 commit comments

Comments
 (0)