Skip to content

Instantly share code, notes, and snippets.

@jayenashar
Last active March 19, 2026 11:46
Show Gist options
  • Select an option

  • Save jayenashar/3c2fa5bdc9086fefbc2ed949fece1795 to your computer and use it in GitHub Desktop.

Select an option

Save jayenashar/3c2fa5bdc9086fefbc2ed949fece1795 to your computer and use it in GitHub Desktop.
google apps script to invite attendee to event based on location

i used AI but it's something like this:

https://script.google.com/

add the Calendar service

function addRoomWithoutNotification() {
  var calendarId = 'me@google-workspace.com';
  var locationsToMatch = ['room.com', 'same-room.com', 'same.com/room'];
  var roomEmail = 'c_1234567890@resource.calendar.google.com'; // Actual room email
  var now = new Date();
  var future = new Date(now.getTime() + 14 * 24 * 60 * 60 * 1000);
  var events = Calendar.Events.list(calendarId, {
    timeMin: now.toISOString(),
    timeMax: future.toISOString(),
    singleEvents: true
  });

  if (!events.items) return;
  
  events.items.forEach(function(event) {
    if (locationsToMatch.some(location => event.location?.includes(location))) {
      var attendees = event.attendees || [];
      var hasRoom = attendees.some(function(a) {
        return (a.email === roomEmail);
      });
      if (!hasRoom) {
        attendees.push({email: roomEmail});
        Calendar.Events.patch(
          {attendees: attendees},
          calendarId,
          event.id,
          {sendUpdates: 'none'}
        );
      }
    }
  });
}
trigger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment