gcal.googlecalendar
Home > @runlightyear/gcal > GoogleCalendar
GoogleCalendar class
This API is in beta and may contain contain bugs. Can be used in production with caution.
Google Calendar connector
Signature:declare class GoogleCalendar extends RestConnector
Extends:
Example 1
Create an event
import { defineAction } from "@runlightyear/lightyear";
import { GoogleCalendar } from "@runlightyear/gcal";
function addHours(date: Date, hours: number) {
return new Date(date.getTime() + hours * 60 * 60 * 1000);
}
defineAction({
name: "createEvent",
title: "Create Event",
apps: ["gcal"],
variables: ["calendarId?", "summary"],
run: async ({ auths, variables }) => {
const gcal = new GoogleCalendar({
auth: auths.gcal,
});
const response = await gcal.createEvent({
calendarId: variables.calendarId || "primary",
event: {
summary: variables.summary!,
start: {
dateTime: addHours(new Date(), 1).toISOString(),
},
end: {
dateTime: addHours(new Date(), 2).toISOString(),
},
},
});
console.log("Response: ", response.data);
},
});
Example 2
Create an event with attendees
import { defineAction } from "@runlightyear/lightyear";
import { GoogleCalendar } from "@runlightyear/gcal";
function addHours(date: Date, hours: number) {
return new Date(date.getTime() + hours * 60 * 60 * 1000);
}
defineAction({
name: "createEventWithAttendees",
title: "Create Event with Attendees",
apps: ["gcal"],
variables: ["calendarId?", "summary", "attendees"],
run: async ({ auths, variables }) => {
const gcal = new GoogleCalendar({
auth: auths.gcal,
});
const attendees = variables.attendees!.split(",");
const response = await gcal.createEvent({
calendarId: variables.calendarId || "primary",
event: {
summary: variables.summary!,
start: {
dateTime: addHours(new Date(), 1).toISOString(),
},
end: {
dateTime: addHours(new Date(), 2).toISOString(),
},
attendees: attendees.map((email) => ({
email,
})),
},
});
console.log("Response: ", response.data);
},
});
Example 3
Create an all-day event
import { defineAction } from "@runlightyear/lightyear";
import { GoogleCalendar } from "@runlightyear/gcal";
function tomorrow() {
const date = new Date();
date.setDate(date.getDate() + 1);
return date.toISOString().split("T")[0];
}
defineAction({
name: "createAllDayEvent",
title: "Create All Day Event",
apps: ["gcal"],
variables: ["calendarId?", "summary"],
run: async ({ auths, variables }) => {
const gcal = new GoogleCalendar({
auth: auths.gcal,
});
const response = await gcal.createEvent({
calendarId: variables.calendarId || "primary",
event: {
summary: variables.summary!,
start: {
date: tomorrow(),
},
end: {
date: tomorrow(),
},
},
});
console.log("Response: ", response.data);
},
});
Example 4
List upcoming events
import { defineAction } from "@runlightyear/lightyear";
import { GoogleCalendar } from "@runlightyear/gcal";
function addDays(date: Date, days: number) {
return new Date(date.getTime() + days * 24 * 60 * 60 * 1000);
}
defineAction({
name: "listUpcomingEvents",
title: "List Upcoming Events",
apps: ["gcal"],
variables: ["calendarId?"],
run: async ({ auths, variables }) => {
const gcal = new GoogleCalendar({
auth: auths.gcal,
});
const response = await gcal.listEvents({
calendarId: variables.calendarId || "primary",
timeMin: new Date().toISOString(),
timeMax: addDays(new Date(), 2).toISOString(),
});
console.log("Response: ", response.data);
},
});
Example 5
Get an event
import { defineAction } from "@runlightyear/lightyear";
import { GoogleCalendar } from "@runlightyear/gcal";
defineAction({
name: "getEvent",
title: "Get Event",
apps: ["gcal"],
variables: ["calendarId?", "eventId"],
run: async ({ auths, variables }) => {
const gcal = new GoogleCalendar({
auth: auths.gcal,
});
const response = await gcal.getEvent({
calendarId: variables.calendarId || "primary",
eventId: variables.eventId!,
});
console.log("Response: ", response.data);
},
});
Example 6
Patch event summary
import { defineAction } from "@runlightyear/lightyear";
import { GoogleCalendar } from "@runlightyear/gcal";
defineAction({
name: "patchEventSummary",
title: "Patch Event Summary",
apps: ["gcal"],
variables: ["calendarId?", "eventId", "summary"],
run: async ({ auths, variables }) => {
const gcal = new GoogleCalendar({
auth: auths.gcal,
});
const response = await gcal.patchEvent({
calendarId: variables.calendarId || "primary",
eventId: variables.eventId!,
event: {
summary: variables.summary!,
},
});
console.log("Response: ", response.data);
},
});
Example 7
Patch event attendees
import { defineAction } from "@runlightyear/lightyear";
import { GoogleCalendar } from "@runlightyear/gcal";
defineAction({
name: "addEventAttendee",
title: "Add Event Attendee",
apps: ["gcal"],
variables: ["calendarId?", "eventId", "attendee"],
run: async ({ auths, variables }) => {
const gcal = new GoogleCalendar({
auth: auths.gcal,
});
const getEventResponse = await gcal.getEvent({
calendarId: variables.calendarId || "primary",
eventId: variables.eventId!,
});
const event = getEventResponse.data;
const response = await gcal.patchEvent({
calendarId: variables.calendarId || "primary",
eventId: variables.eventId!,
event: {
attendees: [...event.attendees, { email: variables.attendee! }],
},
});
console.log("Response: ", response.data);
},
});
Example 8
Update event
import { defineAction } from "@runlightyear/lightyear";
import { GoogleCalendar } from "@runlightyear/gcal";
function addHours(date: Date, hours: number) {
return new Date(date.getTime() + hours * 60 * 60 * 1000);
}
defineAction({
name: "updateEvent",
title: "Update Event",
apps: ["gcal"],
variables: ["calendarId?", "eventId", "summary"],
run: async ({ auths, variables }) => {
const gcal = new GoogleCalendar({
auth: auths.gcal,
});
const response = await gcal.updateEvent({
calendarId: variables.calendarId || "primary",
eventId: variables.eventId!,
event: {
summary: variables.summary!,
start: {
dateTime: addHours(new Date(), 2).toISOString(),
},
end: {
dateTime: addHours(new Date(), 3).toISOString(),
},
},
});
console.log("Response: ", response.data);
},
});
Example 9
Delete event
import { defineAction } from "@runlightyear/lightyear";
import { GoogleCalendar } from "@runlightyear/gcal";
defineAction({
name: "deleteEvent",
title: "Delete Event",
apps: ["gcal"],
variables: ["calendarId?", "eventId"],
run: async ({ auths, variables }) => {
const gcal = new GoogleCalendar({
auth: auths.gcal,
});
const response = await gcal.deleteEvent({
calendarId: variables.calendarId || "primary",
eventId: variables.eventId!,
});
console.log("Response: ", response.data);
},
});
Example 10
On new events
import { GoogleCalendar } from "@runlightyear/gcal";
GoogleCalendar.onNewEvents({
name: "onNewEvents",
title: "On New Events",
run: async ({ data }) => {
console.info("New events", data);
},
});
Example 11
On new and updated events
import { GoogleCalendar } from "@runlightyear/gcal";
GoogleCalendar.onNewAndUpdatedEvents({
name: "onNewAndUpdatedEvents",
title: "On New and Updated Events",
run: async ({ data }) => {
console.info("New and updated events", data);
},
});
Constructors
Constructor | Modifiers | Description |
---|---|---|
(constructor)(props) | (BETA) Constructs a new instance of the GoogleCalendar class |
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
authType | static | AuthType | (BETA) |
OAuth | static | typeof GoogleCalendarOAuth | (BETA) |
Calendar Methods
Method | Modifiers | Description |
---|---|---|
createCalendar(props) | (BETA) Creates a secondary calendar. | |
listCalendars(props) | (BETA) Returns the calendars on the user's calendar list. |
Event Methods
Method | Modifiers | Description |
---|---|---|
createEvent(props) | (BETA) Creates an event. | |
deleteEvent(props) | (BETA) Deletes an event. | |
getEvent(props) | (BETA) Get an event. | |
listEvents(props) | (BETA) Returns events on the specified calendar. | |
patchEvent(props) | (BETA) Patch an event. | |
updateEvent(props) | (BETA) Updates an event. This method does not support patch semantics and always updates the entire event resource. To do a partial update, perform a get followed by an update using etags to ensure atomicity. |
Listener Methods
Method | Modifiers | Description |
---|---|---|
onNewAndUpdatedEvents(props) | static | (BETA) On new and updated events |
onNewEvents(props) | static | (BETA) On new events |
Notification Methods
Method | Modifiers | Description |
---|---|---|
stopChannel(props) | (BETA) Stop notification channel | |
watchEvents(props) | (BETA) Watch for events. |
Other Methods
Method | Modifiers | Description |
---|---|---|
defineEventsWebhook(props) | static | (BETA) Low level interface to define an event webhook. |
getBaseUrl() | (BETA) |