π Apps Script + Gemini Mastery β Issue #20
AI Calendar Assistant (Google Calendar + Apps Script)
https://github.com/lsvekis/Apps-Script-Code-Snippets
Automatically schedule meetings, suggest times, and generate event details using Google Apps Script + Gemini.
β What You Will Build
In this issue, youβll build an AI Calendar Assistant that can:
π
Create events from plain English
π§ Generate titles + descriptions
β° Suggest meeting times
π₯ Add attendees
π Auto-fill event details
π§ Why This Project Matters
Scheduling meetings is one of the most repetitive tasks.
Instead of:
β’ checking availability
β’ writing descriptions
β’ adding details manually
You can just say:
βSchedule a 30-minute meeting with the marketing team next Tuesdayβ
And let AI handle the rest.
π§© Architecture
User prompt
β
Apps Script parses request
β
Gemini structures event
β
Apps Script creates Calendar event
π§± Step 1 β Menu
Code.gs
function onOpen() {SpreadsheetApp.getUi()
.createMenu("AI Tools")
.addItem("AI Calendar Assistant", "showCalendarSidebar")
.addToUi()}function showCalendarSidebar(){SpreadsheetApp.getUi().showSidebar(
HtmlService.createHtmlOutputFromFile("Sidebar")
.setTitle("AI Calendar Assistant")
)}
π§± Step 2 β Sidebar UI
Sidebar.html
<div style="font-family:Arial;padding:14px;"><h2>AI Calendar Assistant</h2><label><b>Describe the meeting</b></label><textarea id="prompt"
style="width:100%;height:80px;">
Example: Schedule a 30-minute meeting with the marketing team next Tuesday
</textarea><button onclick="create()">Create Event</button><pre id="output"
style="white-space:pre-wrap;margin-top:12px;"></pre><script>function create(){document.getElementById("output").textContent="Creating event..."google.script.run
.withSuccessHandler(res=>{
document.getElementById("output").textContent=res
})
.createEventFromPrompt(
document.getElementById("prompt").value
)}</script></div>
π§± Step 3 β Generate Event Details with Gemini
EventGenerator.gs
function createEventFromPrompt(userPrompt){if(!userPrompt) return "Enter a request."const prompt = `
You are a calendar assistant.Convert the request into structured event data.Return JSON:{
"title": "event title",
"description": "event description",
"start": "YYYY-MM-DDTHH:MM",
"end": "YYYY-MM-DDTHH:MM"
}Request:
${userPrompt}
`let resulttry{
result = callGemini(prompt,"")
}catch(e){
return "Gemini error: "+e
}result = result.replace(/```json/g,"").replace(/```/g,"")let eventtry{
event = JSON.parse(result)
}catch(e){
return "Error parsing event."
}return createCalendarEvent_(event)}
π§± Step 4 β Create Calendar Event
CalendarCreator.gs
function createCalendarEvent_(event){const calendar = CalendarApp.getDefaultCalendar()const start = new Date(event.start)
const end = new Date(event.end)calendar.createEvent(
event.title,
start,
end,
{description: event.description}
)return "Event created in Google Calendar."}
π§± Step 5 β Gemini Helper
Reuse:
const GEMINI_API_KEY = "YOUR_API_KEY"
const GEMINI_MODEL = "gemini-2.5-flash"
π§ͺ Example Prompts
Users can say:
Schedule a 30-minute meeting with the marketing team next Tuesday at 2pm
Create a 1-hour project planning session tomorrow morning
Set up a weekly check-in every Monday at 10am
Schedule a call with a client next Friday afternoon
π₯ Advanced Exercises
Readers can extend this by adding:
β
attendee email detection
β
availability checking
β
recurring events
β
meeting links (Google Meet)
β
timezone handling