Google Calendar: send invitation notifications on booking events
Add attendees to calendar events with sendUpdates=all so workers and Evelin receive an instant push notification + invitation email when a booking is created or modified, instead of the event silently appearing. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -27,19 +27,30 @@ class GoogleCalendar {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a calendar event.
|
||||
* Create a calendar event and notify the attendee.
|
||||
* @param string $calendarId Calendar to insert into
|
||||
* @param string $title
|
||||
* @param string $description
|
||||
* @param string $startDatetime ISO 8601 (e.g. 2026-03-10T10:00:00)
|
||||
* @param string $endDatetime
|
||||
* @param string|null $attendeeEmail If set, added as attendee — triggers push notification + invite email
|
||||
* @return string|null The new event ID, or null on failure.
|
||||
*/
|
||||
public function createEvent($calendarId, $title, $description, $startDatetime, $endDatetime) {
|
||||
public function createEvent($calendarId, $title, $description, $startDatetime, $endDatetime, $attendeeEmail = null) {
|
||||
if (!$this->service || empty($calendarId)) return null;
|
||||
try {
|
||||
$event = new Google_Service_Calendar_Event([
|
||||
$eventData = [
|
||||
'summary' => $title,
|
||||
'description' => $description,
|
||||
'start' => ['dateTime' => $startDatetime, 'timeZone' => 'Europe/Oslo'],
|
||||
'end' => ['dateTime' => $endDatetime, 'timeZone' => 'Europe/Oslo'],
|
||||
]);
|
||||
$result = $this->service->events->insert($calendarId, $event);
|
||||
];
|
||||
if (!empty($attendeeEmail)) {
|
||||
$eventData['attendees'] = [['email' => $attendeeEmail]];
|
||||
}
|
||||
$event = new Google_Service_Calendar_Event($eventData);
|
||||
$params = !empty($attendeeEmail) ? ['sendUpdates' => 'all'] : [];
|
||||
$result = $this->service->events->insert($calendarId, $event, $params);
|
||||
return $result->getId();
|
||||
} catch (Exception $e) {
|
||||
return null;
|
||||
@@ -47,10 +58,11 @@ class GoogleCalendar {
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing calendar event.
|
||||
* Update an existing calendar event and notify the attendee.
|
||||
* @param string|null $attendeeEmail If set, added as attendee — triggers update notification
|
||||
* @return string|null The event ID, or null on failure.
|
||||
*/
|
||||
public function updateEvent($calendarId, $eventId, $title, $description, $startDatetime, $endDatetime) {
|
||||
public function updateEvent($calendarId, $eventId, $title, $description, $startDatetime, $endDatetime, $attendeeEmail = null) {
|
||||
if (!$this->service || empty($calendarId) || empty($eventId)) return null;
|
||||
try {
|
||||
$event = $this->service->events->get($calendarId, $eventId);
|
||||
@@ -64,7 +76,11 @@ class GoogleCalendar {
|
||||
'dateTime' => $endDatetime,
|
||||
'timeZone' => 'Europe/Oslo',
|
||||
]));
|
||||
$result = $this->service->events->update($calendarId, $eventId, $event);
|
||||
if (!empty($attendeeEmail)) {
|
||||
$event->setAttendees([new Google_Service_Calendar_EventAttendee(['email' => $attendeeEmail])]);
|
||||
}
|
||||
$params = !empty($attendeeEmail) ? ['sendUpdates' => 'all'] : [];
|
||||
$result = $this->service->events->update($calendarId, $eventId, $event, $params);
|
||||
return $result->getId();
|
||||
} catch (Exception $e) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user