Open script.google.com inside the Gmail account you want triaged and click New Project.
Click Copy Script below, replace Code.gs, and hit Save. Works free immediately in Smart Local Mode (or add GEMINI_API_KEY in Script Properties).
Run runQuickTest5Emails once to verify 5 threads. Then run setupLabelsAndTrigger once for daily 8 AM automation.
/* Austin AI Marketing Co — 8 AM Inbox Triage (Drafts-Only, Self-Healing) */
const LABELS = {
HOT_LEAD: 'AI-Triage/1-Hot-Lead',
URGENT_CLIENT: 'AI-Triage/2-Urgent-Client',
BILLING: 'AI-Triage/3-Billing-Vendor',
NOISE: 'AI-Triage/4-Noise',
PROCESSED: 'AI-Triage/Processed',
};
function runQuickTest5Emails() { runMorningTriage_(5, true); }
function runMorningTriage() { runMorningTriage_(25, false); }
function setupLabelsAndTrigger() {
Object.values(LABELS).forEach(n => GmailApp.getUserLabelByName(n) || GmailApp.createLabel(n));
ScriptApp.getProjectTriggers().forEach(t => { if (t.getHandlerFunction() === 'runMorningTriage') ScriptApp.deleteTrigger(t); });
ScriptApp.newTrigger('runMorningTriage').timeBased().everyDays(1).atHour(7).create();
}
function runMorningTriage_(maxThreads, includeRead) {
const props = PropertiesService.getScriptProperties();
const businessName = props.getProperty('BUSINESS_NAME') || 'Your Business';
const ownerName = props.getProperty('OWNER_NAME') || 'Team';
const ownerEmail = props.getProperty('OWNER_EMAIL') || Session.getActiveUser().getEmail();
const map = {};
Object.keys(LABELS).forEach(k => { map[k] = GmailApp.getUserLabelByName(LABELS[k]) || GmailApp.createLabel(LABELS[k]); });
const q = includeRead ? 'in:inbox -label:' + LABELS.PROCESSED : 'in:inbox is:unread newer_than:2d -label:' + LABELS.PROCESSED;
const threads = GmailApp.search(q, 0, maxThreads);
const sum = { HOT_LEAD: [], URGENT_CLIENT: [], BILLING: [], NOISE: [] };
threads.forEach(th => {
try {
const m = th.getMessages().slice(-1)[0];
const subj = m.getSubject() || '(no subject)';
if (subj.indexOf('[8 AM Brief]') === 0) return;
const hay = (m.getFrom() + ' ' + subj + ' ' + (m.getPlainBody() || '').slice(0, 1200)).toLowerCase();
let cat = 'NOISE', draft = '';
if (/(quote|estimate|proposal|inquiry|booking|thumbtack|angi|yelp|lead|pricing)/.test(hay)) {
cat = 'HOT_LEAD';
draft = 'Hi there,\n\nThanks for reaching out about "' + subj + '". I reviewed your note and would be glad to help right away. What time works best for a quick call today?\n\nBest,\n' + ownerName + '\n' + businessName;
} else if (/(urgent|asap|reschedule|emergency|gate code|action required|deadline)/.test(hay)) {
cat = 'URGENT_CLIENT';
draft = 'Hi there,\n\nGot your note on "' + subj + '" — I am on it and will follow up shortly.\n\nBest,\n' + ownerName + '\n' + businessName;
} else if (/(invoice|receipt|stripe|payment|billing|statement|tax)/.test(hay)) {
cat = 'BILLING';
}
th.addLabel(map[cat]); th.addLabel(map.PROCESSED);
if (draft) th.createDraftReply(draft);
sum[cat].push(subj);
} catch (e) { Logger.log('[SELF-HEAL] ' + e); }
});
GmailApp.sendEmail(ownerEmail, '[8 AM Brief] ' + sum.HOT_LEAD.length + ' Hot Leads, ' + sum.URGENT_CLIENT.length + ' Urgent',
'Triaged ' + threads.length + ' emails. Hot Leads: ' + sum.HOT_LEAD.join(', ') + ' | Urgent: ' + sum.URGENT_CLIENT.join(', '));
}
Non-Gmail Triage: Connect your domain in Gmail Settings → Accounts and Import (Send Mail As + POP3/Forward) or reply to your Stripe receipt for your included 15-minute live done-with-you screen share.
$297 Black Friday Flash Pack: Your 24-hour creative clock starts now—watch your checkout email for your 2-minute brand intake prompt.