A Google Apps Script library that uses Gemini AI.
For example, summarize Gmail messages filtered by user specified query. This library helps you process content from Google Workspace and summarize email content, making it easier to handle large volumes of emails.
at present,
- Writer ( Console / Gmail )
- Searcher & Extracter ( Gmail )
- EmailSummarizer ( Gemini Prompt Customizable )
- EmailSummaryFormatter ( customizable )
- EmailSummaryWorkflow
Add this Library to Your Google Apps Script Project as below
- In your Google Apps Script project, go to Libraries (+ symbol)
- Enter the Library ID:
13l4VrUvxRLXOfER9BJApgXxhkuqBmvYoKtZONNhUgSzbv_bsAebNKt-f
- Select the latest version
- Click Add
async function summarizeRecentEmails () {
// Summarize emails from the last 2 days,
// with default summarize driver ( truncate ) and default writer ( console )
return await AgenticTools.summarizeEmailWorkflow({
query: 'newer_than:2d'
})
}
see https://github.com/mhawksey/GeminiApp?tab=readme-ov-file#setup
async function summarizeImportantEmails () {
// Create a Gemini driver with custom configuration
const geminiDriver = AgenticTools.createEmailSummarizeGeminiDriver({
geminiAuthConfig: <Use your Gemini API key or project configuration>
model: 'gemini-2.0-flash'
})
const summarizer = createEmailSummarizer(geminiDriver);
return await AgenticTools.summarizeEmailWorkflow({
query: 'is:important newer_than:7d',
name: 'Important Emails Summary',
summarizer
})
}
async function summarizeWithCustomPrompt () {
return await AgenticTools.summarizeEmailWorkflow({
query: 'label:project-x',
name: 'Project X Updates',
summarizer: AgenticTools.createEmailSummarizeGeminiDriver(...),
summarizeDriverExecOpts: { // give PromptTemplate
instruction: 'Analyze the following project-related emails and extract key information:',
eachMessage: (message) => {
return message.body + '\n'
},
output: `Provide a structured summary with these sections:
- Project Status
- Key Decisions
- Action Items
- Risks and Issues
- Next Steps`
}
})
}
// without format template customization
const defaultFormatter = AgenticTools.createEmailSummaryFormatter({
name: 'Daily Email Summary',
embedLink: true
})
// with format template customization
const customFormatter = AgenticTools.createEmailSummaryFormatter({
name: 'Weekly Email Digest',
embedLink: true,
formatTemplate: {
/** @type {EmailSummaryFormatterHeaderTemplate} */
header: (count, name) => `${name} (${count} MESSAGES)`,
/** @type {EmailSummaryFormatterSeparatorTemplete} */
separator: (length = 40, char = '*') => char.repeat(length),
/** @type {EmailSummaryFormatterTitleTemplate} */
summaryTitle: (index, summary) => `MESSAGE #${index}: ${summary.subject}`,
/** @type {EmailSummaryFormatterSummaryTemplate} */
summary: (summary, embedLink) => {
return [
AgenticTools.normalizeLineFeeds(summary.summary),
(embedLink) ? `\nOriginal: ${messageUrl(summary)}` : false
].filter((e) => e).join('\n')
}
}
})
Or override exec
method.
see https://github.com/mhawksey/GeminiApp?tab=readme-ov-file#setup
see https://support.google.com/mail/answer/7190?hl=en&co=GENIE.Platform%3DDesktop