From 14c9673aeedfcbc6bb3f12019a021d68eb20dd61 Mon Sep 17 00:00:00 2001 From: Benjamin Okkema Date: Tue, 29 Oct 2024 22:16:28 -0500 Subject: [PATCH] feat: add contact notification email --- package.json | 2 +- src/pages/message.ts | 7 ++++++- src/services/EmailService.ts | 5 +++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index dd8e2a6..7b0fe82 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "build": "npm-run-all build:blog test", "build:blog": "astro build", - "build:worker": "npx wrangler deploy src/functions/index.ts --dry-run --outdir build", + "build:worker": "wrangler deploy src/functions/index.ts --dry-run --outdir build", "migrate:local": "wrangler d1 migrations apply blog --local", "migrate:remote": "wrangler d1 migrations apply blog --remote", "start": "npm-run-all migrate:local start:blog", diff --git a/src/pages/message.ts b/src/pages/message.ts index ed3f5aa..a9d890a 100644 --- a/src/pages/message.ts +++ b/src/pages/message.ts @@ -35,7 +35,12 @@ export async function POST(context: APIContext) { message: "No robots allowed!" }) - await context.locals.runtime.env.BLOG.put(`messages/${data.email}/${new Date().toISOString()}.txt`, data.message) + const key = `messages/${data.email}/${new Date().toISOString()}.txt` + await context.locals.runtime.env.BLOG.put(key, data.message) + await EmailService(context.locals.runtime.env).send({ + subject: `New message from ${data.email}`, + body: `Key: ${key}\n\n---\n\n${data.message}`, + }) return json({ ok: true, diff --git a/src/services/EmailService.ts b/src/services/EmailService.ts index a0eb998..a177d3b 100644 --- a/src/services/EmailService.ts +++ b/src/services/EmailService.ts @@ -1,11 +1,12 @@ import { Problem } from "@okkema/worker" export type Email = { - to: { + to?: { email: string }[] subject: string - html: string + html?: string + body?: string } type EmailService = {