import moment from "https://deno.land/x/[email protected]/mod.ts";
export async function main(inputs, params, accounts) {
let googleAccount = accounts.find(a => a.provider == "google.com");
let startTime = moment().add(5, 'hours').toISOString() // start 5 hours from now
let endTime = moment().add(10, 'days').toISOString() // next 10 day window
let res = await fetch(`https://www.googleapis.com/calendar/v3/calendars/primary/events?timeMin=${startTime}&timeMax=${endTime}`, {
headers: {
"Authorization": `Bearer ${googleAccount.access_token}`
}
})
res = await res.json();
console.log(res)
const events = res.items.map(ci => pick(ci, 'summary', 'start', 'end'))
return {
title: "Upcoming Events",
rows: events
}
}
const pick = (obj, ...keys) => Object.fromEntries(
keys
.filter(key => key in obj)
.map(key => [key, obj[key]])
);