Elffuss BraidHub

kikocis/clonagent public

main · 6.3 KiBRawPermalink
1// Transactional email via the docker-mailserver (SMTP on localhost:587).
2// Set SMTP_* env vars to override; works with any SMTP provider.
3const nodemailer = require('nodemailer');
4
5const FROM_NAME = process.env.SMTP_FROM_NAME || 'ClonAgent';
6const FROM_ADDRESS = process.env.SMTP_FROM_ADDRESS || 'noreply@bot.utopiaia.com';
7
8function createTransport() {
9 if (process.env.SMTP_HOST) {
10 return nodemailer.createTransport({
11 host: process.env.SMTP_HOST,
12 port: parseInt(process.env.SMTP_PORT || '587', 10),
13 secure: process.env.SMTP_SECURE === '1',
14 auth: process.env.SMTP_USER ? {
15 user: process.env.SMTP_USER,
16 pass: process.env.SMTP_PASS,
17 } : undefined,
18 });
19 }
20 // SendGrid via env
21 if (process.env.SENDGRID_API_KEY) {
22 return nodemailer.createTransport({
23 host: 'smtp.sendgrid.net',
24 port: 587,
25 auth: { user: 'apikey', pass: process.env.SENDGRID_API_KEY },
26 });
27 }
28 // Fallback: log to console (dev mode)
29 return null;
30}
31
32async function send({ to, subject, html, text }) {
33 const transport = createTransport();
34 if (!transport) {
35 console.log(`[mailer] (no SMTP configured) To: ${to} | Subject: ${subject}`);
36 return;
37 }
38 await transport.sendMail({
39 from: `"${FROM_NAME}" <${FROM_ADDRESS}>`,
40 to,
41 subject,
42 html,
43 text: text || html.replace(/<[^>]+>/g, ''),
44 });
45}
46
47async function sendWelcome({ to, name }) {
48 const url = process.env.PUBLIC_URL || 'https://clonagent.utopiaia.com';
49 await send({
50 to,
51 subject: `Welcome to ClonAgent, ${name} — your AI engineer is ready`,
52 html: `
53 <div style="font-family:sans-serif;max-width:520px;margin:auto;color:#e2e8f0;background:#0f1117;padding:36px;border-radius:12px">
54 <h1 style="color:#a78bfa;margin:0 0 4px;font-size:22px">Welcome, ${name} 👋</h1>
55 <p style="color:#94a3b8;margin:0 0 24px;font-size:15px">Your ClonAgent is ready. Here's how to get your first agent running in 5 minutes.</p>
56
57 <div style="background:#171b22;border-radius:10px;padding:20px;margin-bottom:20px">
58 <p style="margin:0 0 12px;font-weight:600;color:#e2e8f0">What ClonAgent does</p>
59 <p style="margin:0;color:#94a3b8;font-size:14px;line-height:1.6">
60 You give it a project (a website, an app, any code). It watches an email inbox.
61 When someone authorized emails a bug or request, ClonAgent reads it, fixes the code,
62 deploys the fix, and replies with the result — automatically, while you sleep.
63 </p>
64 </div>
65
66 <p style="font-weight:600;color:#e2e8f0;margin:0 0 12px">3 steps to get started:</p>
67 <table style="width:100%;border-collapse:collapse">
68 <tr>
69 <td style="vertical-align:top;padding:8px 12px 8px 0;color:#7c5cff;font-weight:700;white-space:nowrap">Step 1</td>
70 <td style="padding:8px 0;color:#94a3b8;font-size:14px">Open the chat and describe your agent: what project it manages, who can email it, and how to deploy.</td>
71 </tr>
72 <tr>
73 <td style="vertical-align:top;padding:8px 12px 8px 0;color:#7c5cff;font-weight:700;white-space:nowrap">Step 2</td>
74 <td style="padding:8px 0;color:#94a3b8;font-size:14px">ClonAgent creates everything for you. Just drop in your Gmail credentials (takes 2 minutes).</td>
75 </tr>
76 <tr>
77 <td style="vertical-align:top;padding:8px 12px 8px 0;color:#7c5cff;font-weight:700;white-space:nowrap">Step 3</td>
78 <td style="padding:8px 0;color:#94a3b8;font-size:14px">Turn it on. From now on, manage it entirely by email — send <strong style="color:#e2e8f0">!help</strong> to your bot's inbox to see all commands.</td>
79 </tr>
80 </table>
81
82 <div style="text-align:center;margin-top:28px">
83 <a href="${url}/chat"
84 style="display:inline-block;background:#7c5cff;color:#fff;padding:14px 32px;border-radius:8px;text-decoration:none;font-weight:600;font-size:15px">
85 Create my first agent →
86 </a>
87 </div>
88
89 <div style="margin-top:28px;padding-top:20px;border-top:1px solid #1f2330">
90 <p style="color:#475569;font-size:12px;margin:0">Once your agent is running, you can manage it entirely from email:</p>
91 <p style="color:#64748b;font-size:12px;font-family:monospace;margin:8px 0 0;line-height:1.8">
92 !status &nbsp;·&nbsp; !add someone@company.com &nbsp;·&nbsp; !pause &nbsp;·&nbsp; !resume
93 </p>
94 </div>
95
96 <p style="color:#334155;font-size:11px;margin-top:20px">
97 Created by Kiko Cisneros for <a href="https://utopiaia.com" style="color:#475569">Utopia IA</a>
98 </p>
99 </div>`,
100 });
101}
102
103async function sendUpgradeConfirmation({ to, name, plan }) {
104 await send({
105 to,
106 subject: `You're on the ${plan} plan — ClonAgent`,
107 html: `
108 <div style="font-family:sans-serif;max-width:480px;margin:auto;color:#e2e8f0;background:#0f1117;padding:32px;border-radius:12px">
109 <h1 style="color:#34d399;margin:0 0 8px">You're on ${plan}!</h1>
110 <p>Hi ${name}, your ClonAgent subscription is active. Enjoy your expanded limits.</p>
111 <a href="${process.env.PUBLIC_URL || 'https://clonagent.utopiaia.com'}/billing"
112 style="display:inline-block;background:#7c5cff;color:#fff;padding:10px 20px;border-radius:8px;text-decoration:none;margin-top:12px">
113 Manage billing →
114 </a>
115 </div>`,
116 });
117}
118
119async function sendPasswordReset({ to, name, token }) {
120 const link = `${process.env.PUBLIC_URL || 'https://clonagent.utopiaia.com'}/reset-password?token=${token}`;
121 await send({
122 to,
123 subject: 'Reset your ClonAgent password',
124 html: `
125 <div style="font-family:sans-serif;max-width:480px;margin:auto;color:#e2e8f0;background:#0f1117;padding:32px;border-radius:12px">
126 <h1 style="color:#a78bfa;margin:0 0 8px">Reset your password</h1>
127 <p>Hi ${name}, click below to set a new password. This link expires in 1 hour.</p>
128 <a href="${link}"
129 style="display:inline-block;background:#7c5cff;color:#fff;padding:10px 20px;border-radius:8px;text-decoration:none;margin-top:12px">
130 Reset password →
131 </a>
132 <p style="color:#64748b;font-size:12px;margin-top:24px">If you didn't request this, you can safely ignore this email.</p>
133 </div>`,
134 });
135}
136
137module.exports = { send, sendWelcome, sendUpgradeConfirmation, sendPasswordReset };