UNPKG

google-meet-scheduler

Version:

Generate Google Meet links by creating calendar events using the Google API

53 lines (52 loc) 1.8 kB
import { google } from "googleapis"; import dayjs from "dayjs"; /** * Create a Google Calendar event with Google Meet link. */ export const createGoogleMeetEvent = async ({ summary = "Scheduled Meeting", description = "Created via API", startTime, endTime, timeZone = "UTC", credentials, }) => { try { const oAuth2Client = new google.auth.OAuth2(credentials.clientId, credentials.clientSecret, credentials.redirectUri); oAuth2Client.setCredentials({ refresh_token: credentials.refreshToken, }); const calendar = google.calendar({ version: "v3", auth: oAuth2Client }); const start = startTime || dayjs().add(5, "minute").toDate(); const end = endTime || dayjs(start).add(30, "minute").toDate(); const event = { summary, description, start: { dateTime: start.toISOString(), timeZone, }, end: { dateTime: end.toISOString(), timeZone, }, conferenceData: { createRequest: { requestId: `${Date.now()}`, conferenceSolutionKey: { type: "hangoutsMeet", }, }, }, }; const response = await calendar.events.insert({ calendarId: "primary", requestBody: event, conferenceDataVersion: 1, }); return { success: true, meetLink: response.data?.hangoutLink || "", eventId: response.data.id ?? undefined, }; } catch (error) { return { success: false, error: error?.message || "Unknown error occurred", }; } };