Skip to main content

Multi-Condition Filter

What it does: Passes events only when they satisfy a combination of conditions: weekday timing, business hours, attendee requirements, and keyword exclusions.

Use case: Build a precise rule when a single condition is not enough — for example, syncing only confirmed weekday work meetings that include at least one colleague and are not marked as personal.

function rule(event: RuleEvent): RuleResult {
// Condition 1: Only weekday events
if (!event.isWeekday) {
return { pass: false, reason: 'Event is on a weekend' };
}

// Condition 2: Only during business hours (9 AM – 5 PM)
if (event.hour < 9 || event.hour >= 17) {
return { pass: false, reason: 'Event is outside business hours' };
}

// Condition 3: Must have at least 2 attendees OR be tagged as important
if (event.attendeeCount < 2 && !event.matches('important')) {
return { pass: false, reason: 'No attendees and not flagged as important' };
}

// Condition 4: Exclude personal events
if (event.matches('personal') || event.matches('private')) {
return { pass: false, reason: 'Event is personal' };
}

return { pass: true };
}

How It Works​

Each condition is evaluated in sequence. The first condition that fails causes the gate function to return pass: false with a specific reason, which helps with debugging in the Code Editor. If the event passes all conditions, it is synced. Using early returns keeps the logic flat and easy to read.

The recipe uses several RuleEvent properties:

  • isWeekday — computed from dayOfWeek (evaluated in UTC)
  • hour — the event's start hour (0–23), in UTC — shift the bounds by your UTC offset (see the property reference)
  • attendeeCount — the number of attendees
  • matches() — case-insensitive search in title and description

Customization​

Add a status check to exclude cancellations:

function rule(event: RuleEvent): RuleResult {
if (event.status === 'cancelled') {
return { pass: false, reason: 'Cancelled event' };
}

if (!event.isWeekday) {
return { pass: false, reason: 'Weekend event' };
}

if (event.hour < 9 || event.hour >= 17) {
return { pass: false, reason: 'Outside business hours' };
}

return { pass: true };
}

Loosen conditions with OR logic:

function rule(event: RuleEvent): RuleResult {
// Pass if it matches any approved keyword OR has company attendees
if (
event.matches('standup') ||
event.matches('sync') ||
event.hasAttendee('@company.com')
) {
return { pass: true };
}

return { pass: false, reason: 'Event does not meet approval criteria' };
}