import { Hono } from "hono";
import { SpacePost } from "@spacepost/node";
type Env = { Bindings: { SPACEPOST_API_KEY: string; SPACEPOST_WEBHOOK_SECRET: string } };
const app = new Hono<Env>();
app.post("/send", async (c) => {
const spacepost = new SpacePost(c.env.SPACEPOST_API_KEY);
const { to } = await c.req.json<{ to: string }>();
const { data, error } = await spacepost.emails.send({
from: "Acme <hello@acme.com>",
subject: "Hello from Hono",
html: "<p>Sent from the edge.</p>",
if (error) return c.json(error, (error.statusCode ?? 500) as 400);
app.post("/webhooks/spacepost", async (c) => {
const spacepost = new SpacePost(c.env.SPACEPOST_API_KEY);
const event = await spacepost.webhooks.verify({
payload: await c.req.text(), // raw body
headers: c.req.raw.headers,
secret: c.env.SPACEPOST_WEBHOOK_SECRET,
return c.body(null, 200);
return c.body(null, 400);