Skip to content

Commit 8c3ddb5

Browse files
author
CloudLobster
committed
feat: bond receipt confirmation email sent to sender after deposit
1 parent 970289f commit 8c3ddb5

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

worker/src/routes/attention.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,21 @@ authed.post('/bond', async (c) => {
592592
// Recalculate QAF
593593
await recalculateQAF(c.env.DB, recipient_handle);
594594

595+
// Send bond receipt email to sender
596+
try {
597+
const deadlineDate = new Date((now + window) * 1000).toUTCString();
598+
const receiptId = `bond-${Date.now().toString(36)}-${crypto.randomUUID().slice(0, 8)}`;
599+
const receiptSubject = `🔒 Attention Bond Confirmed — $${verifiedAmount.toFixed(2)} USDC`;
600+
const receiptBody = `Your Attention Bond to ${recipient_handle}@basemail.ai is now active.\n\nAmount: $${verifiedAmount.toFixed(2)} USDC\nDeadline: ${deadlineDate}\nTx: ${tx_hash}\n\nIf they reply before the deadline, you get a full refund.\nIf not, the bond is forfeited.\n\n—\nBaseMail Attention Bonds · https://basemail.ai/dashboard/attention`;
601+
const r2Key = `emails/${auth.handle}/inbox/${receiptId}.eml`;
602+
const rawMime = `From: system@basemail.ai\r\nTo: ${auth.handle}@basemail.ai\r\nSubject: ${receiptSubject}\r\nDate: ${new Date().toUTCString()}\r\nContent-Type: text/plain; charset=utf-8\r\n\r\n${receiptBody}`;
603+
await c.env.EMAIL_STORE.put(r2Key, rawMime);
604+
await c.env.DB.prepare(
605+
`INSERT INTO emails (id, handle, folder, from_addr, to_addr, subject, snippet, r2_key, size, read, created_at)
606+
VALUES (?, ?, 'inbox', 'system@basemail.ai', ?, ?, ?, ?, ?, 0, ?)`
607+
).bind(receiptId, auth.handle, `${auth.handle}@basemail.ai`, receiptSubject, receiptBody.slice(0, 200), r2Key, rawMime.length, now).run();
608+
} catch (_) { /* don't block bond recording */ }
609+
595610
return c.json({
596611
success: true,
597612
email_id,

0 commit comments

Comments
 (0)