mirror of
https://github.com/anomalyco/opencode.git
synced 2026-07-17 12:56:41 +02:00
bc3fe8f4f5
Extract delivery logic from the enterprise route into a dedicated module that grades inquiries via the Zen responses API, falls back to simple regex scoring on failure, and sends templated auto-replies for generic and procurement-blocked leads. Made-with: Cursor
71 lines
1.9 KiB
TypeScript
71 lines
1.9 KiB
TypeScript
import { z } from "zod"
|
|
import { Resource } from "@opencode-ai/console-resource"
|
|
import { AwsClient } from "aws4fetch"
|
|
import { fn } from "./util/fn"
|
|
|
|
export namespace AWS {
|
|
let client: AwsClient
|
|
|
|
const createClient = () => {
|
|
if (!client) {
|
|
client = new AwsClient({
|
|
accessKeyId: Resource.AWS_SES_ACCESS_KEY_ID.value,
|
|
secretAccessKey: Resource.AWS_SES_SECRET_ACCESS_KEY.value,
|
|
region: "us-east-1",
|
|
})
|
|
}
|
|
return client
|
|
}
|
|
|
|
export const sendEmail = fn(
|
|
z.object({
|
|
from: z.string().optional(),
|
|
to: z.string(),
|
|
subject: z.string(),
|
|
body: z.string(),
|
|
text: z.string().optional(),
|
|
html: z.string().optional(),
|
|
replyTo: z.string().optional(),
|
|
}),
|
|
async (input) => {
|
|
const text = input.text ?? input.body
|
|
const html = input.html ?? input.body
|
|
const res = await createClient().fetch("https://email.us-east-1.amazonaws.com/v2/email/outbound-emails", {
|
|
method: "POST",
|
|
headers: {
|
|
"X-Amz-Target": "SES.SendEmail",
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({
|
|
FromEmailAddress: input.from ?? "OpenCode Zen <contact@anoma.ly>",
|
|
Destination: {
|
|
ToAddresses: [input.to],
|
|
},
|
|
...(input.replyTo && { ReplyToAddresses: [input.replyTo] }),
|
|
Content: {
|
|
Simple: {
|
|
Subject: {
|
|
Charset: "UTF-8",
|
|
Data: input.subject,
|
|
},
|
|
Body: {
|
|
Text: {
|
|
Charset: "UTF-8",
|
|
Data: text,
|
|
},
|
|
Html: {
|
|
Charset: "UTF-8",
|
|
Data: html,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
})
|
|
if (!res.ok) {
|
|
throw new Error(`Failed to send email: ${res.statusText}`)
|
|
}
|
|
},
|
|
)
|
|
}
|