Step 4 — Calendar booking
Google Calendar API integration for automated viewing scheduling.
2 min read
Setting up calendar booking
Step 1: Google Calendar API
- Go to console.cloud.google.com
- Create a new project → Enable Calendar API
- Create OAuth 2.0 credentials
- Download the
credentials.jsonfile
Step 2: The booking function
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
import datetime
SCOPES = ["https://www.googleapis.com/auth/calendar"]
def book_viewing(lead, agent_email):
flow = InstalledAppFlow.from_client_secrets_file("credentials.json", SCOPES)
creds = flow.run_local_server(port=0)
service = build("calendar", "v3", credentials=creds)
# Check agent's availability for next 3 days
now = datetime.datetime.utcnow().isoformat() + "Z"
events = service.events().list(
calendarId=agent_email,
timeMin=now,
maxResults=10,
singleEvents=True,
orderBy="startTime",
).execute()
free_slots = find_free_slots(events["items"], lead["timeline"])
# Create the event
event = {
"summary": f"Property viewing — {lead['name']}",
"location": lead["property_address"],
"description": f"Viewing for {lead['name']} (Bayut lead). Budget: {lead['budget']}.",
"start": {
"dateTime": free_slots[0].isoformat(),
"timeZone": "Asia/Dubai",
},
"end": {
"dateTime": (free_slots[0] + datetime.timedelta(hours=1)).isoformat(),
"timeZone": "Asia/Dubai",
},
"attendees": [{"email": lead["email"]}, {"email": agent_email}],
"reminders": {
"useDefault": False,
"overrides": [
{"method": "email", "minutes": 24 * 60},
{"method": "popup", "minutes": 10},
],
},
}
event = service.events().insert(calendarId=agent_email, body=event).execute()
return event.get("htmlLink")
Step 3: What times to offer
Don't ask the lead "when are you free?" — that creates back-and-forth. Instead, offer 3 specific times:
- Today 3pm or 5pm (urgent — creates scarcity)
- Tomorrow 10am (backup option)
- Tomorrow 2pm (alternative)
The AI should say: "I can get you in today at 3pm or 5pm, or tomorrow at 10am. Which works?"
Gotchas
- Time zone — always use Asia/Dubai explicitly
- Working hours — only offer 9am–8pm slots (agents' active hours)
- Conflict detection — check the agent's calendar for conflicts before proposing
- Rescheduling — include a reschedule link in the calendar invite (Google Calendar has built-in rescheduling)
- Property address — you need the actual property address, not just the reference number. Parse it from the portal email or scrape it from the listing page.
The handoff rule
After booking, send:
- Calendar invite to the lead
- SMS confirmation (Twilio) with the agent's name and property address
- CRM record with all conversation history
- Agent notification email with lead details + viewing link
This triple-channel confirmation has a 94% attendance rate for booked viewings.
AI Lead Automation · progress saved in this browser · sign in to sync across devices
Up next
Outreach channels (ranked by ROI)
WhatsApp voice notes (40-60% reply) > LinkedIn signal-triggered DM > LinkedIn cold DM > Instagram DM > Cold email.
2 min