Public
Back
Version 4
1/13/2025
import addresses from "https://esm.sh/email-addresses";
import processEmail from "https://esm.town/v/paulkinlan/emailToLLM";
import { email } from "https://esm.town/v/std/email";
import { extractValInfo } from "https://esm.town/v/stevekrouse/extractValInfo";
import { OpenAI } from "npm:openai";
function stripHtmlBackticks(html: string): string {
return html.replace(/^```html\n?/, "").replace(/\n?```$/, "");
}
export default async function(e: Email) {
const openai = new OpenAI();
console.log(`from: ${e.from} to: ${e.to} subject: ${e.subject}, cc: ${e.cc}, bcc: ${e.bcc}`);
let { from, to, subject } = e;
const toAddr = addresses.parseOneAddress(to);
const { name, local, address } = toAddr;
console.log(`Parsed to address: ${name}, ${local}, ${address}`);
if (address != extractValInfo(import.meta.url).email) {
// This should only trigger for emails from Paul because he was able to enable auto-forwarding. No one else can autoforward because they can't confirm they own this address.
console.log("Email might be an auto forwarded email.");
from = to;
}
const prompt =
`You are a helpful analyst assistant. Provide a concise, professional critique and possible biases of the email content in HTML format optimized for email clients. Use only basic HTML tags like <p>, <strong>, <em>, <ul>, <li>, and <br>. Avoid using <div>, <span>, or any advanced HTML5 elements. Do not include any CSS or JavaScript. Keep the structure simple and focused on content.`;
return await processEmail(e, prompt, {
replyFromEmail: extractValInfo(import.meta.url).email,
replyFromName: "Critique Service",
subject: `Criticque of ${subject}`, // e.subject,
});
}
Updated: January 13, 2025